OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright 2013 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 |
| 9 #include "gm.h" |
| 10 #include "SkBlurMask.h" |
| 11 #include "SkBlurMaskFilter.h" |
| 12 |
| 13 namespace skiagm { |
| 14 |
| 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. |
| 17 // It creates a large blurred rect/rectori then renders the 4 corners and the |
| 18 // middle. |
| 19 class BigBlursGM : public GM { |
| 20 public: |
| 21 BigBlursGM() { |
| 22 this->setBGColor(0xFFDDDDDD); |
| 23 } |
| 24 |
| 25 protected: |
| 26 virtual SkString onShortName() { |
| 27 return SkString("bigblurs"); |
| 28 } |
| 29 |
| 30 virtual SkISize onISize() { |
| 31 return make_isize(kWidth, kHeight); |
| 32 } |
| 33 |
| 34 virtual void onDraw(SkCanvas* canvas) { |
| 35 SkBlurMaskFilter::BlurStyle blurStyles[] = { |
| 36 SkBlurMaskFilter::kInner_BlurStyle, |
| 37 SkBlurMaskFilter::kNormal_BlurStyle, |
| 38 SkBlurMaskFilter::kSolid_BlurStyle, |
| 39 SkBlurMaskFilter::kOuter_BlurStyle |
| 40 }; |
| 41 |
| 42 static const SkScalar kBig = 65536; |
| 43 static const SkScalar kSmall = 64; |
| 44 static const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToS
calar(4)); |
| 45 static const int kOffset = SkScalarRoundToInt(kSmall + 6 * kSigma); |
| 46 |
| 47 const SkRect bigRect = SkRect::MakeWH(kBig, kBig); |
| 48 SkRect insetRect = bigRect; |
| 49 insetRect.inset(20, 20); |
| 50 |
| 51 SkPath rectori; |
| 52 |
| 53 rectori.addRect(bigRect); |
| 54 rectori.addRect(insetRect, SkPath::kCCW_Direction); |
| 55 |
| 56 // UL hand corners of the rendered closeups |
| 57 const SkPoint origins[] = { |
| 58 { -3*kSigma, -3*kSigma, }, // UL |
| 59 { kBig-kSmall-3*kSigma, -3*kSigma }, // UR |
| 60 { kBig-kSmall-3*kSigma, kBig-kSmall-3*kSigma }, // LR |
| 61 { -3*kSigma, kBig-kSmall-3*kSigma }, // LL |
| 62 { kBig/2-kSmall-3*kSigma, kBig/2-kSmall-3*kSigma }, // center |
| 63 }; |
| 64 |
| 65 SkPaint outlinePaint; |
| 66 outlinePaint.setColor(SK_ColorRED); |
| 67 outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 68 |
| 69 SkPaint blurPaint; |
| 70 blurPaint.setAntiAlias(true); |
| 71 blurPaint.setColor(SK_ColorBLACK); |
| 72 |
| 73 int desiredX = 0, desiredY = 0; |
| 74 |
| 75 for (int i = 0; i < 2; ++i) { |
| 76 for (int j = 0; j < (int)SK_ARRAY_COUNT(blurStyles); ++j) { |
| 77 SkMaskFilter* mf = SkBlurMaskFilter::Create(blurStyles[j], kSigm
a); |
| 78 blurPaint.setMaskFilter(mf)->unref(); |
| 79 |
| 80 for (int k = 0; k < (int)SK_ARRAY_COUNT(origins); ++k) { |
| 81 canvas->save(); |
| 82 |
| 83 SkRect clipRect = SkRect::MakeXYWH(SkIntToScalar(desiredX), |
| 84 SkIntToScalar(desiredY), |
| 85 SkIntToScalar(kOffset), |
| 86 SkIntToScalar(kOffset)); |
| 87 |
| 88 canvas->clipRect(clipRect, SkRegion::kReplace_Op, false); |
| 89 |
| 90 canvas->translate(desiredX-origins[k].fX, |
| 91 desiredY-origins[k].fY); |
| 92 |
| 93 if (0 == i) { |
| 94 canvas->drawRect(bigRect, blurPaint); |
| 95 } else { |
| 96 canvas->drawPath(rectori, blurPaint); |
| 97 } |
| 98 canvas->restore(); |
| 99 canvas->drawRect(clipRect, outlinePaint); |
| 100 |
| 101 desiredX += kOffset; |
| 102 } |
| 103 |
| 104 desiredX = 0; |
| 105 desiredY += kOffset; |
| 106 } |
| 107 } |
| 108 } |
| 109 |
| 110 private: |
| 111 static const int kWidth = 406; |
| 112 static const int kHeight = 649; |
| 113 |
| 114 typedef GM INHERITED; |
| 115 }; |
| 116 |
| 117 DEF_GM( return SkNEW(BigBlursGM); ) |
| 118 |
| 119 } |
OLD | NEW |