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

Side by Side Diff: components/exo/exo_compositor_frame_sink.cc

Issue 2493223002: Change exo::SurfaceFactoryOwner to exo::ExoCompositorFrameSink (Closed)
Patch Set: Addressed some comments and rebased Created 4 years 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
(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 "components/exo/exo_compositor_frame_sink.h"
6
7 #include "cc/surfaces/surface_manager.h"
8 #include "components/exo/compositor_frame_sink_holder.h"
Fady Samuel 2016/11/23 14:39:02 You don't need this.
Alex Z. 2016/11/23 15:27:40 Done.
9 #include "ui/aura/env.h"
Fady Samuel 2016/11/23 14:39:02 You don't need this.
Alex Z. 2016/11/23 15:27:40 Done.
10
11 namespace exo {
12
13 ////////////////////////////////////////////////////////////////////////////////
14 // ExoComopositorFrameSink, public:
15
16 ExoCompositorFrameSink::ExoCompositorFrameSink(
17 const cc::FrameSinkId& frame_sink_id,
18 cc::SurfaceManager* surface_manager,
19 cc::mojom::MojoCompositorFrameSinkClientPtr client)
20 : frame_sink_id_(frame_sink_id),
21 surface_manager_(surface_manager),
22 surface_factory_(frame_sink_id, surface_manager, this),
23 client_(std::move(client)) {
24 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
25 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
26 }
27
28 ExoCompositorFrameSink::~ExoCompositorFrameSink() {
29 if (begin_frame_source_ && needs_begin_frame_)
30 begin_frame_source_->RemoveObserver(this);
31 if (last_local_frame_id_.is_valid())
32 surface_factory_.Destroy(last_local_frame_id_);
33
34 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
35
36 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
37 }
38
39 ////////////////////////////////////////////////////////////////////////////////
40 // cc::SurfaceFactoryClient overrides:
41
42 void ExoCompositorFrameSink::ReturnResources(
43 const cc::ReturnedResourceArray& resources) {
44 if (resources.empty()) {
45 return;
46 }
47
48 if (!ack_pending_count_ && client_) {
49 client_->ReclaimResources(resources);
50 return;
51 }
52
53 std::copy(resources.begin(), resources.end(),
54 std::back_inserter(surface_returned_resources_));
55 }
56
57 void ExoCompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id,
58 const gfx::Rect& damage_rect) {
59 if (client_)
60 client_->WillDrawSurface();
61 }
62
63 void ExoCompositorFrameSink::SetBeginFrameSource(
64 cc::BeginFrameSource* begin_frame_source) {
65 if (begin_frame_source_ && added_frame_observer_) {
66 begin_frame_source_->RemoveObserver(this);
67 added_frame_observer_ = false;
68 }
69 begin_frame_source_ = begin_frame_source;
70 UpdateNeedsBeginFrameInternal();
71 }
72
73 ////////////////////////////////////////////////////////////////////////////////
74 // To be cc::mojom::MojoCompositorFrameSink overrides:
75
76 void ExoCompositorFrameSink::SubmitCompositorFrame(
77 const cc::LocalFrameId& local_frame_id,
78 cc::CompositorFrame frame) {
79 if (local_frame_id != last_local_frame_id_) {
80 surface_factory_.Create(local_frame_id);
81 }
82 ++ack_pending_count_;
83 surface_factory_.SubmitCompositorFrame(
84 local_frame_id, std::move(frame),
85 base::Bind(&ExoCompositorFrameSink::DidReceiveCompositorFrameAck,
86 base::Unretained(this)));
87 if (last_local_frame_id_.is_valid() &&
88 local_frame_id != last_local_frame_id_) {
89 surface_factory_.SetPreviousFrameSurface(local_frame_id,
90 last_local_frame_id_);
91 surface_factory_.Destroy(last_local_frame_id_);
92 }
93 last_local_frame_id_ = local_frame_id;
94 }
95
96 ////////////////////////////////////////////////////////////////////////////////
97 // cc::BeginFrameObserver overrides:
98
99 void ExoCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) {
100 UpdateNeedsBeginFrameInternal();
101 last_begin_frame_args_ = args;
102 }
103
104 const cc::BeginFrameArgs& ExoCompositorFrameSink::LastUsedBeginFrameArgs()
105 const {
106 return last_begin_frame_args_;
107 }
108
109 void ExoCompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {}
110
111 ////////////////////////////////////////////////////////////////////////////////
112 // ExoComopositorFrameSink, private:
113
114 void ExoCompositorFrameSink::UpdateNeedsBeginFrameInternal() {
115 if (!begin_frame_source_)
116 return;
117
118 if (needs_begin_frame_ == added_frame_observer_)
119 return;
120
121 added_frame_observer_ = needs_begin_frame_;
122 if (needs_begin_frame_)
123 begin_frame_source_->AddObserver(this);
124 else
125 begin_frame_source_->RemoveObserver(this);
126 }
127
128 void ExoCompositorFrameSink::DidReceiveCompositorFrameAck() {
129 if (!client_)
130 return;
131 client_->DidReceiveCompositorFrameAck();
132 DCHECK_GT(ack_pending_count_, 0);
133 if (!surface_returned_resources_.empty()) {
134 client_->ReclaimResources(surface_returned_resources_);
135 surface_returned_resources_.clear();
136 }
137 ack_pending_count_--;
138 }
139
140 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698