| 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" |
| 11 #include "SkStrokeRec.h" | |
| 12 | 11 |
| 13 #define GPUGL static_cast<GrGpuGL*>(this->getGpu()) | 12 #define GPUGL static_cast<GrGpuGL*>(this->getGpu()) |
| 14 | 13 |
| 15 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 14 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 16 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(GPUGL->glInterface(), R, X) | 15 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(GPUGL->glInterface(), R, X) |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) { | 18 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) { |
| 20 static const GrGLubyte gTable[] = { | 19 static const GrGLubyte gTable[] = { |
| 21 GR_GL_MOVE_TO, | 20 GR_GL_MOVE_TO, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); | 79 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); |
| 81 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); | 80 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); |
| 82 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); | 81 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); |
| 83 } | 82 } |
| 84 | 83 |
| 85 } | 84 } |
| 86 | 85 |
| 87 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. |
| 88 | 87 |
| 89 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) | 88 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) |
| 90 : INHERITED(gpu, kIsWrapped, stroke) { | 89 : INHERITED(gpu, kIsWrapped, path, stroke) { |
| 91 #ifndef SK_SCALAR_IS_FLOAT | 90 #ifndef SK_SCALAR_IS_FLOAT |
| 92 GrCrash("Assumes scalar is float."); | 91 GrCrash("Assumes scalar is float."); |
| 93 #endif | 92 #endif |
| 94 SkASSERT(!path.isEmpty()); | 93 SkASSERT(!path.isEmpty()); |
| 95 | 94 |
| 96 GL_CALL_RET(fPathID, GenPaths(1)); | 95 GL_CALL_RET(fPathID, GenPaths(1)); |
| 97 | 96 |
| 98 SkSTArray<16, GrGLubyte, true> pathCommands; | 97 SkSTArray<16, GrGLubyte, true> pathCommands; |
| 99 SkSTArray<16, SkPoint, true> pathPoints; | 98 SkSTArray<16, SkPoint, true> pathPoints; |
| 100 | 99 |
| 101 int verbCnt = path.countVerbs(); | 100 int verbCnt = fSkPath.countVerbs(); |
| 102 int pointCnt = path.countPoints(); | 101 int pointCnt = fSkPath.countPoints(); |
| 103 pathCommands.resize_back(verbCnt); | 102 pathCommands.resize_back(verbCnt); |
| 104 pathPoints.resize_back(pointCnt); | 103 pathPoints.resize_back(pointCnt); |
| 105 | 104 |
| 106 // TODO: Direct access to path points since we could pass them on directly. | 105 // TODO: Direct access to path points since we could pass them on directly. |
| 107 path.getPoints(&pathPoints[0], pointCnt); | 106 fSkPath.getPoints(&pathPoints[0], pointCnt); |
| 108 path.getVerbs(&pathCommands[0], verbCnt); | 107 fSkPath.getVerbs(&pathCommands[0], verbCnt); |
| 109 | 108 |
| 110 SkDEBUGCODE(int numPts = 0); | 109 SkDEBUGCODE(int numPts = 0); |
| 111 for (int i = 0; i < verbCnt; ++i) { | 110 for (int i = 0; i < verbCnt; ++i) { |
| 112 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); | 111 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]); |
| 113 pathCommands[i] = verb_to_gl_path_cmd(v); | 112 pathCommands[i] = verb_to_gl_path_cmd(v); |
| 114 SkDEBUGCODE(numPts += num_pts(v)); | 113 SkDEBUGCODE(numPts += num_pts(v)); |
| 115 } | 114 } |
| 116 SkASSERT(pathPoints.count() == numPts); | 115 SkASSERT(pathPoints.count() == numPts); |
| 117 | 116 |
| 118 GL_CALL(PathCommands(fPathID, | 117 GL_CALL(PathCommands(fPathID, |
| 119 verbCnt, &pathCommands[0], | 118 verbCnt, &pathCommands[0], |
| 120 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); | 119 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0])); |
| 121 fBounds = path.getBounds(); | |
| 122 | 120 |
| 123 if (stroke.needToApply()) { | 121 if (stroke.needToApply()) { |
| 124 GL_CALL(PathParameterf(fPathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat
(stroke.getWidth()))); | 122 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()))); | 123 GL_CALL(PathParameterf(fPathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(
stroke.getMiter()))); |
| 126 GrGLenum join = join_to_gl_join(stroke.getJoin()); | 124 GrGLenum join = join_to_gl_join(stroke.getJoin()); |
| 127 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_JOIN_STYLE, join)); | 125 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_JOIN_STYLE, join)); |
| 128 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); | 126 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); |
| 129 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_INITIAL_END_CAP, cap)); | 127 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_INITIAL_END_CAP, cap)); |
| 130 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_TERMINAL_END_CAP, cap)); | 128 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_TERMINAL_END_CAP, cap)); |
| 131 | 129 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 145 } | 143 } |
| 146 | 144 |
| 147 INHERITED::onRelease(); | 145 INHERITED::onRelease(); |
| 148 } | 146 } |
| 149 | 147 |
| 150 void GrGLPath::onAbandon() { | 148 void GrGLPath::onAbandon() { |
| 151 fPathID = 0; | 149 fPathID = 0; |
| 152 | 150 |
| 153 INHERITED::onAbandon(); | 151 INHERITED::onAbandon(); |
| 154 } | 152 } |
| OLD | NEW |