OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 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 "SkBlurImageFilter.h" |
| 10 #include "SkRandom.h" |
| 11 |
| 12 // TODO deprecate imageblur |
| 13 |
| 14 #define WIDTH 500 |
| 15 #define HEIGHT 500 |
| 16 |
| 17 static const float kBlurSigmas[] = { |
| 18 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f }; |
| 19 |
| 20 const char* kTestStrings[] = { |
| 21 "The quick`~", |
| 22 "brown fox[]", |
| 23 "jumped over", |
| 24 "the lazy@#$", |
| 25 "dog.{}!%^&", |
| 26 "*()+=-\\'\"/", |
| 27 }; |
| 28 |
| 29 namespace skiagm { |
| 30 |
| 31 class BlurImageFilter : public GM { |
| 32 public: |
| 33 BlurImageFilter() { |
| 34 this->setBGColor(0xFFFFFFFF); |
| 35 fName.printf("imageblur2"); |
| 36 } |
| 37 |
| 38 protected: |
| 39 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 40 return kSkipTiled_Flag; |
| 41 } |
| 42 |
| 43 virtual SkString onShortName() { |
| 44 return fName; |
| 45 } |
| 46 |
| 47 virtual SkISize onISize() { |
| 48 return SkISize::Make(WIDTH, HEIGHT); |
| 49 } |
| 50 |
| 51 virtual void onDraw(SkCanvas* canvas) { |
| 52 const int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas); |
| 53 const int testStringCount = SK_ARRAY_COUNT(kTestStrings); |
| 54 SkScalar dx = WIDTH / sigmaCount; |
| 55 SkScalar dy = HEIGHT / sigmaCount; |
| 56 const SkScalar textSize = 12; |
| 57 |
| 58 for (int x = 0; x < sigmaCount; x++) { |
| 59 SkScalar sigmaX = kBlurSigmas[x]; |
| 60 for (int y = 0; y < sigmaCount; y++) { |
| 61 SkScalar sigmaY = kBlurSigmas[y]; |
| 62 |
| 63 SkPaint paint; |
| 64 paint.setImageFilter(SkBlurImageFilter::Create(sigmaX, sigmaY))-
>unref(); |
| 65 canvas->saveLayer(NULL, &paint); |
| 66 |
| 67 SkRandom rand; |
| 68 SkPaint textPaint; |
| 69 textPaint.setAntiAlias(false); |
| 70 textPaint.setColor(rand.nextBits(24) | 0xFF000000); |
| 71 textPaint.setTextSize(textSize); |
| 72 |
| 73 for (int i = 0; i < testStringCount; i++) { |
| 74 canvas->drawText(kTestStrings[i], |
| 75 strlen(kTestStrings[i]), |
| 76 SkIntToScalar(x * dx), |
| 77 SkIntToScalar(y * dy + textSize * i + textS
ize), |
| 78 textPaint); |
| 79 } |
| 80 canvas->restore(); |
| 81 } |
| 82 } |
| 83 } |
| 84 |
| 85 private: |
| 86 SkString fName; |
| 87 |
| 88 typedef GM INHERITED; |
| 89 }; |
| 90 |
| 91 ////////////////////////////////////////////////////////////////////////////// |
| 92 |
| 93 static GM* MyFactory(void*) { return new BlurImageFilter; } |
| 94 static GMRegistry reg(MyFactory); |
| 95 |
| 96 } |
OLD | NEW |