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 void CompositorFrameSinkHolder::AddResourceReleaseCallback( | |
28 cc::ResourceId id, | |
29 std::unique_ptr<cc::SingleReleaseCallback> callback) { | |
30 release_callbacks_[id] = std::make_pair(this, std::move(callback)); | |
Fady Samuel
2016/11/23 21:14:48
compositor_frame_sink_->SetNeedsBeginFrame(true);
Alex Z.
2016/11/24 18:58:45
Done.
| |
31 } | |
32 | |
33 void CompositorFrameSinkHolder::ActivateFrameCallbacks( | |
34 std::list<FrameCallback>& frame_callbacks) { | |
35 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | |
36 frame_callbacks); | |
37 } | |
38 | |
39 void CompositorFrameSinkHolder::CancelFrameCallbacks() { | |
40 // Call pending frame callbacks with a null frame time to indicate that they | |
41 // have been cancelled. | |
42 for (const auto& frame_callback : active_frame_callbacks_) | |
43 frame_callback.Run(base::TimeTicks()); | |
44 } | |
45 | |
46 CompositorFrameSinkHolder::~CompositorFrameSinkHolder() { | |
47 begin_frame_source_.reset(); | |
48 } | |
49 | |
50 void CompositorFrameSinkHolder::UpdateNeedsBeginFrame() { | |
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 } | |
60 | |
61 void CompositorFrameSinkHolder::SubmitCompositorFrame( | |
62 const cc::LocalFrameId& local_frame_id, | |
63 cc::CompositorFrame frame) { | |
64 if (compositor_frame_sink_) | |
65 compositor_frame_sink_->SubmitCompositorFrame(local_frame_id, | |
66 std::move(frame)); | |
67 } | |
68 | |
69 //////////////////////////////////////////////////////////////////////////////// | |
70 // cc::mojom::MojoCompositorFrameSinkClient overrides: | |
71 | |
72 // TODO(staraz): Implement this | |
73 void CompositorFrameSinkHolder::DidReceiveCompositorFrameAck() {} | |
74 | |
75 void CompositorFrameSinkHolder::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
76 // Run active frame callbacks here | |
77 while (!active_frame_callbacks_.empty()) { | |
78 active_frame_callbacks_.front().Run(args.frame_time); | |
79 active_frame_callbacks_.pop_front(); | |
80 } | |
81 begin_frame_source_->OnBeginFrame(args); | |
82 } | |
83 | |
84 void CompositorFrameSinkHolder::ReclaimResources( | |
85 const cc::ReturnedResourceArray& resources) { | |
86 scoped_refptr<CompositorFrameSinkHolder> holder(this); | |
87 for (auto& resource : resources) { | |
88 auto it = release_callbacks_.find(resource.id); | |
89 DCHECK(it != release_callbacks_.end()); | |
90 it->second.second->Run(resource.sync_token, resource.lost); | |
91 release_callbacks_.erase(it); | |
92 } | |
93 } | |
94 | |
95 void CompositorFrameSinkHolder::WillDrawSurface() { | |
96 if (surface_) | |
97 surface_->WillDraw(); | |
98 } | |
99 | |
100 //////////////////////////////////////////////////////////////////////////////// | |
101 // ExoComopositorFrameSink, private: | |
102 | |
103 void CompositorFrameSinkHolder::OnNeedsBeginFrames(bool needs_begin_frames) { | |
104 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | |
105 } | |
106 | |
107 } // namespace exo | |
OLD | NEW |