OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/single_thread_proxy.h" | 5 #include "cc/single_thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/draw_quad.h" | 9 #include "cc/draw_quad.h" |
10 #include "cc/layer_tree_host.h" | 10 #include "cc/layer_tree_host.h" |
11 #include "cc/layer_tree_impl.h" | 11 #include "cc/layer_tree_impl.h" |
12 #include "cc/output_surface.h" | 12 #include "cc/output_surface.h" |
13 #include "cc/prioritized_resource_manager.h" | 13 #include "cc/prioritized_resource_manager.h" |
14 #include "cc/resource_update_controller.h" | 14 #include "cc/resource_update_controller.h" |
15 #include "cc/thread.h" | 15 #include "cc/thread.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) | 20 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) |
20 { | 21 { |
21 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>()
; | 22 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>()
; |
22 } | 23 } |
23 | 24 |
24 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) | 25 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) |
25 : Proxy(scoped_ptr<Thread>(NULL)) | 26 : Proxy(scoped_ptr<Thread>(NULL)) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 133 |
133 bool SingleThreadProxy::recreateOutputSurface() | 134 bool SingleThreadProxy::recreateOutputSurface() |
134 { | 135 { |
135 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); | 136 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); |
136 DCHECK(Proxy::isMainThread()); | 137 DCHECK(Proxy::isMainThread()); |
137 DCHECK(m_outputSurfaceLost); | 138 DCHECK(m_outputSurfaceLost); |
138 | 139 |
139 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa
ce(); | 140 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa
ce(); |
140 if (!outputSurface.get()) | 141 if (!outputSurface.get()) |
141 return false; | 142 return false; |
| 143 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL; |
| 144 GrContext* offscreenGrContext = NULL; |
| 145 if (m_RendererCapabilitiesForMainThread.usingOffscreenContext3d && m_layerTr
eeHost->needsOffscreenContext()) { |
| 146 offscreenContext3d = m_layerTreeHost->client()->offscreenContext3dForMai
nThread(); |
| 147 if (!offscreenContext3d || !offscreenContext3d->makeContextCurrent()) |
| 148 return false; |
| 149 offscreenGrContext = m_layerTreeHost->client()->offscreenGrContextForMai
nThread(); |
| 150 } |
142 | 151 |
143 bool initialized; | 152 bool initialized; |
144 { | 153 { |
145 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); | 154 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
146 DebugScopedSetImplThread impl(this); | 155 DebugScopedSetImplThread impl(this); |
147 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl-
>resourceProvider()); | 156 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl-
>resourceProvider()); |
148 initialized = m_layerTreeHostImpl->initializeRenderer(outputSurface.Pass
()); | 157 initialized = m_layerTreeHostImpl->initializeRenderer(outputSurface.Pass
()); |
149 if (initialized) { | 158 if (initialized) { |
150 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); | 159 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); |
| 160 m_layerTreeHostImpl->resourceProvider()->setGaneshContexts(offscreen
Context3d, offscreenGrContext); |
151 } | 161 } |
152 } | 162 } |
153 | 163 |
154 if (initialized) | 164 if (initialized) |
155 m_outputSurfaceLost = false; | 165 m_outputSurfaceLost = false; |
156 | 166 |
157 return initialized; | 167 return initialized; |
158 } | 168 } |
159 | 169 |
160 void SingleThreadProxy::renderingStats(RenderingStats* stats) | 170 void SingleThreadProxy::renderingStats(RenderingStats* stats) |
(...skipping 23 matching lines...) Expand all Loading... |
184 { | 194 { |
185 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); | 195 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
186 DebugScopedSetImplThread impl(this); | 196 DebugScopedSetImplThread impl(this); |
187 | 197 |
188 base::TimeTicks startTime = base::TimeTicks::HighResNow(); | 198 base::TimeTicks startTime = base::TimeTicks::HighResNow(); |
189 m_layerTreeHostImpl->beginCommit(); | 199 m_layerTreeHostImpl->beginCommit(); |
190 | 200 |
191 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); | 201 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); |
192 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); | 202 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); |
193 | 203 |
194 scoped_ptr<ResourceUpdateController> updateController = | 204 scoped_ptr<ResourceUpdateController> updateController = ResourceUpdateCo
ntroller::create(NULL, Proxy::mainThread(), queue.Pass(), m_layerTreeHostImpl->r
esourceProvider(), hasImplThread()); |
195 ResourceUpdateController::create( | |
196 NULL, | |
197 Proxy::mainThread(), | |
198 queue.Pass(), | |
199 m_layerTreeHostImpl->resourceProvider(), | |
200 hasImplThread()); | |
201 updateController->finalize(); | 205 updateController->finalize(); |
202 | 206 |
203 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); | 207 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); |
204 | 208 |
205 m_layerTreeHostImpl->commitComplete(); | 209 m_layerTreeHostImpl->commitComplete(); |
206 | 210 |
207 #ifndef NDEBUG | 211 #ifndef NDEBUG |
208 // In the single-threaded case, the scroll deltas should never be | 212 // In the single-threaded case, the scroll deltas should never be |
209 // touched on the impl layer tree. | 213 // touched on the impl layer tree. |
210 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); | 214 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 NOTREACHED(); | 359 NOTREACHED(); |
356 } | 360 } |
357 | 361 |
358 bool SingleThreadProxy::commitAndComposite() | 362 bool SingleThreadProxy::commitAndComposite() |
359 { | 363 { |
360 DCHECK(Proxy::isMainThread()); | 364 DCHECK(Proxy::isMainThread()); |
361 | 365 |
362 if (!m_layerTreeHost->initializeRendererIfNeeded()) | 366 if (!m_layerTreeHost->initializeRendererIfNeeded()) |
363 return false; | 367 return false; |
364 | 368 |
| 369 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL; |
| 370 GrContext* offscreenGrContext = NULL; |
| 371 if (m_RendererCapabilitiesForMainThread.usingOffscreenContext3d && m_layerTr
eeHost->needsOffscreenContext()) { |
| 372 offscreenContext3d = m_layerTreeHost->client()->offscreenContext3dForMai
nThread(); |
| 373 offscreenGrContext = m_layerTreeHost->client()->offscreenGrContextForMai
nThread(); |
| 374 } |
| 375 |
365 m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); | 376 m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); |
366 | 377 |
367 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu
eue); | 378 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu
eue); |
368 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); | 379 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); |
369 | 380 |
370 m_layerTreeHost->willCommit(); | 381 m_layerTreeHost->willCommit(); |
371 doCommit(queue.Pass()); | 382 doCommit(queue.Pass()); |
372 bool result = doComposite(); | 383 bool result = doComposite(offscreenContext3d, offscreenGrContext); |
373 m_layerTreeHost->didBeginFrame(); | 384 m_layerTreeHost->didBeginFrame(); |
374 return result; | 385 return result; |
375 } | 386 } |
376 | 387 |
377 bool SingleThreadProxy::doComposite() | 388 bool SingleThreadProxy::doComposite(WebKit::WebGraphicsContext3D* offscreenC
ontext3d, GrContext* offscreenGrContext) |
378 { | 389 { |
379 DCHECK(!m_outputSurfaceLost); | 390 DCHECK(!m_outputSurfaceLost); |
380 { | 391 { |
381 DebugScopedSetImplThread impl(this); | 392 DebugScopedSetImplThread impl(this); |
382 base::AutoReset<bool> markInside(&m_insideDraw, true); | 393 base::AutoReset<bool> markInside(&m_insideDraw, true); |
383 | 394 |
| 395 m_layerTreeHostImpl->resourceProvider()->setGaneshContexts(offscreenCont
ext3d, offscreenGrContext); |
| 396 |
384 if (!m_layerTreeHostImpl->visible()) | 397 if (!m_layerTreeHostImpl->visible()) |
385 return false; | 398 return false; |
386 | 399 |
387 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); | 400 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); |
388 | 401 |
389 // We guard prepareToDraw() with canDraw() because it always returns a v
alid frame, so can only | 402 // We guard prepareToDraw() with canDraw() because it always returns a v
alid frame, so can only |
390 // be used when such a frame is possible. Since drawLayers() depends on
the result of | 403 // be used when such a frame is possible. Since drawLayers() depends on
the result of |
391 // prepareToDraw(), it is guarded on canDraw() as well. | 404 // prepareToDraw(), it is guarded on canDraw() as well. |
392 if (!m_layerTreeHostImpl->canDraw()) | 405 if (!m_layerTreeHostImpl->canDraw()) |
393 return false; | 406 return false; |
(...skipping 29 matching lines...) Expand all Loading... |
423 } | 436 } |
424 | 437 |
425 skia::RefPtr<SkPicture> SingleThreadProxy::capturePicture() | 438 skia::RefPtr<SkPicture> SingleThreadProxy::capturePicture() |
426 { | 439 { |
427 // Requires impl-side painting, which is only supported in threaded composit
ing. | 440 // Requires impl-side painting, which is only supported in threaded composit
ing. |
428 NOTREACHED(); | 441 NOTREACHED(); |
429 return skia::RefPtr<SkPicture>(); | 442 return skia::RefPtr<SkPicture>(); |
430 } | 443 } |
431 | 444 |
432 } // namespace cc | 445 } // namespace cc |
OLD | NEW |