diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-30 20:04:21 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-30 20:04:21 +0000 |
commit | d42e3f60cd571afb6c0f1837f9e0996bfe149001 (patch) | |
tree | 33ac82a3cd588b20875d92c1d0b47e8b1a0cd531 /gm | |
parent | bbbe9ed59ee1d3077fa4e6368a4a7294240a5ec6 (diff) |
defer drawing/work until first draw, to make debugging easier and speedup
instantiating the obj just to get its name.
git-svn-id: http://skia.googlecode.com/svn/trunk@3568 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/convexpaths.cpp | 23 | ||||
-rw-r--r-- | gm/filltypes.cpp | 13 | ||||
-rw-r--r-- | gm/filltypespersp.cpp | 14 |
3 files changed, 42 insertions, 8 deletions
diff --git a/gm/convexpaths.cpp b/gm/convexpaths.cpp index 2c719e826d..ebe715d866 100644 --- a/gm/convexpaths.cpp +++ b/gm/convexpaths.cpp @@ -9,13 +9,28 @@ #include "SkRandom.h" #include "SkTArray.h" +class SkOnce : SkNoncopyable { +public: + SkOnce() { fDidOnce = false; } + + bool needToDo() const { return !fDidOnce; } + bool alreadyDone() const { return fDidOnce; } + void accomplished() { + SkASSERT(!fDidOnce); + fDidOnce = true; + } + +private: + bool fDidOnce; +}; + namespace skiagm { class ConvexPathsGM : public GM { + SkOnce fOnce; public: ConvexPathsGM() { this->setBGColor(0xFF000000); - this->makePaths(); } protected: @@ -29,6 +44,11 @@ protected: } void makePaths() { + if (fOnce.alreadyDone()) { + return; + } + fOnce.accomplished(); + // CW fPaths.push_back().moveTo(0, 0); fPaths.back().quadTo(50 * SK_Scalar1, 100 * SK_Scalar1, @@ -169,6 +189,7 @@ protected: } virtual void onDraw(SkCanvas* canvas) { + this->makePaths(); SkPaint paint; paint.setAntiAlias(true); diff --git a/gm/filltypes.cpp b/gm/filltypes.cpp index 73c718e20b..e096a6b1fc 100644 --- a/gm/filltypes.cpp +++ b/gm/filltypes.cpp @@ -14,9 +14,14 @@ class FillTypeGM : public GM { public: FillTypeGM() { this->setBGColor(0xFFDDDDDD); - const SkScalar radius = SkIntToScalar(45); - fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); - fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); + } + + void makePath() { + if (fPath.isEmpty()) { + const SkScalar radius = SkIntToScalar(45); + fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); + fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); + } } protected: @@ -57,6 +62,8 @@ protected: } virtual void onDraw(SkCanvas* canvas) { + this->makePath(); + canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); SkPaint paint; diff --git a/gm/filltypespersp.cpp b/gm/filltypespersp.cpp index 33f3242493..e675990631 100644 --- a/gm/filltypespersp.cpp +++ b/gm/filltypespersp.cpp @@ -13,10 +13,14 @@ namespace skiagm { class FillTypePerspGM : public GM { SkPath fPath; public: - FillTypePerspGM() { - const SkScalar radius = SkIntToScalar(45); - fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); - fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); + FillTypePerspGM() {} + + void makePath() { + if (fPath.isEmpty()) { + const SkScalar radius = SkIntToScalar(45); + fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); + fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); + } } protected: @@ -71,6 +75,8 @@ protected: } virtual void onDraw(SkCanvas* canvas) { + this->makePath(); + // do perspective drawPaint as the background; SkPaint bkgnrd; SkPoint center = SkPoint::Make(SkIntToScalar(100), |