skia2/gm/vertices.cpp
commit-bot@chromium.org a90c680386 Turn on quilt mode in DM.
- Rename TileGrid -> Quilt to avoid the name overload.
  - Tag all failing GMs with kSkipTiled_Flag.

You may be wondering, do any GMs pass?  Yes, some do!  And that trends towards all of them as we increase --quiltTile.

Two GMs only fail in --quilt mode in 565.  Otherwise all GMs which fail are skipped, and those which don't fail aren't. (The 8888 variants of those two GMs are skipped even though they pass.)

BUG=skia:2477
R=reed@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/256373002

git-svn-id: http://skia.googlecode.com/svn/trunk@14457 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-04-30 13:20:45 +00:00

122 lines
3.4 KiB
C++

/*
* Copyright 2013 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 "SkGradientShader.h"
#include "SkRandom.h"
static SkShader* make_shader(SkScalar w, SkScalar h) {
const SkColor colors[] = {
SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
};
const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } };
return SkGradientShader::CreateLinear(pts, colors, NULL,
SK_ARRAY_COUNT(colors),
SkShader::kMirror_TileMode);
}
class VerticesGM : public skiagm::GM {
SkPoint fPts[9];
SkPoint fTexs[9];
SkColor fColors[9];
SkShader* fShader;
public:
VerticesGM() : fShader(NULL) {
}
virtual ~VerticesGM() {
SkSafeUnref(fShader);
}
protected:
virtual uint32_t onGetFlags() const SK_OVERRIDE {
return kSkipTiled_Flag;
}
virtual void onOnceBeforeDraw() SK_OVERRIDE {
const SkScalar X = 150;
const SkScalar Y = 150;
fPts[0].set(0, 0); fPts[1].set(X/2, 10); fPts[2].set(X, 0);
fPts[3].set(10, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-10, Y/2);
fPts[6].set(0, Y); fPts[7].set(X/2, Y-10); fPts[8].set(X, Y);
const SkScalar w = 200;
const SkScalar h = 200;
fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0);
fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2);
fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h);
fShader = make_shader(w, h);
SkRandom rand;
for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) {
fColors[i] = rand.nextU() | 0xFF000000;
}
}
virtual SkString onShortName() SK_OVERRIDE {
return SkString("vertices");
}
virtual SkISize onISize() SK_OVERRIDE {
return SkISize::Make(600, 600);
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
// start with the center of a 3x3 grid
static const uint16_t fan[] = {
4,
0, 1, 2, 5, 8, 7, 6, 3, 0
};
const struct {
const SkColor* fColors;
const SkPoint* fTexs;
} rec[] = {
{ fColors, NULL },
{ NULL, fTexs },
{ fColors, fTexs },
};
const SkXfermode::Mode modes[] = {
SkXfermode::kSrc_Mode,
SkXfermode::kDst_Mode,
SkXfermode::kModulate_Mode,
};
SkPaint paint;
paint.setShader(fShader);
canvas->translate(20, 20);
for (size_t j = 0; j < SK_ARRAY_COUNT(modes); ++j) {
SkXfermode* xfer = SkXfermode::Create(modes[j]);
canvas->save();
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode,
SK_ARRAY_COUNT(fPts), fPts,
rec[i].fTexs, rec[i].fColors,
xfer, fan, SK_ARRAY_COUNT(fan), paint);
canvas->translate(200, 0);
}
canvas->restore();
canvas->translate(0, 200);
xfer->unref();
}
}
private:
typedef skiagm::GM INHERITED;
};
DEF_GM( return SkNEW(VerticesGM); )