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