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

Side by Side Diff: Source/core/rendering/compositing/RenderLayerCompositor.cpp

Issue 185293002: Factor GraphicsLayerUpdater out of RenderLayerCompositor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address reviewer comments Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/compositing/GraphicsLayerUpdater.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "core/rendering/RenderEmbeddedObject.h" 52 #include "core/rendering/RenderEmbeddedObject.h"
53 #include "core/rendering/RenderFullScreen.h" 53 #include "core/rendering/RenderFullScreen.h"
54 #include "core/rendering/RenderGeometryMap.h" 54 #include "core/rendering/RenderGeometryMap.h"
55 #include "core/rendering/RenderIFrame.h" 55 #include "core/rendering/RenderIFrame.h"
56 #include "core/rendering/RenderLayerStackingNode.h" 56 #include "core/rendering/RenderLayerStackingNode.h"
57 #include "core/rendering/RenderLayerStackingNodeIterator.h" 57 #include "core/rendering/RenderLayerStackingNodeIterator.h"
58 #include "core/rendering/RenderReplica.h" 58 #include "core/rendering/RenderReplica.h"
59 #include "core/rendering/RenderVideo.h" 59 #include "core/rendering/RenderVideo.h"
60 #include "core/rendering/RenderView.h" 60 #include "core/rendering/RenderView.h"
61 #include "core/rendering/compositing/CompositedLayerMapping.h" 61 #include "core/rendering/compositing/CompositedLayerMapping.h"
62 #include "core/rendering/compositing/GraphicsLayerUpdater.h"
62 #include "platform/OverscrollTheme.h" 63 #include "platform/OverscrollTheme.h"
63 #include "platform/TraceEvent.h" 64 #include "platform/TraceEvent.h"
64 #include "platform/geometry/TransformState.h" 65 #include "platform/geometry/TransformState.h"
65 #include "platform/graphics/GraphicsLayer.h" 66 #include "platform/graphics/GraphicsLayer.h"
66 #include "platform/scroll/ScrollbarTheme.h" 67 #include "platform/scroll/ScrollbarTheme.h"
67 #include "public/platform/Platform.h" 68 #include "public/platform/Platform.h"
68 #include "wtf/TemporaryChange.h" 69 #include "wtf/TemporaryChange.h"
69 70
70 #ifndef NDEBUG 71 #ifndef NDEBUG
71 #include "core/rendering/RenderTreeAsText.h" 72 #include "core/rendering/RenderTreeAsText.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 466
466 { 467 {
467 TRACE_EVENT0("blink_rendering", "RenderLayerCompositor::updateHasVis ibleNonLayerContentLoop"); 468 TRACE_EVENT0("blink_rendering", "RenderLayerCompositor::updateHasVis ibleNonLayerContentLoop");
468 const FrameView::ScrollableAreaSet* scrollableAreas = m_renderView-> frameView()->scrollableAreas(); 469 const FrameView::ScrollableAreaSet* scrollableAreas = m_renderView-> frameView()->scrollableAreas();
469 if (scrollableAreas) { 470 if (scrollableAreas) {
470 for (FrameView::ScrollableAreaSet::iterator it = scrollableAreas ->begin(); it != scrollableAreas->end(); ++it) 471 for (FrameView::ScrollableAreaSet::iterator it = scrollableAreas ->begin(); it != scrollableAreas->end(); ++it)
471 (*it)->updateHasVisibleNonLayerContent(); 472 (*it)->updateHasVisibleNonLayerContent();
472 } 473 }
473 } 474 }
474 475
475 needHierarchyAndGeometryUpdate |= layersChanged; 476 if (layersChanged)
477 needHierarchyAndGeometryUpdate = true;
476 } 478 }
477 479
478 if (needHierarchyAndGeometryUpdate) { 480 if (needHierarchyAndGeometryUpdate) {
479 // Update the hierarchy of the compositing layers. 481 // Update the hierarchy of the compositing layers.
480 Vector<GraphicsLayer*> childList; 482 Vector<GraphicsLayer*> childList;
481 { 483 {
482 TRACE_EVENT0("blink_rendering", "RenderLayerCompositor::rebuildCompo sitingLayerTree"); 484 TRACE_EVENT0("blink_rendering", "GraphicsLayerUpdater::rebuildTree") ;
483 rebuildCompositingLayerTree(updateRoot, childList, 0); 485 GraphicsLayerUpdater(*m_renderView).rebuildTree(*updateRoot, childLi st, 0);
484 } 486 }
485 487
486 // Host the document layer in the RenderView's root layer. 488 // Host the document layer in the RenderView's root layer.
487 if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled() && isMainFra me()) { 489 if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled() && isMainFra me()) {
488 RenderVideo* video = findFullscreenVideoRenderer(m_renderView->docum ent()); 490 RenderVideo* video = findFullscreenVideoRenderer(m_renderView->docum ent());
489 if (video && video->hasCompositedLayerMapping()) { 491 if (video && video->hasCompositedLayerMapping()) {
490 childList.clear(); 492 childList.clear();
491 childList.append(video->compositedLayerMapping()->mainGraphicsLa yer()); 493 childList.append(video->compositedLayerMapping()->mainGraphicsLa yer());
492 } 494 }
493 } 495 }
494 496
495 if (childList.isEmpty()) 497 if (childList.isEmpty())
496 destroyRootLayer(); 498 destroyRootLayer();
497 else 499 else
498 m_rootContentLayer->setChildren(childList); 500 m_rootContentLayer->setChildren(childList);
499 } else if (needGeometryUpdate) { 501 } else if (needGeometryUpdate) {
500 // We just need to do a geometry update. This is only used for position: fixed scrolling; 502 // We just need to do a geometry update. This is only used for position: fixed scrolling;
501 // most of the time, geometry is updated via RenderLayer::styleChanged() . 503 // most of the time, geometry is updated via RenderLayer::styleChanged() .
502 TRACE_EVENT0("blink_rendering", "RenderLayerCompositor::updateLayerTreeG eometry"); 504 TRACE_EVENT0("blink_rendering", "GraphicsLayerUpdater::updateRecursive") ;
503 updateLayerTreeGeometry(updateRoot); 505 GraphicsLayerUpdater(*m_renderView).updateRecursive(*updateRoot);
504 } 506 }
505 507
506 ASSERT(updateRoot || !m_compositingLayersNeedRebuild); 508 ASSERT(updateRoot || !m_compositingLayersNeedRebuild);
507 509
508 if (!hasAcceleratedCompositing()) 510 if (!hasAcceleratedCompositing())
509 enableCompositingMode(false); 511 enableCompositingMode(false);
510 512
511 // The scrolling coordinator may realize that it needs updating while compos iting was being updated in this function. 513 // The scrolling coordinator may realize that it needs updating while compos iting was being updated in this function.
512 needsToUpdateScrollingCoordinator |= scrollingCoordinator() ? scrollingCoord inator()->needsToUpdateAfterCompositingChange() : false; 514 needsToUpdateScrollingCoordinator |= scrollingCoordinator() ? scrollingCoord inator()->needsToUpdateAfterCompositingChange() : false;
513 if (needsToUpdateScrollingCoordinator && isMainFrame() && scrollingCoordinat or() && inCompositingMode()) 515 if (needsToUpdateScrollingCoordinator && isMainFrame() && scrollingCoordinat or() && inCompositingMode())
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 } 1272 }
1271 1273
1272 void RenderLayerCompositor::removeCompositedChildren(RenderLayer* layer) 1274 void RenderLayerCompositor::removeCompositedChildren(RenderLayer* layer)
1273 { 1275 {
1274 ASSERT(layer->hasCompositedLayerMapping()); 1276 ASSERT(layer->hasCompositedLayerMapping());
1275 1277
1276 GraphicsLayer* hostingLayer = layer->compositedLayerMapping()->parentForSubl ayers(); 1278 GraphicsLayer* hostingLayer = layer->compositedLayerMapping()->parentForSubl ayers();
1277 hostingLayer->removeAllChildren(); 1279 hostingLayer->removeAllChildren();
1278 } 1280 }
1279 1281
1280 void RenderLayerCompositor::updateGraphicsLayersMappedToRenderLayer(RenderLayer* layer)
1281 {
1282 if (!layer->hasCompositedLayerMapping())
1283 return;
1284
1285 CompositedLayerMappingPtr compositedLayerMapping = layer->compositedLayerMap ping();
1286
1287 // Note carefully: here we assume that the compositing state of all descenda nts have been updated already,
1288 // so it is legitimate to compute and cache the composited bounds for this l ayer.
1289 compositedLayerMapping->updateCompositedBounds();
1290
1291 if (layer->reflectionInfo()) {
1292 RenderLayer* reflectionLayer = layer->reflectionInfo()->reflectionLayer( );
1293 ASSERT(reflectionLayer);
1294 if (reflectionLayer->hasCompositedLayerMapping())
1295 reflectionLayer->compositedLayerMapping()->updateCompositedBounds();
1296 }
1297
1298 compositedLayerMapping->updateGraphicsLayerConfiguration();
1299 compositedLayerMapping->updateGraphicsLayerGeometry();
1300
1301 if (!layer->parent())
1302 updateRootLayerPosition();
1303
1304 if (compositedLayerMapping->hasUnpositionedOverflowControlsLayers())
1305 layer->scrollableArea()->positionOverflowControls();
1306 }
1307
1308 void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer* layer, Vect or<GraphicsLayer*>& childLayersOfEnclosingLayer, int depth)
1309 {
1310 // Make the layer compositing if necessary, and set up clipping and content layers.
1311 // Note that we can only do work here that is independent of whether the des cendant layers
1312 // have been processed. computeCompositingRequirements() will already have d one the repaint if necessary.
1313
1314 layer->stackingNode()->updateLayerListsIfNeeded();
1315 layer->update3dRenderingContext();
1316
1317 // Used for gathering UMA data about the effect on memory usage of promoting all layers
1318 // that have a webkit-transition on opacity or transform and intersect the v iewport.
1319 static double pixelsWithoutPromotingAllTransitions = 0.0;
1320 static double pixelsAddedByPromotingAllTransitions = 0.0;
1321
1322 if (!depth) {
1323 pixelsWithoutPromotingAllTransitions = 0.0;
1324 pixelsAddedByPromotingAllTransitions = 0.0;
1325 }
1326
1327 const bool hasCompositedLayerMapping = layer->hasCompositedLayerMapping();
1328 CompositedLayerMappingPtr currentCompositedLayerMapping = layer->compositedL ayerMapping();
1329
1330 updateGraphicsLayersMappedToRenderLayer(layer);
1331
1332 // Grab some stats for histograms.
1333 if (hasCompositedLayerMapping) {
1334 pixelsWithoutPromotingAllTransitions += layer->size().height() * layer-> size().width();
1335 } else {
1336 if ((layer->renderer()->style()->transitionForProperty(CSSPropertyOpacit y) ||
1337 layer->renderer()->style()->transitionForProperty(CSSPropertyWebkit Transform)) &&
1338 m_renderView->viewRect().intersects(layer->absoluteBoundingBox()))
1339 pixelsAddedByPromotingAllTransitions += layer->size().height() * lay er->size().width();
1340 }
1341
1342 // If this layer has a compositedLayerMapping, then that is where we place s ubsequent children GraphicsLayers.
1343 // Otherwise children continue to append to the child list of the enclosing layer.
1344 Vector<GraphicsLayer*> layerChildren;
1345 Vector<GraphicsLayer*>& childList = hasCompositedLayerMapping ? layerChildre n : childLayersOfEnclosingLayer;
1346
1347 #if !ASSERT_DISABLED
1348 LayerListMutationDetector mutationChecker(layer->stackingNode());
1349 #endif
1350
1351 if (layer->stackingNode()->isStackingContainer()) {
1352 RenderLayerStackingNodeIterator iterator(*layer->stackingNode(), Negativ eZOrderChildren);
1353 while (RenderLayerStackingNode* curNode = iterator.next())
1354 rebuildCompositingLayerTree(curNode->layer(), childList, depth + 1);
1355
1356 // If a negative z-order child is compositing, we get a foreground layer which needs to get parented.
1357 if (hasCompositedLayerMapping && currentCompositedLayerMapping->foregrou ndLayer())
1358 childList.append(currentCompositedLayerMapping->foregroundLayer());
1359 }
1360
1361 RenderLayerStackingNodeIterator iterator(*layer->stackingNode(), NormalFlowC hildren | PositiveZOrderChildren);
1362 while (RenderLayerStackingNode* curNode = iterator.next())
1363 rebuildCompositingLayerTree(curNode->layer(), childList, depth + 1);
1364
1365 if (hasCompositedLayerMapping) {
1366 bool parented = false;
1367 if (layer->renderer()->isRenderPart())
1368 parented = parentFrameContentLayers(toRenderPart(layer->renderer())) ;
1369
1370 if (!parented)
1371 currentCompositedLayerMapping->parentForSublayers()->setChildren(lay erChildren);
1372
1373 // If the layer has a clipping layer the overflow controls layers will b e siblings of the clipping layer.
1374 // Otherwise, the overflow control layers are normal children.
1375 if (!currentCompositedLayerMapping->hasClippingLayer() && !currentCompos itedLayerMapping->hasScrollingLayer()) {
1376 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapp ing->layerForHorizontalScrollbar()) {
1377 overflowControlLayer->removeFromParent();
1378 currentCompositedLayerMapping->parentForSublayers()->addChild(ov erflowControlLayer);
1379 }
1380
1381 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapp ing->layerForVerticalScrollbar()) {
1382 overflowControlLayer->removeFromParent();
1383 currentCompositedLayerMapping->parentForSublayers()->addChild(ov erflowControlLayer);
1384 }
1385
1386 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapp ing->layerForScrollCorner()) {
1387 overflowControlLayer->removeFromParent();
1388 currentCompositedLayerMapping->parentForSublayers()->addChild(ov erflowControlLayer);
1389 }
1390 }
1391
1392 childLayersOfEnclosingLayer.append(currentCompositedLayerMapping->childF orSuperlayers());
1393 }
1394
1395 if (!depth) {
1396 int percentageIncreaseInPixels = static_cast<int>(pixelsAddedByPromoting AllTransitions / pixelsWithoutPromotingAllTransitions * 100);
1397 blink::Platform::current()->histogramCustomCounts("Renderer.PixelIncreas eFromTransitions", percentageIncreaseInPixels, 0, 1000, 50);
1398 }
1399 }
1400
1401 void RenderLayerCompositor::frameViewDidChangeLocation(const IntPoint& contentsO ffset) 1282 void RenderLayerCompositor::frameViewDidChangeLocation(const IntPoint& contentsO ffset)
1402 { 1283 {
1403 if (m_overflowControlsHostLayer) 1284 if (m_overflowControlsHostLayer)
1404 m_overflowControlsHostLayer->setPosition(contentsOffset); 1285 m_overflowControlsHostLayer->setPosition(contentsOffset);
1405 } 1286 }
1406 1287
1407 void RenderLayerCompositor::frameViewDidChangeSize() 1288 void RenderLayerCompositor::frameViewDidChangeSize()
1408 { 1289 {
1409 if (m_containerLayer) { 1290 if (m_containerLayer) {
1410 FrameView* frameView = m_renderView->frameView(); 1291 FrameView* frameView = m_renderView->frameView();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 return 0; 1399 return 0;
1519 1400
1520 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(renderer->node()); 1401 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(renderer->node());
1521 if (Document* contentDocument = element->contentDocument()) { 1402 if (Document* contentDocument = element->contentDocument()) {
1522 if (RenderView* view = contentDocument->renderView()) 1403 if (RenderView* view = contentDocument->renderView())
1523 return view->compositor(); 1404 return view->compositor();
1524 } 1405 }
1525 return 0; 1406 return 0;
1526 } 1407 }
1527 1408
1409 // FIXME: What does this function do? It needs a clearer name.
1528 bool RenderLayerCompositor::parentFrameContentLayers(RenderPart* renderer) 1410 bool RenderLayerCompositor::parentFrameContentLayers(RenderPart* renderer)
1529 { 1411 {
1530 RenderLayerCompositor* innerCompositor = frameContentsCompositor(renderer); 1412 RenderLayerCompositor* innerCompositor = frameContentsCompositor(renderer);
1531 if (!innerCompositor || !innerCompositor->inCompositingMode() || innerCompos itor->rootLayerAttachment() != RootLayerAttachedViaEnclosingFrame) 1413 if (!innerCompositor || !innerCompositor->inCompositingMode() || innerCompos itor->rootLayerAttachment() != RootLayerAttachedViaEnclosingFrame)
1532 return false; 1414 return false;
1533 1415
1534 RenderLayer* layer = renderer->layer(); 1416 RenderLayer* layer = renderer->layer();
1535 if (!layer->hasCompositedLayerMapping()) 1417 if (!layer->hasCompositedLayerMapping())
1536 return false; 1418 return false;
1537 1419
1538 CompositedLayerMappingPtr compositedLayerMapping = layer->compositedLayerMap ping(); 1420 CompositedLayerMappingPtr compositedLayerMapping = layer->compositedLayerMap ping();
1539 GraphicsLayer* hostingLayer = compositedLayerMapping->parentForSublayers(); 1421 GraphicsLayer* hostingLayer = compositedLayerMapping->parentForSublayers();
1540 GraphicsLayer* rootLayer = innerCompositor->rootGraphicsLayer(); 1422 GraphicsLayer* rootLayer = innerCompositor->rootGraphicsLayer();
1541 if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != r ootLayer) { 1423 if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != r ootLayer) {
1542 hostingLayer->removeAllChildren(); 1424 hostingLayer->removeAllChildren();
1543 hostingLayer->addChild(rootLayer); 1425 hostingLayer->addChild(rootLayer);
1544 } 1426 }
1545 return true; 1427 return true;
1546 } 1428 }
1547 1429
1548 // This just updates layer geometry without changing the hierarchy.
1549 void RenderLayerCompositor::updateLayerTreeGeometry(RenderLayer* layer)
1550 {
1551 updateGraphicsLayersMappedToRenderLayer(layer);
1552
1553 #if !ASSERT_DISABLED
1554 LayerListMutationDetector mutationChecker(layer->stackingNode());
1555 #endif
1556
1557 RenderLayerStackingNodeIterator iterator(*layer->stackingNode(), AllChildren );
1558 while (RenderLayerStackingNode* curNode = iterator.next())
1559 updateLayerTreeGeometry(curNode->layer());
1560 }
1561
1562 // Recurs down the RenderLayer tree until its finds the compositing descendants of compositingAncestor and updates their geometry. 1430 // Recurs down the RenderLayer tree until its finds the compositing descendants of compositingAncestor and updates their geometry.
1563 void RenderLayerCompositor::updateCompositingDescendantGeometry(RenderLayerStack ingNode* compositingAncestor, RenderLayer* layer, bool compositedChildrenOnly) 1431 void RenderLayerCompositor::updateCompositingDescendantGeometry(RenderLayerStack ingNode* compositingAncestor, RenderLayer* layer, bool compositedChildrenOnly)
1564 { 1432 {
1565 if (layer->stackingNode() != compositingAncestor) { 1433 if (layer->stackingNode() != compositingAncestor) {
1566 if (layer->hasCompositedLayerMapping()) { 1434 if (layer->hasCompositedLayerMapping()) {
1567 CompositedLayerMappingPtr compositedLayerMapping = layer->composited LayerMapping(); 1435 CompositedLayerMappingPtr compositedLayerMapping = layer->composited LayerMapping();
1568 compositedLayerMapping->updateCompositedBounds(); 1436 compositedLayerMapping->updateCompositedBounds();
1569 1437
1570 if (layer->reflectionInfo()) { 1438 if (layer->reflectionInfo()) {
1571 RenderLayer* reflectionLayer = layer->reflectionInfo()->reflecti onLayer(); 1439 RenderLayer* reflectionLayer = layer->reflectionInfo()->reflecti onLayer();
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 } else if (graphicsLayer == m_scrollLayer.get()) { 2273 } else if (graphicsLayer == m_scrollLayer.get()) {
2406 name = "LocalFrame Scrolling Layer"; 2274 name = "LocalFrame Scrolling Layer";
2407 } else { 2275 } else {
2408 ASSERT_NOT_REACHED(); 2276 ASSERT_NOT_REACHED();
2409 } 2277 }
2410 2278
2411 return name; 2279 return name;
2412 } 2280 }
2413 2281
2414 } // namespace WebCore 2282 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/compositing/GraphicsLayerUpdater.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698