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

Side by Side Diff: src/gpu/gl/GrGLPath.cpp

Issue 694503003: Implement conics for NVPR (Closed) Base URL: https://skia.googlesource.com/skia.git@hairline-test-fix-unskip-nvpr
Patch Set: cleanup Created 6 years, 1 month 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
« include/core/SkPath.h ('K') | « src/gpu/gl/GrGLDefines.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 inline int num_pts(SkPath::Verb verb) { 34 inline int num_pts(SkPath::Verb verb) {
35 static const int gTable[] = { 35 static const int gTable[] = {
36 1, // move 36 1, // move
37 1, // line 37 1, // line
38 2, // quad 38 2, // quad
39 2, // conic 39 2, // conic
40 3, // cubic 40 3, // cubic
41 0, // close 41 0, // close
42 }; 42 };
43 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb); 43 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb);
44 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb); 44 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb);
45 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb); 45 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb);
46 GR_STATIC_ASSERT(3 == SkPath::kConic_Verb);
46 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb); 47 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb);
47 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb); 48 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb);
48 49
49 SkASSERT(verb >= 0 && (size_t)verb < SK_ARRAY_COUNT(gTable)); 50 SkASSERT(verb >= 0 && (size_t)verb < SK_ARRAY_COUNT(gTable));
50 return gTable[verb]; 51 return gTable[verb];
51 } 52 }
52 #endif
53 53
54 inline GrGLenum join_to_gl_join(SkPaint::Join join) { 54 inline GrGLenum join_to_gl_join(SkPaint::Join join) {
55 static GrGLenum gSkJoinsToGrGLJoins[] = { 55 static GrGLenum gSkJoinsToGrGLJoins[] = {
56 GR_GL_MITER_REVERT, 56 GR_GL_MITER_REVERT,
57 GR_GL_ROUND, 57 GR_GL_ROUND,
58 GR_GL_BEVEL 58 GR_GL_BEVEL
59 }; 59 };
60 return gSkJoinsToGrGLJoins[join]; 60 return gSkJoinsToGrGLJoins[join];
61 GR_STATIC_ASSERT(0 == SkPaint::kMiter_Join); 61 GR_STATIC_ASSERT(0 == SkPaint::kMiter_Join);
62 GR_STATIC_ASSERT(1 == SkPaint::kRound_Join); 62 GR_STATIC_ASSERT(1 == SkPaint::kRound_Join);
(...skipping 17 matching lines...) Expand all
80 } 80 }
81 81
82 static const bool kIsWrapped = false; // The constructor creates the GL path obj ect. 82 static const bool kIsWrapped = false; // The constructor creates the GL path obj ect.
83 83
84 void GrGLPath::InitPathObject(GrGpuGL* gpu, 84 void GrGLPath::InitPathObject(GrGpuGL* gpu,
85 GrGLuint pathID, 85 GrGLuint pathID,
86 const SkPath& skPath, 86 const SkPath& skPath,
87 const SkStrokeRec& stroke) { 87 const SkStrokeRec& stroke) {
88 if (!skPath.isEmpty()) { 88 if (!skPath.isEmpty()) {
89 SkSTArray<16, GrGLubyte, true> pathCommands; 89 SkSTArray<16, GrGLubyte, true> pathCommands;
90 SkSTArray<16, SkPoint, true> pathPoints; 90 SkSTArray<16, GrGLfloat, true> pathCoords;
91 SK_COMPILE_ASSERT(sizeof(SkPoint) == 2 * sizeof(GrGLfloat), sk_point_not _two_floats);
91 92
92 int verbCnt = skPath.countVerbs(); 93 int verbCnt = skPath.countVerbs();
93 int pointCnt = skPath.countPoints(); 94 int pointCnt = skPath.countPoints();
95 int conicWeightCnt = skPath.countConicWeights();
96 int coordCnt = 2 * pointCnt + conicWeightCnt;
97
94 pathCommands.resize_back(verbCnt); 98 pathCommands.resize_back(verbCnt);
95 pathPoints.resize_back(pointCnt); 99 pathCoords.resize_back(coordCnt);
100
101
102 skPath.getVerbs(&pathCommands[0], verbCnt);
96 103
97 // TODO: Direct access to path points since we could pass them on direct ly. 104 // TODO: Direct access to path points since we could pass them on direct ly.
98 skPath.getPoints(&pathPoints[0], pointCnt); 105 if (0 == conicWeightCnt) {
99 skPath.getVerbs(&pathCommands[0], verbCnt); 106 skPath.getPoints(reinterpret_cast<SkPoint*>(&pathCoords[0]), pointCn t);
100 107 SkDEBUGCODE(int numPts = 0);
101 SkDEBUGCODE(int numPts = 0); 108 for (int i = 0; i < verbCnt; ++i) {
102 for (int i = 0; i < verbCnt; ++i) { 109 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]);
103 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); 110 pathCommands[i] = verb_to_gl_path_cmd(v);
104 pathCommands[i] = verb_to_gl_path_cmd(v); 111 SkDEBUGCODE(numPts += num_pts(v));
105 SkDEBUGCODE(numPts += num_pts(v)); 112 }
113 SkASSERT(coordCnt == numPts * 2);
114 } else {
115 int pointIndex = 0;
116 int conicIndex = 0;
117 int coordIndex = 0;
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 int pointsForVerb = num_pts(v);
122 while (pointsForVerb--) {
123 SkPoint p = skPath.getPoint(pointIndex++);
124 pathCoords[coordIndex++] = p.fX;
125 pathCoords[coordIndex++] = p.fY;
126 }
127 if (SkPath::kConic_Verb == v) {
128 pathCoords[coordIndex++] = skPath.getConicWeight(conicIndex+ +);
129 }
130 }
131 SkASSERT(pointCnt == pointIndex);
132 SkASSERT(conicWeightCnt == conicIndex);
133 SkASSERT(coordCnt == coordIndex);
106 } 134 }
107 SkASSERT(pathPoints.count() == numPts);
108 135
109 GR_GL_CALL(gpu->glInterface(), 136 GR_GL_CALL(gpu->glInterface(),
110 PathCommands(pathID, verbCnt, &pathCommands[0], 137 PathCommands(pathID, verbCnt, &pathCommands[0],
111 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); 138 coordCnt, GR_GL_FLOAT, &pathCoords[0]));
112 } else { 139 } else {
113 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, 0, NULL, 0, GR_GL_FL OAT, NULL)); 140 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, 0, NULL, 0, GR_GL_FL OAT, NULL));
114 } 141 }
115 142
116 if (stroke.needToApply()) { 143 if (stroke.needToApply()) {
117 SkASSERT(!stroke.isHairlineStyle()); 144 SkASSERT(!stroke.isHairlineStyle());
118 GR_GL_CALL(gpu->glInterface(), 145 GR_GL_CALL(gpu->glInterface(),
119 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro ke.getWidth()))); 146 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro ke.getWidth())));
120 GR_GL_CALL(gpu->glInterface(), 147 GR_GL_CALL(gpu->glInterface(),
121 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok e.getMiter()))); 148 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok e.getMiter())));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 181 }
155 182
156 INHERITED::onRelease(); 183 INHERITED::onRelease();
157 } 184 }
158 185
159 void GrGLPath::onAbandon() { 186 void GrGLPath::onAbandon() {
160 fPathID = 0; 187 fPathID = 0;
161 188
162 INHERITED::onAbandon(); 189 INHERITED::onAbandon();
163 } 190 }
OLDNEW
« include/core/SkPath.h ('K') | « src/gpu/gl/GrGLDefines.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698