aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrConvexPolyEffect.h
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-30 18:15:51 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-30 18:15:51 +0000
commitc3fe54975daf6274103bcfefe5ed2e7af8d0170a (patch)
tree3f6fd520608519d149f203f9c089ab846e16eb7a /src/gpu/effects/GrConvexPolyEffect.h
parentfd191a135ff2a945edf2d4ead602b795631b200f (diff)
Add convex polygon rendering effect and GM to test it.
BUG=skia:2051 R=robertphillips@google.com, jvanverth@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/149683004 git-svn-id: http://skia.googlecode.com/svn/trunk@13242 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/effects/GrConvexPolyEffect.h')
-rw-r--r--src/gpu/effects/GrConvexPolyEffect.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/gpu/effects/GrConvexPolyEffect.h b/src/gpu/effects/GrConvexPolyEffect.h
new file mode 100644
index 0000000000..8390e149b7
--- /dev/null
+++ b/src/gpu/effects/GrConvexPolyEffect.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrConvexPolyEffect_DEFINED
+#define GrConvexPolyEffect_DEFINED
+
+#include "GrDrawTargetCaps.h"
+#include "GrEffect.h"
+#include "GrVertexEffect.h"
+
+class GrGLConvexPolyEffect;
+class SkPath;
+
+/**
+ * An effect that renders a convex polygon. It is intended to be used as a coverage effect.
+ * Bounding geometry is rendered and the effect computes coverage based on the fragment's
+ * position relative to the polygon.
+ */
+class GrConvexPolyEffect : public GrEffect {
+public:
+ /** This could be expanded to include a AA hairline mode. If so, unify with GrBezierEffect's
+ enum. */
+ enum EdgeType {
+ kFillNoAA_EdgeType,
+ kFillAA_EdgeType,
+
+ kLastEdgeType = kFillAA_EdgeType,
+ };
+
+ enum {
+ kEdgeTypeCnt = kLastEdgeType + 1,
+ kMaxEdges = 8,
+ };
+
+ /**
+ * edges is a set of n edge equations where n is limited to kMaxEdges. It contains 3*n values.
+ * The edges should form a convex polygon. The positive half-plane is considered to be the
+ * inside. The equations should be normalized such that the first two coefficients are a unit
+ * 2d vector.
+ *
+ * Currently the edges are specified in device space. In the future we may prefer to specify
+ * them in src space. There are a number of ways this could be accomplished but we'd probably
+ * have to modify the effect/shaderbuilder interface to make it possible (e.g. give access
+ * to the view matrix or untransformed positions in the fragment shader).
+ */
+ static GrEffectRef* Create(EdgeType edgeType, int n, const SkScalar edges[]) {
+ if (n <= 0 || n > kMaxEdges) {
+ return NULL;
+ }
+ return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrConvexPolyEffect,
+ (edgeType, n, edges))));
+ }
+
+ /**
+ * Creates an effect that clips against the path. If the path is not a convex polygon, is
+ * inverse filled, or has too many edges, this will return NULL.
+ */
+ static GrEffectRef* Create(EdgeType, const SkPath&);
+
+ virtual ~GrConvexPolyEffect();
+
+ static const char* Name() { return "ConvexPoly"; }
+
+ EdgeType getEdgeType() const { return fEdgeType; }
+
+ int getEdgeCount() const { return fEdgeCount; }
+
+ const SkScalar* getEdges() const { return fEdges; }
+
+ typedef GrGLConvexPolyEffect GLEffect;
+
+ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+
+ virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
+
+private:
+ GrConvexPolyEffect(EdgeType edgeType, int n, const SkScalar edges[]);
+
+ virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
+
+ EdgeType fEdgeType;
+ int fEdgeCount;
+ SkScalar fEdges[3 * kMaxEdges];
+
+ GR_DECLARE_EFFECT_TEST;
+
+ typedef GrEffect INHERITED;
+};
+
+
+#endif