Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(692)

Side by Side Diff: cc/single_thread_proxy.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase to 165064 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/draw_quad.h" 10 #include "cc/draw_quad.h"
11 #include "cc/graphics_context.h" 11 #include "cc/graphics_context.h"
12 #include "cc/layer_tree_host.h" 12 #include "cc/layer_tree_host.h"
13 #include "cc/resource_update_controller.h" 13 #include "cc/resource_update_controller.h"
14 14
15 namespace cc { 15 namespace cc {
16 16
17 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) 17 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost)
18 { 18 {
19 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>() ; 19 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>() ;
20 } 20 }
21 21
22 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) 22 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost)
23 : m_layerTreeHost(layerTreeHost) 23 : Proxy(0)
24 , m_layerTreeHost(layerTreeHost)
24 , m_contextLost(false) 25 , m_contextLost(false)
25 , m_rendererInitialized(false) 26 , m_rendererInitialized(false)
26 , m_nextFrameIsNewlyCommittedFrame(false) 27 , m_nextFrameIsNewlyCommittedFrame(false)
27 , m_totalCommitCount(0) 28 , m_totalCommitCount(0)
28 { 29 {
29 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); 30 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
30 DCHECK(Proxy::isMainThread()); 31 DCHECK(Proxy::isMainThread());
31 } 32 }
32 33
33 void SingleThreadProxy::start() 34 void SingleThreadProxy::start()
34 { 35 {
35 DebugScopedSetImplThread impl; 36 DebugScopedSetImplThread impl(this);
36 m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this); 37 m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this);
37 } 38 }
38 39
39 SingleThreadProxy::~SingleThreadProxy() 40 SingleThreadProxy::~SingleThreadProxy()
40 { 41 {
41 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); 42 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
42 DCHECK(Proxy::isMainThread()); 43 DCHECK(Proxy::isMainThread());
43 DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop() got called. 44 DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop() got called.
44 } 45 }
45 46
(...skipping 18 matching lines...) Expand all
64 65
65 void SingleThreadProxy::startPageScaleAnimation(const IntSize& targetPosition, b ool useAnchor, float scale, base::TimeDelta duration) 66 void SingleThreadProxy::startPageScaleAnimation(const IntSize& targetPosition, b ool useAnchor, float scale, base::TimeDelta duration)
66 { 67 {
67 m_layerTreeHostImpl->startPageScaleAnimation(targetPosition, useAnchor, scal e, base::TimeTicks::Now(), duration); 68 m_layerTreeHostImpl->startPageScaleAnimation(targetPosition, useAnchor, scal e, base::TimeTicks::Now(), duration);
68 } 69 }
69 70
70 void SingleThreadProxy::finishAllRendering() 71 void SingleThreadProxy::finishAllRendering()
71 { 72 {
72 DCHECK(Proxy::isMainThread()); 73 DCHECK(Proxy::isMainThread());
73 { 74 {
74 DebugScopedSetImplThread impl; 75 DebugScopedSetImplThread impl(this);
75 m_layerTreeHostImpl->finishAllRendering(); 76 m_layerTreeHostImpl->finishAllRendering();
76 } 77 }
77 } 78 }
78 79
79 bool SingleThreadProxy::isStarted() const 80 bool SingleThreadProxy::isStarted() const
80 { 81 {
81 DCHECK(Proxy::isMainThread()); 82 DCHECK(Proxy::isMainThread());
82 return m_layerTreeHostImpl.get(); 83 return m_layerTreeHostImpl.get();
83 } 84 }
84 85
85 bool SingleThreadProxy::initializeContext() 86 bool SingleThreadProxy::initializeContext()
86 { 87 {
87 DCHECK(Proxy::isMainThread()); 88 DCHECK(Proxy::isMainThread());
88 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); 89 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext();
89 if (!context.get()) 90 if (!context.get())
90 return false; 91 return false;
91 m_contextBeforeInitialization = context.Pass(); 92 m_contextBeforeInitialization = context.Pass();
92 return true; 93 return true;
93 } 94 }
94 95
95 void SingleThreadProxy::setSurfaceReady() 96 void SingleThreadProxy::setSurfaceReady()
96 { 97 {
97 // Scheduling is controlled by the embedder in the single thread case, so no thing to do. 98 // Scheduling is controlled by the embedder in the single thread case, so no thing to do.
98 } 99 }
99 100
100 void SingleThreadProxy::setVisible(bool visible) 101 void SingleThreadProxy::setVisible(bool visible)
101 { 102 {
102 DebugScopedSetImplThread impl; 103 DebugScopedSetImplThread impl(this);
103 m_layerTreeHostImpl->setVisible(visible); 104 m_layerTreeHostImpl->setVisible(visible);
104 } 105 }
105 106
106 bool SingleThreadProxy::initializeRenderer() 107 bool SingleThreadProxy::initializeRenderer()
107 { 108 {
108 DCHECK(Proxy::isMainThread()); 109 DCHECK(Proxy::isMainThread());
109 DCHECK(m_contextBeforeInitialization.get()); 110 DCHECK(m_contextBeforeInitialization.get());
110 { 111 {
111 DebugScopedSetImplThread impl; 112 DebugScopedSetImplThread impl(this);
112 bool ok = m_layerTreeHostImpl->initializeRenderer(m_contextBeforeInitial ization.Pass()); 113 bool ok = m_layerTreeHostImpl->initializeRenderer(m_contextBeforeInitial ization.Pass());
113 if (ok) { 114 if (ok) {
114 m_rendererInitialized = true; 115 m_rendererInitialized = true;
115 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC apabilities(); 116 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC apabilities();
116 } 117 }
117 118
118 return ok; 119 return ok;
119 } 120 }
120 } 121 }
121 122
122 bool SingleThreadProxy::recreateContext() 123 bool SingleThreadProxy::recreateContext()
123 { 124 {
124 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); 125 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext");
125 DCHECK(Proxy::isMainThread()); 126 DCHECK(Proxy::isMainThread());
126 DCHECK(m_contextLost); 127 DCHECK(m_contextLost);
127 128
128 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); 129 scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext();
129 if (!context.get()) 130 if (!context.get())
130 return false; 131 return false;
131 132
132 bool initialized; 133 bool initialized;
133 { 134 {
134 DebugScopedSetMainThreadBlocked mainThreadBlocked; 135 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
135 DebugScopedSetImplThread impl; 136 DebugScopedSetImplThread impl(this);
136 if (!m_layerTreeHostImpl->contentsTexturesPurged()) 137 if (!m_layerTreeHostImpl->contentsTexturesPurged())
137 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI mpl->resourceProvider()); 138 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI mpl->resourceProvider());
138 initialized = m_layerTreeHostImpl->initializeRenderer(context.Pass()); 139 initialized = m_layerTreeHostImpl->initializeRenderer(context.Pass());
139 if (initialized) { 140 if (initialized) {
140 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC apabilities(); 141 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC apabilities();
141 } 142 }
142 } 143 }
143 144
144 if (initialized) 145 if (initialized)
145 m_contextLost = false; 146 m_contextLost = false;
(...skipping 26 matching lines...) Expand all
172 { 173 {
173 // Thread-only feature 174 // Thread-only feature
174 NOTREACHED(); 175 NOTREACHED();
175 } 176 }
176 177
177 void SingleThreadProxy::doCommit(scoped_ptr<ResourceUpdateQueue> queue) 178 void SingleThreadProxy::doCommit(scoped_ptr<ResourceUpdateQueue> queue)
178 { 179 {
179 DCHECK(Proxy::isMainThread()); 180 DCHECK(Proxy::isMainThread());
180 // Commit immediately 181 // Commit immediately
181 { 182 {
182 DebugScopedSetMainThreadBlocked mainThreadBlocked; 183 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
183 DebugScopedSetImplThread impl; 184 DebugScopedSetImplThread impl(this);
184 185
185 base::TimeTicks startTime = base::TimeTicks::HighResNow(); 186 base::TimeTicks startTime = base::TimeTicks::HighResNow();
186 m_layerTreeHostImpl->beginCommit(); 187 m_layerTreeHostImpl->beginCommit();
187 188
188 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin gs(); 189 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin gs();
189 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); 190 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get());
190 191
191 scoped_ptr<ResourceUpdateController> updateController = 192 scoped_ptr<ResourceUpdateController> updateController =
192 ResourceUpdateController::create( 193 ResourceUpdateController::create(
193 NULL, 194 NULL,
194 Proxy::mainThread(), 195 Proxy::mainThread(),
195 queue.Pass(), 196 queue.Pass(),
196 m_layerTreeHostImpl->resourceProvider()); 197 m_layerTreeHostImpl->resourceProvider(),
198 hasImplThread());
197 updateController->finalize(); 199 updateController->finalize();
198 200
199 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); 201 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get());
200 202
201 m_layerTreeHostImpl->commitComplete(); 203 m_layerTreeHostImpl->commitComplete();
202 204
203 #ifndef NDEBUG 205 #ifndef NDEBUG
204 // In the single-threaded case, the scroll deltas should never be 206 // In the single-threaded case, the scroll deltas should never be
205 // touched on the impl layer tree. 207 // touched on the impl layer tree.
206 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS crollDeltas(); 208 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS crollDeltas();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 size_t SingleThreadProxy::maxPartialTextureUpdates() const 249 size_t SingleThreadProxy::maxPartialTextureUpdates() const
248 { 250 {
249 return std::numeric_limits<size_t>::max(); 251 return std::numeric_limits<size_t>::max();
250 } 252 }
251 253
252 void SingleThreadProxy::stop() 254 void SingleThreadProxy::stop()
253 { 255 {
254 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); 256 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
255 DCHECK(Proxy::isMainThread()); 257 DCHECK(Proxy::isMainThread());
256 { 258 {
257 DebugScopedSetMainThreadBlocked mainThreadBlocked; 259 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
258 DebugScopedSetImplThread impl; 260 DebugScopedSetImplThread impl(this);
259 261
260 if (!m_layerTreeHostImpl->contentsTexturesPurged()) 262 if (!m_layerTreeHostImpl->contentsTexturesPurged())
261 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI mpl->resourceProvider()); 263 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostI mpl->resourceProvider());
262 m_layerTreeHostImpl.reset(); 264 m_layerTreeHostImpl.reset();
263 } 265 }
264 m_layerTreeHost = 0; 266 m_layerTreeHost = 0;
265 } 267 }
266 268
267 void SingleThreadProxy::setNeedsRedrawOnImplThread() 269 void SingleThreadProxy::setNeedsRedrawOnImplThread()
268 { 270 {
269 m_layerTreeHost->scheduleComposite(); 271 m_layerTreeHost->scheduleComposite();
270 } 272 }
271 273
272 void SingleThreadProxy::setNeedsCommitOnImplThread() 274 void SingleThreadProxy::setNeedsCommitOnImplThread()
273 { 275 {
274 m_layerTreeHost->scheduleComposite(); 276 m_layerTreeHost->scheduleComposite();
275 } 277 }
276 278
277 void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<A nimationEventsVector> events, base::Time wallClockTime) 279 void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<A nimationEventsVector> events, base::Time wallClockTime)
278 { 280 {
279 DCHECK(Proxy::isImplThread()); 281 DCHECK(Proxy::isImplThread());
280 DebugScopedSetMainThread main; 282 DebugScopedSetMainThread main(this);
281 m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime); 283 m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime);
282 } 284 }
283 285
284 bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitByte s, int priorityCutoff) 286 bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitByte s, int priorityCutoff)
285 { 287 {
286 DCHECK(isImplThread()); 288 DCHECK(isImplThread());
287 if (!m_layerTreeHost->contentsTextureManager()) 289 if (!m_layerTreeHost->contentsTextureManager())
288 return false; 290 return false;
289 291
290 return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(l imitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider()); 292 return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(l imitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider());
(...skipping 20 matching lines...) Expand all
311 { 313 {
312 if (commitAndComposite()) { 314 if (commitAndComposite()) {
313 m_layerTreeHostImpl->swapBuffers(); 315 m_layerTreeHostImpl->swapBuffers();
314 didSwapFrame(); 316 didSwapFrame();
315 } 317 }
316 } 318 }
317 319
318 void SingleThreadProxy::forceSerializeOnSwapBuffers() 320 void SingleThreadProxy::forceSerializeOnSwapBuffers()
319 { 321 {
320 { 322 {
321 DebugScopedSetImplThread impl; 323 DebugScopedSetImplThread impl(this);
322 if (m_rendererInitialized) 324 if (m_rendererInitialized)
323 m_layerTreeHostImpl->renderer()->doNoOp(); 325 m_layerTreeHostImpl->renderer()->doNoOp();
324 } 326 }
325 } 327 }
326 328
327 void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() 329 void SingleThreadProxy::onSwapBuffersCompleteOnImplThread()
328 { 330 {
329 NOTREACHED(); 331 NOTREACHED();
330 } 332 }
331 333
332 bool SingleThreadProxy::commitAndComposite() 334 bool SingleThreadProxy::commitAndComposite()
333 { 335 {
334 DCHECK(Proxy::isMainThread()); 336 DCHECK(Proxy::isMainThread());
335 337
336 if (!m_layerTreeHost->initializeRendererIfNeeded()) 338 if (!m_layerTreeHost->initializeRendererIfNeeded())
337 return false; 339 return false;
338 340
339 // Unlink any texture backings that were deleted 341 // Unlink any texture backings that were deleted
340 PrioritizedTextureManager::BackingList evictedContentsTexturesBackings; 342 PrioritizedTextureManager::BackingList evictedContentsTexturesBackings;
341 { 343 {
342 DebugScopedSetImplThread implThread; 344 DebugScopedSetImplThread impl(this);
343 m_layerTreeHost->contentsTextureManager()->getEvictedBackings(evictedCon tentsTexturesBackings); 345 m_layerTreeHost->contentsTextureManager()->getEvictedBackings(evictedCon tentsTexturesBackings);
344 } 346 }
345 m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(evictedCont entsTexturesBackings); 347 m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(evictedCont entsTexturesBackings);
346 348
347 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu eue); 349 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu eue);
348 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll ocationLimitBytes()); 350 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll ocationLimitBytes());
349 351
350 if (m_layerTreeHostImpl->contentsTexturesPurged()) 352 if (m_layerTreeHostImpl->contentsTexturesPurged())
351 m_layerTreeHostImpl->resetContentsTexturesPurged(); 353 m_layerTreeHostImpl->resetContentsTexturesPurged();
352 354
353 m_layerTreeHost->willCommit(); 355 m_layerTreeHost->willCommit();
354 doCommit(queue.Pass()); 356 doCommit(queue.Pass());
355 bool result = doComposite(); 357 bool result = doComposite();
356 m_layerTreeHost->didBeginFrame(); 358 m_layerTreeHost->didBeginFrame();
357 return result; 359 return result;
358 } 360 }
359 361
360 bool SingleThreadProxy::doComposite() 362 bool SingleThreadProxy::doComposite()
361 { 363 {
362 DCHECK(!m_contextLost); 364 DCHECK(!m_contextLost);
363 { 365 {
364 DebugScopedSetImplThread impl; 366 DebugScopedSetImplThread impl(this);
365 367
366 if (!m_layerTreeHostImpl->visible()) 368 if (!m_layerTreeHostImpl->visible())
367 return false; 369 return false;
368 370
369 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); 371 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now());
370 372
371 // We guard prepareToDraw() with canDraw() because it always returns a v alid frame, so can only 373 // We guard prepareToDraw() with canDraw() because it always returns a v alid frame, so can only
372 // be used when such a frame is possible. Since drawLayers() depends on the result of 374 // be used when such a frame is possible. Since drawLayers() depends on the result of
373 // prepareToDraw(), it is guarded on canDraw() as well. 375 // prepareToDraw(), it is guarded on canDraw() as well.
374 if (!m_layerTreeHostImpl->canDraw()) 376 if (!m_layerTreeHostImpl->canDraw())
(...skipping 16 matching lines...) Expand all
391 393
392 void SingleThreadProxy::didSwapFrame() 394 void SingleThreadProxy::didSwapFrame()
393 { 395 {
394 if (m_nextFrameIsNewlyCommittedFrame) { 396 if (m_nextFrameIsNewlyCommittedFrame) {
395 m_nextFrameIsNewlyCommittedFrame = false; 397 m_nextFrameIsNewlyCommittedFrame = false;
396 m_layerTreeHost->didCommitAndDrawFrame(); 398 m_layerTreeHost->didCommitAndDrawFrame();
397 } 399 }
398 } 400 }
399 401
400 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698