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