Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: third_party/WebKit/Source/core/paint/HTMLCanvasPainter.cpp

Issue 2121933003: [SPv2] Paint accelerated canvases as foreign layers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add 'override' keyword to StubChromeClientForSPv2::didPaint Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/HTMLCanvasPainter.h" 5 #include "core/paint/HTMLCanvasPainter.h"
6 6
7 #include "core/html/HTMLCanvasElement.h" 7 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/canvas/CanvasRenderingContext.h"
8 #include "core/layout/LayoutHTMLCanvas.h" 9 #include "core/layout/LayoutHTMLCanvas.h"
9 #include "core/paint/LayoutObjectDrawingRecorder.h" 10 #include "core/paint/LayoutObjectDrawingRecorder.h"
10 #include "core/paint/PaintInfo.h" 11 #include "core/paint/PaintInfo.h"
11 #include "platform/geometry/LayoutPoint.h" 12 #include "platform/geometry/LayoutPoint.h"
12 #include "platform/graphics/paint/ClipRecorder.h" 13 #include "platform/graphics/paint/ClipRecorder.h"
14 #include "platform/graphics/paint/ForeignLayerDisplayItem.h"
13 15
14 namespace blink { 16 namespace blink {
15 17
16 void HTMLCanvasPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPo int& paintOffset) 18 void HTMLCanvasPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPo int& paintOffset)
17 { 19 {
18 GraphicsContext& context = paintInfo.context; 20 GraphicsContext& context = paintInfo.context;
19 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_layou tHTMLCanvas, paintInfo.phase))
20 return;
21 21
22 LayoutRect contentRect = m_layoutHTMLCanvas.contentBoxRect(); 22 LayoutRect contentRect = m_layoutHTMLCanvas.contentBoxRect();
23 contentRect.moveBy(paintOffset); 23 contentRect.moveBy(paintOffset);
24 LayoutRect paintRect = m_layoutHTMLCanvas.replacedContentRect(); 24 LayoutRect paintRect = m_layoutHTMLCanvas.replacedContentRect();
25 paintRect.moveBy(paintOffset); 25 paintRect.moveBy(paintOffset);
26 26
27 HTMLCanvasElement* canvas = toHTMLCanvasElement(m_layoutHTMLCanvas.node());
28
29 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()
30 && canvas->renderingContext() && canvas->renderingContext()->isAccelerat ed()) {
31 if (WebLayer* layer = canvas->renderingContext()->platformLayer()) {
32 IntRect pixelSnappedRect = pixelSnappedIntRect(contentRect);
33 recordForeignLayer(
34 context, m_layoutHTMLCanvas, DisplayItem::ForeignLayerCanvas,
35 layer, pixelSnappedRect.location(), pixelSnappedRect.size());
36 return;
37 }
38 }
39
40 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_layou tHTMLCanvas, paintInfo.phase))
41 return;
42
27 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutHTMLCanvas, pai ntInfo.phase, contentRect); 43 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutHTMLCanvas, pai ntInfo.phase, contentRect);
28 #if ENABLE(ASSERT) 44 #if ENABLE(ASSERT)
29 // The drawing may be in display list mode or image mode, producing differen t pictures for the same result. 45 // The drawing may be in display list mode or image mode, producing differen t pictures for the same result.
30 drawingRecorder.setUnderInvalidationCheckingMode(DrawingDisplayItem::CheckBi tmap); 46 drawingRecorder.setUnderInvalidationCheckingMode(DrawingDisplayItem::CheckBi tmap);
31 #endif 47 #endif
32 48
33 bool clip = !contentRect.contains(paintRect); 49 bool clip = !contentRect.contains(paintRect);
34 if (clip) { 50 if (clip) {
35 context.save(); 51 context.save();
36 // TODO(chrishtr): this should be pixel-snapped. 52 // TODO(chrishtr): this should be pixel-snapped.
37 context.clip(FloatRect(contentRect)); 53 context.clip(FloatRect(contentRect));
38 } 54 }
39 55
40 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast is set. 56 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast is set.
41 // See bug for more details: crbug.com/353716. 57 // See bug for more details: crbug.com/353716.
42 InterpolationQuality interpolationQuality = m_layoutHTMLCanvas.style()->imag eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul tInterpolationQuality; 58 InterpolationQuality interpolationQuality = m_layoutHTMLCanvas.style()->imag eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul tInterpolationQuality;
43 if (m_layoutHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated) 59 if (m_layoutHTMLCanvas.style()->imageRendering() == ImageRenderingPixelated)
44 interpolationQuality = InterpolationNone; 60 interpolationQuality = InterpolationNone;
45 61
46 InterpolationQuality previousInterpolationQuality = context.imageInterpolati onQuality(); 62 InterpolationQuality previousInterpolationQuality = context.imageInterpolati onQuality();
47 context.setImageInterpolationQuality(interpolationQuality); 63 context.setImageInterpolationQuality(interpolationQuality);
48 toHTMLCanvasElement(m_layoutHTMLCanvas.node())->paint(context, paintRect); 64 canvas->paint(context, paintRect);
49 context.setImageInterpolationQuality(previousInterpolationQuality); 65 context.setImageInterpolationQuality(previousInterpolationQuality);
50 66
51 if (clip) 67 if (clip)
52 context.restore(); 68 context.restore();
53 } 69 }
54 70
55 } // namespace blink 71 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/paint/HTMLCanvasPainterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698