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/layout/LayoutHTMLCanvas.h" | 9 #include "core/layout/LayoutHTMLCanvas.h" |
10 #include "core/paint/LayoutObjectDrawingRecorder.h" | 10 #include "core/paint/LayoutObjectDrawingRecorder.h" |
11 #include "core/paint/PaintInfo.h" | 11 #include "core/paint/PaintInfo.h" |
12 #include "platform/geometry/LayoutPoint.h" | 12 #include "platform/geometry/LayoutPoint.h" |
13 #include "platform/graphics/paint/ClipRecorder.h" | 13 #include "platform/graphics/paint/ClipRecorder.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 void HTMLCanvasPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) | 17 void HTMLCanvasPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) |
18 { | 18 { |
19 GraphicsContext* context = paintInfo.context; | 19 GraphicsContext& context = paintInfo.context; |
20 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, m_layo
utHTMLCanvas, paintInfo.phase, paintOffset)) | 20 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_layou
tHTMLCanvas, paintInfo.phase, paintOffset)) |
21 return; | 21 return; |
22 | 22 |
23 LayoutRect contentRect = m_layoutHTMLCanvas.contentBoxRect(); | 23 LayoutRect contentRect = m_layoutHTMLCanvas.contentBoxRect(); |
24 contentRect.moveBy(paintOffset); | 24 contentRect.moveBy(paintOffset); |
25 LayoutRect paintRect = m_layoutHTMLCanvas.replacedContentRect(); | 25 LayoutRect paintRect = m_layoutHTMLCanvas.replacedContentRect(); |
26 paintRect.moveBy(paintOffset); | 26 paintRect.moveBy(paintOffset); |
27 | 27 |
28 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutHTMLCanvas, pa
intInfo.phase, contentRect, paintOffset); | 28 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutHTMLCanvas, pai
ntInfo.phase, contentRect, paintOffset); |
29 #if ENABLE(ASSERT) | 29 #if ENABLE(ASSERT) |
30 // The drawing may be in display list mode or image mode, producing differen
t pictures for the same result. | 30 // The drawing may be in display list mode or image mode, producing differen
t pictures for the same result. |
31 drawingRecorder.setUnderInvalidationCheckingMode(DrawingDisplayItem::CheckBi
tmap); | 31 drawingRecorder.setUnderInvalidationCheckingMode(DrawingDisplayItem::CheckBi
tmap); |
32 #endif | 32 #endif |
33 | 33 |
34 bool clip = !contentRect.contains(paintRect); | 34 bool clip = !contentRect.contains(paintRect); |
35 if (clip) { | 35 if (clip) { |
36 context->save(); | 36 context.save(); |
37 // TODO(chrishtr): this should be pixel-snapped. | 37 // TODO(chrishtr): this should be pixel-snapped. |
38 context->clip(FloatRect(contentRect)); | 38 context.clip(FloatRect(contentRect)); |
39 } | 39 } |
40 | 40 |
41 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast
is set. | 41 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast
is set. |
42 // See bug for more details: crbug.com/353716. | 42 // See bug for more details: crbug.com/353716. |
43 InterpolationQuality interpolationQuality = m_layoutHTMLCanvas.style()->imag
eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul
tInterpolationQuality; | 43 InterpolationQuality interpolationQuality = m_layoutHTMLCanvas.style()->imag
eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul
tInterpolationQuality; |
44 if (m_layoutHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated) | 44 if (m_layoutHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated) |
45 interpolationQuality = InterpolationNone; | 45 interpolationQuality = InterpolationNone; |
46 | 46 |
47 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); | 47 InterpolationQuality previousInterpolationQuality = context.imageInterpolati
onQuality(); |
48 context->setImageInterpolationQuality(interpolationQuality); | 48 context.setImageInterpolationQuality(interpolationQuality); |
49 toHTMLCanvasElement(m_layoutHTMLCanvas.node())->paint(context, paintRect); | 49 toHTMLCanvasElement(m_layoutHTMLCanvas.node())->paint(context, paintRect); |
50 context->setImageInterpolationQuality(previousInterpolationQuality); | 50 context.setImageInterpolationQuality(previousInterpolationQuality); |
51 | 51 |
52 if (clip) | 52 if (clip) |
53 context->restore(); | 53 context.restore(); |
54 } | 54 } |
55 | 55 |
56 } // namespace blink | 56 } // namespace blink |
OLD | NEW |