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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap); | 74 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap); |
75 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); | 75 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap); |
76 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); | 76 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap); |
77 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); | 77 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount); |
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 size_t 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 GrGLPathRendering* pr = gpu->pathRendering(); | 88 GrGLPathRendering* pr = gpu->pathRendering(); |
89 SkSTArray<16, GrGLubyte, true> pathCommands; | 89 SkSTArray<16, GrGLubyte, true> pathCommands; |
90 SkSTArray<16, SkPoint, true> pathPoints; | 90 SkSTArray<16, SkPoint, true> pathPoints; |
91 | 91 |
92 int verbCnt = skPath.countVerbs(); | 92 int verbCnt = skPath.countVerbs(); |
93 int pointCnt = skPath.countPoints(); | 93 int pointCnt = skPath.countPoints(); |
94 pathCommands.resize_back(verbCnt); | 94 pathCommands.resize_back(verbCnt); |
95 pathPoints.resize_back(pointCnt); | 95 pathPoints.resize_back(pointCnt); |
96 | 96 |
97 // 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. |
(...skipping 12 matching lines...) Expand all Loading... |
110 if (stroke.needToApply()) { | 110 if (stroke.needToApply()) { |
111 SkASSERT(!stroke.isHairlineStyle()); | 111 SkASSERT(!stroke.isHairlineStyle()); |
112 pr->pathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro
ke.getWidth())); | 112 pr->pathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro
ke.getWidth())); |
113 pr->pathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok
e.getMiter())); | 113 pr->pathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok
e.getMiter())); |
114 GrGLenum join = join_to_gl_join(stroke.getJoin()); | 114 GrGLenum join = join_to_gl_join(stroke.getJoin()); |
115 pr->pathParameteri(pathID, GR_GL_PATH_JOIN_STYLE, join); | 115 pr->pathParameteri(pathID, GR_GL_PATH_JOIN_STYLE, join); |
116 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); | 116 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); |
117 pr->pathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap); | 117 pr->pathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap); |
118 pr->pathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap); | 118 pr->pathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap); |
119 } | 119 } |
| 120 |
| 121 size_t approximateSize = 5 * (verbCnt + pointCnt); |
| 122 if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) { |
| 123 // It will take approxoimately twice the memory if it has both fill *and
* stroke. |
| 124 approximateSize *= 2; |
| 125 } |
| 126 return approximateSize; |
120 } | 127 } |
121 | 128 |
122 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) | 129 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke) |
123 : INHERITED(gpu, kIsWrapped, path, stroke), | 130 : INHERITED(gpu, kIsWrapped, path, stroke), |
124 fPathID(gpu->pathRendering()->genPaths(1)) { | 131 fPathID(gpu->pathRendering()->genPaths(1)) { |
125 SkASSERT(!path.isEmpty()); | 132 SkASSERT(!path.isEmpty()); |
126 | 133 |
127 InitPathObject(gpu, fPathID, fSkPath, stroke); | 134 fGpuMemorySize = InitPathObject(gpu, fPathID, fSkPath, stroke); |
128 | 135 |
129 if (stroke.needToApply()) { | 136 if (stroke.needToApply()) { |
130 // FIXME: try to account for stroking, without rasterizing the stroke. | 137 // FIXME: try to account for stroking, without rasterizing the stroke. |
131 fBounds.outset(stroke.getWidth(), stroke.getWidth()); | 138 fBounds.outset(stroke.getWidth(), stroke.getWidth()); |
132 } | 139 } |
133 } | 140 } |
134 | 141 |
135 GrGLPath::~GrGLPath() { | 142 GrGLPath::~GrGLPath() { |
136 this->release(); | 143 this->release(); |
137 } | 144 } |
138 | 145 |
139 void GrGLPath::onRelease() { | 146 void GrGLPath::onRelease() { |
140 if (0 != fPathID && !this->isWrapped()) { | 147 if (0 != fPathID && !this->isWrapped()) { |
141 static_cast<GrGpuGL*>(this->getGpu())->pathRendering()->deletePaths(fPat
hID, 1); | 148 static_cast<GrGpuGL*>(this->getGpu())->pathRendering()->deletePaths(fPat
hID, 1); |
142 fPathID = 0; | 149 fPathID = 0; |
143 } | 150 } |
144 | 151 |
145 INHERITED::onRelease(); | 152 INHERITED::onRelease(); |
146 } | 153 } |
147 | 154 |
148 void GrGLPath::onAbandon() { | 155 void GrGLPath::onAbandon() { |
149 fPathID = 0; | 156 fPathID = 0; |
150 | 157 |
151 INHERITED::onAbandon(); | 158 INHERITED::onAbandon(); |
152 } | 159 } |
OLD | NEW |