2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkGraphics.h"
12 #include "SkLayerDrawLooper.h"
13 #include "SkBlurMaskFilter.h"
15 static SkRect inset(const SkRect& r) {
17 rect.inset(r.width() / 8, r.height() / 8);
21 class PathInteriorGM : public skiagm::GM {
24 this->setBGColor(0xFFDDDDDD);
28 virtual uint32_t onGetFlags() const SK_OVERRIDE {
29 return kSkipTiled_Flag;
32 virtual SkISize onISize() {
33 return SkISize::Make(770, 770);
36 virtual SkString onShortName() SK_OVERRIDE {
37 return SkString("pathinterior");
40 void show(SkCanvas* canvas, const SkPath& path) {
42 paint.setAntiAlias(true);
46 bool hasInterior = path.hasRectangularInterior(&rect);
48 bool hasInterior = false;
51 paint.setColor(hasInterior ? 0xFF8888FF : SK_ColorGRAY);
52 canvas->drawPath(path, paint);
53 paint.setStyle(SkPaint::kStroke_Style);
54 paint.setColor(SK_ColorRED);
55 canvas->drawPath(path, paint);
58 paint.setStyle(SkPaint::kFill_Style);
59 paint.setColor(0x8800FF00);
60 canvas->drawRect(rect, paint);
64 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
65 canvas->translate(8.5f, 8.5f);
67 const SkRect rect = { 0, 0, 80, 80 };
68 const SkScalar RAD = rect.width()/8;
71 for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
72 for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
73 for (int outerRR = 0; outerRR <= 1; ++outerRR) {
74 for (int innerRR = 0; innerRR <= 1; ++innerRR) {
75 for (int outerCW = 0; outerCW <= 1; ++outerCW) {
76 for (int innerCW = 0; innerCW <= 1; ++innerCW) {
78 path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
79 SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
80 SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
82 SkRect r = insetFirst ? inset(rect) : rect;
84 path.addRoundRect(r, RAD, RAD, outerDir);
86 path.addRect(r, outerDir);
88 r = insetFirst ? rect : inset(rect);
90 path.addRoundRect(r, RAD, RAD, innerDir);
92 path.addRect(r, innerDir);
95 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
96 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
100 this->show(canvas, path);
111 typedef GM INHERITED;
114 //////////////////////////////////////////////////////////////////////////////
116 static skiagm::GM* MyFactory(void*) { return new PathInteriorGM; }
117 static skiagm::GMRegistry reg(MyFactory);