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

Side by Side Diff: cc/single_thread_proxy.cc

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