add basic tests for save/restore counting
BUG=skia: Review URL: https://codereview.chromium.org/763503003
This commit is contained in:
parent
c67870cfc1
commit
f0090cb80a
@ -811,6 +811,36 @@ void SkCanvas::updateDeviceCMCache() {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
int SkCanvas::getSaveCount() const {
|
||||||
|
return fMCStack.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int SkCanvas::save() {
|
||||||
|
this->willSave();
|
||||||
|
return this->internalSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkCanvas::restore() {
|
||||||
|
// check for underflow
|
||||||
|
if (fMCStack.count() > 1) {
|
||||||
|
this->willRestore();
|
||||||
|
this->internalRestore();
|
||||||
|
this->didRestore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkCanvas::restoreToCount(int count) {
|
||||||
|
// sanity check
|
||||||
|
if (count < 1) {
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int n = this->getSaveCount() - count;
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
this->restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int SkCanvas::internalSave() {
|
int SkCanvas::internalSave() {
|
||||||
int saveCount = this->getSaveCount(); // record this before the actual save
|
int saveCount = this->getSaveCount(); // record this before the actual save
|
||||||
|
|
||||||
@ -823,11 +853,6 @@ int SkCanvas::internalSave() {
|
|||||||
return saveCount;
|
return saveCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SkCanvas::save() {
|
|
||||||
this->willSave();
|
|
||||||
return this->internalSave();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool bounds_affects_clip(SkCanvas::SaveFlags flags) {
|
static bool bounds_affects_clip(SkCanvas::SaveFlags flags) {
|
||||||
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
|
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
|
||||||
return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0;
|
return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0;
|
||||||
@ -977,15 +1002,6 @@ int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkCanvas::restore() {
|
|
||||||
// check for underflow
|
|
||||||
if (fMCStack.count() > 1) {
|
|
||||||
this->willRestore();
|
|
||||||
this->internalRestore();
|
|
||||||
this->didRestore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkCanvas::internalRestore() {
|
void SkCanvas::internalRestore() {
|
||||||
SkASSERT(fMCStack.count() != 0);
|
SkASSERT(fMCStack.count() != 0);
|
||||||
|
|
||||||
@ -1023,22 +1039,6 @@ void SkCanvas::internalRestore() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SkCanvas::getSaveCount() const {
|
|
||||||
return fMCStack.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkCanvas::restoreToCount(int count) {
|
|
||||||
// sanity check
|
|
||||||
if (count < 1) {
|
|
||||||
count = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int n = this->getSaveCount() - count;
|
|
||||||
for (int i = 0; i < n; ++i) {
|
|
||||||
this->restore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SkCanvas::isDrawingToLayer() const {
|
bool SkCanvas::isDrawingToLayer() const {
|
||||||
return fSaveLayerCount > 0;
|
return fSaveLayerCount > 0;
|
||||||
}
|
}
|
||||||
|
@ -795,3 +795,21 @@ DEF_TEST(Canvas, reporter) {
|
|||||||
|
|
||||||
test_newraster(reporter);
|
test_newraster(reporter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEF_TEST(Canvas_SaveState, reporter) {
|
||||||
|
SkCanvas canvas(10, 10);
|
||||||
|
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
|
||||||
|
|
||||||
|
int n = canvas.save();
|
||||||
|
REPORTER_ASSERT(reporter, 1 == n);
|
||||||
|
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
|
||||||
|
|
||||||
|
n = canvas.saveLayer(NULL, NULL);
|
||||||
|
REPORTER_ASSERT(reporter, 2 == n);
|
||||||
|
REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount());
|
||||||
|
|
||||||
|
canvas.restore();
|
||||||
|
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
|
||||||
|
canvas.restore();
|
||||||
|
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user