| 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 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 316 |
| 317 // static | 317 // static |
| 318 bool CompositorImpl::IsInitialized() { | 318 bool CompositorImpl::IsInitialized() { |
| 319 return g_initialized; | 319 return g_initialized; |
| 320 } | 320 } |
| 321 | 321 |
| 322 CompositorImpl::CompositorImpl(CompositorClient* client, | 322 CompositorImpl::CompositorImpl(CompositorClient* client, |
| 323 gfx::NativeWindow root_window) | 323 gfx::NativeWindow root_window) |
| 324 : frame_sink_id_( | 324 : frame_sink_id_( |
| 325 ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()), | 325 ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()), |
| 326 root_layer_(cc::Layer::Create()), |
| 326 resource_manager_(root_window), | 327 resource_manager_(root_window), |
| 327 device_scale_factor_(1), | 328 device_scale_factor_(1), |
| 328 window_(NULL), | 329 window_(NULL), |
| 329 surface_handle_(gpu::kNullSurfaceHandle), | 330 surface_handle_(gpu::kNullSurfaceHandle), |
| 330 client_(client), | 331 client_(client), |
| 331 root_window_(root_window), | 332 root_window_(root_window), |
| 332 needs_animate_(false), | 333 needs_animate_(false), |
| 333 pending_swapbuffers_(0U), | 334 pending_swapbuffers_(0U), |
| 334 num_successive_context_creation_failures_(0), | 335 num_successive_context_creation_failures_(0), |
| 335 compositor_frame_sink_request_pending_(false), | 336 compositor_frame_sink_request_pending_(false), |
| 336 weak_factory_(this) { | 337 weak_factory_(this) { |
| 337 ui::ContextProviderFactory::GetInstance() | 338 ui::ContextProviderFactory::GetInstance() |
| 338 ->GetSurfaceManager() | 339 ->GetSurfaceManager() |
| 339 ->RegisterFrameSinkId(frame_sink_id_); | 340 ->RegisterFrameSinkId(frame_sink_id_); |
| 340 DCHECK(client); | 341 DCHECK(client); |
| 341 DCHECK(root_window); | 342 DCHECK(root_window); |
| 342 DCHECK(root_window->GetLayer() == nullptr); | |
| 343 root_window->SetLayer(cc::Layer::Create()); | |
| 344 readback_layer_tree_ = cc::Layer::Create(); | 343 readback_layer_tree_ = cc::Layer::Create(); |
| 345 readback_layer_tree_->SetHideLayerAndSubtree(true); | 344 readback_layer_tree_->SetHideLayerAndSubtree(true); |
| 346 root_window->GetLayer()->AddChild(readback_layer_tree_); | 345 root_layer_->AddChild(readback_layer_tree_); |
| 347 root_window->AttachCompositor(this); | 346 root_window->AttachCompositor(this); |
| 348 CreateLayerTreeHost(); | 347 CreateLayerTreeHost(); |
| 349 resource_manager_.Init(host_->GetUIResourceManager()); | 348 resource_manager_.Init(host_->GetUIResourceManager()); |
| 350 } | 349 } |
| 351 | 350 |
| 352 CompositorImpl::~CompositorImpl() { | 351 CompositorImpl::~CompositorImpl() { |
| 353 root_window_->DetachCompositor(); | 352 root_window_->DetachCompositor(); |
| 354 root_window_->SetLayer(nullptr); | |
| 355 // Clean-up any surface references. | 353 // Clean-up any surface references. |
| 356 SetSurface(NULL); | 354 SetSurface(NULL); |
| 357 ui::ContextProviderFactory::GetInstance() | 355 ui::ContextProviderFactory::GetInstance() |
| 358 ->GetSurfaceManager() | 356 ->GetSurfaceManager() |
| 359 ->InvalidateFrameSinkId(frame_sink_id_); | 357 ->InvalidateFrameSinkId(frame_sink_id_); |
| 360 } | 358 } |
| 361 | 359 |
| 362 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 360 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
| 363 return *this; | 361 return *this; |
| 364 } | 362 } |
| 365 | 363 |
| 366 ui::ResourceManager& CompositorImpl::GetResourceManager() { | 364 ui::ResourceManager& CompositorImpl::GetResourceManager() { |
| 367 return resource_manager_; | 365 return resource_manager_; |
| 368 } | 366 } |
| 369 | 367 |
| 370 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 368 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
| 371 if (subroot_layer_.get()) { | 369 if (subroot_layer_.get()) { |
| 372 subroot_layer_->RemoveFromParent(); | 370 subroot_layer_->RemoveFromParent(); |
| 373 subroot_layer_ = NULL; | 371 subroot_layer_ = NULL; |
| 374 } | 372 } |
| 375 if (root_window_->GetLayer()) { | 373 if (root_layer.get()) { |
| 376 subroot_layer_ = root_window_->GetLayer(); | 374 subroot_layer_ = root_layer; |
| 377 root_window_->GetLayer()->AddChild(root_layer); | 375 root_layer_->AddChild(root_layer); |
| 378 } | 376 } |
| 379 } | 377 } |
| 380 | 378 |
| 381 void CompositorImpl::SetSurface(jobject surface) { | 379 void CompositorImpl::SetSurface(jobject surface) { |
| 382 JNIEnv* env = base::android::AttachCurrentThread(); | 380 JNIEnv* env = base::android::AttachCurrentThread(); |
| 383 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); | 381 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); |
| 384 | 382 |
| 385 if (window_) { | 383 if (window_) { |
| 386 // Shut down GL context before unregistering surface. | 384 // Shut down GL context before unregistering surface. |
| 387 SetVisible(false); | 385 SetVisible(false); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 animation_host_ = cc::AnimationHost::CreateMainInstance(); | 430 animation_host_ = cc::AnimationHost::CreateMainInstance(); |
| 433 | 431 |
| 434 cc::LayerTreeHostInProcess::InitParams params; | 432 cc::LayerTreeHostInProcess::InitParams params; |
| 435 params.client = this; | 433 params.client = this; |
| 436 params.task_graph_runner = g_task_graph_runner.Pointer(); | 434 params.task_graph_runner = g_task_graph_runner.Pointer(); |
| 437 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 435 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 438 params.settings = &settings; | 436 params.settings = &settings; |
| 439 params.mutator_host = animation_host_.get(); | 437 params.mutator_host = animation_host_.get(); |
| 440 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); | 438 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); |
| 441 DCHECK(!host_->IsVisible()); | 439 DCHECK(!host_->IsVisible()); |
| 442 host_->GetLayerTree()->SetRootLayer(root_window_->GetLayer()); | 440 host_->GetLayerTree()->SetRootLayer(root_layer_); |
| 443 host_->SetFrameSinkId(frame_sink_id_); | 441 host_->SetFrameSinkId(frame_sink_id_); |
| 444 host_->GetLayerTree()->SetViewportSize(size_); | 442 host_->GetLayerTree()->SetViewportSize(size_); |
| 445 SetHasTransparentBackground(false); | 443 SetHasTransparentBackground(false); |
| 446 host_->GetLayerTree()->SetDeviceScaleFactor(device_scale_factor_); | 444 host_->GetLayerTree()->SetDeviceScaleFactor(device_scale_factor_); |
| 447 | 445 |
| 448 if (needs_animate_) | 446 if (needs_animate_) |
| 449 host_->SetNeedsAnimate(); | 447 host_->SetNeedsAnimate(); |
| 450 } | 448 } |
| 451 | 449 |
| 452 void CompositorImpl::SetVisible(bool visible) { | 450 void CompositorImpl::SetVisible(bool visible) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 479 | 477 |
| 480 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 478 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
| 481 if (size_ == size) | 479 if (size_ == size) |
| 482 return; | 480 return; |
| 483 | 481 |
| 484 size_ = size; | 482 size_ = size; |
| 485 if (host_) | 483 if (host_) |
| 486 host_->GetLayerTree()->SetViewportSize(size); | 484 host_->GetLayerTree()->SetViewportSize(size); |
| 487 if (display_) | 485 if (display_) |
| 488 display_->Resize(size); | 486 display_->Resize(size); |
| 489 root_window_->GetLayer()->SetBounds(size); | 487 root_layer_->SetBounds(size); |
| 490 } | 488 } |
| 491 | 489 |
| 492 void CompositorImpl::SetHasTransparentBackground(bool transparent) { | 490 void CompositorImpl::SetHasTransparentBackground(bool transparent) { |
| 493 has_transparent_background_ = transparent; | 491 has_transparent_background_ = transparent; |
| 494 if (host_) { | 492 if (host_) { |
| 495 host_->GetLayerTree()->set_has_transparent_background(transparent); | 493 host_->GetLayerTree()->set_has_transparent_background(transparent); |
| 496 | 494 |
| 497 // Give a delay in setting the background color to avoid the color for | 495 // Give a delay in setting the background color to avoid the color for |
| 498 // the normal mode (white) affecting the UI transition. | 496 // the normal mode (white) affecting the UI transition. |
| 499 base::ThreadTaskRunnerHandle::Get().get()->PostDelayedTask( | 497 base::ThreadTaskRunnerHandle::Get().get()->PostDelayedTask( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 void CompositorImpl::DidCommit() { | 711 void CompositorImpl::DidCommit() { |
| 714 root_window_->OnCompositingDidCommit(); | 712 root_window_->OnCompositingDidCommit(); |
| 715 } | 713 } |
| 716 | 714 |
| 717 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 715 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
| 718 readback_layer_tree_->AddChild(layer); | 716 readback_layer_tree_->AddChild(layer); |
| 719 } | 717 } |
| 720 | 718 |
| 721 void CompositorImpl::RequestCopyOfOutputOnRootLayer( | 719 void CompositorImpl::RequestCopyOfOutputOnRootLayer( |
| 722 std::unique_ptr<cc::CopyOutputRequest> request) { | 720 std::unique_ptr<cc::CopyOutputRequest> request) { |
| 723 root_window_->GetLayer()->RequestCopyOfOutput(std::move(request)); | 721 root_layer_->RequestCopyOfOutput(std::move(request)); |
| 724 } | 722 } |
| 725 | 723 |
| 726 void CompositorImpl::SetNeedsAnimate() { | 724 void CompositorImpl::SetNeedsAnimate() { |
| 727 needs_animate_ = true; | 725 needs_animate_ = true; |
| 728 if (!host_->IsVisible()) | 726 if (!host_->IsVisible()) |
| 729 return; | 727 return; |
| 730 | 728 |
| 731 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 729 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 732 host_->SetNeedsAnimate(); | 730 host_->SetNeedsAnimate(); |
| 733 } | 731 } |
| 734 | 732 |
| 735 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { | 733 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { |
| 736 return frame_sink_id_; | 734 return frame_sink_id_; |
| 737 } | 735 } |
| 738 | 736 |
| 739 bool CompositorImpl::HavePendingReadbacks() { | 737 bool CompositorImpl::HavePendingReadbacks() { |
| 740 return !readback_layer_tree_->children().empty(); | 738 return !readback_layer_tree_->children().empty(); |
| 741 } | 739 } |
| 742 | 740 |
| 743 } // namespace content | 741 } // namespace content |
| OLD | NEW |