Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.cc

Issue 1706293005: StaticTabSceneLayer owns ToolbarLayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix findbugs issue Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/scene_layer/static_tab_scene_layer.h " 5 #include "chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.h "
6 6
7 #include "cc/layers/layer.h" 7 #include "cc/layers/layer.h"
8 #include "chrome/browser/android/compositor/layer/content_layer.h" 8 #include "chrome/browser/android/compositor/layer/content_layer.h"
9 #include "chrome/browser/android/compositor/layer/toolbar_layer.h"
9 #include "chrome/browser/android/compositor/layer_title_cache.h" 10 #include "chrome/browser/android/compositor/layer_title_cache.h"
10 #include "chrome/browser/android/compositor/tab_content_manager.h" 11 #include "chrome/browser/android/compositor/tab_content_manager.h"
11 #include "content/public/browser/android/compositor.h" 12 #include "content/public/browser/android/compositor.h"
12 #include "jni/StaticTabSceneLayer_jni.h" 13 #include "jni/StaticTabSceneLayer_jni.h"
13 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/android/resources/resource_manager_impl.h"
14 16
15 namespace chrome { 17 namespace chrome {
16 namespace android { 18 namespace android {
17 19
18 StaticTabSceneLayer::StaticTabSceneLayer(JNIEnv* env, jobject jobj) 20 StaticTabSceneLayer::StaticTabSceneLayer(JNIEnv* env, jobject jobj)
19 : SceneLayer(env, jobj), 21 : SceneLayer(env, jobj),
20 last_set_tab_id_(-1), 22 last_set_tab_id_(-1),
21 background_color_(SK_ColorWHITE), 23 background_color_(SK_ColorWHITE),
22 brightness_(1.f) { 24 brightness_(1.f) {
23 } 25 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 jfloat brightness) { 58 jfloat brightness) {
57 background_color_ = default_background_color; 59 background_color_ = default_background_color;
58 gfx::Size content_viewport_size(content_viewport_width, 60 gfx::Size content_viewport_size(content_viewport_width,
59 content_viewport_height); 61 content_viewport_height);
60 gfx::Point content_viewport_offset(content_viewport_x, content_viewport_y); 62 gfx::Point content_viewport_offset(content_viewport_x, content_viewport_y);
61 if (!content_layer_.get()) { 63 if (!content_layer_.get()) {
62 chrome::android::TabContentManager* tab_content_manager = 64 chrome::android::TabContentManager* tab_content_manager =
63 chrome::android::TabContentManager::FromJavaObject( 65 chrome::android::TabContentManager::FromJavaObject(
64 jtab_content_manager); 66 jtab_content_manager);
65 content_layer_ = chrome::android::ContentLayer::Create(tab_content_manager); 67 content_layer_ = chrome::android::ContentLayer::Create(tab_content_manager);
68 layer_->AddChild(content_layer_->layer());
66 } 69 }
67 70
68 // Only override the alpha of content layers when the static tab is first 71 // Only override the alpha of content layers when the static tab is first
69 // assigned to the layer tree. 72 // assigned to the layer tree.
70 float content_alpha_override = 1.f; 73 float content_alpha_override = 1.f;
71 bool should_override_content_alpha = last_set_tab_id_ != id; 74 bool should_override_content_alpha = last_set_tab_id_ != id;
72 last_set_tab_id_ = id; 75 last_set_tab_id_ = id;
73 76
74 // Set up the content layer and move it to the proper position. 77 // Set up the content layer and move it to the proper position.
75 content_layer_->layer()->SetBounds(gfx::Size(width, height)); 78 content_layer_->layer()->SetBounds(gfx::Size(width, height));
(...skipping 26 matching lines...) Expand all
102 // If our orientations are off and we have a static texture, or if we have 105 // If our orientations are off and we have a static texture, or if we have
103 // a live layer of an unexpected width, move the texture in by the 106 // a live layer of an unexpected width, move the texture in by the
104 // appropriate amount. 107 // appropriate amount.
105 x += content_viewport_offset.x(); 108 x += content_viewport_offset.x();
106 y += content_viewport_offset.y(); 109 y += content_viewport_offset.y();
107 } 110 }
108 111
109 content_layer_->layer()->SetPosition(gfx::PointF(x, y)); 112 content_layer_->layer()->SetPosition(gfx::PointF(x, y));
110 content_layer_->layer()->SetIsDrawable(true); 113 content_layer_->layer()->SetIsDrawable(true);
111 114
112 layer_->AddChild(content_layer_->layer());
113
114 // Only applies the brightness filter if the value has changed and is less 115 // Only applies the brightness filter if the value has changed and is less
115 // than 1. 116 // than 1.
116 if (brightness != brightness_) { 117 if (brightness != brightness_) {
117 brightness_ = brightness; 118 brightness_ = brightness;
118 cc::FilterOperations filters; 119 cc::FilterOperations filters;
119 if (brightness_ < 1.f) 120 if (brightness_ < 1.f)
120 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_)); 121 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_));
121 layer_->SetFilters(filters); 122 layer_->SetFilters(filters);
122 } 123 }
123 } 124 }
124 125
125 void StaticTabSceneLayer::SetContentSceneLayer( 126 void StaticTabSceneLayer::UpdateToolbarLayer(
126 JNIEnv* env, 127 JNIEnv* env,
127 const JavaParamRef<jobject>& jobj, 128 const JavaParamRef<jobject>& object,
128 const JavaParamRef<jobject>& jcontent_scene_layer) { 129 const JavaParamRef<jobject>& jresource_manager,
129 SceneLayer* content_scene_layer = FromJavaObject(env, jcontent_scene_layer); 130 jint toolbar_resource_id,
130 scoped_refptr<cc::Layer> layer = content_scene_layer ? 131 jint toolbar_background_color,
131 content_scene_layer->layer() : nullptr; 132 jint url_bar_resource_id,
132 133 jfloat url_bar_alpha,
133 if (content_scene_layer_ && content_scene_layer_ != layer) { 134 jfloat top_offset,
134 content_scene_layer_->RemoveFromParent(); 135 bool visible,
135 content_scene_layer_ = nullptr; 136 bool show_shadow) {
137 // If the toolbar layer has not been created yet, create it.
138 if (!toolbar_layer_) {
139 ui::ResourceManager* resource_manager =
140 ui::ResourceManagerImpl::FromJavaObject(jresource_manager);
141 toolbar_layer_ = ToolbarLayer::Create(resource_manager);
142 toolbar_layer_->layer()->SetHideLayerAndSubtree(true);
143 layer_->AddChild(toolbar_layer_->layer());
136 } 144 }
137 145
138 // TODO(pedrosimonetti): Consider being smarter with regards to when to 146 toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible);
139 // add the layer to the hierarchy. For now, we need to keep adding the 147 if (visible) {
140 // content_scene_layer on every frame because the content_layer is also 148 toolbar_layer_->layer()->SetPosition(gfx::PointF(0, top_offset));
141 // added on every frame. This means that if we only add it once, the 149 // If we're at rest, hide the shadow. The Android view should be drawing.
142 // content_layer will be added again on the next frame and will 150 bool clip_shadow = top_offset >= 0.f && !show_shadow;
143 // occlude the content_scene_layer. 151 toolbar_layer_->PushResource(toolbar_resource_id, toolbar_background_color,
144 if (layer) { 152 false, SK_ColorWHITE, url_bar_resource_id,
145 content_scene_layer_ = layer; 153 url_bar_alpha, false, clip_shadow);
146 layer_->AddChild(layer);
147 } 154 }
148 } 155 }
149 156
157 void StaticTabSceneLayer::UpdateProgressBar(JNIEnv* env,
158 const JavaParamRef<jobject>& object,
159 jint progress_bar_x,
160 jint progress_bar_y,
161 jint progress_bar_width,
162 jint progress_bar_height,
163 jint progress_bar_color,
164 jint progress_bar_background_x,
165 jint progress_bar_background_y,
166 jint progress_bar_background_width,
167 jint progress_bar_background_height,
168 jint progress_bar_background_color) {
169 if (!toolbar_layer_) return;
170 toolbar_layer_->UpdateProgressBar(progress_bar_x,
171 progress_bar_y,
172 progress_bar_width,
173 progress_bar_height,
174 progress_bar_color,
175 progress_bar_background_x,
176 progress_bar_background_y,
177 progress_bar_background_width,
178 progress_bar_background_height,
179 progress_bar_background_color);
180 }
181
150 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { 182 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
151 // This will automatically bind to the Java object and pass ownership there. 183 // This will automatically bind to the Java object and pass ownership there.
152 StaticTabSceneLayer* scene_layer = new StaticTabSceneLayer(env, jobj); 184 StaticTabSceneLayer* scene_layer = new StaticTabSceneLayer(env, jobj);
153 return reinterpret_cast<intptr_t>(scene_layer); 185 return reinterpret_cast<intptr_t>(scene_layer);
154 } 186 }
155 187
156 bool RegisterStaticTabSceneLayer(JNIEnv* env) { 188 bool RegisterStaticTabSceneLayer(JNIEnv* env) {
157 return RegisterNativesImpl(env); 189 return RegisterNativesImpl(env);
158 } 190 }
159 191
160 } // namespace android 192 } // namespace android
161 } // namespace chrome 193 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698