Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
SkRgnBuilder Class Reference
Inheritance diagram for SkRgnBuilder:
SkBlitter

Public Member Functions

 SkRgnBuilder ()
 
 ~SkRgnBuilder () override
 
bool init (int maxHeight, int maxTransitions, bool pathIsInverse)
 
void done ()
 
int computeRunCount () const
 
void copyToRect (SkIRect *) const
 
void copyToRgn (SkRegion::RunType runs[]) const
 
void blitH (int x, int y, int width) override
 Blit a horizontal run of one or more pixels.
 
void blitAntiH (int x, int y, const SkAlpha antialias[], const int16_t runs[]) override
 
- Public Member Functions inherited from SkBlitter
virtual ~SkBlitter ()
 
virtual void blitV (int x, int y, int height, SkAlpha alpha)
 Blit a vertical run of pixels with a constant alpha value.
 
virtual void blitRect (int x, int y, int width, int height)
 Blit a solid rectangle one or more pixels wide.
 
virtual void blitAntiRect (int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha)
 
void blitFatAntiRect (const SkRect &rect)
 
virtual void blitMask (const SkMask &, const SkIRect &clip)
 
virtual void blitAntiH2 (int x, int y, U8CPU a0, U8CPU a1)
 
virtual void blitAntiV2 (int x, int y, U8CPU a0, U8CPU a1)
 
virtual bool isNullBlitter () const
 
virtual int requestRowsPreserved () const
 
virtual void * allocBlitMemory (size_t sz)
 
void blitRectRegion (const SkIRect &rect, const SkRegion &clip)
 
void blitRegion (const SkRegion &clip)
 

Additional Inherited Members

- Static Public Member Functions inherited from SkBlitter
static bool UseLegacyBlitter (const SkPixmap &, const SkPaint &, const SkMatrix &)
 
static SkBlitterChoose (const SkPixmap &dst, const SkMatrix &ctm, const SkPaint &paint, SkArenaAlloc *, bool drawCoverage, sk_sp< SkShader > clipShader, const SkSurfaceProps &props)
 
static SkBlitterChooseSprite (const SkPixmap &dst, const SkPaint &, const SkPixmap &src, int left, int top, SkArenaAlloc *, sk_sp< SkShader > clipShader)
 
- Protected Attributes inherited from SkBlitter
SkAutoMalloc fBlitMemory
 

Detailed Description

Definition at line 44 of file SkRegion_path.cpp.

Constructor & Destructor Documentation

◆ SkRgnBuilder()

SkRgnBuilder::SkRgnBuilder ( )

Definition at line 131 of file SkRegion_path.cpp.

132 : fStorage(nullptr) {
133}

◆ ~SkRgnBuilder()

SkRgnBuilder::~SkRgnBuilder ( )
override

Definition at line 135 of file SkRegion_path.cpp.

135 {
136 sk_free(fStorage);
137}
SK_API void sk_free(void *)

Member Function Documentation

◆ blitAntiH()

void SkRgnBuilder::blitAntiH ( int  x,
int  y,
const SkAlpha  antialias[],
const int16_t  runs[] 
)
inlineoverridevirtual

Blit a horizontal run of antialiased pixels; runs[] is a sparse zero-terminated run-length encoding of spans of constant alpha values. The runs[] and antialias[] work together to represent long runs of pixels with the same alphas. The runs[] contains the number of pixels with the same alpha, and antialias[] contain the coverage value for that number of pixels. The runs[] (and antialias[]) are encoded in a clever way. The runs array is zero terminated, and has enough entries for each pixel plus one, in most cases some of the entries will not contain valid data. An entry in the runs array contains the number of pixels (np) that have the same alpha value. The next np value is found np entries away. For example, if runs[0] = 7, then the next valid entry will by at runs[7]. The runs array and antialias[] are coupled by index. So, if the np entry is at runs[45] = 12 then the alpha value can be found at antialias[45] = 0x88. This would mean to use an alpha value of 0x88 for the next 12 pixels starting at pixel 45.

Implements SkBlitter.

Definition at line 66 of file SkRegion_path.cpp.

66 {
67 SkDEBUGFAIL("blitAntiH not implemented");
68 }
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118

◆ blitH()

void SkRgnBuilder::blitH ( int  x,
int  y,
int  width 
)
overridevirtual

Blit a horizontal run of one or more pixels.

Implements SkBlitter.

Definition at line 177 of file SkRegion_path.cpp.

177 {
178 if (fCurrScanline == nullptr) { // first time
179 fTop = (SkRegion::RunType)(y);
180 fCurrScanline = (Scanline*)fStorage;
181 fCurrScanline->fLastY = (SkRegion::RunType)(y);
182 fCurrXPtr = fCurrScanline->firstX();
183 } else {
184 SkASSERT(y >= fCurrScanline->fLastY);
185
186 if (y > fCurrScanline->fLastY) {
187 // if we get here, we're done with fCurrScanline
188 fCurrScanline->fXCount = (SkRegion::RunType)((int)(fCurrXPtr - fCurrScanline->firstX()));
189
190 int prevLastY = fCurrScanline->fLastY;
191 if (!this->collapsWithPrev()) {
192 fPrevScanline = fCurrScanline;
193 fCurrScanline = fCurrScanline->nextScanline();
194
195 }
196 if (y - 1 > prevLastY) { // insert empty run
197 fCurrScanline->fLastY = (SkRegion::RunType)(y - 1);
198 fCurrScanline->fXCount = 0;
199 fCurrScanline = fCurrScanline->nextScanline();
200 }
201 // setup for the new curr line
202 fCurrScanline->fLastY = (SkRegion::RunType)(y);
203 fCurrXPtr = fCurrScanline->firstX();
204 }
205 }
206 // check if we should extend the current run, or add a new one
207 if (fCurrXPtr > fCurrScanline->firstX() && fCurrXPtr[-1] == x) {
208 fCurrXPtr[-1] = (SkRegion::RunType)(x + width);
209 } else {
210 fCurrXPtr[0] = (SkRegion::RunType)(x);
211 fCurrXPtr[1] = (SkRegion::RunType)(x + width);
212 fCurrXPtr += 2;
213 }
214 SkASSERT(fCurrXPtr - fStorage < fStorageCount);
215}
#define SkASSERT(cond)
Definition SkAssert.h:116
double y
double x
int32_t width

◆ computeRunCount()

int SkRgnBuilder::computeRunCount ( ) const

Definition at line 217 of file SkRegion_path.cpp.

217 {
218 if (fCurrScanline == nullptr) {
219 return 0;
220 }
221
222 const SkRegion::RunType* line = fStorage;
223 const SkRegion::RunType* stop = (const SkRegion::RunType*)fCurrScanline;
224
225 return 2 + (int)(stop - line);
226}
Type::kYUV Type::kRGBA() int(0.7 *637)

◆ copyToRect()

void SkRgnBuilder::copyToRect ( SkIRect r) const

Definition at line 228 of file SkRegion_path.cpp.

228 {
229 SkASSERT(fCurrScanline != nullptr);
230 // A rect's scanline is [bottom intervals left right sentinel] == 5
231 SkASSERT((const SkRegion::RunType*)fCurrScanline - fStorage == 5);
232
233 Scanline* line = (Scanline*)fStorage;
234 SkASSERT(line->fXCount == 2);
235
236 r->setLTRB(line->firstX()[0], fTop, line->firstX()[1], line->fLastY + 1);
237}
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
Definition SkRect.h:253

◆ copyToRgn()

void SkRgnBuilder::copyToRgn ( SkRegion::RunType  runs[]) const

Definition at line 239 of file SkRegion_path.cpp.

239 {
240 SkASSERT(fCurrScanline != nullptr);
241 SkASSERT((const SkRegion::RunType*)fCurrScanline - fStorage > 4);
242
243 Scanline* line = (Scanline*)fStorage;
244 const Scanline* stop = fCurrScanline;
245
246 *runs++ = fTop;
247 do {
248 *runs++ = (SkRegion::RunType)(line->fLastY + 1);
249 int count = line->fXCount;
250 *runs++ = count >> 1; // intervalCount
251 if (count) {
252 memcpy(runs, line->firstX(), count * sizeof(SkRegion::RunType));
253 runs += count;
254 }
256 line = line->nextScanline();
257 } while (line < stop);
258 SkASSERT(line == stop);
260}
int count
static constexpr int SkRegion_kRunTypeSentinel

◆ done()

void SkRgnBuilder::done ( )
inline

Definition at line 52 of file SkRegion_path.cpp.

52 {
53 if (fCurrScanline != nullptr) {
54 fCurrScanline->fXCount = (SkRegion::RunType)((int)(fCurrXPtr - fCurrScanline->firstX()));
55 if (!this->collapsWithPrev()) { // flush the last line
56 fCurrScanline = fCurrScanline->nextScanline();
57 }
58 }
59 }

◆ init()

bool SkRgnBuilder::init ( int  maxHeight,
int  maxTransitions,
bool  pathIsInverse 
)

Definition at line 139 of file SkRegion_path.cpp.

139 {
140 if ((maxHeight | maxTransitions) < 0) {
141 return false;
142 }
143
144 SkSafeMath safe;
145
146 if (pathIsInverse) {
147 // allow for additional X transitions to "invert" each scanline
148 // [ L' ... normal transitions ... R' ]
149 //
150 maxTransitions = safe.addInt(maxTransitions, 2);
151 }
152
153 // compute the count with +1 and +3 slop for the working buffer
154 size_t count = safe.mul(safe.addInt(maxHeight, 1), safe.addInt(3, maxTransitions));
155
156 if (pathIsInverse) {
157 // allow for two "empty" rows for the top and bottom
158 // [ Y, 1, L, R, S] == 5 (*2 for top and bottom)
159 count = safe.add(count, 10);
160 }
161
162 if (!safe || !SkTFitsIn<int32_t>(count)) {
163 return false;
164 }
165 fStorageCount = SkToS32(count);
166
167 fStorage = (SkRegion::RunType*)sk_malloc_canfail(fStorageCount, sizeof(SkRegion::RunType));
168 if (nullptr == fStorage) {
169 return false;
170 }
171
172 fCurrScanline = nullptr; // signal empty collection
173 fPrevScanline = nullptr; // signal first scanline
174 return true;
175}
static void * sk_malloc_canfail(size_t size)
Definition SkMalloc.h:93
constexpr int32_t SkToS32(S x)
Definition SkTo.h:25
int addInt(int a, int b)
Definition SkSafeMath.h:43
size_t add(size_t x, size_t y)
Definition SkSafeMath.h:33
size_t mul(size_t x, size_t y)
Definition SkSafeMath.h:29

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