Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkRgnClipBlitter Class Reference

#include <SkBlitter.h>

Inheritance diagram for SkRgnClipBlitter:
SkBlitter

Public Member Functions

void init (SkBlitter *blitter, const SkRegion *clipRgn)
 
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[], 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.
 
void blitRect (int x, int y, int width, int height) override
 Blit a solid rectangle one or more pixels wide.
 
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 ()
 
void blitFatAntiRect (const SkRect &rect)
 
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
 
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 clipRgn. This means the caller need not perform the clipping ahead of time.

Definition at line 214 of file SkBlitter.h.

Member Function Documentation

◆ allocBlitMemory()

void * SkRgnClipBlitter::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 234 of file SkBlitter.h.

234 {
235 return fBlitter->allocBlitMemory(sz);
236 }
virtual void * allocBlitMemory(size_t sz)
Definition SkBlitter.h:129

◆ blitAntiH()

void SkRgnClipBlitter::blitAntiH ( int  x,
int  y,
const SkAlpha  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 501 of file SkBlitter.cpp.

502 {
503 SkAlpha* aa = const_cast<SkAlpha*>(const_aa);
504 int16_t* runs = const_cast<int16_t*>(const_runs);
505
506 int width = compute_anti_width(runs);
507 SkRegion::Spanerator span(*fRgn, y, x, x + width);
508 int left, right;
509 SkDEBUGCODE(const SkIRect& bounds = fRgn->getBounds();)
510
511 int prevRite = x;
512 while (span.next(&left, &right)) {
513 SkASSERT(x <= left);
515 SkASSERT(left >= bounds.fLeft && right <= bounds.fRight);
516
517 SkAlphaRuns::Break((int16_t*)runs, (uint8_t*)aa, left - x, right - left);
518
519 // now zero before left
520 if (left > prevRite) {
521 int index = prevRite - x;
522 ((uint8_t*)aa)[index] = 0; // skip runs after right
523 ((int16_t*)runs)[index] = SkToS16(left - prevRite);
524 }
525
526 prevRite = right;
527 }
528
529 if (prevRite > x) {
530 ((int16_t*)runs)[prevRite - x] = 0;
531
532 if (x < 0) {
533 int skip = runs[0];
534 SkASSERT(skip >= -x);
535 aa += skip;
536 runs += skip;
537 x += skip;
538 }
539 fBlitter->blitAntiH(x, y, aa, runs);
540 }
541}
#define SkASSERT(cond)
Definition SkAssert.h:116
static int compute_anti_width(const int16_t runs[])
uint8_t SkAlpha
Definition SkColor.h:26
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static bool skip(SkStream *stream, size_t amount)
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
constexpr int16_t SkToS16(S x)
Definition SkTo.h:23
static void Break(int16_t runs[], uint8_t alpha[], int x, int count)
virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[])=0
const SkIRect & getBounds() const
Definition SkRegion.h:165
double y
double x
Optional< SkRect > bounds
Definition SkRecords.h:189
int32_t width

◆ blitAntiRect()

void SkRgnClipBlitter::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 573 of file SkBlitter.cpp.

574 {
575 // The *true* width of the rectangle to blit is width + 2
577 bounds.setXYWH(x, y, width + 2, height);
578
579 SkRegion::Cliperator iter(*fRgn, bounds);
580
581 while (!iter.done()) {
582 const SkIRect& r = iter.rect();
583 SkASSERT(bounds.contains(r));
584 SkASSERT(r.fLeft >= x);
585 SkASSERT(r.fRight <= x + width + 2);
586
587 SkAlpha effectiveLeftAlpha = (r.fLeft == x) ? leftAlpha : 255;
588 SkAlpha effectiveRightAlpha = (r.fRight == x + width + 2) ?
589 rightAlpha : 255;
590
591 if (255 == effectiveLeftAlpha && 255 == effectiveRightAlpha) {
592 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
593 } else if (1 == r.width()) {
594 if (r.fLeft == x) {
595 fBlitter->blitV(r.fLeft, r.fTop, r.height(),
596 effectiveLeftAlpha);
597 } else {
598 SkASSERT(r.fLeft == x + width + 1);
599 fBlitter->blitV(r.fLeft, r.fTop, r.height(),
600 effectiveRightAlpha);
601 }
602 } else {
603 fBlitter->blitAntiRect(r.fLeft, r.fTop, r.width() - 2, r.height(),
604 effectiveLeftAlpha, effectiveRightAlpha);
605 }
606 iter.next();
607 }
608}
virtual void blitAntiRect(int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha)
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.
int32_t height
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
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition SkRect.h:35

◆ blitH()

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

Blit a horizontal run of one or more pixels.

Implements SkBlitter.

Definition at line 491 of file SkBlitter.cpp.

491 {
492 SkRegion::Spanerator span(*fRgn, y, x, x + width);
493 int left, right;
494
495 while (span.next(&left, &right)) {
497 fBlitter->blitH(left, y, right - left);
498 }
499}
virtual void blitH(int x, int y, int width)=0
Blit a horizontal run of one or more pixels.

◆ blitMask()

void SkRgnClipBlitter::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 611 of file SkBlitter.cpp.

611 {
613
614 SkRegion::Cliperator iter(*fRgn, clip);
615 const SkIRect& r = iter.rect();
616 SkBlitter* blitter = fBlitter;
617
618 while (!iter.done()) {
619 blitter->blitMask(mask, r);
620 iter.next();
621 }
622}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
virtual void blitMask(const SkMask &, const SkIRect &clip)
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463
const SkIRect fBounds
Definition SkMask.h:42

◆ blitRect()

void SkRgnClipBlitter::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 558 of file SkBlitter.cpp.

558 {
560 bounds.setXYWH(x, y, width, height);
561
562 SkRegion::Cliperator iter(*fRgn, bounds);
563
564 while (!iter.done()) {
565 const SkIRect& r = iter.rect();
566 SkASSERT(bounds.contains(r));
567
568 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
569 iter.next();
570 }
571}

◆ blitV()

void SkRgnClipBlitter::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 543 of file SkBlitter.cpp.

543 {
545 bounds.setXYWH(x, y, 1, height);
546
547 SkRegion::Cliperator iter(*fRgn, bounds);
548
549 while (!iter.done()) {
550 const SkIRect& r = iter.rect();
551 SkASSERT(bounds.contains(r));
552
553 fBlitter->blitV(x, r.fTop, r.height(), alpha);
554 iter.next();
555 }
556}

◆ init()

void SkRgnClipBlitter::init ( SkBlitter blitter,
const SkRegion clipRgn 
)
inline

Definition at line 216 of file SkBlitter.h.

216 {
217 SkASSERT(clipRgn && !clipRgn->isEmpty());
218 fBlitter = blitter;
219 fRgn = clipRgn;
220 }
bool isEmpty() const
Definition SkRegion.h:146

◆ requestRowsPreserved()

int SkRgnClipBlitter::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 230 of file SkBlitter.h.

230 {
231 return fBlitter->requestRowsPreserved();
232 }
virtual int requestRowsPreserved() const
Definition SkBlitter.h:121

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