Flutter Engine
The Flutter Engine
GrSWMaskHelper.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
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
9
18#include "src/gpu/ganesh/SkGr.h"
21
22static SkPaint get_paint(GrAA aa, uint8_t alpha) {
24 paint.setBlendMode(SkBlendMode::kSrc); // "Replace" mode
25 paint.setAntiAlias(GrAA::kYes == aa);
26 // SkPaint's color is unpremul so this will produce alpha in every channel.
27 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255));
28 return paint;
29}
30
31/**
32 * Draw a single rect element of the clip stack into the accumulation bitmap
33 */
34void GrSWMaskHelper::drawRect(const SkRect& rect, const SkMatrix& matrix, GrAA aa, uint8_t alpha) {
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}
41
43 GrAA aa, uint8_t alpha) {
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}
50
51/**
52 * Draw a single path element of the clip stack into the accumulation bitmap
53 */
55 GrAA aa, uint8_t alpha) {
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}
73
75 GrAA aa, uint8_t alpha) {
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}
110
111bool GrSWMaskHelper::init(const SkIRect& resultBounds) {
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}
128
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)
static SkPaint get_paint(GrAA aa, uint8_t alpha)
GrAA
Definition: GrTypesPriv.h:173
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBackingFit
Definition: SkBackingFit.h:16
SkBlitter * SkA8Blitter_Choose(const SkPixmap &dst, const SkMatrix &ctm, const SkPaint &paint, SkArenaAlloc *alloc, bool drawCoverage, sk_sp< SkShader > clipShader, const SkSurfaceProps &)
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, skgpu::Mipmapped mipmapped, SkBackingFit fit, skgpu::Budgeted budgeted)
Definition: SkGr.cpp:253
#define SkIntToScalar(x)
Definition: SkScalar.h:57
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)
bool init(const SkIRect &resultBounds)
GrSurfaceProxyView toTextureView(GrRecordingContext *, SkBackingFit fit)
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
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
bool tryAlloc(const SkImageInfo &)
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
void drawPaint(const SkPaint &) const
Definition: SkDrawBase.cpp:74
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
const SkMatrix * fCTM
Definition: SkDrawBase.h:155
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:281
Definition: SkPath.h:59
bool erase(SkColor color, const SkIRect &subset) const
Definition: SkPixmap.cpp:742
size_t rowBytes() const
Definition: SkPixmap.h:145
int width() const
Definition: SkPixmap.h:160
int height() const
Definition: SkPixmap.h:166
bool setRect(const SkIRect &)
void applyToPaint(SkPaint *paint) const
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Definition: bitmap.py:1
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
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80
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)
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165