skia2/tests/QuickRejectTest.cpp
mtklein 7e44bb1916 Remove macros that make it look like it's a good idea to not be able to flatten.
There are only a handful of SkFlattenables that are not flattenable.  That
there are any seems highly illogical.  To make this look less like a normal
thing, this removes both macros that marked SkFlattenables as non-flattenable
(in slightly different ways).

The handful of SkFlattenables in our codebase that can't be flattened now
assert violently that they can't be flattened.  They're internal or
part of animator... places where we'll never actually flatten them.

TestLooper and DummyRasterizer were so trivial that I just made them flattenable.

BUG=skia:

Review URL: https://codereview.chromium.org/841753002
2015-01-07 09:06:08 -08:00

93 lines
2.7 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkCanvas.h"
#include "SkDrawLooper.h"
#include "SkTypes.h"
#include "Test.h"
/*
* Subclass of looper that just draws once, with an offset in X.
*/
class TestLooper : public SkDrawLooper {
public:
virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE {
return SkNEW_PLACEMENT(storage, TestDrawLooperContext);
}
virtual size_t contextSize() const SK_OVERRIDE { return sizeof(TestDrawLooperContext); }
#ifndef SK_IGNORE_TO_STRING
virtual void toString(SkString* str) const SK_OVERRIDE {
str->append("TestLooper:");
}
#endif
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(TestLooper);
private:
class TestDrawLooperContext : public SkDrawLooper::Context {
public:
TestDrawLooperContext() : fOnce(true) {}
virtual ~TestDrawLooperContext() {}
virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE {
if (fOnce) {
fOnce = false;
canvas->translate(SkIntToScalar(10), 0);
return true;
}
return false;
}
private:
bool fOnce;
};
};
SkFlattenable* TestLooper::CreateProc(SkReadBuffer&) { return SkNEW(TestLooper); }
static void test_drawBitmap(skiatest::Reporter* reporter) {
SkBitmap src;
src.allocN32Pixels(10, 10);
src.eraseColor(SK_ColorWHITE);
SkBitmap dst;
dst.allocN32Pixels(10, 10);
dst.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(dst);
SkPaint paint;
// we are initially transparent
REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
// we see the bitmap drawn
canvas.drawBitmap(src, 0, 0, &paint);
REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
// reverify we are clear again
dst.eraseColor(SK_ColorTRANSPARENT);
REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
// if the bitmap is clipped out, we don't draw it
canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
// now install our looper, which will draw, since it internally translates
// to the left. The test is to ensure that canvas' quickReject machinary
// allows us through, even though sans-looper we would look like we should
// be clipped out.
paint.setLooper(new TestLooper)->unref();
canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
}
DEF_TEST(QuickReject, reporter) {
test_drawBitmap(reporter);
}