OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/compositor/compositor_view.h" | 5 #include "chrome/browser/android/compositor/compositor_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include <android/bitmap.h> | 9 #include <android/bitmap.h> |
10 #include <android/native_window_jni.h> | 10 #include <android/native_window_jni.h> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 jobject obj, | 77 jobject obj, |
78 jint empty_background_color, | 78 jint empty_background_color, |
79 jboolean low_mem_device, | 79 jboolean low_mem_device, |
80 ui::WindowAndroid* window_android, | 80 ui::WindowAndroid* window_android, |
81 LayerTitleCache* layer_title_cache, | 81 LayerTitleCache* layer_title_cache, |
82 TabContentManager* tab_content_manager) | 82 TabContentManager* tab_content_manager) |
83 : layer_title_cache_(layer_title_cache), | 83 : layer_title_cache_(layer_title_cache), |
84 tab_content_manager_(tab_content_manager), | 84 tab_content_manager_(tab_content_manager), |
85 root_layer_( | 85 root_layer_( |
86 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 86 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
87 toolbar_layer_(ToolbarLayer::Create()), | |
88 scene_layer_(nullptr), | 87 scene_layer_(nullptr), |
89 current_surface_format_(0), | 88 current_surface_format_(0), |
90 content_width_(0), | 89 content_width_(0), |
91 content_height_(0), | 90 content_height_(0), |
92 overdraw_bottom_height_(0), | 91 overdraw_bottom_height_(0), |
93 overlay_video_mode_(false), | 92 overlay_video_mode_(false), |
94 empty_background_color_(empty_background_color), | 93 empty_background_color_(empty_background_color), |
95 weak_factory_(this) { | 94 weak_factory_(this) { |
96 content::BrowserChildProcessObserver::Add(this); | 95 content::BrowserChildProcessObserver::Add(this); |
97 obj_.Reset(env, obj); | 96 obj_.Reset(env, obj); |
98 compositor_.reset(content::Compositor::Create(this, window_android)); | 97 compositor_.reset(content::Compositor::Create(this, window_android)); |
99 | 98 |
| 99 toolbar_layer_ = ToolbarLayer::Create(&(compositor_->GetResourceManager())); |
| 100 |
100 root_layer_->SetIsDrawable(true); | 101 root_layer_->SetIsDrawable(true); |
101 root_layer_->SetBackgroundColor(SK_ColorWHITE); | 102 root_layer_->SetBackgroundColor(SK_ColorWHITE); |
102 | 103 |
103 toolbar_layer_->layer()->SetHideLayerAndSubtree(true); | 104 toolbar_layer_->layer()->SetHideLayerAndSubtree(true); |
104 root_layer_->AddChild(toolbar_layer_->layer()); | 105 root_layer_->AddChild(toolbar_layer_->layer()); |
105 } | 106 } |
106 | 107 |
107 CompositorView::~CompositorView() { | 108 CompositorView::~CompositorView() { |
108 content::BrowserChildProcessObserver::Remove(this); | 109 content::BrowserChildProcessObserver::Remove(this); |
109 tab_content_manager_->OnUIResourcesWereEvicted(); | 110 tab_content_manager_->OnUIResourcesWereEvicted(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 243 } |
243 | 244 |
244 int CompositorView::GetUsableContentHeight() { | 245 int CompositorView::GetUsableContentHeight() { |
245 return std::max(content_height_ - overdraw_bottom_height_, 0); | 246 return std::max(content_height_ - overdraw_bottom_height_, 0); |
246 } | 247 } |
247 | 248 |
248 void CompositorView::UpdateToolbarLayer(JNIEnv* env, | 249 void CompositorView::UpdateToolbarLayer(JNIEnv* env, |
249 jobject object, | 250 jobject object, |
250 jint toolbar_resource_id, | 251 jint toolbar_resource_id, |
251 jint toolbar_background_color, | 252 jint toolbar_background_color, |
| 253 jint url_bar_resource_id, |
| 254 jfloat url_bar_alpha, |
252 jfloat top_offset, | 255 jfloat top_offset, |
253 jfloat brightness, | 256 jfloat brightness, |
254 bool visible, | 257 bool visible, |
255 bool show_shadow) { | 258 bool show_shadow) { |
256 // Ensure the toolbar resource is available before making the layer visible. | |
257 ui::ResourceManager::Resource* resource = | |
258 compositor_->GetResourceManager().GetResource( | |
259 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, toolbar_resource_id); | |
260 if (!resource) | |
261 visible = false; | |
262 | |
263 toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible); | 259 toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible); |
264 if (visible) { | 260 if (visible) { |
265 toolbar_layer_->layer()->SetPosition(gfx::PointF(0, top_offset)); | 261 toolbar_layer_->layer()->SetPosition(gfx::PointF(0, top_offset)); |
266 toolbar_layer_->PushResource(resource, toolbar_background_color, false, | |
267 SK_ColorWHITE, false, brightness); | |
268 | |
269 // If we're at rest, hide the shadow. The Android view should be drawing. | 262 // If we're at rest, hide the shadow. The Android view should be drawing. |
270 toolbar_layer_->layer()->SetMasksToBounds(top_offset >= 0.f | 263 bool clip_shadow = top_offset >= 0.f && !show_shadow; |
271 && !show_shadow); | 264 toolbar_layer_->PushResource(toolbar_resource_id, toolbar_background_color, |
| 265 false, SK_ColorWHITE, url_bar_resource_id, |
| 266 url_bar_alpha, false, brightness, clip_shadow); |
272 } | 267 } |
273 } | 268 } |
274 | 269 |
275 void CompositorView::UpdateProgressBar(JNIEnv* env, | 270 void CompositorView::UpdateProgressBar(JNIEnv* env, |
276 jobject object, | 271 jobject object, |
277 jint progress_bar_x, | 272 jint progress_bar_x, |
278 jint progress_bar_y, | 273 jint progress_bar_y, |
279 jint progress_bar_width, | 274 jint progress_bar_width, |
280 jint progress_bar_height, | 275 jint progress_bar_height, |
281 jint progress_bar_color, | 276 jint progress_bar_color, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // through here but through BrowserChildProcessHostDisconnected() instead. | 320 // through here but through BrowserChildProcessHostDisconnected() instead. |
326 } | 321 } |
327 | 322 |
328 // Register native methods | 323 // Register native methods |
329 bool RegisterCompositorView(JNIEnv* env) { | 324 bool RegisterCompositorView(JNIEnv* env) { |
330 return RegisterNativesImpl(env); | 325 return RegisterNativesImpl(env); |
331 } | 326 } |
332 | 327 |
333 } // namespace android | 328 } // namespace android |
334 } // namespace chrome | 329 } // namespace chrome |
OLD | NEW |