blob: 83786fabdeb2892a4320c40e33588698837ccd00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/paint/html_canvas_painter.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/core/layout/layout_html_canvas.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/platform/geometry/layout_point.h"
#include "third_party/blink/renderer/platform/graphics/paint/drawing_recorder.h"
#include "third_party/blink/renderer/platform/graphics/paint/foreign_layer_display_item.h"
#include "third_party/blink/renderer/platform/graphics/scoped_interpolation_quality.h"
namespace blink {
namespace {
InterpolationQuality InterpolationQualityForCanvas(const ComputedStyle& style) {
if (style.ImageRendering() == EImageRendering::kWebkitOptimizeContrast)
return kInterpolationLow;
if (style.ImageRendering() == EImageRendering::kPixelated)
return kInterpolationNone;
return CanvasDefaultInterpolationQuality;
}
} // namespace
void HTMLCanvasPainter::PaintReplaced(const PaintInfo& paint_info,
const LayoutPoint& paint_offset) {
GraphicsContext& context = paint_info.context;
LayoutRect paint_rect = layout_html_canvas_.ReplacedContentRect();
paint_rect.MoveBy(paint_offset);
HTMLCanvasElement* canvas =
ToHTMLCanvasElement(layout_html_canvas_.GetNode());
if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) {
if (auto* layer = canvas->ContentsCcLayer()) {
IntRect pixel_snapped_rect = PixelSnappedIntRect(paint_rect);
layer->SetOffsetToTransformParent(
gfx::Vector2dF(pixel_snapped_rect.X(), pixel_snapped_rect.Y()));
layer->SetBounds(gfx::Size(pixel_snapped_rect.Size()));
layer->SetIsDrawable(true);
RecordForeignLayer(context, DisplayItem::kForeignLayerCanvas, layer);
if (layout_html_canvas_.GetFrameView()) {
layout_html_canvas_.GetFrameView()
->SetPaintArtifactCompositorNeedsUpdate();
}
return;
}
}
if (DrawingRecorder::UseCachedDrawingIfPossible(context, layout_html_canvas_,
paint_info.phase))
return;
DrawingRecorder recorder(context, layout_html_canvas_, paint_info.phase);
ScopedInterpolationQuality interpolation_quality_scope(
context, InterpolationQualityForCanvas(layout_html_canvas_.StyleRef()));
canvas->Paint(context, paint_rect);
}
} // namespace blink
|