OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "content/browser/android/in_process/synchronous_compositor_registry_in_
proc.h" | |
6 | |
7 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | |
8 #include "content/public/browser/browser_thread.h" | |
9 | |
10 namespace content { | |
11 | |
12 namespace { | |
13 base::LazyInstance<SynchronousCompositorRegistryInProc> g_compositor_registry = | |
14 LAZY_INSTANCE_INITIALIZER; | |
15 } | |
16 | |
17 // static | |
18 SynchronousCompositorRegistryInProc* | |
19 SynchronousCompositorRegistryInProc::GetInstance() { | |
20 return g_compositor_registry.Pointer(); | |
21 } | |
22 | |
23 SynchronousCompositorRegistryInProc::SynchronousCompositorRegistryInProc() { | |
24 DCHECK(CalledOnValidThread()); | |
25 } | |
26 | |
27 SynchronousCompositorRegistryInProc::~SynchronousCompositorRegistryInProc() { | |
28 DCHECK(CalledOnValidThread()); | |
29 } | |
30 | |
31 void SynchronousCompositorRegistryInProc::RegisterCompositor( | |
32 int routing_id, | |
33 SynchronousCompositorImpl* compositor) { | |
34 DCHECK(CalledOnValidThread()); | |
35 DCHECK(compositor); | |
36 Entry& entry = entry_map_[routing_id]; | |
37 DCHECK(!entry.compositor); | |
38 entry.compositor = compositor; | |
39 CheckIsReady(routing_id); | |
40 } | |
41 | |
42 void SynchronousCompositorRegistryInProc::UnregisterCompositor( | |
43 int routing_id, | |
44 SynchronousCompositorImpl* compositor) { | |
45 DCHECK(CalledOnValidThread()); | |
46 DCHECK(compositor); | |
47 DCHECK(entry_map_.find(routing_id) != entry_map_.end()); | |
48 Entry& entry = entry_map_[routing_id]; | |
49 DCHECK_EQ(compositor, entry.compositor); | |
50 | |
51 if (entry.IsReady()) | |
52 UnregisterObjects(routing_id); | |
53 entry.compositor = nullptr; | |
54 RemoveEntryIfNeeded(routing_id); | |
55 } | |
56 | |
57 void SynchronousCompositorRegistryInProc::RegisterBeginFrameSource( | |
58 int routing_id, | |
59 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { | |
60 DCHECK(CalledOnValidThread()); | |
61 DCHECK(begin_frame_source); | |
62 Entry& entry = entry_map_[routing_id]; | |
63 DCHECK(!entry.begin_frame_source); | |
64 entry.begin_frame_source = begin_frame_source; | |
65 CheckIsReady(routing_id); | |
66 } | |
67 | |
68 void SynchronousCompositorRegistryInProc::UnregisterBeginFrameSource( | |
69 int routing_id, | |
70 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { | |
71 DCHECK(CalledOnValidThread()); | |
72 DCHECK(begin_frame_source); | |
73 DCHECK(entry_map_.find(routing_id) != entry_map_.end()); | |
74 Entry& entry = entry_map_[routing_id]; | |
75 DCHECK_EQ(begin_frame_source, entry.begin_frame_source); | |
76 | |
77 if (entry.IsReady()) | |
78 UnregisterObjects(routing_id); | |
79 entry.begin_frame_source = nullptr; | |
80 RemoveEntryIfNeeded(routing_id); | |
81 } | |
82 | |
83 void SynchronousCompositorRegistryInProc::RegisterOutputSurface( | |
84 int routing_id, | |
85 SynchronousCompositorOutputSurface* output_surface) { | |
86 DCHECK(CalledOnValidThread()); | |
87 DCHECK(output_surface); | |
88 Entry& entry = entry_map_[routing_id]; | |
89 DCHECK(!entry.output_surface); | |
90 entry.output_surface = output_surface; | |
91 CheckIsReady(routing_id); | |
92 } | |
93 | |
94 void SynchronousCompositorRegistryInProc::UnregisterOutputSurface( | |
95 int routing_id, | |
96 SynchronousCompositorOutputSurface* output_surface) { | |
97 DCHECK(CalledOnValidThread()); | |
98 DCHECK(output_surface); | |
99 DCHECK(entry_map_.find(routing_id) != entry_map_.end()); | |
100 Entry& entry = entry_map_[routing_id]; | |
101 DCHECK_EQ(output_surface, entry.output_surface); | |
102 | |
103 if (entry.IsReady()) | |
104 UnregisterObjects(routing_id); | |
105 entry.output_surface = nullptr; | |
106 RemoveEntryIfNeeded(routing_id); | |
107 } | |
108 | |
109 void SynchronousCompositorRegistryInProc::RegisterInputHandler( | |
110 int routing_id, | |
111 ui::SynchronousInputHandlerProxy* synchronous_input_handler_proxy) { | |
112 DCHECK(CalledOnValidThread()); | |
113 DCHECK(synchronous_input_handler_proxy); | |
114 Entry& entry = entry_map_[routing_id]; | |
115 DCHECK(!entry.synchronous_input_handler_proxy); | |
116 entry.synchronous_input_handler_proxy = synchronous_input_handler_proxy; | |
117 CheckIsReady(routing_id); | |
118 } | |
119 | |
120 void SynchronousCompositorRegistryInProc::UnregisterInputHandler( | |
121 int routing_id) { | |
122 DCHECK(CalledOnValidThread()); | |
123 DCHECK(entry_map_.find(routing_id) != entry_map_.end()); | |
124 Entry& entry = entry_map_[routing_id]; | |
125 | |
126 if (entry.IsReady()) | |
127 UnregisterObjects(routing_id); | |
128 entry.synchronous_input_handler_proxy = nullptr; | |
129 RemoveEntryIfNeeded(routing_id); | |
130 } | |
131 | |
132 void SynchronousCompositorRegistryInProc::CheckIsReady(int routing_id) { | |
133 DCHECK(entry_map_.find(routing_id) != entry_map_.end()); | |
134 Entry& entry = entry_map_[routing_id]; | |
135 if (entry.IsReady()) { | |
136 entry.compositor->DidInitializeRendererObjects( | |
137 entry.output_surface, entry.begin_frame_source, | |
138 entry.synchronous_input_handler_proxy); | |
139 } | |
140 } | |
141 | |
142 void SynchronousCompositorRegistryInProc::UnregisterObjects(int routing_id) { | |
143 DCHECK(entry_map_.find(routing_id) != entry_map_.end()); | |
144 Entry& entry = entry_map_[routing_id]; | |
145 DCHECK(entry.IsReady()); | |
146 entry.compositor->DidDestroyRendererObjects(); | |
147 } | |
148 | |
149 void SynchronousCompositorRegistryInProc::RemoveEntryIfNeeded(int routing_id) { | |
150 DCHECK(entry_map_.find(routing_id) != entry_map_.end()); | |
151 Entry& entry = entry_map_[routing_id]; | |
152 if (!entry.compositor && !entry.begin_frame_source && !entry.output_surface && | |
153 !entry.synchronous_input_handler_proxy) { | |
154 entry_map_.erase(routing_id); | |
155 } | |
156 } | |
157 | |
158 bool SynchronousCompositorRegistryInProc::CalledOnValidThread() const { | |
159 return BrowserThread::CurrentlyOn(BrowserThread::UI); | |
160 } | |
161 | |
162 SynchronousCompositorRegistryInProc::Entry::Entry() | |
163 : compositor(nullptr), | |
164 begin_frame_source(nullptr), | |
165 output_surface(nullptr), | |
166 synchronous_input_handler_proxy(nullptr) {} | |
167 | |
168 bool SynchronousCompositorRegistryInProc::Entry::IsReady() { | |
169 return compositor && begin_frame_source && output_surface && | |
170 synchronous_input_handler_proxy; | |
171 } | |
172 | |
173 } // namespace content | |
OLD | NEW |