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

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

Issue 2190033002: content: Add ContextProviderFactory to create a render ContextProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: copy ctor. Created 4 years, 4 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 26 matching lines...) Expand all
37 #include "cc/output/output_surface.h" 37 #include "cc/output/output_surface.h"
38 #include "cc/output/output_surface_client.h" 38 #include "cc/output/output_surface_client.h"
39 #include "cc/output/texture_mailbox_deleter.h" 39 #include "cc/output/texture_mailbox_deleter.h"
40 #include "cc/output/vulkan_in_process_context_provider.h" 40 #include "cc/output/vulkan_in_process_context_provider.h"
41 #include "cc/raster/single_thread_task_graph_runner.h" 41 #include "cc/raster/single_thread_task_graph_runner.h"
42 #include "cc/scheduler/begin_frame_source.h" 42 #include "cc/scheduler/begin_frame_source.h"
43 #include "cc/surfaces/display.h" 43 #include "cc/surfaces/display.h"
44 #include "cc/surfaces/display_scheduler.h" 44 #include "cc/surfaces/display_scheduler.h"
45 #include "cc/surfaces/surface_display_output_surface.h" 45 #include "cc/surfaces/surface_display_output_surface.h"
46 #include "cc/surfaces/surface_id_allocator.h" 46 #include "cc/surfaces/surface_id_allocator.h"
47 #include "cc/surfaces/surface_manager.h"
48 #include "cc/trees/layer_tree_host.h" 47 #include "cc/trees/layer_tree_host.h"
49 #include "cc/trees/layer_tree_settings.h" 48 #include "cc/trees/layer_tree_settings.h"
50 #include "components/display_compositor/compositor_overlay_candidate_validator_a ndroid.h" 49 #include "components/display_compositor/compositor_overlay_candidate_validator_a ndroid.h"
51 #include "components/display_compositor/gl_helper.h" 50 #include "components/display_compositor/gl_helper.h"
52 #include "content/browser/android/child_process_launcher_android.h" 51 #include "content/browser/android/child_process_launcher_android.h"
53 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
54 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 52 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
55 #include "content/browser/gpu/compositor_util.h" 53 #include "content/browser/gpu/compositor_util.h"
56 #include "content/browser/gpu/gpu_surface_tracker.h" 54 #include "content/browser/gpu/gpu_surface_tracker.h"
55 #include "content/browser/renderer_host/context_provider_factory_impl_android.h"
57 #include "content/browser/renderer_host/render_widget_host_impl.h" 56 #include "content/browser/renderer_host/render_widget_host_impl.h"
58 #include "content/common/gpu/client/context_provider_command_buffer.h" 57 #include "content/common/gpu/client/context_provider_command_buffer.h"
59 #include "content/common/host_shared_bitmap_manager.h" 58 #include "content/common/host_shared_bitmap_manager.h"
60 #include "content/public/browser/android/compositor.h" 59 #include "content/public/browser/android/compositor.h"
61 #include "content/public/browser/android/compositor_client.h" 60 #include "content/public/browser/android/compositor_client.h"
62 #include "content/public/common/content_switches.h" 61 #include "content/public/common/content_switches.h"
63 #include "gpu/command_buffer/client/context_support.h" 62 #include "gpu/command_buffer/client/context_support.h"
64 #include "gpu/command_buffer/client/gles2_interface.h" 63 #include "gpu/command_buffer/client/gles2_interface.h"
65 #include "gpu/ipc/client/command_buffer_proxy_impl.h" 64 #include "gpu/ipc/client/command_buffer_proxy_impl.h"
66 #include "gpu/ipc/client/gpu_channel_host.h" 65 #include "gpu/ipc/client/gpu_channel_host.h"
67 #include "gpu/vulkan/vulkan_surface.h" 66 #include "gpu/vulkan/vulkan_surface.h"
68 #include "third_party/khronos/GLES2/gl2.h" 67 #include "third_party/khronos/GLES2/gl2.h"
69 #include "third_party/khronos/GLES2/gl2ext.h" 68 #include "third_party/khronos/GLES2/gl2ext.h"
70 #include "third_party/skia/include/core/SkMallocPixelRef.h" 69 #include "third_party/skia/include/core/SkMallocPixelRef.h"
71 #include "ui/android/window_android.h" 70 #include "ui/android/window_android.h"
72 #include "ui/gfx/android/device_display_info.h" 71 #include "ui/gfx/android/device_display_info.h"
73 #include "ui/gfx/swap_result.h" 72 #include "ui/gfx/swap_result.h"
74 73
75 namespace gpu { 74 namespace gpu {
76 struct GpuProcessHostedCALayerTreeParamsMac; 75 struct GpuProcessHostedCALayerTreeParamsMac;
77 } 76 }
78 77
79 namespace content { 78 namespace content {
80 79
81 namespace { 80 namespace {
82 81
83 const unsigned int kMaxDisplaySwapBuffers = 1U; 82 const unsigned int kMaxDisplaySwapBuffers = 1U;
84 83
84 gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits() {
85 constexpr size_t kBytesPerPixel = 4;
86 const size_t full_screen_texture_size_in_bytes =
87 gfx::DeviceDisplayInfo().GetDisplayHeight() *
88 gfx::DeviceDisplayInfo().GetDisplayWidth() * kBytesPerPixel;
89
90 gpu::SharedMemoryLimits limits;
91 // This limit is meant to hold the contents of the display compositor
92 // drawing the scene. See discussion here:
93 // https://codereview.chromium.org/1900993002/diff/90001/content/browser/rende rer_host/compositor_impl_android.cc?context=3&column_width=80&tab_spaces=8
94 limits.command_buffer_size = 64 * 1024;
95 // These limits are meant to hold the uploads for the browser UI without
96 // any excess space.
97 limits.start_transfer_buffer_size = 64 * 1024;
98 limits.min_transfer_buffer_size = 64 * 1024;
99 limits.max_transfer_buffer_size = full_screen_texture_size_in_bytes;
100 // Texture uploads may use mapped memory so give a reasonable limit for
101 // them.
102 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes;
103
104 return limits;
105 }
106
107 gpu::gles2::ContextCreationAttribHelper GetCompositorContextAttributes(
108 bool has_transparent_background) {
109 // This is used for the browser compositor (offscreen) and for the display
110 // compositor (onscreen), so ask for capabilities needed by either one.
111 // The default framebuffer for an offscreen context is not used, so it does
112 // not need alpha, stencil, depth, antialiasing. The display compositor does
113 // not use these things either, except for alpha when it has a transparent
114 // background.
115 gpu::gles2::ContextCreationAttribHelper attributes;
116 attributes.alpha_size = -1;
117 attributes.stencil_size = 0;
118 attributes.depth_size = 0;
119 attributes.samples = 0;
120 attributes.sample_buffers = 0;
121 attributes.bind_generates_resource = false;
122
123 if (has_transparent_background) {
124 attributes.alpha_size = 8;
125 } else if (base::SysInfo::IsLowEndDevice()) {
126 // In this case we prefer to use RGB565 format instead of RGBA8888 if
127 // possible.
128 // TODO(danakj): GpuCommandBufferStub constructor checks for alpha == 0 in
129 // order to enable 565, but it should avoid using 565 when -1s are
130 // specified
131 // (IOW check that a <= 0 && rgb > 0 && rgb <= 565) then alpha should be
132 // -1.
133 attributes.alpha_size = 0;
134 attributes.red_size = 5;
135 attributes.green_size = 6;
136 attributes.blue_size = 5;
137 }
138
139 return attributes;
140 }
141
85 class ExternalBeginFrameSource : public cc::BeginFrameSource, 142 class ExternalBeginFrameSource : public cc::BeginFrameSource,
86 public CompositorImpl::VSyncObserver { 143 public CompositorImpl::VSyncObserver {
87 public: 144 public:
88 explicit ExternalBeginFrameSource(CompositorImpl* compositor) 145 explicit ExternalBeginFrameSource(CompositorImpl* compositor)
89 : compositor_(compositor) { 146 : compositor_(compositor) {
90 compositor_->AddObserver(this); 147 compositor_->AddObserver(this);
91 } 148 }
92 ~ExternalBeginFrameSource() override { compositor_->RemoveObserver(this); } 149 ~ExternalBeginFrameSource() override { compositor_->RemoveObserver(this); }
93 150
94 // cc::BeginFrameSource implementation. 151 // cc::BeginFrameSource implementation.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 OutputSurface::OnSwapBuffersComplete(); 337 OutputSurface::OnSwapBuffersComplete();
281 } 338 }
282 339
283 private: 340 private:
284 std::unique_ptr<gpu::VulkanSurface> surface_; 341 std::unique_ptr<gpu::VulkanSurface> surface_;
285 342
286 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); 343 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface);
287 }; 344 };
288 #endif 345 #endif
289 346
290 base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>>
291 g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER;
292
293 static bool g_initialized = false; 347 static bool g_initialized = false;
294 348
295 base::LazyInstance<cc::SurfaceManager> g_surface_manager =
296 LAZY_INSTANCE_INITIALIZER;
297
298 int g_surface_client_id = 0;
299
300 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { 349 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner {
301 public: 350 public:
302 SingleThreadTaskGraphRunner() { 351 SingleThreadTaskGraphRunner() {
303 Start("CompositorTileWorker1", base::SimpleThread::Options()); 352 Start("CompositorTileWorker1", base::SimpleThread::Options());
304 } 353 }
305 354
306 ~SingleThreadTaskGraphRunner() override { 355 ~SingleThreadTaskGraphRunner() override {
307 Shutdown(); 356 Shutdown();
308 } 357 }
309 }; 358 };
(...skipping 13 matching lines...) Expand all
323 void Compositor::Initialize() { 372 void Compositor::Initialize() {
324 DCHECK(!CompositorImpl::IsInitialized()); 373 DCHECK(!CompositorImpl::IsInitialized());
325 g_initialized = true; 374 g_initialized = true;
326 } 375 }
327 376
328 // static 377 // static
329 bool CompositorImpl::IsInitialized() { 378 bool CompositorImpl::IsInitialized() {
330 return g_initialized; 379 return g_initialized;
331 } 380 }
332 381
333 // static
334 cc::SurfaceManager* CompositorImpl::GetSurfaceManager() {
335 return g_surface_manager.Pointer();
336 }
337
338 // static
339 uint32_t CompositorImpl::AllocateSurfaceClientId() {
340 return ++g_surface_client_id;
341 }
342
343 // static
344 scoped_refptr<cc::VulkanInProcessContextProvider>
345 CompositorImpl::SharedVulkanContextProviderAndroid() {
346 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
347 switches::kEnableVulkan)) {
348 scoped_refptr<cc::VulkanInProcessContextProvider>* context_provider =
349 g_shared_vulkan_context_provider_android_.Pointer();
350 if (!*context_provider)
351 *context_provider = cc::VulkanInProcessContextProvider::Create();
352 return *context_provider;
353 }
354 return nullptr;
355 }
356
357 CompositorImpl::CompositorImpl(CompositorClient* client, 382 CompositorImpl::CompositorImpl(CompositorClient* client,
358 gfx::NativeWindow root_window) 383 gfx::NativeWindow root_window)
359 : surface_id_allocator_( 384 : surface_id_allocator_(
360 new cc::SurfaceIdAllocator(AllocateSurfaceClientId())), 385 new cc::SurfaceIdAllocator(ui::ContextProviderFactory::GetInstance()
386 ->AllocateSurfaceClientId())),
361 resource_manager_(root_window), 387 resource_manager_(root_window),
362 has_transparent_background_(false), 388 has_transparent_background_(false),
363 device_scale_factor_(1), 389 device_scale_factor_(1),
364 window_(NULL), 390 window_(NULL),
365 surface_handle_(gpu::kNullSurfaceHandle), 391 surface_handle_(gpu::kNullSurfaceHandle),
366 client_(client), 392 client_(client),
367 root_window_(root_window), 393 root_window_(root_window),
368 needs_animate_(false), 394 needs_animate_(false),
369 pending_swapbuffers_(0U), 395 pending_swapbuffers_(0U),
370 num_successive_context_creation_failures_(0), 396 num_successive_context_creation_failures_(0),
371 output_surface_request_pending_(false), 397 output_surface_request_pending_(false),
372 needs_begin_frames_(false), 398 needs_begin_frames_(false),
373 weak_factory_(this) { 399 weak_factory_(this) {
374 GetSurfaceManager()->RegisterSurfaceClientId( 400 ui::ContextProviderFactory::GetInstance()
375 surface_id_allocator_->client_id()); 401 ->GetSurfaceManager()
402 ->RegisterSurfaceClientId(surface_id_allocator_->client_id());
376 DCHECK(client); 403 DCHECK(client);
377 DCHECK(root_window); 404 DCHECK(root_window);
378 DCHECK(root_window->GetLayer() == nullptr); 405 DCHECK(root_window->GetLayer() == nullptr);
379 root_window->SetLayer(cc::Layer::Create()); 406 root_window->SetLayer(cc::Layer::Create());
380 root_window->AttachCompositor(this); 407 root_window->AttachCompositor(this);
381 CreateLayerTreeHost(); 408 CreateLayerTreeHost();
382 resource_manager_.Init(host_.get()); 409 resource_manager_.Init(host_.get());
383 } 410 }
384 411
385 CompositorImpl::~CompositorImpl() { 412 CompositorImpl::~CompositorImpl() {
386 root_window_->DetachCompositor(); 413 root_window_->DetachCompositor();
387 root_window_->SetLayer(nullptr); 414 root_window_->SetLayer(nullptr);
388 // Clean-up any surface references. 415 // Clean-up any surface references.
389 SetSurface(NULL); 416 SetSurface(NULL);
390 GetSurfaceManager()->InvalidateSurfaceClientId( 417 ui::ContextProviderFactory::GetInstance()
391 surface_id_allocator_->client_id()); 418 ->GetSurfaceManager()
419 ->InvalidateSurfaceClientId(surface_id_allocator_->client_id());
392 } 420 }
393 421
394 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { 422 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() {
395 return *this; 423 return *this;
396 } 424 }
397 425
398 ui::ResourceManager& CompositorImpl::GetResourceManager() { 426 ui::ResourceManager& CompositorImpl::GetResourceManager() {
399 return resource_manager_; 427 return resource_manager_;
400 } 428 }
401 429
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 511 }
484 512
485 void CompositorImpl::SetVisible(bool visible) { 513 void CompositorImpl::SetVisible(bool visible) {
486 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); 514 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible);
487 if (!visible) { 515 if (!visible) {
488 DCHECK(host_->visible()); 516 DCHECK(host_->visible());
489 host_->SetVisible(false); 517 host_->SetVisible(false);
490 if (!host_->output_surface_lost()) 518 if (!host_->output_surface_lost())
491 host_->ReleaseOutputSurface(); 519 host_->ReleaseOutputSurface();
492 pending_swapbuffers_ = 0; 520 pending_swapbuffers_ = 0;
493 establish_gpu_channel_timeout_.Stop();
494 display_.reset(); 521 display_.reset();
495 } else { 522 } else {
496 host_->SetVisible(true); 523 host_->SetVisible(true);
497 if (output_surface_request_pending_) 524 if (output_surface_request_pending_)
498 RequestNewOutputSurface(); 525 HandlePendingOutputSurfaceRequest();
499 } 526 }
500 } 527 }
501 528
502 void CompositorImpl::setDeviceScaleFactor(float factor) { 529 void CompositorImpl::setDeviceScaleFactor(float factor) {
503 device_scale_factor_ = factor; 530 device_scale_factor_ = factor;
504 if (host_) 531 if (host_)
505 host_->SetDeviceScaleFactor(factor); 532 host_->SetDeviceScaleFactor(factor);
506 } 533 }
507 534
508 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { 535 void CompositorImpl::SetWindowBounds(const gfx::Size& size) {
(...skipping 22 matching lines...) Expand all
531 } 558 }
532 559
533 void CompositorImpl::UpdateLayerTreeHost() { 560 void CompositorImpl::UpdateLayerTreeHost() {
534 client_->UpdateLayerTreeHost(); 561 client_->UpdateLayerTreeHost();
535 if (needs_animate_) { 562 if (needs_animate_) {
536 needs_animate_ = false; 563 needs_animate_ = false;
537 root_window_->Animate(base::TimeTicks::Now()); 564 root_window_->Animate(base::TimeTicks::Now());
538 } 565 }
539 } 566 }
540 567
541 void CompositorImpl::OnGpuChannelEstablished() { 568 void CompositorImpl::RequestNewOutputSurface() {
542 establish_gpu_channel_timeout_.Stop(); 569 DCHECK(!output_surface_request_pending_)
543 CreateOutputSurface(); 570 << "Output Surface Request is already pending?";
544 }
545 571
546 void CompositorImpl::OnGpuChannelTimeout() {
547 LOG(FATAL) << "Timed out waiting for GPU channel.";
548 }
549
550 void CompositorImpl::RequestNewOutputSurface() {
551 output_surface_request_pending_ = true; 572 output_surface_request_pending_ = true;
552 573 HandlePendingOutputSurfaceRequest();
553 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
554 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
555 const int64_t kGpuChannelTimeoutInSeconds = 40;
556 #else
557 const int64_t kGpuChannelTimeoutInSeconds = 10;
558 #endif
559
560 BrowserGpuChannelHostFactory* factory =
561 BrowserGpuChannelHostFactory::instance();
562 if (!factory->GetGpuChannel()) {
563 factory->EstablishGpuChannel(
564 base::Bind(&CompositorImpl::OnGpuChannelEstablished,
565 weak_factory_.GetWeakPtr()));
566 establish_gpu_channel_timeout_.Start(
567 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
568 this, &CompositorImpl::OnGpuChannelTimeout);
569 return;
570 }
571
572 CreateOutputSurface();
573 } 574 }
574 575
575 void CompositorImpl::DidInitializeOutputSurface() { 576 void CompositorImpl::DidInitializeOutputSurface() {
576 num_successive_context_creation_failures_ = 0; 577 num_successive_context_creation_failures_ = 0;
577 output_surface_request_pending_ = false; 578 output_surface_request_pending_ = false;
578 } 579 }
579 580
580 void CompositorImpl::DidFailToInitializeOutputSurface() { 581 void CompositorImpl::DidFailToInitializeOutputSurface() {
581 LOG(ERROR) << "Failed to init OutputSurface for compositor."; 582 LOG(ERROR) << "Failed to init OutputSurface for compositor.";
582 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) 583 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2)
583 << "Too many context creation failures. Giving up... "; 584 << "Too many context creation failures. Giving up... ";
584 RequestNewOutputSurface(); 585 HandlePendingOutputSurfaceRequest();
585 } 586 }
586 587
587 void CompositorImpl::CreateOutputSurface() { 588 void CompositorImpl::HandlePendingOutputSurfaceRequest() {
588 // We might have had a request from a LayerTreeHost that was then 589 DCHECK(output_surface_request_pending_);
589 // hidden (and hidden means we don't have a native surface). 590
590 // Also make sure we only handle this once. 591 // We might have been made invisible now.
591 if (!output_surface_request_pending_ || !host_->visible()) 592 if (!host_->visible())
592 return; 593 return;
593 594
594 scoped_refptr<ContextProviderCommandBuffer> context_provider; 595 #if defined(ENABLE_VULKAN)
595 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = 596 CreateVulkanOutputSurface()
596 SharedVulkanContextProviderAndroid(); 597 if (display_)
598 return;
599 #endif
600
601 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle);
602
603 ContextProviderFactoryImpl::GetInstance()->CreateDisplayContextProvider(
604 window_, GetCompositorContextSharedMemoryLimits(),
605 GetCompositorContextAttributes(has_transparent_background_),
606 false /*support_locking*/, false /*automatic_flushes*/,
607 base::Bind(&CompositorImpl::CreateCompositorOutputSurface,
608 weak_factory_.GetWeakPtr()));
609 }
610
611 #if defined(ENABLE_VULKAN)
612 void CompositorImpl::CreateVulkanOutputSurface() {
613 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
614 switches::kEnableVulkan))
615 return;
616
597 std::unique_ptr<cc::OutputSurface> display_output_surface; 617 std::unique_ptr<cc::OutputSurface> display_output_surface;
598 #if defined(ENABLE_VULKAN) 618 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider =
599 std::unique_ptr<VulkanOutputSurface> vulkan_surface; 619 ui::ContextProviderFactory::GetInstance()
620 ->GetSharedVulkanContextProvider();
600 if (vulkan_context_provider) { 621 if (vulkan_context_provider) {
601 vulkan_surface.reset( 622 std::unique_ptr<VulkanOutputSurface> vulkan_surface(
602 new VulkanOutputSurface(std::move(vulkan_context_provider))); 623 new VulkanOutputSurface(std::move(vulkan_context_provider)));
603 if (!vulkan_surface->Initialize(window_)) { 624 if (!vulkan_surface->Initialize(window_)) {
604 vulkan_surface->Destroy(); 625 vulkan_surface->Destroy();
605 vulkan_surface.reset(); 626 vulkan_surface.reset();
606 } else { 627 } else {
607 display_output_surface = std::move(vulkan_surface); 628 display_output_surface = std::move(vulkan_surface);
608 } 629 }
609 } 630 }
631
632 if (!display_output_surface)
633 return;
634
635 InitializeDisplay(std::move(display_output_surface),
636 std::move(vulkan_context_provider), nullptr);
637 }
610 #endif 638 #endif
611 639
612 if (!display_output_surface) { 640 void CompositorImpl::CreateCompositorOutputSurface(
613 // This is used for the browser compositor (offscreen) and for the display 641 const scoped_refptr<cc::ContextProvider>& context_provider) {
614 // compositor (onscreen), so ask for capabilities needed by either one. 642 DCHECK(output_surface_request_pending_);
615 // The default framebuffer for an offscreen context is not used, so it does
616 // not need alpha, stencil, depth, antialiasing. The display compositor does
617 // not use these things either, except for alpha when it has a transparent
618 // background.
619 gpu::gles2::ContextCreationAttribHelper attributes;
620 attributes.alpha_size = -1;
621 attributes.stencil_size = 0;
622 attributes.depth_size = 0;
623 attributes.samples = 0;
624 attributes.sample_buffers = 0;
625 attributes.bind_generates_resource = false;
626 643
627 if (has_transparent_background_) { 644 // We might be invisible now. If we are invisible, this means the widget
628 attributes.alpha_size = 8; 645 // passed in the context provider request is invalid and a context provider
629 } else if (base::SysInfo::IsLowEndDevice()) { 646 // should not have been created.
630 // In this case we prefer to use RGB565 format instead of RGBA8888 if 647 if (!host_->visible()) {
631 // possible. 648 DCHECK(!context_provider);
632 // TODO(danakj): GpuCommandBufferStub constructor checks for alpha == 0 in 649 return;
633 // order to enable 565, but it should avoid using 565 when -1s are
634 // specified
635 // (IOW check that a <= 0 && rgb > 0 && rgb <= 565) then alpha should be
636 // -1.
637 attributes.alpha_size = 0;
638 attributes.red_size = 5;
639 attributes.green_size = 6;
640 attributes.blue_size = 5;
641 }
642
643 pending_swapbuffers_ = 0;
644
645 DCHECK(window_);
646 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle);
647
648 BrowserGpuChannelHostFactory* factory =
649 BrowserGpuChannelHostFactory::instance();
650 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
651 factory->GetGpuChannel());
652 // If the channel was already lost, we'll get null back here and need to
653 // try again.
654 if (!gpu_channel_host) {
655 RequestNewOutputSurface();
656 return;
657 }
658
659 GURL url("chrome://gpu/CompositorImpl::CreateOutputSurface");
660 constexpr bool automatic_flushes = false;
661 constexpr bool support_locking = false;
662
663 constexpr size_t kBytesPerPixel = 4;
664 const size_t full_screen_texture_size_in_bytes =
665 gfx::DeviceDisplayInfo().GetDisplayHeight() *
666 gfx::DeviceDisplayInfo().GetDisplayWidth() * kBytesPerPixel;
667
668 gpu::SharedMemoryLimits limits;
669 // This limit is meant to hold the contents of the display compositor
670 // drawing the scene. See discussion here:
671 // https://codereview.chromium.org/1900993002/diff/90001/content/browser/ren derer_host/compositor_impl_android.cc?context=3&column_width=80&tab_spaces=8
672 limits.command_buffer_size = 64 * 1024;
673 // These limits are meant to hold the uploads for the browser UI without
674 // any excess space.
675 limits.start_transfer_buffer_size = 64 * 1024;
676 limits.min_transfer_buffer_size = 64 * 1024;
677 limits.max_transfer_buffer_size = full_screen_texture_size_in_bytes;
678 // Texture uploads may use mapped memory so give a reasonable limit for
679 // them.
680 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes;
681
682 context_provider = new ContextProviderCommandBuffer(
683 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT,
684 gpu::GpuStreamPriority::NORMAL, surface_handle_, url, automatic_flushes,
685 support_locking, limits, attributes, nullptr,
686 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT);
687 DCHECK(context_provider.get());
688
689 display_output_surface = base::WrapUnique(new OutputSurfaceWithoutParent(
690 context_provider, base::Bind(&CompositorImpl::PopulateGpuCapabilities,
691 base::Unretained(this))));
692 } 650 }
693 651
694 cc::SurfaceManager* manager = GetSurfaceManager(); 652 DCHECK(window_);
653 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle);
654 // If the context request failed while we still have a valid surface, we need
655 // to try again.
656 if (!context_provider)
657 HandlePendingOutputSurfaceRequest();
Khushal 2016/08/05 19:11:17 I was thinking about the case where we go visible,
658
659 scoped_refptr<ContextProviderCommandBuffer> context_provider_command_buffer =
660 static_cast<ContextProviderCommandBuffer*>(context_provider.get());
661 std::unique_ptr<cc::OutputSurface> display_output_surface(
662 new OutputSurfaceWithoutParent(
663 context_provider_command_buffer,
664 base::Bind(&CompositorImpl::PopulateGpuCapabilities,
665 base::Unretained(this))));
666 InitializeDisplay(std::move(display_output_surface), nullptr,
667 std::move(context_provider));
668 }
669
670 void CompositorImpl::InitializeDisplay(
671 std::unique_ptr<cc::OutputSurface> display_output_surface,
672 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider,
673 scoped_refptr<cc::ContextProvider> context_provider) {
674 DCHECK(output_surface_request_pending_);
675 DCHECK(!display_);
676
677 pending_swapbuffers_ = 0;
678
679 cc::SurfaceManager* manager =
680 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
695 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); 681 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get();
696 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source( 682 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source(
697 new ExternalBeginFrameSource(this)); 683 new ExternalBeginFrameSource(this));
698 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( 684 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler(
699 begin_frame_source.get(), task_runner, 685 begin_frame_source.get(), task_runner,
700 display_output_surface->capabilities().max_frames_pending)); 686 display_output_surface->capabilities().max_frames_pending));
701 687
702 display_.reset(new cc::Display( 688 display_.reset(new cc::Display(
703 HostSharedBitmapManager::current(), 689 HostSharedBitmapManager::current(),
704 BrowserGpuMemoryBufferManager::current(), 690 BrowserGpuMemoryBufferManager::current(),
705 host_->settings().renderer_settings, std::move(begin_frame_source), 691 host_->settings().renderer_settings, std::move(begin_frame_source),
706 std::move(display_output_surface), std::move(scheduler), 692 std::move(display_output_surface), std::move(scheduler),
707 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner))); 693 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner)));
708 694
709 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( 695 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface(
710 vulkan_context_provider 696 vulkan_context_provider ? new cc::SurfaceDisplayOutputSurface(
711 ? new cc::SurfaceDisplayOutputSurface( 697 manager, surface_id_allocator_.get(),
712 manager, surface_id_allocator_.get(), display_.get(), 698 display_.get(), vulkan_context_provider)
713 static_cast<scoped_refptr<cc::VulkanContextProvider>>( 699 : new cc::SurfaceDisplayOutputSurface(
714 vulkan_context_provider)) 700 manager, surface_id_allocator_.get(),
715 : new cc::SurfaceDisplayOutputSurface( 701 display_.get(), context_provider, nullptr));
716 manager, surface_id_allocator_.get(), display_.get(),
717 context_provider, nullptr));
718 702
719 display_->Resize(size_); 703 display_->Resize(size_);
720 host_->SetOutputSurface(std::move(delegated_output_surface)); 704 host_->SetOutputSurface(std::move(delegated_output_surface));
721 } 705 }
722 706
723 void CompositorImpl::PopulateGpuCapabilities( 707 void CompositorImpl::PopulateGpuCapabilities(
724 gpu::Capabilities gpu_capabilities) { 708 gpu::Capabilities gpu_capabilities) {
725 gpu_capabilities_ = gpu_capabilities; 709 gpu_capabilities_ = gpu_capabilities;
726 } 710 }
727 711
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 void CompositorImpl::SetNeedsAnimate() { 783 void CompositorImpl::SetNeedsAnimate() {
800 needs_animate_ = true; 784 needs_animate_ = true;
801 if (!host_->visible()) 785 if (!host_->visible())
802 return; 786 return;
803 787
804 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); 788 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate");
805 host_->SetNeedsAnimate(); 789 host_->SetNeedsAnimate();
806 } 790 }
807 791
808 } // namespace content 792 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698