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

Side by Side Diff: cc/layer_tree_host.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 months 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 "CCLayerTreeHost.h" 7 #include "CCLayerTreeHost.h"
8 8
9 #include "CCFontAtlas.h" 9 #include "CCFontAtlas.h"
10 #include "CCGraphicsContext.h" 10 #include "CCGraphicsContext.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 RendererCapabilities::~RendererCapabilities() 76 RendererCapabilities::~RendererCapabilities()
77 { 77 {
78 } 78 }
79 79
80 bool CCLayerTreeHost::anyLayerTreeHostInstanceExists() 80 bool CCLayerTreeHost::anyLayerTreeHostInstanceExists()
81 { 81 {
82 return numLayerTreeInstances > 0; 82 return numLayerTreeInstances > 0;
83 } 83 }
84 84
85 scoped_ptr<CCLayerTreeHost> CCLayerTreeHost::create(CCLayerTreeHostClient* clien t, const CCLayerTreeSettings& settings) 85 scoped_ptr<CCLayerTreeHost> CCLayerTreeHost::create(CCLayerTreeHostClient* clien t, const CCLayerTreeSettings& settings, CompositorSupportState* compositorSuppor tState)
86 { 86 {
87 scoped_ptr<CCLayerTreeHost> layerTreeHost(new CCLayerTreeHost(client, settin gs)); 87 scoped_ptr<CCLayerTreeHost> layerTreeHost(new CCLayerTreeHost(client, settin gs));
88 if (!layerTreeHost->initialize()) 88 if (!layerTreeHost->initialize(compositorSupportState))
89 return scoped_ptr<CCLayerTreeHost>(); 89 return scoped_ptr<CCLayerTreeHost>();
90 return layerTreeHost.Pass(); 90 return layerTreeHost.Pass();
91 } 91 }
92 92
93 CCLayerTreeHost::CCLayerTreeHost(CCLayerTreeHostClient* client, const CCLayerTre eSettings& settings) 93 CCLayerTreeHost::CCLayerTreeHost(CCLayerTreeHostClient* client, const CCLayerTre eSettings& settings)
94 : m_animating(false) 94 : m_animating(false)
95 , m_needsAnimateLayers(false) 95 , m_needsAnimateLayers(false)
96 , m_client(client) 96 , m_client(client)
97 , m_commitNumber(0) 97 , m_commitNumber(0)
98 , m_renderingStats() 98 , m_renderingStats()
99 , m_rendererInitialized(false) 99 , m_rendererInitialized(false)
100 , m_contextLost(false) 100 , m_contextLost(false)
101 , m_numTimesRecreateShouldFail(0) 101 , m_numTimesRecreateShouldFail(0)
102 , m_numFailedRecreateAttempts(0) 102 , m_numFailedRecreateAttempts(0)
103 , m_settings(settings) 103 , m_settings(settings)
104 , m_deviceScaleFactor(1) 104 , m_deviceScaleFactor(1)
105 , m_visible(true) 105 , m_visible(true)
106 , m_pageScaleFactor(1) 106 , m_pageScaleFactor(1)
107 , m_minPageScaleFactor(1) 107 , m_minPageScaleFactor(1)
108 , m_maxPageScaleFactor(1) 108 , m_maxPageScaleFactor(1)
109 , m_triggerIdleUpdates(true) 109 , m_triggerIdleUpdates(true)
110 , m_backgroundColor(SK_ColorWHITE) 110 , m_backgroundColor(SK_ColorWHITE)
111 , m_hasTransparentBackground(false) 111 , m_hasTransparentBackground(false)
112 , m_partialTextureUpdateRequests(0) 112 , m_partialTextureUpdateRequests(0)
113 { 113 {
114 DCHECK(CCProxy::isMainThread());
115 numLayerTreeInstances++; 114 numLayerTreeInstances++;
116 } 115 }
117 116
118 bool CCLayerTreeHost::initialize() 117 bool CCLayerTreeHost::initialize(CompositorSupportState* compositorSupportState)
119 { 118 {
120 TRACE_EVENT0("cc", "CCLayerTreeHost::initialize"); 119 TRACE_EVENT0("cc", "CCLayerTreeHost::initialize");
121 120
122 if (CCProxy::hasImplThread()) 121 if (compositorThread)
jamesr 2012/10/22 22:00:36 i can't tell where this bool is coming from
123 m_proxy = CCThreadProxy::create(this); 122 m_proxy = CCThreadProxy::create(this, compositorSupportState);
124 else 123 else
125 m_proxy = CCSingleThreadProxy::create(this); 124 m_proxy = CCSingleThreadProxy::create(this); // TODO
126 m_proxy->start(); 125 m_proxy->start();
127 126
128 return m_proxy->initializeContext(); 127 return m_proxy->initializeContext();
129 } 128 }
130 129
131 CCLayerTreeHost::~CCLayerTreeHost() 130 CCLayerTreeHost::~CCLayerTreeHost()
132 { 131 {
133 if (m_rootLayer) 132 if (m_rootLayer)
134 m_rootLayer->setLayerTreeHost(0); 133 m_rootLayer->setLayerTreeHost(0);
135 DCHECK(CCProxy::isMainThread()); 134 DCHECK(m_proxy->isMainThread());
136 TRACE_EVENT0("cc", "CCLayerTreeHost::~CCLayerTreeHost"); 135 TRACE_EVENT0("cc", "CCLayerTreeHost::~CCLayerTreeHost");
137 DCHECK(m_proxy.get()); 136 DCHECK(m_proxy.get());
138 m_proxy->stop(); 137 m_proxy->stop();
139 m_proxy.reset(); 138 m_proxy.reset();
140 numLayerTreeInstances--; 139 numLayerTreeInstances--;
141 RateLimiterMap::iterator it = m_rateLimiters.begin(); 140 RateLimiterMap::iterator it = m_rateLimiters.begin();
142 if (it != m_rateLimiters.end()) 141 if (it != m_rateLimiters.end())
143 it->second->stop(); 142 it->second->stop();
144 } 143 }
145 144
(...skipping 10 matching lines...) Expand all
156 m_client->didRecreateOutputSurface(false); 155 m_client->didRecreateOutputSurface(false);
157 return; 156 return;
158 } 157 }
159 158
160 // Update m_settings based on capabilities that we got back from the rendere r. 159 // Update m_settings based on capabilities that we got back from the rendere r.
161 m_settings.acceleratePainting = m_proxy->rendererCapabilities().usingAcceler atedPainting; 160 m_settings.acceleratePainting = m_proxy->rendererCapabilities().usingAcceler atedPainting;
162 161
163 // Update m_settings based on partial update capability. 162 // Update m_settings based on partial update capability.
164 m_settings.maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdate s, m_proxy->maxPartialTextureUpdates()); 163 m_settings.maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdate s, m_proxy->maxPartialTextureUpdates());
165 164
166 m_contentsTextureManager = CCPrioritizedTextureManager::create(0, m_proxy->r endererCapabilities().maxTextureSize, CCRenderer::ContentPool); 165 m_contentsTextureManager = CCPrioritizedTextureManager::create(0, m_proxy->r endererCapabilities().maxTextureSize, CCRenderer::ContentPool, m_proxy.get());
167 m_surfaceMemoryPlaceholder = m_contentsTextureManager->createTexture(IntSize (), GL_RGBA); 166 m_surfaceMemoryPlaceholder = m_contentsTextureManager->createTexture(IntSize (), GL_RGBA);
168 167
169 m_rendererInitialized = true; 168 m_rendererInitialized = true;
170 169
171 m_settings.defaultTileSize = IntSize(min(m_settings.defaultTileSize.width(), m_proxy->rendererCapabilities().maxTextureSize), 170 m_settings.defaultTileSize = IntSize(min(m_settings.defaultTileSize.width(), m_proxy->rendererCapabilities().maxTextureSize),
172 min(m_settings.defaultTileSize.height() , m_proxy->rendererCapabilities().maxTextureSize)); 171 min(m_settings.defaultTileSize.height() , m_proxy->rendererCapabilities().maxTextureSize));
173 m_settings.maxUntiledLayerSize = IntSize(min(m_settings.maxUntiledLayerSize. width(), m_proxy->rendererCapabilities().maxTextureSize), 172 m_settings.maxUntiledLayerSize = IntSize(min(m_settings.maxUntiledLayerSize. width(), m_proxy->rendererCapabilities().maxTextureSize),
174 min(m_settings.maxUntiledLayerSize. height(), m_proxy->rendererCapabilities().maxTextureSize)); 173 min(m_settings.maxUntiledLayerSize. height(), m_proxy->rendererCapabilities().maxTextureSize));
175 } 174 }
176 175
(...skipping 14 matching lines...) Expand all
191 return RecreateSucceeded; 190 return RecreateSucceeded;
192 } 191 }
193 192
194 // Tolerate a certain number of recreation failures to work around races 193 // Tolerate a certain number of recreation failures to work around races
195 // in the context-lost machinery. 194 // in the context-lost machinery.
196 m_numFailedRecreateAttempts++; 195 m_numFailedRecreateAttempts++;
197 if (m_numFailedRecreateAttempts < 5) { 196 if (m_numFailedRecreateAttempts < 5) {
198 // FIXME: The single thread does not self-schedule context 197 // FIXME: The single thread does not self-schedule context
199 // recreation. So force another recreation attempt to happen by requesti ng 198 // recreation. So force another recreation attempt to happen by requesti ng
200 // another commit. 199 // another commit.
201 if (!CCProxy::hasImplThread()) 200 if (!m_proxy->hasImplThread())
202 setNeedsCommit(); 201 setNeedsCommit();
203 return RecreateFailedButTryAgain; 202 return RecreateFailedButTryAgain;
204 } 203 }
205 204
206 // We have tried too many times to recreate the context. Tell the host to fa ll 205 // We have tried too many times to recreate the context. Tell the host to fa ll
207 // back to software rendering. 206 // back to software rendering.
208 m_client->didRecreateOutputSurface(false); 207 m_client->didRecreateOutputSurface(false);
209 return RecreateFailedAndGaveUp; 208 return RecreateFailedAndGaveUp;
210 } 209 }
211 210
212 void CCLayerTreeHost::deleteContentsTexturesOnImplThread(CCResourceProvider* res ourceProvider) 211 void CCLayerTreeHost::deleteContentsTexturesOnImplThread(CCResourceProvider* res ourceProvider)
213 { 212 {
214 DCHECK(CCProxy::isImplThread()); 213 DCHECK(m_proxy->isImplThread());
215 if (m_rendererInitialized) 214 if (m_rendererInitialized)
216 m_contentsTextureManager->clearAllMemory(resourceProvider); 215 m_contentsTextureManager->clearAllMemory(resourceProvider);
217 } 216 }
218 217
219 void CCLayerTreeHost::acquireLayerTextures() 218 void CCLayerTreeHost::acquireLayerTextures()
220 { 219 {
221 DCHECK(CCProxy::isMainThread()); 220 DCHECK(m_proxy->isMainThread());
222 m_proxy->acquireLayerTextures(); 221 m_proxy->acquireLayerTextures();
223 } 222 }
224 223
225 void CCLayerTreeHost::updateAnimations(double monotonicFrameBeginTime) 224 void CCLayerTreeHost::updateAnimations(double monotonicFrameBeginTime)
226 { 225 {
227 m_animating = true; 226 m_animating = true;
228 m_client->animate(monotonicFrameBeginTime); 227 m_client->animate(monotonicFrameBeginTime);
229 animateLayers(monotonicFrameBeginTime); 228 animateLayers(monotonicFrameBeginTime);
230 m_animating = false; 229 m_animating = false;
231 230
232 m_renderingStats.numAnimationFrames++; 231 m_renderingStats.numAnimationFrames++;
233 } 232 }
234 233
235 void CCLayerTreeHost::layout() 234 void CCLayerTreeHost::layout()
236 { 235 {
237 m_client->layout(); 236 m_client->layout();
238 } 237 }
239 238
240 void CCLayerTreeHost::beginCommitOnImplThread(CCLayerTreeHostImpl* hostImpl) 239 void CCLayerTreeHost::beginCommitOnImplThread(CCLayerTreeHostImpl* hostImpl)
241 { 240 {
242 DCHECK(CCProxy::isImplThread()); 241 DCHECK(m_proxy->isImplThread());
243 TRACE_EVENT0("cc", "CCLayerTreeHost::commitTo"); 242 TRACE_EVENT0("cc", "CCLayerTreeHost::commitTo");
244 } 243 }
245 244
246 // This function commits the CCLayerTreeHost to an impl tree. When modifying 245 // This function commits the CCLayerTreeHost to an impl tree. When modifying
247 // this function, keep in mind that the function *runs* on the impl thread! Any 246 // this function, keep in mind that the function *runs* on the impl thread! Any
248 // code that is logically a main thread operation, e.g. deletion of a LayerChrom ium, 247 // code that is logically a main thread operation, e.g. deletion of a LayerChrom ium,
249 // should be delayed until the CCLayerTreeHost::commitComplete, which will run 248 // should be delayed until the CCLayerTreeHost::commitComplete, which will run
250 // after the commit, but on the main thread. 249 // after the commit, but on the main thread.
251 void CCLayerTreeHost::finishCommitOnImplThread(CCLayerTreeHostImpl* hostImpl) 250 void CCLayerTreeHost::finishCommitOnImplThread(CCLayerTreeHostImpl* hostImpl)
252 { 251 {
253 DCHECK(CCProxy::isImplThread()); 252 DCHECK(m_proxy->isImplThread());
254 253
255 m_contentsTextureManager->updateBackingsInDrawingImplTree(); 254 m_contentsTextureManager->updateBackingsInDrawingImplTree();
256 m_contentsTextureManager->reduceMemory(hostImpl->resourceProvider()); 255 m_contentsTextureManager->reduceMemory(hostImpl->resourceProvider());
257 256
258 hostImpl->setRootLayer(TreeSynchronizer::synchronizeTrees(rootLayer(), hostI mpl->detachLayerTree(), hostImpl)); 257 hostImpl->setRootLayer(TreeSynchronizer::synchronizeTrees(rootLayer(), hostI mpl->detachLayerTree(), hostImpl));
259 258
260 if (m_rootLayer && m_hudLayer) 259 if (m_rootLayer && m_hudLayer)
261 hostImpl->setHudLayer(static_cast<CCHeadsUpDisplayLayerImpl*>(CCLayerTre eHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->id()))); 260 hostImpl->setHudLayer(static_cast<CCHeadsUpDisplayLayerImpl*>(CCLayerTre eHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->id())));
262 else 261 else
263 hostImpl->setHudLayer(0); 262 hostImpl->setHudLayer(0);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 314 }
316 315
317 scoped_ptr<CCLayerTreeHostImpl> CCLayerTreeHost::createLayerTreeHostImpl(CCLayer TreeHostImplClient* client) 316 scoped_ptr<CCLayerTreeHostImpl> CCLayerTreeHost::createLayerTreeHostImpl(CCLayer TreeHostImplClient* client)
318 { 317 {
319 return CCLayerTreeHostImpl::create(m_settings, client); 318 return CCLayerTreeHostImpl::create(m_settings, client);
320 } 319 }
321 320
322 void CCLayerTreeHost::didLoseContext() 321 void CCLayerTreeHost::didLoseContext()
323 { 322 {
324 TRACE_EVENT0("cc", "CCLayerTreeHost::didLoseContext"); 323 TRACE_EVENT0("cc", "CCLayerTreeHost::didLoseContext");
325 DCHECK(CCProxy::isMainThread()); 324 DCHECK(m_proxy->isMainThread());
326 m_contextLost = true; 325 m_contextLost = true;
327 m_numFailedRecreateAttempts = 0; 326 m_numFailedRecreateAttempts = 0;
328 setNeedsCommit(); 327 setNeedsCommit();
329 } 328 }
330 329
331 bool CCLayerTreeHost::compositeAndReadback(void *pixels, const IntRect& rect) 330 bool CCLayerTreeHost::compositeAndReadback(void *pixels, const IntRect& rect)
332 { 331 {
333 m_triggerIdleUpdates = false; 332 m_triggerIdleUpdates = false;
334 bool ret = m_proxy->compositeAndReadback(pixels, rect); 333 bool ret = m_proxy->compositeAndReadback(pixels, rect);
335 m_triggerIdleUpdates = true; 334 m_triggerIdleUpdates = true;
(...skipping 13 matching lines...) Expand all
349 m_proxy->renderingStats(stats); 348 m_proxy->renderingStats(stats);
350 } 349 }
351 350
352 const RendererCapabilities& CCLayerTreeHost::rendererCapabilities() const 351 const RendererCapabilities& CCLayerTreeHost::rendererCapabilities() const
353 { 352 {
354 return m_proxy->rendererCapabilities(); 353 return m_proxy->rendererCapabilities();
355 } 354 }
356 355
357 void CCLayerTreeHost::setNeedsAnimate() 356 void CCLayerTreeHost::setNeedsAnimate()
358 { 357 {
359 DCHECK(CCProxy::hasImplThread()); 358 DCHECK(m_proxy->hasImplThread());
360 m_proxy->setNeedsAnimate(); 359 m_proxy->setNeedsAnimate();
361 } 360 }
362 361
363 void CCLayerTreeHost::setNeedsCommit() 362 void CCLayerTreeHost::setNeedsCommit()
364 { 363 {
365 m_proxy->setNeedsCommit(); 364 m_proxy->setNeedsCommit();
366 } 365 }
367 366
368 void CCLayerTreeHost::setNeedsRedraw() 367 void CCLayerTreeHost::setNeedsRedraw()
369 { 368 {
370 m_proxy->setNeedsRedraw(); 369 m_proxy->setNeedsRedraw();
371 if (!CCThreadProxy::implThread()) 370 if (!m_proxy->implThread())
372 m_client->scheduleComposite(); 371 m_client->scheduleComposite();
373 } 372 }
374 373
375 bool CCLayerTreeHost::commitRequested() const 374 bool CCLayerTreeHost::commitRequested() const
376 { 375 {
377 return m_proxy->commitRequested(); 376 return m_proxy->commitRequested();
378 } 377 }
379 378
380 void CCLayerTreeHost::setAnimationEvents(scoped_ptr<CCAnimationEventsVector> eve nts, double wallClockTime) 379 void CCLayerTreeHost::setAnimationEvents(scoped_ptr<CCAnimationEventsVector> eve nts, double wallClockTime)
381 { 380 {
382 DCHECK(CCThreadProxy::isMainThread()); 381 DCHECK(m_proxy->isMainThread());
383 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime) ; 382 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime) ;
384 } 383 }
385 384
386 void CCLayerTreeHost::didAddAnimation() 385 void CCLayerTreeHost::didAddAnimation()
387 { 386 {
388 m_needsAnimateLayers = true; 387 m_needsAnimateLayers = true;
389 m_proxy->didAddAnimation(); 388 m_proxy->didAddAnimation();
390 } 389 }
391 390
392 void CCLayerTreeHost::setRootLayer(scoped_refptr<LayerChromium> rootLayer) 391 void CCLayerTreeHost::setRootLayer(scoped_refptr<LayerChromium> rootLayer)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 m_proxy->loseContext(); 447 m_proxy->loseContext();
449 } 448 }
450 449
451 CCPrioritizedTextureManager* CCLayerTreeHost::contentsTextureManager() const 450 CCPrioritizedTextureManager* CCLayerTreeHost::contentsTextureManager() const
452 { 451 {
453 return m_contentsTextureManager.get(); 452 return m_contentsTextureManager.get();
454 } 453 }
455 454
456 void CCLayerTreeHost::composite() 455 void CCLayerTreeHost::composite()
457 { 456 {
458 DCHECK(!CCThreadProxy::implThread()); 457 DCHECK(!m_proxy->implThread());
459 static_cast<CCSingleThreadProxy*>(m_proxy.get())->compositeImmediately(); 458 static_cast<CCSingleThreadProxy*>(m_proxy.get())->compositeImmediately();
460 } 459 }
461 460
462 void CCLayerTreeHost::scheduleComposite() 461 void CCLayerTreeHost::scheduleComposite()
463 { 462 {
464 m_client->scheduleComposite(); 463 m_client->scheduleComposite();
465 } 464 }
466 465
467 bool CCLayerTreeHost::initializeRendererIfNeeded() 466 bool CCLayerTreeHost::initializeRendererIfNeeded()
468 { 467 {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 void CCLayerTreeHost::startRateLimiter(WebKit::WebGraphicsContext3D* context) 717 void CCLayerTreeHost::startRateLimiter(WebKit::WebGraphicsContext3D* context)
719 { 718 {
720 if (m_animating) 719 if (m_animating)
721 return; 720 return;
722 721
723 DCHECK(context); 722 DCHECK(context);
724 RateLimiterMap::iterator it = m_rateLimiters.find(context); 723 RateLimiterMap::iterator it = m_rateLimiters.find(context);
725 if (it != m_rateLimiters.end()) 724 if (it != m_rateLimiters.end())
726 it->second->start(); 725 it->second->start();
727 else { 726 else {
728 scoped_refptr<RateLimiter> rateLimiter = RateLimiter::create(context, th is); 727 scoped_refptr<RateLimiter> rateLimiter = RateLimiter::create(context, th is, m_proxy.get());
729 m_rateLimiters[context] = rateLimiter; 728 m_rateLimiters[context] = rateLimiter;
730 rateLimiter->start(); 729 rateLimiter->start();
731 } 730 }
732 } 731 }
733 732
734 void CCLayerTreeHost::stopRateLimiter(WebKit::WebGraphicsContext3D* context) 733 void CCLayerTreeHost::stopRateLimiter(WebKit::WebGraphicsContext3D* context)
735 { 734 {
736 RateLimiterMap::iterator it = m_rateLimiters.find(context); 735 RateLimiterMap::iterator it = m_rateLimiters.find(context);
737 if (it != m_rateLimiters.end()) { 736 if (it != m_rateLimiters.end()) {
738 it->second->stop(); 737 it->second->stop();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 else 816 else
818 layer->notifyAnimationFinished(wallClockTime); 817 layer->notifyAnimationFinished(wallClockTime);
819 } 818 }
820 } 819 }
821 820
822 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) 821 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex)
823 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); 822 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime);
824 } 823 }
825 824
826 } // namespace cc 825 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698