OLD | NEW |
---|---|
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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 drawMatrix.postScale(scale, scale); | 347 drawMatrix.postScale(scale, scale); |
348 drawMatrix.postTranslate(kAntiAliasPad, kAntiAliasPad); | 348 drawMatrix.postTranslate(kAntiAliasPad, kAntiAliasPad); |
349 | 349 |
350 // setup bitmap backing | 350 // setup bitmap backing |
351 // Now translate so the bound's UL corner is at the origin | 351 // Now translate so the bound's UL corner is at the origin |
352 drawMatrix.postTranslate(-devPathBounds.fLeft * SK_Scalar1, | 352 drawMatrix.postTranslate(-devPathBounds.fLeft * SK_Scalar1, |
353 -devPathBounds.fTop * SK_Scalar1); | 353 -devPathBounds.fTop * SK_Scalar1); |
354 SkIRect pathBounds = SkIRect::MakeWH(devPathBounds.width(), | 354 SkIRect pathBounds = SkIRect::MakeWH(devPathBounds.width(), |
355 devPathBounds.height()); | 355 devPathBounds.height()); |
356 | 356 |
357 SkBitmap bmp; | 357 SkAutoPixmapStorage dst; |
jvanverth1
2015/06/08 13:21:10
It's unclear to me why this should be a SkAutoPixm
reed1
2015/06/08 17:00:22
Just me being lazy. Now helper also uses pixmaps
| |
358 const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(pathBounds.fRight, | 358 // reed: should these be width/height instead of right/bottom? |
jvanverth1
2015/06/08 13:21:10
I think it's safe the way it is, though admittedly
reed1
2015/06/08 17:00:22
Hmmm, I could add asserts, but its starting to fee
| |
359 pathBounds.fBottom); | 359 const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(pathBounds.fRight, p athBounds.fBottom); |
360 if (!bmp.tryAllocPixels(bmImageInfo)) { | 360 if (!dst.tryAlloc(bmImageInfo)) { |
jvanverth1
2015/06/08 13:21:10
Change variable name to pmImageInfo?
reed1
2015/06/08 17:00:22
removed local var
| |
361 return false; | 361 return false; |
362 } | 362 } |
363 | 363 sk_bzero(dst.writable_addr(), dst.getSafeSize()); |
364 sk_bzero(bmp.getPixels(), bmp.getSafeSize()); | |
365 | 364 |
366 // rasterize path | 365 // rasterize path |
367 SkPaint paint; | 366 SkPaint paint; |
368 if (stroke.isHairlineStyle()) { | 367 if (stroke.isHairlineStyle()) { |
369 paint.setStyle(SkPaint::kStroke_Style); | 368 paint.setStyle(SkPaint::kStroke_Style); |
370 paint.setStrokeWidth(SK_Scalar1); | 369 paint.setStrokeWidth(SK_Scalar1); |
371 } else { | 370 } else { |
372 if (stroke.isFillStyle()) { | 371 if (stroke.isFillStyle()) { |
373 paint.setStyle(SkPaint::kFill_Style); | 372 paint.setStyle(SkPaint::kFill_Style); |
374 } else { | 373 } else { |
375 paint.setStyle(SkPaint::kStroke_Style); | 374 paint.setStyle(SkPaint::kStroke_Style); |
376 paint.setStrokeJoin(stroke.getJoin()); | 375 paint.setStrokeJoin(stroke.getJoin()); |
377 paint.setStrokeCap(stroke.getCap()); | 376 paint.setStrokeCap(stroke.getCap()); |
378 paint.setStrokeWidth(stroke.getWidth()); | 377 paint.setStrokeWidth(stroke.getWidth()); |
379 } | 378 } |
380 } | 379 } |
381 paint.setAntiAlias(antiAlias); | 380 paint.setAntiAlias(antiAlias); |
382 | 381 |
383 SkDraw draw; | 382 SkDraw draw; |
384 sk_bzero(&draw, sizeof(draw)); | 383 sk_bzero(&draw, sizeof(draw)); |
385 | 384 |
386 SkRasterClip rasterClip; | 385 SkRasterClip rasterClip; |
387 rasterClip.setRect(pathBounds); | 386 rasterClip.setRect(pathBounds); |
388 draw.fRC = &rasterClip; | 387 draw.fRC = &rasterClip; |
389 draw.fClip = &rasterClip.bwRgn(); | 388 draw.fClip = &rasterClip.bwRgn(); |
390 draw.fMatrix = &drawMatrix; | 389 draw.fMatrix = &drawMatrix; |
391 draw.fBitmap = &bmp; | 390 draw.fDst = dst; |
392 | 391 |
393 draw.drawPathCoverage(path, paint); | 392 draw.drawPathCoverage(path, paint); |
394 | 393 |
395 // generate signed distance field | 394 // generate signed distance field |
396 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad); | 395 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad); |
397 int width = devPathBounds.width(); | 396 int width = devPathBounds.width(); |
398 int height = devPathBounds.height(); | 397 int height = devPathBounds.height(); |
399 // TODO We should really generate this directly into the plot somehow | 398 // TODO We should really generate this directly into the plot somehow |
400 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); | 399 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); |
401 | 400 |
402 // Generate signed distance field | 401 // Generate signed distance field |
403 { | 402 SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), |
404 SkAutoLockPixels alp(bmp); | 403 (const unsigned char*)dst.addr(), |
405 | 404 dst.width(), dst.height(), dst.rowByt es()); |
406 SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), | |
407 (const unsigned char*)bmp.getPixe ls(), | |
408 bmp.width(), bmp.height(), bmp.ro wBytes()); | |
409 } | |
410 | 405 |
411 // add to atlas | 406 // add to atlas |
412 SkIPoint16 atlasLocation; | 407 SkIPoint16 atlasLocation; |
413 GrBatchAtlas::AtlasID id; | 408 GrBatchAtlas::AtlasID id; |
414 bool success = atlas->addToAtlas(&id, batchTarget, width, height, dfStor age.get(), | 409 bool success = atlas->addToAtlas(&id, batchTarget, width, height, dfStor age.get(), |
415 &atlasLocation); | 410 &atlasLocation); |
416 if (!success) { | 411 if (!success) { |
417 this->flush(batchTarget, flushInfo); | 412 this->flush(batchTarget, flushInfo); |
418 batchTarget->initDraw(dfProcessor, pipeline); | 413 batchTarget->initDraw(dfProcessor, pipeline); |
419 | 414 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 geometry.fPath = GrTest::TestPath(random); | 653 geometry.fPath = GrTest::TestPath(random); |
659 geometry.fAntiAlias = random->nextBool(); | 654 geometry.fAntiAlias = random->nextBool(); |
660 | 655 |
661 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, | 656 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, |
662 gTestStruct.fAtlas, | 657 gTestStruct.fAtlas, |
663 &gTestStruct.fPathCache, | 658 &gTestStruct.fPathCache, |
664 &gTestStruct.fPathList); | 659 &gTestStruct.fPathList); |
665 } | 660 } |
666 | 661 |
667 #endif | 662 #endif |
OLD | NEW |