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

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

Issue 228663008: Android: Avoid blocking UI thread for GPU channel creation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/compositor_impl_android.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 (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 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 232
233 CompositorImpl::CompositorImpl(CompositorClient* client, 233 CompositorImpl::CompositorImpl(CompositorClient* client,
234 gfx::NativeWindow root_window) 234 gfx::NativeWindow root_window)
235 : root_layer_(cc::Layer::Create()), 235 : root_layer_(cc::Layer::Create()),
236 has_transparent_background_(false), 236 has_transparent_background_(false),
237 device_scale_factor_(1), 237 device_scale_factor_(1),
238 window_(NULL), 238 window_(NULL),
239 surface_id_(0), 239 surface_id_(0),
240 client_(client), 240 client_(client),
241 root_window_(root_window) { 241 root_window_(root_window),
242 weak_factory_(this) {
242 DCHECK(client); 243 DCHECK(client);
243 DCHECK(root_window); 244 DCHECK(root_window);
244 ImageTransportFactoryAndroid::AddObserver(this); 245 ImageTransportFactoryAndroid::AddObserver(this);
245 root_window->AttachCompositor(this); 246 root_window->AttachCompositor(this);
246 } 247 }
247 248
248 CompositorImpl::~CompositorImpl() { 249 CompositorImpl::~CompositorImpl() {
249 root_window_->DetachCompositor(); 250 root_window_->DetachCompositor();
250 ImageTransportFactoryAndroid::RemoveObserver(this); 251 ImageTransportFactoryAndroid::RemoveObserver(this);
251 // Clean-up any surface references. 252 // Clean-up any surface references.
252 SetSurface(NULL); 253 SetSurface(NULL);
253 } 254 }
254 255
255 void CompositorImpl::Composite() { 256 void CompositorImpl::Composite() {
257 BrowserGpuChannelHostFactory* factory =
258 BrowserGpuChannelHostFactory::instance();
259 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) {
danakj 2014/04/14 13:14:46 Is the assumption that SingleThread compositor won
no sievers 2014/04/14 18:50:45 Yes, I changed it in r241897 to guarantee that beh
danakj 2014/04/14 19:30:01 With STP Scheduler, this method goes away entirely
no sievers 2014/04/14 19:40:34 Hmm, would I have to SetDeferCommits() also to mak
danakj 2014/04/14 20:29:35 Ya, I think you would to prevent races where the G
260 CauseForGpuLaunch cause =
261 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
262 factory->EstablishGpuChannel(
263 cause,
264 base::Bind(&CompositorImpl::OnGpuChannelEstablished,
265 weak_factory_.GetWeakPtr()));
266 return;
267 }
268
256 if (host_) 269 if (host_)
257 host_->Composite(gfx::FrameTime::Now()); 270 host_->Composite(gfx::FrameTime::Now());
258 } 271 }
259 272
273 void CompositorImpl::OnGpuChannelEstablished() {
274 ScheduleComposite();
275 }
276
260 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { 277 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) {
261 root_layer_->RemoveAllChildren(); 278 root_layer_->RemoveAllChildren();
262 root_layer_->AddChild(root_layer); 279 root_layer_->AddChild(root_layer);
263 } 280 }
264 281
265 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { 282 void CompositorImpl::SetWindowSurface(ANativeWindow* window) {
266 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); 283 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
267 284
268 if (window_) { 285 if (window_) {
269 tracker->RemoveSurface(surface_id_); 286 tracker->RemoveSurface(surface_id_);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 439 }
423 440
424 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { 441 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) {
425 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); 442 UIResourceMap::iterator it = ui_resource_map_.find(resource_id);
426 if (it != ui_resource_map_.end()) 443 if (it != ui_resource_map_.end())
427 ui_resource_map_.erase(it); 444 ui_resource_map_.erase(it);
428 } 445 }
429 446
430 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 447 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
431 CreateGpuProcessViewContext( 448 CreateGpuProcessViewContext(
449 const scoped_refptr<GpuChannelHost>& gpu_channel_host,
432 const blink::WebGraphicsContext3D::Attributes attributes, 450 const blink::WebGraphicsContext3D::Attributes attributes,
433 int surface_id) { 451 int surface_id) {
434 BrowserGpuChannelHostFactory* factory = 452 DCHECK(gpu_channel_host);
435 BrowserGpuChannelHostFactory::instance();
436 CauseForGpuLaunch cause =
437 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
438 scoped_refptr<GpuChannelHost> gpu_channel_host(
439 factory->EstablishGpuChannelSync(cause));
440 if (!gpu_channel_host)
441 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
442 453
443 GURL url("chrome://gpu/Compositor::createContext3D"); 454 GURL url("chrome://gpu/Compositor::createContext3D");
444 static const size_t kBytesPerPixel = 4; 455 static const size_t kBytesPerPixel = 4;
445 gfx::DeviceDisplayInfo display_info; 456 gfx::DeviceDisplayInfo display_info;
446 size_t full_screen_texture_size_in_bytes = 457 size_t full_screen_texture_size_in_bytes =
447 display_info.GetDisplayHeight() * 458 display_info.GetDisplayHeight() *
448 display_info.GetDisplayWidth() * 459 display_info.GetDisplayWidth() *
449 kBytesPerPixel; 460 kBytesPerPixel;
450 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; 461 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
451 limits.command_buffer_size = 64 * 1024; 462 limits.command_buffer_size = 64 * 1024;
(...skipping 15 matching lines...) Expand all
467 478
468 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( 479 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface(
469 bool fallback) { 480 bool fallback) {
470 blink::WebGraphicsContext3D::Attributes attrs; 481 blink::WebGraphicsContext3D::Attributes attrs;
471 attrs.shareResources = true; 482 attrs.shareResources = true;
472 attrs.noAutomaticFlushes = true; 483 attrs.noAutomaticFlushes = true;
473 484
474 DCHECK(window_); 485 DCHECK(window_);
475 DCHECK(surface_id_); 486 DCHECK(surface_id_);
476 487
477 scoped_refptr<ContextProviderCommandBuffer> context_provider = 488 scoped_refptr<ContextProviderCommandBuffer> context_provider;
478 ContextProviderCommandBuffer::Create( 489 BrowserGpuChannelHostFactory* factory =
479 CreateGpuProcessViewContext(attrs, surface_id_), "BrowserCompositor"); 490 BrowserGpuChannelHostFactory::instance();
491 scoped_refptr<GpuChannelHost> gpu_channel_host = factory->GetGpuChannel();
492 if (gpu_channel_host && !gpu_channel_host->IsLost()) {
danakj 2014/04/14 13:14:46 Say we were to remove the compositor retry-CreateO
no sievers 2014/04/14 18:50:45 Does it really change anything though from how it
danakj 2014/04/14 19:30:01 Ok, I think I want to make it so this method can n
493 context_provider = ContextProviderCommandBuffer::Create(
494 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_),
495 "BrowserCompositor");
496 }
480 if (!context_provider.get()) { 497 if (!context_provider.get()) {
481 LOG(ERROR) << "Failed to create 3D context for compositor."; 498 LOG(ERROR) << "Failed to create 3D context for compositor.";
482 return scoped_ptr<cc::OutputSurface>(); 499 return scoped_ptr<cc::OutputSurface>();
483 } 500 }
484 501
485 return scoped_ptr<cc::OutputSurface>( 502 return scoped_ptr<cc::OutputSurface>(
486 new OutputSurfaceWithoutParent(context_provider)); 503 new OutputSurfaceWithoutParent(context_provider));
487 } 504 }
488 505
489 void CompositorImpl::OnLostResources() { 506 void CompositorImpl::OnLostResources() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 539
523 void CompositorImpl::DidCommit() { 540 void CompositorImpl::DidCommit() {
524 root_window_->OnCompositingDidCommit(); 541 root_window_->OnCompositingDidCommit();
525 } 542 }
526 543
527 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { 544 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) {
528 root_layer_->AddChild(layer); 545 root_layer_->AddChild(layer);
529 } 546 }
530 547
531 } // namespace content 548 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/compositor_impl_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698