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:
parent
c5907e53e5
commit
076f4c9791
@ -1,12 +1,11 @@
|
||||
|
||||
/*
|
||||
* 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 "gm.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkGraphics.h"
|
||||
#include "SkRandom.h"
|
||||
@ -16,12 +15,48 @@
|
||||
#define WIDTH 200
|
||||
#define HEIGHT 200
|
||||
|
||||
class LooperView : public SampleView {
|
||||
class DrawLooperGM : public skiagm::GM {
|
||||
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;
|
||||
|
||||
LooperView() {
|
||||
void init() {
|
||||
if (fLooper) return;
|
||||
|
||||
static const struct {
|
||||
SkColor fColor;
|
||||
SkPaint::Style fStyle;
|
||||
@ -34,9 +69,9 @@ public:
|
||||
{ SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 },
|
||||
{ 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), 3 }
|
||||
};
|
||||
|
||||
|
||||
fLooper = new SkLayerDrawLooper;
|
||||
|
||||
|
||||
SkLayerDrawLooper::LayerInfo info;
|
||||
info.fFlagsMask = SkPaint::kAntiAlias_Flag;
|
||||
info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMaskFilter_Bit;
|
||||
@ -55,45 +90,13 @@ public:
|
||||
paint->setMaskFilter(mf)->unref();
|
||||
}
|
||||
}
|
||||
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
virtual ~LooperView() {
|
||||
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;
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static SkView* MyFactory() { return new LooperView; }
|
||||
static SkViewRegister reg(MyFactory);
|
||||
static skiagm::GM* MyFactory(void*) { return new DrawLooperGM; }
|
||||
static skiagm::GMRegistry reg(MyFactory);
|
||||
|
@ -48,7 +48,6 @@
|
||||
'../samplecode/SampleDegenerateTwoPtRadials.cpp',
|
||||
'../samplecode/SampleDither.cpp',
|
||||
'../samplecode/SampleDitherBitmap.cpp',
|
||||
'../samplecode/SampleDrawLooper.cpp',
|
||||
'../samplecode/SampleEffects.cpp',
|
||||
'../samplecode/SampleEmboss.cpp',
|
||||
'../samplecode/SampleEmptyPath.cpp',
|
||||
|
@ -22,6 +22,7 @@
|
||||
'../gm/dashcubics.cpp',
|
||||
'../gm/dashing.cpp',
|
||||
'../gm/drawbitmaprect.cpp',
|
||||
'../gm/drawlooper.cpp',
|
||||
'../gm/extractbitmap.cpp',
|
||||
'../gm/emptypath.cpp',
|
||||
'../gm/filltypes.cpp',
|
||||
@ -34,6 +35,7 @@
|
||||
'../gm/gradtext.cpp',
|
||||
'../gm/hairmodes.cpp',
|
||||
'../gm/hittestpath.cpp',
|
||||
'../gm/image.cpp',
|
||||
'../gm/imageblur.cpp',
|
||||
'../gm/lighting.cpp',
|
||||
'../gm/imagefiltersbase.cpp',
|
||||
|
@ -201,6 +201,7 @@ void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
|
||||
Rec* rec = fRecs;
|
||||
for (int i = 0; i < fCount; i++) {
|
||||
buffer.writeInt(rec->fInfo.fFlagsMask);
|
||||
buffer.writeInt(rec->fInfo.fPaintBits);
|
||||
buffer.writeInt(rec->fInfo.fColorMode);
|
||||
buffer.writeScalar(rec->fInfo.fOffset.fX);
|
||||
@ -220,6 +221,7 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer)
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
LayerInfo info;
|
||||
info.fFlagsMask = buffer.readInt();
|
||||
info.fPaintBits = buffer.readInt();
|
||||
info.fColorMode = (SkXfermode::Mode)buffer.readInt();
|
||||
info.fOffset.fX = buffer.readScalar();
|
||||
|
Loading…
Reference in New Issue
Block a user