| 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/HTMLCanvasPainter.h" | 6 #include "core/paint/HTMLCanvasPainter.h" |
| 7 | 7 |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/paint/ClipRecorder.h" | |
| 10 #include "core/paint/DrawingRecorder.h" | |
| 11 #include "core/rendering/PaintInfo.h" | 9 #include "core/rendering/PaintInfo.h" |
| 12 #include "core/rendering/RenderHTMLCanvas.h" | 10 #include "core/rendering/RenderHTMLCanvas.h" |
| 13 #include "platform/geometry/LayoutPoint.h" | 11 #include "platform/geometry/LayoutPoint.h" |
| 14 | 12 |
| 15 namespace blink { | 13 namespace blink { |
| 16 | 14 |
| 17 void HTMLCanvasPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) | 15 void HTMLCanvasPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) |
| 18 { | 16 { |
| 19 GraphicsContext* context = paintInfo.context; | 17 GraphicsContext* context = paintInfo.context; |
| 20 | 18 |
| 21 LayoutRect contentRect = m_renderHTMLCanvas.contentBoxRect(); | 19 LayoutRect contentRect = m_renderHTMLCanvas.contentBoxRect(); |
| 22 contentRect.moveBy(paintOffset); | 20 contentRect.moveBy(paintOffset); |
| 23 LayoutRect paintRect = m_renderHTMLCanvas.replacedContentRect(); | 21 LayoutRect paintRect = m_renderHTMLCanvas.replacedContentRect(); |
| 24 paintRect.moveBy(paintOffset); | 22 paintRect.moveBy(paintOffset); |
| 25 | 23 |
| 26 PaintInfo localPaintInfo(paintInfo); | |
| 27 OwnPtr<ClipRecorder> clipRecorder; | |
| 28 bool clip = !contentRect.contains(paintRect); | 24 bool clip = !contentRect.contains(paintRect); |
| 29 if (clip) | 25 if (clip) { |
| 30 clipRecorder = adoptPtr(new ClipRecorder(m_renderHTMLCanvas, paintInfo,
contentRect)); | 26 // Not allowed to overflow the content box. |
| 27 paintInfo.context->save(); |
| 28 paintInfo.context->clip(pixelSnappedIntRect(contentRect)); |
| 29 } |
| 31 | 30 |
| 32 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast
is set. | 31 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast
is set. |
| 33 // See bug for more details: crbug.com/353716. | 32 // See bug for more details: crbug.com/353716. |
| 34 InterpolationQuality interpolationQuality = m_renderHTMLCanvas.style()->imag
eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul
tInterpolationQuality; | 33 InterpolationQuality interpolationQuality = m_renderHTMLCanvas.style()->imag
eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul
tInterpolationQuality; |
| 35 | 34 |
| 36 HTMLCanvasElement* canvas = toHTMLCanvasElement(m_renderHTMLCanvas.node()); | 35 HTMLCanvasElement* canvas = toHTMLCanvasElement(m_renderHTMLCanvas.node()); |
| 37 LayoutSize layoutSize = contentRect.size(); | 36 LayoutSize layoutSize = contentRect.size(); |
| 38 if (m_renderHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated | 37 if (m_renderHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated |
| 39 && (layoutSize.width() > canvas->width() || layoutSize.height() > canvas
->height() || layoutSize == canvas->size())) { | 38 && (layoutSize.width() > canvas->width() || layoutSize.height() > canvas
->height() || layoutSize == canvas->size())) { |
| 40 interpolationQuality = InterpolationNone; | 39 interpolationQuality = InterpolationNone; |
| 41 } | 40 } |
| 42 | 41 |
| 43 DrawingRecorder recorder(context, &m_renderHTMLCanvas, localPaintInfo.phase,
pixelSnappedIntRect(paintRect)); | |
| 44 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); | 42 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); |
| 45 context->setImageInterpolationQuality(interpolationQuality); | 43 context->setImageInterpolationQuality(interpolationQuality); |
| 46 canvas->paint(context, paintRect); | 44 canvas->paint(context, paintRect); |
| 47 context->setImageInterpolationQuality(previousInterpolationQuality); | 45 context->setImageInterpolationQuality(previousInterpolationQuality); |
| 46 |
| 47 if (clip) |
| 48 context->restore(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 } // namespace blink | 51 } // namespace blink |
| OLD | NEW |