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

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

Issue 1821863002: Hook up ui::Compositor to Display's BeginFrameSource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Really revert task runner changes Created 4 years, 8 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 <utility> 10 #include <utility>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "ui/android/window_android.h" 67 #include "ui/android/window_android.h"
68 #include "ui/gfx/android/device_display_info.h" 68 #include "ui/gfx/android/device_display_info.h"
69 #include "ui/gfx/swap_result.h" 69 #include "ui/gfx/swap_result.h"
70 70
71 namespace content { 71 namespace content {
72 72
73 namespace { 73 namespace {
74 74
75 const unsigned int kMaxDisplaySwapBuffers = 1U; 75 const unsigned int kMaxDisplaySwapBuffers = 1U;
76 76
77 class ExternalBeginFrameSource : public cc::BeginFrameSourceBase,
78 public CompositorImpl::VSyncObserver {
79 public:
80 ExternalBeginFrameSource(CompositorImpl* compositor)
81 : compositor_(compositor) {
82 compositor_->AddObserver(this);
83 }
84
85 ~ExternalBeginFrameSource() override {
86 compositor_->RemoveObserver(this);
87 }
88
89 // cc::BeginFrameSourceBase implementation:
90 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override {
91 compositor_->OnNeedsBeginFramesChange(needs_begin_frames);
92 }
93
94 // CompositorImpl::VSyncObserver implementation:
95 void OnVSync(base::TimeTicks frame_time,
96 base::TimeDelta vsync_period) override {
97 CallOnBeginFrame(cc::BeginFrameArgs::Create(
98 BEGINFRAME_FROM_HERE, frame_time, base::TimeTicks::Now(), vsync_period,
99 cc::BeginFrameArgs::NORMAL));
100 }
101
102 private:
103 CompositorImpl* compositor_;
104 };
105
77 // Used to override capabilities_.adjust_deadline_for_parent to false 106 // Used to override capabilities_.adjust_deadline_for_parent to false
78 class OutputSurfaceWithoutParent : public cc::OutputSurface, 107 class OutputSurfaceWithoutParent : public cc::OutputSurface,
79 public CompositorImpl::VSyncObserver { 108 public CompositorImpl::VSyncObserver {
80 public: 109 public:
81 OutputSurfaceWithoutParent( 110 OutputSurfaceWithoutParent(
82 CompositorImpl* compositor, 111 CompositorImpl* compositor,
83 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, 112 const scoped_refptr<ContextProviderCommandBuffer>& context_provider,
84 const base::Callback<void(gpu::Capabilities)>& 113 const base::Callback<void(gpu::Capabilities)>&
85 populate_gpu_capabilities_callback) 114 populate_gpu_capabilities_callback,
115 scoped_ptr<ExternalBeginFrameSource> begin_frame_source)
86 : cc::OutputSurface(context_provider), 116 : cc::OutputSurface(context_provider),
87 compositor_(compositor), 117 compositor_(compositor),
88 populate_gpu_capabilities_callback_(populate_gpu_capabilities_callback), 118 populate_gpu_capabilities_callback_(populate_gpu_capabilities_callback),
89 swap_buffers_completion_callback_( 119 swap_buffers_completion_callback_(
90 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted, 120 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted,
91 base::Unretained(this))), 121 base::Unretained(this))),
92 overlay_candidate_validator_( 122 overlay_candidate_validator_(
93 new BrowserCompositorOverlayCandidateValidatorAndroid()) { 123 new BrowserCompositorOverlayCandidateValidatorAndroid()),
124 begin_frame_source_(std::move(begin_frame_source)) {
94 capabilities_.adjust_deadline_for_parent = false; 125 capabilities_.adjust_deadline_for_parent = false;
95 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers; 126 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers;
96 } 127 }
97 128
98 ~OutputSurfaceWithoutParent() override { compositor_->RemoveObserver(this); } 129 ~OutputSurfaceWithoutParent() override { compositor_->RemoveObserver(this); }
99 130
100 void SwapBuffers(cc::CompositorFrame* frame) override { 131 void SwapBuffers(cc::CompositorFrame* frame) override {
101 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); 132 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info);
102 if (frame->gl_frame_data->sub_buffer_rect.IsEmpty()) { 133 if (frame->gl_frame_data->sub_buffer_rect.IsEmpty()) {
103 context_provider_->ContextSupport()->CommitOverlayPlanes(); 134 context_provider_->ContextSupport()->CommitOverlayPlanes();
104 } else { 135 } else {
105 DCHECK(frame->gl_frame_data->sub_buffer_rect == 136 DCHECK(frame->gl_frame_data->sub_buffer_rect ==
106 gfx::Rect(frame->gl_frame_data->size)); 137 gfx::Rect(frame->gl_frame_data->size));
107 context_provider_->ContextSupport()->Swap(); 138 context_provider_->ContextSupport()->Swap();
108 } 139 }
109 client_->DidSwapBuffers(); 140 client_->DidSwapBuffers();
110 } 141 }
111 142
112 bool BindToClient(cc::OutputSurfaceClient* client) override { 143 bool BindToClient(cc::OutputSurfaceClient* client) override {
113 if (!OutputSurface::BindToClient(client)) 144 if (!OutputSurface::BindToClient(client))
114 return false; 145 return false;
115 146
116 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( 147 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback(
117 swap_buffers_completion_callback_.callback()); 148 swap_buffers_completion_callback_.callback());
118 149
119 populate_gpu_capabilities_callback_.Run( 150 populate_gpu_capabilities_callback_.Run(
120 context_provider_->ContextCapabilities().gpu); 151 context_provider_->ContextCapabilities().gpu);
121 compositor_->AddObserver(this); 152 compositor_->AddObserver(this);
122 153
154 client->SetBeginFrameSource(begin_frame_source_.get());
155
123 return true; 156 return true;
124 } 157 }
125 158
159 void DetachFromClient() override {
160 client_->SetBeginFrameSource(nullptr);
161 OutputSurface::DetachFromClient();
162 }
163
126 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override { 164 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override {
127 return overlay_candidate_validator_.get(); 165 return overlay_candidate_validator_.get();
128 } 166 }
129 167
130 private: 168 private:
131 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() { 169 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() {
132 ContextProviderCommandBuffer* provider_command_buffer = 170 ContextProviderCommandBuffer* provider_command_buffer =
133 static_cast<content::ContextProviderCommandBuffer*>( 171 static_cast<content::ContextProviderCommandBuffer*>(
134 context_provider_.get()); 172 context_provider_.get());
135 gpu::CommandBufferProxyImpl* command_buffer_proxy = 173 gpu::CommandBufferProxyImpl* command_buffer_proxy =
136 provider_command_buffer->GetCommandBufferProxy(); 174 provider_command_buffer->GetCommandBufferProxy();
137 DCHECK(command_buffer_proxy); 175 DCHECK(command_buffer_proxy);
138 return command_buffer_proxy; 176 return command_buffer_proxy;
139 } 177 }
140 178
141 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, 179 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info,
142 gfx::SwapResult result) { 180 gfx::SwapResult result) {
143 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); 181 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info);
144 OutputSurface::OnSwapBuffersComplete(); 182 OutputSurface::OnSwapBuffersComplete();
145 } 183 }
146 184
147 void OnVSync(base::TimeTicks timebase, base::TimeDelta interval) override { 185 void OnVSync(base::TimeTicks timebase, base::TimeDelta interval) override {
148 CommitVSyncParameters(timebase, interval); 186 client_->CommitVSyncParameters(timebase, interval);
149 } 187 }
150 188
189 private:
151 CompositorImpl* compositor_; 190 CompositorImpl* compositor_;
152 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; 191 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_;
153 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, 192 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&,
154 gfx::SwapResult)> 193 gfx::SwapResult)>
155 swap_buffers_completion_callback_; 194 swap_buffers_completion_callback_;
156 scoped_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; 195 scoped_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_;
157 }; 196 scoped_ptr<ExternalBeginFrameSource> begin_frame_source_;
158
159 class ExternalBeginFrameSource : public cc::BeginFrameSourceBase,
160 public CompositorImpl::VSyncObserver {
161 public:
162 ExternalBeginFrameSource(CompositorImpl* compositor)
163 : compositor_(compositor) {
164 compositor_->AddObserver(this);
165 }
166
167 ~ExternalBeginFrameSource() override {
168 compositor_->RemoveObserver(this);
169 }
170
171 // cc::BeginFrameSourceBase implementation:
172 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override {
173 compositor_->OnNeedsBeginFramesChange(needs_begin_frames);
174 }
175
176 // CompositorImpl::VSyncObserver implementation:
177 void OnVSync(base::TimeTicks frame_time,
178 base::TimeDelta vsync_period) override {
179 CallOnBeginFrame(cc::BeginFrameArgs::Create(
180 BEGINFRAME_FROM_HERE, frame_time, base::TimeTicks::Now(), vsync_period,
181 cc::BeginFrameArgs::NORMAL));
182 }
183
184 private:
185 CompositorImpl* compositor_;
186 }; 197 };
187 198
188 static bool g_initialized = false; 199 static bool g_initialized = false;
189 200
190 base::LazyInstance<cc::SurfaceManager> g_surface_manager = 201 base::LazyInstance<cc::SurfaceManager> g_surface_manager =
191 LAZY_INSTANCE_INITIALIZER; 202 LAZY_INSTANCE_INITIALIZER;
192 203
193 int g_surface_id_namespace = 0; 204 int g_surface_id_namespace = 0;
194 205
195 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { 206 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 337 }
327 338
328 void CompositorImpl::CreateLayerTreeHost() { 339 void CompositorImpl::CreateLayerTreeHost() {
329 DCHECK(!host_); 340 DCHECK(!host_);
330 341
331 cc::LayerTreeSettings settings; 342 cc::LayerTreeSettings settings;
332 settings.renderer_settings.refresh_rate = 60.0; 343 settings.renderer_settings.refresh_rate = 60.0;
333 settings.renderer_settings.allow_antialiasing = false; 344 settings.renderer_settings.allow_antialiasing = false;
334 settings.renderer_settings.highp_threshold_min = 2048; 345 settings.renderer_settings.highp_threshold_min = 2048;
335 settings.use_zero_copy = true; 346 settings.use_zero_copy = true;
336 settings.use_external_begin_frame_source = true;
337 347
338 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 348 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
339 settings.initial_debug_state.SetRecordRenderingStats( 349 settings.initial_debug_state.SetRecordRenderingStats(
340 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); 350 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
341 settings.initial_debug_state.show_fps_counter = 351 settings.initial_debug_state.show_fps_counter =
342 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); 352 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
343 settings.single_thread_proxy_scheduler = true; 353 settings.single_thread_proxy_scheduler = true;
344 354
345 cc::LayerTreeHost::InitParams params; 355 cc::LayerTreeHost::InitParams params;
346 params.client = this; 356 params.client = this;
347 params.shared_bitmap_manager = HostSharedBitmapManager::current(); 357 params.shared_bitmap_manager = HostSharedBitmapManager::current();
348 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); 358 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current();
349 params.task_graph_runner = g_task_graph_runner.Pointer(); 359 params.task_graph_runner = g_task_graph_runner.Pointer();
350 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); 360 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
351 params.settings = &settings; 361 params.settings = &settings;
352 params.external_begin_frame_source.reset(new ExternalBeginFrameSource(this));
353 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params); 362 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params);
354 DCHECK(!host_->visible()); 363 DCHECK(!host_->visible());
355 host_->SetRootLayer(root_layer_); 364 host_->SetRootLayer(root_layer_);
356 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); 365 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace());
357 host_->SetViewportSize(size_); 366 host_->SetViewportSize(size_);
358 host_->set_has_transparent_background(has_transparent_background_); 367 host_->set_has_transparent_background(has_transparent_background_);
359 host_->SetDeviceScaleFactor(device_scale_factor_); 368 host_->SetDeviceScaleFactor(device_scale_factor_);
360 369
361 if (needs_animate_) 370 if (needs_animate_)
362 host_->SetNeedsAnimate(); 371 host_->SetNeedsAnimate();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 ContextProviderCommandBuffer::Create( 553 ContextProviderCommandBuffer::Create(
545 CreateGpuProcessViewContext(gpu_channel_host, attributes, 554 CreateGpuProcessViewContext(gpu_channel_host, attributes,
546 surface_id_), 555 surface_id_),
547 DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT)); 556 DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT));
548 DCHECK(context_provider.get()); 557 DCHECK(context_provider.get());
549 558
550 scoped_ptr<cc::OutputSurface> real_output_surface( 559 scoped_ptr<cc::OutputSurface> real_output_surface(
551 new OutputSurfaceWithoutParent( 560 new OutputSurfaceWithoutParent(
552 this, context_provider, 561 this, context_provider,
553 base::Bind(&CompositorImpl::PopulateGpuCapabilities, 562 base::Bind(&CompositorImpl::PopulateGpuCapabilities,
554 base::Unretained(this)))); 563 base::Unretained(this)),
564 make_scoped_ptr(new ExternalBeginFrameSource(this))));
555 565
556 cc::SurfaceManager* manager = GetSurfaceManager(); 566 cc::SurfaceManager* manager = GetSurfaceManager();
557 display_client_.reset( 567 display_client_.reset(
558 new cc::OnscreenDisplayClient(std::move(real_output_surface), manager, 568 new cc::OnscreenDisplayClient(std::move(real_output_surface), manager,
559 HostSharedBitmapManager::current(), 569 HostSharedBitmapManager::current(),
560 BrowserGpuMemoryBufferManager::current(), 570 BrowserGpuMemoryBufferManager::current(),
561 host_->settings().renderer_settings, 571 host_->settings().renderer_settings,
562 base::ThreadTaskRunnerHandle::Get())); 572 base::ThreadTaskRunnerHandle::Get().get(),
573 surface_id_allocator_->id_namespace()));
563 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( 574 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface(
564 new cc::SurfaceDisplayOutputSurface( 575 new cc::SurfaceDisplayOutputSurface(
565 manager, surface_id_allocator_.get(), context_provider, nullptr)); 576 manager, surface_id_allocator_.get(), context_provider, nullptr));
566 577
567 display_client_->set_surface_output_surface(surface_output_surface.get()); 578 display_client_->set_surface_output_surface(surface_output_surface.get());
568 surface_output_surface->set_display_client(display_client_.get()); 579 surface_output_surface->set_display_client(display_client_.get());
569 display_client_->display()->Resize(size_); 580 display_client_->display()->Resize(size_);
570 host_->SetOutputSurface(std::move(surface_output_surface)); 581 host_->SetOutputSurface(std::move(surface_output_surface));
571 } 582 }
572 583
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 657
647 void CompositorImpl::SetNeedsAnimate() { 658 void CompositorImpl::SetNeedsAnimate() {
648 needs_animate_ = true; 659 needs_animate_ = true;
649 if (!host_->visible()) 660 if (!host_->visible())
650 return; 661 return;
651 662
652 host_->SetNeedsAnimate(); 663 host_->SetNeedsAnimate();
653 } 664 }
654 665
655 } // namespace content 666 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698