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)) |
| 21 return; |
20 | 22 |
21 LayoutRect contentRect = m_layoutHTMLCanvas.contentBoxRect(); | 23 LayoutRect contentRect = m_layoutHTMLCanvas.contentBoxRect(); |
22 contentRect.moveBy(paintOffset); | 24 contentRect.moveBy(paintOffset); |
23 LayoutRect paintRect = m_layoutHTMLCanvas.replacedContentRect(); | 25 LayoutRect paintRect = m_layoutHTMLCanvas.replacedContentRect(); |
24 paintRect.moveBy(paintOffset); | 26 paintRect.moveBy(paintOffset); |
25 | 27 |
26 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutHTMLCanvas, pa
intInfo.phase, contentRect); | 28 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutHTMLCanvas, pa
intInfo.phase, contentRect); |
27 if (drawingRecorder.canUseCachedDrawing()) | |
28 return; | |
29 | |
30 #if ENABLE(ASSERT) | 29 #if ENABLE(ASSERT) |
31 // 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. |
32 drawingRecorder.setUnderInvalidationCheckingMode(DrawingDisplayItem::CheckBi
tmap); | 31 drawingRecorder.setUnderInvalidationCheckingMode(DrawingDisplayItem::CheckBi
tmap); |
33 #endif | 32 #endif |
34 | 33 |
35 bool clip = !contentRect.contains(paintRect); | 34 bool clip = !contentRect.contains(paintRect); |
36 if (clip) { | 35 if (clip) { |
37 context->save(); | 36 context->save(); |
38 context->clip(contentRect); | 37 context->clip(contentRect); |
39 } | 38 } |
40 | 39 |
41 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast
is set. | 40 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast
is set. |
42 // See bug for more details: crbug.com/353716. | 41 // See bug for more details: crbug.com/353716. |
43 InterpolationQuality interpolationQuality = m_layoutHTMLCanvas.style()->imag
eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul
tInterpolationQuality; | 42 InterpolationQuality interpolationQuality = m_layoutHTMLCanvas.style()->imag
eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul
tInterpolationQuality; |
44 if (m_layoutHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated) | 43 if (m_layoutHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated) |
45 interpolationQuality = InterpolationNone; | 44 interpolationQuality = InterpolationNone; |
46 | 45 |
47 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); | 46 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); |
48 context->setImageInterpolationQuality(interpolationQuality); | 47 context->setImageInterpolationQuality(interpolationQuality); |
49 toHTMLCanvasElement(m_layoutHTMLCanvas.node())->paint(context, paintRect); | 48 toHTMLCanvasElement(m_layoutHTMLCanvas.node())->paint(context, paintRect); |
50 context->setImageInterpolationQuality(previousInterpolationQuality); | 49 context->setImageInterpolationQuality(previousInterpolationQuality); |
51 | 50 |
52 if (clip) | 51 if (clip) |
53 context->restore(); | 52 context->restore(); |
54 } | 53 } |
55 | 54 |
56 } // namespace blink | 55 } // namespace blink |
OLD | NEW |