Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: src/gpu/GrAADistanceFieldPathRenderer.cpp

Issue 919693003: remove goto in Distance field path renderer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 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 "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
10 10
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 143 }
144 } 144 }
145 145
146 // use signed distance field to render 146 // use signed distance field to render
147 return this->internalDrawPath(target, pipelineBuilder, color, viewMatrix, pa th, pathData); 147 return this->internalDrawPath(target, pipelineBuilder, color, viewMatrix, pa th, pathData);
148 } 148 }
149 149
150 // padding around path bounds to allow for antialiased pixels 150 // padding around path bounds to allow for antialiased pixels
151 const SkScalar kAntiAliasPad = 1.0f; 151 const SkScalar kAntiAliasPad = 1.0f;
152 152
153 inline bool GrAADistanceFieldPathRenderer::uploadPath(GrPlot** plot, SkIPoint16* atlasLocation,
154 int width, int height, voi d* dfStorage) {
155 *plot = fAtlas->addToAtlas(&fPlotUsage, width, height, dfStorage, atlasLocat ion);
156
157 // if atlas full
158 if (NULL == *plot) {
159 if (this->freeUnusedPlot()) {
160 *plot = fAtlas->addToAtlas(&fPlotUsage, width, height, dfStorage, at lasLocation);
161 if (*plot) {
162 return true;
163 }
164 }
165
166 if (c_DumpPathCache) {
167 #ifdef SK_DEVELOPER
168 GrTexture* texture = fAtlas->getTexture();
169 texture->surfacePriv().savePixels("pathcache.png");
170 #endif
171 }
172
173 // before we purge the cache, we must flush any accumulated draws
174 fContext->flush();
175
176 if (this->freeUnusedPlot()) {
177 *plot = fAtlas->addToAtlas(&fPlotUsage, width, height, dfStorage, at lasLocation);
178 if (*plot) {
179 return true;
180 }
181 }
182 return false;
183 }
184 return true;
185 }
186
153 GrAADistanceFieldPathRenderer::PathData* GrAADistanceFieldPathRenderer::addPathT oAtlas( 187 GrAADistanceFieldPathRenderer::PathData* GrAADistanceFieldPathRenderer::addPathT oAtlas(
154 const Sk Path& path, 188 const Sk Path& path,
155 const Sk StrokeRec& stroke, 189 const Sk StrokeRec& stroke,
156 bool ant iAlias, 190 bool ant iAlias,
157 uint32_t dimension, 191 uint32_t dimension,
158 SkScalar scale) { 192 SkScalar scale) {
159 193
160 // generate distance field and add to atlas 194 // generate distance field and add to atlas
161 if (NULL == fAtlas) { 195 if (NULL == fAtlas) {
162 SkISize textureSize = SkISize::Make(ATLAS_TEXTURE_WIDTH, ATLAS_TEXTURE_H EIGHT); 196 SkISize textureSize = SkISize::Make(ATLAS_TEXTURE_WIDTH, ATLAS_TEXTURE_H EIGHT);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); 236 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF);
203 237
204 // generate signed distance field 238 // generate signed distance field
205 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad); 239 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad);
206 int width = devPathBounds.width(); 240 int width = devPathBounds.width();
207 int height = devPathBounds.height(); 241 int height = devPathBounds.height();
208 SkAutoSMalloc<1024> dfStorage(width*height*sizeof(unsigned char)); 242 SkAutoSMalloc<1024> dfStorage(width*height*sizeof(unsigned char));
209 helper.toSDF((unsigned char*) dfStorage.get()); 243 helper.toSDF((unsigned char*) dfStorage.get());
210 244
211 // add to atlas 245 // add to atlas
246 GrPlot* plot;
212 SkIPoint16 atlasLocation; 247 SkIPoint16 atlasLocation;
213 GrPlot* plot = fAtlas->addToAtlas(&fPlotUsage, width, height, dfStorage.get( ), 248 if (!this->uploadPath(&plot, &atlasLocation, width, height, dfStorage.get()) ) {
jvanverth1 2015/02/11 18:14:20 I think this should be okay -- but I would test on
214 &atlasLocation);
215
216 // if atlas full
217 if (NULL == plot) {
218 if (this->freeUnusedPlot()) {
219 plot = fAtlas->addToAtlas(&fPlotUsage, width, height, dfStorage.get( ),
220 &atlasLocation);
221 if (plot) {
222 goto HAS_ATLAS;
223 }
224 }
225
226 if (c_DumpPathCache) {
227 #ifdef SK_DEVELOPER
228 GrTexture* texture = fAtlas->getTexture();
229 texture->surfacePriv().savePixels("pathcache.png");
230 #endif
231 }
232
233 // before we purge the cache, we must flush any accumulated draws
234 fContext->flush();
235
236 if (this->freeUnusedPlot()) {
237 plot = fAtlas->addToAtlas(&fPlotUsage, width, height, dfStorage.get( ),
238 &atlasLocation);
239 if (plot) {
240 goto HAS_ATLAS;
241 }
242 }
243
244 return NULL; 249 return NULL;
245 } 250 }
246 251
247 HAS_ATLAS:
248 // add to cache 252 // add to cache
249 PathData* pathData = SkNEW(PathData); 253 PathData* pathData = SkNEW(PathData);
250 pathData->fKey.fGenID = path.getGenerationID(); 254 pathData->fKey.fGenID = path.getGenerationID();
251 pathData->fKey.fDimension = dimension; 255 pathData->fKey.fDimension = dimension;
252 pathData->fScale = scale; 256 pathData->fScale = scale;
253 pathData->fPlot = plot; 257 pathData->fPlot = plot;
254 // change the scaled rect to match the size of the inset distance field 258 // change the scaled rect to match the size of the inset distance field
255 scaledBounds.fRight = scaledBounds.fLeft + 259 scaledBounds.fRight = scaledBounds.fLeft +
256 SkIntToScalar(devPathBounds.width() - 2*SK_DistanceFieldInset); 260 SkIntToScalar(devPathBounds.width() - 2*SK_DistanceFieldInset);
257 scaledBounds.fBottom = scaledBounds.fTop + 261 scaledBounds.fBottom = scaledBounds.fTop +
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 378
375 viewMatrix.mapRect(&r); 379 viewMatrix.mapRect(&r);
376 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 380 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
377 target->drawIndexedInstances(pipelineBuilder, fCachedGeometryProcessor.get() , 381 target->drawIndexedInstances(pipelineBuilder, fCachedGeometryProcessor.get() ,
378 kTriangles_GrPrimitiveType, 1, 4, 6, &r); 382 kTriangles_GrPrimitiveType, 1, 4, 6, &r);
379 target->resetVertexSource(); 383 target->resetVertexSource();
380 384
381 return true; 385 return true;
382 } 386 }
383 387
OLDNEW
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698