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

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

Issue 23440049: Implement stroking a path with nv_path_rendering (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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
« no previous file with comments | « src/gpu/gl/GrGLPath.h ('k') | src/gpu/gl/GrGpuGL.h » ('j') | 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 "GrGpuGL.h" 10 #include "GrGpuGL.h"
11 #include "SkStrokeRec.h"
11 12
12 #define GPUGL static_cast<GrGpuGL*>(this->getGpu()) 13 #define GPUGL static_cast<GrGpuGL*>(this->getGpu())
13 14
14 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) 15 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
15 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(GPUGL->glInterface(), R, X) 16 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(GPUGL->glInterface(), R, X)
16 17
17 namespace { 18 namespace {
18 inline GrGLubyte verb_to_gl_path_cmd(const SkPath::Verb verb) { 19 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) {
19 static const GrGLubyte gTable[] = { 20 static const GrGLubyte gTable[] = {
20 GR_GL_MOVE_TO, 21 GR_GL_MOVE_TO,
21 GR_GL_LINE_TO, 22 GR_GL_LINE_TO,
22 GR_GL_QUADRATIC_CURVE_TO, 23 GR_GL_QUADRATIC_CURVE_TO,
23 0xFF, // conic 24 0xFF, // conic
24 GR_GL_CUBIC_CURVE_TO, 25 GR_GL_CUBIC_CURVE_TO,
25 GR_GL_CLOSE_PATH, 26 GR_GL_CLOSE_PATH,
26 }; 27 };
27 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb); 28 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb);
28 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb); 29 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb);
29 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb); 30 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb);
30 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb); 31 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb);
31 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb); 32 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb);
32 33
33 SkASSERT(verb >= 0 && (size_t)verb < GR_ARRAY_COUNT(gTable)); 34 SkASSERT(verb >= 0 && (size_t)verb < GR_ARRAY_COUNT(gTable));
34 return gTable[verb]; 35 return gTable[verb];
35 } 36 }
36 37
37 #ifdef SK_DEBUG 38 #ifdef SK_DEBUG
38 inline int num_pts(const SkPath::Verb verb) { 39 inline int num_pts(SkPath::Verb verb) {
39 static const int gTable[] = { 40 static const int gTable[] = {
40 1, // move 41 1, // move
41 1, // line 42 1, // line
42 2, // quad 43 2, // quad
43 2, // conic 44 2, // conic
44 3, // cubic 45 3, // cubic
45 0, // close 46 0, // close
46 }; 47 };
47 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb); 48 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb);
48 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb); 49 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb);
49 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb); 50 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb);
50 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb); 51 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb);
51 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb); 52 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb);
52 53
53 SkASSERT(verb >= 0 && (size_t)verb < GR_ARRAY_COUNT(gTable)); 54 SkASSERT(verb >= 0 && (size_t)verb < GR_ARRAY_COUNT(gTable));
54 return gTable[verb]; 55 return gTable[verb];
55 } 56 }
56 #endif 57 #endif
58
59 inline GrGLenum join_to_gl_join(SkPaint::Join join) {
60 static GrGLenum gSkJoinsToGrGLJoins[] = {
61 GR_GL_MITER_REVERT,
62 GR_GL_ROUND,
63 GR_GL_BEVEL
64 };
65 return gSkJoinsToGrGLJoins[join];
66 GR_STATIC_ASSERT(0 == SkPaint::kMiter_Join);
67 GR_STATIC_ASSERT(1 == SkPaint::kRound_Join);
68 GR_STATIC_ASSERT(2 == SkPaint::kBevel_Join);
69 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gSkJoinsToGrGLJoins) == SkPaint::kJoinCount) ;
70 }
71
72 inline GrGLenum cap_to_gl_cap(SkPaint::Cap cap) {
73 static GrGLenum gSkCapsToGrGLCaps[] = {
74 GR_GL_FLAT,
75 GR_GL_ROUND,
76 GR_GL_SQUARE
77 };
78 return gSkCapsToGrGLCaps[cap];
79 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap);
80 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap);
81 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap);
82 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount);
83 }
84
57 } 85 }
58 86
59 static const bool kIsWrapped = false; // The constructor creates the GL path obj ect. 87 static const bool kIsWrapped = false; // The constructor creates the GL path obj ect.
60 88
61 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path) : INHERITED(gpu, kIsWrapped ) { 89 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
90 : INHERITED(gpu, kIsWrapped, stroke) {
62 #ifndef SK_SCALAR_IS_FLOAT 91 #ifndef SK_SCALAR_IS_FLOAT
63 GrCrash("Assumes scalar is float."); 92 GrCrash("Assumes scalar is float.");
64 #endif 93 #endif
65 SkASSERT(!path.isEmpty()); 94 SkASSERT(!path.isEmpty());
66 95
67 GL_CALL_RET(fPathID, GenPaths(1)); 96 GL_CALL_RET(fPathID, GenPaths(1));
68 97
69 SkSTArray<16, GrGLubyte, true> pathCommands; 98 SkSTArray<16, GrGLubyte, true> pathCommands;
70 SkSTArray<16, SkPoint, true> pathPoints; 99 SkSTArray<16, SkPoint, true> pathPoints;
71 100
(...skipping 11 matching lines...) Expand all
83 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); 112 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]);
84 pathCommands[i] = verb_to_gl_path_cmd(v); 113 pathCommands[i] = verb_to_gl_path_cmd(v);
85 SkDEBUGCODE(numPts += num_pts(v)); 114 SkDEBUGCODE(numPts += num_pts(v));
86 } 115 }
87 SkASSERT(pathPoints.count() == numPts); 116 SkASSERT(pathPoints.count() == numPts);
88 117
89 GL_CALL(PathCommands(fPathID, 118 GL_CALL(PathCommands(fPathID,
90 verbCnt, &pathCommands[0], 119 verbCnt, &pathCommands[0],
91 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); 120 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0]));
92 fBounds = path.getBounds(); 121 fBounds = path.getBounds();
122
123 if (stroke.needToApply()) {
124 GL_CALL(PathParameterf(fPathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat (stroke.getWidth())));
125 GL_CALL(PathParameterf(fPathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat( stroke.getMiter())));
126 GrGLenum join = join_to_gl_join(stroke.getJoin());
127 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_JOIN_STYLE, join));
128 GrGLenum cap = cap_to_gl_cap(stroke.getCap());
129 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_INITIAL_END_CAP, cap));
130 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_TERMINAL_END_CAP, cap));
131
132 // FIXME: try to account for stroking, without rasterizing the stroke.
133 fBounds.outset(SkScalarToFloat(stroke.getWidth()), SkScalarToFloat(strok e.getWidth()));
134 }
93 } 135 }
94 136
95 GrGLPath::~GrGLPath() { 137 GrGLPath::~GrGLPath() {
96 this->release(); 138 this->release();
97 } 139 }
98 140
99 void GrGLPath::onRelease() { 141 void GrGLPath::onRelease() {
100 if (0 != fPathID && !this->isWrapped()) { 142 if (0 != fPathID && !this->isWrapped()) {
101 GL_CALL(DeletePaths(fPathID, 1)); 143 GL_CALL(DeletePaths(fPathID, 1));
102 fPathID = 0; 144 fPathID = 0;
103 } 145 }
104 146
105 INHERITED::onRelease(); 147 INHERITED::onRelease();
106 } 148 }
107 149
108 void GrGLPath::onAbandon() { 150 void GrGLPath::onAbandon() {
109 fPathID = 0; 151 fPathID = 0;
110 152
111 INHERITED::onAbandon(); 153 INHERITED::onAbandon();
112 } 154 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLPath.h ('k') | src/gpu/gl/GrGpuGL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698