Flutter Engine
The Flutter Engine
SkDrawBase.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkDrawBase_DEFINED
9#define SkDrawBase_DEFINED
10
18#include "src/base/SkZip.h"
20#include "src/core/SkMask.h"
21
22#include <cstddef>
23
24class SkArenaAlloc;
25class SkBitmap;
26class SkBlitter;
27class SkDevice;
28class SkGlyph;
29class SkMaskFilter;
30class SkMatrix;
31class SkPath;
32class SkRRect;
33class SkRasterClip;
34class SkShader;
35class SkSurfaceProps;
36struct SkIRect;
37struct SkPoint;
38struct SkRect;
39
41public:
42 SkDrawBase();
43
44 void drawPaint(const SkPaint&) const;
45 void drawRect(const SkRect& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix,
46 const SkRect* postPaintRect) const;
47 void drawRect(const SkRect& rect, const SkPaint& paint) const {
48 this->drawRect(rect, paint, nullptr, nullptr);
49 }
50 void drawRRect(const SkRRect&, const SkPaint&) const;
51 /**
52 * To save on mallocs, we allow a flag that tells us that srcPath is
53 * mutable, so that we don't have to make copies of it as we transform it.
54 *
55 * If prePathMatrix is not null, it should logically be applied before any
56 * stroking or other effects. If there are no effects on the paint that
57 * affect the geometry/rasterization, then the pre matrix can just be
58 * pre-concated with the current matrix.
59 */
60 void drawPath(const SkPath& path, const SkPaint& paint,
61 const SkMatrix* prePathMatrix = nullptr, bool pathIsMutable = false) const {
62 this->drawPath(path, paint, prePathMatrix, pathIsMutable, false);
63 }
64
65 /**
66 * Overwrite the target with the path's coverage (i.e. its mask).
67 * Will overwrite the entire device, so it need not be zero'd first.
68 *
69 * Only device A8 is supported right now.
70 */
72 SkBlitter* customBlitter = nullptr) const {
73 bool isHairline = paint.getStyle() == SkPaint::kStroke_Style &&
74 paint.getStrokeWidth() == 0;
75 this->drawPath(src, paint, nullptr, false, !isHairline, customBlitter);
76 }
77
78 void drawDevicePoints(SkCanvas::PointMode, size_t count, const SkPoint[], const SkPaint&,
79 SkDevice*) const;
80
81 static bool ComputeMaskBounds(const SkRect& devPathBounds, const SkIRect& clipBounds,
82 const SkMaskFilter* filter, const SkMatrix* filterMatrix,
84
85 /** Helper function that creates a mask from a path and an optional maskfilter.
86 Note however, that the resulting mask will not have been actually filtered,
87 that must be done afterwards (by calling filterMask). The maskfilter is provided
88 solely to assist in computing the mask's bounds (if the mode requests that).
89 */
90 static bool DrawToMask(const SkPath& devPath, const SkIRect& clipBounds,
91 const SkMaskFilter*, const SkMatrix* filterMatrix,
94
95 enum RectType {
100 };
101
102 /**
103 * Based on the paint's style, strokeWidth, and the matrix, classify how
104 * to draw the rect. If no special-case is available, returns
105 * kPath_RectType.
106 *
107 * Iff RectType == kStroke_RectType, then strokeSize is set to the device
108 * width and height of the stroke.
109 */
110 static RectType ComputeRectType(const SkRect&, const SkPaint&, const SkMatrix&,
111 SkPoint* strokeSize);
112
114 const SkMatrix& ctm,
115 const SkPaint&,
117 bool drawCoverage,
118 sk_sp<SkShader> clipShader,
119 const SkSurfaceProps&);
120
121
122private:
123 // not supported
124 void paintMasks(SkZip<const SkGlyph*, SkPoint> accepted, const SkPaint& paint) const override;
125 void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull,
126 const SkSamplingOptions&, const SkPaint&) const override;
127
128 void drawPath(const SkPath&,
129 const SkPaint&,
130 const SkMatrix* preMatrix,
131 bool pathIsMutable,
132 bool drawCoverage,
133 SkBlitter* customBlitter = nullptr) const;
134
135 void drawLine(const SkPoint[2], const SkPaint&) const;
136
137 void drawDevPath(const SkPath& devPath,
138 const SkPaint& paint,
139 bool drawCoverage,
140 SkBlitter* customBlitter,
141 bool doFill) const;
142 /**
143 * Return the current clip bounds, in local coordinates, with slop to account
144 * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then
145 * run through the inverse of the matrix).
146 *
147 * If the matrix cannot be inverted, or the current clip is empty, return
148 * false and ignore bounds parameter.
149 */
150 [[nodiscard]] bool computeConservativeLocalClipBounds(SkRect* bounds) const;
151
152public:
154 BlitterChooser* fBlitterChooser{nullptr}; // required
155 const SkMatrix* fCTM{nullptr}; // required
156 const SkRasterClip* fRC{nullptr}; // required
157 const SkSurfaceProps* fProps{nullptr}; // optional
158
159#ifdef SK_DEBUG
160 void validate() const;
161#else
162 void validate() const {}
163#endif
164};
165
166#endif // SkDrawBase_DEFINED
int count
Definition: FontMgrTest.cpp:50
@ kFill_RectType
Definition: SkDrawBase.h:97
@ kPath_RectType
Definition: SkDrawBase.h:99
@ kHair_RectType
Definition: SkDrawBase.h:96
@ kStroke_RectType
Definition: SkDrawBase.h:98
void drawRect(const SkRect &rect, const SkPaint &paint) const
Definition: SkDrawBase.h:47
void drawRRect(const SkRRect &, const SkPaint &) const
Definition: SkDrawBase.cpp:286
BlitterChooser * fBlitterChooser
Definition: SkDrawBase.h:154
void drawPath(const SkPath &path, const SkPaint &paint, const SkMatrix *prePathMatrix=nullptr, bool pathIsMutable=false) const
Definition: SkDrawBase.h:60
static bool DrawToMask(const SkPath &devPath, const SkIRect &clipBounds, const SkMaskFilter *, const SkMatrix *filterMatrix, SkMaskBuilder *dst, SkMaskBuilder::CreateMode mode, SkStrokeRec::InitStyle style)
Definition: SkDrawBase.cpp:559
static bool ComputeMaskBounds(const SkRect &devPathBounds, const SkIRect &clipBounds, const SkMaskFilter *filter, const SkMatrix *filterMatrix, SkIRect *bounds)
Definition: SkDrawBase.cpp:494
void drawPaint(const SkPaint &) const
Definition: SkDrawBase.cpp:74
const SkSurfaceProps * fProps
Definition: SkDrawBase.h:157
const SkRasterClip * fRC
Definition: SkDrawBase.h:156
void drawPathCoverage(const SkPath &src, const SkPaint &paint, SkBlitter *customBlitter=nullptr) const
Definition: SkDrawBase.h:71
void drawRect(const SkRect &prePaintRect, const SkPaint &, const SkMatrix *paintMatrix, const SkRect *postPaintRect) const
Definition: SkDrawBase.cpp:159
SkPixmap fDst
Definition: SkDrawBase.h:153
void validate() const
Definition: SkDrawBase.h:162
static RectType ComputeRectType(const SkRect &, const SkPaint &, const SkMatrix &, SkPoint *strokeSize)
Definition: SkDrawBase.cpp:111
SkBlitter *(const SkPixmap &dst, const SkMatrix &ctm, const SkPaint &, SkArenaAlloc *, bool drawCoverage, sk_sp< SkShader > clipShader, const SkSurfaceProps &) BlitterChooser
Definition: SkDrawBase.h:119
const SkMatrix * fCTM
Definition: SkDrawBase.h:155
void drawDevicePoints(SkCanvas::PointMode, size_t count, const SkPoint[], const SkPaint &, SkDevice *) const
Definition: SkDrawBase.cpp:597
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
Definition: SkZip.h:25
const Paint & paint
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
dst
Definition: cp.py:12
Definition: SkRect.h:32