| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 base::MessageLoop::current()->PostDelayedTask( | 294 base::MessageLoop::current()->PostDelayedTask( |
| 295 FROM_HERE, current_composite_task_->callback(), delay); | 295 FROM_HERE, current_composite_task_->callback(), delay); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void CompositorImpl::Composite(CompositingTrigger trigger) { | 298 void CompositorImpl::Composite(CompositingTrigger trigger) { |
| 299 BrowserGpuChannelHostFactory* factory = | 299 BrowserGpuChannelHostFactory* factory = |
| 300 BrowserGpuChannelHostFactory::instance(); | 300 BrowserGpuChannelHostFactory::instance(); |
| 301 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { | 301 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { |
| 302 CauseForGpuLaunch cause = | 302 CauseForGpuLaunch cause = |
| 303 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 303 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 304 factory->EstablishGpuChannel(cause, | 304 factory->EstablishGpuChannel( |
| 305 base::Bind(&CompositorImpl::ScheduleComposite, | 305 cause, |
| 306 weak_factory_.GetWeakPtr())); | 306 base::Bind(&CompositorImpl::OnGpuChannelEstablished, |
| 307 weak_factory_.GetWeakPtr())); |
| 307 return; | 308 return; |
| 308 } | 309 } |
| 309 | 310 |
| 310 DCHECK(host_); | 311 DCHECK(host_); |
| 311 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | 312 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); |
| 312 DCHECK(needs_composite_); | 313 DCHECK(needs_composite_); |
| 313 DCHECK(!DidCompositeThisFrame()); | 314 DCHECK(!DidCompositeThisFrame()); |
| 314 | 315 |
| 315 if (trigger == COMPOSITE_IMMEDIATELY) | 316 if (trigger == COMPOSITE_IMMEDIATELY) |
| 316 will_composite_immediately_ = false; | 317 will_composite_immediately_ = false; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 343 | 344 |
| 344 did_post_swapbuffers_ = false; | 345 did_post_swapbuffers_ = false; |
| 345 host_->Composite(frame_time); | 346 host_->Composite(frame_time); |
| 346 if (did_post_swapbuffers_) | 347 if (did_post_swapbuffers_) |
| 347 pending_swapbuffers_++; | 348 pending_swapbuffers_++; |
| 348 | 349 |
| 349 // Need to track vsync to avoid compositing more than once per frame. | 350 // Need to track vsync to avoid compositing more than once per frame. |
| 350 root_window_->RequestVSyncUpdate(); | 351 root_window_->RequestVSyncUpdate(); |
| 351 } | 352 } |
| 352 | 353 |
| 354 void CompositorImpl::OnGpuChannelEstablished() { |
| 355 ScheduleComposite(); |
| 356 } |
| 357 |
| 353 UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 358 UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
| 354 return ui_resource_provider_; | 359 return ui_resource_provider_; |
| 355 } | 360 } |
| 356 | 361 |
| 357 ui::SystemUIResourceManager& CompositorImpl::GetSystemUIResourceManager() { | 362 ui::SystemUIResourceManager& CompositorImpl::GetSystemUIResourceManager() { |
| 358 return ui_resource_provider_.GetSystemUIResourceManager(); | 363 return ui_resource_provider_.GetSystemUIResourceManager(); |
| 359 } | 364 } |
| 360 | 365 |
| 361 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 366 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
| 362 if (subroot_layer_) { | 367 if (subroot_layer_) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 limits, | 541 limits, |
| 537 NULL)); | 542 NULL)); |
| 538 } | 543 } |
| 539 | 544 |
| 540 void CompositorImpl::Layout() { | 545 void CompositorImpl::Layout() { |
| 541 ignore_schedule_composite_ = true; | 546 ignore_schedule_composite_ = true; |
| 542 client_->Layout(); | 547 client_->Layout(); |
| 543 ignore_schedule_composite_ = false; | 548 ignore_schedule_composite_ = false; |
| 544 } | 549 } |
| 545 | 550 |
| 546 void CompositorImpl::RequestNewOutputSurface(bool fallback) { | 551 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
| 547 BrowserGpuChannelHostFactory* factory = | 552 bool fallback) { |
| 548 BrowserGpuChannelHostFactory::instance(); | |
| 549 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { | |
| 550 CauseForGpuLaunch cause = | |
| 551 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | |
| 552 factory->EstablishGpuChannel( | |
| 553 cause, | |
| 554 base::Bind(&CompositorImpl::CreateOutputSurface, | |
| 555 weak_factory_.GetWeakPtr(), | |
| 556 fallback)); | |
| 557 return; | |
| 558 } | |
| 559 | |
| 560 CreateOutputSurface(fallback); | |
| 561 } | |
| 562 | |
| 563 void CompositorImpl::CreateOutputSurface(bool fallback) { | |
| 564 blink::WebGraphicsContext3D::Attributes attrs; | 553 blink::WebGraphicsContext3D::Attributes attrs; |
| 565 attrs.shareResources = true; | 554 attrs.shareResources = true; |
| 566 attrs.noAutomaticFlushes = true; | 555 attrs.noAutomaticFlushes = true; |
| 567 pending_swapbuffers_ = 0; | 556 pending_swapbuffers_ = 0; |
| 568 | 557 |
| 569 DCHECK(window_); | 558 DCHECK(window_); |
| 570 DCHECK(surface_id_); | 559 DCHECK(surface_id_); |
| 571 | 560 |
| 572 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 561 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 573 BrowserGpuChannelHostFactory* factory = | 562 BrowserGpuChannelHostFactory* factory = |
| 574 BrowserGpuChannelHostFactory::instance(); | 563 BrowserGpuChannelHostFactory::instance(); |
| 575 scoped_refptr<GpuChannelHost> gpu_channel_host = factory->GetGpuChannel(); | 564 scoped_refptr<GpuChannelHost> gpu_channel_host = factory->GetGpuChannel(); |
| 576 if (gpu_channel_host && !gpu_channel_host->IsLost()) { | 565 if (gpu_channel_host && !gpu_channel_host->IsLost()) { |
| 577 context_provider = ContextProviderCommandBuffer::Create( | 566 context_provider = ContextProviderCommandBuffer::Create( |
| 578 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), | 567 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), |
| 579 "BrowserCompositor"); | 568 "BrowserCompositor"); |
| 580 } | 569 } |
| 581 if (!context_provider.get()) { | 570 if (!context_provider.get()) { |
| 582 LOG(ERROR) << "Failed to create 3D context for compositor."; | 571 LOG(ERROR) << "Failed to create 3D context for compositor."; |
| 583 host_->SetOutputSurface(scoped_ptr<cc::OutputSurface>()); | 572 return scoped_ptr<cc::OutputSurface>(); |
| 584 return; | |
| 585 } | 573 } |
| 586 | 574 |
| 587 host_->SetOutputSurface( | 575 return scoped_ptr<cc::OutputSurface>(new OutputSurfaceWithoutParent( |
| 588 scoped_ptr<cc::OutputSurface>(new OutputSurfaceWithoutParent( | 576 context_provider, weak_factory_.GetWeakPtr())); |
| 589 context_provider, weak_factory_.GetWeakPtr()))); | |
| 590 } | 577 } |
| 591 | 578 |
| 592 void CompositorImpl::PopulateGpuCapabilities( | 579 void CompositorImpl::PopulateGpuCapabilities( |
| 593 gpu::Capabilities gpu_capabilities) { | 580 gpu::Capabilities gpu_capabilities) { |
| 594 ui_resource_provider_.SetSupportsETC1NonPowerOfTwo( | 581 ui_resource_provider_.SetSupportsETC1NonPowerOfTwo( |
| 595 gpu_capabilities.texture_format_etc1_npot); | 582 gpu_capabilities.texture_format_etc1_npot); |
| 596 } | 583 } |
| 597 | 584 |
| 598 void CompositorImpl::OnLostResources() { | 585 void CompositorImpl::OnLostResources() { |
| 599 client_->DidLoseResources(); | 586 client_->DidLoseResources(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 } | 669 } |
| 683 | 670 |
| 684 void CompositorImpl::SetNeedsAnimate() { | 671 void CompositorImpl::SetNeedsAnimate() { |
| 685 if (!host_) | 672 if (!host_) |
| 686 return; | 673 return; |
| 687 | 674 |
| 688 host_->SetNeedsAnimate(); | 675 host_->SetNeedsAnimate(); |
| 689 } | 676 } |
| 690 | 677 |
| 691 } // namespace content | 678 } // namespace content |
| OLD | NEW |