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

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

Powered by Google App Engine
This is Rietveld 408576698