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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
// Copyright 2016 The Chromium Authors
// 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/modules/csspaint/paint_rendering_context_2d.h"
#include <memory>
#include "third_party/blink/renderer/core/geometry/dom_matrix.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_2d_recorder_context.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_canvas.h"
namespace blink {
PaintRenderingContext2D::PaintRenderingContext2D(
const gfx::Size& container_size,
const PaintRenderingContext2DSettings* context_settings,
float zoom,
PaintWorkletGlobalScope* global_scope)
: Canvas2DRecorderContext(zoom),
paint_recorder_(container_size, this),
container_size_(container_size),
context_settings_(context_settings),
global_scope_(global_scope) {
scale(zoom, zoom);
clip_antialiasing_ = kAntiAliased;
GetState().SetShouldAntialias(true);
GetPaintCanvas()->clear(context_settings->alpha() ? SkColors::kTransparent
: SkColors::kBlack);
}
void PaintRenderingContext2D::InitializeForRecording(
cc::PaintCanvas* canvas) const {
RestoreMatrixClipStack(canvas);
}
void PaintRenderingContext2D::RecordingCleared() {
previous_frame_ = std::nullopt;
}
int PaintRenderingContext2D::Width() const {
return container_size_.width();
}
int PaintRenderingContext2D::Height() const {
return container_size_.height();
}
Color PaintRenderingContext2D::GetCurrentColor() const {
// We ignore "currentColor" for PaintRenderingContext2D and just make it
// "black". "currentColor" can be emulated by having "color" as an input
// property for the css-paint-api.
// https://github.com/w3c/css-houdini-drafts/issues/133
return Color::kBlack;
}
const cc::PaintCanvas* PaintRenderingContext2D::GetPaintCanvas() const {
return &paint_recorder_.getRecordingCanvas();
}
void PaintRenderingContext2D::WillDraw(const SkIRect&,
CanvasPerformanceMonitor::DrawType) {}
sk_sp<PaintFilter> PaintRenderingContext2D::StateGetFilter() {
return GetState().GetFilterForOffscreenCanvas(container_size_, this);
}
PredefinedColorSpace PaintRenderingContext2D::GetDefaultImageDataColorSpace()
const {
// PaintRenderingContext2D does not call getImageData or createImageData.
NOTREACHED();
}
void PaintRenderingContext2D::reset() {
Canvas2DRecorderContext::reset();
Canvas2DRecorderContext::transform(effective_zoom_, 0, 0, effective_zoom_, 0,
0);
}
PaintRecord PaintRenderingContext2D::GetRecord() {
if (!paint_recorder_.HasRecordedDrawOps() && !!previous_frame_) {
return *previous_frame_; // Reuse the previous frame
}
return paint_recorder_.ReleaseMainRecording();
}
} // namespace blink
|