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 "components/exo/compositor_frame_sink_holder.h" | |
6 | |
7 #include "cc/resources/returned_resource.h" | |
8 #include "components/exo/surface.h" | |
9 | |
10 namespace exo { | |
11 | |
12 //////////////////////////////////////////////////////////////////////////////// | |
13 // CompositorFrameSinkHolder, public: | |
14 CompositorFrameSinkHolder::CompositorFrameSinkHolder( | |
15 std::unique_ptr<ExoCompositorFrameSink> compositor_frame_sink, | |
16 base::WeakPtr<Surface> surface, | |
17 cc::mojom::MojoCompositorFrameSinkClientRequest request) | |
18 : compositor_frame_sink_(std::move(compositor_frame_sink)), | |
19 surface_(surface), | |
20 begin_frame_source_(base::MakeUnique<cc::ExternalBeginFrameSource>(this)), | |
21 binding_(this, std::move(request)) {} | |
22 | |
23 bool CompositorFrameSinkHolder::HasReleaseCallbacks(cc::ResourceId id) { | |
24 return release_callbacks_.count(id); | |
25 } | |
26 | |
27 bool CompositorFrameSinkHolder::IsReleaseCallbacksEmpty() { | |
28 return release_callbacks_.size() == 0; | |
29 } | |
30 | |
31 void CompositorFrameSinkHolder::AddResourceReleaseCallback( | |
32 cc::ResourceId id, | |
33 std::unique_ptr<cc::SingleReleaseCallback> callback) { | |
34 release_callbacks_[id] = std::make_pair(this, std::move(callback)); | |
35 compositor_frame_sink_->SetNeedsBeginFrame(true); | |
Fady Samuel
2016/11/30 16:41:56
This might not be necessary.
Alex Z.
2016/11/30 20:00:30
Done.
| |
36 } | |
37 | |
38 void CompositorFrameSinkHolder::ActivateFrameCallbacks( | |
39 std::list<FrameCallback>& frame_callbacks) { | |
40 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | |
41 frame_callbacks); | |
42 } | |
43 | |
44 void CompositorFrameSinkHolder::CancelFrameCallbacks() { | |
45 // Call pending frame callbacks with a null frame time to indicate that they | |
46 // have been cancelled. | |
47 for (const auto& frame_callback : active_frame_callbacks_) | |
48 frame_callback.Run(base::TimeTicks()); | |
49 } | |
50 | |
51 void CompositorFrameSinkHolder::EvictFrame() { | |
52 compositor_frame_sink_->EvictFrame(); | |
53 } | |
54 | |
55 CompositorFrameSinkHolder::~CompositorFrameSinkHolder() { | |
56 begin_frame_source_.reset(); | |
Fady Samuel
2016/11/30 16:41:57
Is this necessary?
Alex Z.
2016/11/30 20:00:30
Done.
| |
57 } | |
58 | |
59 void CompositorFrameSinkHolder::UpdateNeedsBeginFrame() { | |
60 if (!begin_frame_source_) | |
61 return; | |
62 | |
63 bool needs_begin_frame = !active_frame_callbacks_.empty(); | |
64 if (needs_begin_frame == needs_begin_frame_) | |
65 return; | |
66 | |
67 needs_begin_frame_ = needs_begin_frame; | |
68 OnNeedsBeginFrames(needs_begin_frame_); | |
69 } | |
70 | |
71 void CompositorFrameSinkHolder::SetNeedsBeginFrame(bool needs_begin_frame) { | |
72 needs_begin_frame_ = needs_begin_frame; | |
73 OnNeedsBeginFrames(needs_begin_frame); | |
74 } | |
75 | |
76 void CompositorFrameSinkHolder::SubmitCompositorFrame( | |
77 const cc::LocalFrameId& local_frame_id, | |
78 cc::CompositorFrame frame) { | |
79 if (compositor_frame_sink_) | |
Fady Samuel
2016/11/30 16:41:57
nit: braces for multi-line blocks.
Alex Z.
2016/11/30 20:00:30
Done.
| |
80 compositor_frame_sink_->SubmitCompositorFrame(local_frame_id, | |
81 std::move(frame)); | |
82 } | |
83 | |
84 //////////////////////////////////////////////////////////////////////////////// | |
85 // cc::mojom::MojoCompositorFrameSinkClient overrides: | |
86 | |
87 // TODO(staraz): Implement this | |
Fady Samuel
2016/11/30 16:41:57
Put the TODO in the body.
Alex Z.
2016/11/30 20:00:30
Done.
| |
88 void CompositorFrameSinkHolder::DidReceiveCompositorFrameAck() {} | |
89 | |
90 void CompositorFrameSinkHolder::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
91 while (!active_frame_callbacks_.empty()) { | |
92 active_frame_callbacks_.front().Run(args.frame_time); | |
93 active_frame_callbacks_.pop_front(); | |
94 } | |
95 begin_frame_source_->OnBeginFrame(args); | |
96 } | |
97 | |
98 void CompositorFrameSinkHolder::ReclaimResources( | |
99 const cc::ReturnedResourceArray& resources) { | |
100 scoped_refptr<CompositorFrameSinkHolder> holder(this); | |
101 for (auto& resource : resources) { | |
102 auto it = release_callbacks_.find(resource.id); | |
103 DCHECK(it != release_callbacks_.end()); | |
104 it->second.second->Run(resource.sync_token, resource.lost); | |
105 release_callbacks_.erase(it); | |
106 } | |
107 } | |
108 | |
109 void CompositorFrameSinkHolder::WillDrawSurface() { | |
110 if (surface_) | |
111 surface_->WillDraw(); | |
112 } | |
113 | |
114 const cc::BeginFrameArgs& CompositorFrameSinkHolder::LastUsedBeginFrameArgs() | |
115 const { | |
116 return last_begin_frame_args_; | |
117 } | |
118 | |
119 void CompositorFrameSinkHolder::OnBeginFrameSourcePausedChanged(bool paused) {} | |
120 | |
121 //////////////////////////////////////////////////////////////////////////////// | |
122 // ExoComopositorFrameSink, private: | |
Fady Samuel
2016/11/30 16:41:57
This comment is wrong. This is BeginFrameObserver,
Alex Z.
2016/11/30 20:00:30
Done.
| |
123 | |
124 void CompositorFrameSinkHolder::OnNeedsBeginFrames(bool needs_begin_frames) { | |
125 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | |
126 } | |
127 | |
128 } // namespace exo | |
OLD | NEW |