| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2011 Google Inc. | 2  * Copyright 2011 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 "SkBlurMask.h" | 
|  | 10 #include "SkBlurMaskFilter.h" | 
| 9 #include "SkCanvas.h" | 11 #include "SkCanvas.h" | 
| 10 #include "SkGraphics.h" | 12 #include "SkGraphics.h" | 
|  | 13 #include "SkLayerDrawLooper.h" | 
| 11 #include "SkRandom.h" | 14 #include "SkRandom.h" | 
| 12 #include "SkLayerDrawLooper.h" |  | 
| 13 #include "SkBlurMaskFilter.h" |  | 
| 14 | 15 | 
| 15 #define WIDTH   200 | 16 #define WIDTH   200 | 
| 16 #define HEIGHT  200 | 17 #define HEIGHT  200 | 
| 17 | 18 | 
| 18 class DrawLooperGM : public skiagm::GM { | 19 class DrawLooperGM : public skiagm::GM { | 
| 19 public: | 20 public: | 
| 20     DrawLooperGM() : fLooper(NULL) { | 21     DrawLooperGM() : fLooper(NULL) { | 
| 21         this->setBGColor(0xFFDDDDDD); | 22         this->setBGColor(0xFFDDDDDD); | 
| 22     } | 23     } | 
| 23 | 24 | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 55     SkLayerDrawLooper*   fLooper; | 56     SkLayerDrawLooper*   fLooper; | 
| 56 | 57 | 
| 57     void init() { | 58     void init() { | 
| 58         if (fLooper) return; | 59         if (fLooper) return; | 
| 59 | 60 | 
| 60         static const struct { | 61         static const struct { | 
| 61             SkColor         fColor; | 62             SkColor         fColor; | 
| 62             SkPaint::Style  fStyle; | 63             SkPaint::Style  fStyle; | 
| 63             SkScalar        fWidth; | 64             SkScalar        fWidth; | 
| 64             SkScalar        fOffset; | 65             SkScalar        fOffset; | 
| 65             int             fBlur; | 66             SkScalar        fBlur; | 
| 66         } gParams[] = { | 67         } gParams[] = { | 
| 67             { SK_ColorWHITE, SkPaint::kStroke_Style, SkIntToScalar(1)*3/4, 0, 0 
     }, | 68             { SK_ColorWHITE, SkPaint::kStroke_Style, SkIntToScalar(1)*3/4, 0, 0 
     }, | 
| 68             { SK_ColorRED, SkPaint::kStroke_Style, SkIntToScalar(4), 0, 0 }, | 69             { SK_ColorRED, SkPaint::kStroke_Style, SkIntToScalar(4), 0, 0 }, | 
| 69             { SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 }, | 70             { SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 }, | 
| 70             { 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), 3 } | 71             { 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), SkIntToSca
     lar(3) } | 
| 71         }; | 72         }; | 
| 72 | 73 | 
| 73         fLooper = new SkLayerDrawLooper; | 74         fLooper = new SkLayerDrawLooper; | 
| 74 | 75 | 
| 75         SkLayerDrawLooper::LayerInfo info; | 76         SkLayerDrawLooper::LayerInfo info; | 
| 76         info.fFlagsMask = SkPaint::kAntiAlias_Flag; | 77         info.fFlagsMask = SkPaint::kAntiAlias_Flag; | 
| 77         info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMa
     skFilter_Bit; | 78         info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMa
     skFilter_Bit; | 
| 78         info.fColorMode = SkXfermode::kSrc_Mode; | 79         info.fColorMode = SkXfermode::kSrc_Mode; | 
| 79 | 80 | 
| 80         for (size_t i = 0; i < SK_ARRAY_COUNT(gParams); i++) { | 81         for (size_t i = 0; i < SK_ARRAY_COUNT(gParams); i++) { | 
| 81             info.fOffset.set(gParams[i].fOffset, gParams[i].fOffset); | 82             info.fOffset.set(gParams[i].fOffset, gParams[i].fOffset); | 
| 82             SkPaint* paint = fLooper->addLayer(info); | 83             SkPaint* paint = fLooper->addLayer(info); | 
| 83             paint->setAntiAlias(true); | 84             paint->setAntiAlias(true); | 
| 84             paint->setColor(gParams[i].fColor); | 85             paint->setColor(gParams[i].fColor); | 
| 85             paint->setStyle(gParams[i].fStyle); | 86             paint->setStyle(gParams[i].fStyle); | 
| 86             paint->setStrokeWidth(gParams[i].fWidth); | 87             paint->setStrokeWidth(gParams[i].fWidth); | 
| 87             if (gParams[i].fBlur > 0) { | 88             if (gParams[i].fBlur > 0) { | 
| 88                 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkIntToScalar(gParam
     s[i].fBlur), | 89                 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kN
     ormal_BlurStyle, | 
| 89                                                             SkBlurMaskFilter::kN
     ormal_BlurStyle); | 90                                          SkBlurMask::ConvertRadiusToSigma(gParam
     s[i].fBlur)); | 
| 90                 paint->setMaskFilter(mf)->unref(); | 91                 paint->setMaskFilter(mf)->unref(); | 
| 91             } | 92             } | 
| 92         } | 93         } | 
| 93     } | 94     } | 
| 94 | 95 | 
| 95     typedef GM INHERITED; | 96     typedef GM INHERITED; | 
| 96 }; | 97 }; | 
| 97 | 98 | 
| 98 ////////////////////////////////////////////////////////////////////////////// | 99 ////////////////////////////////////////////////////////////////////////////// | 
| 99 | 100 | 
| 100 static skiagm::GM* MyFactory(void*) { return new DrawLooperGM; } | 101 static skiagm::GM* MyFactory(void*) { return new DrawLooperGM; } | 
| 101 static skiagm::GMRegistry reg(MyFactory); | 102 static skiagm::GMRegistry reg(MyFactory); | 
| OLD | NEW | 
|---|