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, &paintingInfo, Lay outPoint(), paintFlags)); | |
97 } | |
98 } | |
99 | |
100 paintLayerByApplyingTransform(context, paintingInfo, paintFlags); | |
101 | |
102 return; | 74 return; |
103 } | 75 } |
104 | 76 |
105 paintLayerContentsAndReflection(context, paintingInfo, paintFlags); | 77 paintLayerContentsAndReflection(context, paintingInfo, paintFlags); |
106 } | 78 } |
107 | 79 |
108 class TransparencyLayerHelper { | 80 class TransparencyLayerHelper { |
109 public: | 81 public: |
110 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) |
111 : m_transparencyLayerInProgress(false) | 83 : m_transparencyLayerInProgress(false) |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 // overflow and a subsequent fragment doesn't intersect with the border box of the layer | 336 // overflow and a subsequent fragment doesn't intersect with the border box of the layer |
365 // (i.e. only contains an overflow portion of the layer), intersection w ill fail. The reason | 337 // (i.e. only contains an overflow portion of the layer), intersection w ill fail. The reason |
366 // for this is that fragment.layerBounds is set to the border box, not t he bounding box, of | 338 // for this is that fragment.layerBounds is set to the border box, not t he bounding box, of |
367 // the layer. | 339 // the layer. |
368 if (m_renderLayer.intersectsDamageRect(fragment.layerBounds, fragment.ba ckgroundRect.rect(), localPaintingInfo.rootLayer, &newOffsetFromRoot)) | 340 if (m_renderLayer.intersectsDamageRect(fragment.layerBounds, fragment.ba ckgroundRect.rect(), localPaintingInfo.rootLayer, &newOffsetFromRoot)) |
369 return true; | 341 return true; |
370 } | 342 } |
371 return false; | 343 return false; |
372 } | 344 } |
373 | 345 |
374 void LayerPainter::paintLayerByApplyingTransform(GraphicsContext* context, const LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags, const LayoutPoint& translationOffset) | 346 void LayerPainter::paintLayerWithTransform(GraphicsContext* context, const Layer PaintingInfo& paintingInfo, PaintLayerFlags paintFlags) |
347 { | |
348 TransformationMatrix layerTransform = m_renderLayer.renderableTransform(pain tingInfo.paintBehavior); | |
349 // If the transform can't be inverted, then don't paint anything. | |
350 if (!layerTransform.isInvertible()) | |
351 return; | |
352 | |
353 // FIXME: We should make sure that we don't walk past paintingInfo.rootLayer here. | |
354 // m_renderLayer may be the "root", and then we should avoid looking at its parent. | |
355 RenderLayer* parentLayer = m_renderLayer.parent(); | |
356 | |
357 ClipRect clipRect(LayoutRect::infiniteRect()); | |
chrishtr
2014/11/20 01:46:31
What about intersecting with paintingInfo.paintDir
mstensho (USE GERRIT)
2014/11/20 09:37:55
Can't do it this early for multicol. The clip rect
| |
358 if (parentLayer) { | |
359 // Calculate the clip rectangle that the ancestors establish. | |
360 ClipRectsContext clipRectsContext(paintingInfo.rootLayer, (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : PaintingClipRects, IgnoreOver layScrollbarSize); | |
361 if (shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()) == I gnoreOverflowClip) | |
362 clipRectsContext.setIgnoreOverflowClip(); | |
363 clipRect = m_renderLayer.clipper().backgroundClipRect(clipRectsContext); | |
364 } | |
365 | |
366 RenderLayer* paginationLayer = m_renderLayer.enclosingPaginationLayer(); | |
367 LayerFragments fragments; | |
368 if (paginationLayer) { | |
369 // FIXME: This is a mess. Look closely at this code and the code in Rend erLayer and fix any | |
370 // issues in it & refactor to make it obvious from code structure what i t does and that it's | |
371 // correct. | |
372 ClipRectsCacheSlot cacheSlot = (paintFlags & PaintLayerUncachedClipRects ) ? UncachedClipRects : PaintingClipRects; | |
373 ShouldRespectOverflowClip respectOverflowClip = shouldRespectOverflowCli p(paintFlags, m_renderLayer.renderer()); | |
374 // Calculate the transformed bounding box in the current coordinate spac e, to figure out | |
375 // which fragmentainers (e.g. columns) we need to visit. | |
376 LayoutRect transformedExtent = RenderLayer::transparencyClipBox(&m_rende rLayer, paginationLayer, RenderLayer::PaintingTransparencyClipBox, RenderLayer:: RootOfTransparencyClipBox, paintingInfo.subPixelAccumulation, paintingInfo.paint Behavior); | |
377 // FIXME: we don't check if paginationLayer is within paintingInfo.rootL ayer here. | |
378 paginationLayer->collectFragments(fragments, paintingInfo.rootLayer, pai ntingInfo.paintDirtyRect, cacheSlot, IgnoreOverlayScrollbarSize, respectOverflow Clip, 0, paintingInfo.subPixelAccumulation, &transformedExtent); | |
379 } else { | |
380 // We don't need to collect any fragments in the regular way here. We ha ve already | |
381 // calculated a clip rectangle for the ancestry if it was needed, and cl ipping this | |
382 // layer is something that can be done further down the path, when the t ransform has | |
383 // been applied. | |
384 fragments.append(LayerFragment()); | |
385 } | |
386 | |
387 for (const auto& fragment: fragments) { | |
388 OwnPtr<ClipRecorder> clipRecorder; | |
389 if (parentLayer) { | |
390 ClipRect clipRectForFragment(clipRect); | |
391 if (paginationLayer) { | |
392 clipRectForFragment.moveBy(fragment.paginationOffset); | |
chrishtr
2014/11/20 01:46:31
Ideally, you would adjust for paginationOffset ins
mstensho (USE GERRIT)
2014/11/20 09:37:55
Before creating a ClipRecorder, we call needsToCli
chrishtr
2014/11/20 18:18:19
Yes. Probably worth a FIXME.
mstensho (USE GERRIT)
2014/11/20 20:20:46
Done.
| |
393 clipRectForFragment.intersect(fragment.backgroundRect); | |
394 if (clipRectForFragment.isEmpty()) | |
395 continue; | |
396 } | |
397 if (needsToClip(paintingInfo, clipRectForFragment)) | |
398 clipRecorder = adoptPtr(new ClipRecorder(parentLayer->renderer() , context, DisplayItem::ClipLayerParent, clipRectForFragment, &paintingInfo, fra gment.paginationOffset, paintFlags)); | |
399 } | |
400 | |
401 paintFragmentByApplyingTransform(context, paintingInfo, paintFlags, frag ment.paginationOffset); | |
402 } | |
403 } | |
404 | |
405 void LayerPainter::paintFragmentByApplyingTransform(GraphicsContext* context, co nst LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags, const LayoutPoi nt& fragmentTranslation) | |
375 { | 406 { |
376 // This involves subtracting out the position of the layer in our current co ordinate space, but preserving | 407 // This involves subtracting out the position of the layer in our current co ordinate space, but preserving |
377 // the accumulated error for sub-pixel layout. | 408 // the accumulated error for sub-pixel layout. |
378 LayoutPoint delta; | 409 LayoutPoint delta; |
379 m_renderLayer.convertToLayerCoords(paintingInfo.rootLayer, delta); | 410 m_renderLayer.convertToLayerCoords(paintingInfo.rootLayer, delta); |
380 delta.moveBy(translationOffset); | 411 delta.moveBy(fragmentTranslation); |
381 TransformationMatrix transform(m_renderLayer.renderableTransform(paintingInf o.paintBehavior)); | 412 TransformationMatrix transform(m_renderLayer.renderableTransform(paintingInf o.paintBehavior)); |
382 IntPoint roundedDelta = roundedIntPoint(delta); | 413 IntPoint roundedDelta = roundedIntPoint(delta); |
383 transform.translateRight(roundedDelta.x(), roundedDelta.y()); | 414 transform.translateRight(roundedDelta.x(), roundedDelta.y()); |
384 LayoutSize adjustedSubPixelAccumulation = paintingInfo.subPixelAccumulation + (delta - roundedDelta); | 415 LayoutSize adjustedSubPixelAccumulation = paintingInfo.subPixelAccumulation + (delta - roundedDelta); |
385 | 416 |
386 // Apply the transform. | 417 // Apply the transform. |
387 GraphicsContextStateSaver stateSaver(*context, false); | 418 GraphicsContextStateSaver stateSaver(*context, false); |
388 if (!transform.isIdentity()) { | 419 if (!transform.isIdentity()) { |
389 stateSaver.save(); | 420 stateSaver.save(); |
390 context->concatCTM(transform.toAffineTransform()); | 421 context->concatCTM(transform.toAffineTransform()); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 { | 748 { |
718 if (!m_renderLayer.containsDirtyOverlayScrollbars()) | 749 if (!m_renderLayer.containsDirtyOverlayScrollbars()) |
719 return; | 750 return; |
720 | 751 |
721 LayerPaintingInfo paintingInfo(&m_renderLayer, enclosingIntRect(damageRect), paintBehavior, LayoutSize(), paintingRoot); | 752 LayerPaintingInfo paintingInfo(&m_renderLayer, enclosingIntRect(damageRect), paintBehavior, LayoutSize(), paintingRoot); |
722 paintLayer(context, paintingInfo, PaintLayerPaintingOverlayScrollbars); | 753 paintLayer(context, paintingInfo, PaintLayerPaintingOverlayScrollbars); |
723 | 754 |
724 m_renderLayer.setContainsDirtyOverlayScrollbars(false); | 755 m_renderLayer.setContainsDirtyOverlayScrollbars(false); |
725 } | 756 } |
726 | 757 |
727 void LayerPainter::paintTransformedLayerIntoFragments(GraphicsContext* context, const LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags) | |
728 { | |
729 LayerFragments enclosingPaginationFragments; | |
730 LayoutPoint offsetOfPaginationLayerFromRoot; | |
731 LayoutRect transformedExtent = RenderLayer::transparencyClipBox(&m_renderLay er, m_renderLayer.enclosingPaginationLayer(), RenderLayer::PaintingTransparencyC lipBox, RenderLayer::RootOfTransparencyClipBox, paintingInfo.subPixelAccumulatio n, paintingInfo.paintBehavior); | |
732 m_renderLayer.enclosingPaginationLayer()->collectFragments(enclosingPaginati onFragments, paintingInfo.rootLayer, paintingInfo.paintDirtyRect, | |
733 (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : Paintin gClipRects, IgnoreOverlayScrollbarSize, | |
734 shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()), &offset OfPaginationLayerFromRoot, paintingInfo.subPixelAccumulation, &transformedExtent ); | |
735 | |
736 for (size_t i = 0; i < enclosingPaginationFragments.size(); ++i) { | |
737 const LayerFragment& fragment = enclosingPaginationFragments.at(i); | |
738 | |
739 // Apply the page/column clip for this fragment, as well as any clips es tablished by layers in between us and | |
740 // the enclosing pagination layer. | |
741 LayoutRect clipRect = fragment.backgroundRect.rect(); | |
742 | |
743 // Now compute the clips within a given fragment | |
744 if (m_renderLayer.parent() != m_renderLayer.enclosingPaginationLayer()) { | |
745 m_renderLayer.enclosingPaginationLayer()->convertToLayerCoords(paint ingInfo.rootLayer, offsetOfPaginationLayerFromRoot); | |
746 | |
747 ClipRectsContext clipRectsContext(m_renderLayer.enclosingPaginationL ayer(), (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : Paintin gClipRects, IgnoreOverlayScrollbarSize); | |
748 if (shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()) == IgnoreOverflowClip) | |
749 clipRectsContext.setIgnoreOverflowClip(); | |
750 LayoutRect parentClipRect = m_renderLayer.clipper().backgroundClipRe ct(clipRectsContext).rect(); | |
751 parentClipRect.moveBy(fragment.paginationOffset + offsetOfPagination LayerFromRoot); | |
752 clipRect.intersect(parentClipRect); | |
753 } | |
754 | |
755 OwnPtr<ClipRecorder> clipRecorder; | |
756 if (needsToClip(paintingInfo, clipRect)) | |
757 clipRecorder = adoptPtr(new ClipRecorder(m_renderLayer.renderer(), c ontext, DisplayItem::ClipLayerFragmentParent, clipRect, &paintingInfo, LayoutPoi nt(), paintFlags)); | |
758 | |
759 paintLayerByApplyingTransform(context, paintingInfo, paintFlags, fragmen t.paginationOffset); | |
760 } | |
761 } | |
762 | |
763 } // namespace blink | 758 } // namespace blink |
OLD | NEW |