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