| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "gm.h" | 9 #include "gm.h" |
| 10 #include "SkBlurMask.h" | 10 #include "SkBlurMask.h" |
| 11 #include "SkBlurMaskFilter.h" | 11 #include "SkBlurMaskFilter.h" |
| 12 | 12 |
| 13 namespace skiagm { | 13 namespace skiagm { |
| 14 | 14 |
| 15 // This GM exercises the blurred rect nine-patching special cases when the | 15 // This GM exercises the blurred rect nine-patching special cases when the |
| 16 // blurred rect is very large and/or very far from the origin. | 16 // blurred geometry is very large and/or very far from the origin. |
| 17 // It creates a large blurred rect/rectori then renders the 4 corners and the | 17 // It creates large blurred geometry then renders the 4 corners and the middle. |
| 18 // middle. | 18 // The three geometries tested are: |
| 19 // a large rect |
| 20 // a large thin rectorii (inner rect is only 20 inside outer rect) |
| 21 // a large thick rectorii (inner rect is tiny compared to outer rect) |
| 22 // This last case is inappropriate for the nine-patch fast path. |
| 19 class BigBlursGM : public GM { | 23 class BigBlursGM : public GM { |
| 20 public: | 24 public: |
| 21 BigBlursGM() { | 25 BigBlursGM() { |
| 22 this->setBGColor(0xFFDDDDDD); | 26 this->setBGColor(0xFFDDDDDD); |
| 23 } | 27 } |
| 24 | 28 |
| 25 protected: | 29 protected: |
| 26 virtual SkString onShortName() SK_OVERRIDE { | 30 virtual SkString onShortName() SK_OVERRIDE { |
| 27 return SkString("bigblurs"); | 31 return SkString("bigblurs"); |
| 28 } | 32 } |
| 29 | 33 |
| 30 virtual SkISize onISize() SK_OVERRIDE { | 34 virtual SkISize onISize() SK_OVERRIDE { |
| 31 return make_isize(kWidth, kHeight); | 35 return make_isize(kWidth, kHeight); |
| 32 } | 36 } |
| 33 | 37 |
| 34 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 38 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 35 static const int kBig = 65536; | 39 static const int kBig = 65536; |
| 36 static const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToS
calar(4)); | 40 static const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToS
calar(4)); |
| 37 | 41 |
| 38 const SkRect bigRect = SkRect::MakeWH(SkIntToScalar(kBig), SkIntToScalar
(kBig)); | 42 const SkRect bigRect = SkRect::MakeWH(SkIntToScalar(kBig), SkIntToScalar
(kBig)); |
| 39 SkRect insetRect = bigRect; | 43 SkRect insetRect = bigRect; |
| 40 insetRect.inset(20, 20); | 44 insetRect.inset(20, 20); |
| 41 | 45 |
| 42 SkPath rectori; | 46 SkPath thinRectori; |
| 47 thinRectori.addRect(bigRect); |
| 48 thinRectori.addRect(insetRect, SkPath::kCCW_Direction); |
| 43 | 49 |
| 44 rectori.addRect(bigRect); | 50 insetRect.inset(kBig/2-40, kBig/2-40); |
| 45 rectori.addRect(insetRect, SkPath::kCCW_Direction); | 51 |
| 52 SkPath thickRectori; |
| 53 thickRectori.addRect(bigRect); |
| 54 thickRectori.addRect(insetRect, SkPath::kCCW_Direction); |
| 46 | 55 |
| 47 // The blur extends 3*kSigma out from the big rect. | 56 // The blur extends 3*kSigma out from the big rect. |
| 48 // Offset the close-up windows so we get the entire blur | 57 // Offset the close-up windows so we get the entire blur |
| 49 static const SkScalar kLeftTopPad = 3*kSigma; // use on left & up of
big rect | 58 static const SkScalar kLeftTopPad = 3*kSigma; // use on left & up of
big rect |
| 50 static const SkScalar kRightBotPad = kCloseUpSize-3*kSigma; // use on ri
ght and bot sides | 59 static const SkScalar kRightBotPad = kCloseUpSize-3*kSigma; // use on ri
ght and bot sides |
| 51 | 60 |
| 52 // UL hand corners of the rendered closeups | 61 // UL hand corners of the rendered closeups |
| 53 const SkPoint origins[] = { | 62 const SkPoint origins[] = { |
| 54 { -kLeftTopPad, -kLeftTopPad }, // UL | 63 { -kLeftTopPad, -kLeftTopPad }, // UL |
| 55 { kBig-kRightBotPad, -kLeftTopPad }, // UR | 64 { kBig-kRightBotPad, -kLeftTopPad }, // UR |
| 56 { kBig-kRightBotPad, kBig-kRightBotPad }, // LR | 65 { kBig-kRightBotPad, kBig-kRightBotPad }, // LR |
| 57 { -kLeftTopPad, kBig-kRightBotPad }, // LL | 66 { -kLeftTopPad, kBig-kRightBotPad }, // LL |
| 58 { kBig/2-kCloseUpSize/2, kBig/2-kCloseUpSize/2 }, // center | 67 { kBig/2-kCloseUpSize/2, kBig/2-kCloseUpSize/2 }, // center |
| 59 }; | 68 }; |
| 60 | 69 |
| 61 SkPaint outlinePaint; | 70 SkPaint outlinePaint; |
| 62 outlinePaint.setColor(SK_ColorRED); | 71 outlinePaint.setColor(SK_ColorRED); |
| 63 outlinePaint.setStyle(SkPaint::kStroke_Style); | 72 outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 64 | 73 |
| 65 SkPaint blurPaint; | 74 SkPaint blurPaint; |
| 66 blurPaint.setAntiAlias(true); | 75 blurPaint.setAntiAlias(true); |
| 67 blurPaint.setColor(SK_ColorBLACK); | 76 blurPaint.setColor(SK_ColorBLACK); |
| 68 | 77 |
| 69 int desiredX = 0, desiredY = 0; | 78 int desiredX = 0, desiredY = 0; |
| 70 | 79 |
| 71 for (int i = 0; i < 2; ++i) { | 80 for (int i = 0; i < kNumGeometryTypes; ++i) { |
| 72 for (int j = 0; j < SkBlurMaskFilter::kBlurStyleCount; ++j) { | 81 for (int j = 0; j < SkBlurMaskFilter::kBlurStyleCount; ++j) { |
| 73 SkMaskFilter* mf = SkBlurMaskFilter::Create((SkBlurMaskFilter::B
lurStyle)j, | 82 SkMaskFilter* mf = SkBlurMaskFilter::Create((SkBlurMaskFilter::B
lurStyle)j, |
| 74 kSigma); | 83 kSigma); |
| 75 blurPaint.setMaskFilter(mf)->unref(); | 84 blurPaint.setMaskFilter(mf)->unref(); |
| 76 | 85 |
| 77 for (int k = 0; k < (int)SK_ARRAY_COUNT(origins); ++k) { | 86 for (int k = 0; k < (int)SK_ARRAY_COUNT(origins); ++k) { |
| 78 canvas->save(); | 87 canvas->save(); |
| 79 | 88 |
| 80 SkRect clipRect = SkRect::MakeXYWH(SkIntToScalar(desiredX), | 89 SkRect clipRect = SkRect::MakeXYWH(SkIntToScalar(desiredX), |
| 81 SkIntToScalar(desiredY), | 90 SkIntToScalar(desiredY), |
| 82 SkIntToScalar(kCloseUpSiz
e), | 91 SkIntToScalar(kCloseUpSiz
e), |
| 83 SkIntToScalar(kCloseUpSiz
e)); | 92 SkIntToScalar(kCloseUpSiz
e)); |
| 84 | 93 |
| 85 canvas->clipRect(clipRect, SkRegion::kReplace_Op, false); | 94 canvas->clipRect(clipRect, SkRegion::kReplace_Op, false); |
| 86 | 95 |
| 87 canvas->translate(desiredX-origins[k].fX, | 96 canvas->translate(desiredX-origins[k].fX, |
| 88 desiredY-origins[k].fY); | 97 desiredY-origins[k].fY); |
| 89 | 98 |
| 90 if (0 == i) { | 99 if (0 == i) { |
| 91 canvas->drawRect(bigRect, blurPaint); | 100 canvas->drawRect(bigRect, blurPaint); |
| 101 } else if (1 == i) { |
| 102 canvas->drawPath(thinRectori, blurPaint); |
| 92 } else { | 103 } else { |
| 93 canvas->drawPath(rectori, blurPaint); | 104 canvas->drawPath(thickRectori, blurPaint); |
| 94 } | 105 } |
| 106 |
| 95 canvas->restore(); | 107 canvas->restore(); |
| 96 canvas->drawRect(clipRect, outlinePaint); | 108 canvas->drawRect(clipRect, outlinePaint); |
| 97 | 109 |
| 98 desiredX += kCloseUpSize; | 110 desiredX += kCloseUpSize; |
| 99 } | 111 } |
| 100 | 112 |
| 101 desiredX = 0; | 113 desiredX = 0; |
| 102 desiredY += kCloseUpSize; | 114 desiredY += kCloseUpSize; |
| 103 } | 115 } |
| 104 } | 116 } |
| 105 } | 117 } |
| 106 | 118 |
| 107 private: | 119 private: |
| 120 static const int kNumGeometryTypes = 3; |
| 108 static const int kCloseUpSize = 64; | 121 static const int kCloseUpSize = 64; |
| 109 static const int kWidth = 5 * kCloseUpSize; | 122 static const int kWidth = 5 * kCloseUpSize; |
| 110 static const int kHeight = 2 * SkBlurMaskFilter::kBlurStyleCount * kCloseUpS
ize; | 123 static const int kHeight = kNumGeometryTypes * |
| 124 SkBlurMaskFilter::kBlurStyleCount * |
| 125 kCloseUpSize; |
| 111 | 126 |
| 112 typedef GM INHERITED; | 127 typedef GM INHERITED; |
| 113 }; | 128 }; |
| 114 | 129 |
| 115 DEF_GM( return SkNEW(BigBlursGM); ) | 130 DEF_GM( return SkNEW(BigBlursGM); ) |
| 116 | 131 |
| 117 } | 132 } |
| OLD | NEW |