blob: 0e13945899ca82fab04dc1e5a6976f426615f22d [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 {
bsalomon@google.coma19818a2014-01-07 17:20:33 +000025 return this->INHERITED::onGetFlags() |
26 GM::kSkipTiled_Flag |
27 GM::kSkipPicture_Flag |
skia.committer@gmail.com8f7a1082014-01-08 07:01:49 +000028 GM::kSkipPipe_Flag |
bsalomon@google.coma19818a2014-01-07 17:20:33 +000029 GM::kSkipPipeCrossProcess_Flag;
commit-bot@chromium.org40eb3c12014-01-06 23:41:14 +000030 }
31
32 virtual SkString onShortName() SK_OVERRIDE {
33 return SkString("imagealphathreshold");
34 }
35
36 virtual SkISize onISize() SK_OVERRIDE {
37 return make_isize(WIDTH, HEIGHT);
38 }
39
40 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
41 SkIRect rects[2];
42 rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
43 rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
44 SkRegion region;
45 region.setRects(rects, 2);
46
47 SkMatrix matrix;
48 matrix.reset();
49 matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f);
commit-bot@chromium.org9109e182014-01-07 16:04:01 +000050 matrix.postScale(.8f, .8f);
commit-bot@chromium.org40eb3c12014-01-06 23:41:14 +000051
52 canvas->concat(matrix);
53
54 SkPaint paint;
55 paint.setImageFilter(
56 SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref();
57 canvas->saveLayer(NULL, &paint);
58 paint.setAntiAlias(true);
59
60 SkPaint rect_paint;
61 rect_paint.setColor(0xFF0000FF);
62 canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2),
63 rect_paint);
64 rect_paint.setColor(0xBFFF0000);
65 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2),
66 rect_paint);
67 rect_paint.setColor(0x3F00FF00);
68 canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
69 rect_paint);
70 rect_paint.setColor(0x00000000);
71 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
72 rect_paint);
73
74 canvas->restore();
75 }
76
77private:
78 typedef GM INHERITED;
79};
80
81//////////////////////////////////////////////////////////////////////////////
82
83static GM* MyFactory(void*) { return new ImageAlphaThresholdGM; }
84static GMRegistry reg(MyFactory);
85
86}