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