add new perlin noise gm to test localmatrix
BUG=skia: Review URL: https://codereview.chromium.org/283533002 git-svn-id: http://skia.googlecode.com/svn/trunk@14698 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
261d0153e2
commit
a501a64827
@ -8,9 +8,7 @@
|
||||
#include "gm.h"
|
||||
#include "SkPerlinNoiseShader.h"
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
class PerlinNoiseGM : public GM {
|
||||
class PerlinNoiseGM : public skiagm::GM {
|
||||
public:
|
||||
PerlinNoiseGM() {
|
||||
this->setBGColor(0xFF000000);
|
||||
@ -23,7 +21,7 @@ protected:
|
||||
}
|
||||
|
||||
virtual SkISize onISize() {
|
||||
return make_isize(200, 500);
|
||||
return SkISize::Make(200, 500);
|
||||
}
|
||||
|
||||
void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
|
||||
@ -85,9 +83,89 @@ private:
|
||||
SkISize fSize;
|
||||
};
|
||||
|
||||
class PerlinNoiseGM2 : public skiagm::GM {
|
||||
public:
|
||||
PerlinNoiseGM2() {
|
||||
fSize = SkISize::Make(80, 80);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString onShortName() {
|
||||
return SkString("perlinnoise_localmatrix");
|
||||
}
|
||||
|
||||
virtual SkISize onISize() {
|
||||
return SkISize::Make(640, 480);
|
||||
}
|
||||
|
||||
void install(SkPaint* paint, SkPerlinNoiseShader::Type type,
|
||||
float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed,
|
||||
bool stitchTiles) {
|
||||
SkShader* shader = (type == SkPerlinNoiseShader::kFractalNoise_Type) ?
|
||||
SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves,
|
||||
seed, stitchTiles ? &fSize : NULL) :
|
||||
SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves,
|
||||
seed, stitchTiles ? &fSize : NULL);
|
||||
paint->setShader(shader)->unref();
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
canvas->translate(10, 10);
|
||||
|
||||
SkPaint paint;
|
||||
install(&paint, SkPerlinNoiseShader::kFractalNoise_Type, 0.1f, 0.1f, 2, 0, false);
|
||||
|
||||
const SkScalar w = SkIntToScalar(fSize.width());
|
||||
const SkScalar h = SkIntToScalar(fSize.height());
|
||||
|
||||
SkRect r = SkRect::MakeWH(w, h);
|
||||
canvas->drawRect(r, paint);
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(w * 5/4, 0);
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->restore();
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(0, h + 10);
|
||||
canvas->scale(2, 2);
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->restore();
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(w + 100, h + 10);
|
||||
canvas->scale(2, 2);
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->restore();
|
||||
|
||||
// The next row should draw the same as the previous, even though we are using a local
|
||||
// matrix instead of the canvas.
|
||||
|
||||
canvas->translate(0, h * 2 + 10);
|
||||
|
||||
SkMatrix lm;
|
||||
lm.setScale(2, 2);
|
||||
paint.getShader()->setLocalMatrix(lm);
|
||||
r.fRight += r.width();
|
||||
r.fBottom += r.height();
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(0, h + 10);
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->restore();
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(w + 100, h + 10);
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef GM INHERITED;
|
||||
SkISize fSize;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static GM* MyFactory(void*) { return new PerlinNoiseGM; }
|
||||
static GMRegistry reg(MyFactory);
|
||||
|
||||
}
|
||||
DEF_GM( return new PerlinNoiseGM; )
|
||||
DEF_GM( return new PerlinNoiseGM2; )
|
||||
|
Loading…
Reference in New Issue
Block a user