| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 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 "SkBlurMask.h" |
| 10 #include "SkBlurMaskFilter.h" |
| 9 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 10 #include "SkBlurMaskFilter.h" | 12 #include "SkColorFilter.h" |
| 11 #include "SkLayerDrawLooper.h" | 13 #include "SkLayerDrawLooper.h" |
| 12 #include "SkColorFilter.h" | |
| 13 | 14 |
| 14 // This GM tests 3 different ways of drawing four shadows around a square: | 15 // This GM tests 3 different ways of drawing four shadows around a square: |
| 15 // just using 4 blurred rects | 16 // just using 4 blurred rects |
| 16 // using 4 1-level draw loopers | 17 // using 4 1-level draw loopers |
| 17 // using 1 4-level draw looper | 18 // using 1 4-level draw looper |
| 18 // They all produce exactly the same pixels | 19 // They all produce exactly the same pixels |
| 19 class MegaLooperGM : public skiagm::GM { | 20 class MegaLooperGM : public skiagm::GM { |
| 20 public: | 21 public: |
| 21 // The types define "<# of loopers> x <# of stages per looper>" | 22 // The types define "<# of loopers> x <# of stages per looper>" |
| 22 enum Type { | 23 enum Type { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize,
kHalfSquareSize }; | 104 SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize,
kHalfSquareSize }; |
| 104 rect.offset(gBlurOffsets[i]); | 105 rect.offset(gBlurOffsets[i]); |
| 105 rect.offset(x, y); | 106 rect.offset(x, y); |
| 106 canvas->drawRect(rect, paint); | 107 canvas->drawRect(rect, paint); |
| 107 } | 108 } |
| 108 | 109 |
| 109 canvas->restore(); | 110 canvas->restore(); |
| 110 } | 111 } |
| 111 | 112 |
| 112 SkMaskFilter* createBlur() { | 113 SkMaskFilter* createBlur() { |
| 113 static const SkScalar kBlurRadius = 25.0f; | 114 static const SkScalar kBlurSigma = SkBlurMask::ConvertRadiusToSigma(SkIn
tToScalar(25)); |
| 114 | 115 |
| 115 return SkBlurMaskFilter::Create(kBlurRadius, | 116 return SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle, |
| 116 SkBlurMaskFilter::kNormal_BlurStyle, | 117 kBlurSigma, |
| 117 SkBlurMaskFilter::kHighQuality_BlurFlag)
; | 118 SkBlurMaskFilter::kHighQuality_BlurFlag)
; |
| 118 } | 119 } |
| 119 | 120 |
| 120 // This draws 4 blurred shadows around a single square (centered at x, y). | 121 // This draws 4 blurred shadows around a single square (centered at x, y). |
| 121 // Each blur is offset +/- half the square's side in x & y from the original | 122 // Each blur is offset +/- half the square's side in x & y from the original |
| 122 // (so each blurred rect is centered at one of the corners of the original). | 123 // (so each blurred rect is centered at one of the corners of the original). |
| 123 // For each blur a large outer clip is centered around the blurred rect | 124 // For each blur a large outer clip is centered around the blurred rect |
| 124 // while a difference clip stays at the location of the original rect. | 125 // while a difference clip stays at the location of the original rect. |
| 125 // Each blurred rect is drawn with a draw looper where the original (non- | 126 // Each blurred rect is drawn with a draw looper where the original (non- |
| 126 // blurred rect) is offset to reside outside of the large outer clip (so | 127 // blurred rect) is offset to reside outside of the large outer clip (so |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 { -kHalfSquareSize, -kHalfSquareSize } | 242 { -kHalfSquareSize, -kHalfSquareSize } |
| 242 }; | 243 }; |
| 243 | 244 |
| 244 const SkColor MegaLooperGM::gColors[4] = { | 245 const SkColor MegaLooperGM::gColors[4] = { |
| 245 SK_ColorGREEN, SK_ColorYELLOW, SK_ColorBLUE, SK_ColorRED | 246 SK_ColorGREEN, SK_ColorYELLOW, SK_ColorBLUE, SK_ColorRED |
| 246 }; | 247 }; |
| 247 | 248 |
| 248 DEF_GM( return new MegaLooperGM(MegaLooperGM::k0x0_Type); ) | 249 DEF_GM( return new MegaLooperGM(MegaLooperGM::k0x0_Type); ) |
| 249 DEF_GM( return new MegaLooperGM(MegaLooperGM::k4x1_Type); ) | 250 DEF_GM( return new MegaLooperGM(MegaLooperGM::k4x1_Type); ) |
| 250 DEF_GM( return new MegaLooperGM(MegaLooperGM::k1x4_Type); ) | 251 DEF_GM( return new MegaLooperGM(MegaLooperGM::k1x4_Type); ) |
| OLD | NEW |