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

Side by Side Diff: cc/surfaces/compositor_frame_sink_support.cc

Issue 2687433002: Move surface reference code to CompositorFrameSinkSupport. (Closed)
Patch Set: Revert to patch 2 to reland. Created 3 years, 10 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
« no previous file with comments | « cc/surfaces/compositor_frame_sink_support.h ('k') | cc/surfaces/referenced_surface_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "cc/surfaces/compositor_frame_sink_support.h" 5 #include "cc/surfaces/compositor_frame_sink_support.h"
6 6
7 #include <algorithm>
8 #include <utility>
9 #include <vector>
10
7 #include "cc/output/compositor_frame.h" 11 #include "cc/output/compositor_frame.h"
8 #include "cc/scheduler/begin_frame_source.h" 12 #include "cc/scheduler/begin_frame_source.h"
9 #include "cc/surfaces/compositor_frame_sink_support_client.h" 13 #include "cc/surfaces/compositor_frame_sink_support_client.h"
10 #include "cc/surfaces/display.h" 14 #include "cc/surfaces/display.h"
11 #include "cc/surfaces/surface.h" 15 #include "cc/surfaces/surface.h"
12 #include "cc/surfaces/surface_manager.h" 16 #include "cc/surfaces/surface_manager.h"
17 #include "cc/surfaces/surface_reference.h"
13 18
14 namespace cc { 19 namespace cc {
15 20
16 CompositorFrameSinkSupport::CompositorFrameSinkSupport( 21 CompositorFrameSinkSupport::CompositorFrameSinkSupport(
17 CompositorFrameSinkSupportClient* client, 22 CompositorFrameSinkSupportClient* client,
18 SurfaceManager* surface_manager, 23 SurfaceManager* surface_manager,
19 const FrameSinkId& frame_sink_id, 24 const FrameSinkId& frame_sink_id,
20 std::unique_ptr<Display> display, 25 std::unique_ptr<Display> display,
21 std::unique_ptr<BeginFrameSource> display_begin_frame_source) 26 std::unique_ptr<BeginFrameSource> display_begin_frame_source)
22 : client_(client), 27 : client_(client),
23 surface_manager_(surface_manager), 28 surface_manager_(surface_manager),
24 frame_sink_id_(frame_sink_id), 29 frame_sink_id_(frame_sink_id),
25 display_begin_frame_source_(std::move(display_begin_frame_source)), 30 display_begin_frame_source_(std::move(display_begin_frame_source)),
26 display_(std::move(display)), 31 display_(std::move(display)),
27 surface_factory_(frame_sink_id_, surface_manager_, this), 32 surface_factory_(frame_sink_id_, surface_manager_, this),
33 reference_tracker_(frame_sink_id),
28 weak_factory_(this) { 34 weak_factory_(this) {
29 surface_manager_->RegisterFrameSinkId(frame_sink_id_); 35 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
30 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); 36 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
31 37
32 if (display_) { 38 if (display_) {
33 display_->Initialize(this, surface_manager_); 39 display_->Initialize(this, surface_manager_);
34 display_->SetVisible(true); 40 display_->SetVisible(true);
35 } 41 }
36 } 42 }
37 43
38 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { 44 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() {
45 // For display root surfaces, the surface is no longer going to be visible
46 // so make it unreachable from the top-level root.
47 if (surface_manager_->using_surface_references() && display_ &&
48 reference_tracker_.current_surface_id().is_valid())
49 RemoveTopLevelRootReference(reference_tracker_.current_surface_id());
50
39 for (auto& child_frame_sink_id : child_frame_sinks_) { 51 for (auto& child_frame_sink_id : child_frame_sinks_) {
40 DCHECK(child_frame_sink_id.is_valid()); 52 DCHECK(child_frame_sink_id.is_valid());
41 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, 53 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_,
42 child_frame_sink_id); 54 child_frame_sink_id);
43 } 55 }
44 // SurfaceFactory's destructor will attempt to return resources which will 56 // SurfaceFactory's destructor will attempt to return resources which will
45 // call back into here and access |client_| so we should destroy 57 // call back into here and access |client_| so we should destroy
46 // |surface_factory_|'s resources early on. 58 // |surface_factory_|'s resources early on.
47 surface_factory_.EvictSurface(); 59 surface_factory_.EvictSurface();
48 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); 60 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
49 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); 61 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
50 } 62 }
51 63
52 void CompositorFrameSinkSupport::EvictFrame() { 64 void CompositorFrameSinkSupport::EvictFrame() {
53 surface_factory_.EvictSurface(); 65 surface_factory_.EvictSurface();
54 } 66 }
55 67
56 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { 68 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
57 needs_begin_frame_ = needs_begin_frame; 69 needs_begin_frame_ = needs_begin_frame;
58 UpdateNeedsBeginFramesInternal(); 70 UpdateNeedsBeginFramesInternal();
59 } 71 }
60 72
61 void CompositorFrameSinkSupport::SubmitCompositorFrame( 73 void CompositorFrameSinkSupport::SubmitCompositorFrame(
62 const LocalSurfaceId& local_surface_id, 74 const LocalSurfaceId& local_surface_id,
63 CompositorFrame frame) { 75 CompositorFrame frame) {
64 ++ack_pending_count_; 76 ++ack_pending_count_;
65 surface_factory_.SubmitCompositorFrame( 77 float device_scale_factor = frame.metadata.device_scale_factor;
66 local_surface_id, std::move(frame), 78
67 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, 79 if (surface_manager_->using_surface_references()) {
68 weak_factory_.GetWeakPtr())); 80 SurfaceId last_surface_id = reference_tracker_.current_surface_id();
69 if (display_) { 81
70 display_->SetLocalSurfaceId(local_surface_id, 82 // Populate list of surface references to add and remove based on reference
71 frame.metadata.device_scale_factor); 83 // surfaces in current frame compared with the last frame.
84 reference_tracker_.UpdateReferences(local_surface_id,
85 frame.metadata.referenced_surfaces);
86
87 surface_factory_.SubmitCompositorFrame(
88 local_surface_id, std::move(frame),
89 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
90 weak_factory_.GetWeakPtr()));
91
92 UpdateSurfaceReferences(last_surface_id, local_surface_id);
93 } else {
94 surface_factory_.SubmitCompositorFrame(
95 local_surface_id, std::move(frame),
96 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
97 weak_factory_.GetWeakPtr()));
72 } 98 }
99
100 if (display_)
101 display_->SetLocalSurfaceId(local_surface_id, device_scale_factor);
73 } 102 }
74 103
75 void CompositorFrameSinkSupport::Require(const LocalSurfaceId& local_surface_id, 104 void CompositorFrameSinkSupport::Require(const LocalSurfaceId& local_surface_id,
76 const SurfaceSequence& sequence) { 105 const SurfaceSequence& sequence) {
77 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_surface_id), 106 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_surface_id),
78 sequence); 107 sequence);
79 } 108 }
80 109
81 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { 110 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) {
82 surface_manager_->SatisfySequence(sequence); 111 surface_manager_->SatisfySequence(sequence);
83 } 112 }
84 113
114 void CompositorFrameSinkSupport::UpdateSurfaceReferences(
115 const SurfaceId& last_surface_id,
116 const LocalSurfaceId& local_surface_id) {
117 const bool surface_id_changed =
118 last_surface_id.local_surface_id() != local_surface_id;
119
120 // If this is a display root surface and the SurfaceId is changing, make the
121 // new SurfaceId reachable from the top-level root.
122 if (display_ && surface_id_changed)
123 AddTopLevelRootReference(reference_tracker_.current_surface_id());
124
125 // Add references based on CompositorFrame referenced surfaces. If the
126 // SurfaceId has changed all referenced surfaces will be in this list.
127 if (!reference_tracker_.references_to_add().empty()) {
128 surface_manager_->AddSurfaceReferences(
129 reference_tracker_.references_to_add());
130 }
131
132 // If this is a display root surface and the SurfaceId is changing, make the
133 // old SurfaceId unreachable from the top-level root. This needs to happen
134 // after adding all references for the new SurfaceId.
135 if (display_ && surface_id_changed && last_surface_id.is_valid())
136 RemoveTopLevelRootReference(last_surface_id);
137
138 // Remove references based on CompositorFrame referenced surfaces. If the
139 // SurfaceId has changed this list will be empty.
140 if (!reference_tracker_.references_to_remove().empty()) {
141 DCHECK(!surface_id_changed);
142 surface_manager_->RemoveSurfaceReferences(
143 reference_tracker_.references_to_remove());
144 }
145 }
146
147 void CompositorFrameSinkSupport::AddTopLevelRootReference(
148 const SurfaceId& surface_id) {
149 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
150 surface_manager_->AddSurfaceReferences({reference});
151 }
152
153 void CompositorFrameSinkSupport::RemoveTopLevelRootReference(
154 const SurfaceId& surface_id) {
155 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
156 surface_manager_->RemoveSurfaceReferences({reference});
157 }
158
85 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { 159 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() {
86 DCHECK_GT(ack_pending_count_, 0); 160 DCHECK_GT(ack_pending_count_, 0);
87 ack_pending_count_--; 161 ack_pending_count_--;
88 162
89 if (!client_) 163 if (!client_)
90 return; 164 return;
91 client_->DidReceiveCompositorFrameAck(); 165 client_->DidReceiveCompositorFrameAck();
92 if (!surface_returned_resources_.empty()) { 166 if (!surface_returned_resources_.empty()) {
93 client_->ReclaimResources(surface_returned_resources_); 167 client_->ReclaimResources(surface_returned_resources_);
94 surface_returned_resources_.clear(); 168 surface_returned_resources_.clear();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return; 247 return;
174 248
175 added_frame_observer_ = needs_begin_frame_; 249 added_frame_observer_ = needs_begin_frame_;
176 if (needs_begin_frame_) 250 if (needs_begin_frame_)
177 begin_frame_source_->AddObserver(this); 251 begin_frame_source_->AddObserver(this);
178 else 252 else
179 begin_frame_source_->RemoveObserver(this); 253 begin_frame_source_->RemoveObserver(this);
180 } 254 }
181 255
182 } // namespace cc 256 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/compositor_frame_sink_support.h ('k') | cc/surfaces/referenced_surface_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698