1 2 /* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 #include "gm.h" 9 #include "SkBlurMask.h" 10 #include "SkBlurMaskFilter.h" 11 12 namespace skiagm { 13 14 class BlursGM : public GM { 15 public: 16 BlursGM() { 17 this->setBGColor(0xFFDDDDDD); 18 } 19 20 protected: 21 #ifdef SK_SCALAR_IS_FIXED 22 virtual uint32_t onGetFlags() const SK_OVERRIDE { 23 // SkCanvas::drawCircle, used by this test, performs a quick reject. 24 // The large size given to the device used by SkGPipeCanvas means that 25 // the device clip will not be set properly and circles will be 26 // rejected when in FIXED. 27 return this->INHERITED::onGetFlags() | GM::kSkipPipe_Flag; 28 } 29 #endif 30 31 virtual SkString onShortName() { 32 return SkString("blurs"); 33 } 34 35 virtual SkISize onISize() { 36 return make_isize(700, 500); 37 } 38 39 virtual void onDraw(SkCanvas* canvas) { 40 SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999); 41 static const struct { 42 SkBlurMaskFilter::BlurStyle fStyle; 43 int fCx, fCy; 44 } gRecs[] = { 45 { NONE, 0, 0 }, 46 { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 }, 47 { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 }, 48 { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 }, 49 { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 }, 50 }; 51 52 SkPaint paint; 53 paint.setAntiAlias(true); 54 paint.setTextSize(SkIntToScalar(25)); 55 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0)); 56 57 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; 58 for (int j = 0; j < 2; j++) { 59 canvas->save(); 60 paint.setColor(SK_ColorBLUE); 61 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { 62 if (gRecs[i].fStyle != NONE) { 63 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle, 64 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)), 65 flags); 66 paint.setMaskFilter(mf)->unref(); 67 } else { 68 paint.setMaskFilter(NULL); 69 } 70 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100), 71 SkIntToScalar(200 + gRecs[i].fCy*100), 72 SkIntToScalar(50), 73 paint); 74 } 75 // draw text 76 { 77 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle, 78 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), 79 flags); 80 paint.setMaskFilter(mf)->unref(); 81 SkScalar x = SkIntToScalar(70); 82 SkScalar y = SkIntToScalar(400); 83 paint.setColor(SK_ColorBLACK); 84 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 85 canvas->drawText("Hamburgefons Style", 18, 86 x, y + SkIntToScalar(50), paint); 87 paint.setMaskFilter(NULL); 88 paint.setColor(SK_ColorWHITE); 89 x -= SkIntToScalar(2); 90 y -= SkIntToScalar(2); 91 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 92 } 93 canvas->restore(); 94 flags = SkBlurMaskFilter::kHighQuality_BlurFlag; 95 canvas->translate(SkIntToScalar(350), SkIntToScalar(0)); 96 } 97 } 98 99 private: 100 typedef GM INHERITED; 101 }; 102 103 ////////////////////////////////////////////////////////////////////////////// 104 105 static GM* MyFactory(void*) { return new BlursGM; } 106 static GMRegistry reg(MyFactory); 107 108 } 109