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 Display* display, | 20 std::unique_ptr<Display> display, |
21 bool handles_frame_sink_id_invalidation, | 21 std::unique_ptr<BeginFrameSource> display_begin_frame_source) |
22 bool needs_sync_points) | |
23 : client_(client), | 22 : client_(client), |
24 surface_manager_(surface_manager), | 23 surface_manager_(surface_manager), |
25 frame_sink_id_(frame_sink_id), | 24 frame_sink_id_(frame_sink_id), |
26 display_(display), | 25 display_begin_frame_source_(std::move(display_begin_frame_source)), |
| 26 display_(std::move(display)), |
27 surface_factory_(frame_sink_id_, surface_manager_, this), | 27 surface_factory_(frame_sink_id_, surface_manager_, this), |
28 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), | |
29 weak_factory_(this) { | 28 weak_factory_(this) { |
30 if (handles_frame_sink_id_invalidation_) | 29 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
31 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 30 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
32 | 31 |
33 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 32 if (display_) { |
34 surface_factory_.set_needs_sync_points(needs_sync_points); | |
35 | |
36 if (display_) | |
37 display_->Initialize(this, surface_manager_); | 33 display_->Initialize(this, surface_manager_); |
| 34 display_->SetVisible(true); |
| 35 } |
38 } | 36 } |
39 | 37 |
40 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { | 38 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { |
41 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does | |
42 // not call into |this| after it's deleted. | |
43 SetNeedsBeginFrame(false); | |
44 | |
45 for (auto& child_frame_sink_id : child_frame_sinks_) { | 39 for (auto& child_frame_sink_id : child_frame_sinks_) { |
46 DCHECK(child_frame_sink_id.is_valid()); | 40 DCHECK(child_frame_sink_id.is_valid()); |
47 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 41 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
48 child_frame_sink_id); | 42 child_frame_sink_id); |
49 } | 43 } |
50 // SurfaceFactory's destructor will attempt to return resources which will | 44 // SurfaceFactory's destructor will attempt to return resources which will |
51 // call back into here and access |client_| so we should destroy | 45 // call back into here and access |client_| so we should destroy |
52 // |surface_factory_|'s resources early on. | 46 // |surface_factory_|'s resources early on. |
53 surface_factory_.EvictSurface(); | 47 surface_factory_.EvictSurface(); |
54 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 48 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
55 if (handles_frame_sink_id_invalidation_) | 49 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
56 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | |
57 } | 50 } |
58 | 51 |
59 void CompositorFrameSinkSupport::EvictFrame() { | 52 void CompositorFrameSinkSupport::EvictFrame() { |
60 surface_factory_.EvictSurface(); | 53 surface_factory_.EvictSurface(); |
61 } | 54 } |
62 | 55 |
63 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 56 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
64 needs_begin_frame_ = needs_begin_frame; | 57 needs_begin_frame_ = needs_begin_frame; |
65 UpdateNeedsBeginFramesInternal(); | 58 UpdateNeedsBeginFramesInternal(); |
66 } | 59 } |
67 | 60 |
68 void CompositorFrameSinkSupport::SubmitCompositorFrame( | 61 void CompositorFrameSinkSupport::SubmitCompositorFrame( |
69 const LocalSurfaceId& local_surface_id, | 62 const LocalSurfaceId& local_surface_id, |
70 CompositorFrame frame) { | 63 CompositorFrame frame) { |
71 ++ack_pending_count_; | 64 ++ack_pending_count_; |
| 65 surface_factory_.SubmitCompositorFrame( |
| 66 local_surface_id, std::move(frame), |
| 67 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
| 68 weak_factory_.GetWeakPtr())); |
72 if (display_) { | 69 if (display_) { |
73 display_->SetLocalSurfaceId(local_surface_id, | 70 display_->SetLocalSurfaceId(local_surface_id, |
74 frame.metadata.device_scale_factor); | 71 frame.metadata.device_scale_factor); |
75 } | 72 } |
76 surface_factory_.SubmitCompositorFrame( | |
77 local_surface_id, std::move(frame), | |
78 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | |
79 weak_factory_.GetWeakPtr())); | |
80 } | 73 } |
81 | 74 |
82 void CompositorFrameSinkSupport::Require(const LocalSurfaceId& local_surface_id, | 75 void CompositorFrameSinkSupport::Require(const LocalSurfaceId& local_surface_id, |
83 const SurfaceSequence& sequence) { | 76 const SurfaceSequence& sequence) { |
84 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_surface_id), | 77 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_surface_id), |
85 sequence); | 78 sequence); |
86 } | 79 } |
87 | 80 |
88 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { | 81 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { |
89 surface_manager_->SatisfySequence(sequence); | 82 surface_manager_->SatisfySequence(sequence); |
(...skipping 22 matching lines...) Expand all Loading... |
112 void CompositorFrameSinkSupport::RemoveChildFrameSink( | 105 void CompositorFrameSinkSupport::RemoveChildFrameSink( |
113 const FrameSinkId& child_frame_sink_id) { | 106 const FrameSinkId& child_frame_sink_id) { |
114 auto it = child_frame_sinks_.find(child_frame_sink_id); | 107 auto it = child_frame_sinks_.find(child_frame_sink_id); |
115 DCHECK(it != child_frame_sinks_.end()); | 108 DCHECK(it != child_frame_sinks_.end()); |
116 DCHECK(it->is_valid()); | 109 DCHECK(it->is_valid()); |
117 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 110 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
118 child_frame_sink_id); | 111 child_frame_sink_id); |
119 child_frame_sinks_.erase(it); | 112 child_frame_sinks_.erase(it); |
120 } | 113 } |
121 | 114 |
122 void CompositorFrameSinkSupport::ForceReclaimResources() { | |
123 surface_factory_.ClearSurface(); | |
124 } | |
125 | |
126 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} | 115 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} |
127 | 116 |
128 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( | 117 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( |
129 bool will_draw_and_swap, | 118 bool will_draw_and_swap, |
130 const RenderPassList& render_passes) {} | 119 const RenderPassList& render_passes) {} |
131 | 120 |
132 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} | 121 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} |
133 | 122 |
134 void CompositorFrameSinkSupport::ReturnResources( | 123 void CompositorFrameSinkSupport::ReturnResources( |
135 const ReturnedResourceArray& resources) { | 124 const ReturnedResourceArray& resources) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return; | 173 return; |
185 | 174 |
186 added_frame_observer_ = needs_begin_frame_; | 175 added_frame_observer_ = needs_begin_frame_; |
187 if (needs_begin_frame_) | 176 if (needs_begin_frame_) |
188 begin_frame_source_->AddObserver(this); | 177 begin_frame_source_->AddObserver(this); |
189 else | 178 else |
190 begin_frame_source_->RemoveObserver(this); | 179 begin_frame_source_->RemoveObserver(this); |
191 } | 180 } |
192 | 181 |
193 } // namespace cc | 182 } // namespace cc |
OLD | NEW |