OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
6 #include "core/paint/NinePieceImagePainter.h" | 6 #include "core/paint/NinePieceImagePainter.h" |
7 | 7 |
8 #include "core/frame/UseCounter.h" | 8 #include "core/frame/UseCounter.h" |
9 #include "core/layout/ImageQualityController.h" | 9 #include "core/layout/ImageQualityController.h" |
10 #include "core/layout/LayoutBoxModelObject.h" | 10 #include "core/layout/LayoutBoxModelObject.h" |
11 #include "core/paint/BoxPainter.h" | 11 #include "core/paint/BoxPainter.h" |
12 #include "core/paint/NinePieceImageGrid.h" | 12 #include "core/paint/NinePieceImageGrid.h" |
13 #include "core/style/ComputedStyle.h" | 13 #include "core/style/ComputedStyle.h" |
14 #include "core/style/NinePieceImage.h" | 14 #include "core/style/NinePieceImage.h" |
15 #include "platform/geometry/IntSize.h" | 15 #include "platform/geometry/IntSize.h" |
16 #include "platform/geometry/LayoutRect.h" | 16 #include "platform/geometry/LayoutRect.h" |
17 #include "platform/graphics/GraphicsContext.h" | 17 #include "platform/graphics/GraphicsContext.h" |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 | 20 |
21 NinePieceImagePainter::NinePieceImagePainter(const LayoutBoxModelObject& layoutO
bject) | 21 NinePieceImagePainter::NinePieceImagePainter(const LayoutBoxModelObject& layoutO
bject) |
22 : m_layoutObject(layoutObject) | 22 : m_layoutObject(layoutObject) |
23 { | 23 { |
24 } | 24 } |
25 | 25 |
26 bool NinePieceImagePainter::paint(GraphicsContext* graphicsContext, const Layout
Rect& rect, const ComputedStyle& style, | 26 bool NinePieceImagePainter::paint(GraphicsContext& graphicsContext, const Layout
Rect& rect, const ComputedStyle& style, |
27 const NinePieceImage& ninePieceImage, SkXfermode::Mode op) const | 27 const NinePieceImage& ninePieceImage, SkXfermode::Mode op) const |
28 { | 28 { |
29 StyleImage* styleImage = ninePieceImage.image(); | 29 StyleImage* styleImage = ninePieceImage.image(); |
30 if (!styleImage) | 30 if (!styleImage) |
31 return false; | 31 return false; |
32 | 32 |
33 if (!styleImage->isLoaded()) | 33 if (!styleImage->isLoaded()) |
34 return true; // Never paint a nine-piece image incrementally, but don't
paint the fallback borders either. | 34 return true; // Never paint a nine-piece image incrementally, but don't
paint the fallback borders either. |
35 | 35 |
36 if (!styleImage->canRender()) | 36 if (!styleImage->canRender()) |
(...skipping 15 matching lines...) Expand all Loading... |
52 | 52 |
53 IntSize imageSize = roundedIntSize(m_layoutObject.calculateImageIntrinsicDim
ensions(styleImage, borderImageRect.size(), | 53 IntSize imageSize = roundedIntSize(m_layoutObject.calculateImageIntrinsicDim
ensions(styleImage, borderImageRect.size(), |
54 LayoutBoxModelObject::DoNotScaleByEffectiveZoom)); | 54 LayoutBoxModelObject::DoNotScaleByEffectiveZoom)); |
55 | 55 |
56 IntRectOutsets borderWidths(style.borderTopWidth(), style.borderRightWidth()
, | 56 IntRectOutsets borderWidths(style.borderTopWidth(), style.borderRightWidth()
, |
57 style.borderBottomWidth(), style.borderLeftWidth()); | 57 style.borderBottomWidth(), style.borderLeftWidth()); |
58 NinePieceImageGrid grid(ninePieceImage, imageSize, pixelSnappedIntRect(borde
rImageRect), borderWidths); | 58 NinePieceImageGrid grid(ninePieceImage, imageSize, pixelSnappedIntRect(borde
rImageRect), borderWidths); |
59 | 59 |
60 RefPtr<Image> image = styleImage->image(&m_layoutObject, imageSize, style.ef
fectiveZoom()); | 60 RefPtr<Image> image = styleImage->image(&m_layoutObject, imageSize, style.ef
fectiveZoom()); |
61 | 61 |
62 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ
uality(m_layoutObject, | 62 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ
uality(m_layoutObject, image.get(), 0, rectWithOutsets.size()); |
63 graphicsContext, image.get(), 0, rectWithOutsets.size()); | 63 InterpolationQuality previousInterpolationQuality = graphicsContext.imageInt
erpolationQuality(); |
64 InterpolationQuality previousInterpolationQuality = graphicsContext->imageIn
terpolationQuality(); | 64 graphicsContext.setImageInterpolationQuality(interpolationQuality); |
65 graphicsContext->setImageInterpolationQuality(interpolationQuality); | |
66 | 65 |
67 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", | 66 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", |
68 InspectorPaintImageEvent::data(m_layoutObject, *styleImage)); | 67 InspectorPaintImageEvent::data(m_layoutObject, *styleImage)); |
69 | 68 |
70 for (NinePiece piece = MinPiece; piece < MaxPiece; ++piece) { | 69 for (NinePiece piece = MinPiece; piece < MaxPiece; ++piece) { |
71 NinePieceImageGrid::NinePieceDrawInfo drawInfo = grid.getNinePieceDrawIn
fo(piece); | 70 NinePieceImageGrid::NinePieceDrawInfo drawInfo = grid.getNinePieceDrawIn
fo(piece); |
72 | 71 |
73 if (drawInfo.isDrawable) { | 72 if (drawInfo.isDrawable) { |
74 if (drawInfo.isCornerPiece) { | 73 if (drawInfo.isCornerPiece) { |
75 graphicsContext->drawImage(image.get(), drawInfo.destination, dr
awInfo.source, op); | 74 graphicsContext.drawImage(image.get(), drawInfo.destination, dra
wInfo.source, op); |
76 } else { | 75 } else { |
77 graphicsContext->drawTiledImage(image.get(), drawInfo.destinatio
n, | 76 graphicsContext.drawTiledImage(image.get(), drawInfo.destination
, |
78 drawInfo.source, drawInfo.tileScale, drawInfo.tileRule.horiz
ontal, | 77 drawInfo.source, drawInfo.tileScale, drawInfo.tileRule.horiz
ontal, |
79 drawInfo.tileRule.vertical, op); | 78 drawInfo.tileRule.vertical, op); |
80 } | 79 } |
81 } | 80 } |
82 } | 81 } |
83 | 82 |
84 graphicsContext->setImageInterpolationQuality(previousInterpolationQuality); | 83 graphicsContext.setImageInterpolationQuality(previousInterpolationQuality); |
85 return true; | 84 return true; |
86 } | 85 } |
87 | 86 |
88 } // namespace blink | 87 } // namespace blink |
OLD | NEW |