| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 TransformationMatrix layerTransform = m_renderLayer.renderableTransform(
paintingInfo.paintBehavior); |
| 74 // If the transform can't be inverted, then don't paint anything. | 74 // If the transform can't be inverted, then don't paint anything. |
| 75 if (!layerTransform.isInvertible()) | 75 if (!layerTransform.isInvertible()) |
| 76 return; | 76 return; |
| 77 | 77 |
| 78 // If we have a transparency layer enclosing us and we are the root of a
transform, then we need to establish the transparency | |
| 79 // layer from the parent now, assuming there is a parent | |
| 80 if (paintFlags & PaintLayerHaveTransparency) { | |
| 81 // FIXME: can we get rid of this? It would mean transparency starts
after clipping in these cases. | |
| 82 if (m_renderLayer.parent()) | |
| 83 LayerPainter(*m_renderLayer.parent()).beginTransparencyLayers(co
ntext, paintingInfo.rootLayer, paintingInfo.paintDirtyRect, paintingInfo.subPixe
lAccumulation, paintingInfo.paintBehavior); | |
| 84 else | |
| 85 beginTransparencyLayers(context, paintingInfo.rootLayer, paintin
gInfo.paintDirtyRect, paintingInfo.subPixelAccumulation, paintingInfo.paintBehav
ior); | |
| 86 } | |
| 87 | |
| 88 if (m_renderLayer.enclosingPaginationLayer()) { | 78 if (m_renderLayer.enclosingPaginationLayer()) { |
| 79 // FIXME: unify this one-off path with the code below. |
| 89 paintTransformedLayerIntoFragments(context, paintingInfo, paintFlags
); | 80 paintTransformedLayerIntoFragments(context, paintingInfo, paintFlags
); |
| 90 return; | 81 return; |
| 91 } | 82 } |
| 92 | 83 |
| 93 // Make sure the parent's clip rects have been calculated. | 84 // Make sure the parent's clip rects have been calculated. |
| 94 ClipRect clipRect = paintingInfo.paintDirtyRect; | 85 ClipRect clipRect = paintingInfo.paintDirtyRect; |
| 95 | 86 |
| 96 OwnPtr<ClipRecorder> clipRecorder; | 87 OwnPtr<ClipRecorder> clipRecorder; |
| 97 if (m_renderLayer.parent()) { | 88 if (m_renderLayer.parent()) { |
| 98 ClipRectsContext clipRectsContext(paintingInfo.rootLayer, (paintFlag
s & PaintLayerUncachedClipRects) ? UncachedClipRects : PaintingClipRects, Ignore
OverlayScrollbarSize); | 89 ClipRectsContext clipRectsContext(paintingInfo.rootLayer, (paintFlag
s & PaintLayerUncachedClipRects) ? UncachedClipRects : PaintingClipRects, Ignore
OverlayScrollbarSize); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 109 } | 100 } |
| 110 | 101 |
| 111 paintLayerByApplyingTransform(context, paintingInfo, paintFlags); | 102 paintLayerByApplyingTransform(context, paintingInfo, paintFlags); |
| 112 | 103 |
| 113 return; | 104 return; |
| 114 } | 105 } |
| 115 | 106 |
| 116 paintLayerContentsAndReflection(context, paintingInfo, paintFlags); | 107 paintLayerContentsAndReflection(context, paintingInfo, paintFlags); |
| 117 } | 108 } |
| 118 | 109 |
| 119 bool LayerPainter::shouldCreateTransparencyLayerForBlendMode() | 110 class TransparencyLayerHelper { |
| 120 { | 111 public: |
| 121 return !m_renderLayer.renderer()->isDocumentElement() && m_renderLayer.stack
ingNode()->isStackingContext() && m_renderLayer.hasNonIsolatedDescendantWithBlen
dMode(); | 112 TransparencyLayerHelper(GraphicsContext* context, RenderLayer& renderLayer,
const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize
& subPixelAccumulation, PaintBehavior paintBehavior) |
| 122 } | 113 : m_transparencyLayerInProgress(false) |
| 114 , m_context(context) |
| 115 { |
| 116 // Blending operations must be performed only with the nearest ancestor
stacking context. |
| 117 // Note that there is no need to create a transparency layer if we're pa
inting the root. |
| 118 // FIXME: this should be unified further into RenderLayer::paintsWithTra
nsparency(). |
| 119 bool shouldUseTransparencyLayerForBlendMode = !renderLayer.renderer()->i
sDocumentElement() && renderLayer.stackingNode()->isStackingContext() && renderL
ayer.hasNonIsolatedDescendantWithBlendMode(); |
| 120 if (!shouldUseTransparencyLayerForBlendMode && !renderLayer.paintsWithTr
ansparency(paintBehavior)) |
| 121 return; |
| 123 | 122 |
| 124 void LayerPainter::beginTransparencyLayers(GraphicsContext* context, const Rende
rLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize& subPixelA
ccumulation, PaintBehavior paintBehavior) | 123 context->save(); |
| 125 { | 124 LayoutRect clipRect = renderLayer.paintingExtent(rootLayer, paintDirtyRe
ct, subPixelAccumulation, paintBehavior); |
| 126 // Blending operations must be performed only with the nearest ancestor stac
king context. | 125 context->clip(clipRect); |
| 127 // Note that there is no need to create a transparency layer if we're painti
ng the root. | |
| 128 // FIXME: this should be unified further into RenderLayer::paintsWithTranspa
rency(). | |
| 129 if (!m_renderLayer.paintsWithTransparency(paintBehavior) && !shouldCreateTra
nsparencyLayerForBlendMode()) | |
| 130 return; | |
| 131 | 126 |
| 132 // FIXME: refactor to remove this. | 127 if (renderLayer.renderer()->hasBlendMode()) |
| 133 if (m_renderLayer.usedTransparency()) | 128 context->setCompositeOperation(context->compositeOperation(), render
Layer.renderer()->style()->blendMode()); |
| 134 return; | |
| 135 | 129 |
| 136 m_renderLayer.setUsedTransparency(true); | 130 context->beginTransparencyLayer(renderLayer.renderer()->opacity()); |
| 137 context->save(); | |
| 138 LayoutRect clipRect = m_renderLayer.paintingExtent(rootLayer, paintDirtyRect
, subPixelAccumulation, paintBehavior); | |
| 139 context->clip(clipRect); | |
| 140 | 131 |
| 141 if (m_renderLayer.renderer()->hasBlendMode()) | 132 if (renderLayer.renderer()->hasBlendMode()) |
| 142 context->setCompositeOperation(context->compositeOperation(), m_renderLa
yer.renderer()->style()->blendMode()); | 133 context->setCompositeOperation(context->compositeOperation(), WebBle
ndModeNormal); |
| 134 #ifdef REVEAL_TRANSPARENCY_LAYERS |
| 135 context->fillRect(clipRect, Color(0.0f, 0.0f, 0.5f, 0.2f)); |
| 136 #endif |
| 137 m_transparencyLayerInProgress = true; |
| 138 } |
| 143 | 139 |
| 144 context->beginTransparencyLayer(m_renderLayer.renderer()->opacity()); | 140 ~TransparencyLayerHelper() |
| 145 | 141 { |
| 146 if (m_renderLayer.renderer()->hasBlendMode()) | 142 if (m_transparencyLayerInProgress) { |
| 147 context->setCompositeOperation(context->compositeOperation(), WebBlendMo
deNormal); | 143 m_context->endLayer(); |
| 148 #ifdef REVEAL_TRANSPARENCY_LAYERS | 144 m_context->restore(); |
| 149 context->fillRect(clipRect, Color(0.0f, 0.0f, 0.5f, 0.2f)); | 145 } |
| 150 #endif | 146 } |
| 151 } | 147 private: |
| 148 bool m_transparencyLayerInProgress; |
| 149 GraphicsContext* m_context; |
| 150 }; |
| 152 | 151 |
| 153 void LayerPainter::paintLayerContentsAndReflection(GraphicsContext* context, con
st LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags) | 152 void LayerPainter::paintLayerContentsAndReflection(GraphicsContext* context, con
st LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags) |
| 154 { | 153 { |
| 155 ASSERT(m_renderLayer.isSelfPaintingLayer() || m_renderLayer.hasSelfPaintingL
ayerDescendant()); | 154 ASSERT(m_renderLayer.isSelfPaintingLayer() || m_renderLayer.hasSelfPaintingL
ayerDescendant()); |
| 156 | 155 |
| 157 PaintLayerFlags localPaintFlags = paintFlags & ~(PaintLayerAppliedTransform)
; | 156 PaintLayerFlags localPaintFlags = paintFlags & ~(PaintLayerAppliedTransform)
; |
| 158 | 157 |
| 159 // Paint the reflection first if we have one. | 158 // Paint the reflection first if we have one. |
| 160 if (m_renderLayer.reflectionInfo()) | 159 if (m_renderLayer.reflectionInfo()) |
| 161 m_renderLayer.reflectionInfo()->paint(context, paintingInfo, localPaintF
lags | PaintLayerPaintingReflection); | 160 m_renderLayer.reflectionInfo()->paint(context, paintingInfo, localPaintF
lags | PaintLayerPaintingReflection); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 262 |
| 264 LayoutPoint offsetFromRoot; | 263 LayoutPoint offsetFromRoot; |
| 265 m_renderLayer.convertToLayerCoords(paintingInfo.rootLayer, offsetFromRoot); | 264 m_renderLayer.convertToLayerCoords(paintingInfo.rootLayer, offsetFromRoot); |
| 266 | 265 |
| 267 if (m_renderLayer.compositingState() == PaintsIntoOwnBacking) | 266 if (m_renderLayer.compositingState() == PaintsIntoOwnBacking) |
| 268 offsetFromRoot.move(m_renderLayer.subpixelAccumulation()); | 267 offsetFromRoot.move(m_renderLayer.subpixelAccumulation()); |
| 269 | 268 |
| 270 LayoutRect rootRelativeBounds; | 269 LayoutRect rootRelativeBounds; |
| 271 bool rootRelativeBoundsComputed = false; | 270 bool rootRelativeBoundsComputed = false; |
| 272 | 271 |
| 272 // These helpers output clip and transparency layers using a RAII pattern. S
tack-allocated-varibles are destructed in the reverse order of construction, |
| 273 // so they are nested properly. |
| 273 ClipPathHelper clipPathHelper(context, m_renderLayer, paintingInfo, rootRela
tiveBounds, rootRelativeBoundsComputed, offsetFromRoot, paintFlags); | 274 ClipPathHelper clipPathHelper(context, m_renderLayer, paintingInfo, rootRela
tiveBounds, rootRelativeBoundsComputed, offsetFromRoot, paintFlags); |
| 274 | 275 TransparencyLayerHelper transparencyLayerHelper(context, m_renderLayer, pain
tingInfo.rootLayer, paintingInfo.paintDirtyRect, paintingInfo.subPixelAccumulati
on, paintingInfo.paintBehavior); |
| 275 beginTransparencyLayers(context, paintingInfo.rootLayer, paintingInfo.paintD
irtyRect, paintingInfo.subPixelAccumulation, paintingInfo.paintBehavior); | |
| 276 | 276 |
| 277 LayerPaintingInfo localPaintingInfo(paintingInfo); | 277 LayerPaintingInfo localPaintingInfo(paintingInfo); |
| 278 | 278 |
| 279 LayerFragments layerFragments; | 279 LayerFragments layerFragments; |
| 280 if (shouldPaintContent || shouldPaintOutline || isPaintingOverlayScrollbars)
{ | 280 if (shouldPaintContent || shouldPaintOutline || isPaintingOverlayScrollbars)
{ |
| 281 // Collect the fragments. This will compute the clip rectangles and pain
t offsets for each layer fragment. | 281 // Collect the fragments. This will compute the clip rectangles and pain
t offsets for each layer fragment. |
| 282 m_renderLayer.collectFragments(layerFragments, localPaintingInfo.rootLay
er, localPaintingInfo.paintDirtyRect, | 282 m_renderLayer.collectFragments(layerFragments, localPaintingInfo.rootLay
er, localPaintingInfo.paintDirtyRect, |
| 283 (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : Pai
ntingClipRects, IgnoreOverlayScrollbarSize, | 283 (paintFlags & PaintLayerUncachedClipRects) ? UncachedClipRects : Pai
ntingClipRects, IgnoreOverlayScrollbarSize, |
| 284 shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()), &of
fsetFromRoot, localPaintingInfo.subPixelAccumulation); | 284 shouldRespectOverflowClip(paintFlags, m_renderLayer.renderer()), &of
fsetFromRoot, localPaintingInfo.subPixelAccumulation); |
| 285 if (shouldPaintContent) | 285 if (shouldPaintContent) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 } | 327 } |
| 328 | 328 |
| 329 if (shouldPaintOutline) | 329 if (shouldPaintOutline) |
| 330 paintOutlineForFragments(layerFragments, context, localPaintingInfo,
paintBehavior, paintingRootForRenderer, paintFlags); | 330 paintOutlineForFragments(layerFragments, context, localPaintingInfo,
paintBehavior, paintingRootForRenderer, paintFlags); |
| 331 | 331 |
| 332 if (shouldPaintNormalFlowAndPosZOrderLists) | 332 if (shouldPaintNormalFlowAndPosZOrderLists) |
| 333 paintChildren(NormalFlowChildren | PositiveZOrderChildren, context,
paintingInfo, paintFlags); | 333 paintChildren(NormalFlowChildren | PositiveZOrderChildren, context,
paintingInfo, paintFlags); |
| 334 | 334 |
| 335 if (shouldPaintOverlayScrollbars) | 335 if (shouldPaintOverlayScrollbars) |
| 336 paintOverflowControlsForFragments(layerFragments, context, localPain
tingInfo, paintFlags); | 336 paintOverflowControlsForFragments(layerFragments, context, localPain
tingInfo, paintFlags); |
| 337 } // Filter painter block | 337 } // FilterPainter block |
| 338 | 338 |
| 339 bool shouldPaintMask = (paintFlags & PaintLayerPaintingCompositingMaskPhase)
&& shouldPaintContent && m_renderLayer.renderer()->hasMask() && !selectionOnly; | 339 bool shouldPaintMask = (paintFlags & PaintLayerPaintingCompositingMaskPhase)
&& shouldPaintContent && m_renderLayer.renderer()->hasMask() && !selectionOnly; |
| 340 bool shouldPaintClippingMask = (paintFlags & PaintLayerPaintingChildClipping
MaskPhase) && shouldPaintContent && !selectionOnly; | 340 bool shouldPaintClippingMask = (paintFlags & PaintLayerPaintingChildClipping
MaskPhase) && shouldPaintContent && !selectionOnly; |
| 341 | 341 |
| 342 if (shouldPaintMask) | 342 if (shouldPaintMask) |
| 343 paintMaskForFragments(layerFragments, context, localPaintingInfo, painti
ngRootForRenderer, paintFlags); | 343 paintMaskForFragments(layerFragments, context, localPaintingInfo, painti
ngRootForRenderer, paintFlags); |
| 344 | |
| 345 if (shouldPaintClippingMask) { | 344 if (shouldPaintClippingMask) { |
| 346 // Paint the border radius mask for the fragments. | 345 // Paint the border radius mask for the fragments. |
| 347 paintChildClippingMaskForFragments(layerFragments, context, localPaintin
gInfo, paintingRootForRenderer, paintFlags); | 346 paintChildClippingMaskForFragments(layerFragments, context, localPaintin
gInfo, paintingRootForRenderer, paintFlags); |
| 348 } | 347 } |
| 349 | |
| 350 // End our transparency layer | |
| 351 if (((paintFlags & PaintLayerHaveTransparency) || shouldCreateTransparencyLa
yerForBlendMode()) && m_renderLayer.usedTransparency() | |
| 352 && !(m_renderLayer.reflectionInfo() && m_renderLayer.reflectionInfo()->i
sPaintingInsideReflection())) { | |
| 353 context->endLayer(); | |
| 354 context->restore(); | |
| 355 m_renderLayer.setUsedTransparency(false); | |
| 356 } | |
| 357 } | 348 } |
| 358 | 349 |
| 359 static bool inContainingBlockChain(RenderLayer* startLayer, RenderLayer* endLaye
r) | 350 static bool inContainingBlockChain(RenderLayer* startLayer, RenderLayer* endLaye
r) |
| 360 { | 351 { |
| 361 if (startLayer == endLayer) | 352 if (startLayer == endLayer) |
| 362 return true; | 353 return true; |
| 363 | 354 |
| 364 RenderView* view = startLayer->renderer()->view(); | 355 RenderView* view = startLayer->renderer()->view(); |
| 365 for (RenderBlock* currentBlock = startLayer->renderer()->containingBlock();
currentBlock && currentBlock != view; currentBlock = currentBlock->containingBlo
ck()) { | 356 for (RenderBlock* currentBlock = startLayer->renderer()->containingBlock();
currentBlock && currentBlock != view; currentBlock = currentBlock->containingBlo
ck()) { |
| 366 if (currentBlock->layer() == endLayer) | 357 if (currentBlock->layer() == endLayer) |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 801 |
| 811 OwnPtr<ClipRecorder> clipRecorder; | 802 OwnPtr<ClipRecorder> clipRecorder; |
| 812 if (needsToClip(paintingInfo, clipRect)) | 803 if (needsToClip(paintingInfo, clipRect)) |
| 813 clipRecorder = adoptPtr(new ClipRecorder(m_renderLayer.renderer(), c
ontext, DisplayItem::ClipLayerFragmentParent, clipRect)); | 804 clipRecorder = adoptPtr(new ClipRecorder(m_renderLayer.renderer(), c
ontext, DisplayItem::ClipLayerFragmentParent, clipRect)); |
| 814 | 805 |
| 815 paintLayerByApplyingTransform(context, paintingInfo, paintFlags, fragmen
t.paginationOffset); | 806 paintLayerByApplyingTransform(context, paintingInfo, paintFlags, fragmen
t.paginationOffset); |
| 816 } | 807 } |
| 817 } | 808 } |
| 818 | 809 |
| 819 } // namespace blink | 810 } // namespace blink |
| OLD | NEW |