Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
GrSWMaskHelper Class Reference

#include <GrSWMaskHelper.h>

Inheritance diagram for GrSWMaskHelper:
SkNoncopyable

Public Member Functions

 GrSWMaskHelper (SkAutoPixmapStorage *pixels=nullptr)
 
bool init (const SkIRect &resultBounds)
 
void drawRect (const SkRect &rect, const SkMatrix &matrix, GrAA, uint8_t alpha)
 
void drawRRect (const SkRRect &rrect, const SkMatrix &matrix, GrAA, uint8_t alpha)
 
void drawShape (const GrStyledShape &, const SkMatrix &matrix, GrAA, uint8_t alpha)
 
void drawShape (const GrShape &, const SkMatrix &matrix, GrAA, uint8_t alpha)
 
GrSurfaceProxyView toTextureView (GrRecordingContext *, SkBackingFit fit)
 
void clear (uint8_t alpha)
 

Detailed Description

The GrSWMaskHelper helps generate clip masks using the software rendering path. It is intended to be used as:

GrSWMaskHelper helper(context); helper.init(...);

draw one or more paths/rects specifying the required boolean ops

toTextureView(); // to get it from the internal bitmap to the GPU

The result of this process will be the final mask (on the GPU) in the upper left hand corner of the texture.

Definition at line 39 of file GrSWMaskHelper.h.

Constructor & Destructor Documentation

◆ GrSWMaskHelper()

GrSWMaskHelper::GrSWMaskHelper ( SkAutoPixmapStorage pixels = nullptr)
inline

Definition at line 41 of file GrSWMaskHelper.h.

42 : fPixels(pixels ? pixels : &fPixelsStorage) { }

Member Function Documentation

◆ clear()

void GrSWMaskHelper::clear ( uint8_t  alpha)
inline

Definition at line 66 of file GrSWMaskHelper.h.

66 {
67 fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
68 }
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
bool erase(SkColor color, const SkIRect &subset) const
Definition: SkPixmap.cpp:742

◆ drawRect()

void GrSWMaskHelper::drawRect ( const SkRect rect,
const SkMatrix matrix,
GrAA  aa,
uint8_t  alpha 
)

Draw a single rect element of the clip stack into the accumulation bitmap

Definition at line 34 of file GrSWMaskHelper.cpp.

34 {
35 SkMatrix translatedMatrix = matrix;
36 translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
37 fDraw.fCTM = &translatedMatrix;
38
39 fDraw.drawRect(rect, get_paint(aa, alpha));
40}
static SkPaint get_paint(GrAA aa, uint8_t alpha)
void drawRect(const SkRect &prePaintRect, const SkPaint &, const SkMatrix *paintMatrix, const SkRect *postPaintRect) const
Definition: SkDrawBase.cpp:159
const SkMatrix * fCTM
Definition: SkDrawBase.h:155
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:281
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ drawRRect()

void GrSWMaskHelper::drawRRect ( const SkRRect rrect,
const SkMatrix matrix,
GrAA  aa,
uint8_t  alpha 
)

Definition at line 42 of file GrSWMaskHelper.cpp.

43 {
44 SkMatrix translatedMatrix = matrix;
45 translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
46 fDraw.fCTM = &translatedMatrix;
47
48 fDraw.drawRRect(rrect, get_paint(aa, alpha));
49}
void drawRRect(const SkRRect &, const SkPaint &) const
Definition: SkDrawBase.cpp:286
SkRRect rrect
Definition: SkRecords.h:232

◆ drawShape() [1/2]

void GrSWMaskHelper::drawShape ( const GrShape shape,
const SkMatrix matrix,
GrAA  aa,
uint8_t  alpha 
)

Definition at line 74 of file GrSWMaskHelper.cpp.

75 {
76 SkPaint paint = get_paint(aa, alpha);
77
78 SkMatrix translatedMatrix = matrix;
79 translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
80 fDraw.fCTM = &translatedMatrix;
81
82 if (shape.inverted()) {
83 if (shape.isEmpty() || shape.isLine() || shape.isPoint()) {
84 // These shapes are empty for simple fills, so when inverted, cover everything
85 fDraw.drawPaint(paint);
86 return;
87 }
88 // Else fall through to the draw method using asPath(), which will toggle fill type properly
89 } else if (shape.isEmpty() || shape.isLine() || shape.isPoint()) {
90 // Do nothing, these shapes do not cover any pixels for simple fills
91 return;
92 } else if (shape.isRect()) {
93 fDraw.drawRect(shape.rect(), paint);
94 return;
95 } else if (shape.isRRect()) {
96 fDraw.drawRRect(shape.rrect(), paint);
97 return;
98 }
99
100 // A complex, or inverse-filled shape, so go through drawPath.
101 SkPath path;
102 shape.asPath(&path);
103 if (0xFF == alpha) {
104 SkASSERT(0xFF == paint.getAlpha());
106 } else {
107 fDraw.drawPath(path, paint);
108 }
109}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkRect & rect()
Definition: GrShape.h:134
bool isRRect() const
Definition: GrShape.h:87
bool isLine() const
Definition: GrShape.h:90
SkRRect & rrect()
Definition: GrShape.h:137
bool isRect() const
Definition: GrShape.h:86
bool isPoint() const
Definition: GrShape.h:85
bool inverted() const
Definition: GrShape.h:99
void asPath(SkPath *out, bool simpleFill=true) const
Definition: GrShape.cpp:423
bool isEmpty() const
Definition: GrShape.h:84
void drawPath(const SkPath &path, const SkPaint &paint, const SkMatrix *prePathMatrix=nullptr, bool pathIsMutable=false) const
Definition: SkDrawBase.h:60
void drawPaint(const SkPaint &) const
Definition: SkDrawBase.cpp:74
void drawPathCoverage(const SkPath &src, const SkPaint &paint, SkBlitter *customBlitter=nullptr) const
Definition: SkDrawBase.h:71
Definition: SkPath.h:59
const Paint & paint
Definition: color_source.cc:38
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

◆ drawShape() [2/2]

void GrSWMaskHelper::drawShape ( const GrStyledShape shape,
const SkMatrix matrix,
GrAA  aa,
uint8_t  alpha 
)

Draw a single path element of the clip stack into the accumulation bitmap

Definition at line 54 of file GrSWMaskHelper.cpp.

55 {
56 SkPaint paint = get_paint(aa, alpha);
57 paint.setPathEffect(shape.style().refPathEffect());
59
60 SkMatrix translatedMatrix = matrix;
61 translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
62 fDraw.fCTM = &translatedMatrix;
63
65 shape.asPath(&path);
66 if (0xFF == alpha) {
67 SkASSERT(0xFF == paint.getAlpha());
69 } else {
70 fDraw.drawPath(path, paint);
71 }
72}
sk_sp< SkPathEffect > refPathEffect() const
Definition: GrStyle.h:120
const SkStrokeRec & strokeRec() const
Definition: GrStyle.h:140
void asPath(SkPath *out) const
const GrStyle & style() const
void applyToPaint(SkPaint *paint) const

◆ init()

bool GrSWMaskHelper::init ( const SkIRect resultBounds)

Definition at line 111 of file GrSWMaskHelper.cpp.

111 {
112 // We will need to translate draws so the bound's UL corner is at the origin
113 fTranslate = {-SkIntToScalar(resultBounds.fLeft), -SkIntToScalar(resultBounds.fTop)};
114 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), resultBounds.height());
115
116 const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(bounds.width(), bounds.height());
117 if (!fPixels->tryAlloc(bmImageInfo)) {
118 return false;
119 }
120 fPixels->erase(0);
121
123 fDraw.fDst = *fPixels;
124 fRasterClip.setRect(bounds);
125 fDraw.fRC = &fRasterClip;
126 return true;
127}
SkBlitter * SkA8Blitter_Choose(const SkPixmap &dst, const SkMatrix &ctm, const SkPaint &paint, SkArenaAlloc *alloc, bool drawCoverage, sk_sp< SkShader > clipShader, const SkSurfaceProps &)
#define SkIntToScalar(x)
Definition: SkScalar.h:57
bool tryAlloc(const SkImageInfo &)
BlitterChooser * fBlitterChooser
Definition: SkDrawBase.h:154
const SkRasterClip * fRC
Definition: SkDrawBase.h:156
SkPixmap fDst
Definition: SkDrawBase.h:153
bool setRect(const SkIRect &)
Optional< SkRect > bounds
Definition: SkRecords.h:189
Definition: SkRect.h:32
constexpr int32_t height() const
Definition: SkRect.h:165
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
constexpr int32_t width() const
Definition: SkRect.h:158
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
static SkImageInfo MakeA8(int width, int height)

◆ toTextureView()

GrSurfaceProxyView GrSWMaskHelper::toTextureView ( GrRecordingContext rContext,
SkBackingFit  fit 
)

Definition at line 129 of file GrSWMaskHelper.cpp.

129 {
130 SkImageInfo ii = SkImageInfo::MakeA8(fPixels->width(), fPixels->height());
131 size_t rowBytes = fPixels->rowBytes();
132
134 SkAssertResult(bitmap.installPixels(ii, fPixels->detachPixels(), rowBytes,
135 [](void* addr, void* context) { sk_free(addr); },
136 nullptr));
137 bitmap.setImmutable();
138
140}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, skgpu::Mipmapped mipmapped, SkBackingFit fit, skgpu::Budgeted budgeted)
Definition: SkGr.cpp:253
size_t rowBytes() const
Definition: SkPixmap.h:145
int width() const
Definition: SkPixmap.h:160
int height() const
Definition: SkPixmap.h:166
Definition: bitmap.py:1
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80

The documentation for this class was generated from the following files: