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: | |
reveman
2016/12/07 00:46:57
nit: blankline after this
Alex Z.
2016/12/07 20:09:35
Done.
| |
14 CompositorFrameSinkHolder::CompositorFrameSinkHolder( | |
15 cc::mojom::MojoCompositorFrameSinkPtr 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); | |
reveman
2016/12/07 00:46:57
release_callbacks_.find(id) != release_callbacks_.
Alex Z.
2016/12/07 20:09:35
Done.
| |
25 } | |
26 | |
27 bool CompositorFrameSinkHolder::IsReleaseCallbacksEmpty() { | |
28 return release_callbacks_.size() == 0; | |
reveman
2016/12/07 00:46:56
release_callbacks_.empty() is easier to read
Alex Z.
2016/12/07 20:09:35
Done.
| |
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 } | |
36 | |
37 void CompositorFrameSinkHolder::ActivateFrameCallbacks( | |
38 std::list<FrameCallback>& frame_callbacks) { | |
39 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | |
40 frame_callbacks); | |
41 } | |
42 | |
43 void CompositorFrameSinkHolder::CancelFrameCallbacks() { | |
44 // Call pending frame callbacks with a null frame time to indicate that they | |
45 // have been cancelled. | |
46 for (const auto& frame_callback : active_frame_callbacks_) | |
47 frame_callback.Run(base::TimeTicks()); | |
48 } | |
49 | |
50 void CompositorFrameSinkHolder::UpdateNeedsBeginFrame() { | |
reveman
2016/12/07 00:46:56
this is private. please move down into correct sec
Alex Z.
2016/12/07 20:09:35
Done.
| |
51 if (!begin_frame_source_) | |
52 return; | |
53 | |
54 bool needs_begin_frame = !active_frame_callbacks_.empty(); | |
55 if (needs_begin_frame == needs_begin_frame_) | |
56 return; | |
57 | |
58 needs_begin_frame_ = needs_begin_frame; | |
59 OnNeedsBeginFrames(needs_begin_frame_); | |
60 } | |
61 | |
62 void CompositorFrameSinkHolder::SetNeedsBeginFrame(bool needs_begin_frame) { | |
63 needs_begin_frame_ = needs_begin_frame; | |
64 OnNeedsBeginFrames(needs_begin_frame); | |
65 } | |
66 | |
67 //////////////////////////////////////////////////////////////////////////////// | |
68 // cc::mojom::MojoCompositorFrameSinkClient overrides: | |
69 | |
70 void CompositorFrameSinkHolder::DidReceiveCompositorFrameAck() { | |
71 // TODO(staraz): Implement this | |
72 } | |
73 | |
74 void CompositorFrameSinkHolder::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
75 while (!active_frame_callbacks_.empty()) { | |
76 active_frame_callbacks_.front().Run(args.frame_time); | |
77 active_frame_callbacks_.pop_front(); | |
78 } | |
79 begin_frame_source_->OnBeginFrame(args); | |
80 } | |
81 | |
82 void CompositorFrameSinkHolder::ReclaimResources( | |
83 const cc::ReturnedResourceArray& resources) { | |
84 scoped_refptr<CompositorFrameSinkHolder> holder(this); | |
85 for (auto& resource : resources) { | |
86 auto it = release_callbacks_.find(resource.id); | |
87 DCHECK(it != release_callbacks_.end()); | |
88 it->second.second->Run(resource.sync_token, resource.lost); | |
89 release_callbacks_.erase(it); | |
90 } | |
91 } | |
92 | |
93 //////////////////////////////////////////////////////////////////////////////// | |
94 // cc::BeginFrameObserver: | |
reveman
2016/12/07 00:46:57
nit: cc::BeginFrameObserver overrides:
Alex Z.
2016/12/07 20:09:35
Done.
| |
95 const cc::BeginFrameArgs& CompositorFrameSinkHolder::LastUsedBeginFrameArgs() | |
96 const { | |
97 return last_begin_frame_args_; | |
98 } | |
99 | |
100 void CompositorFrameSinkHolder::OnBeginFrameSourcePausedChanged(bool paused) {} | |
101 | |
102 //////////////////////////////////////////////////////////////////////////////// | |
103 // ExoComopositorFrameSink, private: | |
104 | |
105 CompositorFrameSinkHolder::~CompositorFrameSinkHolder() {} | |
106 | |
107 void CompositorFrameSinkHolder::WillDrawSurface() { | |
reveman
2016/12/07 00:46:56
this is not private. please move up to the correct
Alex Z.
2016/12/07 20:09:35
Done.
| |
108 if (surface_) | |
109 surface_->WillDraw(); | |
110 | |
111 UpdateNeedsBeginFrame(); | |
112 } | |
113 | |
114 //////////////////////////////////////////////////////////////////////////////// | |
reveman
2016/12/07 00:46:56
please move this up to match the new location in t
Alex Z.
2016/12/07 20:09:35
Done.
| |
115 // cc::ExternalBeginFrameSouceClient: | |
reveman
2016/12/07 00:46:56
cc::ExternalBeginFrameSouceClient overrides:
Alex Z.
2016/12/07 20:09:35
Done.
| |
116 void CompositorFrameSinkHolder::OnNeedsBeginFrames(bool needs_begin_frames) { | |
reveman
2016/12/07 00:46:57
nit: blankline before this
Alex Z.
2016/12/07 20:09:35
Done.
| |
117 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | |
118 } | |
reveman
2016/12/07 00:46:56
nit: blankline after this
Alex Z.
2016/12/07 20:09:35
Done.
| |
119 } // namespace exo | |
OLD | NEW |