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 "config.h" | 5 #include "config.h" |
6 #include "core/paint/ImagePainter.h" | 6 #include "core/paint/ImagePainter.h" |
7 | 7 |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
10 #include "core/editing/FrameSelection.h" | 10 #include "core/editing/FrameSelection.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 Path path = areaElement.computePath(&m_layoutImage); | 52 Path path = areaElement.computePath(&m_layoutImage); |
53 if (path.isEmpty()) | 53 if (path.isEmpty()) |
54 return; | 54 return; |
55 | 55 |
56 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); | 56 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); |
57 int outlineWidth = areaElementStyle.outlineWidth(); | 57 int outlineWidth = areaElementStyle.outlineWidth(); |
58 if (!outlineWidth) | 58 if (!outlineWidth) |
59 return; | 59 return; |
60 | 60 |
| 61 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.conte
xt, m_layoutImage, paintInfo.phase)) |
| 62 return; |
| 63 |
61 IntRect focusRect = m_layoutImage.absoluteContentBox(); | 64 IntRect focusRect = m_layoutImage.absoluteContentBox(); |
62 | |
63 LayoutObjectDrawingRecorder drawingRecorder(*paintInfo.context, m_layoutImag
e, paintInfo.phase, focusRect); | 65 LayoutObjectDrawingRecorder drawingRecorder(*paintInfo.context, m_layoutImag
e, paintInfo.phase, focusRect); |
64 if (drawingRecorder.canUseCachedDrawing()) | |
65 return; | |
66 | 66 |
67 // FIXME: Clip path instead of context when Skia pathops is ready. | 67 // FIXME: Clip path instead of context when Skia pathops is ready. |
68 // https://crbug.com/251206 | 68 // https://crbug.com/251206 |
69 | 69 |
70 paintInfo.context->save(); | 70 paintInfo.context->save(); |
71 paintInfo.context->clip(focusRect); | 71 paintInfo.context->clip(focusRect); |
72 paintInfo.context->drawFocusRing(path, outlineWidth, | 72 paintInfo.context->drawFocusRing(path, outlineWidth, |
73 areaElementStyle.outlineOffset(), | 73 areaElementStyle.outlineOffset(), |
74 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); | 74 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); |
75 paintInfo.context->restore(); | 75 paintInfo.context->restore(); |
76 } | 76 } |
77 | 77 |
78 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 78 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
79 { | 79 { |
80 LayoutUnit cWidth = m_layoutImage.contentWidth(); | 80 LayoutUnit cWidth = m_layoutImage.contentWidth(); |
81 LayoutUnit cHeight = m_layoutImage.contentHeight(); | 81 LayoutUnit cHeight = m_layoutImage.contentHeight(); |
82 | 82 |
83 GraphicsContext* context = paintInfo.context; | 83 GraphicsContext* context = paintInfo.context; |
84 | 84 |
85 if (!m_layoutImage.imageResource()->hasImage()) { | 85 if (!m_layoutImage.imageResource()->hasImage()) { |
86 if (paintInfo.phase == PaintPhaseSelection) | 86 if (paintInfo.phase == PaintPhaseSelection) |
87 return; | 87 return; |
88 | |
89 if (cWidth > 2 && cHeight > 2) { | 88 if (cWidth > 2 && cHeight > 2) { |
| 89 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context
, m_layoutImage, paintInfo.phase)) |
| 90 return; |
90 // Draw an outline rect where the image should be. | 91 // Draw an outline rect where the image should be. |
91 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); | 92 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); |
92 | |
93 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage,
paintInfo.phase, paintRect); | 93 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage,
paintInfo.phase, paintRect); |
94 if (drawingRecorder.canUseCachedDrawing()) | |
95 return; | |
96 context->setStrokeStyle(SolidStroke); | 94 context->setStrokeStyle(SolidStroke); |
97 context->setStrokeColor(Color::lightGray); | 95 context->setStrokeColor(Color::lightGray); |
98 context->setFillColor(Color::transparent); | 96 context->setFillColor(Color::transparent); |
99 context->drawRect(paintRect); | 97 context->drawRect(paintRect); |
100 } | 98 } |
101 } else if (cWidth > 0 && cHeight > 0) { | 99 } else if (cWidth > 0 && cHeight > 0) { |
| 100 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, m_
layoutImage, paintInfo.phase)) |
| 101 return; |
102 LayoutRect contentRect = m_layoutImage.contentBoxRect(); | 102 LayoutRect contentRect = m_layoutImage.contentBoxRect(); |
103 contentRect.moveBy(paintOffset); | 103 contentRect.moveBy(paintOffset); |
104 LayoutRect paintRect = m_layoutImage.replacedContentRect(); | 104 LayoutRect paintRect = m_layoutImage.replacedContentRect(); |
105 paintRect.moveBy(paintOffset); | 105 paintRect.moveBy(paintOffset); |
106 | 106 |
107 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage, pai
ntInfo.phase, contentRect); | 107 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage, pai
ntInfo.phase, contentRect); |
108 if (drawingRecorder.canUseCachedDrawing()) | |
109 return; | |
110 bool clip = !contentRect.contains(paintRect); | 108 bool clip = !contentRect.contains(paintRect); |
111 if (clip) { | 109 if (clip) { |
112 context->save(); | 110 context->save(); |
113 context->clip(contentRect); | 111 context->clip(contentRect); |
114 } | 112 } |
115 | 113 |
116 paintIntoRect(context, paintRect); | 114 paintIntoRect(context, paintRect); |
117 | 115 |
118 if (clip) | 116 if (clip) |
119 context->restore(); | 117 context->restore(); |
(...skipping 18 matching lines...) Expand all Loading... |
138 | 136 |
139 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); | 137 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); |
140 | 138 |
141 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); | 139 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); |
142 context->setImageInterpolationQuality(interpolationQuality); | 140 context->setImageInterpolationQuality(interpolationQuality); |
143 context->drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, m_la
youtImage.shouldRespectImageOrientation()); | 141 context->drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, m_la
youtImage.shouldRespectImageOrientation()); |
144 context->setImageInterpolationQuality(previousInterpolationQuality); | 142 context->setImageInterpolationQuality(previousInterpolationQuality); |
145 } | 143 } |
146 | 144 |
147 } // namespace blink | 145 } // namespace blink |
OLD | NEW |