Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkMagnifierImageFilter.h" | 9 #include "SkAlphaThresholdFilter.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| 11 | 11 |
| 12 #define WIDTH 500 | 12 #define WIDTH 500 |
| 13 #define HEIGHT 500 | 13 #define HEIGHT 500 |
| 14 | 14 |
| 15 namespace skiagm { | 15 namespace skiagm { |
| 16 | 16 |
| 17 class ImageMagnifierGM : public GM { | 17 class ImageAlphaThresholdGM : public GM { |
| 18 public: | 18 public: |
| 19 ImageMagnifierGM() { | 19 ImageAlphaThresholdGM() { |
| 20 this->setBGColor(0xFF000000); | 20 this->setBGColor(0xFF000000); |
| 21 } | 21 } |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 24 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 25 // Skip tiled drawing until https://code.google.com/p/skia/issues/detail ?id=781 is fixed. | |
| 26 return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag; | 25 return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag; |
| 27 } | 26 } |
| 28 | 27 |
| 29 virtual SkString onShortName() SK_OVERRIDE { | 28 virtual SkString onShortName() SK_OVERRIDE { |
| 30 return SkString("imagemagnifier"); | 29 return SkString("imagealphathreshold"); |
| 31 } | 30 } |
| 32 | 31 |
| 33 virtual SkISize onISize() SK_OVERRIDE { | 32 virtual SkISize onISize() SK_OVERRIDE { |
| 34 return make_isize(WIDTH, HEIGHT); | 33 return make_isize(WIDTH, HEIGHT); |
| 35 } | 34 } |
| 36 | 35 |
| 37 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 36 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 37 SkIRect rects[2]; | |
| 38 rects[0] = SkIRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(150), | |
| 39 SkIntToScalar(WIDTH), | |
| 40 SkIntToScalar(HEIGHT - 300)); | |
| 41 rects[1] = SkIRect::MakeXYWH(SkIntToScalar(150), SkIntToScalar(0), | |
| 42 SkIntToScalar(WIDTH - 300), | |
| 43 SkIntToScalar(HEIGHT)); | |
| 44 SkRegion region; | |
| 45 region.setRects(rects, 2); | |
|
Wez
2013/12/17 06:39:04
So we need to plumb through the window shape throu
Zachary Kuznia
2013/12/18 00:06:27
Yes. I have a CL in Chromium that does this; I'll
| |
| 46 | |
| 38 SkPaint paint; | 47 SkPaint paint; |
| 39 paint.setImageFilter( | 48 paint.setImageFilter( |
| 40 new SkMagnifierImageFilter( | 49 new SkAlphaThresholdFilter(region, 0, .2))->unref(); |
| 41 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100), | |
| 42 SkIntToScalar(WIDTH / 2), | |
| 43 SkIntToScalar(HEIGHT / 2)), | |
| 44 100))->unref(); | |
| 45 canvas->saveLayer(NULL, &paint); | 50 canvas->saveLayer(NULL, &paint); |
| 46 paint.setAntiAlias(true); | 51 paint.setAntiAlias(true); |
| 47 const char* str = "The quick brown fox jumped over the lazy dog."; | 52 const char* str = "The quick brown fox jumped over the lazy dog."; |
| 48 SkRandom rand; | 53 SkRandom rand; |
| 49 for (int i = 0; i < 25; ++i) { | 54 for (int i = 0; i < 25; ++i) { |
| 50 int x = rand.nextULessThan(WIDTH); | 55 int x = rand.nextULessThan(WIDTH); |
| 51 int y = rand.nextULessThan(HEIGHT); | 56 int y = rand.nextULessThan(HEIGHT); |
| 52 paint.setColor(rand.nextBits(24) | 0xFF000000); | 57 paint.setColor(rand.nextBits(24) | 0xFF000000); |
| 53 paint.setTextSize(rand.nextRangeScalar(0, 300)); | 58 paint.setTextSize(rand.nextRangeScalar(0, 300)); |
| 54 canvas->drawText(str, strlen(str), SkIntToScalar(x), | 59 canvas->drawText(str, strlen(str), SkIntToScalar(x), |
| 55 SkIntToScalar(y), paint); | 60 SkIntToScalar(y), paint); |
| 56 } | 61 } |
| 57 canvas->restore(); | 62 canvas->restore(); |
| 58 } | 63 } |
| 59 | 64 |
| 60 private: | 65 private: |
| 61 typedef GM INHERITED; | 66 typedef GM INHERITED; |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 ////////////////////////////////////////////////////////////////////////////// | 69 ////////////////////////////////////////////////////////////////////////////// |
| 65 | 70 |
| 66 static GM* MyFactory(void*) { return new ImageMagnifierGM; } | 71 static GM* MyFactory(void*) { return new ImageAlphaThresholdGM; } |
| 67 static GMRegistry reg(MyFactory); | 72 static GMRegistry reg(MyFactory); |
| 68 | 73 |
| 69 } | 74 } |
| OLD | NEW |