From 79fbb40bca9d815ef79b896b31ba6ee736817e0f Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Wed, 12 Mar 2014 09:42:01 +0000 Subject: [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 --- tests/QuickRejectTest.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'tests/QuickRejectTest.cpp') 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() }; -- cgit v1.2.3