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
This commit is contained in:
reed@google.com 2012-03-30 20:04:21 +00:00
parent bbbe9ed59e
commit d42e3f60cd
3 changed files with 42 additions and 8 deletions

View File

@ -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);

View File

@ -14,10 +14,15 @@ class FillTypeGM : public GM {
public:
FillTypeGM() {
this->setBGColor(0xFFDDDDDD);
}
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:
virtual SkString onShortName() {
@ -57,6 +62,8 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) {
this->makePath();
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
SkPaint paint;

View File

@ -13,11 +13,15 @@ namespace skiagm {
class FillTypePerspGM : public GM {
SkPath fPath;
public:
FillTypePerspGM() {
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:
virtual SkString onShortName() {
@ -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),