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/exo_compositor_frame_sink.h" | |
6 | |
7 #include "cc/surfaces/surface_manager.h" | |
8 #include "ui/aura/env.h" | |
9 | |
10 namespace exo { | |
11 | |
12 //////////////////////////////////////////////////////////////////////////////// | |
13 // ExoCompositorFrameSink, public: | |
14 | |
15 ExoCompositorFrameSink::ExoCompositorFrameSink() | |
16 : frame_sink_id_( | |
17 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId()) { | |
Fady Samuel
2016/11/14 23:29:41
Don't allocate the FrameSinkId in here. Instead, t
Alex Z.
2016/11/15 15:53:58
Done.
| |
18 id_allocator_.reset(new cc::SurfaceIdAllocator()); | |
19 } | |
20 | |
21 void ExoCompositorFrameSink::Init(cc::SurfaceManager* surface_manager) { | |
22 surface_factory_.reset( | |
23 new cc::SurfaceFactory(frame_sink_id_, surface_manager, this)); | |
24 } | |
25 | |
26 void ExoCompositorFrameSink::UnregisterSurface( | |
27 const cc::SurfaceId& surface_id) { | |
28 if (surface_id.local_frame_id().is_valid()) | |
29 surface_factory_->Destroy(surface_id.local_frame_id()); | |
30 } | |
31 | |
32 const cc::SurfaceId& ExoCompositorFrameSink::CommitToNewSurface( | |
33 const cc::LocalFrameId& old_local_frame_id) { | |
34 cc::LocalFrameId local_frame_id = id_allocator_->GenerateId(); | |
35 surface_factory_->Create(local_frame_id); | |
36 | |
37 if (old_local_frame_id.is_valid()) { | |
38 surface_factory_->SetPreviousFrameSurface(local_frame_id, | |
39 old_local_frame_id); | |
40 surface_factory_->Destroy(old_local_frame_id); | |
41 } | |
42 | |
43 return std::move(cc::SurfaceId(frame_sink_id_, local_frame_id)); | |
44 } | |
45 //////////////////////////////////////////////////////////////////////////////// | |
46 // cc::SurfaceFactoryClient overrides: | |
47 | |
48 void ExoCompositorFrameSink::ReturnResources( | |
49 const cc::ReturnedResourceArray& resources) { | |
50 scoped_refptr<ExoCompositorFrameSink> holder(this); | |
51 for (auto& resource : resources) { | |
52 auto it = release_callbacks_.find(resource.id); | |
53 DCHECK(it != release_callbacks_.end()); | |
54 it->second.second->Run(resource.sync_token, resource.lost); | |
55 release_callbacks_.erase(it); | |
56 } | |
57 } | |
58 | |
59 void ExoCompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id, | |
60 const gfx::Rect& damage_rect) {} | |
61 | |
62 void ExoCompositorFrameSink::SetBeginFrameSource( | |
63 cc::BeginFrameSource* begin_frame_source) { | |
64 if (begin_frame_source_ && added_frame_observer_) { | |
65 begin_frame_source_->RemoveObserver(this); | |
66 added_frame_observer_ = false; | |
67 } | |
68 begin_frame_source_ = begin_frame_source; | |
69 UpdateNeedsBeginFrameInternal(); | |
70 } | |
71 | |
72 //////////////////////////////////////////////////////////////////////////////// | |
73 // cc::mojom::MojoCompositorFrameSink overrides: | |
74 | |
75 void ExoCompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { | |
76 needs_begin_frame_ = needs_begin_frame; | |
77 UpdateNeedsBeginFrameInternal(); | |
78 } | |
79 | |
80 void ExoCompositorFrameSink::SubmitCompositorFrame(cc::CompositorFrame frame) {} | |
81 | |
82 //////////////////////////////////////////////////////////////////////////////// | |
83 // cc::BeginFrameObserver overrides: | |
84 | |
85 void ExoCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
86 UpdateNeedsBeginFrameInternal(); | |
87 last_begin_frame_args_ = args; | |
88 } | |
89 | |
90 const cc::BeginFrameArgs& ExoCompositorFrameSink::LastUsedBeginFrameArgs() | |
91 const { | |
92 return last_begin_frame_args_; | |
93 } | |
94 | |
95 void ExoCompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {} | |
96 | |
97 //////////////////////////////////////////////////////////////////////////////// | |
98 // ExoCompositorFrameSink, private: | |
99 | |
100 ExoCompositorFrameSink::~ExoCompositorFrameSink() { | |
101 if (surface_factory_->manager()) | |
102 surface_factory_->manager()->InvalidateFrameSinkId(frame_sink_id_); | |
103 } | |
104 | |
105 void ExoCompositorFrameSink::UpdateNeedsBeginFrameInternal() { | |
106 if (!begin_frame_source_) | |
107 return; | |
108 | |
109 if (needs_begin_frame_ == added_frame_observer_) | |
110 return; | |
111 | |
112 added_frame_observer_ = needs_begin_frame_; | |
113 if (needs_begin_frame_) | |
114 begin_frame_source_->AddObserver(this); | |
115 else | |
116 begin_frame_source_->RemoveObserver(this); | |
117 } | |
118 | |
119 } // namespace exo | |
OLD | NEW |