OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/output_surface.h" | 5 #include "cc/output/compositor_frame_sink.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "base/trace_event/memory_dump_manager.h" | 14 #include "base/trace_event/memory_dump_manager.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "cc/output/compositor_frame_sink_client.h" |
16 #include "cc/output/managed_memory_policy.h" | 17 #include "cc/output/managed_memory_policy.h" |
17 #include "cc/output/output_surface_client.h" | |
18 #include "gpu/GLES2/gl2extchromium.h" | 18 #include "gpu/GLES2/gl2extchromium.h" |
19 #include "gpu/command_buffer/client/context_support.h" | 19 #include "gpu/command_buffer/client/context_support.h" |
20 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
21 #include "third_party/skia/include/core/SkTraceMemoryDump.h" | 21 #include "third_party/skia/include/core/SkTraceMemoryDump.h" |
22 #include "third_party/skia/include/gpu/GrContext.h" | 22 #include "third_party/skia/include/gpu/GrContext.h" |
23 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
24 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
25 #include "ui/gl/trace_util.h" | 25 #include "ui/gl/trace_util.h" |
26 | 26 |
27 class SkDiscardableMemory; | 27 class SkDiscardableMemory; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 base::trace_event::ProcessMemoryDump* pmd_; | 114 base::trace_event::ProcessMemoryDump* pmd_; |
115 uint64_t share_group_tracing_guid_; | 115 uint64_t share_group_tracing_guid_; |
116 | 116 |
117 DISALLOW_COPY_AND_ASSIGN(SkiaGpuTraceMemoryDump); | 117 DISALLOW_COPY_AND_ASSIGN(SkiaGpuTraceMemoryDump); |
118 }; | 118 }; |
119 | 119 |
120 } // namespace | 120 } // namespace |
121 | 121 |
122 OutputSurface::OutputSurface( | 122 CompositorFrameSink::CompositorFrameSink( |
123 scoped_refptr<ContextProvider> context_provider, | 123 scoped_refptr<ContextProvider> context_provider, |
124 scoped_refptr<ContextProvider> worker_context_provider, | 124 scoped_refptr<ContextProvider> worker_context_provider, |
125 std::unique_ptr<SoftwareOutputDevice> software_device) | 125 std::unique_ptr<SoftwareOutputDevice> software_device) |
126 : context_provider_(std::move(context_provider)), | 126 : context_provider_(std::move(context_provider)), |
127 worker_context_provider_(std::move(worker_context_provider)), | 127 worker_context_provider_(std::move(worker_context_provider)), |
128 software_device_(std::move(software_device)), | 128 software_device_(std::move(software_device)), |
129 weak_ptr_factory_(this) { | 129 weak_ptr_factory_(this) { |
130 client_thread_checker_.DetachFromThread(); | 130 client_thread_checker_.DetachFromThread(); |
131 } | 131 } |
132 | 132 |
133 OutputSurface::OutputSurface( | 133 CompositorFrameSink::CompositorFrameSink( |
134 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 134 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
135 : vulkan_context_provider_(vulkan_context_provider), | 135 : vulkan_context_provider_(vulkan_context_provider), |
136 weak_ptr_factory_(this) { | 136 weak_ptr_factory_(this) { |
137 client_thread_checker_.DetachFromThread(); | 137 client_thread_checker_.DetachFromThread(); |
138 } | 138 } |
139 | 139 |
140 OutputSurface::~OutputSurface() { | 140 CompositorFrameSink::~CompositorFrameSink() { |
141 if (client_) | 141 if (client_) |
142 DetachFromClientInternal(); | 142 DetachFromClientInternal(); |
143 } | 143 } |
144 | 144 |
145 bool OutputSurface::HasExternalStencilTest() const { | 145 bool CompositorFrameSink::HasExternalStencilTest() const { |
146 return false; | 146 return false; |
147 } | 147 } |
148 | 148 |
149 void OutputSurface::ApplyExternalStencil() {} | 149 void CompositorFrameSink::ApplyExternalStencil() {} |
150 | 150 |
151 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { | 151 bool CompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { |
152 DCHECK(client_thread_checker_.CalledOnValidThread()); | 152 DCHECK(client_thread_checker_.CalledOnValidThread()); |
153 DCHECK(client); | 153 DCHECK(client); |
154 DCHECK(!client_); | 154 DCHECK(!client_); |
155 client_ = client; | 155 client_ = client; |
156 bool success = true; | 156 bool success = true; |
157 | 157 |
158 if (context_provider_.get()) { | 158 if (context_provider_.get()) { |
159 success = context_provider_->BindToCurrentThread(); | 159 success = context_provider_->BindToCurrentThread(); |
160 if (success) { | 160 if (success) { |
161 context_provider_->SetLostContextCallback(base::Bind( | 161 context_provider_->SetLostContextCallback( |
162 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); | 162 base::Bind(&CompositorFrameSink::DidLoseCompositorFrameSink, |
| 163 base::Unretained(this))); |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
166 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 167 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
167 // Don't register a dump provider in these cases. | 168 // Don't register a dump provider in these cases. |
168 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 | 169 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 |
169 if (base::ThreadTaskRunnerHandle::IsSet()) { | 170 if (base::ThreadTaskRunnerHandle::IsSet()) { |
170 // Now that we are on the context thread, register a dump provider with this | 171 // Now that we are on the context thread, register a dump provider with this |
171 // thread's task runner. This will overwrite any previous dump provider | 172 // thread's task runner. This will overwrite any previous dump provider |
172 // registered. | 173 // registered. |
173 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 174 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
174 this, "OutputSurface", base::ThreadTaskRunnerHandle::Get()); | 175 this, "CompositorFrameSink", base::ThreadTaskRunnerHandle::Get()); |
175 } | 176 } |
176 | 177 |
177 if (!success) | 178 if (!success) |
178 DetachFromClient(); | 179 DetachFromClient(); |
179 return success; | 180 return success; |
180 } | 181 } |
181 | 182 |
182 void OutputSurface::DetachFromClient() { | 183 void CompositorFrameSink::DetachFromClient() { |
183 DetachFromClientInternal(); | 184 DetachFromClientInternal(); |
184 } | 185 } |
185 | 186 |
186 void OutputSurface::EnsureBackbuffer() { | 187 void CompositorFrameSink::EnsureBackbuffer() { |
187 if (software_device_) | 188 if (software_device_) |
188 software_device_->EnsureBackbuffer(); | 189 software_device_->EnsureBackbuffer(); |
189 } | 190 } |
190 | 191 |
191 void OutputSurface::DiscardBackbuffer() { | 192 void CompositorFrameSink::DiscardBackbuffer() { |
192 if (context_provider_.get()) | 193 if (context_provider_.get()) |
193 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); | 194 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); |
194 if (software_device_) | 195 if (software_device_) |
195 software_device_->DiscardBackbuffer(); | 196 software_device_->DiscardBackbuffer(); |
196 } | 197 } |
197 | 198 |
198 void OutputSurface::Reshape(const gfx::Size& size, | 199 void CompositorFrameSink::Reshape(const gfx::Size& size, |
199 float scale_factor, | 200 float scale_factor, |
200 const gfx::ColorSpace& color_space, | 201 const gfx::ColorSpace& color_space, |
201 bool has_alpha) { | 202 bool has_alpha) { |
202 device_color_space_ = color_space; | 203 device_color_space_ = color_space; |
203 if (size == surface_size_ && scale_factor == device_scale_factor_ && | 204 if (size == surface_size_ && scale_factor == device_scale_factor_ && |
204 has_alpha == has_alpha_) | 205 has_alpha == has_alpha_) |
205 return; | 206 return; |
206 | 207 |
207 surface_size_ = size; | 208 surface_size_ = size; |
208 device_scale_factor_ = scale_factor; | 209 device_scale_factor_ = scale_factor; |
209 has_alpha_ = has_alpha; | 210 has_alpha_ = has_alpha; |
210 if (context_provider_.get()) { | 211 if (context_provider_.get()) { |
211 context_provider_->ContextGL()->ResizeCHROMIUM(size.width(), size.height(), | 212 context_provider_->ContextGL()->ResizeCHROMIUM(size.width(), size.height(), |
212 scale_factor, has_alpha); | 213 scale_factor, has_alpha); |
213 } | 214 } |
214 if (software_device_) | 215 if (software_device_) |
215 software_device_->Resize(size, scale_factor); | 216 software_device_->Resize(size, scale_factor); |
216 } | 217 } |
217 | 218 |
218 void OutputSurface::BindFramebuffer() { | 219 void CompositorFrameSink::BindFramebuffer() { |
219 DCHECK(context_provider_.get()); | 220 DCHECK(context_provider_.get()); |
220 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); | 221 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); |
221 } | 222 } |
222 | 223 |
223 void OutputSurface::PostSwapBuffersComplete() { | 224 void CompositorFrameSink::PostSwapBuffersComplete() { |
224 base::ThreadTaskRunnerHandle::Get()->PostTask( | 225 base::ThreadTaskRunnerHandle::Get()->PostTask( |
225 FROM_HERE, base::Bind(&OutputSurface::OnSwapBuffersComplete, | 226 FROM_HERE, base::Bind(&CompositorFrameSink::OnSwapBuffersComplete, |
226 weak_ptr_factory_.GetWeakPtr())); | 227 weak_ptr_factory_.GetWeakPtr())); |
227 } | 228 } |
228 | 229 |
229 // We don't post tasks bound to the client directly since they might run | 230 // We don't post tasks bound to the client directly since they might run |
230 // after the OutputSurface has been destroyed. | 231 // after the CompositorFrameSink has been destroyed. |
231 void OutputSurface::OnSwapBuffersComplete() { | 232 void CompositorFrameSink::OnSwapBuffersComplete() { |
232 client_->DidSwapBuffersComplete(); | 233 client_->DidSwapBuffersComplete(); |
233 } | 234 } |
234 | 235 |
235 void OutputSurface::DidReceiveTextureInUseResponses( | 236 void CompositorFrameSink::DidReceiveTextureInUseResponses( |
236 const gpu::TextureInUseResponses& responses) { | 237 const gpu::TextureInUseResponses& responses) { |
237 client_->DidReceiveTextureInUseResponses(responses); | 238 client_->DidReceiveTextureInUseResponses(responses); |
238 } | 239 } |
239 | 240 |
240 OverlayCandidateValidator* OutputSurface::GetOverlayCandidateValidator() const { | 241 OverlayCandidateValidator* CompositorFrameSink::GetOverlayCandidateValidator() |
| 242 const { |
241 return nullptr; | 243 return nullptr; |
242 } | 244 } |
243 | 245 |
244 bool OutputSurface::IsDisplayedAsOverlayPlane() const { | 246 bool CompositorFrameSink::IsDisplayedAsOverlayPlane() const { |
245 return false; | 247 return false; |
246 } | 248 } |
247 | 249 |
248 unsigned OutputSurface::GetOverlayTextureId() const { | 250 unsigned CompositorFrameSink::GetOverlayTextureId() const { |
249 return 0; | 251 return 0; |
250 } | 252 } |
251 | 253 |
252 bool OutputSurface::SurfaceIsSuspendForRecycle() const { | 254 bool CompositorFrameSink::SurfaceIsSuspendForRecycle() const { |
253 return false; | 255 return false; |
254 } | 256 } |
255 | 257 |
256 bool OutputSurface::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 258 bool CompositorFrameSink::OnMemoryDump( |
257 base::trace_event::ProcessMemoryDump* pmd) { | 259 const base::trace_event::MemoryDumpArgs& args, |
| 260 base::trace_event::ProcessMemoryDump* pmd) { |
258 if (auto* context_provider = this->context_provider()) { | 261 if (auto* context_provider = this->context_provider()) { |
259 // No need to lock, main context provider is not shared. | 262 // No need to lock, main context provider is not shared. |
260 if (auto* gr_context = context_provider->GrContext()) { | 263 if (auto* gr_context = context_provider->GrContext()) { |
261 SkiaGpuTraceMemoryDump trace_memory_dump( | 264 SkiaGpuTraceMemoryDump trace_memory_dump( |
262 pmd, context_provider->ContextSupport()->ShareGroupTracingGUID()); | 265 pmd, context_provider->ContextSupport()->ShareGroupTracingGUID()); |
263 gr_context->dumpMemoryStatistics(&trace_memory_dump); | 266 gr_context->dumpMemoryStatistics(&trace_memory_dump); |
264 } | 267 } |
265 } | 268 } |
266 if (auto* context_provider = worker_context_provider()) { | 269 if (auto* context_provider = worker_context_provider()) { |
267 ContextProvider::ScopedContextLock scoped_context(context_provider); | 270 ContextProvider::ScopedContextLock scoped_context(context_provider); |
268 | 271 |
269 if (auto* gr_context = context_provider->GrContext()) { | 272 if (auto* gr_context = context_provider->GrContext()) { |
270 SkiaGpuTraceMemoryDump trace_memory_dump( | 273 SkiaGpuTraceMemoryDump trace_memory_dump( |
271 pmd, context_provider->ContextSupport()->ShareGroupTracingGUID()); | 274 pmd, context_provider->ContextSupport()->ShareGroupTracingGUID()); |
272 gr_context->dumpMemoryStatistics(&trace_memory_dump); | 275 gr_context->dumpMemoryStatistics(&trace_memory_dump); |
273 } | 276 } |
274 } | 277 } |
275 | 278 |
276 return true; | 279 return true; |
277 } | 280 } |
278 | 281 |
279 void OutputSurface::DetachFromClientInternal() { | 282 void CompositorFrameSink::DetachFromClientInternal() { |
280 DCHECK(client_thread_checker_.CalledOnValidThread()); | 283 DCHECK(client_thread_checker_.CalledOnValidThread()); |
281 DCHECK(client_); | 284 DCHECK(client_); |
282 | 285 |
283 // Unregister any dump provider. Safe to call (no-op) if we have not yet | 286 // Unregister any dump provider. Safe to call (no-op) if we have not yet |
284 // registered. | 287 // registered. |
285 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 288 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
286 this); | 289 this); |
287 | 290 |
288 if (context_provider_.get()) { | 291 if (context_provider_.get()) { |
289 context_provider_->SetLostContextCallback( | 292 context_provider_->SetLostContextCallback( |
290 ContextProvider::LostContextCallback()); | 293 ContextProvider::LostContextCallback()); |
291 } | 294 } |
292 context_provider_ = nullptr; | 295 context_provider_ = nullptr; |
293 client_ = nullptr; | 296 client_ = nullptr; |
294 weak_ptr_factory_.InvalidateWeakPtrs(); | 297 weak_ptr_factory_.InvalidateWeakPtrs(); |
295 } | 298 } |
296 | 299 |
297 void OutputSurface::DidLoseOutputSurface() { | 300 void CompositorFrameSink::DidLoseCompositorFrameSink() { |
298 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); | 301 TRACE_EVENT0("cc", "CompositorFrameSink::DidLoseCompositorFrameSink"); |
299 client_->DidLoseOutputSurface(); | 302 client_->DidLoseCompositorFrameSink(); |
300 } | 303 } |
301 | 304 |
302 } // namespace cc | 305 } // namespace cc |
OLD | NEW |