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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #include "gpu/command_buffer/client/context_support.h" | 58 #include "gpu/command_buffer/client/context_support.h" |
59 #include "gpu/command_buffer/client/gles2_interface.h" | 59 #include "gpu/command_buffer/client/gles2_interface.h" |
60 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 60 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
61 #include "gpu/ipc/client/gpu_channel_host.h" | 61 #include "gpu/ipc/client/gpu_channel_host.h" |
62 #include "gpu/ipc/common/gpu_surface_tracker.h" | 62 #include "gpu/ipc/common/gpu_surface_tracker.h" |
63 #include "gpu/vulkan/vulkan_surface.h" | 63 #include "gpu/vulkan/vulkan_surface.h" |
64 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 64 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
65 #include "third_party/khronos/GLES2/gl2.h" | 65 #include "third_party/khronos/GLES2/gl2.h" |
66 #include "third_party/khronos/GLES2/gl2ext.h" | 66 #include "third_party/khronos/GLES2/gl2ext.h" |
67 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 67 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 68 #include "ui/android/view_root.h" |
68 #include "ui/android/window_android.h" | 69 #include "ui/android/window_android.h" |
69 #include "ui/display/display.h" | 70 #include "ui/display/display.h" |
70 #include "ui/display/screen.h" | 71 #include "ui/display/screen.h" |
71 #include "ui/gfx/swap_result.h" | 72 #include "ui/gfx/swap_result.h" |
72 | 73 |
73 namespace gpu { | 74 namespace gpu { |
74 struct GpuProcessHostedCALayerTreeParamsMac; | 75 struct GpuProcessHostedCALayerTreeParamsMac; |
75 } | 76 } |
76 | 77 |
77 namespace content { | 78 namespace content { |
78 | 79 |
79 namespace { | 80 namespace { |
80 | 81 |
81 const unsigned int kMaxDisplaySwapBuffers = 1U; | 82 const unsigned int kMaxDisplaySwapBuffers = 1U; |
82 | 83 |
83 gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits( | 84 gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits( |
84 gfx::NativeWindow window) { | 85 gfx::NativeWindow window) { |
85 constexpr size_t kBytesPerPixel = 4; | 86 constexpr size_t kBytesPerPixel = 4; |
86 const gfx::Size size = display::Screen::GetScreen() | 87 const gfx::Size size = display::Screen::GetScreen() |
87 ->GetDisplayNearestWindow(window) | 88 ->GetDisplayNearestWindowAndroid(window) |
88 .GetSizeInPixel(); | 89 .GetSizeInPixel(); |
89 const size_t full_screen_texture_size_in_bytes = | 90 const size_t full_screen_texture_size_in_bytes = |
90 size.width() * size.height() * kBytesPerPixel; | 91 size.width() * size.height() * kBytesPerPixel; |
91 | 92 |
92 gpu::SharedMemoryLimits limits; | 93 gpu::SharedMemoryLimits limits; |
93 // This limit is meant to hold the contents of the display compositor | 94 // This limit is meant to hold the contents of the display compositor |
94 // drawing the scene. See discussion here: | 95 // drawing the scene. See discussion here: |
95 // https://codereview.chromium.org/1900993002/diff/90001/content/browser/rende
rer_host/compositor_impl_android.cc?context=3&column_width=80&tab_spaces=8 | 96 // https://codereview.chromium.org/1900993002/diff/90001/content/browser/rende
rer_host/compositor_impl_android.cc?context=3&column_width=80&tab_spaces=8 |
96 limits.command_buffer_size = 64 * 1024; | 97 limits.command_buffer_size = 64 * 1024; |
97 // These limits are meant to hold the uploads for the browser UI without | 98 // These limits are meant to hold the uploads for the browser UI without |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 303 } |
303 }; | 304 }; |
304 | 305 |
305 base::LazyInstance<SingleThreadTaskGraphRunner> g_task_graph_runner = | 306 base::LazyInstance<SingleThreadTaskGraphRunner> g_task_graph_runner = |
306 LAZY_INSTANCE_INITIALIZER; | 307 LAZY_INSTANCE_INITIALIZER; |
307 | 308 |
308 } // anonymous namespace | 309 } // anonymous namespace |
309 | 310 |
310 // static | 311 // static |
311 Compositor* Compositor::Create(CompositorClient* client, | 312 Compositor* Compositor::Create(CompositorClient* client, |
312 gfx::NativeWindow root_window) { | 313 ui::ViewRoot* view_root) { |
313 return client ? new CompositorImpl(client, root_window) : NULL; | 314 return client ? new CompositorImpl(client, view_root) : NULL; |
314 } | 315 } |
315 | 316 |
316 // static | 317 // static |
317 void Compositor::Initialize() { | 318 void Compositor::Initialize() { |
318 DCHECK(!CompositorImpl::IsInitialized()); | 319 DCHECK(!CompositorImpl::IsInitialized()); |
319 g_initialized = true; | 320 g_initialized = true; |
320 } | 321 } |
321 | 322 |
322 // static | 323 // static |
323 bool CompositorImpl::IsInitialized() { | 324 bool CompositorImpl::IsInitialized() { |
324 return g_initialized; | 325 return g_initialized; |
325 } | 326 } |
326 | 327 |
327 CompositorImpl::CompositorImpl(CompositorClient* client, | 328 CompositorImpl::CompositorImpl(CompositorClient* client, |
328 gfx::NativeWindow root_window) | 329 ui::ViewRoot* view_root) |
329 : frame_sink_id_( | 330 : frame_sink_id_( |
330 ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()), | 331 ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()), |
331 resource_manager_(root_window), | 332 resource_manager_(view_root->GetWindowAndroid()), |
332 window_(NULL), | 333 window_(NULL), |
333 surface_handle_(gpu::kNullSurfaceHandle), | 334 surface_handle_(gpu::kNullSurfaceHandle), |
334 client_(client), | 335 client_(client), |
335 root_window_(root_window), | 336 root_window_(view_root->GetWindowAndroid()), |
| 337 view_root_(view_root), |
336 needs_animate_(false), | 338 needs_animate_(false), |
337 pending_swapbuffers_(0U), | 339 pending_swapbuffers_(0U), |
338 num_successive_context_creation_failures_(0), | 340 num_successive_context_creation_failures_(0), |
339 compositor_frame_sink_request_pending_(false), | 341 compositor_frame_sink_request_pending_(false), |
340 weak_factory_(this) { | 342 weak_factory_(this) { |
341 ui::ContextProviderFactory::GetInstance() | 343 ui::ContextProviderFactory::GetInstance() |
342 ->GetSurfaceManager() | 344 ->GetSurfaceManager() |
343 ->RegisterFrameSinkId(frame_sink_id_); | 345 ->RegisterFrameSinkId(frame_sink_id_); |
344 DCHECK(client); | 346 DCHECK(client); |
345 DCHECK(root_window); | 347 DCHECK(view_root); |
346 DCHECK(root_window->GetLayer() == nullptr); | 348 DCHECK(view_root->GetLayer() == nullptr); |
347 root_window->SetLayer(cc::Layer::Create()); | 349 view_root->SetLayer(cc::Layer::Create()); |
348 readback_layer_tree_ = cc::Layer::Create(); | 350 readback_layer_tree_ = cc::Layer::Create(); |
349 readback_layer_tree_->SetHideLayerAndSubtree(true); | 351 readback_layer_tree_->SetHideLayerAndSubtree(true); |
350 root_window->GetLayer()->AddChild(readback_layer_tree_); | 352 view_root->GetLayer()->AddChild(readback_layer_tree_); |
351 root_window->AttachCompositor(this); | 353 root_window_->AttachCompositor(this); |
352 CreateLayerTreeHost(); | 354 CreateLayerTreeHost(); |
353 resource_manager_.Init(host_->GetUIResourceManager()); | 355 resource_manager_.Init(host_->GetUIResourceManager()); |
354 } | 356 } |
355 | 357 |
356 CompositorImpl::~CompositorImpl() { | 358 CompositorImpl::~CompositorImpl() { |
357 root_window_->DetachCompositor(); | 359 root_window_->DetachCompositor(); |
358 root_window_->SetLayer(nullptr); | 360 view_root_->SetLayer(nullptr); |
359 // Clean-up any surface references. | 361 // Clean-up any surface references. |
360 SetSurface(NULL); | 362 SetSurface(NULL); |
361 ui::ContextProviderFactory::GetInstance() | 363 ui::ContextProviderFactory::GetInstance() |
362 ->GetSurfaceManager() | 364 ->GetSurfaceManager() |
363 ->InvalidateFrameSinkId(frame_sink_id_); | 365 ->InvalidateFrameSinkId(frame_sink_id_); |
364 } | 366 } |
365 | 367 |
366 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 368 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
367 return *this; | 369 return *this; |
368 } | 370 } |
369 | 371 |
370 ui::ResourceManager& CompositorImpl::GetResourceManager() { | 372 ui::ResourceManager& CompositorImpl::GetResourceManager() { |
371 return resource_manager_; | 373 return resource_manager_; |
372 } | 374 } |
373 | 375 |
374 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 376 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
375 if (subroot_layer_.get()) { | 377 if (subroot_layer_.get()) { |
376 subroot_layer_->RemoveFromParent(); | 378 subroot_layer_->RemoveFromParent(); |
377 subroot_layer_ = NULL; | 379 subroot_layer_ = NULL; |
378 } | 380 } |
379 if (root_window_->GetLayer()) { | 381 if (view_root_->GetLayer()) { |
380 subroot_layer_ = root_window_->GetLayer(); | 382 subroot_layer_ = view_root_->GetLayer(); |
381 root_window_->GetLayer()->AddChild(root_layer); | 383 view_root_->GetLayer()->AddChild(root_layer); |
382 } | 384 } |
383 } | 385 } |
384 | 386 |
385 void CompositorImpl::SetSurface(jobject surface) { | 387 void CompositorImpl::SetSurface(jobject surface) { |
386 JNIEnv* env = base::android::AttachCurrentThread(); | 388 JNIEnv* env = base::android::AttachCurrentThread(); |
387 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); | 389 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); |
388 | 390 |
389 if (window_) { | 391 if (window_) { |
390 // Shut down GL context before unregistering surface. | 392 // Shut down GL context before unregistering surface. |
391 SetVisible(false); | 393 SetVisible(false); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 animation_host_ = cc::AnimationHost::CreateMainInstance(); | 438 animation_host_ = cc::AnimationHost::CreateMainInstance(); |
437 | 439 |
438 cc::LayerTreeHost::InitParams params; | 440 cc::LayerTreeHost::InitParams params; |
439 params.client = this; | 441 params.client = this; |
440 params.task_graph_runner = g_task_graph_runner.Pointer(); | 442 params.task_graph_runner = g_task_graph_runner.Pointer(); |
441 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 443 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
442 params.settings = &settings; | 444 params.settings = &settings; |
443 params.mutator_host = animation_host_.get(); | 445 params.mutator_host = animation_host_.get(); |
444 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 446 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
445 DCHECK(!host_->IsVisible()); | 447 DCHECK(!host_->IsVisible()); |
446 host_->SetRootLayer(root_window_->GetLayer()); | 448 host_->SetRootLayer(view_root_->GetLayer()); |
447 host_->SetFrameSinkId(frame_sink_id_); | 449 host_->SetFrameSinkId(frame_sink_id_); |
448 host_->SetViewportSize(size_); | 450 host_->SetViewportSize(size_); |
449 SetHasTransparentBackground(false); | 451 SetHasTransparentBackground(false); |
450 host_->SetDeviceScaleFactor(1); | 452 host_->SetDeviceScaleFactor(1); |
451 | 453 |
452 if (needs_animate_) | 454 if (needs_animate_) |
453 host_->SetNeedsAnimate(); | 455 host_->SetNeedsAnimate(); |
454 } | 456 } |
455 | 457 |
456 void CompositorImpl::SetVisible(bool visible) { | 458 void CompositorImpl::SetVisible(bool visible) { |
(...skipping 21 matching lines...) Expand all Loading... |
478 | 480 |
479 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 481 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
480 if (size_ == size) | 482 if (size_ == size) |
481 return; | 483 return; |
482 | 484 |
483 size_ = size; | 485 size_ = size; |
484 if (host_) | 486 if (host_) |
485 host_->SetViewportSize(size); | 487 host_->SetViewportSize(size); |
486 if (display_) | 488 if (display_) |
487 display_->Resize(size); | 489 display_->Resize(size); |
488 root_window_->GetLayer()->SetBounds(size); | 490 view_root_->GetLayer()->SetBounds(size); |
489 } | 491 } |
490 | 492 |
491 void CompositorImpl::SetHasTransparentBackground(bool transparent) { | 493 void CompositorImpl::SetHasTransparentBackground(bool transparent) { |
492 has_transparent_background_ = transparent; | 494 has_transparent_background_ = transparent; |
493 if (host_) { | 495 if (host_) { |
494 host_->set_has_transparent_background(transparent); | 496 host_->set_has_transparent_background(transparent); |
495 | 497 |
496 // Give a delay in setting the background color to avoid the color for | 498 // Give a delay in setting the background color to avoid the color for |
497 // the normal mode (white) affecting the UI transition. | 499 // the normal mode (white) affecting the UI transition. |
498 base::ThreadTaskRunnerHandle::Get().get()->PostDelayedTask( | 500 base::ThreadTaskRunnerHandle::Get().get()->PostDelayedTask( |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 void CompositorImpl::DidCommit() { | 721 void CompositorImpl::DidCommit() { |
720 root_window_->OnCompositingDidCommit(); | 722 root_window_->OnCompositingDidCommit(); |
721 } | 723 } |
722 | 724 |
723 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 725 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
724 readback_layer_tree_->AddChild(layer); | 726 readback_layer_tree_->AddChild(layer); |
725 } | 727 } |
726 | 728 |
727 void CompositorImpl::RequestCopyOfOutputOnRootLayer( | 729 void CompositorImpl::RequestCopyOfOutputOnRootLayer( |
728 std::unique_ptr<cc::CopyOutputRequest> request) { | 730 std::unique_ptr<cc::CopyOutputRequest> request) { |
729 root_window_->GetLayer()->RequestCopyOfOutput(std::move(request)); | 731 view_root_->GetLayer()->RequestCopyOfOutput(std::move(request)); |
730 } | 732 } |
731 | 733 |
732 void CompositorImpl::SetNeedsAnimate() { | 734 void CompositorImpl::SetNeedsAnimate() { |
733 needs_animate_ = true; | 735 needs_animate_ = true; |
734 if (!host_->IsVisible()) | 736 if (!host_->IsVisible()) |
735 return; | 737 return; |
736 | 738 |
737 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 739 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
738 host_->SetNeedsAnimate(); | 740 host_->SetNeedsAnimate(); |
739 } | 741 } |
(...skipping 22 matching lines...) Expand all Loading... |
762 ui::ContextProviderFactory::GetInstance() | 764 ui::ContextProviderFactory::GetInstance() |
763 ->GetSurfaceManager() | 765 ->GetSurfaceManager() |
764 ->UnregisterFrameSinkHierarchy(frame_sink_id_, frame_sink_id); | 766 ->UnregisterFrameSinkHierarchy(frame_sink_id_, frame_sink_id); |
765 } | 767 } |
766 | 768 |
767 bool CompositorImpl::HavePendingReadbacks() { | 769 bool CompositorImpl::HavePendingReadbacks() { |
768 return !readback_layer_tree_->children().empty(); | 770 return !readback_layer_tree_->children().empty(); |
769 } | 771 } |
770 | 772 |
771 } // namespace content | 773 } // namespace content |
OLD | NEW |