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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 Path path = areaElement.computePath(&m_layoutImage); | 55 Path path = areaElement.computePath(&m_layoutImage); |
56 if (path.isEmpty()) | 56 if (path.isEmpty()) |
57 return; | 57 return; |
58 | 58 |
59 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); | 59 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); |
60 int outlineWidth = areaElementStyle.outlineWidth(); | 60 int outlineWidth = areaElementStyle.outlineWidth(); |
61 if (!outlineWidth) | 61 if (!outlineWidth) |
62 return; | 62 return; |
63 | 63 |
64 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.conte
xt, m_layoutImage, paintInfo.phase, paintOffset)) | 64 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutImage, paintInfo.phase, paintOffset)) |
65 return; | 65 return; |
66 | 66 |
67 IntRect focusRect = m_layoutImage.absoluteContentBox(); | 67 IntRect focusRect = m_layoutImage.absoluteContentBox(); |
68 LayoutObjectDrawingRecorder drawingRecorder(*paintInfo.context, m_layoutImag
e, paintInfo.phase, focusRect, paintOffset); | 68 LayoutObjectDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage
, paintInfo.phase, focusRect, paintOffset); |
69 | 69 |
70 // FIXME: Clip path instead of context when Skia pathops is ready. | 70 // FIXME: Clip path instead of context when Skia pathops is ready. |
71 // https://crbug.com/251206 | 71 // https://crbug.com/251206 |
72 | 72 |
73 paintInfo.context->save(); | 73 paintInfo.context.save(); |
74 paintInfo.context->clip(focusRect); | 74 paintInfo.context.clip(focusRect); |
75 paintInfo.context->drawFocusRing(path, outlineWidth, | 75 paintInfo.context.drawFocusRing(path, outlineWidth, |
76 areaElementStyle.outlineOffset(), | 76 areaElementStyle.outlineOffset(), |
77 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); | 77 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); |
78 paintInfo.context->restore(); | 78 paintInfo.context.restore(); |
79 } | 79 } |
80 | 80 |
81 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 81 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
82 { | 82 { |
83 LayoutUnit cWidth = m_layoutImage.contentWidth(); | 83 LayoutUnit cWidth = m_layoutImage.contentWidth(); |
84 LayoutUnit cHeight = m_layoutImage.contentHeight(); | 84 LayoutUnit cHeight = m_layoutImage.contentHeight(); |
85 | 85 |
86 GraphicsContext* context = paintInfo.context; | 86 GraphicsContext& context = paintInfo.context; |
87 | 87 |
88 if (!m_layoutImage.imageResource()->hasImage()) { | 88 if (!m_layoutImage.imageResource()->hasImage()) { |
89 if (paintInfo.phase == PaintPhaseSelection) | 89 if (paintInfo.phase == PaintPhaseSelection) |
90 return; | 90 return; |
91 if (cWidth > 2 && cHeight > 2) { | 91 if (cWidth > 2 && cHeight > 2) { |
92 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context
, m_layoutImage, paintInfo.phase, paintOffset)) | 92 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context,
m_layoutImage, paintInfo.phase, paintOffset)) |
93 return; | 93 return; |
94 // Draw an outline rect where the image should be. | 94 // Draw an outline rect where the image should be. |
95 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); | 95 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); |
96 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage,
paintInfo.phase, paintRect, paintOffset); | 96 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutImage,
paintInfo.phase, paintRect, paintOffset); |
97 context->setStrokeStyle(SolidStroke); | 97 context.setStrokeStyle(SolidStroke); |
98 context->setStrokeColor(Color::lightGray); | 98 context.setStrokeColor(Color::lightGray); |
99 context->setFillColor(Color::transparent); | 99 context.setFillColor(Color::transparent); |
100 context->drawRect(paintRect); | 100 context.drawRect(paintRect); |
101 } | 101 } |
102 } else if (cWidth > 0 && cHeight > 0) { | 102 } else if (cWidth > 0 && cHeight > 0) { |
103 LayoutRect contentRect = m_layoutImage.contentBoxRect(); | 103 LayoutRect contentRect = m_layoutImage.contentBoxRect(); |
104 contentRect.moveBy(paintOffset); | 104 contentRect.moveBy(paintOffset); |
105 LayoutRect paintRect = m_layoutImage.replacedContentRect(); | 105 LayoutRect paintRect = m_layoutImage.replacedContentRect(); |
106 paintRect.moveBy(paintOffset); | 106 paintRect.moveBy(paintOffset); |
107 | 107 |
108 Optional<ClipRecorder> clipRecorder; | 108 Optional<ClipRecorder> clipRecorder; |
109 if (!contentRect.contains(paintRect)) { | 109 if (!contentRect.contains(paintRect)) { |
110 // TODO(fmalita): can we get rid of this clip and adjust the image s
rc/dst rect instead? | 110 // TODO(fmalita): can we get rid of this clip and adjust the image s
rc/dst rect instead? |
111 clipRecorder.emplace(*context, m_layoutImage, paintInfo.displayItemT
ypeForClipping(), contentRect); | 111 clipRecorder.emplace(context, m_layoutImage, paintInfo.displayItemTy
peForClipping(), contentRect); |
112 } | 112 } |
113 | 113 |
114 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, m_
layoutImage, paintInfo.phase, paintOffset)) | 114 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_l
ayoutImage, paintInfo.phase, paintOffset)) |
115 return; | 115 return; |
116 | 116 |
117 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage, pai
ntInfo.phase, contentRect, paintOffset); | 117 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutImage, pain
tInfo.phase, contentRect, paintOffset); |
118 paintIntoRect(context, paintRect); | 118 paintIntoRect(context, paintRect); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void ImagePainter::paintIntoRect(GraphicsContext* context, const LayoutRect& rec
t) | 122 void ImagePainter::paintIntoRect(GraphicsContext& context, const LayoutRect& rec
t) |
123 { | 123 { |
124 if (!m_layoutImage.imageResource()->hasImage() || m_layoutImage.imageResourc
e()->errorOccurred()) | 124 if (!m_layoutImage.imageResource()->hasImage() || m_layoutImage.imageResourc
e()->errorOccurred()) |
125 return; // FIXME: should we just ASSERT these conditions? (audit all cal
lers). | 125 return; // FIXME: should we just ASSERT these conditions? (audit all cal
lers). |
126 | 126 |
127 IntRect alignedRect = pixelSnappedIntRect(rect); | 127 IntRect alignedRect = pixelSnappedIntRect(rect); |
128 if (alignedRect.width() <= 0 || alignedRect.height() <= 0) | 128 if (alignedRect.width() <= 0 || alignedRect.height() <= 0) |
129 return; | 129 return; |
130 | 130 |
131 RefPtr<Image> image = m_layoutImage.imageResource()->image(alignedRect.size(
), m_layoutImage.style()->effectiveZoom()); | 131 RefPtr<Image> image = m_layoutImage.imageResource()->image(alignedRect.size(
), m_layoutImage.style()->effectiveZoom()); |
132 if (!image || image->isNull()) | 132 if (!image || image->isNull()) |
133 return; | 133 return; |
134 | 134 |
135 // FIXME: why is interpolation quality selection not included in the Instrum
entation reported cost of drawing an image? | 135 // FIXME: why is interpolation quality selection not included in the Instrum
entation reported cost of drawing an image? |
136 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ
uality(m_layoutImage, context, image.get(), image.get(), LayoutSize(alignedRect.
size())); | 136 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ
uality(m_layoutImage, image.get(), image.get(), LayoutSize(alignedRect.size())); |
137 | 137 |
138 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); | 138 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); |
139 | 139 |
140 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); | 140 InterpolationQuality previousInterpolationQuality = context.imageInterpolati
onQuality(); |
141 context->setImageInterpolationQuality(interpolationQuality); | 141 context.setImageInterpolationQuality(interpolationQuality); |
142 context->drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, Layo
utObject::shouldRespectImageOrientation(&m_layoutImage)); | 142 context.drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, Layou
tObject::shouldRespectImageOrientation(&m_layoutImage)); |
143 context->setImageInterpolationQuality(previousInterpolationQuality); | 143 context.setImageInterpolationQuality(previousInterpolationQuality); |
144 } | 144 } |
145 | 145 |
146 } // namespace blink | 146 } // namespace blink |
OLD | NEW |