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 "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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, | 111 // Sets a preferred composited raster scale for box with a background image, |
112 // if possible. | 112 // if possible. |
113 // |srcRect| is the rect, in the space of the source image, to raster. | 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. | 114 // |destRect| is the rect, in the local layout space of |obj|, to raster. |
115 inline void updatePreferredRasterScaleFromImage( | 115 inline void updatePreferredRasterBoundsFromImage( |
116 const FloatRect srcRect, | 116 const FloatRect srcRect, |
117 const FloatRect& destRect, | 117 const FloatRect& destRect, |
118 const LayoutBoxModelObject& obj) { | 118 const LayoutBoxModelObject& obj) { |
119 if (!RuntimeEnabledFeatures::preferredImageRasterScaleEnabled()) | 119 if (!RuntimeEnabledFeatures::preferredImageRasterBoundsEnabled()) |
120 return; | 120 return; |
121 // Not yet implemented for SPv2. | 121 // Not yet implemented for SPv2. |
122 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 122 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
123 return; | 123 return; |
124 if (destRect.width() == 0.0f || destRect.height() == 0.0f) | 124 if (destRect.width() == 0.0f || destRect.height() == 0.0f) |
125 return; | 125 return; |
126 float widthScale = srcRect.width() / destRect.width(); | |
127 float heightScale = srcRect.height() / destRect.height(); | |
128 float rasterScale = std::min(std::min(widthScale, heightScale), 10.0f); | |
129 if (PaintLayer* paintLayer = obj.layer()) { | 126 if (PaintLayer* paintLayer = obj.layer()) { |
130 if (paintLayer->compositingState() != PaintsIntoOwnBacking) | 127 if (paintLayer->compositingState() != PaintsIntoOwnBacking) |
131 return; | 128 return; |
132 paintLayer->graphicsLayerBacking()->setPreferredRasterScale(rasterScale); | 129 // TODO(chrishtr): ensure that this rounding does not ever lose any |
| 130 // precision. |
| 131 paintLayer->graphicsLayerBacking()->setPreferredRasterBounds( |
| 132 roundedIntSize(srcRect.size())); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 inline void clearPreferredRasterScale(const LayoutBox& obj) { | 136 inline void clearPreferredRasterBounds(const LayoutBox& obj) { |
| 137 if (!RuntimeEnabledFeatures::preferredImageRasterBoundsEnabled()) |
| 138 return; |
137 if (PaintLayer* paintLayer = obj.layer()) { | 139 if (PaintLayer* paintLayer = obj.layer()) { |
138 if (paintLayer->compositingState() != PaintsIntoOwnBacking) | 140 if (paintLayer->compositingState() != PaintsIntoOwnBacking) |
139 return; | 141 return; |
140 paintLayer->graphicsLayerBacking()->clearPreferredRasterScale(); | 142 paintLayer->graphicsLayerBacking()->clearPreferredRasterBounds(); |
141 } | 143 } |
142 } | 144 } |
143 | 145 |
144 void BoxPainter::paintBoxDecorationBackgroundWithRect( | 146 void BoxPainter::paintBoxDecorationBackgroundWithRect( |
145 const PaintInfo& paintInfo, | 147 const PaintInfo& paintInfo, |
146 const LayoutPoint& paintOffset, | 148 const LayoutPoint& paintOffset, |
147 const LayoutRect& paintRect) { | 149 const LayoutRect& paintRect) { |
148 bool paintingOverflowContents = | 150 bool paintingOverflowContents = |
149 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( | 151 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( |
150 &m_layoutBox, paintInfo); | 152 &m_layoutBox, paintInfo); |
(...skipping 19 matching lines...) Expand all Loading... |
170 paintingOverflowContents ? static_cast<const DisplayItemClient&>( | 172 paintingOverflowContents ? static_cast<const DisplayItemClient&>( |
171 *m_layoutBox.layer() | 173 *m_layoutBox.layer() |
172 ->compositedLayerMapping() | 174 ->compositedLayerMapping() |
173 ->scrollingContentsLayer()) | 175 ->scrollingContentsLayer()) |
174 : m_layoutBox; | 176 : m_layoutBox; |
175 if (DrawingRecorder::useCachedDrawingIfPossible( | 177 if (DrawingRecorder::useCachedDrawingIfPossible( |
176 paintInfo.context, displayItemClient, | 178 paintInfo.context, displayItemClient, |
177 DisplayItem::kBoxDecorationBackground)) | 179 DisplayItem::kBoxDecorationBackground)) |
178 return; | 180 return; |
179 | 181 |
180 clearPreferredRasterScale(m_layoutBox); | 182 clearPreferredRasterBounds(m_layoutBox); |
181 | 183 |
182 DrawingRecorder recorder( | 184 DrawingRecorder recorder( |
183 paintInfo.context, displayItemClient, | 185 paintInfo.context, displayItemClient, |
184 DisplayItem::kBoxDecorationBackground, | 186 DisplayItem::kBoxDecorationBackground, |
185 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset))); | 187 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset))); |
186 BoxDecorationData boxDecorationData(m_layoutBox); | 188 BoxDecorationData boxDecorationData(m_layoutBox); |
187 GraphicsContextStateSaver stateSaver(paintInfo.context, false); | 189 GraphicsContextStateSaver stateSaver(paintInfo.context, false); |
188 | 190 |
189 if (!paintingOverflowContents) { | 191 if (!paintingOverflowContents) { |
190 // FIXME: Should eventually give the theme control over whether the box | 192 // FIXME: Should eventually give the theme control over whether the box |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize); | 651 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize); |
650 | 652 |
651 // The shadow may have been applied with the color fill. | 653 // The shadow may have been applied with the color fill. |
652 const ShadowContext shadowContext( | 654 const ShadowContext shadowContext( |
653 context, obj, info.shouldPaintShadow && !info.shouldPaintColor); | 655 context, obj, info.shouldPaintShadow && !info.shouldPaintColor); |
654 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", | 656 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", |
655 "data", InspectorPaintImageEvent::data(obj, *info.image)); | 657 "data", InspectorPaintImageEvent::data(obj, *info.image)); |
656 context.drawImageRRect(imageContext.image(), border, srcRect, | 658 context.drawImageRRect(imageContext.image(), border, srcRect, |
657 imageContext.compositeOp()); | 659 imageContext.compositeOp()); |
658 | 660 |
659 updatePreferredRasterScaleFromImage(srcRect, border.rect(), obj); | 661 updatePreferredRasterBoundsFromImage(srcRect, border.rect(), obj); |
660 | 662 |
661 return true; | 663 return true; |
662 } | 664 } |
663 | 665 |
664 } // anonymous namespace | 666 } // anonymous namespace |
665 | 667 |
666 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, | 668 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, |
667 const PaintInfo& paintInfo, | 669 const PaintInfo& paintInfo, |
668 const Color& color, | 670 const Color& color, |
669 const FillLayer& bgLayer, | 671 const FillLayer& bgLayer, |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( | 1110 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( |
1109 const ComputedStyle& style, | 1111 const ComputedStyle& style, |
1110 const Document& document) { | 1112 const Document& document) { |
1111 return document.printing() && | 1113 return document.printing() && |
1112 style.getPrintColorAdjust() == PrintColorAdjustEconomy && | 1114 style.getPrintColorAdjust() == PrintColorAdjustEconomy && |
1113 (!document.settings() || | 1115 (!document.settings() || |
1114 !document.settings()->shouldPrintBackgrounds()); | 1116 !document.settings()->shouldPrintBackgrounds()); |
1115 } | 1117 } |
1116 | 1118 |
1117 } // namespace blink | 1119 } // namespace blink |
OLD | NEW |