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