| 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; |
| 358 const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(pathBounds.fRight, | 358 if (!dst.tryAlloc(SkImageInfo::MakeA8(pathBounds.width(), |
| 359 pathBounds.fBottom); | 359 pathBounds.height()))) { |
| 360 if (!bmp.tryAllocPixels(bmImageInfo)) { | |
| 361 return false; | 360 return false; |
| 362 } | 361 } |
| 363 | 362 sk_bzero(dst.writable_addr(), dst.getSafeSize()); |
| 364 sk_bzero(bmp.getPixels(), bmp.getSafeSize()); | |
| 365 | 363 |
| 366 // rasterize path | 364 // rasterize path |
| 367 SkPaint paint; | 365 SkPaint paint; |
| 368 if (stroke.isHairlineStyle()) { | 366 if (stroke.isHairlineStyle()) { |
| 369 paint.setStyle(SkPaint::kStroke_Style); | 367 paint.setStyle(SkPaint::kStroke_Style); |
| 370 paint.setStrokeWidth(SK_Scalar1); | 368 paint.setStrokeWidth(SK_Scalar1); |
| 371 } else { | 369 } else { |
| 372 if (stroke.isFillStyle()) { | 370 if (stroke.isFillStyle()) { |
| 373 paint.setStyle(SkPaint::kFill_Style); | 371 paint.setStyle(SkPaint::kFill_Style); |
| 374 } else { | 372 } else { |
| 375 paint.setStyle(SkPaint::kStroke_Style); | 373 paint.setStyle(SkPaint::kStroke_Style); |
| 376 paint.setStrokeJoin(stroke.getJoin()); | 374 paint.setStrokeJoin(stroke.getJoin()); |
| 377 paint.setStrokeCap(stroke.getCap()); | 375 paint.setStrokeCap(stroke.getCap()); |
| 378 paint.setStrokeWidth(stroke.getWidth()); | 376 paint.setStrokeWidth(stroke.getWidth()); |
| 379 } | 377 } |
| 380 } | 378 } |
| 381 paint.setAntiAlias(antiAlias); | 379 paint.setAntiAlias(antiAlias); |
| 382 | 380 |
| 383 SkDraw draw; | 381 SkDraw draw; |
| 384 sk_bzero(&draw, sizeof(draw)); | 382 sk_bzero(&draw, sizeof(draw)); |
| 385 | 383 |
| 386 SkRasterClip rasterClip; | 384 SkRasterClip rasterClip; |
| 387 rasterClip.setRect(pathBounds); | 385 rasterClip.setRect(pathBounds); |
| 388 draw.fRC = &rasterClip; | 386 draw.fRC = &rasterClip; |
| 389 draw.fClip = &rasterClip.bwRgn(); | 387 draw.fClip = &rasterClip.bwRgn(); |
| 390 draw.fMatrix = &drawMatrix; | 388 draw.fMatrix = &drawMatrix; |
| 391 draw.fBitmap = &bmp; | 389 draw.fDst = dst; |
| 392 | 390 |
| 393 draw.drawPathCoverage(path, paint); | 391 draw.drawPathCoverage(path, paint); |
| 394 | 392 |
| 395 // generate signed distance field | 393 // generate signed distance field |
| 396 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad); | 394 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad); |
| 397 int width = devPathBounds.width(); | 395 int width = devPathBounds.width(); |
| 398 int height = devPathBounds.height(); | 396 int height = devPathBounds.height(); |
| 399 // TODO We should really generate this directly into the plot somehow | 397 // TODO We should really generate this directly into the plot somehow |
| 400 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); | 398 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); |
| 401 | 399 |
| 402 // Generate signed distance field | 400 // Generate signed distance field |
| 403 { | 401 SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), |
| 404 SkAutoLockPixels alp(bmp); | 402 (const unsigned char*)dst.addr(), |
| 405 | 403 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 | 404 |
| 411 // add to atlas | 405 // add to atlas |
| 412 SkIPoint16 atlasLocation; | 406 SkIPoint16 atlasLocation; |
| 413 GrBatchAtlas::AtlasID id; | 407 GrBatchAtlas::AtlasID id; |
| 414 bool success = atlas->addToAtlas(&id, batchTarget, width, height, dfStor
age.get(), | 408 bool success = atlas->addToAtlas(&id, batchTarget, width, height, dfStor
age.get(), |
| 415 &atlasLocation); | 409 &atlasLocation); |
| 416 if (!success) { | 410 if (!success) { |
| 417 this->flush(batchTarget, flushInfo); | 411 this->flush(batchTarget, flushInfo); |
| 418 batchTarget->initDraw(dfProcessor, pipeline); | 412 batchTarget->initDraw(dfProcessor, pipeline); |
| 419 | 413 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 geometry.fPath = GrTest::TestPath(random); | 652 geometry.fPath = GrTest::TestPath(random); |
| 659 geometry.fAntiAlias = random->nextBool(); | 653 geometry.fAntiAlias = random->nextBool(); |
| 660 | 654 |
| 661 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, | 655 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, |
| 662 gTestStruct.fAtlas, | 656 gTestStruct.fAtlas, |
| 663 &gTestStruct.fPathCache, | 657 &gTestStruct.fPathCache, |
| 664 &gTestStruct.fPathList); | 658 &gTestStruct.fPathList); |
| 665 } | 659 } |
| 666 | 660 |
| 667 #endif | 661 #endif |
| OLD | NEW |