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
3 // found in the LICENSE file.
6 #include "core/paint/HTMLCanvasPainter.h"
8 #include "core/html/HTMLCanvasElement.h"
9 #include "core/rendering/PaintInfo.h"
10 #include "core/rendering/RenderHTMLCanvas.h"
11 #include "platform/geometry/LayoutPoint.h"
15 void HTMLCanvasPainter::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
17 GraphicsContext* context = paintInfo.context;
19 LayoutRect contentRect = m_renderHTMLCanvas.contentBoxRect();
20 contentRect.moveBy(paintOffset);
21 LayoutRect paintRect = m_renderHTMLCanvas.replacedContentRect();
22 paintRect.moveBy(paintOffset);
24 bool clip = !contentRect.contains(paintRect);
26 // Not allowed to overflow the content box.
27 paintInfo.context->save();
28 paintInfo.context->clip(pixelSnappedIntRect(contentRect));
31 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast is set.
32 // See bug for more details: crbug.com/353716.
33 InterpolationQuality interpolationQuality = m_renderHTMLCanvas.style()->imageRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaultInterpolationQuality;
35 HTMLCanvasElement* canvas = toHTMLCanvasElement(m_renderHTMLCanvas.node());
36 LayoutSize layoutSize = contentRect.size();
37 if (m_renderHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated
38 && (layoutSize.width() > canvas->width() || layoutSize.height() > canvas->height() || layoutSize == canvas->size())) {
39 interpolationQuality = InterpolationNone;
42 InterpolationQuality previousInterpolationQuality = context->imageInterpolationQuality();
43 context->setImageInterpolationQuality(interpolationQuality);
44 canvas->paint(context, paintRect);
45 context->setImageInterpolationQuality(previousInterpolationQuality);