Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: content/browser/frame_host/render_widget_host_view_child_frame.cc

Issue 2728183002: RendererCompositorFrameSink should handle local surface id allocation (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/frame_host/render_widget_host_view_child_frame.h" 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 RenderWidgetHost* widget_host) 51 RenderWidgetHost* widget_host)
52 : host_(RenderWidgetHostImpl::From(widget_host)), 52 : host_(RenderWidgetHostImpl::From(widget_host)),
53 frame_sink_id_( 53 frame_sink_id_(
54 base::checked_cast<uint32_t>(widget_host->GetProcess()->GetID()), 54 base::checked_cast<uint32_t>(widget_host->GetProcess()->GetID()),
55 base::checked_cast<uint32_t>(widget_host->GetRoutingID())), 55 base::checked_cast<uint32_t>(widget_host->GetRoutingID())),
56 next_surface_sequence_(1u), 56 next_surface_sequence_(1u),
57 last_compositor_frame_sink_id_(0), 57 last_compositor_frame_sink_id_(0),
58 current_surface_scale_factor_(1.f), 58 current_surface_scale_factor_(1.f),
59 frame_connector_(nullptr), 59 frame_connector_(nullptr),
60 weak_factory_(this) { 60 weak_factory_(this) {
61 id_allocator_.reset(new cc::LocalSurfaceIdAllocator());
62 GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); 61 GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
63 CreateCompositorFrameSinkSupport(); 62 CreateCompositorFrameSinkSupport();
64 } 63 }
65 64
66 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { 65 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() {
67 ResetCompositorFrameSinkSupport(); 66 ResetCompositorFrameSinkSupport();
68 if (GetSurfaceManager()) 67 if (GetSurfaceManager())
69 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 68 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
70 } 69 }
71 70
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 void RenderWidgetHostViewChildFrame::DidReceiveCompositorFrameAck() { 343 void RenderWidgetHostViewChildFrame::DidReceiveCompositorFrameAck() {
345 if (!host_) 344 if (!host_)
346 return; 345 return;
347 host_->Send(new ViewMsg_ReclaimCompositorResources( 346 host_->Send(new ViewMsg_ReclaimCompositorResources(
348 host_->GetRoutingID(), last_compositor_frame_sink_id_, 347 host_->GetRoutingID(), last_compositor_frame_sink_id_,
349 true /* is_swap_ack */, cc::ReturnedResourceArray())); 348 true /* is_swap_ack */, cc::ReturnedResourceArray()));
350 } 349 }
351 350
352 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame( 351 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame(
353 uint32_t compositor_frame_sink_id, 352 uint32_t compositor_frame_sink_id,
353 const cc::LocalSurfaceId& local_surface_id,
354 cc::CompositorFrame frame) { 354 cc::CompositorFrame frame) {
355 // If the renderer changed its frame sink, reset the 355 // If the renderer changed its frame sink, reset the
356 // CompositorFrameSinkSupport to avoid returning stale resources. 356 // CompositorFrameSinkSupport to avoid returning stale resources.
357 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { 357 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) {
358 ResetCompositorFrameSinkSupport(); 358 ResetCompositorFrameSinkSupport();
359 CreateCompositorFrameSinkSupport(); 359 CreateCompositorFrameSinkSupport();
360 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 360 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
361 local_surface_id_ = cc::LocalSurfaceId();
362 } 361 }
363 362
364 gfx::Size new_frame_size = frame.render_pass_list.back()->output_rect.size(); 363 current_surface_size_ = frame.render_pass_list.back()->output_rect.size();
365 float new_scale_factor = frame.metadata.device_scale_factor; 364 current_surface_scale_factor_ = frame.metadata.device_scale_factor;
366 bool allocated_new_local_surface_id = false; 365
367 if (!local_surface_id_.is_valid() || 366 support_->SubmitCompositorFrame(local_surface_id, std::move(frame));
368 new_frame_size != current_surface_size_ || 367 has_frame_ = true;
369 new_scale_factor != current_surface_scale_factor_) { 368
370 local_surface_id_ = id_allocator_->GenerateId(); 369 if (local_surface_id_ != local_surface_id || HasEmbedderChanged()) {
371 current_surface_size_ = frame.render_pass_list.back()->output_rect.size(); 370 local_surface_id_ = local_surface_id;
372 current_surface_scale_factor_ = frame.metadata.device_scale_factor; 371 SendSurfaceInfoToEmbedder();
373 allocated_new_local_surface_id = true;
374 } 372 }
375 373
376 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame));
377 has_frame_ = true;
378
379 if (allocated_new_local_surface_id || HasEmbedderChanged())
380 SendSurfaceInfoToEmbedder();
381 ProcessFrameSwappedCallbacks(); 374 ProcessFrameSwappedCallbacks();
382 } 375 }
383 376
384 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { 377 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() {
385 cc::SurfaceSequence sequence = 378 cc::SurfaceSequence sequence =
386 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); 379 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++);
387 cc::SurfaceManager* manager = GetSurfaceManager(); 380 cc::SurfaceManager* manager = GetSurfaceManager();
388 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); 381 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_);
389 // The renderer process will satisfy this dependency when it creates a 382 // The renderer process will satisfy this dependency when it creates a
390 // SurfaceLayer. 383 // SurfaceLayer.
391 manager->RequireSequence(surface_id, sequence); 384 manager->RequireSequence(surface_id, sequence);
392 cc::SurfaceInfo surface_info(surface_id, current_surface_scale_factor_, 385 cc::SurfaceInfo surface_info(surface_id, current_surface_scale_factor_,
393 current_surface_size_); 386 current_surface_size_);
394 SendSurfaceInfoToEmbedderImpl(surface_info, sequence); 387 SendSurfaceInfoToEmbedderImpl(surface_info, sequence);
395 } 388 }
396 389
397 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedderImpl( 390 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedderImpl(
398 const cc::SurfaceInfo& surface_info, 391 const cc::SurfaceInfo& surface_info,
399 const cc::SurfaceSequence& sequence) { 392 const cc::SurfaceSequence& sequence) {
400 frame_connector_->SetChildFrameSurface(surface_info, sequence); 393 frame_connector_->SetChildFrameSurface(surface_info, sequence);
401 } 394 }
402 395
403 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( 396 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame(
404 uint32_t compositor_frame_sink_id, 397 uint32_t compositor_frame_sink_id,
398 const cc::LocalSurfaceId& local_surface_id,
405 cc::CompositorFrame frame) { 399 cc::CompositorFrame frame) {
406 TRACE_EVENT0("content", 400 TRACE_EVENT0("content",
407 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame"); 401 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame");
408 last_scroll_offset_ = frame.metadata.root_scroll_offset; 402 last_scroll_offset_ = frame.metadata.root_scroll_offset;
409 if (!frame_connector_) 403 if (!frame_connector_)
410 return; 404 return;
411 ProcessCompositorFrame(compositor_frame_sink_id, std::move(frame)); 405 ProcessCompositorFrame(compositor_frame_sink_id, local_surface_id,
406 std::move(frame));
412 } 407 }
413 408
414 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { 409 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() {
415 // We only use callbacks once, therefore we make a new list for registration 410 // We only use callbacks once, therefore we make a new list for registration
416 // before we start, and discard the old list entries when we are done. 411 // before we start, and discard the old list entries when we are done.
417 FrameSwappedCallbackList process_callbacks; 412 FrameSwappedCallbackList process_callbacks;
418 process_callbacks.swap(frame_swapped_callbacks_); 413 process_callbacks.swap(frame_swapped_callbacks_);
419 for (std::unique_ptr<base::Closure>& callback : process_callbacks) 414 for (std::unique_ptr<base::Closure>& callback : process_callbacks)
420 callback->Run(); 415 callback->Run();
421 } 416 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 frame_sink_id_); 699 frame_sink_id_);
705 } 700 }
706 support_.reset(); 701 support_.reset();
707 } 702 }
708 703
709 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { 704 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() {
710 return false; 705 return false;
711 } 706 }
712 707
713 } // namespace content 708 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698