[ngatoy] Remove old clipping system
Bug: skia:11837 Change-Id: I9f338279ce2648c788c4eb011639ac6d27c946ac Reviewed-on: https://skia-review.googlesource.com/c/skia/+/418696 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
d812cead57
commit
7c4aa813d3
@ -52,30 +52,10 @@ uint32_t RectCmd::getDrawZ() const {
|
||||
}
|
||||
|
||||
SortKey RectCmd::getKey() {
|
||||
return SortKey(fPaint.isTransparent(), fMCState->id(), this->getSortZ(), fPaint.toID());
|
||||
}
|
||||
|
||||
static void apply_diff(FakeCanvas* c, const FakeMCBlob& desired, const FakeMCBlob* prior) {
|
||||
int prefix = desired.determineSharedPrefix(prior);
|
||||
|
||||
if (prior) {
|
||||
for (int j = prefix; j < prior->count(); ++j) {
|
||||
c->restore();
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = prefix; j < desired.count(); ++j) {
|
||||
desired[j].apply(c);
|
||||
}
|
||||
return SortKey(fPaint.isTransparent(), this->getSortZ(), fPaint.toID());
|
||||
}
|
||||
|
||||
void RectCmd::execute(FakeCanvas* c) const {
|
||||
if (fMCState) {
|
||||
// When replaying the test case 'fMCState' will be null. When actually executing the Cmd
|
||||
// after sorting, 'fMCState' will be non-null.
|
||||
apply_diff(c, *fMCState, c->snapState().get());
|
||||
}
|
||||
|
||||
c->drawRect(fID, fRect, fPaint);
|
||||
}
|
||||
|
||||
@ -95,6 +75,7 @@ void RectCmd::execute(SkCanvas* c) const {
|
||||
SkTileMode::kClamp));
|
||||
} else {
|
||||
SkASSERT(fPaint.toID() == kRadialMat);
|
||||
|
||||
auto shader = SkGradientShader::MakeRadial(SkPoint::Make(128.0f, 128.0f),
|
||||
128.0f,
|
||||
colors,
|
||||
@ -115,14 +96,15 @@ static bool is_opaque(SkColor c) {
|
||||
void RectCmd::rasterize(uint32_t zBuffer[256][256], SkBitmap* dstBM) const {
|
||||
|
||||
uint32_t z = this->getDrawZ();
|
||||
SkIRect scissor = fMCState->scissor();
|
||||
|
||||
for (int y = fRect.fTop; y < fRect.fBottom; ++y) {
|
||||
for (int x = fRect.fLeft; x < fRect.fRight; ++x) {
|
||||
if (fMCState->clipped(x, y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (z > zBuffer[x][y]) {
|
||||
if (!scissor.contains(x, y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
zBuffer[x][y] = z;
|
||||
|
||||
SkColor c = fPaint.evalColor(x, y);
|
||||
@ -172,7 +154,7 @@ SortKey ClipCmd::getKey() {
|
||||
// Not used this iteration
|
||||
SkASSERT(0);
|
||||
|
||||
return SortKey(false, 0, this->getSortZ(), kInvalidMat);
|
||||
return SortKey(false, this->getSortZ(), kInvalidMat);
|
||||
}
|
||||
|
||||
void ClipCmd::execute(FakeCanvas* c) const {
|
||||
|
@ -16,6 +16,8 @@ class SortKey;
|
||||
#include "experimental/ngatoy/Fake.h"
|
||||
#include "experimental/ngatoy/ngatypes.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
class Cmd {
|
||||
public:
|
||||
Cmd() : fID(ID::Invalid()) {}
|
||||
@ -26,8 +28,6 @@ public:
|
||||
|
||||
virtual SortKey getKey() = 0;
|
||||
|
||||
virtual const FakeMCBlob* state() const { return nullptr; }
|
||||
|
||||
// To generate the actual image
|
||||
virtual void execute(FakeCanvas*) const = 0;
|
||||
virtual void rasterize(uint32_t zBuffer[256][256], SkBitmap* dstBM) const = 0;
|
||||
@ -97,7 +97,7 @@ public:
|
||||
uint32_t getDrawZ() const;
|
||||
|
||||
SortKey getKey() override;
|
||||
const FakeMCBlob* state() const override { return fMCState.get(); }
|
||||
const FakeMCBlob* state() const { return fMCState.get(); }
|
||||
|
||||
void execute(FakeCanvas*) const override;
|
||||
void execute(SkCanvas*) const override;
|
||||
@ -147,4 +147,5 @@ private:
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
||||
#endif // Cmds_DEFINED
|
||||
|
@ -76,7 +76,6 @@ void FakeDevice::save() {
|
||||
}
|
||||
|
||||
void FakeDevice::drawRect(ID id, PaintersOrder paintersOrder, SkIRect r, FakePaint p) {
|
||||
|
||||
sk_sp<FakeMCBlob> state = fTracker.snapState();
|
||||
SkASSERT(state);
|
||||
|
||||
@ -85,8 +84,10 @@ void FakeDevice::drawRect(ID id, PaintersOrder paintersOrder, SkIRect r, FakePai
|
||||
fSortedCmds.push_back(tmp);
|
||||
}
|
||||
|
||||
void FakeDevice::clipRect(ID id, SkIRect r) {
|
||||
fTracker.clipRect(r);
|
||||
void FakeDevice::clipRect(ID id, PaintersOrder paintersOrder, SkIRect r) {
|
||||
auto tmp = new ClipCmd(id, paintersOrder, r);
|
||||
|
||||
fTracker.clipRect(r, tmp);
|
||||
}
|
||||
|
||||
void FakeDevice::restore() {
|
||||
@ -106,8 +107,6 @@ void FakeDevice::finalize() {
|
||||
void FakeDevice::getOrder(std::vector<ID>* ops) const {
|
||||
SkASSERT(fFinalized);
|
||||
|
||||
// ops->reserve(fSortedCmds.size());
|
||||
|
||||
for (auto c : fSortedCmds) {
|
||||
ops->push_back(c->id());
|
||||
}
|
||||
@ -136,7 +135,7 @@ void FakeCanvas::drawRect(ID id, SkIRect r, FakePaint p) {
|
||||
void FakeCanvas::clipRect(ID id, SkIRect r) {
|
||||
SkASSERT(!fFinalized);
|
||||
|
||||
fDeviceStack.back()->clipRect(id, r);
|
||||
fDeviceStack.back()->clipRect(id, this->nextPaintersOrder(), r);
|
||||
}
|
||||
|
||||
void FakeCanvas::finalize() {
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "experimental/ngatoy/SortKey.h"
|
||||
#include "experimental/ngatoy/ngatypes.h"
|
||||
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkColor.h"
|
||||
#include "include/core/SkMatrix.h"
|
||||
@ -15,6 +16,7 @@
|
||||
#include <vector>
|
||||
|
||||
class Cmd;
|
||||
class ClipCmd;
|
||||
class FakeCanvas;
|
||||
class SkBitmap;
|
||||
class SkCanvas;
|
||||
@ -29,8 +31,9 @@ public:
|
||||
public:
|
||||
MCState() {}
|
||||
|
||||
void addRect(SkIRect r) {
|
||||
void addRect(SkIRect r, ClipCmd* clipCmd) {
|
||||
fRects.push_back(r.makeOffset(fTrans.fX, fTrans.fY));
|
||||
fCmds.push_back(clipCmd);
|
||||
fCached = nullptr;
|
||||
}
|
||||
|
||||
@ -48,15 +51,9 @@ public:
|
||||
|
||||
void apply(SkCanvas*) const;
|
||||
void apply(FakeCanvas*) const;
|
||||
bool clipped(int x, int y) const {
|
||||
for (auto r : fRects) {
|
||||
if (!r.contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<SkIRect>& rects() const { return fRects; }
|
||||
const std::vector<ClipCmd*>& cmds() const { return fCmds; }
|
||||
|
||||
sk_sp<FakeMCBlob> getCached() const {
|
||||
return fCached;
|
||||
@ -68,19 +65,25 @@ public:
|
||||
protected:
|
||||
friend class FakeMCBlob;
|
||||
|
||||
SkIPoint fTrans { 0, 0 };
|
||||
SkIPoint fTrans { 0, 0 };
|
||||
// These clip rects are in the 'parent' space of this MCState (i.e., in the coordinate
|
||||
// frame of the MCState prior to this one in 'fStack'). Alternatively, the 'fTrans' in
|
||||
// effect when they were added has already been applied.
|
||||
std::vector<SkIRect> fRects;
|
||||
sk_sp<FakeMCBlob> fCached;
|
||||
std::vector<SkIRect> fRects;
|
||||
std::vector<ClipCmd*> fCmds;
|
||||
sk_sp<FakeMCBlob> fCached;
|
||||
};
|
||||
|
||||
FakeMCBlob(const std::vector<MCState>& stack) : fID(NextID()), fStack(stack) {
|
||||
fScissor = SkIRect::MakeLTRB(-1000, -1000, 1000, 1000);
|
||||
|
||||
for (auto s : fStack) {
|
||||
// xform the clip rects into device space
|
||||
for (auto& r : s.fRects) {
|
||||
r.offset(fCTM);
|
||||
if (!fScissor.intersect(r)) {
|
||||
fScissor.setEmpty();
|
||||
}
|
||||
}
|
||||
fCTM += s.getTrans();
|
||||
}
|
||||
@ -105,16 +108,7 @@ public:
|
||||
SkIPoint ctm() const { return fCTM; }
|
||||
const std::vector<MCState>& mcStates() const { return fStack; }
|
||||
const MCState& operator[](int index) const { return fStack[index]; }
|
||||
|
||||
bool clipped(int x, int y) const {
|
||||
for (auto& s : fStack) {
|
||||
if (s.clipped(x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
SkIRect scissor() const { return fScissor; }
|
||||
|
||||
private:
|
||||
static int NextID() {
|
||||
@ -124,6 +118,7 @@ private:
|
||||
|
||||
const int fID;
|
||||
SkIPoint fCTM { 0, 0 };
|
||||
SkIRect fScissor;
|
||||
std::vector<MCState> fStack;
|
||||
};
|
||||
|
||||
@ -148,8 +143,8 @@ public:
|
||||
fStack.push_back(FakeMCBlob::MCState());
|
||||
}
|
||||
|
||||
void clipRect(SkIRect clipRect) {
|
||||
fStack.back().addRect(clipRect);
|
||||
void clipRect(SkIRect clipRect, ClipCmd* clipCmd) {
|
||||
fStack.back().addRect(clipRect, clipCmd);
|
||||
}
|
||||
|
||||
// For now we only store translates - in the full Skia this would be the whole 4x4 matrix
|
||||
@ -256,7 +251,7 @@ public:
|
||||
|
||||
void save();
|
||||
void drawRect(ID, PaintersOrder, SkIRect, FakePaint);
|
||||
void clipRect(ID, SkIRect);
|
||||
void clipRect(ID, PaintersOrder, SkIRect);
|
||||
void translate(SkIPoint trans) {
|
||||
fTracker.translate(trans);
|
||||
}
|
||||
|
@ -36,28 +36,21 @@ public:
|
||||
static const uint32_t kDepthMask = (0x1 << kNumDepthBits) - 1;
|
||||
static const uint32_t kMaxDepth = kDepthMask;
|
||||
|
||||
static const uint32_t kClipShift = kNumMaterialBits + kNumDepthBits;
|
||||
static const uint32_t kNumClipBits = 8;
|
||||
static const uint32_t kClipMask = (0x01 << kNumClipBits) - 1;
|
||||
static const uint32_t kMaxClipID = kClipMask;
|
||||
|
||||
static const uint32_t kTransparentShift = kNumMaterialBits + kNumDepthBits + kNumClipBits;
|
||||
static const uint32_t kTransparentShift = kNumMaterialBits + kNumDepthBits;
|
||||
static const uint32_t kNumTransparentBits = 1;
|
||||
static const uint32_t kTransparentMask = (0x1 << kNumTransparentBits) - 1;
|
||||
|
||||
// TODO: make it clearer that we're initializing the default depth to be 0 here (since the
|
||||
// default key is opaque, its sense is flipped)
|
||||
SortKey() : fKey((kMaxDepth - 1) << kMaterialShift) {}
|
||||
explicit SortKey(bool transparent, uint32_t clipID, uint32_t depth, uint32_t material) {
|
||||
SkASSERT(clipID != 0 && depth != 0 /* && material != 0*/);
|
||||
SkASSERT(!(clipID & ~kClipMask));
|
||||
explicit SortKey(bool transparent, uint32_t depth, uint32_t material) {
|
||||
SkASSERT(depth != 0 /* && material != 0*/);
|
||||
SkASSERT(!(depth & ~kDepthMask));
|
||||
SkASSERT(!(material & ~kMaterialMask));
|
||||
|
||||
// TODO: better encapsulate the reversal of the depth & material when the key is opaque
|
||||
if (transparent) {
|
||||
fKey = (0x1 << kTransparentShift) |
|
||||
(clipID & kClipMask) << kClipShift |
|
||||
(depth & kDepthMask) << kDepthShift |
|
||||
(material & kMaterialMask) << kMaterialShift;
|
||||
} else {
|
||||
@ -68,8 +61,7 @@ public:
|
||||
munged = kMaxDepth - depth - 1;
|
||||
SkASSERT(!(munged & ~kDepthMask));
|
||||
|
||||
fKey = (clipID & kClipMask) << kClipShift |
|
||||
(munged & kDepthMask) << kMaterialShift |
|
||||
fKey = (munged & kDepthMask) << kMaterialShift |
|
||||
(material & kMaterialMask) << kDepthShift;
|
||||
}
|
||||
}
|
||||
@ -78,16 +70,12 @@ public:
|
||||
return (fKey >> kTransparentShift) & kTransparentMask;
|
||||
}
|
||||
|
||||
uint32_t clipID() const {
|
||||
return (fKey >> kClipShift) & kClipMask;
|
||||
}
|
||||
|
||||
uint32_t depth() const {
|
||||
if (this->transparent()) {
|
||||
return (fKey >> kDepthShift) & kDepthMask;
|
||||
}
|
||||
|
||||
// TODO: foo
|
||||
// TODO: better encapsulate the reversal of the depth & material when the key is opaque
|
||||
uint32_t tmp = (fKey >> kMaterialShift) & kDepthMask;
|
||||
return (kMaxDepth - tmp) - 1;
|
||||
}
|
||||
|
@ -113,21 +113,18 @@ static void save_files(int testID, const SkBitmap& expected, const SkBitmap& act
|
||||
static void key_test() {
|
||||
SortKey k;
|
||||
SkASSERT(!k.transparent());
|
||||
SkASSERT(k.clipID() == 0);
|
||||
SkASSERT(k.depth() == 0);
|
||||
SkASSERT(k.material() == 0);
|
||||
// k.dump();
|
||||
|
||||
SortKey k1(false, 4, 1, 3);
|
||||
SortKey k1(false, 1, 3);
|
||||
SkASSERT(!k1.transparent());
|
||||
SkASSERT(k1.clipID() == 4);
|
||||
SkASSERT(k1.depth() == 1);
|
||||
SkASSERT(k1.material() == 3);
|
||||
// k1.dump();
|
||||
|
||||
SortKey k2(true, 7, 2, 1);
|
||||
SortKey k2(true, 2, 1);
|
||||
SkASSERT(k2.transparent());
|
||||
SkASSERT(k2.clipID() == 7);
|
||||
SkASSERT(k2.depth() == 2);
|
||||
SkASSERT(k2.material() == 1);
|
||||
// k2.dump();
|
||||
@ -180,7 +177,7 @@ static void mcstack_test() {
|
||||
//----------------
|
||||
s.push();
|
||||
s.translate(s1Trans);
|
||||
s.clipRect(r);
|
||||
s.clipRect(r, new ClipCmd(ID(1), {}, r));
|
||||
|
||||
auto state1 = s.snapState();
|
||||
check_state(state1.get(), s1Trans, expectedS1Clips);
|
||||
@ -188,13 +185,13 @@ static void mcstack_test() {
|
||||
//----------------
|
||||
s.push();
|
||||
s.translate(s2TransA);
|
||||
s.clipRect(r);
|
||||
s.clipRect(r, new ClipCmd(ID(2), {}, r));
|
||||
|
||||
auto state2a = s.snapState();
|
||||
check_state(state2a.get(), s1Trans + s2TransA, expectedS2aClips);
|
||||
|
||||
s.translate(s2TransB);
|
||||
s.clipRect(r);
|
||||
s.clipRect(r, new ClipCmd(ID(3), {}, r));
|
||||
|
||||
auto state2b = s.snapState();
|
||||
check_state(state2b.get(), s1Trans + s2TransA + s2TransB, expectedS2bClips);
|
||||
|
@ -52,5 +52,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user