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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return; | 236 return; |
237 } | 237 } |
238 | 238 |
239 cc::CompositorFrame submit_frame; | 239 cc::CompositorFrame submit_frame; |
240 | 240 |
241 if (in_software_draw_) { | 241 if (in_software_draw_) { |
242 // The frame we send to the client is actually just the metadata. Preserve | 242 // The frame we send to the client is actually just the metadata. Preserve |
243 // the |frame| for the software path below. | 243 // the |frame| for the software path below. |
244 submit_frame.metadata = frame.metadata.Clone(); | 244 submit_frame.metadata = frame.metadata.Clone(); |
245 | 245 |
246 if (!root_local_surface_id_.is_valid()) { | |
247 root_local_surface_id_ = local_surface_id_allocator_->GenerateId(); | |
248 child_local_surface_id_ = local_surface_id_allocator_->GenerateId(); | |
249 } | |
250 | |
251 display_->SetLocalSurfaceId(root_local_surface_id_, | |
252 frame.metadata.device_scale_factor); | |
253 | |
254 // The layer compositor should be giving a frame that covers the | 246 // The layer compositor should be giving a frame that covers the |
255 // |sw_viewport_for_current_draw_| but at 0,0. | 247 // |sw_viewport_for_current_draw_| but at 0,0. |
256 gfx::Size child_size = sw_viewport_for_current_draw_.size(); | 248 gfx::Size child_size = sw_viewport_for_current_draw_.size(); |
257 DCHECK(gfx::Rect(child_size) == frame.render_pass_list.back()->output_rect); | 249 DCHECK(gfx::Rect(child_size) == frame.render_pass_list.back()->output_rect); |
258 | 250 |
259 // Make a size that covers from 0,0 and includes the area coming from the | 251 // Make a size that covers from 0,0 and includes the area coming from the |
260 // layer compositor. | 252 // layer compositor. |
261 gfx::Size display_size(sw_viewport_for_current_draw_.right(), | 253 gfx::Size display_size(sw_viewport_for_current_draw_.right(), |
262 sw_viewport_for_current_draw_.bottom()); | 254 sw_viewport_for_current_draw_.bottom()); |
263 display_->Resize(display_size); | 255 display_->Resize(display_size); |
264 | 256 |
| 257 if (!root_local_surface_id_.is_valid() || display_size_ != display_size || |
| 258 device_scale_factor_ != frame.metadata.device_scale_factor) { |
| 259 root_local_surface_id_ = local_surface_id_allocator_->GenerateId(); |
| 260 display_size_ = display_size; |
| 261 device_scale_factor_ = frame.metadata.device_scale_factor; |
| 262 } |
| 263 |
| 264 if (!child_local_surface_id_.is_valid() || child_size_ != child_size || |
| 265 device_scale_factor_ != frame.metadata.device_scale_factor) { |
| 266 child_local_surface_id_ = local_surface_id_allocator_->GenerateId(); |
| 267 child_size_ = child_size; |
| 268 device_scale_factor_ = frame.metadata.device_scale_factor; |
| 269 } |
| 270 |
| 271 display_->SetLocalSurfaceId(root_local_surface_id_, |
| 272 frame.metadata.device_scale_factor); |
| 273 |
265 // The offset for the child frame relative to the origin of the canvas being | 274 // The offset for the child frame relative to the origin of the canvas being |
266 // drawn into. | 275 // drawn into. |
267 gfx::Transform child_transform; | 276 gfx::Transform child_transform; |
268 child_transform.Translate( | 277 child_transform.Translate( |
269 gfx::Vector2dF(sw_viewport_for_current_draw_.OffsetFromOrigin())); | 278 gfx::Vector2dF(sw_viewport_for_current_draw_.OffsetFromOrigin())); |
270 | 279 |
271 // Make a root frame that embeds the frame coming from the layer compositor | 280 // Make a root frame that embeds the frame coming from the layer compositor |
272 // and positions it based on the provided viewport. | 281 // and positions it based on the provided viewport. |
273 // TODO(danakj): We could apply the transform here instead of passing it to | 282 // TODO(danakj): We could apply the transform here instead of passing it to |
274 // the CompositorFrameSink client too? (We'd have to do the same for | 283 // the CompositorFrameSink client too? (We'd have to do the same for |
275 // hardware frames in SurfacesInstance?) | 284 // hardware frames in SurfacesInstance?) |
276 cc::CompositorFrame embed_frame; | 285 cc::CompositorFrame embed_frame; |
277 embed_frame.metadata.begin_frame_ack = frame.metadata.begin_frame_ack; | 286 embed_frame.metadata.begin_frame_ack = frame.metadata.begin_frame_ack; |
| 287 embed_frame.metadata.device_scale_factor = |
| 288 frame.metadata.device_scale_factor; |
278 embed_frame.render_pass_list.push_back(cc::RenderPass::Create()); | 289 embed_frame.render_pass_list.push_back(cc::RenderPass::Create()); |
279 | 290 |
280 // The embedding RenderPass covers the entire Display's area. | 291 // The embedding RenderPass covers the entire Display's area. |
281 const auto& embed_render_pass = embed_frame.render_pass_list.back(); | 292 const auto& embed_render_pass = embed_frame.render_pass_list.back(); |
282 embed_render_pass->SetNew(1, gfx::Rect(display_size), | 293 embed_render_pass->SetNew(1, gfx::Rect(display_size), |
283 gfx::Rect(display_size), gfx::Transform()); | 294 gfx::Rect(display_size), gfx::Transform()); |
284 embed_render_pass->has_transparent_background = false; | 295 embed_render_pass->has_transparent_background = false; |
285 | 296 |
286 // The RenderPass has a single SurfaceDrawQuad (and SharedQuadState for it). | 297 // The RenderPass has a single SurfaceDrawQuad (and SharedQuadState for it). |
287 auto* shared_quad_state = | 298 auto* shared_quad_state = |
288 embed_render_pass->CreateAndAppendSharedQuadState(); | 299 embed_render_pass->CreateAndAppendSharedQuadState(); |
289 auto* surface_quad = | 300 auto* surface_quad = |
290 embed_render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 301 embed_render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
291 shared_quad_state->SetAll( | 302 shared_quad_state->SetAll( |
292 child_transform, gfx::Rect(child_size), gfx::Rect(child_size), | 303 child_transform, gfx::Rect(child_size), gfx::Rect(child_size), |
293 gfx::Rect() /* clip_rect */, false /* is_clipped */, 1.f /* opacity */, | 304 gfx::Rect() /* clip_rect */, false /* is_clipped */, 1.f /* opacity */, |
294 SkBlendMode::kSrcOver, 0 /* sorting_context_id */); | 305 SkBlendMode::kSrcOver, 0 /* sorting_context_id */); |
295 surface_quad->SetNew( | 306 surface_quad->SetNew( |
296 shared_quad_state, gfx::Rect(child_size), gfx::Rect(child_size), | 307 shared_quad_state, gfx::Rect(child_size), gfx::Rect(child_size), |
297 cc::SurfaceId(kChildFrameSinkId, child_local_surface_id_), | 308 cc::SurfaceId(kChildFrameSinkId, child_local_surface_id_), |
298 cc::SurfaceDrawQuadType::PRIMARY, nullptr); | 309 cc::SurfaceDrawQuadType::PRIMARY, nullptr); |
299 | 310 |
300 child_support_->SubmitCompositorFrame(child_local_surface_id_, | 311 bool result = child_support_->SubmitCompositorFrame(child_local_surface_id_, |
301 std::move(frame)); | 312 std::move(frame)); |
302 root_support_->SubmitCompositorFrame(root_local_surface_id_, | 313 DCHECK(result); |
303 std::move(embed_frame)); | 314 result = root_support_->SubmitCompositorFrame(root_local_surface_id_, |
| 315 std::move(embed_frame)); |
| 316 DCHECK(result); |
304 display_->DrawAndSwap(); | 317 display_->DrawAndSwap(); |
305 } else { | 318 } else { |
306 // For hardware draws we send the whole frame to the client so it can draw | 319 // For hardware draws we send the whole frame to the client so it can draw |
307 // the content in it. | 320 // the content in it. |
308 submit_frame = std::move(frame); | 321 submit_frame = std::move(frame); |
309 } | 322 } |
310 | 323 |
311 sync_client_->SubmitCompositorFrame(compositor_frame_sink_id_, | 324 sync_client_->SubmitCompositorFrame(compositor_frame_sink_id_, |
312 std::move(submit_frame)); | 325 std::move(submit_frame)); |
313 DeliverMessages(); | 326 DeliverMessages(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 const cc::ReturnedResourceArray& resources) { | 495 const cc::ReturnedResourceArray& resources) { |
483 DCHECK(resources.empty()); | 496 DCHECK(resources.empty()); |
484 client_->ReclaimResources(resources); | 497 client_->ReclaimResources(resources); |
485 } | 498 } |
486 | 499 |
487 void SynchronousCompositorFrameSink::WillDrawSurface( | 500 void SynchronousCompositorFrameSink::WillDrawSurface( |
488 const cc::LocalSurfaceId& local_surface_id, | 501 const cc::LocalSurfaceId& local_surface_id, |
489 const gfx::Rect& damage_rect) {} | 502 const gfx::Rect& damage_rect) {} |
490 | 503 |
491 } // namespace content | 504 } // namespace content |
OLD | NEW |