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