aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/nested.cpp125
-rw-r--r--gyp/gmslides.gypi1
-rw-r--r--src/gpu/GrContext.cpp25
3 files changed, 143 insertions, 8 deletions
diff --git a/gm/nested.cpp b/gm/nested.cpp
new file mode 100644
index 0000000000..333fa1d31d
--- /dev/null
+++ b/gm/nested.cpp
@@ -0,0 +1,125 @@
+/*
+ * 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 "SkRandom.h"
+#include "SkRRect.h"
+
+namespace skiagm {
+
+// Test out various combinations of nested rects, ovals and rrects.
+class NestedGM : public GM {
+public:
+ NestedGM(bool doAA) : fDoAA(doAA) {
+ this->setBGColor(0xFFDDDDDD);
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ SkString name("nested");
+ if (fDoAA) {
+ name.append("_aa");
+ } else {
+ name.append("_bw");
+ }
+ return name;
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return make_isize(kImageWidth, kImageHeight);
+ }
+
+ enum Shapes {
+ kRect_Shape = 0,
+ kRRect_Shape,
+ kOval_Shape,
+ kShapeCount
+ };
+
+ static void AddShape(SkPath* path, const SkRect& rect, Shapes shape, SkPath::Direction dir) {
+ switch (shape) {
+ case kRect_Shape:
+ path->addRect(rect, dir);
+ break;
+ case kRRect_Shape: {
+ SkRRect rr;
+ rr.setRectXY(rect, 5, 5);
+ path->addRRect(rr, dir);
+ break;
+ }
+ case kOval_Shape:
+ path->addOval(rect, dir);
+ break;
+ default:
+ break;
+ }
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+
+ SkPaint shapePaint;
+ shapePaint.setColor(SK_ColorBLACK);
+ shapePaint.setAntiAlias(fDoAA);
+
+ SkRect outerRect = SkRect::MakeWH(40, 40);
+
+ SkRect innerRects[] = {
+ { 10, 10, 30, 30 }, // small
+ { .5f, 18, 4.5f, 22 } // smaller and offset to left
+ };
+
+ // draw a background pattern to make transparency errors more apparent
+ SkMWCRandom rand;
+
+ for (int y = 0; y < kImageHeight; y += 10) {
+ for (int x = 0; x < kImageWidth; x += 10) {
+ SkRect r = SkRect::MakeXYWH(SkIntToScalar(x),
+ SkIntToScalar(y),
+ 10, 10);
+ SkPaint p;
+ p.setColor(rand.nextU() | 0xFF000000);
+ canvas->drawRect(r, p);
+ }
+ }
+
+ canvas->translate(2, 2);
+ for (int outerShape = 0; outerShape < kShapeCount; ++outerShape) {
+ canvas->save();
+ for (int innerShape = 0; innerShape < kShapeCount; ++innerShape) {
+ for (size_t innerRect = 0; innerRect < SK_ARRAY_COUNT(innerRects); ++innerRect) {
+ SkPath path;
+
+ AddShape(&path, outerRect, (Shapes) outerShape, SkPath::kCW_Direction);
+ AddShape(&path, innerRects[innerRect], (Shapes) innerShape,
+ SkPath::kCCW_Direction);
+
+ canvas->drawPath(path, shapePaint);
+ canvas->translate(45, 0);
+ }
+ }
+ canvas->restore();
+ canvas->translate(0, 45);
+ }
+
+ }
+
+private:
+ static const int kImageWidth = 269;
+ static const int kImageHeight = 134;
+
+ bool fDoAA;
+
+ typedef GM INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return new NestedGM(true); )
+DEF_GM( return new NestedGM(false); )
+
+
+}
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index bc0fc65415..b1e6530b96 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -78,6 +78,7 @@
'../gm/mixedxfermodes.cpp',
'../gm/modecolorfilters.cpp',
'../gm/morphology.cpp',
+ '../gm/nested.cpp',
'../gm/ninepatchstretch.cpp',
'../gm/nocolorbleed.cpp',
'../gm/optimizations.cpp',
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b35b356b59..4bd8098218 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1011,8 +1011,6 @@ void GrContext::drawOval(const GrPaint& paint,
}
}
-namespace {
-
// Can 'path' be drawn as a pair of filled nested rectangles?
static bool is_nested_rects(GrDrawTarget* target,
const SkPath& path,
@@ -1047,15 +1045,26 @@ static bool is_nested_rects(GrDrawTarget* target,
return false;
}
- if (SkPath::kWinding_FillType == path.getFillType()) {
+ if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) {
// The two rects need to be wound opposite to each other
- return dirs[0] != dirs[1];
- } else {
- return true;
+ return false;
}
-}
-};
+ // Right now, nested rects where the margin is not the same width
+ // all around do not render correctly
+ const SkScalar* outer = rects[0].asScalars();
+ const SkScalar* inner = rects[1].asScalars();
+
+ SkScalar margin = SkScalarAbs(outer[0] - inner[0]);
+ for (int i = 1; i < 4; ++i) {
+ SkScalar temp = SkScalarAbs(outer[i] - inner[i]);
+ if (!SkScalarNearlyEqual(margin, temp)) {
+ return false;
+ }
+ }
+
+ return true;
+}
void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const SkStrokeRec& stroke) {