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

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

Issue 1643143002: Generate Signed Distance Field directly from vector path (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Temporary use legacy distance field Created 3 years, 11 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/GrDistanceFieldGenFromVector.cpp ('k') | src/gpu/text/GrAtlasGlyphCache.cpp » ('j') | 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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * Copyright 2017 ARM Ltd.
3 * 4 *
4 * 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
5 * found in the LICENSE file. 6 * found in the LICENSE file.
6 */ 7 */
7 8
8 #include "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
9 10
10 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
11 #include "GrBuffer.h" 12 #include "GrBuffer.h"
12 #include "GrContext.h" 13 #include "GrContext.h"
13 #include "GrOpFlushState.h" 14 #include "GrOpFlushState.h"
14 #include "GrPipelineBuilder.h" 15 #include "GrPipelineBuilder.h"
15 #include "GrResourceProvider.h" 16 #include "GrResourceProvider.h"
16 #include "GrSWMaskHelper.h" 17 #include "GrSWMaskHelper.h"
17 #include "GrSurfacePriv.h" 18 #include "GrSurfacePriv.h"
18 #include "GrTexturePriv.h" 19 #include "GrTexturePriv.h"
19 #include "effects/GrDistanceFieldGeoProc.h" 20 #include "effects/GrDistanceFieldGeoProc.h"
20 #include "ops/GrMeshDrawOp.h" 21 #include "ops/GrMeshDrawOp.h"
21 22
23 #include "SkPathOps.h"
22 #include "SkDistanceFieldGen.h" 24 #include "SkDistanceFieldGen.h"
25 #include "GrDistanceFieldGenFromVector.h"
23 26
24 #define ATLAS_TEXTURE_WIDTH 2048 27 #define ATLAS_TEXTURE_WIDTH 2048
25 #define ATLAS_TEXTURE_HEIGHT 2048 28 #define ATLAS_TEXTURE_HEIGHT 2048
26 #define PLOT_WIDTH 512 29 #define PLOT_WIDTH 512
27 #define PLOT_HEIGHT 256 30 #define PLOT_HEIGHT 256
28 31
29 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH) 32 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH)
30 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT) 33 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT)
31 34
32 #ifdef DF_PATH_TRACKING 35 #ifdef DF_PATH_TRACKING
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // place devBounds at origin 331 // place devBounds at origin
329 int width = devPathBounds.width() + 2*intPad; 332 int width = devPathBounds.width() + 2*intPad;
330 int height = devPathBounds.height() + 2*intPad; 333 int height = devPathBounds.height() + 2*intPad;
331 devPathBounds = SkIRect::MakeWH(width, height); 334 devPathBounds = SkIRect::MakeWH(width, height);
332 335
333 // draw path to bitmap 336 // draw path to bitmap
334 SkMatrix drawMatrix; 337 SkMatrix drawMatrix;
335 drawMatrix.setScale(scale, scale); 338 drawMatrix.setScale(scale, scale);
336 drawMatrix.postTranslate(intPad - dx, intPad - dy); 339 drawMatrix.postTranslate(intPad - dx, intPad - dy);
337 340
338 // setup bitmap backing
339 SkASSERT(devPathBounds.fLeft == 0); 341 SkASSERT(devPathBounds.fLeft == 0);
340 SkASSERT(devPathBounds.fTop == 0); 342 SkASSERT(devPathBounds.fTop == 0);
341 SkAutoPixmapStorage dst;
342 if (!dst.tryAlloc(SkImageInfo::MakeA8(devPathBounds.width(),
343 devPathBounds.height()))) {
344 return false;
345 }
346 sk_bzero(dst.writable_addr(), dst.getSafeSize());
347 343
348 // rasterize path 344 // setup signed distance field storage
349 SkPaint paint; 345 SkIRect dfBounds = devPathBounds.makeOutset(SK_DistanceFieldPad, SK_Dist anceFieldPad);
350 paint.setStyle(SkPaint::kFill_Style); 346 width = dfBounds.width();
351 paint.setAntiAlias(true); 347 height = dfBounds.height();
352 348 // TODO We should really generate this directly into the plot somehow
353 SkDraw draw; 349 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char));
354 sk_bzero(&draw, sizeof(draw));
355
356 SkRasterClip rasterClip;
357 rasterClip.setRect(devPathBounds);
358 draw.fRC = &rasterClip;
359 draw.fMatrix = &drawMatrix;
360 draw.fDst = dst;
361 350
362 SkPath path; 351 SkPath path;
363 shape.asPath(&path); 352 shape.asPath(&path);
364 draw.drawPathCoverage(path, paint); 353 #ifndef SK_USE_LEGACY_DISTANCE_FIELDS
354 // Generate signed distance field directly from SkPath
355 bool succeed = GrGenerateDistanceFieldFromPath((unsigned char*)dfStorage .get(),
356 path, drawMatrix,
357 width, height, width * sizeof(unsigned c har));
358 if (!succeed) {
359 #endif
360 // setup bitmap backing
361 SkAutoPixmapStorage dst;
362 if (!dst.tryAlloc(SkImageInfo::MakeA8(devPathBounds.width(),
363 devPathBounds.height()))) {
364 return false;
365 }
366 sk_bzero(dst.writable_addr(), dst.getSafeSize());
365 367
366 // generate signed distance field 368 // rasterize path
367 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad); 369 SkPaint paint;
368 width = devPathBounds.width(); 370 paint.setStyle(SkPaint::kFill_Style);
369 height = devPathBounds.height(); 371 paint.setAntiAlias(true);
370 // TODO We should really generate this directly into the plot somehow
371 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char));
372 372
373 // Generate signed distance field 373 SkDraw draw;
374 SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), 374 sk_bzero(&draw, sizeof(draw));
375 (const unsigned char*)dst.addr(), 375
376 dst.width(), dst.height(), dst.rowByt es()); 376 SkRasterClip rasterClip;
377 rasterClip.setRect(devPathBounds);
378 draw.fRC = &rasterClip;
379 draw.fMatrix = &drawMatrix;
380 draw.fDst = dst;
381
382 draw.drawPathCoverage(path, paint);
383
384 // Generate signed distance field
385 SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(),
386 (const unsigned char*)dst.addr(),
387 dst.width(), dst.height(), dst.ro wBytes());
388 #ifndef SK_USE_LEGACY_DISTANCE_FIELDS
389 }
390 #endif
377 391
378 // add to atlas 392 // add to atlas
379 SkIPoint16 atlasLocation; 393 SkIPoint16 atlasLocation;
380 GrDrawOpAtlas::AtlasID id; 394 GrDrawOpAtlas::AtlasID id;
381 if (!atlas->addToAtlas(&id, target, width, height, dfStorage.get(), &atl asLocation)) { 395 if (!atlas->addToAtlas(&id, target, width, height, dfStorage.get(), &atl asLocation)) {
382 this->flush(target, flushInfo); 396 this->flush(target, flushInfo);
383 if (!atlas->addToAtlas(&id, target, width, height, dfStorage.get(), &atlasLocation)) { 397 if (!atlas->addToAtlas(&id, target, width, height, dfStorage.get(), &atlasLocation)) {
384 return false; 398 return false;
385 } 399 }
386 } 400 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 shape, 620 shape,
607 viewMatrix, 621 viewMatrix,
608 gTestStruct.fAtlas.get(), 622 gTestStruct.fAtlas.get(),
609 &gTestStruct.fShapeCache, 623 &gTestStruct.fShapeCache,
610 &gTestStruct.fShapeList, 624 &gTestStruct.fShapeList,
611 gammaCorrect) 625 gammaCorrect)
612 .release(); 626 .release();
613 } 627 }
614 628
615 #endif 629 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldGenFromVector.cpp ('k') | src/gpu/text/GrAtlasGlyphCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698