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

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 82553015: Switch the android overscroll glow to use UIResources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor naming changes Created 7 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/compositor_impl_android.h" 5 #include "content/browser/renderer_host/compositor_impl_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 #include <map> 9 #include <map>
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return jsurface; 131 return jsurface;
132 } 132 }
133 133
134 CompositorImpl::CompositorImpl(CompositorClient* client, 134 CompositorImpl::CompositorImpl(CompositorClient* client,
135 gfx::NativeWindow root_window) 135 gfx::NativeWindow root_window)
136 : root_layer_(cc::Layer::Create()), 136 : root_layer_(cc::Layer::Create()),
137 has_transparent_background_(false), 137 has_transparent_background_(false),
138 window_(NULL), 138 window_(NULL),
139 surface_id_(0), 139 surface_id_(0),
140 client_(client), 140 client_(client),
141 root_window_(root_window) { 141 root_window_(root_window),
142 overscroll_edge_id_(0),
143 overscroll_glow_id_(0) {
142 DCHECK(client); 144 DCHECK(client);
143 DCHECK(root_window); 145 DCHECK(root_window);
144 ImageTransportFactoryAndroid::AddObserver(this); 146 ImageTransportFactoryAndroid::AddObserver(this);
147 LoadOverscrollResources();
no sievers 2013/11/26 20:10:17 I feel like all this is some very specific functio
powei 2013/11/26 22:17:41 Placing it outside of the compositor sounds good t
145 root_window->AttachCompositor(); 148 root_window->AttachCompositor();
146 } 149 }
147 150
148 CompositorImpl::~CompositorImpl() { 151 CompositorImpl::~CompositorImpl() {
149 root_window_->DetachCompositor(); 152 root_window_->DetachCompositor();
150 ImageTransportFactoryAndroid::RemoveObserver(this); 153 ImageTransportFactoryAndroid::RemoveObserver(this);
151 // Clean-up any surface references. 154 // Clean-up any surface references.
152 SetSurface(NULL); 155 SetSurface(NULL);
153 } 156 }
154 157
158 void CompositorImpl::LoadOverscrollResources() {
159 TRACE_EVENT0("compositor", "CompositorImpl::LoadOverscrollResources");
jdduke (slow) 2013/11/26 01:39:54 We did some optimizations to improve overscroll re
powei 2013/11/26 22:17:41 Good idea. I'll give asynchronous load a try.
160 SkBitmap edge_skbitmap = gfx::CreateSkBitmapFromResource(
161 "android:drawable/overscroll_edge", gfx::Size(128, 12));
162 edge_skbitmap.setImmutable();
163 overscroll_edge_bitmap_.reset(new cc::UIResourceBitmap(edge_skbitmap));
164
165 SkBitmap glow_skbitmap = gfx::CreateSkBitmapFromResource(
166 "android:drawable/overscroll_glow", gfx::Size(128, 64));
167 glow_skbitmap.setImmutable();
168 overscroll_glow_bitmap_.reset(new cc::UIResourceBitmap(glow_skbitmap));
169 }
170
155 void CompositorImpl::Composite() { 171 void CompositorImpl::Composite() {
156 if (host_) 172 if (host_)
157 host_->Composite(gfx::FrameTime::Now()); 173 host_->Composite(gfx::FrameTime::Now());
158 } 174 }
159 175
160 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { 176 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) {
161 root_layer_->RemoveAllChildren(); 177 root_layer_->RemoveAllChildren();
162 root_layer_->AddChild(root_layer); 178 root_layer_->AddChild(root_layer);
163 } 179 }
164 180
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); 225 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface));
210 } 226 }
211 } 227 }
212 } 228 }
213 229
214 void CompositorImpl::SetVisible(bool visible) { 230 void CompositorImpl::SetVisible(bool visible) {
215 if (!visible) { 231 if (!visible) {
216 ui_resource_map_.clear(); 232 ui_resource_map_.clear();
217 host_.reset(); 233 host_.reset();
218 client_->UIResourcesAreInvalid(); 234 client_->UIResourcesAreInvalid();
235 overscroll_edge_id_ = 0;
236 overscroll_glow_id_ = 0;
219 } else if (!host_) { 237 } else if (!host_) {
220 cc::LayerTreeSettings settings; 238 cc::LayerTreeSettings settings;
221 settings.refresh_rate = 60.0; 239 settings.refresh_rate = 60.0;
222 settings.impl_side_painting = false; 240 settings.impl_side_painting = false;
223 settings.allow_antialiasing = false; 241 settings.allow_antialiasing = false;
224 settings.calculate_top_controls_position = false; 242 settings.calculate_top_controls_position = false;
225 settings.top_controls_height = 0.f; 243 settings.top_controls_height = 0.f;
226 settings.use_memory_management = false; 244 settings.use_memory_management = false;
227 settings.highp_threshold_min = 2048; 245 settings.highp_threshold_min = 2048;
228 246
229 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); 247 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
230 host_->SetRootLayer(root_layer_); 248 host_->SetRootLayer(root_layer_);
231 249
232 host_->SetVisible(true); 250 host_->SetVisible(true);
233 host_->SetLayerTreeHostClientReady(); 251 host_->SetLayerTreeHostClientReady();
234 host_->SetViewportSize(size_); 252 host_->SetViewportSize(size_);
235 host_->set_has_transparent_background(has_transparent_background_); 253 host_->set_has_transparent_background(has_transparent_background_);
236 // Need to recreate the UI resources because a new LayerTreeHost has been 254 // Need to recreate the UI resources because a new LayerTreeHost has been
237 // created. 255 // created.
238 client_->DidLoseUIResources(); 256 client_->DidLoseUIResources();
257
258 overscroll_edge_id_ = GenerateUIResource(*overscroll_edge_bitmap_);
259 overscroll_glow_id_ = GenerateUIResource(*overscroll_glow_bitmap_);
239 } 260 }
240 } 261 }
241 262
242 void CompositorImpl::setDeviceScaleFactor(float factor) { 263 void CompositorImpl::setDeviceScaleFactor(float factor) {
243 if (host_) 264 if (host_)
244 host_->SetDeviceScaleFactor(factor); 265 host_->SetDeviceScaleFactor(factor);
245 } 266 }
246 267
247 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { 268 void CompositorImpl::SetWindowBounds(const gfx::Size& size) {
248 if (size_ == size) 269 if (size_ == size)
(...skipping 22 matching lines...) Expand all
271 ui_resource_map_.set(id, ui_resource.Pass()); 292 ui_resource_map_.set(id, ui_resource.Pass());
272 return id; 293 return id;
273 } 294 }
274 295
275 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { 296 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) {
276 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); 297 UIResourceMap::iterator it = ui_resource_map_.find(resource_id);
277 if (it != ui_resource_map_.end()) 298 if (it != ui_resource_map_.end())
278 ui_resource_map_.erase(it); 299 ui_resource_map_.erase(it);
279 } 300 }
280 301
302 gfx::Size CompositorImpl::GetUIResourceSize(cc::UIResourceId resource_id)
303 const {
304 DCHECK(resource_id);
305 if (!host_)
306 return gfx::Size();
307 return host_->GetUIResourceSize(resource_id);
308 }
309
281 blink::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { 310 blink::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) {
282 unsigned int texture_id = BuildBasicTexture(); 311 unsigned int texture_id = BuildBasicTexture();
283 blink::WebGraphicsContext3D* context = 312 blink::WebGraphicsContext3D* context =
284 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); 313 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
285 if (texture_id == 0 || context->isContextLost() || 314 if (texture_id == 0 || context->isContextLost() ||
286 !context->makeContextCurrent()) 315 !context->makeContextCurrent())
287 return 0; 316 return 0;
288 blink::WebGLId format = GetGLFormatForBitmap(bitmap); 317 blink::WebGLId format = GetGLFormatForBitmap(bitmap);
289 blink::WebGLId type = GetGLTypeForBitmap(bitmap); 318 blink::WebGLId type = GetGLTypeForBitmap(bitmap);
290 319
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 case ANDROID_BITMAP_FORMAT_RGBA_8888: 515 case ANDROID_BITMAP_FORMAT_RGBA_8888:
487 return GL_UNSIGNED_BYTE; 516 return GL_UNSIGNED_BYTE;
488 break; 517 break;
489 case ANDROID_BITMAP_FORMAT_RGB_565: 518 case ANDROID_BITMAP_FORMAT_RGB_565:
490 default: 519 default:
491 return GL_UNSIGNED_SHORT_5_6_5; 520 return GL_UNSIGNED_SHORT_5_6_5;
492 } 521 }
493 } 522 }
494 523
495 void CompositorImpl::DidCommit() { 524 void CompositorImpl::DidCommit() {
496 root_window_->OnCompositingDidCommit(); 525 root_window_->OnCompositingDidCommit(this);
497 } 526 }
498 527
499 } // namespace content 528 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698