Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 { | |
| 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 SkPaint paint; | |
|
bsalomon
2013/12/18 14:38:12
Can we make the GM somehow test that the filter re
Zachary Kuznia
2013/12/19 01:28:40
Done.
| |
| 44 paint.setImageFilter( | |
| 45 SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref(); | |
| 46 canvas->saveLayer(NULL, &paint); | |
| 47 paint.setAntiAlias(true); | |
| 48 | |
| 49 SkPaint rect_paint; | |
| 50 rect_paint.setColor(0xFF0000FF); | |
| 51 canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2), | |
| 52 rect_paint); | |
| 53 rect_paint.setColor(0xBFFF0000); | |
| 54 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2), | |
| 55 rect_paint); | |
| 56 rect_paint.setColor(0x3F00FF00); | |
| 57 canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), | |
| 58 rect_paint); | |
| 59 rect_paint.setColor(0x00000000); | |
| 60 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIG HT / 2), | |
| 61 rect_paint); | |
| 62 canvas->restore(); | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 typedef GM INHERITED; | |
| 67 }; | |
| 68 | |
| 69 ////////////////////////////////////////////////////////////////////////////// | |
| 70 | |
| 71 static GM* MyFactory(void*) { return new ImageAlphaThresholdGM; } | |
| 72 static GMRegistry reg(MyFactory); | |
| 73 | |
| 74 } | |
| OLD | NEW |