OLD | NEW |
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 "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
8 #include "cc/scheduler/begin_frame_source.h" | 8 #include "cc/scheduler/begin_frame_source.h" |
9 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 9 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
10 #include "cc/surfaces/display.h" | 10 #include "cc/surfaces/display.h" |
11 #include "cc/surfaces/surface.h" | 11 #include "cc/surfaces/surface.h" |
12 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 CompositorFrameSinkSupport::CompositorFrameSinkSupport( | 16 CompositorFrameSinkSupport::CompositorFrameSinkSupport( |
17 CompositorFrameSinkSupportClient* client, | 17 CompositorFrameSinkSupportClient* client, |
18 SurfaceManager* surface_manager, | 18 SurfaceManager* surface_manager, |
19 const FrameSinkId& frame_sink_id, | 19 const FrameSinkId& frame_sink_id, |
20 std::unique_ptr<Display> display, | 20 Display* display) |
21 std::unique_ptr<BeginFrameSource> display_begin_frame_source) | |
22 : client_(client), | 21 : client_(client), |
23 surface_manager_(surface_manager), | 22 surface_manager_(surface_manager), |
24 frame_sink_id_(frame_sink_id), | 23 frame_sink_id_(frame_sink_id), |
25 display_begin_frame_source_(std::move(display_begin_frame_source)), | 24 display_(display), |
26 display_(std::move(display)), | |
27 surface_factory_(frame_sink_id_, surface_manager_, this), | 25 surface_factory_(frame_sink_id_, surface_manager_, this), |
28 weak_factory_(this) { | 26 weak_factory_(this) { |
29 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 27 surface_manager->RegisterFrameSinkId(frame_sink_id_); |
30 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 28 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
31 | 29 |
32 if (display_) { | 30 if (display_) |
33 display_->Initialize(this, surface_manager_); | 31 display_->Initialize(this, surface_manager_); |
34 display_->SetVisible(true); | |
35 } | |
36 } | 32 } |
37 | 33 |
38 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { | 34 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { |
39 for (auto& child_frame_sink_id : child_frame_sinks_) { | 35 for (auto& child_frame_sink_id : child_frame_sinks_) { |
40 DCHECK(child_frame_sink_id.is_valid()); | 36 DCHECK(child_frame_sink_id.is_valid()); |
41 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 37 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
42 child_frame_sink_id); | 38 child_frame_sink_id); |
43 } | 39 } |
44 // SurfaceFactory's destructor will attempt to return resources which will | 40 // SurfaceFactory's destructor will attempt to return resources which will |
45 // call back into here and access |client_| so we should destroy | 41 // call back into here and access |client_| so we should destroy |
(...skipping 23 matching lines...) Expand all Loading... |
69 // clients may want finer control over the Display sizing - since it | 65 // clients may want finer control over the Display sizing - since it |
70 // really means the actual size of the native window (Linux/Win Aura) or | 66 // really means the actual size of the native window (Linux/Win Aura) or |
71 // display (Ozone). We may need to either prevent or gutter Display frames | 67 // display (Ozone). We may need to either prevent or gutter Display frames |
72 // until there is a correctly-sized top-level CompositorFrame available | 68 // until there is a correctly-sized top-level CompositorFrame available |
73 // (see ui::Compositor::DisableSwapUntilResize). We might want to resize | 69 // (see ui::Compositor::DisableSwapUntilResize). We might want to resize |
74 // Display earlier. | 70 // Display earlier. |
75 display_->Resize(frame_size); | 71 display_->Resize(frame_size); |
76 } | 72 } |
77 } | 73 } |
78 ++ack_pending_count_; | 74 ++ack_pending_count_; |
| 75 if (display_) { |
| 76 display_->SetLocalFrameId(local_frame_id_, |
| 77 frame.metadata.device_scale_factor); |
| 78 } |
79 surface_factory_.SubmitCompositorFrame( | 79 surface_factory_.SubmitCompositorFrame( |
80 local_frame_id_, std::move(frame), | 80 local_frame_id_, std::move(frame), |
81 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 81 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
82 weak_factory_.GetWeakPtr())); | 82 weak_factory_.GetWeakPtr())); |
83 if (display_) { | |
84 display_->SetLocalFrameId(local_frame_id_, | |
85 frame.metadata.device_scale_factor); | |
86 } | |
87 } | 83 } |
88 | 84 |
89 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id, | 85 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id, |
90 const SurfaceSequence& sequence) { | 86 const SurfaceSequence& sequence) { |
91 Surface* surface = surface_manager_->GetSurfaceForId( | 87 Surface* surface = surface_manager_->GetSurfaceForId( |
92 SurfaceId(frame_sink_id_, local_frame_id)); | 88 SurfaceId(frame_sink_id_, local_frame_id)); |
93 if (!surface) { | 89 if (!surface) { |
94 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 90 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
95 return; | 91 return; |
96 } | 92 } |
97 surface->AddDestructionDependency(sequence); | 93 surface->AddDestructionDependency(sequence); |
98 } | 94 } |
99 | 95 |
100 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { | 96 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { |
101 std::vector<uint32_t> sequences = {sequence.sequence}; | 97 std::vector<uint32_t> sequences = {sequence.sequence}; |
102 surface_manager_->DidSatisfySequences(sequence.frame_sink_id, &sequences); | 98 surface_manager_->DidSatisfySequences(sequence.frame_sink_id, &sequences); |
103 } | 99 } |
104 | 100 |
105 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { | 101 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { |
106 DCHECK_GT(ack_pending_count_, 0); | 102 DCHECK_GT(ack_pending_count_, 0); |
107 ack_pending_count_--; | 103 ack_pending_count_--; |
108 | 104 |
109 if (!client_) | 105 if (!client_) |
110 return; | 106 return; |
| 107 |
111 client_->DidReceiveCompositorFrameAck(); | 108 client_->DidReceiveCompositorFrameAck(); |
112 if (!surface_returned_resources_.empty()) { | 109 if (!surface_returned_resources_.empty()) { |
113 client_->ReclaimResources(surface_returned_resources_); | 110 client_->ReclaimResources(surface_returned_resources_); |
114 surface_returned_resources_.clear(); | 111 surface_returned_resources_.clear(); |
115 } | 112 } |
116 } | 113 } |
117 | 114 |
118 void CompositorFrameSinkSupport::AddChildFrameSink( | 115 void CompositorFrameSinkSupport::AddChildFrameSink( |
119 const FrameSinkId& child_frame_sink_id) { | 116 const FrameSinkId& child_frame_sink_id) { |
120 child_frame_sinks_.insert(child_frame_sink_id); | 117 child_frame_sinks_.insert(child_frame_sink_id); |
121 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, | 118 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, |
122 child_frame_sink_id); | 119 child_frame_sink_id); |
123 } | 120 } |
124 | 121 |
125 void CompositorFrameSinkSupport::RemoveChildFrameSink( | 122 void CompositorFrameSinkSupport::RemoveChildFrameSink( |
126 const FrameSinkId& child_frame_sink_id) { | 123 const FrameSinkId& child_frame_sink_id) { |
127 auto it = child_frame_sinks_.find(child_frame_sink_id); | 124 auto it = child_frame_sinks_.find(child_frame_sink_id); |
128 DCHECK(it != child_frame_sinks_.end()); | 125 DCHECK(it != child_frame_sinks_.end()); |
129 DCHECK(it->is_valid()); | 126 DCHECK(it->is_valid()); |
130 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 127 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
131 child_frame_sink_id); | 128 child_frame_sink_id); |
132 child_frame_sinks_.erase(it); | 129 child_frame_sinks_.erase(it); |
133 } | 130 } |
134 | 131 |
| 132 void CompositorFrameSinkSupport::SetNeedsSyncPoints(bool needs_sync_points) { |
| 133 surface_factory_.set_needs_sync_points(needs_sync_points); |
| 134 } |
| 135 |
| 136 void CompositorFrameSinkSupport::ForceReclaimResources() { |
| 137 if (local_frame_id_.is_valid()) |
| 138 surface_factory_.ClearSurface(); |
| 139 } |
| 140 |
135 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} | 141 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} |
136 | 142 |
137 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( | 143 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( |
138 bool will_draw_and_swap, | 144 bool will_draw_and_swap, |
139 const RenderPassList& render_passes) {} | 145 const RenderPassList& render_passes) {} |
140 | 146 |
141 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} | 147 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} |
142 | 148 |
143 void CompositorFrameSinkSupport::ReturnResources( | 149 void CompositorFrameSinkSupport::ReturnResources( |
144 const ReturnedResourceArray& resources) { | 150 const ReturnedResourceArray& resources) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 return; | 199 return; |
194 | 200 |
195 added_frame_observer_ = needs_begin_frame_; | 201 added_frame_observer_ = needs_begin_frame_; |
196 if (needs_begin_frame_) | 202 if (needs_begin_frame_) |
197 begin_frame_source_->AddObserver(this); | 203 begin_frame_source_->AddObserver(this); |
198 else | 204 else |
199 begin_frame_source_->RemoveObserver(this); | 205 begin_frame_source_->RemoveObserver(this); |
200 } | 206 } |
201 | 207 |
202 } // namespace cc | 208 } // namespace cc |
OLD | NEW |