Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "core/paint/LayerPainter.h" | 6 #include "core/paint/LayerPainter.h" |
| 7 | 7 |
| 8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
| 9 #include "core/page/Page.h" | 9 #include "core/page/Page.h" |
| 10 #include "core/paint/FilterPainter.h" | 10 #include "core/paint/FilterPainter.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 | 63 |
| 64 // If this layer is totally invisible then there is nothing to paint. | 64 // If this layer is totally invisible then there is nothing to paint. |
| 65 if (!m_renderLayer.renderer()->opacity()) | 65 if (!m_renderLayer.renderer()->opacity()) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 if (m_renderLayer.paintsWithTransparency(paintingInfo.paintBehavior)) | 68 if (m_renderLayer.paintsWithTransparency(paintingInfo.paintBehavior)) |
| 69 paintFlags |= PaintLayerHaveTransparency; | 69 paintFlags |= PaintLayerHaveTransparency; |
| 70 | 70 |
| 71 // PaintLayerAppliedTransform is used in RenderReplica, to avoid applying th e transform twice. | 71 // PaintLayerAppliedTransform is used in RenderReplica, to avoid applying th e transform twice. |
| 72 if (m_renderLayer.paintsWithTransform(paintingInfo.paintBehavior) && !(paint Flags & PaintLayerAppliedTransform)) { | 72 if (m_renderLayer.paintsWithTransform(paintingInfo.paintBehavior) && !(paint Flags & PaintLayerAppliedTransform)) { |
| 73 TransformationMatrix layerTransform = m_renderLayer.renderableTransform( paintingInfo.paintBehavior); | 73 paintLayerWithTransform(context, paintingInfo, paintFlags); |
| 74 // If the transform can't be inverted, then don't paint anything. | |
| 75 if (!layerTransform.isInvertible()) | |
| 76 return; | |
| 77 | |
| 78 if (m_renderLayer.enclosingPaginationLayer()) { | |
| 79 // FIXME: unify this one-off path with the code below. | |
| 80 paintTransformedLayerIntoFragments(context, paintingInfo, paintFlags ); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 // Make sure the parent's clip rects have been calculated. | |
| 85 ClipRect clipRect = paintingInfo.paintDirtyRect; | |
| 86 | |
| 87 OwnPtr<ClipRecorder> clipRecorder; | |
| 88 if (m_renderLayer.parent()) { | |
| 89 ClipRectsContext clipRectsContext(paintingInfo.rootLayer, (paintFlag s & PaintLayerUncachedClipRects) ? UncachedClipRects : PaintingClipRects, Ignore OverlayScrollbarSize); | |
| 90 if (shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()) == IgnoreOverflowClip) | |
| 91 clipRectsContext.setIgnoreOverflowClip(); | |
| 92 clipRect = m_renderLayer.clipper().backgroundClipRect(clipRectsConte xt); | |
| 93 clipRect.intersect(paintingInfo.paintDirtyRect); | |
| 94 | |
| 95 if (needsToClip(paintingInfo, clipRect)) { | |
| 96 clipRecorder = adoptPtr(new ClipRecorder(m_renderLayer.parent()- >renderer(), context, DisplayItem::ClipLayerParent, clipRect)); | |
| 97 if (clipRect.hasRadius()) | |
| 98 applyRoundedRectClips(*m_renderLayer.parent(), paintingInfo, context, LayoutPoint(), paintFlags, *clipRecorder); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 paintLayerByApplyingTransform(context, paintingInfo, paintFlags); | |
| 103 | |
| 104 return; | 74 return; |
| 105 } | 75 } |
| 106 | 76 |
| 107 paintLayerContentsAndReflection(context, paintingInfo, paintFlags); | 77 paintLayerContentsAndReflection(context, paintingInfo, paintFlags); |
| 108 } | 78 } |
| 109 | 79 |
| 110 class TransparencyLayerHelper { | 80 class TransparencyLayerHelper { |
| 111 public: | 81 public: |
| 112 TransparencyLayerHelper(GraphicsContext* context, RenderLayer& renderLayer, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize & subPixelAccumulation, PaintBehavior paintBehavior) | 82 TransparencyLayerHelper(GraphicsContext* context, RenderLayer& renderLayer, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize & subPixelAccumulation, PaintBehavior paintBehavior) |
| 113 : m_transparencyLayerInProgress(false) | 83 : m_transparencyLayerInProgress(false) |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 // overflow and a subsequent fragment doesn't intersect with the border box of the layer | 374 // overflow and a subsequent fragment doesn't intersect with the border box of the layer |
| 405 // (i.e. only contains an overflow portion of the layer), intersection w ill fail. The reason | 375 // (i.e. only contains an overflow portion of the layer), intersection w ill fail. The reason |
| 406 // for this is that fragment.layerBounds is set to the border box, not t he bounding box, of | 376 // for this is that fragment.layerBounds is set to the border box, not t he bounding box, of |
| 407 // the layer. | 377 // the layer. |
| 408 if (m_renderLayer.intersectsDamageRect(fragment.layerBounds, fragment.ba ckgroundRect.rect(), localPaintingInfo.rootLayer, &newOffsetFromRoot)) | 378 if (m_renderLayer.intersectsDamageRect(fragment.layerBounds, fragment.ba ckgroundRect.rect(), localPaintingInfo.rootLayer, &newOffsetFromRoot)) |
| 409 return true; | 379 return true; |
| 410 } | 380 } |
| 411 return false; | 381 return false; |
| 412 } | 382 } |
| 413 | 383 |
| 414 void LayerPainter::paintLayerByApplyingTransform(GraphicsContext* context, const LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags, const LayoutPoint& translationOffset) | 384 void LayerPainter::paintLayerWithTransform(GraphicsContext* context, const Layer PaintingInfo& paintingInfo, PaintLayerFlags paintFlags) |
| 385 { | |
| 386 TransformationMatrix layerTransform = m_renderLayer.renderableTransform(pain tingInfo.paintBehavior); | |
| 387 // If the transform can't be inverted, then don't paint anything. | |
| 388 if (!layerTransform.isInvertible()) | |
| 389 return; | |
| 390 | |
| 391 // If this is the "root" layer, clipping wrt. the ancestry has already been set up, which | |
| 392 // means that we can skip some unnecessary work (and even potentially incorr ect work at | |
| 393 // that, if the ancestry has additional transforms). | |
| 394 RenderLayer* parentLayer = &m_renderLayer == paintingInfo.rootLayer ? 0 : m_ renderLayer.parent(); | |
|
chrishtr
2014/11/18 18:36:18
This logic is new? Fixes a bug?
mstensho (USE GERRIT)
2014/11/19 19:23:01
Yes, it used to only check m_renderLayer.parent().
chrishtr
2014/11/19 19:34:51
I don't think it's good practice to change more th
mstensho (USE GERRIT)
2014/11/19 22:39:06
Done.
| |
| 395 | |
| 396 ClipRect clipRect(LayoutRect::infiniteRect()); | |
| 397 if (parentLayer) { | |
| 398 // Calculate the clip rectangle that the ancestors establish. | |
| 399 ClipRectsContext clipRectsContext(paintingInfo.rootLayer, (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : PaintingClipRects, IgnoreOver layScrollbarSize); | |
| 400 if (shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()) == I gnoreOverflowClip) | |
| 401 clipRectsContext.setIgnoreOverflowClip(); | |
| 402 clipRect = m_renderLayer.clipper().backgroundClipRect(clipRectsContext); | |
| 403 } | |
| 404 | |
| 405 RenderLayer* paginationLayer = m_renderLayer.enclosingPaginationLayer(); | |
| 406 LayerFragments fragments; | |
| 407 if (paginationLayer) { | |
| 408 ClipRectsCacheSlot cacheSlot = (paintFlags & PaintLayerUncachedClipRects ) ? UncachedClipRects : PaintingClipRects; | |
| 409 ShouldRespectOverflowClip respectOverflowClip = shouldRespectOverflowCli p(paintFlags, m_renderLayer.renderer()); | |
| 410 // Calculate the transformed bounding box in the current coordinate spac e, to figure out | |
| 411 // which fragmentainers (e.g. columns) we need to visit. | |
| 412 LayoutRect transformedExtent = RenderLayer::transparencyClipBox(&m_rende rLayer, paginationLayer, RenderLayer::PaintingTransparencyClipBox, RenderLayer:: RootOfTransparencyClipBox, paintingInfo.subPixelAccumulation, paintingInfo.paint Behavior); | |
| 413 paginationLayer->collectFragments(fragments, paintingInfo.rootLayer, pai ntingInfo.paintDirtyRect, cacheSlot, IgnoreOverlayScrollbarSize, respectOverflow Clip, 0, paintingInfo.subPixelAccumulation, &transformedExtent); | |
|
chrishtr
2014/11/18 18:36:18
Add a RenderLayer::collectFragments method that hi
mstensho (USE GERRIT)
2014/11/19 19:23:01
OK, this isn't very pretty. Need to think a little
chrishtr
2014/11/19 19:34:51
Let's put in a big FIXME to look closely at this c
mstensho (USE GERRIT)
2014/11/19 22:39:06
Done.
| |
| 414 } else { | |
| 415 // We don't need to collect any fragments in the regular way here. We ha ve already | |
| 416 // calculated a clip rectangle for the ancestry if it was needed, and cl ipping this | |
| 417 // layer is something that can be done further down the path, when the t ransform has | |
| 418 // been applied. | |
| 419 fragments.append(LayerFragment()); | |
| 420 } | |
| 421 | |
| 422 for (const auto& fragment: fragments) { | |
| 423 ClipRect clipRectForFragment(clipRect); | |
| 424 if (paginationLayer) { | |
| 425 clipRectForFragment.moveBy(fragment.paginationOffset); | |
| 426 clipRectForFragment.intersect(fragment.backgroundRect); | |
| 427 if (clipRectForFragment.isEmpty()) | |
| 428 continue; | |
| 429 } | |
| 430 OwnPtr<ClipRecorder> clipRecorder; | |
| 431 if (parentLayer && needsToClip(paintingInfo, clipRectForFragment)) { | |
|
mstensho (USE GERRIT)
2014/11/19 19:23:01
All the clipping stuff above for multicol should b
| |
| 432 clipRecorder = adoptPtr(new ClipRecorder(parentLayer->renderer(), co ntext, DisplayItem::ClipLayerParent, clipRectForFragment)); | |
| 433 if (clipRectForFragment.hasRadius()) | |
|
chrishtr
2014/11/18 18:36:18
You're going to need to rebase on top of my latest
mstensho (USE GERRIT)
2014/11/19 19:23:01
Done.
| |
| 434 applyRoundedRectClips(*parentLayer, paintingInfo, context, fragm ent.paginationOffset, paintFlags, *clipRecorder); | |
| 435 } | |
| 436 | |
| 437 paintFragmentByApplyingTransform(context, paintingInfo, paintFlags, frag ment.paginationOffset); | |
| 438 } | |
| 439 } | |
| 440 | |
| 441 void LayerPainter::paintFragmentByApplyingTransform(GraphicsContext* context, co nst LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags, const LayoutPoi nt& fragmentTranslation) | |
| 415 { | 442 { |
| 416 // This involves subtracting out the position of the layer in our current co ordinate space, but preserving | 443 // This involves subtracting out the position of the layer in our current co ordinate space, but preserving |
| 417 // the accumulated error for sub-pixel layout. | 444 // the accumulated error for sub-pixel layout. |
| 418 LayoutPoint delta; | 445 LayoutPoint delta; |
| 419 m_renderLayer.convertToLayerCoords(paintingInfo.rootLayer, delta); | 446 m_renderLayer.convertToLayerCoords(paintingInfo.rootLayer, delta); |
| 420 delta.moveBy(translationOffset); | 447 delta.moveBy(fragmentTranslation); |
| 421 TransformationMatrix transform(m_renderLayer.renderableTransform(paintingInf o.paintBehavior)); | 448 TransformationMatrix transform(m_renderLayer.renderableTransform(paintingInf o.paintBehavior)); |
| 422 IntPoint roundedDelta = roundedIntPoint(delta); | 449 IntPoint roundedDelta = roundedIntPoint(delta); |
| 423 transform.translateRight(roundedDelta.x(), roundedDelta.y()); | 450 transform.translateRight(roundedDelta.x(), roundedDelta.y()); |
| 424 LayoutSize adjustedSubPixelAccumulation = paintingInfo.subPixelAccumulation + (delta - roundedDelta); | 451 LayoutSize adjustedSubPixelAccumulation = paintingInfo.subPixelAccumulation + (delta - roundedDelta); |
| 425 | 452 |
| 426 // Apply the transform. | 453 // Apply the transform. |
| 427 GraphicsContextStateSaver stateSaver(*context, false); | 454 GraphicsContextStateSaver stateSaver(*context, false); |
| 428 if (!transform.isIdentity()) { | 455 if (!transform.isIdentity()) { |
| 429 stateSaver.save(); | 456 stateSaver.save(); |
| 430 context->concatCTM(transform.toAffineTransform()); | 457 context->concatCTM(transform.toAffineTransform()); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 { | 790 { |
| 764 if (!m_renderLayer.containsDirtyOverlayScrollbars()) | 791 if (!m_renderLayer.containsDirtyOverlayScrollbars()) |
| 765 return; | 792 return; |
| 766 | 793 |
| 767 LayerPaintingInfo paintingInfo(&m_renderLayer, enclosingIntRect(damageRect), paintBehavior, LayoutSize(), paintingRoot); | 794 LayerPaintingInfo paintingInfo(&m_renderLayer, enclosingIntRect(damageRect), paintBehavior, LayoutSize(), paintingRoot); |
| 768 paintLayer(context, paintingInfo, PaintLayerPaintingOverlayScrollbars); | 795 paintLayer(context, paintingInfo, PaintLayerPaintingOverlayScrollbars); |
| 769 | 796 |
| 770 m_renderLayer.setContainsDirtyOverlayScrollbars(false); | 797 m_renderLayer.setContainsDirtyOverlayScrollbars(false); |
| 771 } | 798 } |
| 772 | 799 |
| 773 void LayerPainter::paintTransformedLayerIntoFragments(GraphicsContext* context, const LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags) | |
| 774 { | |
| 775 LayerFragments enclosingPaginationFragments; | |
| 776 LayoutPoint offsetOfPaginationLayerFromRoot; | |
| 777 LayoutRect transformedExtent = RenderLayer::transparencyClipBox(&m_renderLay er, m_renderLayer.enclosingPaginationLayer(), RenderLayer::PaintingTransparencyC lipBox, RenderLayer::RootOfTransparencyClipBox, paintingInfo.subPixelAccumulatio n, paintingInfo.paintBehavior); | |
| 778 m_renderLayer.enclosingPaginationLayer()->collectFragments(enclosingPaginati onFragments, paintingInfo.rootLayer, paintingInfo.paintDirtyRect, | |
| 779 (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : Paintin gClipRects, IgnoreOverlayScrollbarSize, | |
| 780 shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()), &offset OfPaginationLayerFromRoot, paintingInfo.subPixelAccumulation, &transformedExtent ); | |
| 781 | |
| 782 for (size_t i = 0; i < enclosingPaginationFragments.size(); ++i) { | |
| 783 const LayerFragment& fragment = enclosingPaginationFragments.at(i); | |
| 784 | |
| 785 // Apply the page/column clip for this fragment, as well as any clips es tablished by layers in between us and | |
| 786 // the enclosing pagination layer. | |
| 787 LayoutRect clipRect = fragment.backgroundRect.rect(); | |
| 788 | |
| 789 // Now compute the clips within a given fragment | |
| 790 if (m_renderLayer.parent() != m_renderLayer.enclosingPaginationLayer()) { | |
| 791 m_renderLayer.enclosingPaginationLayer()->convertToLayerCoords(paint ingInfo.rootLayer, offsetOfPaginationLayerFromRoot); | |
| 792 | |
| 793 ClipRectsContext clipRectsContext(m_renderLayer.enclosingPaginationL ayer(), (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : Paintin gClipRects, IgnoreOverlayScrollbarSize); | |
| 794 if (shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()) == IgnoreOverflowClip) | |
| 795 clipRectsContext.setIgnoreOverflowClip(); | |
| 796 LayoutRect parentClipRect = m_renderLayer.clipper().backgroundClipRe ct(clipRectsContext).rect(); | |
| 797 parentClipRect.moveBy(fragment.paginationOffset + offsetOfPagination LayerFromRoot); | |
| 798 clipRect.intersect(parentClipRect); | |
| 799 } | |
| 800 | |
| 801 OwnPtr<ClipRecorder> clipRecorder; | |
| 802 if (needsToClip(paintingInfo, clipRect)) | |
| 803 clipRecorder = adoptPtr(new ClipRecorder(m_renderLayer.renderer(), c ontext, DisplayItem::ClipLayerFragmentParent, clipRect)); | |
| 804 | |
| 805 paintLayerByApplyingTransform(context, paintingInfo, paintFlags, fragmen t.paginationOffset); | |
| 806 } | |
| 807 } | |
| 808 | |
| 809 } // namespace blink | 800 } // namespace blink |
| OLD | NEW |