OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrGLPath.h" | 9 #include "GrGLPath.h" |
10 #include "GrGLPathRendering.h" | 10 #include "GrGLPathRendering.h" |
11 #include "GrGpuGL.h" | 11 #include "GrGpuGL.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) { | 14 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) { |
15 static const GrGLubyte gTable[] = { | 15 static const GrGLubyte gTable[] = { |
16 GR_GL_MOVE_TO, | 16 GR_GL_MOVE_TO, |
17 GR_GL_LINE_TO, | 17 GR_GL_LINE_TO, |
18 GR_GL_QUADRATIC_CURVE_TO, | 18 GR_GL_QUADRATIC_CURVE_TO, |
19 0xFF, // conic | 19 GR_GL_CONIC_CURVE_TO, |
20 GR_GL_CUBIC_CURVE_TO, | 20 GR_GL_CUBIC_CURVE_TO, |
21 GR_GL_CLOSE_PATH, | 21 GR_GL_CLOSE_PATH, |
22 }; | 22 }; |
23 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb); | 23 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb); |
24 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb); | 24 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb); |
25 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb); | 25 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb); |
26 GR_STATIC_ASSERT(3 == SkPath::kConic_Verb); | |
26 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb); | 27 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb); |
27 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb); | 28 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb); |
28 | 29 |
29 SkASSERT(verb >= 0 && (size_t)verb < SK_ARRAY_COUNT(gTable)); | 30 SkASSERT(verb >= 0 && (size_t)verb < SK_ARRAY_COUNT(gTable)); |
30 return gTable[verb]; | 31 return gTable[verb]; |
31 } | 32 } |
32 | 33 |
33 #ifdef SK_DEBUG | 34 #ifdef SK_DEBUG |
34 inline int num_pts(SkPath::Verb verb) { | 35 inline int num_coords(SkPath::Verb verb) { |
35 static const int gTable[] = { | 36 static const int gTable[] = { |
36 1, // move | 37 2, // move |
37 1, // line | 38 2, // line |
38 2, // quad | 39 4, // quad |
39 2, // conic | 40 5, // conic |
40 3, // cubic | 41 6, // cubic |
41 0, // close | 42 0, // close |
42 }; | 43 }; |
43 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb); | 44 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb); |
44 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb); | 45 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb); |
45 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb); | 46 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb); |
47 GR_STATIC_ASSERT(3 == SkPath::kConic_Verb); | |
46 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb); | 48 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb); |
47 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb); | 49 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb); |
48 | 50 |
49 SkASSERT(verb >= 0 && (size_t)verb < SK_ARRAY_COUNT(gTable)); | 51 SkASSERT(verb >= 0 && (size_t)verb < SK_ARRAY_COUNT(gTable)); |
50 return gTable[verb]; | 52 return gTable[verb]; |
51 } | 53 } |
52 #endif | 54 #endif |
53 | 55 |
54 inline GrGLenum join_to_gl_join(SkPaint::Join join) { | 56 inline GrGLenum join_to_gl_join(SkPaint::Join join) { |
55 static GrGLenum gSkJoinsToGrGLJoins[] = { | 57 static GrGLenum gSkJoinsToGrGLJoins[] = { |
(...skipping 14 matching lines...) Expand all Loading... | |
70 GR_GL_ROUND, | 72 GR_GL_ROUND, |
71 GR_GL_SQUARE | 73 GR_GL_SQUARE |
72 }; | 74 }; |
73 return gSkCapsToGrGLCaps[cap]; | 75 return gSkCapsToGrGLCaps[cap]; |
74 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap); | 76 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap); |
75 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); | 77 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); |
76 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); | 78 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); |
77 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); | 79 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); |
78 } | 80 } |
79 | 81 |
82 inline void points_to_coords(const SkPoint points[], size_t first_point, size_t amount, | |
83 GrGLfloat coords[]) { | |
84 for (size_t i = 0; i < amount; ++i) { | |
85 coords[i * 2] = SkScalarToFloat(points[first_point + i].fX); | |
86 coords[i * 2 + 1] = SkScalarToFloat(points[first_point + i].fY); | |
87 } | |
88 } | |
80 } | 89 } |
81 | 90 |
82 static const bool kIsWrapped = false; // The constructor creates the GL path obj ect. | 91 static const bool kIsWrapped = false; // The constructor creates the GL path obj ect. |
83 | 92 |
84 void GrGLPath::InitPathObject(GrGpuGL* gpu, | 93 void GrGLPath::InitPathObject(GrGpuGL* gpu, |
85 GrGLuint pathID, | 94 GrGLuint pathID, |
86 const SkPath& skPath, | 95 const SkPath& skPath, |
87 const SkStrokeRec& stroke) { | 96 const SkStrokeRec& stroke) { |
88 if (!skPath.isEmpty()) { | 97 if (!skPath.isEmpty()) { |
89 SkSTArray<16, GrGLubyte, true> pathCommands; | |
90 SkSTArray<16, SkPoint, true> pathPoints; | |
91 | |
92 int verbCnt = skPath.countVerbs(); | 98 int verbCnt = skPath.countVerbs(); |
93 int pointCnt = skPath.countPoints(); | 99 int pointCnt = skPath.countPoints(); |
94 pathCommands.resize_back(verbCnt); | 100 int minCoordCnt = pointCnt * 2; |
95 pathPoints.resize_back(pointCnt); | |
96 | 101 |
97 // TODO: Direct access to path points since we could pass them on direct ly. | 102 SkSTArray<16, GrGLubyte, true> pathCommands(verbCnt); |
98 skPath.getPoints(&pathPoints[0], pointCnt); | 103 SkSTArray<16, GrGLfloat, true> pathCoords(minCoordCnt); |
99 skPath.getVerbs(&pathCommands[0], verbCnt); | |
100 | 104 |
101 SkDEBUGCODE(int numPts = 0); | 105 SkDEBUGCODE(int numCoords = 0); |
102 for (int i = 0; i < verbCnt; ++i) { | 106 |
103 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); | 107 if ((skPath.getSegmentMasks() & SkPath::kConic_SegmentMask) == 0) { |
104 pathCommands[i] = verb_to_gl_path_cmd(v); | 108 // This branch does type punning, converting SkPoint* to GrGLfloat*. |
105 SkDEBUGCODE(numPts += num_pts(v)); | 109 SK_COMPILE_ASSERT(sizeof(SkPoint) == sizeof(GrGLfloat) * 2, sk_point _not_two_floats); |
110 // This branch does not convert with SkScalarToFloat. | |
111 #ifndef SK_SCALAR_IS_FLOAT | |
bsalomon
2014/11/19 16:53:33
There is some interest in scalar=double. I suppose
| |
112 #error Need SK_SCALAR_IS_FLOAT. | |
113 #endif | |
114 pathCommands.resize_back(verbCnt); | |
115 pathCoords.resize_back(minCoordCnt); | |
116 skPath.getPoints(reinterpret_cast<SkPoint*>(&pathCoords[0]), pointCn t); | |
117 skPath.getVerbs(&pathCommands[0], verbCnt); | |
118 for (int i = 0; i < verbCnt; ++i) { | |
119 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); | |
120 pathCommands[i] = verb_to_gl_path_cmd(v); | |
121 SkDEBUGCODE(numCoords += num_coords(v)); | |
122 } | |
123 } else { | |
124 SkPoint points[4]; | |
125 SkPath::RawIter iter(skPath); | |
126 SkPath::Verb verb; | |
127 while ((verb = iter.next(points)) != SkPath::kDone_Verb) { | |
128 pathCommands.push_back(verb_to_gl_path_cmd(verb)); | |
129 GrGLfloat coords[6]; | |
130 int coordsForVerb; | |
131 switch (verb) { | |
132 case SkPath::kMove_Verb: | |
133 points_to_coords(points, 0, 1, coords); | |
134 coordsForVerb = 2; | |
135 break; | |
136 case SkPath::kLine_Verb: | |
137 points_to_coords(points, 1, 1, coords); | |
138 coordsForVerb = 2; | |
139 break; | |
140 case SkPath::kConic_Verb: | |
141 points_to_coords(points, 1, 2, coords); | |
142 coords[4] = SkScalarToFloat(iter.conicWeight()); | |
143 coordsForVerb = 5; | |
144 break; | |
145 case SkPath::kQuad_Verb: | |
146 points_to_coords(points, 1, 2, coords); | |
147 coordsForVerb = 4; | |
148 break; | |
149 case SkPath::kCubic_Verb: | |
150 points_to_coords(points, 1, 3, coords); | |
151 coordsForVerb = 6; | |
152 break; | |
153 case SkPath::kClose_Verb: | |
154 continue; | |
155 default: | |
156 SkASSERT(false); // Not reached. | |
157 continue; | |
158 } | |
159 SkDEBUGCODE(numCoords += num_coords(verb)); | |
160 pathCoords.push_back_n(coordsForVerb, coords); | |
161 } | |
106 } | 162 } |
107 SkASSERT(pathPoints.count() == numPts); | |
108 | 163 |
109 GR_GL_CALL(gpu->glInterface(), | 164 SkASSERT(verbCnt == pathCommands.count()); |
110 PathCommands(pathID, verbCnt, &pathCommands[0], | 165 SkASSERT(numCoords == pathCoords.count()); |
111 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); | 166 |
167 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, pathCommands.count() , &pathCommands[0], | |
168 pathCoords.count(), GR_GL_FLOAT, &pathCoords[0])); | |
112 } else { | 169 } else { |
113 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, 0, NULL, 0, GR_GL_FL OAT, NULL)); | 170 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, 0, NULL, 0, GR_GL_FL OAT, NULL)); |
114 } | 171 } |
115 | 172 |
116 if (stroke.needToApply()) { | 173 if (stroke.needToApply()) { |
117 SkASSERT(!stroke.isHairlineStyle()); | 174 SkASSERT(!stroke.isHairlineStyle()); |
118 GR_GL_CALL(gpu->glInterface(), | 175 GR_GL_CALL(gpu->glInterface(), |
119 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro ke.getWidth()))); | 176 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro ke.getWidth()))); |
120 GR_GL_CALL(gpu->glInterface(), | 177 GR_GL_CALL(gpu->glInterface(), |
121 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok e.getMiter()))); | 178 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok e.getMiter()))); |
(...skipping 24 matching lines...) Expand all Loading... | |
146 } | 203 } |
147 | 204 |
148 INHERITED::onRelease(); | 205 INHERITED::onRelease(); |
149 } | 206 } |
150 | 207 |
151 void GrGLPath::onAbandon() { | 208 void GrGLPath::onAbandon() { |
152 fPathID = 0; | 209 fPathID = 0; |
153 | 210 |
154 INHERITED::onAbandon(); | 211 INHERITED::onAbandon(); |
155 } | 212 } |
OLD | NEW |