diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-12 09:42:01 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-12 09:42:01 +0000 |
commit | 79fbb40bca9d815ef79b896b31ba6ee736817e0f (patch) | |
tree | e68a9d73abf9bdbef00d5facf6ca406a395527f7 /tests | |
parent | ad07e69d4cbd4924678f923d744dc01517bd6a78 (diff) |
[WIP] Add Context to SkDrawLooper.
SkDrawLooper carries some state during draws. This CL extracts this state into
a separate class Context, which is then passed by the users of SkDrawLooper
into the appropriate methods.
This is a step towards making SkDrawLooper immutable.
BUG=skia:2141
R=scroggo@google.com, reed@google.com, sugoi@google.com
Author: dominikg@chromium.org
Review URL: https://codereview.chromium.org/155513012
git-svn-id: http://skia.googlecode.com/svn/trunk@13760 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LayerDrawLooperTest.cpp | 31 | ||||
-rw-r--r-- | tests/QuickRejectTest.cpp | 33 |
2 files changed, 41 insertions, 23 deletions
diff --git a/tests/LayerDrawLooperTest.cpp b/tests/LayerDrawLooperTest.cpp index 68dd5e06e7..1facb23b51 100644 --- a/tests/LayerDrawLooperTest.cpp +++ b/tests/LayerDrawLooperTest.cpp @@ -15,6 +15,7 @@ #include "SkRect.h" #include "SkRefCnt.h" #include "SkScalar.h" +#include "SkSmallAllocator.h" #include "SkXfermode.h" #include "Test.h" @@ -57,10 +58,12 @@ static void test_frontToBack(skiatest::Reporter* reporter) { SkCanvas canvas(&device); SkPaint paint; SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper()); - looper->init(&canvas); + SkSmallAllocator<1, 32> allocator; + void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize()); + SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); // The back layer should come first. - REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrc_Mode)); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); @@ -68,14 +71,14 @@ static void test_frontToBack(skiatest::Reporter* reporter) { paint.reset(); // Then the front layer. - REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); // Only two layers were added, so that should be the end. - REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); } static void test_backToFront(skiatest::Reporter* reporter) { @@ -95,10 +98,12 @@ static void test_backToFront(skiatest::Reporter* reporter) { SkCanvas canvas(&device); SkPaint paint; SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper()); - looper->init(&canvas); + SkSmallAllocator<1, 32> allocator; + void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize()); + SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); // The back layer should come first. - REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); @@ -106,14 +111,14 @@ static void test_backToFront(skiatest::Reporter* reporter) { paint.reset(); // Then the front layer. - REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrc_Mode)); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); // Only two layers were added, so that should be the end. - REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); } static void test_mixed(skiatest::Reporter* reporter) { @@ -133,10 +138,12 @@ static void test_mixed(skiatest::Reporter* reporter) { SkCanvas canvas(&device); SkPaint paint; SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper()); - looper->init(&canvas); + SkSmallAllocator<1, 32> allocator; + void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize()); + SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); // The back layer should come first. - REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); @@ -144,14 +151,14 @@ static void test_mixed(skiatest::Reporter* reporter) { paint.reset(); // Then the front layer. - REPORTER_ASSERT(reporter, looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrc_Mode)); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); // Only two layers were added, so that should be the end. - REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint)); + REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); } DEF_TEST(LayerDrawLooper, reporter) { diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp index 2d367389bb..ef145525e9 100644 --- a/tests/QuickRejectTest.cpp +++ b/tests/QuickRejectTest.cpp @@ -7,6 +7,7 @@ #include "SkCanvas.h" #include "SkDrawLooper.h" +#include "SkTypes.h" #include "Test.h" /* @@ -14,20 +15,12 @@ */ class TestLooper : public SkDrawLooper { public: - bool fOnce; - virtual void init(SkCanvas*) SK_OVERRIDE { - fOnce = true; + virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE { + return SkNEW_PLACEMENT(storage, TestDrawLooperContext); } - virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE { - if (fOnce) { - fOnce = false; - canvas->translate(SkIntToScalar(10), 0); - return true; - } - return false; - } + virtual size_t contextSize() const SK_OVERRIDE { return sizeof(TestDrawLooperContext); } #ifdef SK_DEVELOPER virtual void toString(SkString* str) const SK_OVERRIDE { @@ -35,6 +28,24 @@ public: } #endif +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; + }; + SK_DECLARE_UNFLATTENABLE_OBJECT() }; |