Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 base::MessageLoop::current()->PostDelayedTask( | 274 base::MessageLoop::current()->PostDelayedTask( |
| 275 FROM_HERE, current_composite_task_->callback(), delay); | 275 FROM_HERE, current_composite_task_->callback(), delay); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void CompositorImpl::Composite(CompositingTrigger trigger) { | 278 void CompositorImpl::Composite(CompositingTrigger trigger) { |
| 279 BrowserGpuChannelHostFactory* factory = | 279 BrowserGpuChannelHostFactory* factory = |
| 280 BrowserGpuChannelHostFactory::instance(); | 280 BrowserGpuChannelHostFactory::instance(); |
| 281 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { | 281 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { |
| 282 CauseForGpuLaunch cause = | 282 CauseForGpuLaunch cause = |
| 283 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 283 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 284 factory->EstablishGpuChannel( | 284 factory->EstablishGpuChannel(cause, |
| 285 cause, | 285 base::Bind(&CompositorImpl::ScheduleComposite, |
| 286 base::Bind(&CompositorImpl::OnGpuChannelEstablished, | 286 weak_factory_.GetWeakPtr())); |
| 287 weak_factory_.GetWeakPtr())); | |
| 288 return; | 287 return; |
| 289 } | 288 } |
| 290 | 289 |
| 291 DCHECK(host_); | 290 DCHECK(host_); |
| 292 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | 291 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); |
| 293 DCHECK(needs_composite_); | 292 DCHECK(needs_composite_); |
| 294 DCHECK(!DidCompositeThisFrame()); | 293 DCHECK(!DidCompositeThisFrame()); |
| 295 | 294 |
| 296 if (trigger == COMPOSITE_IMMEDIATELY) | 295 if (trigger == COMPOSITE_IMMEDIATELY) |
| 297 will_composite_immediately_ = false; | 296 will_composite_immediately_ = false; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 324 | 323 |
| 325 did_post_swapbuffers_ = false; | 324 did_post_swapbuffers_ = false; |
| 326 host_->Composite(frame_time); | 325 host_->Composite(frame_time); |
| 327 if (did_post_swapbuffers_) | 326 if (did_post_swapbuffers_) |
| 328 pending_swapbuffers_++; | 327 pending_swapbuffers_++; |
| 329 | 328 |
| 330 // Need to track vsync to avoid compositing more than once per frame. | 329 // Need to track vsync to avoid compositing more than once per frame. |
| 331 root_window_->RequestVSyncUpdate(); | 330 root_window_->RequestVSyncUpdate(); |
| 332 } | 331 } |
| 333 | 332 |
| 334 void CompositorImpl::OnGpuChannelEstablished() { | |
| 335 ScheduleComposite(); | |
| 336 } | |
| 337 | |
| 338 UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 333 UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
| 339 return ui_resource_provider_; | 334 return ui_resource_provider_; |
| 340 } | 335 } |
| 341 | 336 |
| 342 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 337 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
| 343 root_layer_->RemoveAllChildren(); | 338 root_layer_->RemoveAllChildren(); |
| 344 if (root_layer) | 339 if (root_layer) |
| 345 root_layer_->AddChild(root_layer); | 340 root_layer_->AddChild(root_layer); |
| 346 } | 341 } |
| 347 | 342 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 limits, | 488 limits, |
| 494 NULL)); | 489 NULL)); |
| 495 } | 490 } |
| 496 | 491 |
| 497 void CompositorImpl::Layout() { | 492 void CompositorImpl::Layout() { |
| 498 ignore_schedule_composite_ = true; | 493 ignore_schedule_composite_ = true; |
| 499 client_->Layout(); | 494 client_->Layout(); |
| 500 ignore_schedule_composite_ = false; | 495 ignore_schedule_composite_ = false; |
| 501 } | 496 } |
| 502 | 497 |
| 503 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 498 void CompositorImpl::RequestNewOutputSurface(bool fallback) { |
| 504 bool fallback) { | 499 BrowserGpuChannelHostFactory* factory = |
| 500 BrowserGpuChannelHostFactory::instance(); | |
| 501 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { | |
| 502 CauseForGpuLaunch cause = | |
| 503 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | |
| 504 factory->EstablishGpuChannel( | |
| 505 cause, | |
| 506 base::Bind(&CompositorImpl::CreateOutputSurface, | |
| 507 weak_factory_.GetWeakPtr(), | |
| 508 fallback)); | |
| 509 return; | |
| 510 } | |
| 511 | |
| 512 CreateOutputSurface(fallback); | |
| 513 } | |
| 514 | |
| 515 void CompositorImpl::CreateOutputSurface(bool fallback) { | |
| 505 blink::WebGraphicsContext3D::Attributes attrs; | 516 blink::WebGraphicsContext3D::Attributes attrs; |
| 506 attrs.shareResources = true; | 517 attrs.shareResources = true; |
| 507 attrs.noAutomaticFlushes = true; | 518 attrs.noAutomaticFlushes = true; |
| 508 pending_swapbuffers_ = 0; | 519 pending_swapbuffers_ = 0; |
| 509 | 520 |
| 510 DCHECK(window_); | 521 DCHECK(window_); |
| 511 DCHECK(surface_id_); | 522 DCHECK(surface_id_); |
| 512 | 523 |
| 513 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 524 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 514 BrowserGpuChannelHostFactory* factory = | 525 BrowserGpuChannelHostFactory* factory = |
| 515 BrowserGpuChannelHostFactory::instance(); | 526 BrowserGpuChannelHostFactory::instance(); |
| 516 scoped_refptr<GpuChannelHost> gpu_channel_host = factory->GetGpuChannel(); | 527 scoped_refptr<GpuChannelHost> gpu_channel_host = factory->GetGpuChannel(); |
| 517 if (gpu_channel_host && !gpu_channel_host->IsLost()) { | 528 if (gpu_channel_host && !gpu_channel_host->IsLost()) { |
| 518 context_provider = ContextProviderCommandBuffer::Create( | 529 context_provider = ContextProviderCommandBuffer::Create( |
| 519 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), | 530 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), |
| 520 "BrowserCompositor"); | 531 "BrowserCompositor"); |
| 521 } | 532 } |
| 522 if (!context_provider.get()) { | 533 if (!context_provider.get()) { |
| 523 LOG(ERROR) << "Failed to create 3D context for compositor."; | 534 LOG(ERROR) << "Failed to create 3D context for compositor."; |
| 524 return scoped_ptr<cc::OutputSurface>(); | 535 host_->SetOutputSurface(scoped_ptr<cc::OutputSurface>()); |
|
no sievers
2014/06/23 19:53:58
either return here or if-else
enne (OOO)
2014/06/24 22:20:06
Oops! Good catch. Done.
| |
| 525 } | 536 } |
| 526 | 537 |
| 527 return scoped_ptr<cc::OutputSurface>( | 538 host_->SetOutputSurface(scoped_ptr<cc::OutputSurface>( |
| 528 new OutputSurfaceWithoutParent(context_provider)); | 539 new OutputSurfaceWithoutParent(context_provider))); |
| 529 } | 540 } |
| 530 | 541 |
| 531 void CompositorImpl::OnLostResources() { | 542 void CompositorImpl::OnLostResources() { |
| 532 client_->DidLoseResources(); | 543 client_->DidLoseResources(); |
| 533 ui_resource_provider_.UIResourcesAreInvalid(); | 544 ui_resource_provider_.UIResourcesAreInvalid(); |
| 534 } | 545 } |
| 535 | 546 |
| 536 void CompositorImpl::ScheduleComposite() { | 547 void CompositorImpl::ScheduleComposite() { |
| 537 DCHECK(!needs_composite_ || WillComposite()); | 548 DCHECK(!needs_composite_ || WillComposite()); |
| 538 if (ignore_schedule_composite_) | 549 if (ignore_schedule_composite_) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 } | 627 } |
| 617 | 628 |
| 618 void CompositorImpl::SetNeedsAnimate() { | 629 void CompositorImpl::SetNeedsAnimate() { |
| 619 if (!host_) | 630 if (!host_) |
| 620 return; | 631 return; |
| 621 | 632 |
| 622 host_->SetNeedsAnimate(); | 633 host_->SetNeedsAnimate(); |
| 623 } | 634 } |
| 624 | 635 |
| 625 } // namespace content | 636 } // namespace content |
| OLD | NEW |