Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: src/gpu/effects/GrConvexPolyEffect.h

Issue 149683004: Add convex polygon rendering effect and GM to test it. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: more cleanup Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
robertphillips 2014/01/29 20:57:55 Fix this name?
bsalomon 2014/01/29 22:19:42 nice catch, guess you can tell how I started this
8 #ifndef GrBezierEffect_DEFINED
9 #define GrBezierEffect_DEFINED
10
11 #include "GrDrawTargetCaps.h"
12 #include "GrEffect.h"
13 #include "GrVertexEffect.h"
14
15 class GrGLConvexPolyEffect;
16 class SkPath;
17
18 /**
19 * An effect that renders a convex polygon. It is intended to be used as a cover age effect.
20 * Bounding geometry is rendered and the effect computes coverage based on the f ragment's
21 * position relative to the polygon.
22 */
23 class GrConvexPolyEffect : public GrEffect {
24 public:
25 /** This could be expanded to include a AA hairline mode. If so, unify with GrBezierEffect's
26 enum. */
27 enum EdgeType {
28 kFillNoAA_EdgeType,
29 kFillAA_EdgeType,
30
31 kLastEdgeType = kFillAA_EdgeType,
32 };
33
34 enum {
35 kEdgeTypeCnt = kLastEdgeType + 1,
36 kMaxEdges = 8,
37 };
38
39 /**
robertphillips 2014/01/29 20:57:55 Do we want to state in the comment that n must be
bsalomon 2014/01/29 22:19:42 Done.
40 * edges is a set of n edge equations. It contains 3*n values. The edges sho uld form a convex
robertphillips 2014/01/29 20:57:55 equations rather than equalizations?
bsalomon 2014/01/29 22:19:42 Done.
41 * polygon. The positive half-plane is considered to be the inside. The equa lizations should
42 * be normalized such that the first two coefficients are a unit 2d vector.
43 *
44 * Currently the edges are specified in device space. In the future we may p refer to specify
45 * them in src space. There are a number of ways this could be accomplished but we'd probably
46 * have to modify the effect/shaderbuilder interface to make it possible (e. g. give access
47 * to the view matrix or untransformed positions in the fragment shader).
48 */
49 static GrEffectRef* Create(EdgeType edgeType, int n, const SkScalar edges[]) {
50 if (n <= 0 || n > kMaxEdges) {
51 return NULL;
52 }
53 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrConvexPolyEffect,
54 (edgeType, n, edges))) );
55 }
56
57 /**
58 * Creates an effect that clips against the path. If the path is not a conve x polygon, is
59 * inverse filled, or has too many edges, this will return NULL.
60 */
61 static GrEffectRef* Create(EdgeType, const SkPath&);
62
63 virtual ~GrConvexPolyEffect();
64
65 static const char* Name() { return "ConvexPoly"; }
66
67 EdgeType getEdgeType() const { return fEdgeType; }
68
69 int getEdgeCount() const { return fEdgeCount; }
70
71 const SkScalar* getEdges() const { return fEdges; }
72
73 typedef GrGLConvexPolyEffect GLEffect;
74
75 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
76
77 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
78
79 private:
80 GrConvexPolyEffect(EdgeType edgeType, int n, const SkScalar edges[]);
81
82 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
83
84 EdgeType fEdgeType;
85 int fEdgeCount;
86 SkScalar fEdges[3 * kMaxEdges];
87
88 GR_DECLARE_EFFECT_TEST;
89
90 typedef GrEffect INHERITED;
91 };
92
93
94 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698