2013-12-30 04:07:34 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2016-03-08 19:53:31 +00:00
|
|
|
#include "SkColorFilter.h"
|
2013-12-30 04:07:34 +00:00
|
|
|
#include "SkGradientShader.h"
|
2013-12-30 04:20:38 +00:00
|
|
|
#include "SkRandom.h"
|
2013-12-30 04:07:34 +00:00
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> make_shader1(SkScalar w, SkScalar h) {
|
2013-12-30 15:51:25 +00:00
|
|
|
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 } };
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
|
|
|
|
SkShader::kMirror_TileMode);
|
2013-12-30 04:07:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> make_shader2() {
|
|
|
|
return SkShader::MakeColorShader(SK_ColorBLUE);
|
2016-03-08 19:53:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:17:23 +00:00
|
|
|
static sk_sp<SkColorFilter> make_color_filter() {
|
|
|
|
return SkColorFilter::MakeModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode);
|
2016-03-08 19:53:31 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 04:07:34 +00:00
|
|
|
class VerticesGM : public skiagm::GM {
|
2016-03-22 17:17:23 +00:00
|
|
|
SkPoint fPts[9];
|
|
|
|
SkPoint fTexs[9];
|
|
|
|
SkColor fColors[9];
|
|
|
|
sk_sp<SkShader> fShader1;
|
|
|
|
sk_sp<SkShader> fShader2;
|
|
|
|
sk_sp<SkColorFilter> fColorFilter;
|
2013-12-30 04:07:34 +00:00
|
|
|
|
|
|
|
public:
|
2016-03-08 19:53:31 +00:00
|
|
|
VerticesGM() {}
|
2013-12-30 04:07:34 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-03-08 19:53:31 +00:00
|
|
|
const SkScalar X = 30;
|
|
|
|
const SkScalar Y = 30;
|
2013-12-30 15:51:25 +00:00
|
|
|
|
2016-03-08 19:53:31 +00:00
|
|
|
fPts[0].set(0, 0); fPts[1].set(X/2, 3); fPts[2].set(X, 0);
|
|
|
|
fPts[3].set(3, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-3, Y/2);
|
|
|
|
fPts[6].set(0, Y); fPts[7].set(X/2, Y-3); fPts[8].set(X, Y);
|
2013-12-30 04:07:34 +00:00
|
|
|
|
2016-03-08 19:53:31 +00:00
|
|
|
const SkScalar w = 40;
|
|
|
|
const SkScalar h = 40;
|
2013-12-30 04:07:34 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
fShader1 = make_shader1(w, h);
|
|
|
|
fShader2 = make_shader2();
|
2016-03-22 17:17:23 +00:00
|
|
|
fColorFilter = make_color_filter();
|
2013-12-30 04:07:34 +00:00
|
|
|
|
|
|
|
SkRandom rand;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) {
|
2013-12-30 15:51:25 +00:00
|
|
|
fColors[i] = rand.nextU() | 0xFF000000;
|
2013-12-30 04:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-05-05 20:41:21 +00:00
|
|
|
SkString name("vertices");
|
|
|
|
return name;
|
2013-12-30 04:07:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-12-30 15:51:25 +00:00
|
|
|
return SkISize::Make(600, 600);
|
2013-12-30 04:07:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-12-30 15:51:25 +00:00
|
|
|
// start with the center of a 3x3 grid
|
2013-12-30 04:07:34 +00:00
|
|
|
static const uint16_t fan[] = {
|
|
|
|
4,
|
|
|
|
0, 1, 2, 5, 8, 7, 6, 3, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct {
|
2016-03-22 17:17:23 +00:00
|
|
|
const SkColor* fColors;
|
|
|
|
const SkPoint* fTexs;
|
|
|
|
const sk_sp<SkShader>& fShader;
|
|
|
|
const sk_sp<SkColorFilter>& fColorFilter;
|
|
|
|
uint8_t fAlpha;
|
2013-12-30 04:07:34 +00:00
|
|
|
} rec[] = {
|
2016-03-08 19:53:31 +00:00
|
|
|
{ fColors, nullptr, fShader1, nullptr , 0xFF },
|
|
|
|
{ nullptr, fTexs , fShader1, nullptr , 0xFF },
|
|
|
|
{ fColors, fTexs , fShader1, nullptr , 0xFF },
|
|
|
|
{ fColors, nullptr, fShader2, nullptr , 0xFF },
|
|
|
|
{ nullptr, fTexs , fShader2, nullptr , 0xFF },
|
|
|
|
{ fColors, fTexs , fShader2, nullptr , 0xFF },
|
|
|
|
{ fColors, nullptr, fShader1, fColorFilter, 0xFF },
|
|
|
|
{ nullptr, fTexs , fShader1, fColorFilter, 0xFF },
|
|
|
|
{ fColors, fTexs , fShader1, fColorFilter, 0xFF },
|
|
|
|
{ fColors, nullptr, fShader2, fColorFilter, 0xFF },
|
|
|
|
{ nullptr, fTexs , fShader2, fColorFilter, 0xFF },
|
|
|
|
{ fColors, fTexs , fShader2, fColorFilter, 0xFF },
|
|
|
|
{ fColors, nullptr, fShader1, nullptr , 0x80 },
|
|
|
|
{ nullptr, fTexs , fShader1, nullptr , 0x80 },
|
|
|
|
{ fColors, fTexs , fShader1, nullptr , 0x80 },
|
|
|
|
{ fColors, nullptr, fShader2, nullptr , 0x80 },
|
|
|
|
{ nullptr, fTexs , fShader2, nullptr , 0x80 },
|
|
|
|
{ fColors, fTexs , fShader2, nullptr , 0x80 },
|
|
|
|
{ fColors, nullptr, fShader1, fColorFilter, 0x80 },
|
|
|
|
{ nullptr, fTexs , fShader1, fColorFilter, 0x80 },
|
|
|
|
{ fColors, fTexs , fShader1, fColorFilter, 0x80 },
|
|
|
|
{ fColors, nullptr, fShader2, fColorFilter, 0x80 },
|
|
|
|
{ nullptr, fTexs , fShader2, fColorFilter, 0x80 },
|
|
|
|
{ fColors, fTexs , fShader2, fColorFilter, 0x80 },
|
2013-12-30 04:07:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SkXfermode::Mode modes[] = {
|
2016-03-08 19:53:31 +00:00
|
|
|
SkXfermode::kClear_Mode,
|
2013-12-30 04:07:34 +00:00
|
|
|
SkXfermode::kSrc_Mode,
|
|
|
|
SkXfermode::kDst_Mode,
|
2016-03-08 19:53:31 +00:00
|
|
|
SkXfermode::kSrcOver_Mode,
|
|
|
|
SkXfermode::kDstOver_Mode,
|
|
|
|
SkXfermode::kSrcIn_Mode,
|
|
|
|
SkXfermode::kDstIn_Mode,
|
|
|
|
SkXfermode::kSrcOut_Mode,
|
|
|
|
SkXfermode::kDstOut_Mode,
|
|
|
|
SkXfermode::kSrcATop_Mode,
|
|
|
|
SkXfermode::kDstATop_Mode,
|
|
|
|
SkXfermode::kXor_Mode,
|
|
|
|
SkXfermode::kPlus_Mode,
|
2013-12-30 04:07:34 +00:00
|
|
|
SkXfermode::kModulate_Mode,
|
2016-03-08 19:53:31 +00:00
|
|
|
SkXfermode::kScreen_Mode,
|
|
|
|
SkXfermode::kOverlay_Mode,
|
|
|
|
SkXfermode::kDarken_Mode,
|
|
|
|
SkXfermode::kLighten_Mode,
|
|
|
|
SkXfermode::kColorDodge_Mode,
|
|
|
|
SkXfermode::kColorBurn_Mode,
|
|
|
|
SkXfermode::kHardLight_Mode,
|
|
|
|
SkXfermode::kSoftLight_Mode,
|
|
|
|
SkXfermode::kDifference_Mode,
|
|
|
|
SkXfermode::kExclusion_Mode,
|
|
|
|
SkXfermode::kMultiply_Mode,
|
|
|
|
SkXfermode::kHue_Mode,
|
|
|
|
SkXfermode::kSaturation_Mode,
|
|
|
|
SkXfermode::kColor_Mode,
|
|
|
|
SkXfermode::kLuminosity_Mode,
|
2013-12-30 04:07:34 +00:00
|
|
|
};
|
2013-12-30 07:01:37 +00:00
|
|
|
|
2013-12-30 04:07:34 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
2016-03-08 19:53:31 +00:00
|
|
|
canvas->translate(4, 4);
|
|
|
|
int x = 0;
|
2013-12-30 04:07:34 +00:00
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(modes); ++j) {
|
2016-03-29 18:32:50 +00:00
|
|
|
auto xfer = SkXfermode::Make(modes[j]);
|
2013-12-30 04:07:34 +00:00
|
|
|
canvas->save();
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
|
2016-03-08 19:53:31 +00:00
|
|
|
paint.setShader(rec[i].fShader);
|
|
|
|
paint.setColorFilter(rec[i].fColorFilter);
|
|
|
|
paint.setAlpha(rec[i].fAlpha);
|
|
|
|
//if (2 == x)
|
2013-12-30 04:07:34 +00:00
|
|
|
canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode,
|
|
|
|
SK_ARRAY_COUNT(fPts), fPts,
|
|
|
|
rec[i].fTexs, rec[i].fColors,
|
|
|
|
xfer, fan, SK_ARRAY_COUNT(fan), paint);
|
2016-03-08 19:53:31 +00:00
|
|
|
canvas->translate(40, 0);
|
|
|
|
++x;
|
2013-12-30 04:07:34 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
2016-03-08 19:53:31 +00:00
|
|
|
canvas->translate(0, 40);
|
2013-12-30 04:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2014-05-05 20:41:21 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-03-08 19:53:31 +00:00
|
|
|
DEF_GM(return new VerticesGM();)
|