fix LayerDrawLooper to record its fFlagsMask

convert SampleDrawLooper to a GM



git-svn-id: http://skia.googlecode.com/svn/trunk@4854 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-07-31 14:32:38 +00:00
parent c5907e53e5
commit 076f4c9791
4 changed files with 49 additions and 43 deletions

View File

@ -1,12 +1,11 @@
/* /*
* Copyright 2011 Google Inc. * Copyright 2011 Google Inc.
* *
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "SampleCode.h"
#include "SkView.h" #include "gm.h"
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkGraphics.h" #include "SkGraphics.h"
#include "SkRandom.h" #include "SkRandom.h"
@ -16,12 +15,48 @@
#define WIDTH 200 #define WIDTH 200
#define HEIGHT 200 #define HEIGHT 200
class LooperView : public SampleView { class DrawLooperGM : public skiagm::GM {
public: public:
DrawLooperGM() : fLooper(NULL) {
this->setBGColor(0xFFDDDDDD);
}
virtual ~DrawLooperGM() {
SkSafeUnref(fLooper);
}
protected:
virtual SkISize onISize() {
return SkISize::Make(520, 160);
}
virtual SkString onShortName() SK_OVERRIDE {
return SkString("drawlooper");
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
this->init();
SkPaint paint;
paint.setTextSize(SkIntToScalar(72));
paint.setLooper(fLooper);
canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
SkIntToScalar(30), paint);
canvas->drawRectCoords(SkIntToScalar(150), SkIntToScalar(50),
SkIntToScalar(200), SkIntToScalar(100), paint);
canvas->drawText("Looper", 6, SkIntToScalar(230), SkIntToScalar(100),
paint);
}
private:
SkLayerDrawLooper* fLooper; SkLayerDrawLooper* fLooper;
LooperView() { void init() {
if (fLooper) return;
static const struct { static const struct {
SkColor fColor; SkColor fColor;
SkPaint::Style fStyle; SkPaint::Style fStyle;
@ -34,9 +69,9 @@ public:
{ SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 }, { SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 },
{ 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), 3 } { 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), 3 }
}; };
fLooper = new SkLayerDrawLooper; fLooper = new SkLayerDrawLooper;
SkLayerDrawLooper::LayerInfo info; SkLayerDrawLooper::LayerInfo info;
info.fFlagsMask = SkPaint::kAntiAlias_Flag; info.fFlagsMask = SkPaint::kAntiAlias_Flag;
info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMaskFilter_Bit; info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMaskFilter_Bit;
@ -55,45 +90,13 @@ public:
paint->setMaskFilter(mf)->unref(); paint->setMaskFilter(mf)->unref();
} }
} }
this->setBGColor(0xFFDDDDDD);
} }
virtual ~LooperView() { typedef GM INHERITED;
SkSafeUnref(fLooper);
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "DrawLooper");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
SkPaint paint;
paint.setTextSize(SkIntToScalar(72));
paint.setLooper(fLooper);
canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
SkIntToScalar(30), paint);
canvas->drawRectCoords(SkIntToScalar(150), SkIntToScalar(50),
SkIntToScalar(200), SkIntToScalar(100), paint);
canvas->drawText("Looper", 6, SkIntToScalar(230), SkIntToScalar(100),
paint);
}
private:
typedef SampleView INHERITED;
}; };
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new LooperView; } static skiagm::GM* MyFactory(void*) { return new DrawLooperGM; }
static SkViewRegister reg(MyFactory); static skiagm::GMRegistry reg(MyFactory);

View File

@ -48,7 +48,6 @@
'../samplecode/SampleDegenerateTwoPtRadials.cpp', '../samplecode/SampleDegenerateTwoPtRadials.cpp',
'../samplecode/SampleDither.cpp', '../samplecode/SampleDither.cpp',
'../samplecode/SampleDitherBitmap.cpp', '../samplecode/SampleDitherBitmap.cpp',
'../samplecode/SampleDrawLooper.cpp',
'../samplecode/SampleEffects.cpp', '../samplecode/SampleEffects.cpp',
'../samplecode/SampleEmboss.cpp', '../samplecode/SampleEmboss.cpp',
'../samplecode/SampleEmptyPath.cpp', '../samplecode/SampleEmptyPath.cpp',

View File

@ -22,6 +22,7 @@
'../gm/dashcubics.cpp', '../gm/dashcubics.cpp',
'../gm/dashing.cpp', '../gm/dashing.cpp',
'../gm/drawbitmaprect.cpp', '../gm/drawbitmaprect.cpp',
'../gm/drawlooper.cpp',
'../gm/extractbitmap.cpp', '../gm/extractbitmap.cpp',
'../gm/emptypath.cpp', '../gm/emptypath.cpp',
'../gm/filltypes.cpp', '../gm/filltypes.cpp',
@ -34,6 +35,7 @@
'../gm/gradtext.cpp', '../gm/gradtext.cpp',
'../gm/hairmodes.cpp', '../gm/hairmodes.cpp',
'../gm/hittestpath.cpp', '../gm/hittestpath.cpp',
'../gm/image.cpp',
'../gm/imageblur.cpp', '../gm/imageblur.cpp',
'../gm/lighting.cpp', '../gm/lighting.cpp',
'../gm/imagefiltersbase.cpp', '../gm/imagefiltersbase.cpp',

View File

@ -201,6 +201,7 @@ void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const {
Rec* rec = fRecs; Rec* rec = fRecs;
for (int i = 0; i < fCount; i++) { for (int i = 0; i < fCount; i++) {
buffer.writeInt(rec->fInfo.fFlagsMask);
buffer.writeInt(rec->fInfo.fPaintBits); buffer.writeInt(rec->fInfo.fPaintBits);
buffer.writeInt(rec->fInfo.fColorMode); buffer.writeInt(rec->fInfo.fColorMode);
buffer.writeScalar(rec->fInfo.fOffset.fX); buffer.writeScalar(rec->fInfo.fOffset.fX);
@ -220,6 +221,7 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer)
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
LayerInfo info; LayerInfo info;
info.fFlagsMask = buffer.readInt();
info.fPaintBits = buffer.readInt(); info.fPaintBits = buffer.readInt();
info.fColorMode = (SkXfermode::Mode)buffer.readInt(); info.fColorMode = (SkXfermode::Mode)buffer.readInt();
info.fOffset.fX = buffer.readScalar(); info.fOffset.fX = buffer.readScalar();