| 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" |
| 11 #include "core/html/HTMLAreaElement.h" | 11 #include "core/html/HTMLAreaElement.h" |
| 12 #include "core/html/HTMLImageElement.h" | 12 #include "core/html/HTMLImageElement.h" |
| 13 #include "core/layout/LayoutImage.h" | 13 #include "core/layout/LayoutImage.h" |
| 14 #include "core/layout/LayoutReplaced.h" | 14 #include "core/layout/LayoutReplaced.h" |
| 15 #include "core/layout/TextRunConstructor.h" | 15 #include "core/layout/TextRunConstructor.h" |
| 16 #include "core/page/Page.h" | 16 #include "core/page/Page.h" |
| 17 #include "core/paint/BoxPainter.h" | 17 #include "core/paint/BoxPainter.h" |
| 18 #include "core/paint/LayoutObjectDrawingRecorder.h" | 18 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 19 #include "core/paint/PaintInfo.h" | 19 #include "core/paint/PaintInfo.h" |
| 20 #include "platform/geometry/LayoutPoint.h" | 20 #include "platform/geometry/LayoutPoint.h" |
| 21 #include "platform/graphics/Path.h" | 21 #include "platform/graphics/Path.h" |
| 22 #include "platform/graphics/paint/ClipRecorder.h" | |
| 23 | 22 |
| 24 namespace blink { | 23 namespace blink { |
| 25 | 24 |
| 26 void ImagePainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOff
set) | 25 void ImagePainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOff
set) |
| 27 { | 26 { |
| 28 m_layoutImage.LayoutReplaced::paint(paintInfo, paintOffset); | 27 m_layoutImage.LayoutReplaced::paint(paintInfo, paintOffset); |
| 29 | 28 |
| 30 if (paintInfo.phase == PaintPhaseOutline) | 29 if (paintInfo.phase == PaintPhaseOutline) |
| 31 paintAreaElementFocusRing(paintInfo, paintOffset); | 30 paintAreaElementFocusRing(paintInfo, paintOffset); |
| 32 } | 31 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 return; | 94 return; |
| 96 // Draw an outline rect where the image should be. | 95 // Draw an outline rect where the image should be. |
| 97 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); | 96 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); |
| 98 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutImage,
paintInfo.phase, paintRect); | 97 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutImage,
paintInfo.phase, paintRect); |
| 99 context.setStrokeStyle(SolidStroke); | 98 context.setStrokeStyle(SolidStroke); |
| 100 context.setStrokeColor(Color::lightGray); | 99 context.setStrokeColor(Color::lightGray); |
| 101 context.setFillColor(Color::transparent); | 100 context.setFillColor(Color::transparent); |
| 102 context.drawRect(paintRect); | 101 context.drawRect(paintRect); |
| 103 } | 102 } |
| 104 } else if (cWidth > 0 && cHeight > 0) { | 103 } else if (cWidth > 0 && cHeight > 0) { |
| 104 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_l
ayoutImage, paintInfo.phase)) |
| 105 return; |
| 106 |
| 105 LayoutRect contentRect = m_layoutImage.contentBoxRect(); | 107 LayoutRect contentRect = m_layoutImage.contentBoxRect(); |
| 106 contentRect.moveBy(paintOffset); | 108 contentRect.moveBy(paintOffset); |
| 107 LayoutRect paintRect = m_layoutImage.replacedContentRect(); | 109 LayoutRect paintRect = m_layoutImage.replacedContentRect(); |
| 108 paintRect.moveBy(paintOffset); | 110 paintRect.moveBy(paintOffset); |
| 109 | 111 |
| 110 Optional<ClipRecorder> clipRecorder; | |
| 111 if (!contentRect.contains(paintRect)) { | |
| 112 // TODO(fmalita): can we get rid of this clip and adjust the image s
rc/dst rect instead? | |
| 113 clipRecorder.emplace(context, m_layoutImage, paintInfo.displayItemTy
peForClipping(), pixelSnappedIntRect(contentRect)); | |
| 114 } | |
| 115 | |
| 116 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_l
ayoutImage, paintInfo.phase)) | |
| 117 return; | |
| 118 | |
| 119 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutImage, pain
tInfo.phase, contentRect); | 112 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutImage, pain
tInfo.phase, contentRect); |
| 120 paintIntoRect(context, paintRect); | 113 paintIntoRect(context, paintRect, contentRect); |
| 121 } | 114 } |
| 122 } | 115 } |
| 123 | 116 |
| 124 void ImagePainter::paintIntoRect(GraphicsContext& context, const LayoutRect& rec
t) | 117 void ImagePainter::paintIntoRect(GraphicsContext& context, const LayoutRect& des
tRect, const LayoutRect& contentRect) |
| 125 { | 118 { |
| 126 if (!m_layoutImage.imageResource()->hasImage() || m_layoutImage.imageResourc
e()->errorOccurred()) | 119 if (!m_layoutImage.imageResource()->hasImage() || m_layoutImage.imageResourc
e()->errorOccurred()) |
| 127 return; // FIXME: should we just ASSERT these conditions? (audit all cal
lers). | 120 return; // FIXME: should we just ASSERT these conditions? (audit all cal
lers). |
| 128 | 121 |
| 129 IntRect alignedRect = pixelSnappedIntRect(rect); | 122 IntRect pixelSnappedDestRect = pixelSnappedIntRect(destRect); |
| 130 if (alignedRect.width() <= 0 || alignedRect.height() <= 0) | 123 if (pixelSnappedDestRect.isEmpty()) |
| 131 return; | 124 return; |
| 132 | 125 |
| 133 RefPtr<Image> image = m_layoutImage.imageResource()->image(alignedRect.size(
), m_layoutImage.style()->effectiveZoom()); | 126 RefPtr<Image> image = m_layoutImage.imageResource()->image(pixelSnappedDestR
ect.size(), m_layoutImage.style()->effectiveZoom()); |
| 134 if (!image || image->isNull()) | 127 if (!image || image->isNull()) |
| 135 return; | 128 return; |
| 136 | 129 |
| 137 // FIXME: why is interpolation quality selection not included in the Instrum
entation reported cost of drawing an image? | 130 // FIXME: why is interpolation quality selection not included in the Instrum
entation reported cost of drawing an image? |
| 138 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ
uality(m_layoutImage, image.get(), image.get(), LayoutSize(alignedRect.size())); | 131 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ
uality(m_layoutImage, image.get(), image.get(), LayoutSize(pixelSnappedDestRect.
size())); |
| 132 |
| 133 FloatRect srcRect = image->rect(); |
| 134 // If the content rect requires clipping, adjust |srcRect| and |pixelSnapped
DestRect| over using a clip. |
| 135 if (!contentRect.contains(destRect)) { |
| 136 IntRect pixelSnappedContentRect = pixelSnappedIntRect(contentRect); |
| 137 pixelSnappedContentRect.intersect(pixelSnappedDestRect); |
| 138 if (pixelSnappedContentRect.isEmpty()) |
| 139 return; |
| 140 srcRect = mapRect(pixelSnappedContentRect, pixelSnappedDestRect, srcRect
); |
| 141 pixelSnappedDestRect = pixelSnappedContentRect; |
| 142 } |
| 139 | 143 |
| 140 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); | 144 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); |
| 141 | 145 |
| 142 InterpolationQuality previousInterpolationQuality = context.imageInterpolati
onQuality(); | 146 InterpolationQuality previousInterpolationQuality = context.imageInterpolati
onQuality(); |
| 143 context.setImageInterpolationQuality(interpolationQuality); | 147 context.setImageInterpolationQuality(interpolationQuality); |
| 144 context.drawImage(image.get(), alignedRect, nullptr, SkXfermode::kSrcOver_Mo
de, | 148 context.drawImage(image.get(), pixelSnappedDestRect, &srcRect, SkXfermode::k
SrcOver_Mode, |
| 145 LayoutObject::shouldRespectImageOrientation(&m_layoutImage)); | 149 LayoutObject::shouldRespectImageOrientation(&m_layoutImage)); |
| 146 context.setImageInterpolationQuality(previousInterpolationQuality); | 150 context.setImageInterpolationQuality(previousInterpolationQuality); |
| 147 } | 151 } |
| 148 | 152 |
| 149 } // namespace blink | 153 } // namespace blink |
| OLD | NEW |