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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/single_thread_proxy.h" | 7 #include "cc/single_thread_proxy.h" |
8 | 8 |
9 #include "CCDrawQuad.h" | 9 #include "CCDrawQuad.h" |
10 #include "CCGraphicsContext.h" | 10 #include "CCGraphicsContext.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "cc/layer_tree_host.h" | 12 #include "cc/layer_tree_host.h" |
13 #include "cc/texture_update_controller.h" | 13 #include "cc/texture_update_controller.h" |
14 #include "cc/timer.h" | 14 #include "cc/timer.h" |
15 #include <wtf/CurrentTime.h> | 15 #include <wtf/CurrentTime.h> |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) | 19 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) |
20 { | 20 { |
21 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>()
; | 21 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>()
; |
22 } | 22 } |
23 | 23 |
24 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) | 24 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) |
25 : m_layerTreeHost(layerTreeHost) | 25 : Proxy(0) |
| 26 , m_layerTreeHost(layerTreeHost) |
26 , m_contextLost(false) | 27 , m_contextLost(false) |
27 , m_rendererInitialized(false) | 28 , m_rendererInitialized(false) |
28 , m_nextFrameIsNewlyCommittedFrame(false) | 29 , m_nextFrameIsNewlyCommittedFrame(false) |
29 , m_totalCommitCount(0) | 30 , m_totalCommitCount(0) |
30 { | 31 { |
31 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 32 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
32 DCHECK(Proxy::isMainThread()); | 33 DCHECK(Proxy::isMainThread()); |
33 } | 34 } |
34 | 35 |
35 void SingleThreadProxy::start() | 36 void SingleThreadProxy::start() |
36 { | 37 { |
37 DebugScopedSetImplThread impl; | 38 DebugScopedSetImplThread impl(this); |
38 m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this); | 39 m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this); |
39 } | 40 } |
40 | 41 |
41 SingleThreadProxy::~SingleThreadProxy() | 42 SingleThreadProxy::~SingleThreadProxy() |
42 { | 43 { |
43 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); | 44 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
44 DCHECK(Proxy::isMainThread()); | 45 DCHECK(Proxy::isMainThread()); |
45 DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop()
got called. | 46 DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop()
got called. |
46 } | 47 } |
47 | 48 |
(...skipping 18 matching lines...) Expand all Loading... |
66 | 67 |
67 void SingleThreadProxy::startPageScaleAnimation(const IntSize& targetPosition, b
ool useAnchor, float scale, double duration) | 68 void SingleThreadProxy::startPageScaleAnimation(const IntSize& targetPosition, b
ool useAnchor, float scale, double duration) |
68 { | 69 { |
69 m_layerTreeHostImpl->startPageScaleAnimation(targetPosition, useAnchor, scal
e, monotonicallyIncreasingTime(), duration); | 70 m_layerTreeHostImpl->startPageScaleAnimation(targetPosition, useAnchor, scal
e, monotonicallyIncreasingTime(), duration); |
70 } | 71 } |
71 | 72 |
72 void SingleThreadProxy::finishAllRendering() | 73 void SingleThreadProxy::finishAllRendering() |
73 { | 74 { |
74 DCHECK(Proxy::isMainThread()); | 75 DCHECK(Proxy::isMainThread()); |
75 { | 76 { |
76 DebugScopedSetImplThread impl; | 77 DebugScopedSetImplThread impl(this); |
77 m_layerTreeHostImpl->finishAllRendering(); | 78 m_layerTreeHostImpl->finishAllRendering(); |
78 } | 79 } |
79 } | 80 } |
80 | 81 |
81 bool SingleThreadProxy::isStarted() const | 82 bool SingleThreadProxy::isStarted() const |
82 { | 83 { |
83 DCHECK(Proxy::isMainThread()); | 84 DCHECK(Proxy::isMainThread()); |
84 return m_layerTreeHostImpl.get(); | 85 return m_layerTreeHostImpl.get(); |
85 } | 86 } |
86 | 87 |
87 bool SingleThreadProxy::initializeContext() | 88 bool SingleThreadProxy::initializeContext() |
88 { | 89 { |
89 DCHECK(Proxy::isMainThread()); | 90 DCHECK(Proxy::isMainThread()); |
90 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); | 91 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); |
91 if (!context.get()) | 92 if (!context.get()) |
92 return false; | 93 return false; |
93 m_contextBeforeInitialization = context.Pass(); | 94 m_contextBeforeInitialization = context.Pass(); |
94 return true; | 95 return true; |
95 } | 96 } |
96 | 97 |
97 void SingleThreadProxy::setSurfaceReady() | 98 void SingleThreadProxy::setSurfaceReady() |
98 { | 99 { |
99 // Scheduling is controlled by the embedder in the single thread case, so no
thing to do. | 100 // Scheduling is controlled by the embedder in the single thread case, so no
thing to do. |
100 } | 101 } |
101 | 102 |
102 void SingleThreadProxy::setVisible(bool visible) | 103 void SingleThreadProxy::setVisible(bool visible) |
103 { | 104 { |
104 DebugScopedSetImplThread impl; | 105 DebugScopedSetImplThread impl(this); |
105 m_layerTreeHostImpl->setVisible(visible); | 106 m_layerTreeHostImpl->setVisible(visible); |
106 } | 107 } |
107 | 108 |
108 bool SingleThreadProxy::initializeRenderer() | 109 bool SingleThreadProxy::initializeRenderer() |
109 { | 110 { |
110 DCHECK(Proxy::isMainThread()); | 111 DCHECK(Proxy::isMainThread()); |
111 DCHECK(m_contextBeforeInitialization.get()); | 112 DCHECK(m_contextBeforeInitialization.get()); |
112 { | 113 { |
113 DebugScopedSetImplThread impl; | 114 DebugScopedSetImplThread impl(this); |
114 bool ok = m_layerTreeHostImpl->initializeRenderer(m_contextBeforeInitial
ization.Pass()); | 115 bool ok = m_layerTreeHostImpl->initializeRenderer(m_contextBeforeInitial
ization.Pass()); |
115 if (ok) { | 116 if (ok) { |
116 m_rendererInitialized = true; | 117 m_rendererInitialized = true; |
117 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); | 118 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); |
118 } | 119 } |
119 | 120 |
120 return ok; | 121 return ok; |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 bool SingleThreadProxy::recreateContext() | 125 bool SingleThreadProxy::recreateContext() |
125 { | 126 { |
126 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); | 127 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); |
127 DCHECK(Proxy::isMainThread()); | 128 DCHECK(Proxy::isMainThread()); |
128 DCHECK(m_contextLost); | 129 DCHECK(m_contextLost); |
129 | 130 |
130 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); | 131 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); |
131 if (!context.get()) | 132 if (!context.get()) |
132 return false; | 133 return false; |
133 | 134 |
134 bool initialized; | 135 bool initialized; |
135 { | 136 { |
136 DebugScopedSetMainThreadBlocked mainThreadBlocked; | 137 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
137 DebugScopedSetImplThread impl; | 138 DebugScopedSetImplThread impl(this); |
138 if (!m_layerTreeHostImpl->contentsTexturesPurged()) | 139 if (!m_layerTreeHostImpl->contentsTexturesPurged()) |
139 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI
mpl->resourceProvider()); | 140 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI
mpl->resourceProvider()); |
140 initialized = m_layerTreeHostImpl->initializeRenderer(context.Pass()); | 141 initialized = m_layerTreeHostImpl->initializeRenderer(context.Pass()); |
141 if (initialized) { | 142 if (initialized) { |
142 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); | 143 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); |
143 } | 144 } |
144 } | 145 } |
145 | 146 |
146 if (initialized) | 147 if (initialized) |
147 m_contextLost = false; | 148 m_contextLost = false; |
(...skipping 26 matching lines...) Expand all Loading... |
174 { | 175 { |
175 // Thread-only feature | 176 // Thread-only feature |
176 NOTREACHED(); | 177 NOTREACHED(); |
177 } | 178 } |
178 | 179 |
179 void SingleThreadProxy::doCommit(scoped_ptr<TextureUpdateQueue> queue) | 180 void SingleThreadProxy::doCommit(scoped_ptr<TextureUpdateQueue> queue) |
180 { | 181 { |
181 DCHECK(Proxy::isMainThread()); | 182 DCHECK(Proxy::isMainThread()); |
182 // Commit immediately | 183 // Commit immediately |
183 { | 184 { |
184 DebugScopedSetMainThreadBlocked mainThreadBlocked; | 185 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
185 DebugScopedSetImplThread impl; | 186 DebugScopedSetImplThread impl(this); |
186 | 187 |
187 base::TimeTicks startTime = base::TimeTicks::HighResNow(); | 188 base::TimeTicks startTime = base::TimeTicks::HighResNow(); |
188 m_layerTreeHostImpl->beginCommit(); | 189 m_layerTreeHostImpl->beginCommit(); |
189 | 190 |
190 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); | 191 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); |
191 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); | 192 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); |
192 | 193 |
193 scoped_ptr<TextureUpdateController> updateController = | 194 scoped_ptr<TextureUpdateController> updateController = |
194 TextureUpdateController::create( | 195 TextureUpdateController::create( |
195 NULL, | 196 NULL, |
196 Proxy::mainThread(), | 197 Proxy::mainThread(), |
197 queue.Pass(), | 198 queue.Pass(), |
198 m_layerTreeHostImpl->resourceProvider()); | 199 m_layerTreeHostImpl->resourceProvider(), |
| 200 hasImplThread()); |
199 updateController->finalize(); | 201 updateController->finalize(); |
200 | 202 |
201 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); | 203 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); |
202 | 204 |
203 m_layerTreeHostImpl->commitComplete(); | 205 m_layerTreeHostImpl->commitComplete(); |
204 | 206 |
205 #ifndef NDEBUG | 207 #ifndef NDEBUG |
206 // In the single-threaded case, the scroll deltas should never be | 208 // In the single-threaded case, the scroll deltas should never be |
207 // touched on the impl layer tree. | 209 // touched on the impl layer tree. |
208 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); | 210 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 size_t SingleThreadProxy::maxPartialTextureUpdates() const | 245 size_t SingleThreadProxy::maxPartialTextureUpdates() const |
244 { | 246 { |
245 return std::numeric_limits<size_t>::max(); | 247 return std::numeric_limits<size_t>::max(); |
246 } | 248 } |
247 | 249 |
248 void SingleThreadProxy::stop() | 250 void SingleThreadProxy::stop() |
249 { | 251 { |
250 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); | 252 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
251 DCHECK(Proxy::isMainThread()); | 253 DCHECK(Proxy::isMainThread()); |
252 { | 254 { |
253 DebugScopedSetMainThreadBlocked mainThreadBlocked; | 255 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
254 DebugScopedSetImplThread impl; | 256 DebugScopedSetImplThread impl(this); |
255 | 257 |
256 if (!m_layerTreeHostImpl->contentsTexturesPurged()) | 258 if (!m_layerTreeHostImpl->contentsTexturesPurged()) |
257 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI
mpl->resourceProvider()); | 259 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI
mpl->resourceProvider()); |
258 m_layerTreeHostImpl.reset(); | 260 m_layerTreeHostImpl.reset(); |
259 } | 261 } |
260 m_layerTreeHost = 0; | 262 m_layerTreeHost = 0; |
261 } | 263 } |
262 | 264 |
263 void SingleThreadProxy::setNeedsRedrawOnImplThread() | 265 void SingleThreadProxy::setNeedsRedrawOnImplThread() |
264 { | 266 { |
265 m_layerTreeHost->scheduleComposite(); | 267 m_layerTreeHost->scheduleComposite(); |
266 } | 268 } |
267 | 269 |
268 void SingleThreadProxy::setNeedsCommitOnImplThread() | 270 void SingleThreadProxy::setNeedsCommitOnImplThread() |
269 { | 271 { |
270 m_layerTreeHost->scheduleComposite(); | 272 m_layerTreeHost->scheduleComposite(); |
271 } | 273 } |
272 | 274 |
273 void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<A
nimationEventsVector> events, double wallClockTime) | 275 void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<A
nimationEventsVector> events, double wallClockTime) |
274 { | 276 { |
275 DCHECK(Proxy::isImplThread()); | 277 DCHECK(Proxy::isImplThread()); |
276 DebugScopedSetMainThread main; | 278 DebugScopedSetMainThread main(this); |
277 m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime); | 279 m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime); |
278 } | 280 } |
279 | 281 |
280 bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitByte
s, int priorityCutoff) | 282 bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitByte
s, int priorityCutoff) |
281 { | 283 { |
282 DCHECK(isImplThread()); | 284 DCHECK(isImplThread()); |
283 if (!m_layerTreeHost->contentsTextureManager()) | 285 if (!m_layerTreeHost->contentsTextureManager()) |
284 return false; | 286 return false; |
285 | 287 |
286 return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(l
imitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider()); | 288 return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(l
imitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider()); |
287 } | 289 } |
288 | 290 |
289 // Called by the legacy scheduling path (e.g. where render_widget does the sched
uling) | 291 // Called by the legacy scheduling path (e.g. where render_widget does the sched
uling) |
290 void SingleThreadProxy::compositeImmediately() | 292 void SingleThreadProxy::compositeImmediately() |
291 { | 293 { |
292 if (commitAndComposite()) { | 294 if (commitAndComposite()) { |
293 m_layerTreeHostImpl->swapBuffers(); | 295 m_layerTreeHostImpl->swapBuffers(); |
294 didSwapFrame(); | 296 didSwapFrame(); |
295 } | 297 } |
296 } | 298 } |
297 | 299 |
298 void SingleThreadProxy::forceSerializeOnSwapBuffers() | 300 void SingleThreadProxy::forceSerializeOnSwapBuffers() |
299 { | 301 { |
300 { | 302 { |
301 DebugScopedSetImplThread impl; | 303 DebugScopedSetImplThread impl(this); |
302 if (m_rendererInitialized) | 304 if (m_rendererInitialized) |
303 m_layerTreeHostImpl->renderer()->doNoOp(); | 305 m_layerTreeHostImpl->renderer()->doNoOp(); |
304 } | 306 } |
305 } | 307 } |
306 | 308 |
307 void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() | 309 void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() |
308 { | 310 { |
309 NOTREACHED(); | 311 NOTREACHED(); |
310 } | 312 } |
311 | 313 |
312 bool SingleThreadProxy::commitAndComposite() | 314 bool SingleThreadProxy::commitAndComposite() |
313 { | 315 { |
314 DCHECK(Proxy::isMainThread()); | 316 DCHECK(Proxy::isMainThread()); |
315 | 317 |
316 if (!m_layerTreeHost->initializeRendererIfNeeded()) | 318 if (!m_layerTreeHost->initializeRendererIfNeeded()) |
317 return false; | 319 return false; |
318 | 320 |
319 // Unlink any texture backings that were deleted | 321 // Unlink any texture backings that were deleted |
320 PrioritizedTextureManager::BackingList evictedContentsTexturesBackings; | 322 PrioritizedTextureManager::BackingList evictedContentsTexturesBackings; |
321 { | 323 { |
322 DebugScopedSetImplThread implThread; | 324 DebugScopedSetImplThread impl(this); |
323 m_layerTreeHost->contentsTextureManager()->getEvictedBackings(evictedCon
tentsTexturesBackings); | 325 m_layerTreeHost->contentsTextureManager()->getEvictedBackings(evictedCon
tentsTexturesBackings); |
324 } | 326 } |
325 m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(evictedCont
entsTexturesBackings); | 327 m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(evictedCont
entsTexturesBackings); |
326 | 328 |
327 scoped_ptr<TextureUpdateQueue> queue = make_scoped_ptr(new TextureUpdateQueu
e); | 329 scoped_ptr<TextureUpdateQueue> queue = make_scoped_ptr(new TextureUpdateQueu
e); |
328 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); | 330 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); |
329 | 331 |
330 if (m_layerTreeHostImpl->contentsTexturesPurged()) | 332 if (m_layerTreeHostImpl->contentsTexturesPurged()) |
331 m_layerTreeHostImpl->resetContentsTexturesPurged(); | 333 m_layerTreeHostImpl->resetContentsTexturesPurged(); |
332 | 334 |
333 m_layerTreeHost->willCommit(); | 335 m_layerTreeHost->willCommit(); |
334 doCommit(queue.Pass()); | 336 doCommit(queue.Pass()); |
335 bool result = doComposite(); | 337 bool result = doComposite(); |
336 m_layerTreeHost->didBeginFrame(); | 338 m_layerTreeHost->didBeginFrame(); |
337 return result; | 339 return result; |
338 } | 340 } |
339 | 341 |
340 bool SingleThreadProxy::doComposite() | 342 bool SingleThreadProxy::doComposite() |
341 { | 343 { |
342 DCHECK(!m_contextLost); | 344 DCHECK(!m_contextLost); |
343 { | 345 { |
344 DebugScopedSetImplThread impl; | 346 DebugScopedSetImplThread impl(this); |
345 | 347 |
346 if (!m_layerTreeHostImpl->visible()) | 348 if (!m_layerTreeHostImpl->visible()) |
347 return false; | 349 return false; |
348 | 350 |
349 double monotonicTime = monotonicallyIncreasingTime(); | 351 double monotonicTime = monotonicallyIncreasingTime(); |
350 double wallClockTime = currentTime(); | 352 double wallClockTime = currentTime(); |
351 m_layerTreeHostImpl->animate(monotonicTime, wallClockTime); | 353 m_layerTreeHostImpl->animate(monotonicTime, wallClockTime); |
352 | 354 |
353 // We guard prepareToDraw() with canDraw() because it always returns a v
alid frame, so can only | 355 // We guard prepareToDraw() with canDraw() because it always returns a v
alid frame, so can only |
354 // be used when such a frame is possible. Since drawLayers() depends on
the result of | 356 // be used when such a frame is possible. Since drawLayers() depends on
the result of |
(...skipping 18 matching lines...) Expand all Loading... |
373 | 375 |
374 void SingleThreadProxy::didSwapFrame() | 376 void SingleThreadProxy::didSwapFrame() |
375 { | 377 { |
376 if (m_nextFrameIsNewlyCommittedFrame) { | 378 if (m_nextFrameIsNewlyCommittedFrame) { |
377 m_nextFrameIsNewlyCommittedFrame = false; | 379 m_nextFrameIsNewlyCommittedFrame = false; |
378 m_layerTreeHost->didCommitAndDrawFrame(); | 380 m_layerTreeHost->didCommitAndDrawFrame(); |
379 } | 381 } |
380 } | 382 } |
381 | 383 |
382 } | 384 } |
OLD | NEW |