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. | 259 // Ensure the toolbar resource is available before making the layer visible. |
257 ui::ResourceManager::Resource* resource = | 260 ui::ResourceManager::Resource* resource = |
258 compositor_->GetResourceManager().GetResource( | 261 compositor_->GetResourceManager().GetResource( |
259 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, toolbar_resource_id); | 262 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, toolbar_resource_id); |
260 if (!resource) | 263 if (!resource) |
261 visible = false; | 264 visible = false; |
262 | 265 |
263 toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible); | 266 toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible); |
264 if (visible) { | 267 if (visible) { |
265 toolbar_layer_->layer()->SetPosition(gfx::PointF(0, top_offset)); | 268 toolbar_layer_->layer()->SetPosition(gfx::PointF(0, top_offset)); |
266 toolbar_layer_->PushResource(resource, toolbar_background_color, false, | 269 toolbar_layer_->PushResource(resource, toolbar_background_color, false, |
267 SK_ColorWHITE, false, brightness); | 270 SK_ColorWHITE, url_bar_resource_id, |
| 271 url_bar_alpha, false, brightness); |
268 | 272 |
269 // If we're at rest, hide the shadow. The Android view should be drawing. | 273 // If we're at rest, hide the shadow. The Android view should be drawing. |
270 toolbar_layer_->layer()->SetMasksToBounds(top_offset >= 0.f | 274 toolbar_layer_->layer()->SetMasksToBounds(top_offset >= 0.f |
271 && !show_shadow); | 275 && !show_shadow); |
272 } | 276 } |
273 } | 277 } |
274 | 278 |
275 void CompositorView::UpdateProgressBar(JNIEnv* env, | 279 void CompositorView::UpdateProgressBar(JNIEnv* env, |
276 jobject object, | 280 jobject object, |
277 jint progress_bar_x, | 281 jint progress_bar_x, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // through here but through BrowserChildProcessHostDisconnected() instead. | 329 // through here but through BrowserChildProcessHostDisconnected() instead. |
326 } | 330 } |
327 | 331 |
328 // Register native methods | 332 // Register native methods |
329 bool RegisterCompositorView(JNIEnv* env) { | 333 bool RegisterCompositorView(JNIEnv* env) { |
330 return RegisterNativesImpl(env); | 334 return RegisterNativesImpl(env); |
331 } | 335 } |
332 | 336 |
333 } // namespace android | 337 } // namespace android |
334 } // namespace chrome | 338 } // namespace chrome |
OLD | NEW |