| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 (destRect.width() == 0.0f || destRect.height() == 0.0f) |
| 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()) { |
| 130 if (paintLayer->compositingState() != PaintsIntoOwnBacking) |
| 131 return; |
| 132 paintLayer->graphicsLayerBacking()->setPreferredRasterScale(rasterScale); |
| 133 } |
| 134 } |
| 135 |
| 136 inline void clearPreferredRasterScale(const LayoutBox& obj) { |
| 137 if (PaintLayer* paintLayer = obj.layer()) { |
| 138 if (paintLayer->compositingState() != PaintsIntoOwnBacking) |
| 139 return; |
| 140 paintLayer->graphicsLayerBacking()->clearPreferredRasterScale(); |
| 141 } |
| 142 } |
| 143 |
| 111 void BoxPainter::paintBoxDecorationBackgroundWithRect( | 144 void BoxPainter::paintBoxDecorationBackgroundWithRect( |
| 112 const PaintInfo& paintInfo, | 145 const PaintInfo& paintInfo, |
| 113 const LayoutPoint& paintOffset, | 146 const LayoutPoint& paintOffset, |
| 114 const LayoutRect& paintRect) { | 147 const LayoutRect& paintRect) { |
| 115 bool paintingOverflowContents = | 148 bool paintingOverflowContents = |
| 116 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( | 149 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( |
| 117 &m_layoutBox, paintInfo); | 150 &m_layoutBox, paintInfo); |
| 118 const ComputedStyle& style = m_layoutBox.styleRef(); | 151 const ComputedStyle& style = m_layoutBox.styleRef(); |
| 119 | 152 |
| 120 Optional<DisplayItemCacheSkipper> cacheSkipper; | 153 Optional<DisplayItemCacheSkipper> cacheSkipper; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 paintingOverflowContents ? static_cast<const DisplayItemClient&>( | 170 paintingOverflowContents ? static_cast<const DisplayItemClient&>( |
| 138 *m_layoutBox.layer() | 171 *m_layoutBox.layer() |
| 139 ->compositedLayerMapping() | 172 ->compositedLayerMapping() |
| 140 ->scrollingContentsLayer()) | 173 ->scrollingContentsLayer()) |
| 141 : m_layoutBox; | 174 : m_layoutBox; |
| 142 if (DrawingRecorder::useCachedDrawingIfPossible( | 175 if (DrawingRecorder::useCachedDrawingIfPossible( |
| 143 paintInfo.context, displayItemClient, | 176 paintInfo.context, displayItemClient, |
| 144 DisplayItem::kBoxDecorationBackground)) | 177 DisplayItem::kBoxDecorationBackground)) |
| 145 return; | 178 return; |
| 146 | 179 |
| 180 clearPreferredRasterScale(m_layoutBox); |
| 181 |
| 147 DrawingRecorder recorder( | 182 DrawingRecorder recorder( |
| 148 paintInfo.context, displayItemClient, | 183 paintInfo.context, displayItemClient, |
| 149 DisplayItem::kBoxDecorationBackground, | 184 DisplayItem::kBoxDecorationBackground, |
| 150 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset))); | 185 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset))); |
| 151 BoxDecorationData boxDecorationData(m_layoutBox); | 186 BoxDecorationData boxDecorationData(m_layoutBox); |
| 152 GraphicsContextStateSaver stateSaver(paintInfo.context, false); | 187 GraphicsContextStateSaver stateSaver(paintInfo.context, false); |
| 153 | 188 |
| 154 if (!paintingOverflowContents) { | 189 if (!paintingOverflowContents) { |
| 155 // FIXME: Should eventually give the theme control over whether the box | 190 // FIXME: Should eventually give the theme control over whether the box |
| 156 // shadow should paint, since controls could have custom shadows of their | 191 // shadow should paint, since controls could have custom shadows of their |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize); | 649 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize); |
| 615 | 650 |
| 616 // The shadow may have been applied with the color fill. | 651 // The shadow may have been applied with the color fill. |
| 617 const ShadowContext shadowContext( | 652 const ShadowContext shadowContext( |
| 618 context, obj, info.shouldPaintShadow && !info.shouldPaintColor); | 653 context, obj, info.shouldPaintShadow && !info.shouldPaintColor); |
| 619 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", | 654 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", |
| 620 "data", InspectorPaintImageEvent::data(obj, *info.image)); | 655 "data", InspectorPaintImageEvent::data(obj, *info.image)); |
| 621 context.drawImageRRect(imageContext.image(), border, srcRect, | 656 context.drawImageRRect(imageContext.image(), border, srcRect, |
| 622 imageContext.compositeOp()); | 657 imageContext.compositeOp()); |
| 623 | 658 |
| 659 updatePreferredRasterScaleFromImage(srcRect, border.rect(), obj); |
| 660 |
| 624 return true; | 661 return true; |
| 625 } | 662 } |
| 626 | 663 |
| 627 } // anonymous namespace | 664 } // anonymous namespace |
| 628 | 665 |
| 629 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, | 666 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, |
| 630 const PaintInfo& paintInfo, | 667 const PaintInfo& paintInfo, |
| 631 const Color& color, | 668 const Color& color, |
| 632 const FillLayer& bgLayer, | 669 const FillLayer& bgLayer, |
| 633 const LayoutRect& rect, | 670 const LayoutRect& rect, |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( | 1108 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( |
| 1072 const ComputedStyle& style, | 1109 const ComputedStyle& style, |
| 1073 const Document& document) { | 1110 const Document& document) { |
| 1074 return document.printing() && | 1111 return document.printing() && |
| 1075 style.getPrintColorAdjust() == PrintColorAdjustEconomy && | 1112 style.getPrintColorAdjust() == PrintColorAdjustEconomy && |
| 1076 (!document.settings() || | 1113 (!document.settings() || |
| 1077 !document.settings()->shouldPrintBackgrounds()); | 1114 !document.settings()->shouldPrintBackgrounds()); |
| 1078 } | 1115 } |
| 1079 | 1116 |
| 1080 } // namespace blink | 1117 } // namespace blink |
| OLD | NEW |