OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/surfaces/compositor_frame_sink_support.h" | |
6 | |
7 #include "cc/output/compositor_frame.h" | |
8 #include "cc/scheduler/begin_frame_source.h" | |
9 #include "cc/surfaces/compositor_frame_sink_support_client.h" | |
10 #include "cc/surfaces/display.h" | |
11 #include "cc/surfaces/surface_manager.h" | |
12 | |
13 namespace cc { | |
14 | |
15 CompositorFrameSinkSupport::CompositorFrameSinkSupport( | |
16 CompositorFrameSinkSupportClient* client, | |
17 SurfaceManager* surface_manager, | |
18 const FrameSinkId& frame_sink_id, | |
19 std::unique_ptr<Display> display) | |
20 : client_(client), | |
21 surface_manager_(surface_manager), | |
22 frame_sink_id_(frame_sink_id), | |
23 display_(std::move(display)), | |
24 surface_factory_(frame_sink_id_, surface_manager_, this), | |
25 weak_factory_(this) { | |
26 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | |
27 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | |
28 | |
29 if (display_) { | |
30 display_->Initialize(this, surface_manager_); | |
31 display_->SetVisible(true); | |
32 } | |
33 } | |
34 | |
35 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { | |
36 // SurfaceFactory's destructor will attempt to return resources which will | |
37 // call back into here and access |client_| so we should destroy | |
38 // |surface_factory_|'s resources early on. | |
39 surface_factory_.EvictSurface(); | |
40 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | |
41 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | |
42 } | |
43 | |
44 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | |
45 needs_begin_frame_ = needs_begin_frame; | |
46 UpdateNeedsBeginFramesInternal(); | |
47 } | |
48 | |
49 void CompositorFrameSinkSupport::SubmitCompositorFrame( | |
50 const LocalFrameId& local_frame_id, | |
51 CompositorFrame frame) { | |
52 // If the size of the CompostiorFrame has changed then destroy the existing | |
53 // Surface and create a new one of the appropriate size. | |
54 if (local_frame_id_ != local_frame_id) { | |
55 local_frame_id_ = local_frame_id; | |
56 if (display_ && !frame.render_pass_list.empty()) { | |
57 gfx::Size frame_size = frame.render_pass_list[0]->output_rect.size(); | |
58 display_->Resize(frame_size); | |
piman
2016/12/02 22:44:29
This is probably ok as a first pass, but I think w
Fady Samuel
2016/12/02 23:05:11
I converted your feedback into a TODO(piman, fsamu
| |
59 } | |
60 } | |
61 ++ack_pending_count_; | |
62 surface_factory_.SubmitCompositorFrame( | |
63 local_frame_id_, std::move(frame), | |
64 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | |
65 weak_factory_.GetWeakPtr())); | |
66 if (display_) { | |
67 display_->SetLocalFrameId(local_frame_id_, | |
68 frame.metadata.device_scale_factor); | |
69 } | |
70 } | |
71 | |
72 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { | |
73 if (!client_) | |
74 return; | |
75 client_->DidReceiveCompositorFrameAck(); | |
76 DCHECK_GT(ack_pending_count_, 0); | |
77 if (!surface_returned_resources_.empty()) { | |
78 client_->ReclaimResources(surface_returned_resources_); | |
79 surface_returned_resources_.clear(); | |
80 } | |
81 ack_pending_count_--; | |
piman
2016/12/02 22:44:29
nit: should we do this even if client_ is null, fo
Fady Samuel
2016/12/02 23:05:11
Done.
| |
82 } | |
83 | |
84 void CompositorFrameSinkSupport::AddChildFrameSink( | |
85 const FrameSinkId& child_frame_sink_id) { | |
86 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, | |
87 child_frame_sink_id); | |
88 } | |
89 | |
90 void CompositorFrameSinkSupport::RemoveChildFrameSink( | |
91 const FrameSinkId& child_frame_sink_id) { | |
92 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | |
93 child_frame_sink_id); | |
94 } | |
95 | |
96 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} | |
97 | |
98 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( | |
99 bool will_draw_and_swap, | |
100 const RenderPassList& render_passes) {} | |
101 | |
102 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} | |
103 | |
104 void CompositorFrameSinkSupport::ReturnResources( | |
105 const ReturnedResourceArray& resources) { | |
106 if (resources.empty()) | |
107 return; | |
108 | |
109 if (!ack_pending_count_ && client_) { | |
110 client_->ReclaimResources(resources); | |
111 return; | |
112 } | |
113 | |
114 std::copy(resources.begin(), resources.end(), | |
115 std::back_inserter(surface_returned_resources_)); | |
116 } | |
117 | |
118 void CompositorFrameSinkSupport::SetBeginFrameSource( | |
119 BeginFrameSource* begin_frame_source) { | |
120 // TODO(tansell): Implement this. | |
piman
2016/12/02 22:44:29
nit: what is "this" ?
That function looks like it
Fady Samuel
2016/12/02 23:05:11
It is stale. Removed.
| |
121 if (begin_frame_source_ && added_frame_observer_) { | |
122 begin_frame_source_->RemoveObserver(this); | |
123 added_frame_observer_ = false; | |
124 } | |
125 begin_frame_source_ = begin_frame_source; | |
126 UpdateNeedsBeginFramesInternal(); | |
127 } | |
128 | |
129 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { | |
130 UpdateNeedsBeginFramesInternal(); | |
131 last_begin_frame_args_ = args; | |
132 if (client_) | |
133 client_->OnBeginFrame(args); | |
134 } | |
135 | |
136 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() | |
137 const { | |
138 return last_begin_frame_args_; | |
139 } | |
140 | |
141 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {} | |
142 | |
143 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() { | |
144 if (!begin_frame_source_) | |
145 return; | |
146 | |
147 if (needs_begin_frame_ == added_frame_observer_) | |
148 return; | |
149 | |
150 added_frame_observer_ = needs_begin_frame_; | |
151 if (needs_begin_frame_) | |
152 begin_frame_source_->AddObserver(this); | |
153 else | |
154 begin_frame_source_->RemoveObserver(this); | |
155 } | |
156 | |
157 } // namespace cc | |
OLD | NEW |