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

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

Powered by Google App Engine
This is Rietveld 408576698