| 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" | 9 #include "SkBlurMask.h" |
| 10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
| 11 | 11 |
| 12 class BlursGM : public skiagm::GM { | 12 class BlursGM : public skiagm::GM { |
| 13 public: | 13 public: |
| 14 BlursGM() { | 14 BlursGM() { |
| 15 this->setBGColor(0xFFDDDDDD); | 15 this->setBGColor(0xFFDDDDDD); |
| 16 } | 16 } |
| 17 | 17 |
| 18 protected: | 18 protected: |
| 19 | 19 |
| 20 SkString onShortName() SK_OVERRIDE { | 20 SkString onShortName() override { |
| 21 return SkString("blurs"); | 21 return SkString("blurs"); |
| 22 } | 22 } |
| 23 | 23 |
| 24 SkISize onISize() SK_OVERRIDE { | 24 SkISize onISize() override { |
| 25 return SkISize::Make(700, 500); | 25 return SkISize::Make(700, 500); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 28 void onDraw(SkCanvas* canvas) override { |
| 29 SkBlurStyle NONE = SkBlurStyle(-999); | 29 SkBlurStyle NONE = SkBlurStyle(-999); |
| 30 static const struct { | 30 static const struct { |
| 31 SkBlurStyle fStyle; | 31 SkBlurStyle fStyle; |
| 32 int fCx, fCy; | 32 int fCx, fCy; |
| 33 } gRecs[] = { | 33 } gRecs[] = { |
| 34 { NONE, 0, 0 }, | 34 { NONE, 0, 0 }, |
| 35 { kInner_SkBlurStyle, -1, 0 }, | 35 { kInner_SkBlurStyle, -1, 0 }, |
| 36 { kNormal_SkBlurStyle, 0, 1 }, | 36 { kNormal_SkBlurStyle, 0, 1 }, |
| 37 { kSolid_SkBlurStyle, 0, -1 }, | 37 { kSolid_SkBlurStyle, 0, -1 }, |
| 38 { kOuter_SkBlurStyle, 1, 0 }, | 38 { kOuter_SkBlurStyle, 1, 0 }, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 ////////////////////////////////////////////////////////////////////////////////
////////////// | 94 ////////////////////////////////////////////////////////////////////////////////
////////////// |
| 95 | 95 |
| 96 // exercise a special-case of blurs, which is two nested rects. These are drawn
specially, | 96 // exercise a special-case of blurs, which is two nested rects. These are drawn
specially, |
| 97 // and possibly cached. | 97 // and possibly cached. |
| 98 // | 98 // |
| 99 // in particular, we want to notice that the 2nd rect draws slightly differently
, since it | 99 // in particular, we want to notice that the 2nd rect draws slightly differently
, since it |
| 100 // is translated a fractional amount. | 100 // is translated a fractional amount. |
| 101 // | 101 // |
| 102 class Blur2RectsGM : public skiagm::GM { | 102 class Blur2RectsGM : public skiagm::GM { |
| 103 public: | 103 public: |
| 104 SkString onShortName() SK_OVERRIDE { | 104 SkString onShortName() override { |
| 105 return SkString("blur2rects"); | 105 return SkString("blur2rects"); |
| 106 } | 106 } |
| 107 | 107 |
| 108 SkISize onISize() SK_OVERRIDE { | 108 SkISize onISize() override { |
| 109 return SkISize::Make(700, 500); | 109 return SkISize::Make(700, 500); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 112 void onDraw(SkCanvas* canvas) override { |
| 113 SkPaint paint; | 113 SkPaint paint; |
| 114 | 114 |
| 115 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 115 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
| 116 2.3f))->unref(); | 116 2.3f))->unref(); |
| 117 | 117 |
| 118 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100); | 118 SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100); |
| 119 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80); | 119 SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80); |
| 120 SkPath path; | 120 SkPath path; |
| 121 path.addRect(outer, SkPath::kCW_Direction); | 121 path.addRect(outer, SkPath::kCW_Direction); |
| 122 path.addRect(inner, SkPath::kCCW_Direction); | 122 path.addRect(inner, SkPath::kCCW_Direction); |
| 123 | 123 |
| 124 canvas->drawPath(path, paint); | 124 canvas->drawPath(path, paint); |
| 125 // important to translate by a factional amount to exercise a different
"phase" | 125 // important to translate by a factional amount to exercise a different
"phase" |
| 126 // of the same path w.r.t. the pixel grid | 126 // of the same path w.r.t. the pixel grid |
| 127 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.2
5f; | 127 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.2
5f; |
| 128 canvas->translate(dx, 0); | 128 canvas->translate(dx, 0); |
| 129 canvas->drawPath(path, paint); | 129 canvas->drawPath(path, paint); |
| 130 } | 130 } |
| 131 }; | 131 }; |
| 132 DEF_GM( return new Blur2RectsGM; ) | 132 DEF_GM( return new Blur2RectsGM; ) |
| 133 | 133 |
| 134 class Blur2RectsNonNinePatchGM : public skiagm::GM { | 134 class Blur2RectsNonNinePatchGM : public skiagm::GM { |
| 135 public: | 135 public: |
| 136 SkString onShortName() SK_OVERRIDE { | 136 SkString onShortName() override { |
| 137 return SkString("blur2rectsnonninepatch"); | 137 return SkString("blur2rectsnonninepatch"); |
| 138 } | 138 } |
| 139 | 139 |
| 140 SkISize onISize() SK_OVERRIDE { | 140 SkISize onISize() override { |
| 141 return SkISize::Make(700, 500); | 141 return SkISize::Make(700, 500); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 144 void onDraw(SkCanvas* canvas) override { |
| 145 SkPaint paint; | 145 SkPaint paint; |
| 146 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 146 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
| 147 4.3f))->unref(); | 147 4.3f))->unref(); |
| 148 | 148 |
| 149 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100); | 149 SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100); |
| 150 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10); | 150 SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10); |
| 151 SkPath path; | 151 SkPath path; |
| 152 path.addRect(outer, SkPath::kCW_Direction); | 152 path.addRect(outer, SkPath::kCW_Direction); |
| 153 path.addRect(inner, SkPath::kCW_Direction); | 153 path.addRect(inner, SkPath::kCW_Direction); |
| 154 canvas->drawPath(path, paint); | 154 canvas->drawPath(path, paint); |
| 155 | 155 |
| 156 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.2
5f; | 156 SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.2
5f; |
| 157 canvas->translate(dx, 0); | 157 canvas->translate(dx, 0); |
| 158 canvas->drawPath(path, paint); | 158 canvas->drawPath(path, paint); |
| 159 | 159 |
| 160 // Translate to outside of clip bounds. | 160 // Translate to outside of clip bounds. |
| 161 canvas->translate(-dx, 0); | 161 canvas->translate(-dx, 0); |
| 162 canvas->translate(-30, -150); | 162 canvas->translate(-30, -150); |
| 163 canvas->drawPath(path, paint); | 163 canvas->drawPath(path, paint); |
| 164 } | 164 } |
| 165 }; | 165 }; |
| 166 DEF_GM( return new Blur2RectsNonNinePatchGM; ) | 166 DEF_GM( return new Blur2RectsNonNinePatchGM; ) |
| OLD | NEW |