| 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 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 SkSTArray<16, GrGLubyte, true> pathCommands; | 88 if (!skPath.isEmpty()) { |
| 89 SkSTArray<16, SkPoint, true> pathPoints; | 89 SkSTArray<16, GrGLubyte, true> pathCommands; |
| 90 SkSTArray<16, SkPoint, true> pathPoints; |
| 90 | 91 |
| 91 int verbCnt = skPath.countVerbs(); | 92 int verbCnt = skPath.countVerbs(); |
| 92 int pointCnt = skPath.countPoints(); | 93 int pointCnt = skPath.countPoints(); |
| 93 pathCommands.resize_back(verbCnt); | 94 pathCommands.resize_back(verbCnt); |
| 94 pathPoints.resize_back(pointCnt); | 95 pathPoints.resize_back(pointCnt); |
| 95 | 96 |
| 96 // 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 direct
ly. |
| 97 skPath.getPoints(&pathPoints[0], pointCnt); | 98 skPath.getPoints(&pathPoints[0], pointCnt); |
| 98 skPath.getVerbs(&pathCommands[0], verbCnt); | 99 skPath.getVerbs(&pathCommands[0], verbCnt); |
| 99 | 100 |
| 100 SkDEBUGCODE(int numPts = 0); | 101 SkDEBUGCODE(int numPts = 0); |
| 101 for (int i = 0; i < verbCnt; ++i) { | 102 for (int i = 0; i < verbCnt; ++i) { |
| 102 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); | 103 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); |
| 103 pathCommands[i] = verb_to_gl_path_cmd(v); | 104 pathCommands[i] = verb_to_gl_path_cmd(v); |
| 104 SkDEBUGCODE(numPts += num_pts(v)); | 105 SkDEBUGCODE(numPts += num_pts(v)); |
| 106 } |
| 107 SkASSERT(pathPoints.count() == numPts); |
| 108 |
| 109 GR_GL_CALL(gpu->glInterface(), |
| 110 PathCommands(pathID, verbCnt, &pathCommands[0], |
| 111 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); |
| 105 } | 112 } |
| 106 SkASSERT(pathPoints.count() == numPts); | |
| 107 | 113 |
| 108 GR_GL_CALL(gpu->glInterface(), | |
| 109 PathCommands(pathID, verbCnt, &pathCommands[0], | |
| 110 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); | |
| 111 if (stroke.needToApply()) { | 114 if (stroke.needToApply()) { |
| 112 SkASSERT(!stroke.isHairlineStyle()); | 115 SkASSERT(!stroke.isHairlineStyle()); |
| 113 GR_GL_CALL(gpu->glInterface(), | 116 GR_GL_CALL(gpu->glInterface(), |
| 114 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro
ke.getWidth()))); | 117 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro
ke.getWidth()))); |
| 115 GR_GL_CALL(gpu->glInterface(), | 118 GR_GL_CALL(gpu->glInterface(), |
| 116 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok
e.getMiter()))); | 119 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok
e.getMiter()))); |
| 117 GrGLenum join = join_to_gl_join(stroke.getJoin()); | 120 GrGLenum join = join_to_gl_join(stroke.getJoin()); |
| 118 GR_GL_CALL(gpu->glInterface(), | 121 GR_GL_CALL(gpu->glInterface(), |
| 119 PathParameteri(pathID, GR_GL_PATH_JOIN_STYLE, join)); | 122 PathParameteri(pathID, GR_GL_PATH_JOIN_STYLE, join)); |
| 120 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); | 123 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); |
| 121 GR_GL_CALL(gpu->glInterface(), | 124 GR_GL_CALL(gpu->glInterface(), |
| 122 PathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap)); | 125 PathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap)); |
| 123 GR_GL_CALL(gpu->glInterface(), | 126 GR_GL_CALL(gpu->glInterface(), |
| 124 PathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap)); | 127 PathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap)); |
| 125 } | 128 } |
| 126 } | 129 } |
| 127 | 130 |
| 128 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) | 131 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) |
| 129 : INHERITED(gpu, kIsWrapped, path, stroke), | 132 : INHERITED(gpu, kIsWrapped, path, stroke), |
| 130 fPathID(gpu->glPathRendering()->genPaths(1)) { | 133 fPathID(gpu->glPathRendering()->genPaths(1)) { |
| 131 SkASSERT(!path.isEmpty()); | |
| 132 | 134 |
| 133 InitPathObject(gpu, fPathID, fSkPath, stroke); | 135 InitPathObject(gpu, fPathID, fSkPath, stroke); |
| 134 | 136 |
| 135 if (stroke.needToApply()) { | 137 if (stroke.needToApply()) { |
| 136 // FIXME: try to account for stroking, without rasterizing the stroke. | 138 // FIXME: try to account for stroking, without rasterizing the stroke. |
| 137 fBounds.outset(stroke.getWidth(), stroke.getWidth()); | 139 fBounds.outset(stroke.getWidth(), stroke.getWidth()); |
| 138 } | 140 } |
| 139 this->registerWithCache(); | 141 this->registerWithCache(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 GrGLPath::~GrGLPath() { | 144 GrGLPath::~GrGLPath() { |
| 143 this->release(); | 145 this->release(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 void GrGLPath::onRelease() { | 148 void GrGLPath::onRelease() { |
| 147 if (0 != fPathID && !this->isWrapped()) { | 149 if (0 != fPathID && !this->isWrapped()) { |
| 148 static_cast<GrGpuGL*>(this->getGpu())->glPathRendering()->deletePaths(fP
athID, 1); | 150 static_cast<GrGpuGL*>(this->getGpu())->glPathRendering()->deletePaths(fP
athID, 1); |
| 149 fPathID = 0; | 151 fPathID = 0; |
| 150 } | 152 } |
| 151 | 153 |
| 152 INHERITED::onRelease(); | 154 INHERITED::onRelease(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 void GrGLPath::onAbandon() { | 157 void GrGLPath::onAbandon() { |
| 156 fPathID = 0; | 158 fPathID = 0; |
| 157 | 159 |
| 158 INHERITED::onAbandon(); | 160 INHERITED::onAbandon(); |
| 159 } | 161 } |
| OLD | NEW |