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

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

Issue 2612083002: DirectCompositorFrameSink Uses CompositorFrameSinkSupport (Closed)
Patch Set: CompositorFrameSinkSupport takes a flag indicating if it's supporting a DirectCompositorFrameSink Created 3 years, 11 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 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) 21 bool direct_compositor_frame_sink)
22 : client_(client), 22 : client_(client),
23 surface_manager_(surface_manager), 23 surface_manager_(surface_manager),
24 frame_sink_id_(frame_sink_id), 24 frame_sink_id_(frame_sink_id),
25 display_begin_frame_source_(std::move(display_begin_frame_source)), 25 display_(display),
26 display_(std::move(display)),
27 surface_factory_(frame_sink_id_, surface_manager_, this), 26 surface_factory_(frame_sink_id_, surface_manager_, this),
27 direct_compositor_frame_sink_(direct_compositor_frame_sink),
28 weak_factory_(this) { 28 weak_factory_(this) {
29 surface_manager_->RegisterFrameSinkId(frame_sink_id_); 29 if (!direct_compositor_frame_sink_)
30 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
31
30 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); 32 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
31 33
32 if (display_) { 34 if (display_) {
33 display_->Initialize(this, surface_manager_); 35 display_->Initialize(this, surface_manager_);
34 display_->SetVisible(true); 36 display_->SetVisible(true);
35 } 37 }
36 } 38 }
37 39
38 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { 40 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() {
39 for (auto& child_frame_sink_id : child_frame_sinks_) { 41 for (auto& child_frame_sink_id : child_frame_sinks_) {
40 DCHECK(child_frame_sink_id.is_valid()); 42 DCHECK(child_frame_sink_id.is_valid());
41 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, 43 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_,
42 child_frame_sink_id); 44 child_frame_sink_id);
43 } 45 }
44 // SurfaceFactory's destructor will attempt to return resources which will 46 // SurfaceFactory's destructor will attempt to return resources which will
45 // call back into here and access |client_| so we should destroy 47 // call back into here and access |client_| so we should destroy
46 // |surface_factory_|'s resources early on. 48 // |surface_factory_|'s resources early on.
47 surface_factory_.EvictSurface(); 49 surface_factory_.EvictSurface();
48 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); 50 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
49 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); 51 if (!direct_compositor_frame_sink_)
52 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
50 } 53 }
51 54
52 void CompositorFrameSinkSupport::EvictFrame() { 55 void CompositorFrameSinkSupport::EvictFrame() {
53 surface_factory_.EvictSurface(); 56 surface_factory_.EvictSurface();
54 } 57 }
55 58
56 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { 59 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
57 needs_begin_frame_ = needs_begin_frame; 60 needs_begin_frame_ = needs_begin_frame;
58 UpdateNeedsBeginFramesInternal(); 61 UpdateNeedsBeginFramesInternal();
59 } 62 }
60 63
61 void CompositorFrameSinkSupport::SubmitCompositorFrame( 64 void CompositorFrameSinkSupport::SubmitCompositorFrame(
62 const LocalFrameId& local_frame_id, 65 const LocalFrameId& local_frame_id,
63 CompositorFrame frame) { 66 CompositorFrame frame) {
64 if (local_frame_id_ != local_frame_id) { 67 if (local_frame_id_ != local_frame_id) {
65 local_frame_id_ = local_frame_id; 68 local_frame_id_ = local_frame_id;
66 if (display_ && !frame.render_pass_list.empty()) { 69 if (display_ && !frame.render_pass_list.empty()) {
67 gfx::Size frame_size = frame.render_pass_list[0]->output_rect.size(); 70 gfx::Size frame_size = frame.render_pass_list[0]->output_rect.size();
68 // TODO(piman, fsamuel): We will likely want to revisit this because some 71 // TODO(piman, fsamuel): We will likely want to revisit this because some
69 // clients may want finer control over the Display sizing - since it 72 // 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 73 // 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 74 // display (Ozone). We may need to either prevent or gutter Display frames
72 // until there is a correctly-sized top-level CompositorFrame available 75 // until there is a correctly-sized top-level CompositorFrame available
73 // (see ui::Compositor::DisableSwapUntilResize). We might want to resize 76 // (see ui::Compositor::DisableSwapUntilResize). We might want to resize
74 // Display earlier. 77 // Display earlier.
75 display_->Resize(frame_size); 78 display_->Resize(frame_size);
76 } 79 }
77 } 80 }
78 ++ack_pending_count_; 81 ++ack_pending_count_;
82 if (display_) {
83 display_->SetLocalFrameId(local_frame_id_,
84 frame.metadata.device_scale_factor);
85 }
79 surface_factory_.SubmitCompositorFrame( 86 surface_factory_.SubmitCompositorFrame(
80 local_frame_id_, std::move(frame), 87 local_frame_id_, std::move(frame),
81 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, 88 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
82 weak_factory_.GetWeakPtr())); 89 weak_factory_.GetWeakPtr()));
83 if (display_) {
84 display_->SetLocalFrameId(local_frame_id_,
85 frame.metadata.device_scale_factor);
86 }
87 } 90 }
88 91
89 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id, 92 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id,
90 const SurfaceSequence& sequence) { 93 const SurfaceSequence& sequence) {
91 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_frame_id), 94 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_frame_id),
92 sequence); 95 sequence);
93 } 96 }
94 97
95 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { 98 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) {
96 surface_manager_->SatisfySequence(sequence); 99 surface_manager_->SatisfySequence(sequence);
97 } 100 }
98 101
99 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { 102 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() {
100 DCHECK_GT(ack_pending_count_, 0); 103 DCHECK_GT(ack_pending_count_, 0);
101 ack_pending_count_--; 104 ack_pending_count_--;
102 105
103 if (!client_) 106 if (!client_)
104 return; 107 return;
108
105 client_->DidReceiveCompositorFrameAck(); 109 client_->DidReceiveCompositorFrameAck();
106 if (!surface_returned_resources_.empty()) { 110 if (!surface_returned_resources_.empty()) {
107 client_->ReclaimResources(surface_returned_resources_); 111 client_->ReclaimResources(surface_returned_resources_);
108 surface_returned_resources_.clear(); 112 surface_returned_resources_.clear();
109 } 113 }
110 } 114 }
111 115
112 void CompositorFrameSinkSupport::AddChildFrameSink( 116 void CompositorFrameSinkSupport::AddChildFrameSink(
113 const FrameSinkId& child_frame_sink_id) { 117 const FrameSinkId& child_frame_sink_id) {
114 child_frame_sinks_.insert(child_frame_sink_id); 118 child_frame_sinks_.insert(child_frame_sink_id);
115 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, 119 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_,
116 child_frame_sink_id); 120 child_frame_sink_id);
117 } 121 }
118 122
119 void CompositorFrameSinkSupport::RemoveChildFrameSink( 123 void CompositorFrameSinkSupport::RemoveChildFrameSink(
120 const FrameSinkId& child_frame_sink_id) { 124 const FrameSinkId& child_frame_sink_id) {
121 auto it = child_frame_sinks_.find(child_frame_sink_id); 125 auto it = child_frame_sinks_.find(child_frame_sink_id);
122 DCHECK(it != child_frame_sinks_.end()); 126 DCHECK(it != child_frame_sinks_.end());
123 DCHECK(it->is_valid()); 127 DCHECK(it->is_valid());
124 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, 128 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_,
125 child_frame_sink_id); 129 child_frame_sink_id);
126 child_frame_sinks_.erase(it); 130 child_frame_sinks_.erase(it);
127 } 131 }
128 132
133 void CompositorFrameSinkSupport::SetNeedsSyncPoints(bool needs_sync_points) {
134 surface_factory_.set_needs_sync_points(needs_sync_points);
135 }
136
137 void CompositorFrameSinkSupport::ForceReclaimResources() {
138 if (local_frame_id_.is_valid())
139 surface_factory_.ClearSurface();
140 }
141
129 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} 142 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {}
130 143
131 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( 144 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap(
132 bool will_draw_and_swap, 145 bool will_draw_and_swap,
133 const RenderPassList& render_passes) {} 146 const RenderPassList& render_passes) {}
134 147
135 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} 148 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {}
136 149
137 void CompositorFrameSinkSupport::ReturnResources( 150 void CompositorFrameSinkSupport::ReturnResources(
138 const ReturnedResourceArray& resources) { 151 const ReturnedResourceArray& resources) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return; 200 return;
188 201
189 added_frame_observer_ = needs_begin_frame_; 202 added_frame_observer_ = needs_begin_frame_;
190 if (needs_begin_frame_) 203 if (needs_begin_frame_)
191 begin_frame_source_->AddObserver(this); 204 begin_frame_source_->AddObserver(this);
192 else 205 else
193 begin_frame_source_->RemoveObserver(this); 206 begin_frame_source_->RemoveObserver(this);
194 } 207 }
195 208
196 } // namespace cc 209 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698