blob: a6643a688fc8dbe645a021f338ffdc9a4cd64241 [file] [log] [blame]
scroggo@google.com32f20eb2012-06-29 17:28:50 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "gm.h"
10
11#include "SkCanvas.h"
12#include "SkComposeShader.h"
13#include "SkGradientShader.h"
14#include "SkGraphics.h"
15#include "SkShader.h"
16#include "SkString.h"
17#include "SkXfermode.h"
18
19namespace skiagm {
20
21class ShaderGM : public GM {
22public:
23 ShaderGM() {
24 SkPoint pts[2];
25 SkColor colors[2];
26
27 pts[0].set(0, 0);
28 pts[1].set(SkIntToScalar(100), 0);
29 colors[0] = SK_ColorRED;
30 colors[1] = SK_ColorBLUE;
31 SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
32 SkShader::kClamp_TileMode);
33
34 pts[0].set(0, 0);
35 pts[1].set(0, SkIntToScalar(100));
36 colors[0] = SK_ColorBLACK;
37 colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
38 SkShader* shaderB = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
39 SkShader::kClamp_TileMode);
40
41 SkXfermode* mode = SkXfermode::Create(SkXfermode::kDstIn_Mode);
42
43 fShader = new SkComposeShader(shaderA, shaderB, mode);
44 shaderA->unref();
45 shaderB->unref();
46 mode->unref();
47 }
48
49 virtual ~ShaderGM() {
50 SkSafeUnref(fShader);
51 }
52
53protected:
54 virtual SkString onShortName() SK_OVERRIDE {
55 return SkString("composeshader");
56 }
57
58 virtual SkISize onISize() SK_OVERRIDE {
59 return make_isize(640, 480);
60 }
61
scroggo@google.com32f20eb2012-06-29 17:28:50 +000062 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
63
64 SkPaint paint;
scroggo@google.com32f20eb2012-06-29 17:28:50 +000065
66 paint.setColor(SK_ColorGREEN);
67 canvas->drawRectCoords(0, 0, SkIntToScalar(100), SkIntToScalar(100), paint);
68 paint.setShader(fShader);
69 canvas->drawRectCoords(0, 0, SkIntToScalar(100), SkIntToScalar(100), paint);
70 }
71
72private:
73 SkShader* fShader;
74 typedef GM INHERITED ;
75};
76
77//////////////////////////////////////////////////////////////////////////////
78
79static GM* MyFactory(void*) { return new ShaderGM; }
80static GMRegistry reg(MyFactory);
81
82} // namespace