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

Side by Side Diff: cc/layer_tree_host.cc

Issue 11450019: Finish the rename from cc::GraphicsContext to cc::OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
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 "cc/layer_tree_host.h" 5 #include "cc/layer_tree_host.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "cc/font_atlas.h" 11 #include "cc/font_atlas.h"
12 #include "cc/graphics_context.h"
13 #include "cc/heads_up_display_layer.h" 12 #include "cc/heads_up_display_layer.h"
14 #include "cc/heads_up_display_layer_impl.h" 13 #include "cc/heads_up_display_layer_impl.h"
15 #include "cc/layer.h" 14 #include "cc/layer.h"
16 #include "cc/layer_animation_controller.h" 15 #include "cc/layer_animation_controller.h"
17 #include "cc/layer_iterator.h" 16 #include "cc/layer_iterator.h"
18 #include "cc/layer_tree_host_client.h" 17 #include "cc/layer_tree_host_client.h"
19 #include "cc/layer_tree_host_common.h" 18 #include "cc/layer_tree_host_common.h"
20 #include "cc/layer_tree_host_impl.h" 19 #include "cc/layer_tree_host_impl.h"
21 #include "cc/math_util.h" 20 #include "cc/math_util.h"
22 #include "cc/occlusion_tracker.h" 21 #include "cc/occlusion_tracker.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 139 }
141 } 140 }
142 } 141 }
143 142
144 LayerTreeSettings::~LayerTreeSettings() 143 LayerTreeSettings::~LayerTreeSettings()
145 { 144 {
146 } 145 }
147 146
148 RendererCapabilities::RendererCapabilities() 147 RendererCapabilities::RendererCapabilities()
149 : bestTextureFormat(0) 148 : bestTextureFormat(0)
150 , contextHasCachedFrontBuffer(false)
151 , usingPartialSwap(false)
152 , usingAcceleratedPainting(false) 149 , usingAcceleratedPainting(false)
153 , usingSetVisibility(false) 150 , usingSetVisibility(false)
154 , usingSwapCompleteCallback(false) 151 , usingSwapCompleteCallback(false)
155 , usingGpuMemoryManager(false) 152 , usingGpuMemoryManager(false)
156 , usingDiscardFramebuffer(false) 153 , usingDiscardFramebuffer(false)
157 , usingEglImage(false) 154 , usingEglImage(false)
158 , maxTextureSize(0) 155 , maxTextureSize(0)
159 { 156 {
160 } 157 }
161 158
(...skipping 15 matching lines...) Expand all
177 } 174 }
178 175
179 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) 176 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings)
180 : m_animating(false) 177 : m_animating(false)
181 , m_needsAnimateLayers(false) 178 , m_needsAnimateLayers(false)
182 , m_needsFullTreeSync(true) 179 , m_needsFullTreeSync(true)
183 , m_client(client) 180 , m_client(client)
184 , m_commitNumber(0) 181 , m_commitNumber(0)
185 , m_renderingStats() 182 , m_renderingStats()
186 , m_rendererInitialized(false) 183 , m_rendererInitialized(false)
187 , m_contextLost(false) 184 , m_outputSurfaceLost(false)
188 , m_numTimesRecreateShouldFail(0) 185 , m_numTimesRecreateShouldFail(0)
189 , m_numFailedRecreateAttempts(0) 186 , m_numFailedRecreateAttempts(0)
190 , m_settings(settings) 187 , m_settings(settings)
191 , m_debugState(settings.initialDebugState) 188 , m_debugState(settings.initialDebugState)
192 , m_deviceScaleFactor(1) 189 , m_deviceScaleFactor(1)
193 , m_visible(true) 190 , m_visible(true)
194 , m_pageScaleFactor(1) 191 , m_pageScaleFactor(1)
195 , m_minPageScaleFactor(1) 192 , m_minPageScaleFactor(1)
196 , m_maxPageScaleFactor(1) 193 , m_maxPageScaleFactor(1)
197 , m_triggerIdleUpdates(true) 194 , m_triggerIdleUpdates(true)
198 , m_backgroundColor(SK_ColorWHITE) 195 , m_backgroundColor(SK_ColorWHITE)
199 , m_hasTransparentBackground(false) 196 , m_hasTransparentBackground(false)
200 , m_partialTextureUpdateRequests(0) 197 , m_partialTextureUpdateRequests(0)
201 { 198 {
202 numLayerTreeInstances++; 199 numLayerTreeInstances++;
203 } 200 }
204 201
205 bool LayerTreeHost::initialize(scoped_ptr<Thread> implThread) 202 bool LayerTreeHost::initialize(scoped_ptr<Thread> implThread)
206 { 203 {
207 TRACE_EVENT0("cc", "LayerTreeHost::initialize"); 204 TRACE_EVENT0("cc", "LayerTreeHost::initialize");
208 205
209 if (implThread) 206 if (implThread)
210 m_proxy = ThreadProxy::create(this, implThread.Pass()); 207 m_proxy = ThreadProxy::create(this, implThread.Pass());
211 else 208 else
212 m_proxy = SingleThreadProxy::create(this); 209 m_proxy = SingleThreadProxy::create(this);
213 m_proxy->start(); 210 m_proxy->start();
214 211
215 return m_proxy->initializeContext(); 212 return m_proxy->initializeOutputSurface();
216 } 213 }
217 214
218 LayerTreeHost::~LayerTreeHost() 215 LayerTreeHost::~LayerTreeHost()
219 { 216 {
220 if (m_rootLayer) 217 if (m_rootLayer)
221 m_rootLayer->setLayerTreeHost(0); 218 m_rootLayer->setLayerTreeHost(0);
222 DCHECK(m_proxy); 219 DCHECK(m_proxy);
223 DCHECK(m_proxy->isMainThread()); 220 DCHECK(m_proxy->isMainThread());
224 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); 221 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
225 m_proxy->stop(); 222 m_proxy->stop();
226 numLayerTreeInstances--; 223 numLayerTreeInstances--;
227 RateLimiterMap::iterator it = m_rateLimiters.begin(); 224 RateLimiterMap::iterator it = m_rateLimiters.begin();
228 if (it != m_rateLimiters.end()) 225 if (it != m_rateLimiters.end())
229 it->second->stop(); 226 it->second->stop();
230 } 227 }
231 228
232 void LayerTreeHost::setSurfaceReady() 229 void LayerTreeHost::setSurfaceReady()
233 { 230 {
234 m_proxy->setSurfaceReady(); 231 m_proxy->setSurfaceReady();
235 } 232 }
236 233
237 void LayerTreeHost::initializeRenderer() 234 void LayerTreeHost::initializeRenderer()
238 { 235 {
239 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); 236 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer");
240 if (!m_proxy->initializeRenderer()) { 237 if (!m_proxy->initializeRenderer()) {
241 // Uh oh, better tell the client that we can't do anything with this con text. 238 // Uh oh, better tell the client that we can't do anything with this out put surface.
242 m_client->didRecreateOutputSurface(false); 239 m_client->didRecreateOutputSurface(false);
243 return; 240 return;
244 } 241 }
245 242
246 // Update m_settings based on capabilities that we got back from the rendere r. 243 // Update m_settings based on capabilities that we got back from the rendere r.
247 m_settings.acceleratePainting = m_proxy->rendererCapabilities().usingAcceler atedPainting; 244 m_settings.acceleratePainting = m_proxy->rendererCapabilities().usingAcceler atedPainting;
248 245
249 // Update m_settings based on partial update capability. 246 // Update m_settings based on partial update capability.
250 m_settings.maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdate s, m_proxy->maxPartialTextureUpdates()); 247 m_settings.maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdate s, m_proxy->maxPartialTextureUpdates());
251 248
252 m_contentsTextureManager = PrioritizedResourceManager::create(Renderer::Cont entPool, m_proxy.get()); 249 m_contentsTextureManager = PrioritizedResourceManager::create(Renderer::Cont entPool, m_proxy.get());
253 m_surfaceMemoryPlaceholder = m_contentsTextureManager->createTexture(gfx::Si ze(), GL_RGBA); 250 m_surfaceMemoryPlaceholder = m_contentsTextureManager->createTexture(gfx::Si ze(), GL_RGBA);
254 251
255 m_rendererInitialized = true; 252 m_rendererInitialized = true;
256 253
257 m_settings.defaultTileSize = gfx::Size(min(m_settings.defaultTileSize.width( ), m_proxy->rendererCapabilities().maxTextureSize), 254 m_settings.defaultTileSize = gfx::Size(min(m_settings.defaultTileSize.width( ), m_proxy->rendererCapabilities().maxTextureSize),
258 min(m_settings.defaultTileSize.height (), m_proxy->rendererCapabilities().maxTextureSize)); 255 min(m_settings.defaultTileSize.height (), m_proxy->rendererCapabilities().maxTextureSize));
259 m_settings.maxUntiledLayerSize = gfx::Size(min(m_settings.maxUntiledLayerSiz e.width(), m_proxy->rendererCapabilities().maxTextureSize), 256 m_settings.maxUntiledLayerSize = gfx::Size(min(m_settings.maxUntiledLayerSiz e.width(), m_proxy->rendererCapabilities().maxTextureSize),
260 min(m_settings.maxUntiledLayerSiz e.height(), m_proxy->rendererCapabilities().maxTextureSize)); 257 min(m_settings.maxUntiledLayerSiz e.height(), m_proxy->rendererCapabilities().maxTextureSize));
261 } 258 }
262 259
263 LayerTreeHost::RecreateResult LayerTreeHost::recreateContext() 260 LayerTreeHost::RecreateResult LayerTreeHost::recreateOutputSurface()
264 { 261 {
265 TRACE_EVENT0("cc", "LayerTreeHost::recreateContext"); 262 TRACE_EVENT0("cc", "LayerTreeHost::recreateOutputSurface");
266 DCHECK(m_contextLost); 263 DCHECK(m_outputSurfaceLost);
267 264
268 bool recreated = false; 265 bool recreated = false;
269 if (!m_numTimesRecreateShouldFail) 266 if (!m_numTimesRecreateShouldFail)
270 recreated = m_proxy->recreateContext(); 267 recreated = m_proxy->recreateOutputSurface();
271 else 268 else
272 m_numTimesRecreateShouldFail--; 269 m_numTimesRecreateShouldFail--;
273 270
274 if (recreated) { 271 if (recreated) {
275 m_client->didRecreateOutputSurface(true); 272 m_client->didRecreateOutputSurface(true);
276 m_contextLost = false; 273 m_outputSurfaceLost = false;
277 return RecreateSucceeded; 274 return RecreateSucceeded;
278 } 275 }
279 276
280 // Tolerate a certain number of recreation failures to work around races 277 // Tolerate a certain number of recreation failures to work around races
281 // in the context-lost machinery. 278 // in the output-surface-lost machinery.
282 m_numFailedRecreateAttempts++; 279 m_numFailedRecreateAttempts++;
283 if (m_numFailedRecreateAttempts < 5) { 280 if (m_numFailedRecreateAttempts < 5) {
284 // FIXME: The single thread does not self-schedule context 281 // FIXME: The single thread does not self-schedule output surface
285 // recreation. So force another recreation attempt to happen by requesti ng 282 // recreation. So force another recreation attempt to happen by requesti ng
286 // another commit. 283 // another commit.
287 if (!m_proxy->hasImplThread()) 284 if (!m_proxy->hasImplThread())
288 setNeedsCommit(); 285 setNeedsCommit();
289 return RecreateFailedButTryAgain; 286 return RecreateFailedButTryAgain;
290 } 287 }
291 288
292 // We have tried too many times to recreate the context. Tell the host to fa ll 289 // We have tried too many times to recreate the output surface. Tell the
293 // back to software rendering. 290 // host to fall back to software rendering.
294 m_client->didRecreateOutputSurface(false); 291 m_client->didRecreateOutputSurface(false);
295 return RecreateFailedAndGaveUp; 292 return RecreateFailedAndGaveUp;
296 } 293 }
297 294
298 void LayerTreeHost::deleteContentsTexturesOnImplThread(ResourceProvider* resourc eProvider) 295 void LayerTreeHost::deleteContentsTexturesOnImplThread(ResourceProvider* resourc eProvider)
299 { 296 {
300 DCHECK(m_proxy->isImplThread()); 297 DCHECK(m_proxy->isImplThread());
301 if (m_rendererInitialized) 298 if (m_rendererInitialized)
302 m_contentsTextureManager->clearAllMemory(resourceProvider); 299 m_contentsTextureManager->clearAllMemory(resourceProvider);
303 } 300 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 m_hudLayer->removeFromParent(); 406 m_hudLayer->removeFromParent();
410 m_hudLayer = 0; 407 m_hudLayer = 0;
411 } 408 }
412 } 409 }
413 410
414 void LayerTreeHost::commitComplete() 411 void LayerTreeHost::commitComplete()
415 { 412 {
416 m_client->didCommit(); 413 m_client->didCommit();
417 } 414 }
418 415
419 scoped_ptr<GraphicsContext> LayerTreeHost::createContext() 416 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface()
420 { 417 {
421 return m_client->createOutputSurface(); 418 return m_client->createOutputSurface();
422 } 419 }
423 420
424 scoped_ptr<InputHandler> LayerTreeHost::createInputHandler() 421 scoped_ptr<InputHandler> LayerTreeHost::createInputHandler()
425 { 422 {
426 return m_client->createInputHandler(); 423 return m_client->createInputHandler();
427 } 424 }
428 425
429 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::createLayerTreeHostImpl(LayerTreeHo stImplClient* client) 426 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::createLayerTreeHostImpl(LayerTreeHo stImplClient* client)
430 { 427 {
431 return LayerTreeHostImpl::create(m_settings, client, m_proxy.get()); 428 return LayerTreeHostImpl::create(m_settings, client, m_proxy.get());
432 } 429 }
433 430
434 void LayerTreeHost::didLoseContext() 431 void LayerTreeHost::didLoseOutputSurface()
435 { 432 {
436 TRACE_EVENT0("cc", "LayerTreeHost::didLoseContext"); 433 TRACE_EVENT0("cc", "LayerTreeHost::didLoseOutputSurface");
437 DCHECK(m_proxy->isMainThread()); 434 DCHECK(m_proxy->isMainThread());
438 m_contextLost = true; 435 m_outputSurfaceLost = true;
439 m_numFailedRecreateAttempts = 0; 436 m_numFailedRecreateAttempts = 0;
440 setNeedsCommit(); 437 setNeedsCommit();
441 } 438 }
442 439
443 bool LayerTreeHost::compositeAndReadback(void *pixels, const gfx::Rect& rect) 440 bool LayerTreeHost::compositeAndReadback(void *pixels, const gfx::Rect& rect)
444 { 441 {
445 m_triggerIdleUpdates = false; 442 m_triggerIdleUpdates = false;
446 bool ret = m_proxy->compositeAndReadback(pixels, rect); 443 bool ret = m_proxy->compositeAndReadback(pixels, rect);
447 m_triggerIdleUpdates = true; 444 m_triggerIdleUpdates = true;
448 return ret; 445 return ret;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 return; 573 return;
577 m_visible = visible; 574 m_visible = visible;
578 m_proxy->setVisible(visible); 575 m_proxy->setVisible(visible);
579 } 576 }
580 577
581 void LayerTreeHost::startPageScaleAnimation(gfx::Vector2d targetOffset, bool use Anchor, float scale, base::TimeDelta duration) 578 void LayerTreeHost::startPageScaleAnimation(gfx::Vector2d targetOffset, bool use Anchor, float scale, base::TimeDelta duration)
582 { 579 {
583 m_proxy->startPageScaleAnimation(targetOffset, useAnchor, scale, duration); 580 m_proxy->startPageScaleAnimation(targetOffset, useAnchor, scale, duration);
584 } 581 }
585 582
586 void LayerTreeHost::loseContext(int numTimes) 583 void LayerTreeHost::loseOutputSurface(int numTimes)
587 { 584 {
588 TRACE_EVENT1("cc", "LayerTreeHost::loseCompositorContext", "numTimes", numTi mes); 585 TRACE_EVENT1("cc", "LayerTreeHost::loseCompositorOutputSurface", "numTimes", numTimes);
589 m_numTimesRecreateShouldFail = numTimes - 1; 586 m_numTimesRecreateShouldFail = numTimes - 1;
590 m_proxy->loseContext(); 587 m_proxy->loseOutputSurface();
591 } 588 }
592 589
593 PrioritizedResourceManager* LayerTreeHost::contentsTextureManager() const 590 PrioritizedResourceManager* LayerTreeHost::contentsTextureManager() const
594 { 591 {
595 return m_contentsTextureManager.get(); 592 return m_contentsTextureManager.get();
596 } 593 }
597 594
598 void LayerTreeHost::composite() 595 void LayerTreeHost::composite()
599 { 596 {
600 if (!m_proxy->hasImplThread()) 597 if (!m_proxy->hasImplThread())
601 static_cast<SingleThreadProxy*>(m_proxy.get())->compositeImmediately(); 598 static_cast<SingleThreadProxy*>(m_proxy.get())->compositeImmediately();
602 else 599 else
603 setNeedsCommit(); 600 setNeedsCommit();
604 } 601 }
605 602
606 void LayerTreeHost::scheduleComposite() 603 void LayerTreeHost::scheduleComposite()
607 { 604 {
608 m_client->scheduleComposite(); 605 m_client->scheduleComposite();
609 } 606 }
610 607
611 bool LayerTreeHost::initializeRendererIfNeeded() 608 bool LayerTreeHost::initializeRendererIfNeeded()
612 { 609 {
613 if (!m_rendererInitialized) { 610 if (!m_rendererInitialized) {
614 initializeRenderer(); 611 initializeRenderer();
615 // If we couldn't initialize, then bail since we're returning to softwar e mode. 612 // If we couldn't initialize, then bail since we're returning to softwar e mode.
616 if (!m_rendererInitialized) 613 if (!m_rendererInitialized)
617 return false; 614 return false;
618 } 615 }
619 if (m_contextLost) { 616 if (m_outputSurfaceLost) {
620 if (recreateContext() != RecreateSucceeded) 617 if (recreateOutputSurface() != RecreateSucceeded)
621 return false; 618 return false;
622 } 619 }
623 return true; 620 return true;
624 } 621 }
625 622
626 void LayerTreeHost::updateLayers(ResourceUpdateQueue& queue, size_t memoryAlloca tionLimitBytes) 623 void LayerTreeHost::updateLayers(ResourceUpdateQueue& queue, size_t memoryAlloca tionLimitBytes)
627 { 624 {
628 DCHECK(m_rendererInitialized); 625 DCHECK(m_rendererInitialized);
629 626
630 if (!rootLayer()) 627 if (!rootLayer())
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 else 960 else
964 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); 961 layer->notifyAnimationFinished(wallClockTime.ToDoubleT());
965 } 962 }
966 } 963 }
967 964
968 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) 965 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex)
969 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); 966 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime);
970 } 967 }
971 968
972 } // namespace cc 969 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698