Reorganize and hide aa clip impl into .cpp file

Bug: skia:10205
Change-Id: Ia2dd9b99f5282a46aaeaf8eac54c9f6bfd583fc6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/445617
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
Michael Ludwig 2021-09-03 12:18:23 -04:00 committed by SkCQ
parent 9a1f92e4ff
commit 181bb97c38
5 changed files with 937 additions and 1040 deletions

File diff suppressed because it is too large Load Diff

View File

@ -19,12 +19,6 @@ public:
~SkAAClip();
SkAAClip& operator=(const SkAAClip&);
friend bool operator==(const SkAAClip&, const SkAAClip&);
friend bool operator!=(const SkAAClip& a, const SkAAClip& b) {
return !(a == b);
}
void swap(SkAAClip&);
bool isEmpty() const { return nullptr == fRunHead; }
const SkIRect& getBounds() const { return fBounds; }
@ -48,31 +42,17 @@ public:
bool op(const SkAAClip&, SkRegion::Op);
bool translate(int dx, int dy, SkAAClip* dst) const;
bool translate(int dx, int dy) {
return this->translate(dx, dy, this);
}
/**
* Allocates a mask the size of the aaclip, and expands its data into
* the mask, using kA8_Format
* the mask, using kA8_Format. Used for tests and visualization purposes.
*/
void copyToMask(SkMask*) const;
// called internally
bool quickContains(int left, int top, int right, int bottom) const;
bool quickContains(const SkIRect& r) const {
return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom);
}
const uint8_t* findRow(int y, int* lastYForRow = nullptr) const;
const uint8_t* findX(const uint8_t data[], int x, int* initialCount = nullptr) const;
class Iter;
struct RunHead;
struct YOffset;
class Builder;
#ifdef SK_DEBUG
void validate() const;
void debug(bool compress_y=false) const;
@ -82,17 +62,24 @@ public:
#endif
private:
class Builder;
struct RunHead;
friend class SkAAClipBlitter;
SkIRect fBounds;
RunHead* fRunHead;
void freeRuns();
bool quickContains(int left, int top, int right, int bottom) const;
bool trimBounds();
bool trimTopBottom();
bool trimLeftRight();
friend class Builder;
class BuilderBlitter;
friend class BuilderBlitter;
// For SkAAClipBlitter and quickContains
const uint8_t* findRow(int y, int* lastYForRow = nullptr) const;
const uint8_t* findX(const uint8_t data[], int x, int* initialCount = nullptr) const;
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -82,20 +82,6 @@ SkRasterClip::~SkRasterClip() {
SkDEBUGCODE(this->validate();)
}
bool SkRasterClip::operator==(const SkRasterClip& other) const {
if (fIsBW != other.fIsBW) {
return false;
}
bool isEqual = fIsBW ? fBW == other.fBW : fAA == other.fAA;
#ifdef SK_DEBUG
if (isEqual) {
SkASSERT(fIsEmpty == other.fIsEmpty);
SkASSERT(fIsRect == other.fIsRect);
}
#endif
return isEqual;
}
bool SkRasterClip::setEmpty() {
AUTO_RASTERCLIP_VALIDATE(*this);

View File

@ -32,11 +32,6 @@ public:
SkRasterClip& operator=(const SkRasterClip&);
bool operator==(const SkRasterClip&) const;
bool operator!=(const SkRasterClip& other) const {
return !(*this == other);
}
bool isBW() const { return fIsBW; }
bool isAA() const { return !fIsBW; }
const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; }

View File

@ -101,6 +101,27 @@ static void copyToMask(const SkRegion& rgn, SkMask* mask) {
canvas.drawColor(SK_ColorBLACK);
}
static void copyToMask(const SkRasterClip& rc, SkMask* mask) {
if (rc.isBW()) {
copyToMask(rc.bwRgn(), mask);
} else {
rc.aaRgn().copyToMask(mask);
}
}
static bool operator==(const SkRasterClip& a, const SkRasterClip& b) {
if (a.isEmpty() && b.isEmpty()) {
return true;
} else if (a.isEmpty() != b.isEmpty() || a.isBW() != b.isBW() || a.isRect() != b.isRect()) {
return false;
}
SkMask mask0, mask1;
copyToMask(a, &mask0);
copyToMask(b, &mask1);
return mask0 == mask1;
}
static SkIRect rand_rect(SkRandom& rand, int n) {
int x = rand.nextS() % n;
int y = rand.nextS() % n;
@ -216,31 +237,27 @@ static void test_path_bounds(skiatest::Reporter* reporter) {
}
static void test_empty(skiatest::Reporter* reporter) {
SkAAClip clip0, clip1;
SkAAClip clip;
REPORTER_ASSERT(reporter, clip0.isEmpty());
REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty());
REPORTER_ASSERT(reporter, clip1 == clip0);
REPORTER_ASSERT(reporter, clip.isEmpty());
REPORTER_ASSERT(reporter, clip.getBounds().isEmpty());
clip0.translate(10, 10); // should have no effect on empty
REPORTER_ASSERT(reporter, clip0.isEmpty());
REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty());
REPORTER_ASSERT(reporter, clip1 == clip0);
clip.translate(10, 10, &clip); // should have no effect on empty
REPORTER_ASSERT(reporter, clip.isEmpty());
REPORTER_ASSERT(reporter, clip.getBounds().isEmpty());
SkIRect r = { 10, 10, 40, 50 };
clip0.setRect(r);
REPORTER_ASSERT(reporter, !clip0.isEmpty());
REPORTER_ASSERT(reporter, !clip0.getBounds().isEmpty());
REPORTER_ASSERT(reporter, clip0 != clip1);
REPORTER_ASSERT(reporter, clip0.getBounds() == r);
clip.setRect(r);
REPORTER_ASSERT(reporter, !clip.isEmpty());
REPORTER_ASSERT(reporter, !clip.getBounds().isEmpty());
REPORTER_ASSERT(reporter, clip.getBounds() == r);
clip0.setEmpty();
REPORTER_ASSERT(reporter, clip0.isEmpty());
REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty());
REPORTER_ASSERT(reporter, clip1 == clip0);
clip.setEmpty();
REPORTER_ASSERT(reporter, clip.isEmpty());
REPORTER_ASSERT(reporter, clip.getBounds().isEmpty());
SkMask mask;
clip0.copyToMask(&mask);
clip.copyToMask(&mask);
REPORTER_ASSERT(reporter, nullptr == mask.fImage);
REPORTER_ASSERT(reporter, mask.fBounds.isEmpty());
}