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 updatePreferredRasterBoundsFromImage( | |
116 const FloatRect srcRect, | |
117 const FloatRect& destRect, | |
118 const LayoutBoxModelObject& obj) { | |
119 if (!RuntimeEnabledFeatures::preferredImageRasterBoundsEnabled()) | |
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 if (PaintLayer* paintLayer = obj.layer()) { | |
127 if (paintLayer->compositingState() != PaintsIntoOwnBacking) | |
128 return; | |
129 // TODO(chrishtr): ensure that this rounding does not ever lose any | |
130 // precision. | |
131 paintLayer->graphicsLayerBacking()->setPreferredRasterBounds( | |
132 roundedIntSize(srcRect.size())); | |
133 } | |
134 } | |
135 | |
136 inline void clearPreferredRasterBounds(const LayoutBox& obj) { | |
137 if (!RuntimeEnabledFeatures::preferredImageRasterBoundsEnabled()) | |
138 return; | |
139 if (PaintLayer* paintLayer = obj.layer()) { | |
140 if (paintLayer->compositingState() != PaintsIntoOwnBacking) | |
141 return; | |
142 paintLayer->graphicsLayerBacking()->clearPreferredRasterBounds(); | |
143 } | |
144 } | |
145 | |
146 void BoxPainter::paintBoxDecorationBackgroundWithRect( | 111 void BoxPainter::paintBoxDecorationBackgroundWithRect( |
147 const PaintInfo& paintInfo, | 112 const PaintInfo& paintInfo, |
148 const LayoutPoint& paintOffset, | 113 const LayoutPoint& paintOffset, |
149 const LayoutRect& paintRect) { | 114 const LayoutRect& paintRect) { |
150 bool paintingOverflowContents = | 115 bool paintingOverflowContents = |
151 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( | 116 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( |
152 &m_layoutBox, paintInfo); | 117 &m_layoutBox, paintInfo); |
153 const ComputedStyle& style = m_layoutBox.styleRef(); | 118 const ComputedStyle& style = m_layoutBox.styleRef(); |
154 | 119 |
155 Optional<DisplayItemCacheSkipper> cacheSkipper; | 120 Optional<DisplayItemCacheSkipper> cacheSkipper; |
(...skipping 16 matching lines...) Expand all Loading... |
172 paintingOverflowContents ? static_cast<const DisplayItemClient&>( | 137 paintingOverflowContents ? static_cast<const DisplayItemClient&>( |
173 *m_layoutBox.layer() | 138 *m_layoutBox.layer() |
174 ->compositedLayerMapping() | 139 ->compositedLayerMapping() |
175 ->scrollingContentsLayer()) | 140 ->scrollingContentsLayer()) |
176 : m_layoutBox; | 141 : m_layoutBox; |
177 if (DrawingRecorder::useCachedDrawingIfPossible( | 142 if (DrawingRecorder::useCachedDrawingIfPossible( |
178 paintInfo.context, displayItemClient, | 143 paintInfo.context, displayItemClient, |
179 DisplayItem::kBoxDecorationBackground)) | 144 DisplayItem::kBoxDecorationBackground)) |
180 return; | 145 return; |
181 | 146 |
182 clearPreferredRasterBounds(m_layoutBox); | |
183 | |
184 DrawingRecorder recorder( | 147 DrawingRecorder recorder( |
185 paintInfo.context, displayItemClient, | 148 paintInfo.context, displayItemClient, |
186 DisplayItem::kBoxDecorationBackground, | 149 DisplayItem::kBoxDecorationBackground, |
187 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset))); | 150 FloatRect(boundsForDrawingRecorder(paintInfo, paintOffset))); |
188 BoxDecorationData boxDecorationData(m_layoutBox); | 151 BoxDecorationData boxDecorationData(m_layoutBox); |
189 GraphicsContextStateSaver stateSaver(paintInfo.context, false); | 152 GraphicsContextStateSaver stateSaver(paintInfo.context, false); |
190 | 153 |
191 if (!paintingOverflowContents) { | 154 if (!paintingOverflowContents) { |
192 // FIXME: Should eventually give the theme control over whether the box | 155 // FIXME: Should eventually give the theme control over whether the box |
193 // shadow should paint, since controls could have custom shadows of their | 156 // shadow should paint, since controls could have custom shadows of their |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 ? imageTile.size() | 554 ? imageTile.size() |
592 : FloatSize(imageContext.image()->size()); | 555 : FloatSize(imageContext.image()->size()); |
593 const FloatRect srcRect = | 556 const FloatRect srcRect = |
594 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize); | 557 Image::computeSubsetForTile(imageTile, border.rect(), intrinsicTileSize); |
595 | 558 |
596 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", | 559 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", |
597 "data", InspectorPaintImageEvent::data(obj, *info.image)); | 560 "data", InspectorPaintImageEvent::data(obj, *info.image)); |
598 context.drawImageRRect(imageContext.image(), border, srcRect, | 561 context.drawImageRRect(imageContext.image(), border, srcRect, |
599 imageContext.compositeOp()); | 562 imageContext.compositeOp()); |
600 | 563 |
601 updatePreferredRasterBoundsFromImage(srcRect, border.rect(), obj); | |
602 | |
603 return true; | 564 return true; |
604 } | 565 } |
605 | 566 |
606 } // anonymous namespace | 567 } // anonymous namespace |
607 | 568 |
608 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, | 569 void BoxPainter::paintFillLayer(const LayoutBoxModelObject& obj, |
609 const PaintInfo& paintInfo, | 570 const PaintInfo& paintInfo, |
610 const Color& color, | 571 const Color& color, |
611 const FillLayer& bgLayer, | 572 const FillLayer& bgLayer, |
612 const LayoutRect& rect, | 573 const LayoutRect& rect, |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( | 1051 bool BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( |
1091 const ComputedStyle& style, | 1052 const ComputedStyle& style, |
1092 const Document& document) { | 1053 const Document& document) { |
1093 return document.printing() && | 1054 return document.printing() && |
1094 style.printColorAdjust() == EPrintColorAdjust::kEconomy && | 1055 style.printColorAdjust() == EPrintColorAdjust::kEconomy && |
1095 (!document.settings() || | 1056 (!document.settings() || |
1096 !document.settings()->getShouldPrintBackgrounds()); | 1057 !document.settings()->getShouldPrintBackgrounds()); |
1097 } | 1058 } |
1098 | 1059 |
1099 } // namespace blink | 1060 } // namespace blink |
OLD | NEW |