OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/android/synchronous_compositor_frame_sink.h" | 5 #include "content/renderer/android/synchronous_compositor_frame_sink.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "third_party/skia/include/core/SkCanvas.h" | 41 #include "third_party/skia/include/core/SkCanvas.h" |
42 #include "ui/gfx/geometry/rect_conversions.h" | 42 #include "ui/gfx/geometry/rect_conversions.h" |
43 #include "ui/gfx/skia_util.h" | 43 #include "ui/gfx/skia_util.h" |
44 #include "ui/gfx/transform.h" | 44 #include "ui/gfx/transform.h" |
45 | 45 |
46 namespace content { | 46 namespace content { |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 const int64_t kFallbackTickTimeoutInMilliseconds = 100; | 50 const int64_t kFallbackTickTimeoutInMilliseconds = 100; |
51 const cc::FrameSinkId kFrameSinkId(1, 1); | 51 const cc::FrameSinkId kRootFrameSinkId(1, 1); |
| 52 const cc::FrameSinkId kChildFrameSinkId(1, 2); |
52 | 53 |
53 // Do not limit number of resources, so use an unrealistically high value. | 54 // Do not limit number of resources, so use an unrealistically high value. |
54 const size_t kNumResourcesLimit = 10 * 1000 * 1000; | 55 const size_t kNumResourcesLimit = 10 * 1000 * 1000; |
55 | 56 |
56 class SoftwareDevice : public cc::SoftwareOutputDevice { | 57 class SoftwareDevice : public cc::SoftwareOutputDevice { |
57 public: | 58 public: |
58 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {} | 59 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {} |
59 | 60 |
60 void Resize(const gfx::Size& pixel_size, float device_scale_factor) override { | 61 void Resize(const gfx::Size& pixel_size, float device_scale_factor) override { |
61 // Intentional no-op: canvas size is controlled by the embedder. | 62 // Intentional no-op: canvas size is controlled by the embedder. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 gpu_memory_buffer_manager, | 116 gpu_memory_buffer_manager, |
116 nullptr), | 117 nullptr), |
117 routing_id_(routing_id), | 118 routing_id_(routing_id), |
118 compositor_frame_sink_id_(compositor_frame_sink_id), | 119 compositor_frame_sink_id_(compositor_frame_sink_id), |
119 registry_(registry), | 120 registry_(registry), |
120 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), | 121 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), |
121 memory_policy_(0u), | 122 memory_policy_(0u), |
122 frame_swap_message_queue_(frame_swap_message_queue), | 123 frame_swap_message_queue_(frame_swap_message_queue), |
123 surface_manager_(new cc::SurfaceManager), | 124 surface_manager_(new cc::SurfaceManager), |
124 surface_id_allocator_(new cc::SurfaceIdAllocator()), | 125 surface_id_allocator_(new cc::SurfaceIdAllocator()), |
125 surface_factory_( | 126 root_factory_(new cc::SurfaceFactory(kRootFrameSinkId, |
126 new cc::SurfaceFactory(kFrameSinkId, surface_manager_.get(), this)), | 127 surface_manager_.get(), |
| 128 this)), |
| 129 child_factory_(new cc::SurfaceFactory(kChildFrameSinkId, |
| 130 surface_manager_.get(), |
| 131 this)), |
127 begin_frame_source_(std::move(begin_frame_source)) { | 132 begin_frame_source_(std::move(begin_frame_source)) { |
128 DCHECK(registry_); | 133 DCHECK(registry_); |
129 DCHECK(sender_); | 134 DCHECK(sender_); |
130 DCHECK(begin_frame_source_); | 135 DCHECK(begin_frame_source_); |
131 thread_checker_.DetachFromThread(); | 136 thread_checker_.DetachFromThread(); |
132 memory_policy_.priority_cutoff_when_visible = | 137 memory_policy_.priority_cutoff_when_visible = |
133 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 138 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
134 } | 139 } |
135 | 140 |
136 SynchronousCompositorFrameSink::~SynchronousCompositorFrameSink() = default; | 141 SynchronousCompositorFrameSink::~SynchronousCompositorFrameSink() = default; |
(...skipping 24 matching lines...) Expand all Loading... |
161 return false; | 166 return false; |
162 | 167 |
163 DCHECK(begin_frame_source_); | 168 DCHECK(begin_frame_source_); |
164 client_->SetBeginFrameSource(begin_frame_source_.get()); | 169 client_->SetBeginFrameSource(begin_frame_source_.get()); |
165 client_->SetMemoryPolicy(memory_policy_); | 170 client_->SetMemoryPolicy(memory_policy_); |
166 client_->SetTreeActivationCallback( | 171 client_->SetTreeActivationCallback( |
167 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, | 172 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, |
168 base::Unretained(this))); | 173 base::Unretained(this))); |
169 registry_->RegisterCompositorFrameSink(routing_id_, this); | 174 registry_->RegisterCompositorFrameSink(routing_id_, this); |
170 | 175 |
171 surface_manager_->RegisterFrameSinkId(kFrameSinkId); | 176 surface_manager_->RegisterFrameSinkId(kRootFrameSinkId); |
172 surface_manager_->RegisterSurfaceFactoryClient(kFrameSinkId, this); | 177 surface_manager_->RegisterFrameSinkId(kChildFrameSinkId); |
| 178 surface_manager_->RegisterSurfaceFactoryClient(kRootFrameSinkId, this); |
| 179 surface_manager_->RegisterSurfaceFactoryClient(kChildFrameSinkId, this); |
173 | 180 |
174 cc::RendererSettings software_renderer_settings; | 181 cc::RendererSettings software_renderer_settings; |
175 | 182 |
176 auto output_surface = base::MakeUnique<SoftwareOutputSurface>( | 183 auto output_surface = base::MakeUnique<SoftwareOutputSurface>( |
177 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_)); | 184 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_)); |
178 software_output_surface_ = output_surface.get(); | 185 software_output_surface_ = output_surface.get(); |
179 | 186 |
180 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as | 187 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as |
181 // this Display is only used for resourcesless software draws, where no | 188 // this Display is only used for resourcesless software draws, where no |
182 // resources are included in the frame swapped from the compositor. So there | 189 // resources are included in the frame swapped from the compositor. So there |
183 // is no need for these. | 190 // is no need for these. |
184 display_.reset(new cc::Display( | 191 display_.reset(new cc::Display( |
185 nullptr /* shared_bitmap_manager */, | 192 nullptr /* shared_bitmap_manager */, |
186 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, | 193 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, |
187 kFrameSinkId, nullptr /* begin_frame_source */, std::move(output_surface), | 194 kRootFrameSinkId, nullptr /* begin_frame_source */, |
188 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); | 195 std::move(output_surface), nullptr /* scheduler */, |
| 196 nullptr /* texture_mailbox_deleter */)); |
189 display_->Initialize(&display_client_, surface_manager_.get()); | 197 display_->Initialize(&display_client_, surface_manager_.get()); |
190 display_->SetVisible(true); | 198 display_->SetVisible(true); |
191 return true; | 199 return true; |
192 } | 200 } |
193 | 201 |
194 void SynchronousCompositorFrameSink::DetachFromClient() { | 202 void SynchronousCompositorFrameSink::DetachFromClient() { |
195 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
196 client_->SetBeginFrameSource(nullptr); | 204 client_->SetBeginFrameSource(nullptr); |
197 // Destroy the begin frame source on the same thread it was bound on. | 205 // Destroy the begin frame source on the same thread it was bound on. |
198 begin_frame_source_ = nullptr; | 206 begin_frame_source_ = nullptr; |
199 registry_->UnregisterCompositorFrameSink(routing_id_, this); | 207 registry_->UnregisterCompositorFrameSink(routing_id_, this); |
200 client_->SetTreeActivationCallback(base::Closure()); | 208 client_->SetTreeActivationCallback(base::Closure()); |
201 if (root_local_frame_id_.is_valid()) { | 209 root_factory_->EvictSurface(); |
202 surface_factory_->Destroy(root_local_frame_id_); | 210 child_factory_->EvictSurface(); |
203 surface_factory_->Destroy(child_local_frame_id_); | 211 surface_manager_->UnregisterSurfaceFactoryClient(kRootFrameSinkId); |
204 } | 212 surface_manager_->UnregisterSurfaceFactoryClient(kChildFrameSinkId); |
205 surface_manager_->UnregisterSurfaceFactoryClient(kFrameSinkId); | 213 surface_manager_->InvalidateFrameSinkId(kRootFrameSinkId); |
206 surface_manager_->InvalidateFrameSinkId(kFrameSinkId); | 214 surface_manager_->InvalidateFrameSinkId(kChildFrameSinkId); |
207 software_output_surface_ = nullptr; | 215 software_output_surface_ = nullptr; |
208 display_ = nullptr; | 216 display_ = nullptr; |
209 surface_factory_ = nullptr; | 217 child_factory_ = nullptr; |
| 218 root_factory_ = nullptr; |
210 surface_id_allocator_ = nullptr; | 219 surface_id_allocator_ = nullptr; |
211 surface_manager_ = nullptr; | 220 surface_manager_ = nullptr; |
212 cc::CompositorFrameSink::DetachFromClient(); | 221 cc::CompositorFrameSink::DetachFromClient(); |
213 CancelFallbackTick(); | 222 CancelFallbackTick(); |
214 } | 223 } |
215 | 224 |
216 static void NoOpDrawCallback() {} | 225 static void NoOpDrawCallback() {} |
217 | 226 |
218 void SynchronousCompositorFrameSink::SubmitCompositorFrame( | 227 void SynchronousCompositorFrameSink::SubmitCompositorFrame( |
219 cc::CompositorFrame frame) { | 228 cc::CompositorFrame frame) { |
(...skipping 10 matching lines...) Expand all Loading... |
230 | 239 |
231 cc::CompositorFrame submit_frame; | 240 cc::CompositorFrame submit_frame; |
232 | 241 |
233 if (in_software_draw_) { | 242 if (in_software_draw_) { |
234 // The frame we send to the client is actually just the metadata. Preserve | 243 // The frame we send to the client is actually just the metadata. Preserve |
235 // the |frame| for the software path below. | 244 // the |frame| for the software path below. |
236 submit_frame.metadata = frame.metadata.Clone(); | 245 submit_frame.metadata = frame.metadata.Clone(); |
237 | 246 |
238 if (!root_local_frame_id_.is_valid()) { | 247 if (!root_local_frame_id_.is_valid()) { |
239 root_local_frame_id_ = surface_id_allocator_->GenerateId(); | 248 root_local_frame_id_ = surface_id_allocator_->GenerateId(); |
240 surface_factory_->Create(root_local_frame_id_); | |
241 child_local_frame_id_ = surface_id_allocator_->GenerateId(); | 249 child_local_frame_id_ = surface_id_allocator_->GenerateId(); |
242 surface_factory_->Create(child_local_frame_id_); | |
243 } | 250 } |
244 | 251 |
245 display_->SetLocalFrameId(root_local_frame_id_, | 252 display_->SetLocalFrameId(root_local_frame_id_, |
246 frame.metadata.device_scale_factor); | 253 frame.metadata.device_scale_factor); |
247 | 254 |
248 // The layer compositor should be giving a frame that covers the | 255 // The layer compositor should be giving a frame that covers the |
249 // |sw_viewport_for_current_draw_| but at 0,0. | 256 // |sw_viewport_for_current_draw_| but at 0,0. |
250 gfx::Size child_size = sw_viewport_for_current_draw_.size(); | 257 gfx::Size child_size = sw_viewport_for_current_draw_.size(); |
251 DCHECK(gfx::Rect(child_size) == frame.render_pass_list.back()->output_rect); | 258 DCHECK(gfx::Rect(child_size) == frame.render_pass_list.back()->output_rect); |
252 | 259 |
(...skipping 24 matching lines...) Expand all Loading... |
277 | 284 |
278 // The RenderPass has a single SurfaceDrawQuad (and SharedQuadState for it). | 285 // The RenderPass has a single SurfaceDrawQuad (and SharedQuadState for it). |
279 auto* shared_quad_state = | 286 auto* shared_quad_state = |
280 embed_render_pass->CreateAndAppendSharedQuadState(); | 287 embed_render_pass->CreateAndAppendSharedQuadState(); |
281 auto* surface_quad = | 288 auto* surface_quad = |
282 embed_render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 289 embed_render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
283 shared_quad_state->SetAll( | 290 shared_quad_state->SetAll( |
284 child_transform, child_size, gfx::Rect(child_size), | 291 child_transform, child_size, gfx::Rect(child_size), |
285 gfx::Rect() /* clip_rect */, false /* is_clipped */, 1.f /* opacity */, | 292 gfx::Rect() /* clip_rect */, false /* is_clipped */, 1.f /* opacity */, |
286 SkBlendMode::kSrcOver, 0 /* sorting_context_id */); | 293 SkBlendMode::kSrcOver, 0 /* sorting_context_id */); |
287 surface_quad->SetNew(shared_quad_state, gfx::Rect(child_size), | 294 surface_quad->SetNew( |
288 gfx::Rect(child_size), | 295 shared_quad_state, gfx::Rect(child_size), gfx::Rect(child_size), |
289 cc::SurfaceId(kFrameSinkId, child_local_frame_id_)); | 296 cc::SurfaceId(kChildFrameSinkId, child_local_frame_id_)); |
290 | 297 |
291 surface_factory_->SubmitCompositorFrame( | 298 child_factory_->SubmitCompositorFrame( |
292 child_local_frame_id_, std::move(frame), base::Bind(&NoOpDrawCallback)); | 299 child_local_frame_id_, std::move(frame), base::Bind(&NoOpDrawCallback)); |
293 surface_factory_->SubmitCompositorFrame(root_local_frame_id_, | 300 root_factory_->SubmitCompositorFrame(root_local_frame_id_, |
294 std::move(embed_frame), | 301 std::move(embed_frame), |
295 base::Bind(&NoOpDrawCallback)); | 302 base::Bind(&NoOpDrawCallback)); |
296 display_->DrawAndSwap(); | 303 display_->DrawAndSwap(); |
297 } else { | 304 } else { |
298 // For hardware draws we send the whole frame to the client so it can draw | 305 // For hardware draws we send the whole frame to the client so it can draw |
299 // the content in it. | 306 // the content in it. |
300 submit_frame = std::move(frame); | 307 submit_frame = std::move(frame); |
301 } | 308 } |
302 | 309 |
303 sync_client_->SubmitCompositorFrame(compositor_frame_sink_id_, | 310 sync_client_->SubmitCompositorFrame(compositor_frame_sink_id_, |
304 std::move(submit_frame)); | 311 std::move(submit_frame)); |
305 DeliverMessages(); | 312 DeliverMessages(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 client_->ReclaimResources(resources); | 469 client_->ReclaimResources(resources); |
463 } | 470 } |
464 | 471 |
465 void SynchronousCompositorFrameSink::SetBeginFrameSource( | 472 void SynchronousCompositorFrameSink::SetBeginFrameSource( |
466 cc::BeginFrameSource* begin_frame_source) { | 473 cc::BeginFrameSource* begin_frame_source) { |
467 // Software output is synchronous and doesn't use a BeginFrameSource. | 474 // Software output is synchronous and doesn't use a BeginFrameSource. |
468 NOTREACHED(); | 475 NOTREACHED(); |
469 } | 476 } |
470 | 477 |
471 } // namespace content | 478 } // namespace content |
OLD | NEW |