blob: 7597090aa872bfa9a0510c6e57687d15e47a427b [file] [log] [blame]
commit-bot@chromium.org40eb3c12014-01-06 23:41:14 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkAlphaThresholdFilter.h"
10#include "SkRandom.h"
11
12#define WIDTH 500
13#define HEIGHT 500
14
15namespace skiagm {
16
17class ImageAlphaThresholdGM : public GM {
18public:
19 ImageAlphaThresholdGM() {
20 this->setBGColor(0xFFFFFFFF);
21 }
22
23protected:
24 virtual uint32_t onGetFlags() const SK_OVERRIDE {
25 return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag;
26 }
27
28 virtual SkString onShortName() SK_OVERRIDE {
29 return SkString("imagealphathreshold");
30 }
31
32 virtual SkISize onISize() SK_OVERRIDE {
33 return make_isize(WIDTH, HEIGHT);
34 }
35
36 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
37 SkIRect rects[2];
38 rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
39 rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
40 SkRegion region;
41 region.setRects(rects, 2);
42
43 SkMatrix matrix;
44 matrix.reset();
45 matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f);
commit-bot@chromium.org9109e182014-01-07 16:04:01 +000046 matrix.postScale(.8f, .8f);
commit-bot@chromium.org40eb3c12014-01-06 23:41:14 +000047
48 canvas->concat(matrix);
49
50 SkPaint paint;
51 paint.setImageFilter(
52 SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref();
53 canvas->saveLayer(NULL, &paint);
54 paint.setAntiAlias(true);
55
56 SkPaint rect_paint;
57 rect_paint.setColor(0xFF0000FF);
58 canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2),
59 rect_paint);
60 rect_paint.setColor(0xBFFF0000);
61 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2),
62 rect_paint);
63 rect_paint.setColor(0x3F00FF00);
64 canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
65 rect_paint);
66 rect_paint.setColor(0x00000000);
67 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
68 rect_paint);
69
70 canvas->restore();
71 }
72
73private:
74 typedef GM INHERITED;
75};
76
77//////////////////////////////////////////////////////////////////////////////
78
79static GM* MyFactory(void*) { return new ImageAlphaThresholdGM; }
80static GMRegistry reg(MyFactory);
81
82}