Index: gm/bigblurs.cpp |
=================================================================== |
--- gm/bigblurs.cpp (revision 0) |
+++ gm/bigblurs.cpp (revision 0) |
@@ -0,0 +1,119 @@ |
+ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "gm.h" |
+#include "SkBlurMask.h" |
+#include "SkBlurMaskFilter.h" |
+ |
+namespace skiagm { |
+ |
+// This GM exercises the blurred rect nine-patching special cases when the |
+// blurred rect is very large and/or very far from the origin. |
+// It creates a large blurred rect/rectori then renders the 4 corners and the |
+// middle. |
+class BigBlursGM : public GM { |
+public: |
+ BigBlursGM() { |
+ this->setBGColor(0xFFDDDDDD); |
+ } |
+ |
+protected: |
+ virtual SkString onShortName() { |
+ return SkString("bigblurs"); |
+ } |
+ |
+ virtual SkISize onISize() { |
+ return make_isize(kWidth, kHeight); |
+ } |
+ |
+ virtual void onDraw(SkCanvas* canvas) { |
+ SkBlurMaskFilter::BlurStyle blurStyles[] = { |
+ SkBlurMaskFilter::kInner_BlurStyle, |
+ SkBlurMaskFilter::kNormal_BlurStyle, |
+ SkBlurMaskFilter::kSolid_BlurStyle, |
+ SkBlurMaskFilter::kOuter_BlurStyle |
+ }; |
+ |
+ static const SkScalar kBig = 65536; |
+ static const SkScalar kSmall = 64; |
+ static const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)); |
+ static const int kOffset = SkScalarRoundToInt(kSmall + 6 * kSigma); |
+ |
+ const SkRect bigRect = SkRect::MakeWH(kBig, kBig); |
+ SkRect insetRect = bigRect; |
+ insetRect.inset(20, 20); |
+ |
+ SkPath rectori; |
+ |
+ rectori.addRect(bigRect); |
+ rectori.addRect(insetRect, SkPath::kCCW_Direction); |
+ |
+ // UL hand corners of the rendered closeups |
+ const SkPoint origins[] = { |
+ { -3*kSigma, -3*kSigma, }, // UL |
+ { kBig-kSmall-3*kSigma, -3*kSigma }, // UR |
+ { kBig-kSmall-3*kSigma, kBig-kSmall-3*kSigma }, // LR |
+ { -3*kSigma, kBig-kSmall-3*kSigma }, // LL |
+ { kBig/2-kSmall-3*kSigma, kBig/2-kSmall-3*kSigma }, // center |
+ }; |
+ |
+ SkPaint outlinePaint; |
+ outlinePaint.setColor(SK_ColorRED); |
+ outlinePaint.setStyle(SkPaint::kStroke_Style); |
+ |
+ SkPaint blurPaint; |
+ blurPaint.setAntiAlias(true); |
+ blurPaint.setColor(SK_ColorBLACK); |
+ |
+ int desiredX = 0, desiredY = 0; |
+ |
+ for (int i = 0; i < 2; ++i) { |
+ for (int j = 0; j < (int)SK_ARRAY_COUNT(blurStyles); ++j) { |
+ SkMaskFilter* mf = SkBlurMaskFilter::Create(blurStyles[j], kSigma); |
+ blurPaint.setMaskFilter(mf)->unref(); |
+ |
+ for (int k = 0; k < (int)SK_ARRAY_COUNT(origins); ++k) { |
+ canvas->save(); |
+ |
+ SkRect clipRect = SkRect::MakeXYWH(SkIntToScalar(desiredX), |
+ SkIntToScalar(desiredY), |
+ SkIntToScalar(kOffset), |
+ SkIntToScalar(kOffset)); |
+ |
+ canvas->clipRect(clipRect, SkRegion::kReplace_Op, false); |
+ |
+ canvas->translate(desiredX-origins[k].fX, |
+ desiredY-origins[k].fY); |
+ |
+ if (0 == i) { |
+ canvas->drawRect(bigRect, blurPaint); |
+ } else { |
+ canvas->drawPath(rectori, blurPaint); |
+ } |
+ canvas->restore(); |
+ canvas->drawRect(clipRect, outlinePaint); |
+ |
+ desiredX += kOffset; |
+ } |
+ |
+ desiredX = 0; |
+ desiredY += kOffset; |
+ } |
+ } |
+ } |
+ |
+private: |
+ static const int kWidth = 406; |
+ static const int kHeight = 649; |
+ |
+ typedef GM INHERITED; |
+}; |
+ |
+DEF_GM( return SkNEW(BigBlursGM); ) |
+ |
+} |
Property changes on: gm\bigblurs.cpp |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |