add gm test for drawing hairlines (and varying thin lines) in xfermodes
add --nopdf option to gm app git-svn-id: http://skia.googlecode.com/svn/trunk@2281 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
3ad3d44f15
commit
ab9739777c
@ -511,6 +511,7 @@ int main(int argc, char * const argv[]) {
|
||||
const char* diffPath = NULL; // if non-null, where we write our diffs (from compare)
|
||||
const char* matchStr = NULL;
|
||||
|
||||
bool doPDF = true;
|
||||
bool doReplay = true;
|
||||
bool doSerialize = false;
|
||||
const char* const commandName = argv[0];
|
||||
@ -533,6 +534,8 @@ int main(int argc, char * const argv[]) {
|
||||
}
|
||||
} else if (strcmp(*argv, "--noreplay") == 0) {
|
||||
doReplay = false;
|
||||
} else if (strcmp(*argv, "--nopdf") == 0) {
|
||||
doPDF = false;
|
||||
} else if (strcmp(*argv, "--serialize") == 0) {
|
||||
doSerialize = true;
|
||||
} else if (strcmp(*argv, "--match") == 0) {
|
||||
@ -604,6 +607,10 @@ int main(int argc, char * const argv[]) {
|
||||
SkBitmap forwardRenderedBitmap;
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
|
||||
if ((kPDF_Backend == gRec[i].fBackend) && !doPDF) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool testSuccess = test_drawing(gm, gRec[i],
|
||||
writePath, readPath, diffPath, gGrContext,
|
||||
rt, &forwardRenderedBitmap);
|
||||
|
150
gm/hairmodes.cpp
Normal file
150
gm/hairmodes.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 "gm.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorPriv.h"
|
||||
#include "SkShader.h"
|
||||
|
||||
static SkCanvas* create_canvas(int w, int h) {
|
||||
SkBitmap bm;
|
||||
bm.setConfig(SkBitmap::kARGB_8888_Config, w, h);
|
||||
bm.allocPixels();
|
||||
bm.eraseColor(0);
|
||||
return new SkCanvas(bm);
|
||||
}
|
||||
|
||||
static const SkBitmap& extract_bitmap(SkCanvas* canvas) {
|
||||
return canvas->getDevice()->accessBitmap(false);
|
||||
}
|
||||
|
||||
static const struct {
|
||||
SkXfermode::Mode fMode;
|
||||
const char* fLabel;
|
||||
} gModes[] = {
|
||||
{ SkXfermode::kClear_Mode, "Clear" },
|
||||
{ SkXfermode::kSrc_Mode, "Src" },
|
||||
{ SkXfermode::kDst_Mode, "Dst" },
|
||||
{ SkXfermode::kSrcOver_Mode, "SrcOver" },
|
||||
{ SkXfermode::kDstOver_Mode, "DstOver" },
|
||||
{ SkXfermode::kSrcIn_Mode, "SrcIn" },
|
||||
{ SkXfermode::kDstIn_Mode, "DstIn" },
|
||||
{ SkXfermode::kSrcOut_Mode, "SrcOut" },
|
||||
{ SkXfermode::kDstOut_Mode, "DstOut" },
|
||||
{ SkXfermode::kSrcATop_Mode, "SrcATop" },
|
||||
{ SkXfermode::kDstATop_Mode, "DstATop" },
|
||||
{ SkXfermode::kXor_Mode, "Xor" },
|
||||
};
|
||||
|
||||
const int gWidth = 64;
|
||||
const int gHeight = 64;
|
||||
const SkScalar W = SkIntToScalar(gWidth);
|
||||
const SkScalar H = SkIntToScalar(gHeight);
|
||||
|
||||
static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha a1) {
|
||||
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
SkRect r = SkRect::MakeWH(W, H);
|
||||
r.inset(W/10, H/10);
|
||||
|
||||
paint.setColor(SK_ColorBLUE);
|
||||
paint.setAlpha(a0);
|
||||
canvas->drawOval(r, paint);
|
||||
|
||||
paint.setColor(SK_ColorRED);
|
||||
paint.setAlpha(a1);
|
||||
paint.setXfermode(mode);
|
||||
for (int angle = 0; angle < 24; ++angle) {
|
||||
SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth;
|
||||
SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight;
|
||||
paint.setStrokeWidth(SK_Scalar1 * angle * 2 / 24);
|
||||
canvas->drawLine(W/2, H/2, W/2 + x, H/2 + y, paint);
|
||||
}
|
||||
|
||||
return H;
|
||||
}
|
||||
|
||||
static SkShader* make_bg_shader() {
|
||||
SkBitmap bm;
|
||||
bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
|
||||
bm.allocPixels();
|
||||
*bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
|
||||
*bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCC, 0xCC, 0xCC);
|
||||
|
||||
SkShader* s = SkShader::CreateBitmapShader(bm,
|
||||
SkShader::kRepeat_TileMode,
|
||||
SkShader::kRepeat_TileMode);
|
||||
|
||||
SkMatrix m;
|
||||
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
|
||||
s->setLocalMatrix(m);
|
||||
return s;
|
||||
}
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
class HairModesGM : public GM {
|
||||
SkPaint fBGPaint;
|
||||
public:
|
||||
HairModesGM() {
|
||||
fBGPaint.setShader(make_bg_shader())->unref();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual SkString onShortName() {
|
||||
return SkString("hairmodes");
|
||||
}
|
||||
|
||||
virtual SkISize onISize() { return make_isize(640, 480); }
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
canvas->drawColor(SK_ColorWHITE);
|
||||
|
||||
const SkRect bounds = SkRect::MakeWH(W, H);
|
||||
static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
|
||||
|
||||
canvas->translate(SkIntToScalar(4), SkIntToScalar(4));
|
||||
|
||||
for (int alpha = 0; alpha < 4; ++alpha) {
|
||||
canvas->save();
|
||||
canvas->save();
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) {
|
||||
if (6 == i) {
|
||||
canvas->restore();
|
||||
canvas->translate(W * 5, 0);
|
||||
canvas->save();
|
||||
}
|
||||
SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
|
||||
|
||||
canvas->drawRect(bounds, fBGPaint);
|
||||
canvas->saveLayer(&bounds, NULL);
|
||||
SkScalar dy = drawCell(canvas, mode,
|
||||
gAlphaValue[alpha & 1],
|
||||
gAlphaValue[alpha & 2]);
|
||||
canvas->restore();
|
||||
|
||||
canvas->translate(0, dy * 5 / 4);
|
||||
SkSafeUnref(mode);
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->restore();
|
||||
canvas->translate(W * 5 / 4, 0);
|
||||
}
|
||||
}
|
||||
private:
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static GM* MyFactory(void*) { return new HairModesGM; }
|
||||
static GMRegistry reg(MyFactory);
|
||||
|
||||
}
|
@ -71,6 +71,7 @@
|
||||
'../samplecode/SampleGradients.cpp',
|
||||
'../samplecode/SampleHairCurves.cpp',
|
||||
'../samplecode/SampleHairline.cpp',
|
||||
'../samplecode/SampleHairModes.cpp',
|
||||
'../samplecode/SampleImage.cpp',
|
||||
'../samplecode/SampleImageDir.cpp',
|
||||
'../samplecode/SampleLayerMask.cpp',
|
||||
|
@ -18,6 +18,7 @@
|
||||
'../gm/filltypespersp.cpp',
|
||||
'../gm/gmmain.cpp',
|
||||
'../gm/gradients.cpp',
|
||||
'../gm/hairmodes.cpp',
|
||||
'../gm/lcdtext.cpp',
|
||||
'../gm/ninepatchstretch.cpp',
|
||||
'../gm/nocolorbleed.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user