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

#include <SkBlitter.h>

Inheritance diagram for SkRectClipBlitter:
SkBlitter

Public Member Functions

void init (SkBlitter *blitter, const SkIRect &clipRect)
 
void blitH (int x, int y, int width) override
 Blit a horizontal run of one or more pixels. More...
 
void blitAntiH (int x, int y, const SkAlpha[], const int16_t runs[]) override
 
void blitV (int x, int y, int height, SkAlpha alpha) override
 Blit a vertical run of pixels with a constant alpha value. More...
 
void blitRect (int x, int y, int width, int height) override
 Blit a solid rectangle one or more pixels wide. More...
 
void blitAntiRect (int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha) override
 
void blitMask (const SkMask &, const SkIRect &clip) override
 
int requestRowsPreserved () const override
 
void * allocBlitMemory (size_t sz) override
 
- Public Member Functions inherited from SkBlitter
virtual ~SkBlitter ()
 
virtual void blitH (int x, int y, int width)=0
 Blit a horizontal run of one or more pixels. More...
 
virtual void blitAntiH (int x, int y, const SkAlpha antialias[], const int16_t runs[])=0
 
virtual void blitV (int x, int y, int height, SkAlpha alpha)
 Blit a vertical run of pixels with a constant alpha value. More...
 
virtual void blitRect (int x, int y, int width, int height)
 Blit a solid rectangle one or more pixels wide. More...
 
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

Wraps another (real) blitter, and ensures that the real blitter is only called with coordinates that have been clipped by the specified clipRect. This means the caller need not perform the clipping ahead of time.

Definition at line 182 of file SkBlitter.h.

Member Function Documentation

◆ allocBlitMemory()

void * SkRectClipBlitter::allocBlitMemory ( size_t  sz)
inlineoverridevirtual

This function allocates memory for the blitter that the blitter then owns. The memory can be used by the calling function at will, but it will be released when the blitter's destructor is called. This function returns nullptr if no persistent memory is needed by the blitter.

Reimplemented from SkBlitter.

Definition at line 202 of file SkBlitter.h.

202 {
203 return fBlitter->allocBlitMemory(sz);
204 }
virtual void * allocBlitMemory(size_t sz)
Definition: SkBlitter.h:130

◆ blitAntiH()

void SkRectClipBlitter::blitAntiH ( int  x,
int  y,
const  antialias[],
const int16_t  runs[] 
)
overridevirtual

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 379 of file SkBlitter.cpp.

380 {
381 SkAlpha* aa = const_cast<SkAlpha*>(const_aa);
382 int16_t* runs = const_cast<int16_t*>(const_runs);
383
384 if (!y_in_rect(y, fClipRect) || left >= fClipRect.fRight) {
385 return;
386 }
387
388 int x0 = left;
389 int x1 = left + compute_anti_width(runs);
390
391 if (x1 <= fClipRect.fLeft) {
392 return;
393 }
394
395 SkASSERT(x0 < x1);
396 if (x0 < fClipRect.fLeft) {
397 int dx = fClipRect.fLeft - x0;
398 SkAlphaRuns::BreakAt((int16_t*)runs, (uint8_t*)aa, dx);
399 runs += dx;
400 aa += dx;
401 x0 = fClipRect.fLeft;
402 }
403
404 SkASSERT(x0 < x1 && runs[x1 - x0] == 0);
405 if (x1 > fClipRect.fRight) {
406 x1 = fClipRect.fRight;
407 SkAlphaRuns::BreakAt((int16_t*)runs, (uint8_t*)aa, x1 - x0);
408 ((int16_t*)runs)[x1 - x0] = 0;
409 }
410
411 SkASSERT(x0 < x1 && runs[x1 - x0] == 0);
412 SkASSERT(compute_anti_width(runs) == x1 - x0);
413
414 fBlitter->blitAntiH(x0, y, aa, runs);
415}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int compute_anti_width(const int16_t runs[])
Definition: SkBlitter.cpp:333
static bool y_in_rect(int y, const SkIRect &rect)
Definition: SkBlitter.cpp:349
uint8_t SkAlpha
Definition: SkColor.h:26
static bool left(const SkPoint &p0, const SkPoint &p1)
static void BreakAt(int16_t runs[], uint8_t alpha[], int x)
Definition: SkAlphaRuns.h:179
virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[])=0
double y
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35

◆ blitAntiRect()

void SkRectClipBlitter::blitAntiRect ( int  x,
int  y,
int  width,
int  height,
SkAlpha  leftAlpha,
SkAlpha  rightAlpha 
)
overridevirtual

Blit a rectangle with one alpha-blended column on the left, width (zero or more) opaque pixels, and one alpha-blended column on the right. The result will always be at least two pixels wide.

Default implementation doesn't check for easy optimizations such as alpha == 255; also uses blitV(), which some subclasses may not support.

Reimplemented from SkBlitter.

Definition at line 448 of file SkBlitter.cpp.

449 {
450 SkIRect r;
451
452 // The *true* width of the rectangle blitted is width+2:
453 r.setLTRB(left, y, left + width + 2, y + height);
454 if (r.intersect(fClipRect)) {
455 if (r.fLeft != left) {
456 SkASSERT(r.fLeft > left);
457 leftAlpha = 255;
458 }
459 if (r.fRight != left + width + 2) {
460 SkASSERT(r.fRight < left + width + 2);
461 rightAlpha = 255;
462 }
463 if (255 == leftAlpha && 255 == rightAlpha) {
464 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
465 } else if (1 == r.width()) {
466 if (r.fLeft == left) {
467 fBlitter->blitV(r.fLeft, r.fTop, r.height(), leftAlpha);
468 } else {
469 SkASSERT(r.fLeft == left + width + 1);
470 fBlitter->blitV(r.fLeft, r.fTop, r.height(), rightAlpha);
471 }
472 } else {
473 fBlitter->blitAntiRect(r.fLeft, r.fTop, r.width() - 2, r.height(),
474 leftAlpha, rightAlpha);
475 }
476 }
477}
virtual void blitAntiRect(int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha)
Definition: SkBlitter.cpp:143
virtual void blitV(int x, int y, int height, SkAlpha alpha)
Blit a vertical run of pixels with a constant alpha value.
Definition: SkBlitter.cpp:119
virtual void blitRect(int x, int y, int width, int height)
Blit a solid rectangle one or more pixels wide.
Definition: SkBlitter.cpp:133
int32_t height
int32_t width
Definition: SkRect.h:32
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
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
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
Definition: SkRect.h:253

◆ blitH()

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

Blit a horizontal run of one or more pixels.

Implements SkBlitter.

Definition at line 357 of file SkBlitter.cpp.

357 {
358 SkASSERT(width > 0);
359
360 if (!y_in_rect(y, fClipRect)) {
361 return;
362 }
363
364 int right = left + width;
365
366 if (left < fClipRect.fLeft) {
367 left = fClipRect.fLeft;
368 }
369 if (right > fClipRect.fRight) {
370 right = fClipRect.fRight;
371 }
372
373 width = right - left;
374 if (width > 0) {
375 fBlitter->blitH(left, y, width);
376 }
377}
static bool right(const SkPoint &p0, const SkPoint &p1)
virtual void blitH(int x, int y, int width)=0
Blit a horizontal run of one or more pixels.

◆ blitMask()

void SkRectClipBlitter::blitMask ( const SkMask mask,
const SkIRect clip 
)
overridevirtual

Blit a pattern of pixels defined by a rectangle-clipped mask; typically used for text.

Reimplemented from SkBlitter.

Definition at line 479 of file SkBlitter.cpp.

479 {
481
482 SkIRect r = clip;
483
484 if (r.intersect(fClipRect)) {
485 fBlitter->blitMask(mask, r);
486 }
487}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
virtual void blitMask(const SkMask &, const SkIRect &clip)
Definition: SkBlitter.cpp:201
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
const SkIRect fBounds
Definition: SkMask.h:42

◆ blitRect()

void SkRectClipBlitter::blitRect ( int  x,
int  y,
int  width,
int  height 
)
overridevirtual

Blit a solid rectangle one or more pixels wide.

Reimplemented from SkBlitter.

Definition at line 439 of file SkBlitter.cpp.

439 {
440 SkIRect r;
441
442 r.setLTRB(left, y, left + width, y + height);
443 if (r.intersect(fClipRect)) {
444 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
445 }
446}

◆ blitV()

void SkRectClipBlitter::blitV ( int  x,
int  y,
int  height,
SkAlpha  alpha 
)
overridevirtual

Blit a vertical run of pixels with a constant alpha value.

Reimplemented from SkBlitter.

Definition at line 417 of file SkBlitter.cpp.

417 {
418 SkASSERT(height > 0);
419
420 if (!x_in_rect(x, fClipRect)) {
421 return;
422 }
423
424 int y0 = y;
425 int y1 = y + height;
426
427 if (y0 < fClipRect.fTop) {
428 y0 = fClipRect.fTop;
429 }
430 if (y1 > fClipRect.fBottom) {
431 y1 = fClipRect.fBottom;
432 }
433
434 if (y0 < y1) {
435 fBlitter->blitV(x, y0, y1 - y0, alpha);
436 }
437}
static bool x_in_rect(int x, const SkIRect &rect)
Definition: SkBlitter.cpp:353
double x
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36

◆ init()

void SkRectClipBlitter::init ( SkBlitter blitter,
const SkIRect clipRect 
)
inline

Definition at line 184 of file SkBlitter.h.

184 {
185 SkASSERT(!clipRect.isEmpty());
186 fBlitter = blitter;
187 fClipRect = clipRect;
188 }
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw

◆ requestRowsPreserved()

int SkRectClipBlitter::requestRowsPreserved ( ) const
inlineoverridevirtual

Special methods for blitters that can blit more than one row at a time. This function returns the number of rows that this blitter could optimally process at a time. It is still required to support blitting one scanline at a time.

Reimplemented from SkBlitter.

Definition at line 198 of file SkBlitter.h.

198 {
199 return fBlitter->requestRowsPreserved();
200 }
virtual int requestRowsPreserved() const
Definition: SkBlitter.h:122

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