commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | namespace skiagm { |
| 16 | |
| 17 | class ImageAlphaThresholdGM : public GM { |
| 18 | public: |
| 19 | ImageAlphaThresholdGM() { |
| 20 | this->setBGColor(0xFFFFFFFF); |
| 21 | } |
| 22 | |
| 23 | protected: |
| 24 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
bsalomon@google.com | a19818a | 2014-01-07 17:20:33 +0000 | [diff] [blame] | 25 | return this->INHERITED::onGetFlags() | |
| 26 | GM::kSkipTiled_Flag | |
| 27 | GM::kSkipPicture_Flag | |
skia.committer@gmail.com | 8f7a108 | 2014-01-08 07:01:49 +0000 | [diff] [blame] | 28 | GM::kSkipPipe_Flag | |
bsalomon@google.com | a19818a | 2014-01-07 17:20:33 +0000 | [diff] [blame] | 29 | GM::kSkipPipeCrossProcess_Flag; |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 30 | } |
| 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.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 50 | matrix.postScale(.8f, .8f); |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 51 | |
| 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 | |
| 77 | private: |
| 78 | typedef GM INHERITED; |
| 79 | }; |
| 80 | |
| 81 | ////////////////////////////////////////////////////////////////////////////// |
| 82 | |
| 83 | static GM* MyFactory(void*) { return new ImageAlphaThresholdGM; } |
| 84 | static GMRegistry reg(MyFactory); |
| 85 | |
| 86 | } |