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

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

Issue 143283011: Make squashing work with subpixel layout (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add ASSERT 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2010, 2011 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 LayoutRect result = PaintInfo::infiniteRect(); 554 LayoutRect result = PaintInfo::infiniteRect();
555 if (renderer->hasOverflowClip()) 555 if (renderer->hasOverflowClip())
556 result = renderer->overflowClipRect(LayoutPoint()); 556 result = renderer->overflowClipRect(LayoutPoint());
557 557
558 if (renderer->hasClip()) 558 if (renderer->hasClip())
559 result.intersect(renderer->clipRect(LayoutPoint())); 559 result.intersect(renderer->clipRect(LayoutPoint()));
560 560
561 return pixelSnappedIntRect(result); 561 return pixelSnappedIntRect(result);
562 } 562 }
563 563
564 static LayoutPoint computeOffsetFromCompositedAncestor(const RenderLayer* layer, const RenderLayer* compositedAncestor)
565 {
566 LayoutPoint offset;
567 layer->convertToLayerCoords(compositedAncestor, offset);
568 if (compositedAncestor)
569 offset.move(compositedAncestor->compositedLayerMapping()->subpixelAccumu lation());
570 return offset;
571 }
572
564 void CompositedLayerMapping::adjustBoundsForSubPixelAccumulation(const RenderLay er* compositedAncestor, IntRect& localBounds, IntRect& relativeBounds, IntPoint& delta) 573 void CompositedLayerMapping::adjustBoundsForSubPixelAccumulation(const RenderLay er* compositedAncestor, IntRect& localBounds, IntRect& relativeBounds, IntPoint& delta)
565 { 574 {
566 LayoutRect localRawCompositingBounds = compositedBounds(); 575 LayoutRect localRawCompositingBounds = compositedBounds();
567 LayoutPoint rawDelta; 576 LayoutPoint rawDelta = computeOffsetFromCompositedAncestor(&m_owningLayer, c ompositedAncestor);
568 m_owningLayer.convertToLayerCoords(compositedAncestor, rawDelta);
569 if (compositedAncestor)
570 rawDelta.move(compositedAncestor->compositedLayerMapping()->subpixelAccu mulation());
571 delta = flooredIntPoint(rawDelta); 577 delta = flooredIntPoint(rawDelta);
572 m_subpixelAccumulation = toLayoutSize(rawDelta).fraction(); 578 m_subpixelAccumulation = toLayoutSize(rawDelta).fraction();
573 RELEASE_ASSERT(m_subpixelAccumulation.width() < 1 && m_subpixelAccumulation. height() < 1); 579 RELEASE_ASSERT(m_subpixelAccumulation.width() < 1 && m_subpixelAccumulation. height() < 1);
574 580
575 // Move the bounds by the subpixel accumulation so that it pixel-snaps relat ive to absolute pixels instead of local coordinates. 581 // Move the bounds by the subpixel accumulation so that it pixel-snaps relat ive to absolute pixels instead of local coordinates.
576 localRawCompositingBounds.move(m_subpixelAccumulation); 582 localRawCompositingBounds.move(m_subpixelAccumulation);
577 localBounds = pixelSnappedIntRect(localRawCompositingBounds); 583 localBounds = pixelSnappedIntRect(localRawCompositingBounds);
578 584
579 relativeBounds = localBounds; 585 relativeBounds = localBounds;
580 relativeBounds.moveBy(delta); 586 relativeBounds.moveBy(delta);
(...skipping 12 matching lines...) Expand all
593 599
594 // Store the local bounds of the RenderLayer subtree before applying the offset. 600 // Store the local bounds of the RenderLayer subtree before applying the offset.
595 m_squashedLayers[i].compositedBounds = squashedBounds; 601 m_squashedLayers[i].compositedBounds = squashedBounds;
596 602
597 squashedBounds.move(m_squashedLayers[i].offsetFromSquashingCLM); 603 squashedBounds.move(m_squashedLayers[i].offsetFromSquashingCLM);
598 totalSquashBounds.unite(squashedBounds); 604 totalSquashBounds.unite(squashedBounds);
599 } 605 }
600 606
601 // The totalSquashBounds is positioned with respect to m_owningLayer of this CompositedLayerMapping. 607 // The totalSquashBounds is positioned with respect to m_owningLayer of this CompositedLayerMapping.
602 // But the squashingLayer needs to be positioned with respect to the ancesto r CompositedLayerMapping. 608 // But the squashingLayer needs to be positioned with respect to the ancesto r CompositedLayerMapping.
603 // The conversion between m_owningLayer and the ancestor CLM is already comp uted in the caller as |delta|. 609 // The conversion between m_owningLayer and the ancestor CLM is already comp uted in the caller as
604 // FIXME: probably not the right place to round from LayoutPoint to IntPoint ? 610 // |delta| + |m_subpixelAccumulation|.
605 IntPoint squashLayerPosition = pixelSnappedIntRect(totalSquashBounds).locati on(); 611 LayoutPoint rawDelta = delta + m_subpixelAccumulation;
606 squashLayerPosition.moveBy(delta); 612 totalSquashBounds.moveBy(rawDelta);
613 IntRect squashLayerBounds = enclosingIntRect(totalSquashBounds);
614 IntPoint squashLayerOrigin = squashLayerBounds.location();
615 LayoutPoint squashLayerOriginInOwningLayerSpace = LayoutPoint(squashLayerOri gin - rawDelta);
607 616
608 m_squashingLayer->setPosition(squashLayerPosition); 617 m_squashingLayer->setPosition(squashLayerBounds.location());
609 m_squashingLayer->setSize(totalSquashBounds.size()); 618 m_squashingLayer->setSize(squashLayerBounds.size());
610 619
611 // Now that the squashing bounds are known, we can convert the RenderLayer p ainting offsets 620 // Now that the squashing bounds are known, we can convert the RenderLayer p ainting offsets
612 // from CLM owning layer space to the squashing layer space. 621 // from CLM owning layer space to the squashing layer space.
613 // 622 //
614 // The painting offset we want to compute for each squashed RenderLayer is e ssentially the position of 623 // The painting offset we want to compute for each squashed RenderLayer is e ssentially the position of
615 // the squashed RenderLayer described w.r.t. m_squashingLayer's origin. For this purpose we already cached 624 // the squashed RenderLayer described w.r.t. m_squashingLayer's origin. For this purpose we already cached
616 // offsetFromSquashingCLM before, which describes where the squashed RenderL ayer is located w.r.t. 625 // offsetFromSquashingCLM before, which describes where the squashed RenderL ayer is located w.r.t.
617 // m_owningLayer. So we just need to convert that point from m_owningLayer s pace to m_squashingLayer 626 // m_owningLayer. So we just need to convert that point from m_owningLayer s pace to m_squashingLayer
618 // space. This is simply done by subtracing totalSquashBounds... but then th e offset overall needs to be 627 // space. This is simply done by subtracing squashLayerOriginInOwningLayerSp ace, but then the offset
619 // negated because that's the direction that the painting code expects the o ffset to be. 628 // overall needs to be negated because that's the direction that the paintin g code expects the
629 // offset to be.
620 for (size_t i = 0; i < m_squashedLayers.size(); ++i) { 630 for (size_t i = 0; i < m_squashedLayers.size(); ++i) {
621 m_squashedLayers[i].offsetFromRenderer = IntSize(-m_squashedLayers[i].of fsetFromSquashingCLM.width() + totalSquashBounds.x(), 631 LayoutSize offsetFromSquashLayerOrigin = LayoutPoint(m_squashedLayers[i] .offsetFromSquashingCLM) - squashLayerOriginInOwningLayerSpace;
622 -m_squashedLayers[i].offsetFromSquashingCLM.height() + totalSquashBo unds.y()); 632 m_squashedLayers[i].offsetFromRenderer = -flooredIntSize(offsetFromSquas hLayerOrigin);
633 m_squashedLayers[i].subpixelAccumulation = offsetFromSquashLayerOrigin.f raction();
634 ASSERT(m_squashedLayers[i].subpixelAccumulation ==
leviw_travelin_and_unemployed 2014/03/19 20:30:27 Perfect, thank you!
635 toLayoutSize(computeOffsetFromCompositedAncestor(m_squashedLayers[i] .renderLayer, m_squashedLayers[i].renderLayer->ancestorCompositingLayer())).frac tion());
623 636
624 // FIXME: find a better design to avoid this redundant value - most like ly it will make 637 // FIXME: find a better design to avoid this redundant value - most like ly it will make
625 // sense to move the paint task info into RenderLayer's m_compositingPro perties. 638 // sense to move the paint task info into RenderLayer's m_compositingPro perties.
626 m_squashedLayers[i].renderLayer->setOffsetFromSquashingLayerOrigin(m_squ ashedLayers[i].offsetFromRenderer); 639 m_squashedLayers[i].renderLayer->setOffsetFromSquashingLayerOrigin(m_squ ashedLayers[i].offsetFromRenderer);
627 } 640 }
628 } 641 }
629 642
630 GraphicsLayerUpdater::UpdateType CompositedLayerMapping::updateGraphicsLayerGeom etry(GraphicsLayerUpdater::UpdateType updateType) 643 GraphicsLayerUpdater::UpdateType CompositedLayerMapping::updateGraphicsLayerGeom etry(GraphicsLayerUpdater::UpdateType updateType)
631 { 644 {
632 // If we haven't built z-order lists yet, wait until later. 645 // If we haven't built z-order lists yet, wait until later.
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 1909
1897 IntSize offset = paintInfo.offsetFromRenderer; 1910 IntSize offset = paintInfo.offsetFromRenderer;
1898 context->translate(-offset); 1911 context->translate(-offset);
1899 1912
1900 // The dirtyRect is in the coords of the painting root. 1913 // The dirtyRect is in the coords of the painting root.
1901 IntRect dirtyRect(clip); 1914 IntRect dirtyRect(clip);
1902 dirtyRect.move(offset); 1915 dirtyRect.move(offset);
1903 1916
1904 if (!(paintInfo.paintingPhase & GraphicsLayerPaintOverflowContents)) { 1917 if (!(paintInfo.paintingPhase & GraphicsLayerPaintOverflowContents)) {
1905 LayoutRect bounds = paintInfo.compositedBounds; 1918 LayoutRect bounds = paintInfo.compositedBounds;
1906 bounds.move(m_subpixelAccumulation); 1919 bounds.move(paintInfo.subpixelAccumulation);
1907 dirtyRect.intersect(pixelSnappedIntRect(bounds)); 1920 dirtyRect.intersect(pixelSnappedIntRect(bounds));
1908 } else { 1921 } else {
1909 dirtyRect.move(roundedIntSize(m_subpixelAccumulation)); 1922 dirtyRect.move(roundedIntSize(paintInfo.subpixelAccumulation));
1910 } 1923 }
1911 1924
1912 #ifndef NDEBUG 1925 #ifndef NDEBUG
1913 paintInfo.renderLayer->renderer()->assertSubtreeIsLaidOut(); 1926 paintInfo.renderLayer->renderer()->assertSubtreeIsLaidOut();
1914 #endif 1927 #endif
1915 1928
1916 if (paintInfo.renderLayer->compositingState() != PaintsIntoGroupedBacking) { 1929 if (paintInfo.renderLayer->compositingState() != PaintsIntoGroupedBacking) {
1917 // FIXME: GraphicsLayers need a way to split for RenderRegions. 1930 // FIXME: GraphicsLayers need a way to split for RenderRegions.
1918 LayerPaintingInfo paintingInfo(paintInfo.renderLayer, dirtyRect, PaintBe haviorNormal, m_subpixelAccumulation); 1931 LayerPaintingInfo paintingInfo(paintInfo.renderLayer, dirtyRect, PaintBe haviorNormal, paintInfo.subpixelAccumulation);
1919 paintInfo.renderLayer->paintLayerContents(context, paintingInfo, paintFl ags); 1932 paintInfo.renderLayer->paintLayerContents(context, paintingInfo, paintFl ags);
1920 1933
1921 ASSERT(!paintInfo.isBackgroundLayer || paintFlags & PaintLayerPaintingRo otBackgroundOnly); 1934 ASSERT(!paintInfo.isBackgroundLayer || paintFlags & PaintLayerPaintingRo otBackgroundOnly);
1922 1935
1923 if (paintInfo.renderLayer->containsDirtyOverlayScrollbars()) 1936 if (paintInfo.renderLayer->containsDirtyOverlayScrollbars())
1924 paintInfo.renderLayer->paintLayerContents(context, paintingInfo, pai ntFlags | PaintLayerPaintingOverlayScrollbars); 1937 paintInfo.renderLayer->paintLayerContents(context, paintingInfo, pai ntFlags | PaintLayerPaintingOverlayScrollbars);
1925 } else { 1938 } else {
1926 ASSERT(compositor()->layerSquashingEnabled()); 1939 ASSERT(compositor()->layerSquashingEnabled());
1927 LayerPaintingInfo paintingInfo(paintInfo.renderLayer, dirtyRect, PaintBe haviorNormal, LayoutSize()); 1940 LayerPaintingInfo paintingInfo(paintInfo.renderLayer, dirtyRect, PaintBe haviorNormal, paintInfo.subpixelAccumulation);
1928 paintInfo.renderLayer->paintLayer(context, paintingInfo, paintFlags); 1941 paintInfo.renderLayer->paintLayer(context, paintingInfo, paintFlags);
1929 } 1942 }
1930 1943
1931 ASSERT(!paintInfo.renderLayer->m_usedTransparency); 1944 ASSERT(!paintInfo.renderLayer->m_usedTransparency);
1932 1945
1933 // Manually restore the context to its original state by applying the opposi te translation. 1946 // Manually restore the context to its original state by applying the opposi te translation.
1934 context->translate(offset); 1947 context->translate(offset);
1935 } 1948 }
1936 1949
1937 static void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRect& clip) 1950 static void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRect& clip)
(...skipping 28 matching lines...) Expand all
1966 || graphicsLayer == m_maskLayer.get() 1979 || graphicsLayer == m_maskLayer.get()
1967 || graphicsLayer == m_childClippingMaskLayer.get() 1980 || graphicsLayer == m_childClippingMaskLayer.get()
1968 || graphicsLayer == m_scrollingContentsLayer.get()) { 1981 || graphicsLayer == m_scrollingContentsLayer.get()) {
1969 1982
1970 GraphicsLayerPaintInfo paintInfo; 1983 GraphicsLayerPaintInfo paintInfo;
1971 paintInfo.renderLayer = &m_owningLayer; 1984 paintInfo.renderLayer = &m_owningLayer;
1972 paintInfo.compositedBounds = compositedBounds(); 1985 paintInfo.compositedBounds = compositedBounds();
1973 paintInfo.offsetFromRenderer = graphicsLayer->offsetFromRenderer(); 1986 paintInfo.offsetFromRenderer = graphicsLayer->offsetFromRenderer();
1974 paintInfo.paintingPhase = paintingPhase; 1987 paintInfo.paintingPhase = paintingPhase;
1975 paintInfo.isBackgroundLayer = (graphicsLayer == m_backgroundLayer); 1988 paintInfo.isBackgroundLayer = (graphicsLayer == m_backgroundLayer);
1989 paintInfo.subpixelAccumulation = m_subpixelAccumulation;
1976 1990
1977 // We have to use the same root as for hit testing, because both methods can compute and cache clipRects. 1991 // We have to use the same root as for hit testing, because both methods can compute and cache clipRects.
1978 doPaintTask(paintInfo, &context, clip); 1992 doPaintTask(paintInfo, &context, clip);
1979 } else if (graphicsLayer == m_squashingLayer.get()) { 1993 } else if (graphicsLayer == m_squashingLayer.get()) {
1980 ASSERT(compositor()->layerSquashingEnabled()); 1994 ASSERT(compositor()->layerSquashingEnabled());
1981 for (size_t i = 0; i < m_squashedLayers.size(); ++i) 1995 for (size_t i = 0; i < m_squashedLayers.size(); ++i)
1982 doPaintTask(m_squashedLayers[i], &context, clip); 1996 doPaintTask(m_squashedLayers[i], &context, clip);
1983 } else if (graphicsLayer == layerForHorizontalScrollbar()) { 1997 } else if (graphicsLayer == layerForHorizontalScrollbar()) {
1984 paintScrollbar(m_owningLayer.scrollableArea()->horizontalScrollbar(), co ntext, clip); 1998 paintScrollbar(m_owningLayer.scrollableArea()->horizontalScrollbar(), co ntext, clip);
1985 } else if (graphicsLayer == layerForVerticalScrollbar()) { 1999 } else if (graphicsLayer == layerForVerticalScrollbar()) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 LayoutRect bounds = m_compositedBounds; 2051 LayoutRect bounds = m_compositedBounds;
2038 bounds.move(m_subpixelAccumulation); 2052 bounds.move(m_subpixelAccumulation);
2039 return pixelSnappedIntRect(bounds); 2053 return pixelSnappedIntRect(bounds);
2040 } 2054 }
2041 2055
2042 void CompositedLayerMapping::setCompositedBounds(const LayoutRect& bounds) 2056 void CompositedLayerMapping::setCompositedBounds(const LayoutRect& bounds)
2043 { 2057 {
2044 m_compositedBounds = bounds; 2058 m_compositedBounds = bounds;
2045 } 2059 }
2046 2060
2047 bool CompositedLayerMapping::updateSquashingLayerAssignment(RenderLayer* layer, IntSize offsetFromSquashingCLM, size_t nextSquashedLayerIndex) 2061 bool CompositedLayerMapping::updateSquashingLayerAssignment(RenderLayer* layer, LayoutSize offsetFromSquashingCLM, size_t nextSquashedLayerIndex)
2048 { 2062 {
2049 ASSERT(compositor()->layerSquashingEnabled()); 2063 ASSERT(compositor()->layerSquashingEnabled());
2050 2064
2051 GraphicsLayerPaintInfo paintInfo; 2065 GraphicsLayerPaintInfo paintInfo;
2052 paintInfo.renderLayer = layer; 2066 paintInfo.renderLayer = layer;
2053 // NOTE: composited bounds are updated elsewhere 2067 // NOTE: composited bounds are updated elsewhere
2054 // NOTE: offsetFromRenderer is updated elsewhere 2068 // NOTE: offsetFromRenderer is updated elsewhere
2055 paintInfo.offsetFromSquashingCLM = offsetFromSquashingCLM; 2069 paintInfo.offsetFromSquashingCLM = offsetFromSquashingCLM;
2056 paintInfo.paintingPhase = GraphicsLayerPaintAllWithOverflowClip; 2070 paintInfo.paintingPhase = GraphicsLayerPaintAllWithOverflowClip;
2057 paintInfo.isBackgroundLayer = false; 2071 paintInfo.isBackgroundLayer = false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 } else if (graphicsLayer == m_scrollingContentsLayer.get()) { 2146 } else if (graphicsLayer == m_scrollingContentsLayer.get()) {
2133 name = "Scrolling Contents Layer"; 2147 name = "Scrolling Contents Layer";
2134 } else { 2148 } else {
2135 ASSERT_NOT_REACHED(); 2149 ASSERT_NOT_REACHED();
2136 } 2150 }
2137 2151
2138 return name; 2152 return name;
2139 } 2153 }
2140 2154
2141 } // namespace WebCore 2155 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/compositing/CompositedLayerMapping.h ('k') | Source/core/rendering/compositing/RenderLayerCompositor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698