Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: unittest Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
436 animation_host_ = cc::AnimationHost::CreateMainInstance(); 438 animation_host_ = cc::AnimationHost::CreateMainInstance();
437 439
438 cc::LayerTreeHostInProcess::InitParams params; 440 cc::LayerTreeHostInProcess::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::LayerTreeHostInProcess::CreateSingleThreaded(this, &params); 446 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, &params);
445 DCHECK(!host_->IsVisible()); 447 DCHECK(!host_->IsVisible());
446 host_->GetLayerTree()->SetRootLayer(root_window_->GetLayer()); 448 host_->GetLayerTree()->SetRootLayer(view_root_->GetLayer());
447 host_->SetFrameSinkId(frame_sink_id_); 449 host_->SetFrameSinkId(frame_sink_id_);
448 host_->GetLayerTree()->SetViewportSize(size_); 450 host_->GetLayerTree()->SetViewportSize(size_);
449 SetHasTransparentBackground(false); 451 SetHasTransparentBackground(false);
450 host_->GetLayerTree()->SetDeviceScaleFactor(1); 452 host_->GetLayerTree()->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 20 matching lines...) Expand all
477 479
478 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { 480 void CompositorImpl::SetWindowBounds(const gfx::Size& size) {
479 if (size_ == size) 481 if (size_ == size)
480 return; 482 return;
481 483
482 size_ = size; 484 size_ = size;
483 if (host_) 485 if (host_)
484 host_->GetLayerTree()->SetViewportSize(size); 486 host_->GetLayerTree()->SetViewportSize(size);
485 if (display_) 487 if (display_)
486 display_->Resize(size); 488 display_->Resize(size);
487 root_window_->GetLayer()->SetBounds(size); 489 view_root_->GetLayer()->SetBounds(size);
488 } 490 }
489 491
490 void CompositorImpl::SetHasTransparentBackground(bool transparent) { 492 void CompositorImpl::SetHasTransparentBackground(bool transparent) {
491 has_transparent_background_ = transparent; 493 has_transparent_background_ = transparent;
492 if (host_) { 494 if (host_) {
493 host_->GetLayerTree()->set_has_transparent_background(transparent); 495 host_->GetLayerTree()->set_has_transparent_background(transparent);
494 496
495 // Give a delay in setting the background color to avoid the color for 497 // Give a delay in setting the background color to avoid the color for
496 // the normal mode (white) affecting the UI transition. 498 // the normal mode (white) affecting the UI transition.
497 base::ThreadTaskRunnerHandle::Get().get()->PostDelayedTask( 499 base::ThreadTaskRunnerHandle::Get().get()->PostDelayedTask(
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 void CompositorImpl::DidCommit() { 714 void CompositorImpl::DidCommit() {
713 root_window_->OnCompositingDidCommit(); 715 root_window_->OnCompositingDidCommit();
714 } 716 }
715 717
716 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { 718 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) {
717 readback_layer_tree_->AddChild(layer); 719 readback_layer_tree_->AddChild(layer);
718 } 720 }
719 721
720 void CompositorImpl::RequestCopyOfOutputOnRootLayer( 722 void CompositorImpl::RequestCopyOfOutputOnRootLayer(
721 std::unique_ptr<cc::CopyOutputRequest> request) { 723 std::unique_ptr<cc::CopyOutputRequest> request) {
722 root_window_->GetLayer()->RequestCopyOfOutput(std::move(request)); 724 view_root_->GetLayer()->RequestCopyOfOutput(std::move(request));
723 } 725 }
724 726
725 void CompositorImpl::SetNeedsAnimate() { 727 void CompositorImpl::SetNeedsAnimate() {
726 needs_animate_ = true; 728 needs_animate_ = true;
727 if (!host_->IsVisible()) 729 if (!host_->IsVisible())
728 return; 730 return;
729 731
730 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); 732 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate");
731 host_->SetNeedsAnimate(); 733 host_->SetNeedsAnimate();
732 } 734 }
733 735
734 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { 736 cc::FrameSinkId CompositorImpl::GetFrameSinkId() {
735 return frame_sink_id_; 737 return frame_sink_id_;
736 } 738 }
737 739
738 bool CompositorImpl::HavePendingReadbacks() { 740 bool CompositorImpl::HavePendingReadbacks() {
739 return !readback_layer_tree_->children().empty(); 741 return !readback_layer_tree_->children().empty();
740 } 742 }
741 743
742 } // namespace content 744 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698