allow GMs to animate

BUG=skia:

Review URL: https://codereview.chromium.org/888283002
This commit is contained in:
reed 2015-02-01 19:01:04 -08:00 committed by Commit bot
parent 47471cf19c
commit d9adfe6a22
17 changed files with 159 additions and 295 deletions

View File

@ -10,6 +10,9 @@
#include "SkRandom.h"
class AddArcGM : public skiagm::GM {
public:
AddArcGM() : fRotate(0) {}
protected:
SkString onShortName() SK_OVERRIDE { return SkString("addarc"); }
@ -29,20 +32,30 @@ protected:
const SkScalar sweepAngle = 345;
SkRandom rand;
SkScalar sign = 1;
while (r.width() > paint.getStrokeWidth() * 3) {
paint.setColor(rand.nextU() | (0xFF << 24));
SkScalar startAngle = rand.nextUScalar1() * 360;
SkScalar speed = SkScalarSqrt(16 / r.width()) * 0.5f;
startAngle += fRotate * 360 * speed * sign;
SkPath path;
path.addArc(r, startAngle, sweepAngle);
canvas->drawPath(path, paint);
r.inset(inset, inset);
sign = -sign;
}
}
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
fRotate = SkDoubleToScalar(fmod(curr * 0.001, 360));
return true;
}
private:
SkScalar fRotate;
typedef skiagm::GM INHERITED;
};
DEF_GM( return new AddArcGM; )

View File

@ -51,6 +51,12 @@ void GM::setBGColor(SkColor color) {
fBGColor = color;
}
bool GM::animatePulse(SkMSec curr, SkMSec prev) {
return this->onAnimatePulse(curr, prev);
}
/////////////////////////////////////////////////////////////////////////////////////////////
void GM::onDrawBackground(SkCanvas* canvas) {
canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode);
}
@ -101,3 +107,4 @@ SkISize skiagm::SimpleGM::onISize() {
SkString skiagm::SimpleGM::onShortName() {
return fName;
}

View File

@ -92,6 +92,8 @@ namespace skiagm {
fStarterMatrix = matrix;
}
bool animatePulse(SkMSec curr, SkMSec prev);
protected:
/** draws a standard message that the GM is only intended to be used with the GPU.*/
void drawGpuOnlyMessage(SkCanvas*);
@ -101,6 +103,7 @@ namespace skiagm {
virtual SkISize onISize() = 0;
virtual SkString onShortName() = 0;
virtual bool onAnimatePulse(SkMSec curr, SkMSec prev) { return false; }
virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
private:

View File

@ -70,6 +70,10 @@ protected:
fGM->drawBackground(canvas);
}
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
return fGM->animatePulse(curr, prev);
}
private:
GM* fGM;
typedef SampleView INHERITED;

View File

@ -11,14 +11,23 @@
#include "SkCanvas.h"
#include "SkRandom.h"
SkScalar get_anim_sin(SkMSec time, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) {
if (!periodInSec) {
return 0;
}
double t = (double)time / 1000.0 + phaseInSec;
t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
amplitude = SK_ScalarHalf * amplitude;
return amplitude * SkDoubleToScalar(sin(t)) + amplitude;
}
class AnimBlurView : public SampleView {
public:
AnimBlurView() {
}
AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "AnimBlur");
return true;
@ -26,17 +35,7 @@ protected:
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
SkScalar blurSigma = SampleCode::GetAnimSinScalar(100 * SK_Scalar1,
4 * SK_Scalar1,
5 * SK_Scalar1);
SkScalar circleRadius = 3 * SK_Scalar1 +
SampleCode::GetAnimSinScalar(150 * SK_Scalar1,
25 * SK_Scalar1,
3 * SK_Scalar1);
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
static const SkBlurStyle gStyles[] = {
kNormal_SkBlurStyle,
kInner_SkBlurStyle,
@ -48,20 +47,27 @@ protected:
for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) {
SkMaskFilter* mf = SkBlurMaskFilter::Create(
gStyles[i],
blurSigma,
fBlurSigma,
SkBlurMaskFilter::kHighQuality_BlurFlag);
SkPaint paint;
SkSafeUnref(paint.setMaskFilter(mf));
paint.setColor(random.nextU() | 0xff000000);
canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1,
200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1,
circleRadius, paint);
fCircleRadius, paint);
}
this->inval(NULL);
}
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
fBlurSigma = get_anim_sin(curr, 100, 4, 5);
fCircleRadius = 3 + get_anim_sin(curr, 150, 25, 3);
return true;
}
private:
typedef SkView INHERITED;
SkScalar fBlurSigma, fCircleRadius;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -1,97 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SampleCode.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
class GradientView : public SampleView {
public:
GradientView() {
this->setBGColor(0xFFDDDDDD);
}
protected:
struct GradData {
int fCount;
const SkColor* fColors;
const SkScalar* fPos;
};
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Gradients");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
paint.setStyle(SkPaint::kFill_Style);
SkPoint p = SkPoint::Make(0,0);
SkPoint q = SkPoint::Make(100,100);
SkPoint pts[] = {p, q};
SkScalar t, temp, x, y;
SkColor gColors[] = {
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
};
t = SampleCode::GetAnimScalar(SkIntToScalar(2), SkIntToScalar(20));
temp = SampleCode::GetAnimScalar(SkIntToScalar(1), SkIntToScalar(8));
SkScalar step = SK_ScalarPI / (10);
SkScalar angle = t * step;
x = SkScalarSinCos(angle, &y);
SkScalar colorPositions[] = { 0, 0.1 + x, 0.4 + y, 0.9 - x + y, 1.0};
GradData data = { 5, gColors, colorPositions };
SkRect r = { 0, 0, SkIntToScalar(200), SkIntToScalar(200) };
SkShader* shader1 = SkGradientShader::CreateLinear(
pts, data.fColors, data.fPos,data.fCount,
SkShader::kMirror_TileMode);
paint.setShader(shader1)->unref();
canvas->drawRect(r, paint);
SkPoint s = SkPoint::Make(100,100);
SkShader* shader2 = SkGradientShader::CreateRadial(
s, 100, data.fColors, data.fPos, data.fCount,
SkShader::kMirror_TileMode);
paint.setShader(shader2)->unref();
canvas->translate(250, 0);
canvas->drawRect(r, paint);
SkShader* shader3 = SkGradientShader::CreateTwoPointRadial(
p, 0, q, 100, data.fColors, data.fPos, data.fCount,
SkShader::kMirror_TileMode);
paint.setShader(shader3)->unref();
canvas->translate(0, 250);
canvas->drawRect(r, paint);
SkShader* shader4 = SkGradientShader::CreateSweep(
100, 100, data.fColors, data.fPos, data.fCount);
paint.setShader(shader4)->unref();
canvas->translate(-250, 0);
canvas->drawRect(r, paint);
this->inval(NULL);
}
private:
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new GradientView; }
static SkViewRegister reg(MyFactory);

View File

@ -662,6 +662,19 @@ static bool curr_title(SkWindow* wind, SkString* title) {
return false;
}
bool SampleWindow::sendAnimatePulse() {
SkView* view = curr_view(this);
if (SampleView::IsSampleView(view)) {
if (fDoAnimate) {
return ((SampleView*)view)->animatePulse(gAnimTime, gAnimTimePrev);
} else {
// 0 signals the view that we are no longer animating
((SampleView*)view)->animatePulse(0, 0);
}
}
return false;
}
void SampleWindow::setZoomCenter(float x, float y)
{
fZoomCenterX = x;
@ -823,6 +836,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fDeviceType = kANGLE_DeviceType;
#endif
fDoAnimate = true;
fUseClip = false;
fNClip = false;
fAnimating = false;
@ -1130,6 +1144,10 @@ void SampleWindow::draw(SkCanvas* canvas) {
this->postInvalDelay();
}
if (this->sendAnimatePulse()) {
this->inval(NULL);
}
// do this last
fDevManager->publishCanvas(fDeviceType, canvas, this);
}
@ -1709,6 +1727,12 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
}
switch (uni) {
case ' ':
fDoAnimate = !fDoAnimate;
if (this->sendAnimatePulse()) {
this->inval(NULL);
}
break;
case 'B':
post_event_to_sink(SkNEW_ARGS(SkEvent, ("PictFileView::toggleBBox")), curr_view(this));
// Cannot call updateTitle() synchronously, because the toggleBBox event is still in

View File

@ -175,6 +175,7 @@ private:
bool fSaveToPdf;
SkAutoTUnref<SkDocument> fPDFDocument;
bool fDoAnimate;
bool fUseClip;
bool fNClip;
bool fAnimating;
@ -238,6 +239,7 @@ private:
int findByTitle(const char*);
void listTitles();
SkSize tileSize() const;
bool sendAnimatePulse();
typedef SkOSWindow INHERITED;
};

View File

@ -195,9 +195,13 @@ protected:
}
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
fAnimatingDrawable->setSweep(SampleCode::GetAnimScalar(360/24, 360));
canvas->EXPERIMENTAL_drawDrawable(fRootDrawable);
this->inval(NULL);
}
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
SkScalar angle = SkDoubleToScalar(fmod(curr * 0.36 / 24, 360));
fAnimatingDrawable->setSweep(angle);
return true;
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {

View File

@ -86,12 +86,14 @@ protected:
SkRect r = { -150, -150, 150, 150 };
canvas->drawRoundRect(r, 30, 30, paint);
}
}
fRY += SampleCode::GetAnimSecondsDelta() * 90;
if (fRY >= SkIntToScalar(360)) {
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
fRY += (curr - prev) * 0.09f;
if (fRY >= 360) {
fRY = 0;
}
this->inval(NULL);
return true;
}
private:

View File

@ -36,6 +36,7 @@ public:
static bool FastTextQ(const SkEvent&);
private:
static SkMSec GetAnimTime();
static SkMSec GetAnimTimeDelta();
static SkScalar GetAnimSecondsDelta();
@ -44,6 +45,8 @@ public:
static SkScalar GetAnimSinScalar(SkScalar amplitude,
SkScalar periodInSec,
SkScalar phaseInSec = 0);
friend class SampleWindow;
};
//////////////////////////////////////////////////////////////////////////////
@ -117,6 +120,7 @@ public:
{}
void setBGColor(SkColor color) { fBGColor = color; }
bool animatePulse(SkMSec curr, SkMSec prev) { return this->onAnimatePulse(curr, prev); }
static bool IsSampleView(SkView*);
static bool SetRepeatDraw(SkView*, int count);
@ -136,6 +140,7 @@ public:
protected:
virtual void onDrawBackground(SkCanvas*);
virtual void onDrawContent(SkCanvas*) = 0;
virtual bool onAnimatePulse(SkMSec curr, SkMSec prev) { return false; }
// overrides
virtual bool onEvent(const SkEvent& evt);

View File

@ -37,7 +37,6 @@ static void draw_gradient2(SkCanvas* canvas, const SkRect& rect, SkScalar delta)
class DegenerateTwoPtRadialsView : public SampleView {
public:
DegenerateTwoPtRadialsView() {
fTime = 0;
@ -45,8 +44,7 @@ public:
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "DegenerateTwoPtRadials");
return true;
@ -54,8 +52,7 @@ protected:
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
fTime += SampleCode::GetAnimSecondsDelta();
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
SkScalar delta = fTime / 15.f;
int intPart = SkScalarFloorToInt(delta);
delta = delta - SK_Scalar1 * intPart;
@ -77,7 +74,11 @@ protected:
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLACK);
canvas->drawText(txt.c_str(), txt.size(), l + w/2 + w*DELTA_SCALE*delta, t + h + SK_Scalar1 * 10, paint);
this->inval(NULL);
}
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
fTime += (curr - prev) * 0.001f;
return true;
}
private:

View File

@ -46,6 +46,7 @@ class HTDrawable : public SkCanvasDrawable {
SkRect fR;
SkColor fColor;
SkInterpolator* fInterp;
SkMSec fTime;
public:
HTDrawable(SkRandom& rand) {
@ -53,18 +54,21 @@ public:
rand.nextRangeF(20, 200), rand.nextRangeF(20, 200));
fColor = rand_opaque_color(rand.nextU());
fInterp = NULL;
fTime = 0;
}
void spawnAnimation() {
void spawnAnimation(SkMSec now) {
this->setTime(now);
SkDELETE(fInterp);
fInterp = SkNEW_ARGS(SkInterpolator, (5, 3));
SkScalar values[5];
color_to_floats(fColor, values); values[4] = 0;
fInterp->setKeyFrame(0, SampleCode::GetAnimTime(), values);
fInterp->setKeyFrame(0, now, values);
values[0] = 0; values[4] = 180;
fInterp->setKeyFrame(1, SampleCode::GetAnimTime() + 1000, values);
fInterp->setKeyFrame(1, now + 1000, values);
color_to_floats(rand_opaque_color(fColor), values); values[4] = 360;
fInterp->setKeyFrame(2, SampleCode::GetAnimTime() + 2000, values);
fInterp->setKeyFrame(2, now + 2000, values);
fInterp->setMirror(true);
fInterp->setRepeatCount(3);
@ -76,6 +80,8 @@ public:
return oval_contains(fR, x, y);
}
void setTime(SkMSec time) { fTime = time; }
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkAutoCanvasRestore acr(canvas, false);
@ -84,7 +90,7 @@ public:
if (fInterp) {
SkScalar values[5];
SkInterpolator::Result res = fInterp->timeToValues(SampleCode::GetAnimTime(), values);
SkInterpolator::Result res = fInterp->timeToValues(fTime, values);
fColor = floats_to_color(values);
canvas->save();
@ -104,7 +110,7 @@ public:
paint.setColor(fColor);
canvas->drawRect(fR, paint);
}
SkRect onGetBounds() SK_OVERRIDE { return fR; }
};
@ -121,6 +127,7 @@ public:
};
Rec fArray[N];
SkAutoTUnref<SkCanvasDrawable> fRoot;
SkMSec fTime;
HTView() {
SkRandom rand;
@ -146,14 +153,21 @@ protected:
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
canvas->EXPERIMENTAL_drawDrawable(fRoot);
this->inval(NULL);
}
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
fTime = curr;
for (int i = 0; i < N; ++i) {
fArray[i].fDrawable->setTime(fTime);
}
return true;
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
// search backwards to find the top-most
for (int i = N - 1; i >= 0; --i) {
if (fArray[i].fDrawable->hitTest(x, y)) {
fArray[i].fDrawable->spawnAnimation();
fArray[i].fDrawable->spawnAnimation(fTime);
break;
}
}

View File

@ -30,20 +30,6 @@
static SkRandom gRand;
static void test_chromium_9005() {
SkBitmap bm;
bm.allocN32Pixels(800, 600);
SkCanvas canvas(bm);
SkPoint pt0 = { 799.33374f, 1.2360189f };
SkPoint pt1 = { 808.49969f, -7.4338055f };
SkPaint paint;
paint.setAntiAlias(true);
canvas.drawLine(pt0.fX, pt0.fY, pt1.fX, pt1.fY, paint);
}
static void generate_pts(SkPoint pts[], int count, int w, int h) {
for (int i = 0; i < count; i++) {
pts[i].set(gRand.nextUScalar1() * 3 * w - SkIntToScalar(w),
@ -191,7 +177,6 @@ class HairlineView : public SampleView {
bool fDoAA;
public:
HairlineView() {
fCounter = 0;
fProcIndex = 0;
fDoAA = true;
fNow = 0;
@ -199,7 +184,7 @@ public:
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SkString str;
str.printf("Hair-%s", gProcs[fProcIndex].fName);
@ -215,15 +200,9 @@ protected:
canvas->drawBitmap(b1, SkIntToScalar(b0.width()), 0, NULL);
}
int fCounter;
virtual void onDrawContent(SkCanvas* canvas) {
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
gRand.setSeed(fNow);
if (false) { // avoid bit rot, suppress warning
test_chromium_9005();
}
SkBitmap bm, bm2;
bm.allocN32Pixels(WIDTH + MARGIN*2, HEIGHT + MARGIN*2);
// this will erase our margin, which we want to always stay 0
@ -240,23 +219,18 @@ protected:
bm2.eraseColor(SK_ColorTRANSPARENT);
gProcs[fProcIndex].fProc(&c2, paint, bm);
canvas->drawBitmap(bm2, SkIntToScalar(10), SkIntToScalar(10), NULL);
SkMSec now = SampleCode::GetAnimTime();
if (fNow != now) {
fNow = now;
fCounter += 1;
fDoAA = !fDoAA;
if (fCounter > 50) {
fProcIndex = cycle_hairproc_index(fProcIndex);
// todo: signal that we want to rebuild our TITLE
fCounter = 0;
}
this->inval(NULL);
}
}
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
unsigned modi) {
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
if (fDoAA) {
fProcIndex = cycle_hairproc_index(fProcIndex);
// todo: signal that we want to rebuild our TITLE
}
fDoAA = !fDoAA;
return true;
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
fDoAA = !fDoAA;
this->inval(NULL);
return this->INHERITED::onFindClickHandler(x, y, modi);

View File

@ -21,13 +21,12 @@
#include "SkPixelXorXfermode.h"
#define CORNER_RADIUS 12
static SkScalar gPhase;
static const int gXY[] = {
4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
};
static SkPathEffect* make_pe(int flags) {
static SkPathEffect* make_pe(int flags, SkScalar phase) {
if (flags == 1)
return SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
@ -38,7 +37,8 @@ static SkPathEffect* make_pe(int flags) {
path.close();
path.offset(SkIntToScalar(-6), 0);
SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kRotate_Style);
SkPathEffect* outer = SkPath1DPathEffect::Create(path, 12, phase,
SkPath1DPathEffect::kRotate_Style);
if (flags == 2)
return outer;
@ -51,7 +51,7 @@ static SkPathEffect* make_pe(int flags) {
return pe;
}
static SkPathEffect* make_warp_pe() {
static SkPathEffect* make_warp_pe(SkScalar phase) {
SkPath path;
path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
@ -60,7 +60,7 @@ static SkPathEffect* make_warp_pe() {
path.offset(SkIntToScalar(-6), 0);
SkPathEffect* outer = SkPath1DPathEffect::Create(
path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kMorph_Style);
path, 12, phase, SkPath1DPathEffect::kMorph_Style);
SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
@ -80,29 +80,21 @@ public:
SkPaint paint;
paint.setAntiAlias(true);
#if 0
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SK_Scalar1*4);
this->addLayer(paint);
paint.setStrokeWidth(SK_Scalar1*1);
paint.setXfermode(SkXfermode::kClear_Mode);
this->addLayer(paint);
#else
paint.setAlpha(0x66);
this->addLayer(paint, SkIntToScalar(4), SkIntToScalar(4));
paint.setAlpha(0xFF);
this->addLayer(paint);
#endif
}
};
class PathEffectView : public SampleView {
SkPath fPath;
SkPoint fClickPt;
SkScalar fPhase;
public:
PathEffectView() {
PathEffectView() : fPhase(0) {
SkRandom rand;
int steps = 20;
SkScalar dist = SkIntToScalar(400);
@ -134,8 +126,7 @@ public:
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "PathEffects");
return true;
@ -143,45 +134,35 @@ protected:
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
gPhase -= SampleCode::GetAnimSecondsDelta() * 40;
this->inval(NULL);
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
#if 0
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(5));
canvas->drawPath(fPath, paint);
paint.setStrokeWidth(0);
paint.setColor(SK_ColorWHITE);
paint.setPathEffect(make_pe(1))->unref();
canvas->drawPath(fPath, paint);
#endif
canvas->translate(0, SkIntToScalar(50));
canvas->translate(0, 50);
paint.setColor(SK_ColorBLUE);
paint.setPathEffect(make_pe(2))->unref();
paint.setPathEffect(make_pe(2, fPhase))->unref();
canvas->drawPath(fPath, paint);
canvas->translate(0, SkIntToScalar(50));
canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0xBB, 0);
paint.setPathEffect(make_pe(3))->unref();
paint.setPathEffect(make_pe(3, fPhase))->unref();
canvas->drawPath(fPath, paint);
canvas->translate(0, SkIntToScalar(50));
canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0, 0);
paint.setPathEffect(make_warp_pe())->unref();
paint.setPathEffect(make_warp_pe(fPhase))->unref();
TestRastBuilder testRastBuilder;
paint.setRasterizer(testRastBuilder.detachRasterizer())->unref();
canvas->drawPath(fPath, paint);
}
bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
fPhase -= (curr - prev) * 0.04f;
return true;
}
private:
typedef SampleView INHERITED;
};

View File

@ -95,7 +95,7 @@ public:
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Picture");
return true;
@ -123,7 +123,7 @@ protected:
}
virtual void onDrawContent(SkCanvas* canvas) {
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
this->drawSomething(canvas);
SkPictureRecorder recorder;
@ -150,22 +150,6 @@ protected:
canvas->translate(-SkIntToScalar(100), 0);
canvas->drawPicture(pict);
canvas->restore();
#ifdef SK_DEVELOPER
if (false) {
SkDebugfDumper dumper;
SkDumpCanvas dumpCanvas(&dumper);
dumpCanvas.drawPicture(pict);
}
#endif
// This used to re-record the sub-picture and redraw the parent
// A capability that is now forbidden!
SkRandom rand(SampleCode::GetAnimTime());
canvas->translate(SkIntToScalar(10), SkIntToScalar(250));
canvas->drawPicture(fPicture);
delayInval(500);
}
private:
@ -175,7 +159,7 @@ private:
(new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay);
}
virtual bool onEvent(const SkEvent& evt) {
bool onEvent(const SkEvent& evt) SK_OVERRIDE {
if (evt.isType(INVAL_ALL_TYPE)) {
this->inval(NULL);
return true;

View File

@ -1,63 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
class SpiralView : public SampleView {
public:
SpiralView() {
this->setBGColor(0xFFDDDDDD);
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Spiral");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
paint.setStyle(SkPaint::kFill_Style);
SkRect r;
SkScalar l,t,x,y;
l = SampleCode::GetAnimScalar(SkIntToScalar(10),
SkIntToScalar(400));
t = SampleCode::GetAnimScalar(SkIntToScalar(5),
SkIntToScalar(200));
canvas->translate(320,240);
for (int i = 0; i < 35; i++) {
paint.setColor(0xFFF00FF0 - i * 0x04000000);
SkScalar step = SK_ScalarPI / (55 - i);
SkScalar angle = t * step;
x = (20 + SkIntToScalar(i) * 5) * SkScalarSinCos(angle, &y);
y *= (20 + SkIntToScalar(i) * 5);
r.set(x, y, x + SkIntToScalar(10), y + SkIntToScalar(10));
canvas->drawRect(r, paint);
}
this->inval(NULL);
}
private:
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new SpiralView; }
static SkViewRegister reg(MyFactory);