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

Side by Side 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 unified diff | Download patch
OLDNEW
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 "core/paint/BoxPainter.h" 5 #include "core/paint/BoxPainter.h"
6 6
7 #include "core/HTMLNames.h" 7 #include "core/HTMLNames.h"
8 #include "core/frame/Settings.h" 8 #include "core/frame/Settings.h"
9 #include "core/html/HTMLFrameOwnerElement.h" 9 #include "core/html/HTMLFrameOwnerElement.h"
10 #include "core/layout/ImageQualityController.h" 10 #include "core/layout/ImageQualityController.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 namespace { 102 namespace {
103 103
104 bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance) { 104 bool bleedAvoidanceIsClipping(BackgroundBleedAvoidance bleedAvoidance) {
105 return bleedAvoidance == BackgroundBleedClipOnly || 105 return bleedAvoidance == BackgroundBleedClipOnly ||
106 bleedAvoidance == BackgroundBleedClipLayer; 106 bleedAvoidance == BackgroundBleedClipLayer;
107 } 107 }
108 108
109 } // anonymous namespace 109 } // anonymous namespace
110 110
111 // Sets a preferred composited raster scale for box with a background image,
112 // if possible.
113 // |srcRect| is the rect, in the space of the source image, to raster.
114 // |destRect| is the rect, in the local layout space of |obj|, to raster.
115 inline void updatePreferredRasterScaleFromImage(
116 const FloatRect srcRect,
117 const FloatRect& destRect,
118 const LayoutBoxModelObject& obj) {
119 if (!RuntimeEnabledFeatures::preferredImageRasterScaleEnabled())
120 return;
121 // Not yet implemented for SPv2.
122 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
123 return;
124 if (!obj.layer())
125 return;
126 if (destRect.width() == 0.0f || destRect.height() == 0.0f)
127 return;
128 float widthScale = srcRect.width() / destRect.width();
129 float heightScale = srcRect.height() / destRect.height();
130 float rasterScale = std::min(std::min(widthScale, heightScale), 10.0f);
131 if (PaintLayer* paintLayer = obj.layer()) {
132 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.
133 return;
134 paintLayer->graphicsLayerBacking()->setPreferredRasterScale(rasterScale);
135 }
136 }
137
138 inline void clearPreferredRasterScale(const LayoutBox& obj) {
139 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.
140 return;
141 if (PaintLayer* paintLayer = obj.layer()) {
142 if (paintLayer->compositingState() != PaintsIntoOwnBacking)
143 return;
144 paintLayer->graphicsLayerBacking()->clearPreferredRasterScale();
145 }
146 }
147
111 void BoxPainter::paintBoxDecorationBackgroundWithRect( 148 void BoxPainter::paintBoxDecorationBackgroundWithRect(
112 const PaintInfo& paintInfo, 149 const PaintInfo& paintInfo,
113 const LayoutPoint& paintOffset, 150 const LayoutPoint& paintOffset,
114 const LayoutRect& paintRect) { 151 const LayoutRect& paintRect) {
115 bool paintingOverflowContents = 152 bool paintingOverflowContents =
116 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( 153 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer(
117 &m_layoutBox, paintInfo); 154 &m_layoutBox, paintInfo);
118 const ComputedStyle& style = m_layoutBox.styleRef(); 155 const ComputedStyle& style = m_layoutBox.styleRef();
119 156
120 Optional<DisplayItemCacheSkipper> cacheSkipper; 157 Optional<DisplayItemCacheSkipper> cacheSkipper;
(...skipping 16 matching lines...) Expand all
137 paintingOverflowContents ? static_cast<const DisplayItemClient&>( 174 paintingOverflowContents ? static_cast<const DisplayItemClient&>(
138 *m_layoutBox.layer() 175 *m_layoutBox.layer()
139 ->compositedLayerMapping() 176 ->compositedLayerMapping()
140 ->scrollingContentsLayer()) 177 ->scrollingContentsLayer())
141 : m_layoutBox; 178 : m_layoutBox;
142 if (DrawingRecorder::useCachedDrawingIfPossible( 179 if (DrawingRecorder::useCachedDrawingIfPossible(
143 paintInfo.context, displayItemClient, 180 paintInfo.context, displayItemClient,
144 DisplayItem::kBoxDecorationBackground)) 181 DisplayItem::kBoxDecorationBackground))
145 return; 182 return;
146 183
184 clearPreferredRasterScale(m_layoutBox);
185
147 DrawingRecorder recorder( 186 DrawingRecorder recorder(
148 paintInfo.context, displayItemClient, 187 paintInfo.context, displayItemClient,
149 DisplayItem::kBoxDecorationBackground, 188 DisplayItem::kBoxDecorationBackground,
150 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset))); 189 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset)));
151 BoxDecorationData boxDecorationData(m_layoutBox); 190 BoxDecorationData boxDecorationData(m_layoutBox);
152 GraphicsContextStateSaver stateSaver(paintInfo.context, false); 191 GraphicsContextStateSaver stateSaver(paintInfo.context, false);
153 192
154 if (!paintingOverflowContents) { 193 if (!paintingOverflowContents) {
155 // FIXME: Should eventually give the theme control over whether the box 194 // FIXME: Should eventually give the theme control over whether the box
156 // shadow should paint, since controls could have custom shadows of their 195 // shadow should paint, since controls could have custom shadows of their
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize); 653 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize);
615 654
616 // The shadow may have been applied with the color fill. 655 // The shadow may have been applied with the color fill.
617 const ShadowContext shadowContext( 656 const ShadowContext shadowContext(
618 context, obj, info.shouldPaintShadow && !info.shouldPaintColor); 657 context, obj, info.shouldPaintShadow && !info.shouldPaintColor);
619 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", 658 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage",
620 "data", InspectorPaintImageEvent::data(obj, *info.image)); 659 "data", InspectorPaintImageEvent::data(obj, *info.image));
621 context.drawImageRRect(imageContext.image(), border, srcRect, 660 context.drawImageRRect(imageContext.image(), border, srcRect,
622 imageContext.compositeOp()); 661 imageContext.compositeOp());
623 662
663 updatePreferredRasterScaleFromImage(srcRect, border.rect(), obj);
664
624 return true; 665 return true;
625 } 666 }
626 667
627 } // anonymous namespace 668 } // anonymous namespace
628 669
629 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, 670 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj,
630 const PaintInfo& paintInfo, 671 const PaintInfo& paintInfo,
631 const Color& color, 672 const Color& color,
632 const FillLayer& bgLayer, 673 const FillLayer& bgLayer,
633 const LayoutRect& rect, 674 const LayoutRect& rect,
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( 1112 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy(
1072 const ComputedStyle& style, 1113 const ComputedStyle& style,
1073 const Document& document) { 1114 const Document& document) {
1074 return document.printing() && 1115 return document.printing() &&
1075 style.getPrintColorAdjust() == PrintColorAdjustEconomy && 1116 style.getPrintColorAdjust() == PrintColorAdjustEconomy &&
1076 (!document.settings() || 1117 (!document.settings() ||
1077 !document.settings()->shouldPrintBackgrounds()); 1118 !document.settings()->shouldPrintBackgrounds());
1078 } 1119 }
1079 1120
1080 } // namespace blink 1121 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698