2011-10-10 14:08:47 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2011-10-10 14:08:47 +00:00
|
|
|
#include "SkShader.h"
|
|
|
|
|
2011-11-14 13:14:58 +00:00
|
|
|
static void test4(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPoint pts[] = {
|
|
|
|
{10, 160}, {610, 160},
|
|
|
|
{610, 160}, {10, 160},
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-11-14 13:14:58 +00:00
|
|
|
{610, 160}, {610, 160},
|
|
|
|
{610, 199}, {610, 199},
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-11-14 13:14:58 +00:00
|
|
|
{10, 198}, {610, 198},
|
|
|
|
{610, 199}, {10, 199},
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-11-14 13:14:58 +00:00
|
|
|
{10, 160}, {10, 160},
|
|
|
|
{10, 199}, {10, 199}
|
|
|
|
};
|
|
|
|
char verbs[] = {
|
2012-08-23 18:14:13 +00:00
|
|
|
0, 1, 1, 1, 4,
|
2011-11-14 13:14:58 +00:00
|
|
|
0, 1, 1, 1, 4,
|
|
|
|
0, 1, 1, 1, 4,
|
|
|
|
0, 1, 1, 1, 4
|
|
|
|
};
|
|
|
|
SkPath path;
|
|
|
|
SkPoint* ptPtr = pts;
|
2011-11-23 15:01:08 +00:00
|
|
|
for (size_t i = 0; i < sizeof(verbs); ++i) {
|
2011-11-14 13:14:58 +00:00
|
|
|
switch ((SkPath::Verb) verbs[i]) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
path.moveTo(ptPtr->fX, ptPtr->fY);
|
|
|
|
++ptPtr;
|
|
|
|
break;
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
path.lineTo(ptPtr->fX, ptPtr->fY);
|
|
|
|
++ptPtr;
|
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
path.close();
|
|
|
|
break;
|
2011-11-23 15:01:08 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
break;
|
2011-11-14 13:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SkRect clip = {0, 130, 772, 531};
|
|
|
|
canvas->clipRect(clip);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
2011-10-10 14:08:47 +00:00
|
|
|
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);
|
|
|
|
|
2016-03-29 18:32:50 +00:00
|
|
|
static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, SkAlpha a1) {
|
2011-10-10 14:08:47 +00:00
|
|
|
|
|
|
|
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);
|
2016-03-29 18:32:50 +00:00
|
|
|
paint.setXfermode(std::move(mode));
|
2011-10-10 14:08:47 +00:00
|
|
|
|
|
|
|
SkScalar offset = SK_Scalar1 / 3;
|
|
|
|
SkRect rect = SkRect::MakeXYWH(W / 4 + offset,
|
|
|
|
H / 4 + offset,
|
|
|
|
W / 2, H / 2);
|
|
|
|
canvas->drawRect(rect, paint);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-10-10 14:08:47 +00:00
|
|
|
return H;
|
|
|
|
}
|
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_bg_shader() {
|
2011-10-10 14:08:47 +00:00
|
|
|
SkBitmap bm;
|
2014-01-25 16:46:20 +00:00
|
|
|
bm.allocN32Pixels(2, 2);
|
2011-10-10 14:08:47 +00:00
|
|
|
*bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
|
2015-07-29 12:27:47 +00:00
|
|
|
*bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCE,
|
|
|
|
0xCF, 0xCE);
|
2011-10-10 14:08:47 +00:00
|
|
|
|
2015-03-27 02:57:08 +00:00
|
|
|
const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(6), SkIntToScalar(6));
|
2016-03-09 17:50:50 +00:00
|
|
|
return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
|
|
|
|
&m);
|
2011-10-10 14:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace skiagm {
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-10-10 14:08:47 +00:00
|
|
|
class AARectModesGM : public GM {
|
|
|
|
SkPaint fBGPaint;
|
|
|
|
public:
|
|
|
|
AARectModesGM () {
|
2016-03-09 17:50:50 +00:00
|
|
|
fBGPaint.setShader(make_bg_shader());
|
2011-10-10 14:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2011-10-10 14:08:47 +00:00
|
|
|
return SkString("aarectmodes");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(640, 480); }
|
2011-10-10 14:08:47 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-06-06 12:10:45 +00:00
|
|
|
if (false) { // avoid bit rot, suppress warning
|
|
|
|
test4(canvas);
|
|
|
|
}
|
2011-10-10 14:08:47 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
canvas->drawRect(bounds, fBGPaint);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(&bounds, nullptr);
|
2016-03-29 18:32:50 +00:00
|
|
|
SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fMode),
|
2011-10-10 14:08:47 +00:00
|
|
|
gAlphaValue[alpha & 1],
|
|
|
|
gAlphaValue[alpha & 2]);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->translate(0, dy * 5 / 4);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(W * 5 / 4, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new AARectModesGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|