File: paint_rendering_context_2d.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (90 lines) | stat: -rw-r--r-- 2,908 bytes parent folder | download | duplicates (5)
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