Chromium Code Reviews| Index: third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| diff --git a/third_party/WebKit/Source/core/paint/BoxPainter.cpp b/third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| index 213c528534aa3e0ccd2a69b0cd82f42f829f7be9..839a2654ab9f3f0c5db25ae8c5bd44d3302d1586 100644 |
| --- a/third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| +++ b/third_party/WebKit/Source/core/paint/BoxPainter.cpp |
| @@ -108,6 +108,43 @@ bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance) { |
| } // anonymous namespace |
| +// Sets a preferred composited raster scale for box with a background image, |
| +// if possible. |
| +// |srcRect| is the rect, in the space of the source image, to raster. |
| +// |destRect| is the rect, in the local layout space of |obj|, to raster. |
| +inline void updatePreferredRasterScaleFromImage( |
| + const FloatRect srcRect, |
| + const FloatRect& destRect, |
| + const LayoutBoxModelObject& obj) { |
| + if (!RuntimeEnabledFeatures::preferredImageRasterScaleEnabled()) |
| + return; |
| + // Not yet implemented for SPv2. |
| + if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| + return; |
| + if (!obj.layer()) |
| + return; |
| + if (destRect.width() == 0.0f || destRect.height() == 0.0f) |
| + return; |
| + float widthScale = srcRect.width() / destRect.width(); |
| + float heightScale = srcRect.height() / destRect.height(); |
| + float rasterScale = std::min(std::min(widthScale, heightScale), 10.0f); |
| + if (PaintLayer* paintLayer = obj.layer()) { |
| + if (paintLayer->compositingState() != PaintsIntoOwnBacking) |
|
Stephen Chennney
2016/10/17 14:31:30
Move the check for paints into own backing up to w
chrishtr
2016/10/19 03:51:36
Removed the early-out above, since it's redundant.
|
| + return; |
| + paintLayer->graphicsLayerBacking()->setPreferredRasterScale(rasterScale); |
| + } |
| +} |
| + |
| +inline void clearPreferredRasterScale(const LayoutBox& obj) { |
| + if (!obj.layer()) |
|
Stephen Chennney
2016/10/17 14:31:30
You don't need this. You check it again immediatel
chrishtr
2016/10/19 03:51:36
Good point, removed.
|
| + return; |
| + if (PaintLayer* paintLayer = obj.layer()) { |
| + if (paintLayer->compositingState() != PaintsIntoOwnBacking) |
| + return; |
| + paintLayer->graphicsLayerBacking()->clearPreferredRasterScale(); |
| + } |
| +} |
| + |
| void BoxPainter::paintBoxDecorationBackgroundWithRect( |
| const PaintInfo& paintInfo, |
| const LayoutPoint& paintOffset, |
| @@ -144,6 +181,8 @@ void BoxPainter::paintBoxDecorationBackgroundWithRect( |
| DisplayItem::kBoxDecorationBackground)) |
| return; |
| + clearPreferredRasterScale(m_layoutBox); |
| + |
| DrawingRecorder recorder( |
| paintInfo.context, displayItemClient, |
| DisplayItem::kBoxDecorationBackground, |
| @@ -621,6 +660,8 @@ inline bool paintFastBottomLayer(const LayoutBoxModelObject& obj, |
| context.drawImageRRect(imageContext.image(), border, srcRect, |
| imageContext.compositeOp()); |
| + updatePreferredRasterScaleFromImage(srcRect, border.rect(), obj); |
| + |
| return true; |
| } |