| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 g_shared_vulkan_context_provider_android_.Pointer(); | 356 g_shared_vulkan_context_provider_android_.Pointer(); |
| 357 if (!*context_provider) | 357 if (!*context_provider) |
| 358 *context_provider = cc::VulkanInProcessContextProvider::Create(); | 358 *context_provider = cc::VulkanInProcessContextProvider::Create(); |
| 359 return *context_provider; | 359 return *context_provider; |
| 360 } | 360 } |
| 361 return nullptr; | 361 return nullptr; |
| 362 } | 362 } |
| 363 | 363 |
| 364 CompositorImpl::CompositorImpl(CompositorClient* client, | 364 CompositorImpl::CompositorImpl(CompositorClient* client, |
| 365 gfx::NativeWindow root_window) | 365 gfx::NativeWindow root_window) |
| 366 : root_layer_(cc::Layer::Create()), | 366 : surface_id_allocator_(CreateSurfaceIdAllocator()), |
| 367 surface_id_allocator_(CreateSurfaceIdAllocator()), | |
| 368 resource_manager_(root_window), | 367 resource_manager_(root_window), |
| 369 has_transparent_background_(false), | 368 has_transparent_background_(false), |
| 370 device_scale_factor_(1), | 369 device_scale_factor_(1), |
| 371 window_(NULL), | 370 window_(NULL), |
| 372 surface_handle_(gpu::kNullSurfaceHandle), | 371 surface_handle_(gpu::kNullSurfaceHandle), |
| 373 client_(client), | 372 client_(client), |
| 374 root_window_(root_window), | 373 root_window_(root_window), |
| 375 needs_animate_(false), | 374 needs_animate_(false), |
| 376 pending_swapbuffers_(0U), | 375 pending_swapbuffers_(0U), |
| 377 num_successive_context_creation_failures_(0), | 376 num_successive_context_creation_failures_(0), |
| 378 output_surface_request_pending_(false), | 377 output_surface_request_pending_(false), |
| 379 needs_begin_frames_(false), | 378 needs_begin_frames_(false), |
| 380 weak_factory_(this) { | 379 weak_factory_(this) { |
| 381 DCHECK(client); | 380 DCHECK(client); |
| 382 DCHECK(root_window); | 381 DCHECK(root_window); |
| 382 DCHECK(root_window->GetLayer() == nullptr); |
| 383 root_window->SetLayer(cc::Layer::Create()); |
| 383 root_window->AttachCompositor(this); | 384 root_window->AttachCompositor(this); |
| 384 CreateLayerTreeHost(); | 385 CreateLayerTreeHost(); |
| 385 resource_manager_.Init(host_.get()); | 386 resource_manager_.Init(host_.get()); |
| 386 } | 387 } |
| 387 | 388 |
| 388 CompositorImpl::~CompositorImpl() { | 389 CompositorImpl::~CompositorImpl() { |
| 389 root_window_->DetachCompositor(); | 390 root_window_->DetachCompositor(); |
| 391 root_window_->SetLayer(nullptr); |
| 390 // Clean-up any surface references. | 392 // Clean-up any surface references. |
| 391 SetSurface(NULL); | 393 SetSurface(NULL); |
| 392 } | 394 } |
| 393 | 395 |
| 394 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 396 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
| 395 return *this; | 397 return *this; |
| 396 } | 398 } |
| 397 | 399 |
| 398 ui::ResourceManager& CompositorImpl::GetResourceManager() { | 400 ui::ResourceManager& CompositorImpl::GetResourceManager() { |
| 399 return resource_manager_; | 401 return resource_manager_; |
| 400 } | 402 } |
| 401 | 403 |
| 402 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 404 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
| 403 if (subroot_layer_.get()) { | 405 if (subroot_layer_.get()) { |
| 404 subroot_layer_->RemoveFromParent(); | 406 subroot_layer_->RemoveFromParent(); |
| 405 subroot_layer_ = NULL; | 407 subroot_layer_ = NULL; |
| 406 } | 408 } |
| 407 if (root_layer.get()) { | 409 if (root_window_->GetLayer()) { |
| 408 subroot_layer_ = root_layer; | 410 subroot_layer_ = root_window_->GetLayer(); |
| 409 root_layer_->AddChild(root_layer); | 411 root_window_->GetLayer()->AddChild(root_layer); |
| 410 } | 412 } |
| 411 } | 413 } |
| 412 | 414 |
| 413 void CompositorImpl::SetSurface(jobject surface) { | 415 void CompositorImpl::SetSurface(jobject surface) { |
| 414 JNIEnv* env = base::android::AttachCurrentThread(); | 416 JNIEnv* env = base::android::AttachCurrentThread(); |
| 415 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); | 417 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); |
| 416 | 418 |
| 417 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 419 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 418 | 420 |
| 419 if (window_) { | 421 if (window_) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 cc::LayerTreeHost::InitParams params; | 467 cc::LayerTreeHost::InitParams params; |
| 466 params.client = this; | 468 params.client = this; |
| 467 params.shared_bitmap_manager = HostSharedBitmapManager::current(); | 469 params.shared_bitmap_manager = HostSharedBitmapManager::current(); |
| 468 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); | 470 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); |
| 469 params.task_graph_runner = g_task_graph_runner.Pointer(); | 471 params.task_graph_runner = g_task_graph_runner.Pointer(); |
| 470 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 472 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 471 params.settings = &settings; | 473 params.settings = &settings; |
| 472 params.animation_host = cc::AnimationHost::CreateMainInstance(); | 474 params.animation_host = cc::AnimationHost::CreateMainInstance(); |
| 473 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 475 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
| 474 DCHECK(!host_->visible()); | 476 DCHECK(!host_->visible()); |
| 475 host_->SetRootLayer(root_layer_); | 477 host_->SetRootLayer(root_window_->GetLayer()); |
| 476 host_->set_surface_client_id(surface_id_allocator_->client_id()); | 478 host_->set_surface_client_id(surface_id_allocator_->client_id()); |
| 477 host_->SetViewportSize(size_); | 479 host_->SetViewportSize(size_); |
| 478 host_->set_has_transparent_background(has_transparent_background_); | 480 host_->set_has_transparent_background(has_transparent_background_); |
| 479 host_->SetDeviceScaleFactor(device_scale_factor_); | 481 host_->SetDeviceScaleFactor(device_scale_factor_); |
| 480 | 482 |
| 481 if (needs_animate_) | 483 if (needs_animate_) |
| 482 host_->SetNeedsAnimate(); | 484 host_->SetNeedsAnimate(); |
| 483 } | 485 } |
| 484 | 486 |
| 485 void CompositorImpl::SetVisible(bool visible) { | 487 void CompositorImpl::SetVisible(bool visible) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 507 | 509 |
| 508 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 510 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
| 509 if (size_ == size) | 511 if (size_ == size) |
| 510 return; | 512 return; |
| 511 | 513 |
| 512 size_ = size; | 514 size_ = size; |
| 513 if (host_) | 515 if (host_) |
| 514 host_->SetViewportSize(size); | 516 host_->SetViewportSize(size); |
| 515 if (display_) | 517 if (display_) |
| 516 display_->Resize(size); | 518 display_->Resize(size); |
| 517 root_layer_->SetBounds(size); | 519 root_window_->GetLayer()->SetBounds(size); |
| 518 } | 520 } |
| 519 | 521 |
| 520 void CompositorImpl::SetHasTransparentBackground(bool flag) { | 522 void CompositorImpl::SetHasTransparentBackground(bool flag) { |
| 521 has_transparent_background_ = flag; | 523 has_transparent_background_ = flag; |
| 522 if (host_) | 524 if (host_) |
| 523 host_->set_has_transparent_background(flag); | 525 host_->set_has_transparent_background(flag); |
| 524 } | 526 } |
| 525 | 527 |
| 526 void CompositorImpl::SetNeedsComposite() { | 528 void CompositorImpl::SetNeedsComposite() { |
| 527 if (!host_->visible()) | 529 if (!host_->visible()) |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 host_->SetNeedsCommit(); | 772 host_->SetNeedsCommit(); |
| 771 client_->OnSwapBuffersCompleted(0); | 773 client_->OnSwapBuffersCompleted(0); |
| 772 } | 774 } |
| 773 | 775 |
| 774 void CompositorImpl::DidCommit() { | 776 void CompositorImpl::DidCommit() { |
| 775 root_window_->OnCompositingDidCommit(); | 777 root_window_->OnCompositingDidCommit(); |
| 776 } | 778 } |
| 777 | 779 |
| 778 void CompositorImpl::RequestCopyOfOutputOnRootLayer( | 780 void CompositorImpl::RequestCopyOfOutputOnRootLayer( |
| 779 std::unique_ptr<cc::CopyOutputRequest> request) { | 781 std::unique_ptr<cc::CopyOutputRequest> request) { |
| 780 root_layer_->RequestCopyOfOutput(std::move(request)); | 782 root_window_->GetLayer()->RequestCopyOfOutput(std::move(request)); |
| 781 } | 783 } |
| 782 | 784 |
| 783 void CompositorImpl::OnVSync(base::TimeTicks frame_time, | 785 void CompositorImpl::OnVSync(base::TimeTicks frame_time, |
| 784 base::TimeDelta vsync_period) { | 786 base::TimeDelta vsync_period) { |
| 785 FOR_EACH_OBSERVER(VSyncObserver, observer_list_, | 787 FOR_EACH_OBSERVER(VSyncObserver, observer_list_, |
| 786 OnVSync(frame_time, vsync_period)); | 788 OnVSync(frame_time, vsync_period)); |
| 787 if (needs_begin_frames_) | 789 if (needs_begin_frames_) |
| 788 root_window_->RequestVSyncUpdate(); | 790 root_window_->RequestVSyncUpdate(); |
| 789 } | 791 } |
| 790 | 792 |
| 791 void CompositorImpl::OnNeedsBeginFramesChange(bool needs_begin_frames) { | 793 void CompositorImpl::OnNeedsBeginFramesChange(bool needs_begin_frames) { |
| 792 if (needs_begin_frames_ == needs_begin_frames) | 794 if (needs_begin_frames_ == needs_begin_frames) |
| 793 return; | 795 return; |
| 794 | 796 |
| 795 needs_begin_frames_ = needs_begin_frames; | 797 needs_begin_frames_ = needs_begin_frames; |
| 796 if (needs_begin_frames_) | 798 if (needs_begin_frames_) |
| 797 root_window_->RequestVSyncUpdate(); | 799 root_window_->RequestVSyncUpdate(); |
| 798 } | 800 } |
| 799 | 801 |
| 800 void CompositorImpl::SetNeedsAnimate() { | 802 void CompositorImpl::SetNeedsAnimate() { |
| 801 needs_animate_ = true; | 803 needs_animate_ = true; |
| 802 if (!host_->visible()) | 804 if (!host_->visible()) |
| 803 return; | 805 return; |
| 804 | 806 |
| 805 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 807 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 806 host_->SetNeedsAnimate(); | 808 host_->SetNeedsAnimate(); |
| 807 } | 809 } |
| 808 | 810 |
| 809 } // namespace content | 811 } // namespace content |
| OLD | NEW |