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

Unified Diff: third_party/WebKit/Source/core/paint/BoxPainter.cpp

Issue 2410513002: Plumb preferred raster scale for background images from Blink to cc layers. (Closed)
Patch Set: none Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
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..d0281a0234b0a7d95e32d8509aa9d324cbebd5f0 100644
--- a/third_party/WebKit/Source/core/paint/BoxPainter.cpp
+++ b/third_party/WebKit/Source/core/paint/BoxPainter.cpp
@@ -108,6 +108,39 @@ 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 (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)
+ return;
+ paintLayer->graphicsLayerBacking()->setPreferredRasterScale(rasterScale);
+ }
+}
+
+inline void clearPreferredRasterScale(const LayoutBox& obj) {
+ if (PaintLayer* paintLayer = obj.layer()) {
+ if (paintLayer->compositingState() != PaintsIntoOwnBacking)
+ return;
+ paintLayer->graphicsLayerBacking()->clearPreferredRasterScale();
+ }
+}
+
void BoxPainter::paintBoxDecorationBackgroundWithRect(
const PaintInfo& paintInfo,
const LayoutPoint& paintOffset,
@@ -144,6 +177,8 @@ void BoxPainter::paintBoxDecorationBackgroundWithRect(
DisplayItem::kBoxDecorationBackground))
return;
+ clearPreferredRasterScale(m_layoutBox);
+
DrawingRecorder recorder(
paintInfo.context, displayItemClient,
DisplayItem::kBoxDecorationBackground,
@@ -621,6 +656,8 @@ inline bool paintFastBottomLayer(const LayoutBoxModelObject& obj,
context.drawImageRRect(imageContext.image(), border, srcRect,
imageContext.compositeOp());
+ updatePreferredRasterScaleFromImage(srcRect, border.rect(), obj);
+
return true;
}

Powered by Google App Engine
This is Rietveld 408576698