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 "GrGpuGL.h" | 11 #include "GrGpuGL.h" |
11 | 12 |
12 #define GPUGL static_cast<GrGpuGL*>(this->getGpu()) | |
13 | |
14 #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 | |
17 namespace { | 13 namespace { |
18 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) { | 14 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) { |
19 static const GrGLubyte gTable[] = { | 15 static const GrGLubyte gTable[] = { |
20 GR_GL_MOVE_TO, | 16 GR_GL_MOVE_TO, |
21 GR_GL_LINE_TO, | 17 GR_GL_LINE_TO, |
22 GR_GL_QUADRATIC_CURVE_TO, | 18 GR_GL_QUADRATIC_CURVE_TO, |
23 0xFF, // conic | 19 0xFF, // conic |
24 GR_GL_CUBIC_CURVE_TO, | 20 GR_GL_CUBIC_CURVE_TO, |
25 GR_GL_CLOSE_PATH, | 21 GR_GL_CLOSE_PATH, |
26 }; | 22 }; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap); | 74 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap); |
79 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); | 75 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); |
80 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); | 76 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); |
81 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); | 77 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); |
82 } | 78 } |
83 | 79 |
84 } | 80 } |
85 | 81 |
86 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. |
87 | 83 |
88 void GrGLPath::InitPathObject(const GrGLInterface* gl, | 84 void GrGLPath::InitPathObject(GrGpuGL* gpu, |
89 GrGLuint pathID, | 85 GrGLuint pathID, |
90 const SkPath& skPath, | 86 const SkPath& skPath, |
91 const SkStrokeRec& stroke) { | 87 const SkStrokeRec& stroke) { |
| 88 GrGLPathRendering* pr = gpu->pathRendering(); |
92 SkSTArray<16, GrGLubyte, true> pathCommands; | 89 SkSTArray<16, GrGLubyte, true> pathCommands; |
93 SkSTArray<16, SkPoint, true> pathPoints; | 90 SkSTArray<16, SkPoint, true> pathPoints; |
94 | 91 |
95 int verbCnt = skPath.countVerbs(); | 92 int verbCnt = skPath.countVerbs(); |
96 int pointCnt = skPath.countPoints(); | 93 int pointCnt = skPath.countPoints(); |
97 pathCommands.resize_back(verbCnt); | 94 pathCommands.resize_back(verbCnt); |
98 pathPoints.resize_back(pointCnt); | 95 pathPoints.resize_back(pointCnt); |
99 | 96 |
100 // TODO: Direct access to path points since we could pass them on directly. | 97 // TODO: Direct access to path points since we could pass them on directly. |
101 skPath.getPoints(&pathPoints[0], pointCnt); | 98 skPath.getPoints(&pathPoints[0], pointCnt); |
102 skPath.getVerbs(&pathCommands[0], verbCnt); | 99 skPath.getVerbs(&pathCommands[0], verbCnt); |
103 | 100 |
104 SkDEBUGCODE(int numPts = 0); | 101 SkDEBUGCODE(int numPts = 0); |
105 for (int i = 0; i < verbCnt; ++i) { | 102 for (int i = 0; i < verbCnt; ++i) { |
106 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); | 103 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); |
107 pathCommands[i] = verb_to_gl_path_cmd(v); | 104 pathCommands[i] = verb_to_gl_path_cmd(v); |
108 SkDEBUGCODE(numPts += num_pts(v)); | 105 SkDEBUGCODE(numPts += num_pts(v)); |
109 } | 106 } |
110 SkASSERT(pathPoints.count() == numPts); | 107 SkASSERT(pathPoints.count() == numPts); |
111 | 108 |
112 GR_GL_CALL(gl, PathCommands(pathID, | 109 pr->pathCommands(pathID, verbCnt, &pathCommands[0], 2 * pointCnt, GR_GL_FLOA
T, &pathPoints[0]); |
113 verbCnt, &pathCommands[0], | |
114 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); | |
115 | |
116 if (stroke.needToApply()) { | 110 if (stroke.needToApply()) { |
117 SkASSERT(!stroke.isHairlineStyle()); | 111 SkASSERT(!stroke.isHairlineStyle()); |
118 GR_GL_CALL(gl, PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarT
oFloat(stroke.getWidth()))); | 112 pr->pathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro
ke.getWidth())); |
119 GR_GL_CALL(gl, PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarTo
Float(stroke.getMiter()))); | 113 pr->pathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok
e.getMiter())); |
120 GrGLenum join = join_to_gl_join(stroke.getJoin()); | 114 GrGLenum join = join_to_gl_join(stroke.getJoin()); |
121 GR_GL_CALL(gl, PathParameteri(pathID, GR_GL_PATH_JOIN_STYLE, join)); | 115 pr->pathParameteri(pathID, GR_GL_PATH_JOIN_STYLE, join); |
122 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); | 116 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); |
123 GR_GL_CALL(gl, PathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap)); | 117 pr->pathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap); |
124 GR_GL_CALL(gl, PathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap))
; | 118 pr->pathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap); |
125 } | 119 } |
126 } | 120 } |
127 | 121 |
128 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) | 122 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) |
129 : INHERITED(gpu, kIsWrapped, path, stroke) { | 123 : INHERITED(gpu, kIsWrapped, path, stroke), |
| 124 fPathID(gpu->pathRendering()->genPaths(1)) { |
130 SkASSERT(!path.isEmpty()); | 125 SkASSERT(!path.isEmpty()); |
131 | 126 |
132 fPathID = gpu->createGLPathObject(); | 127 InitPathObject(gpu, fPathID, fSkPath, stroke); |
133 | |
134 InitPathObject(static_cast<GrGpuGL*>(this->getGpu())->glInterface(), | |
135 fPathID, fSkPath, stroke); | |
136 | 128 |
137 if (stroke.needToApply()) { | 129 if (stroke.needToApply()) { |
138 // FIXME: try to account for stroking, without rasterizing the stroke. | 130 // FIXME: try to account for stroking, without rasterizing the stroke. |
139 fBounds.outset(stroke.getWidth(), stroke.getWidth()); | 131 fBounds.outset(stroke.getWidth(), stroke.getWidth()); |
140 } | 132 } |
141 } | 133 } |
142 | 134 |
143 GrGLPath::~GrGLPath() { | 135 GrGLPath::~GrGLPath() { |
144 this->release(); | 136 this->release(); |
145 } | 137 } |
146 | 138 |
147 void GrGLPath::onRelease() { | 139 void GrGLPath::onRelease() { |
148 if (0 != fPathID && !this->isWrapped()) { | 140 if (0 != fPathID && !this->isWrapped()) { |
149 static_cast<GrGpuGL*>(this->getGpu())->deleteGLPathObject(fPathID); | 141 static_cast<GrGpuGL*>(this->getGpu())->pathRendering()->deletePaths(fPat
hID, 1); |
150 fPathID = 0; | 142 fPathID = 0; |
151 } | 143 } |
152 | 144 |
153 INHERITED::onRelease(); | 145 INHERITED::onRelease(); |
154 } | 146 } |
155 | 147 |
156 void GrGLPath::onAbandon() { | 148 void GrGLPath::onAbandon() { |
157 fPathID = 0; | 149 fPathID = 0; |
158 | 150 |
159 INHERITED::onAbandon(); | 151 INHERITED::onAbandon(); |
160 } | 152 } |
OLD | NEW |