OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
13 #include "GrFontScaler.h" | 13 #include "GrFontScaler.h" |
14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
15 #include "GrGpuResourcePriv.h" | 15 #include "GrGpuResourcePriv.h" |
16 #include "GrLayerHoister.h" | 16 #include "GrLayerHoister.h" |
17 #include "GrRecordReplaceDraw.h" | 17 #include "GrRecordReplaceDraw.h" |
18 #include "GrStrokeInfo.h" | 18 #include "GrStrokeInfo.h" |
19 #include "GrTextContext.h" | 19 #include "GrTextContext.h" |
20 #include "GrTracing.h" | 20 #include "GrTracing.h" |
21 #include "SkCanvasPriv.h" | 21 #include "SkCanvasPriv.h" |
22 #include "SkDrawProcs.h" | 22 #include "SkDrawProcs.h" |
23 #include "SkErrorInternals.h" | 23 #include "SkErrorInternals.h" |
24 #include "SkGlyphCache.h" | 24 #include "SkGlyphCache.h" |
25 #include "SkGrTexturePixelRef.h" | 25 #include "SkGrTexturePixelRef.h" |
26 #include "SkGrPriv.h" | |
26 #include "SkImage_Base.h" | 27 #include "SkImage_Base.h" |
27 #include "SkImageFilter.h" | 28 #include "SkImageFilter.h" |
28 #include "SkLayerInfo.h" | 29 #include "SkLayerInfo.h" |
29 #include "SkMaskFilter.h" | 30 #include "SkMaskFilter.h" |
30 #include "SkPathEffect.h" | 31 #include "SkPathEffect.h" |
31 #include "SkPicture.h" | 32 #include "SkPicture.h" |
32 #include "SkPictureData.h" | 33 #include "SkPictureData.h" |
33 #include "SkRRect.h" | 34 #include "SkRRect.h" |
34 #include "SkRecord.h" | 35 #include "SkRecord.h" |
35 #include "SkStroke.h" | 36 #include "SkStroke.h" |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfacePr ops())); | 377 fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfacePr ops())); |
377 } | 378 } |
378 | 379 |
379 /////////////////////////////////////////////////////////////////////////////// | 380 /////////////////////////////////////////////////////////////////////////////// |
380 | 381 |
381 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 382 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
382 CHECK_SHOULD_DRAW(draw); | 383 CHECK_SHOULD_DRAW(draw); |
383 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); | 384 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
384 | 385 |
385 GrPaint grPaint; | 386 GrPaint grPaint; |
386 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { | 387 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
387 return; | 388 return; |
388 } | 389 } |
389 | 390 |
390 fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); | 391 fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); |
391 } | 392 } |
392 | 393 |
393 // must be in SkCanvas::PointMode order | 394 // must be in SkCanvas::PointMode order |
394 static const GrPrimitiveType gPointMode2PrimtiveType[] = { | 395 static const GrPrimitiveType gPointMode2PrimtiveType[] = { |
395 kPoints_GrPrimitiveType, | 396 kPoints_GrPrimitiveType, |
396 kLines_GrPrimitiveType, | 397 kLines_GrPrimitiveType, |
(...skipping 28 matching lines...) Expand all Loading... | |
425 CHECK_SHOULD_DRAW(draw); | 426 CHECK_SHOULD_DRAW(draw); |
426 | 427 |
427 SkScalar width = paint.getStrokeWidth(); | 428 SkScalar width = paint.getStrokeWidth(); |
428 if (width < 0) { | 429 if (width < 0) { |
429 return; | 430 return; |
430 } | 431 } |
431 | 432 |
432 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod e) { | 433 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod e) { |
433 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); | 434 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
434 GrPaint grPaint; | 435 GrPaint grPaint; |
435 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPai nt)) { | 436 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
436 return; | 437 return; |
437 } | 438 } |
438 SkPath path; | 439 SkPath path; |
439 path.setIsVolatile(true); | 440 path.setIsVolatile(true); |
440 path.moveTo(pts[0]); | 441 path.moveTo(pts[0]); |
441 path.lineTo(pts[1]); | 442 path.lineTo(pts[1]); |
442 fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, pat h, strokeInfo); | 443 fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, pat h, strokeInfo); |
443 return; | 444 return; |
444 } | 445 } |
445 | 446 |
446 // we only handle non-antialiased hairlines and paints without path effects or mask filters, | 447 // we only handle non-antialiased hairlines and paints without path effects or mask filters, |
447 // else we let the SkDraw call our drawPath() | 448 // else we let the SkDraw call our drawPath() |
448 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || | 449 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || |
449 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { | 450 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { |
450 draw.drawPoints(mode, count, pts, paint, true); | 451 draw.drawPoints(mode, count, pts, paint, true); |
451 return; | 452 return; |
452 } | 453 } |
453 | 454 |
454 GrPaint grPaint; | 455 GrPaint grPaint; |
455 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { | 456 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
456 return; | 457 return; |
457 } | 458 } |
458 | 459 |
459 fDrawContext->drawVertices(fRenderTarget, | 460 fDrawContext->drawVertices(fRenderTarget, |
460 fClip, | 461 fClip, |
461 grPaint, | 462 grPaint, |
462 *draw.fMatrix, | 463 *draw.fMatrix, |
463 gPointMode2PrimtiveType[mode], | 464 gPointMode2PrimtiveType[mode], |
464 SkToS32(count), | 465 SkToS32(count), |
465 (SkPoint*)pts, | 466 (SkPoint*)pts, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 | 509 |
509 if (usePath) { | 510 if (usePath) { |
510 SkPath path; | 511 SkPath path; |
511 path.setIsVolatile(true); | 512 path.setIsVolatile(true); |
512 path.addRect(rect); | 513 path.addRect(rect); |
513 this->drawPath(draw, path, paint, nullptr, true); | 514 this->drawPath(draw, path, paint, nullptr, true); |
514 return; | 515 return; |
515 } | 516 } |
516 | 517 |
517 GrPaint grPaint; | 518 GrPaint grPaint; |
518 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { | 519 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
519 return; | 520 return; |
520 } | 521 } |
521 | 522 |
522 fDrawContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, & strokeInfo); | 523 fDrawContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, & strokeInfo); |
523 } | 524 } |
524 | 525 |
525 /////////////////////////////////////////////////////////////////////////////// | 526 /////////////////////////////////////////////////////////////////////////////// |
526 | 527 |
527 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 528 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
528 const SkPaint& paint) { | 529 const SkPaint& paint) { |
529 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext); | 530 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext); |
530 CHECK_FOR_ANNOTATION(paint); | 531 CHECK_FOR_ANNOTATION(paint); |
531 CHECK_SHOULD_DRAW(draw); | 532 CHECK_SHOULD_DRAW(draw); |
532 | 533 |
533 GrPaint grPaint; | 534 GrPaint grPaint; |
534 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { | 535 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
535 return; | 536 return; |
536 } | 537 } |
537 | 538 |
538 GrStrokeInfo strokeInfo(paint); | 539 GrStrokeInfo strokeInfo(paint); |
539 if (paint.getMaskFilter()) { | 540 if (paint.getMaskFilter()) { |
540 // try to hit the fast path for drawing filtered round rects | 541 // try to hit the fast path for drawing filtered round rects |
541 | 542 |
542 SkRRect devRRect; | 543 SkRRect devRRect; |
543 if (rect.transform(*draw.fMatrix, &devRRect)) { | 544 if (rect.transform(*draw.fMatrix, &devRRect)) { |
544 if (devRRect.allCornersCircular()) { | 545 if (devRRect.allCornersCircular()) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 | 596 |
596 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 597 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
597 const SkRRect& inner, const SkPaint& paint) { | 598 const SkRRect& inner, const SkPaint& paint) { |
598 SkStrokeRec stroke(paint); | 599 SkStrokeRec stroke(paint); |
599 if (stroke.isFillStyle()) { | 600 if (stroke.isFillStyle()) { |
600 | 601 |
601 CHECK_FOR_ANNOTATION(paint); | 602 CHECK_FOR_ANNOTATION(paint); |
602 CHECK_SHOULD_DRAW(draw); | 603 CHECK_SHOULD_DRAW(draw); |
603 | 604 |
604 GrPaint grPaint; | 605 GrPaint grPaint; |
605 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPai nt)) { | 606 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
606 return; | 607 return; |
607 } | 608 } |
608 | 609 |
609 if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect() ) { | 610 if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect() ) { |
610 fDrawContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatri x, outer, inner); | 611 fDrawContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatri x, outer, inner); |
611 return; | 612 return; |
612 } | 613 } |
613 } | 614 } |
614 | 615 |
615 SkPath path; | 616 SkPath path; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 | 648 |
648 if (usePath) { | 649 if (usePath) { |
649 SkPath path; | 650 SkPath path; |
650 path.setIsVolatile(true); | 651 path.setIsVolatile(true); |
651 path.addOval(oval); | 652 path.addOval(oval); |
652 this->drawPath(draw, path, paint, nullptr, true); | 653 this->drawPath(draw, path, paint, nullptr, true); |
653 return; | 654 return; |
654 } | 655 } |
655 | 656 |
656 GrPaint grPaint; | 657 GrPaint grPaint; |
657 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { | 658 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
658 return; | 659 return; |
659 } | 660 } |
660 | 661 |
661 fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, s trokeInfo); | 662 fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, s trokeInfo); |
662 } | 663 } |
663 | 664 |
664 #include "SkMaskFilter.h" | 665 #include "SkMaskFilter.h" |
665 | 666 |
666 /////////////////////////////////////////////////////////////////////////////// | 667 /////////////////////////////////////////////////////////////////////////////// |
667 | 668 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
984 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr , ¶ms)); | 985 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr , ¶ms)); |
985 | 986 |
986 if (!texture) { | 987 if (!texture) { |
987 SkErrorInternals::SetError(kInternalError_SkError, | 988 SkErrorInternals::SetError(kInternalError_SkError, |
988 "Couldn't convert bitmap to texture."); | 989 "Couldn't convert bitmap to texture."); |
989 return; | 990 return; |
990 } | 991 } |
991 | 992 |
992 // Setup paint | 993 // Setup paint |
993 GrColor paintColor = (kAlpha_8_SkColorType == bitmapPtr->colorType()) ? | 994 GrColor paintColor = (kAlpha_8_SkColorType == bitmapPtr->colorType()) ? |
994 SkColor2GrColor(paint.getColor()) : | 995 SkColorToPremulGrColor(paint.getColor()) : |
995 SkColor2GrColorJustAlpha(paint.getColor()); | 996 SkColorAlphaToGrColor(paint.getColor()); |
996 | 997 |
997 GrPaint grPaint; | 998 GrPaint grPaint; |
998 | 999 |
999 // Create and insert texture effect | 1000 // Create and insert texture effect |
1000 SkAutoTUnref<const GrFragmentProcessor> fp; | 1001 SkAutoTUnref<const GrFragmentProcessor> fp; |
1001 if (doBicubic) { | 1002 if (doBicubic) { |
1002 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure, | 1003 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure, |
1003 SkMatrix::I(), | 1004 SkMatrix::I(), |
1004 tm)); | 1005 tm)); |
1005 } else { | 1006 } else { |
1006 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture, | 1007 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture, |
1007 SkMatrix::I(), params)); | 1008 SkMatrix::I(), params)); |
1008 } | 1009 } |
1009 | 1010 |
1010 // The bitmap read has to be first | 1011 if (!SkPaintToGrPaintReplaceShader(context, paint, fp, &grPaint)) { |
1011 grPaint.addColorFragmentProcessor(fp); | |
1012 if (!SkPaint2GrPaintNoShader(context, paint, SkColor2GrColor(paint.getColor( )), false, | |
1013 &grPaint)) { | |
1014 return; | 1012 return; |
1015 } | 1013 } |
1016 | 1014 |
1017 grPaint.setColor(paintColor); | 1015 grPaint.setColor(paintColor); |
egdaniel
2015/09/25 20:01:55
something seems weird about the SkToGr setting the
bsalomon
2015/09/25 20:45:07
overlooked deleting this.
| |
1018 | 1016 |
1019 // Setup dst rect and final matrix | 1017 // Setup dst rect and final matrix |
1020 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; | 1018 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; |
1021 | 1019 |
1022 SkRect devRect; | 1020 SkRect devRect; |
1023 viewMatrix.mapRect(&devRect, dstRect); | 1021 viewMatrix.mapRect(&devRect, dstRect); |
1024 | 1022 |
1025 SkMatrix matrix; | 1023 SkMatrix matrix; |
1026 matrix.setIDiv(bitmapPtr->width(), bitmapPtr->height()); | 1024 matrix.setIDiv(bitmapPtr->width(), bitmapPtr->height()); |
1027 | 1025 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1304 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), | 1302 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
1305 SkScalarMul(srcRect.fTop, hInv), | 1303 SkScalarMul(srcRect.fTop, hInv), |
1306 SkScalarMul(srcRect.fRight, wInv), | 1304 SkScalarMul(srcRect.fRight, wInv), |
1307 SkScalarMul(srcRect.fBottom, hInv)); | 1305 SkScalarMul(srcRect.fBottom, hInv)); |
1308 | 1306 |
1309 SkRect textureDomain = SkRect::MakeEmpty(); | 1307 SkRect textureDomain = SkRect::MakeEmpty(); |
1310 | 1308 |
1311 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring | 1309 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
1312 // the rest from the SkPaint. | 1310 // the rest from the SkPaint. |
1313 GrPaint grPaint; | 1311 GrPaint grPaint; |
1314 SkAutoTUnref<GrFragmentProcessor> fp; | 1312 SkAutoTUnref<const GrFragmentProcessor> fp; |
1315 | 1313 |
1316 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) { | 1314 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) { |
1317 // Use a constrained texture domain to avoid color bleeding | 1315 // Use a constrained texture domain to avoid color bleeding |
1318 SkScalar left, top, right, bottom; | 1316 SkScalar left, top, right, bottom; |
1319 if (srcRect.width() > SK_Scalar1) { | 1317 if (srcRect.width() > SK_Scalar1) { |
1320 SkScalar border = SK_ScalarHalf / texture->width(); | 1318 SkScalar border = SK_ScalarHalf / texture->width(); |
1321 left = paintRect.left() + border; | 1319 left = paintRect.left() + border; |
1322 right = paintRect.right() - border; | 1320 right = paintRect.right() - border; |
1323 } else { | 1321 } else { |
1324 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); | 1322 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
(...skipping 20 matching lines...) Expand all Loading... | |
1345 } else if (bicubic) { | 1343 } else if (bicubic) { |
1346 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); | 1344 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
1347 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() }; | 1345 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() }; |
1348 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure, SkMatrix::I(), | 1346 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure, SkMatrix::I(), |
1349 tileModes)); | 1347 tileModes)); |
1350 } else { | 1348 } else { |
1351 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture, | 1349 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture, |
1352 SkMatrix::I(), params)); | 1350 SkMatrix::I(), params)); |
1353 } | 1351 } |
1354 | 1352 |
1355 grPaint.addColorFragmentProcessor(fp); | 1353 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); |
1356 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); | 1354 if (alphaOnly) { |
1357 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor() ) : | 1355 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); |
1358 SkColor2GrColor(paint.getColor()); | 1356 } else { |
1359 if (!SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grP aint)) { | 1357 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); |
1358 } | |
1359 | |
1360 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { | |
1360 return; | 1361 return; |
1361 } | 1362 } |
1362 | 1363 |
1363 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect, | 1364 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect, |
1364 paintRect); | 1365 paintRect); |
1365 } | 1366 } |
1366 | 1367 |
1367 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, | 1368 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, |
1368 int width, int height, | 1369 int width, int height, |
1369 const SkImageFilter* filter, | 1370 const SkImageFilter* filter, |
(...skipping 24 matching lines...) Expand all Loading... | |
1394 int w = bitmap.width(); | 1395 int w = bitmap.width(); |
1395 int h = bitmap.height(); | 1396 int h = bitmap.height(); |
1396 | 1397 |
1397 GrTexture* texture; | 1398 GrTexture* texture; |
1398 // draw sprite uses the default texture params | 1399 // draw sprite uses the default texture params |
1399 AutoBitmapTexture abt(fContext, bitmap, nullptr, &texture); | 1400 AutoBitmapTexture abt(fContext, bitmap, nullptr, &texture); |
1400 if (!texture) { | 1401 if (!texture) { |
1401 return; | 1402 return; |
1402 } | 1403 } |
1403 | 1404 |
1405 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); | |
1406 | |
1404 SkImageFilter* filter = paint.getImageFilter(); | 1407 SkImageFilter* filter = paint.getImageFilter(); |
1405 // This bitmap will own the filtered result as a texture. | 1408 // This bitmap will own the filtered result as a texture. |
1406 SkBitmap filteredBitmap; | 1409 SkBitmap filteredBitmap; |
1407 | 1410 |
1408 if (filter) { | 1411 if (filter) { |
1409 SkIPoint offset = SkIPoint::Make(0, 0); | 1412 SkIPoint offset = SkIPoint::Make(0, 0); |
1410 SkMatrix matrix(*draw.fMatrix); | 1413 SkMatrix matrix(*draw.fMatrix); |
1411 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); | 1414 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
1412 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); | 1415 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
1413 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); | 1416 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
1414 // This cache is transient, and is freed (along with all its contained | 1417 // This cache is transient, and is freed (along with all its contained |
1415 // textures) when it goes out of scope. | 1418 // textures) when it goes out of scope. |
1416 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1419 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
1417 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB itmap, | 1420 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB itmap, |
1418 &offset)) { | 1421 &offset)) { |
1419 texture = (GrTexture*) filteredBitmap.getTexture(); | 1422 texture = (GrTexture*) filteredBitmap.getTexture(); |
1420 w = filteredBitmap.width(); | 1423 w = filteredBitmap.width(); |
1421 h = filteredBitmap.height(); | 1424 h = filteredBitmap.height(); |
1422 left += offset.x(); | 1425 left += offset.x(); |
1423 top += offset.y(); | 1426 top += offset.y(); |
1424 } else { | 1427 } else { |
1425 return; | 1428 return; |
1426 } | 1429 } |
1430 SkASSERT(!GrPixelConfigIsAlphaOnly(texture->config())); | |
1431 alphaOnly = false; | |
1427 } | 1432 } |
1428 | 1433 |
1429 GrPaint grPaint; | 1434 GrPaint grPaint; |
1430 grPaint.addColorTextureProcessor(texture, SkMatrix::I()); | 1435 SkAutoTUnref<const GrFragmentProcessor> fp( |
1431 | 1436 GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager(), texture , SkMatrix::I())); |
1432 if (!SkPaint2GrPaintNoShader(this->context(), paint, | 1437 if (alphaOnly) { |
1433 SkColor2GrColorJustAlpha(paint.getColor()), fal se, &grPaint)) { | 1438 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); |
1439 } else { | |
1440 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | |
1441 } | |
1442 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { | |
1434 return; | 1443 return; |
1435 } | 1444 } |
1436 | 1445 |
1437 fDrawContext->drawNonAARectToRect(fRenderTarget, | 1446 fDrawContext->drawNonAARectToRect(fRenderTarget, |
1438 fClip, | 1447 fClip, |
1439 grPaint, | 1448 grPaint, |
1440 SkMatrix::I(), | 1449 SkMatrix::I(), |
1441 SkRect::MakeXYWH(SkIntToScalar(left), | 1450 SkRect::MakeXYWH(SkIntToScalar(left), |
1442 SkIntToScalar(top), | 1451 SkIntToScalar(top), |
1443 SkIntToScalar(w), | 1452 SkIntToScalar(w), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1535 w = filteredBitmap.width(); | 1544 w = filteredBitmap.width(); |
1536 h = filteredBitmap.height(); | 1545 h = filteredBitmap.height(); |
1537 x += offset.fX; | 1546 x += offset.fX; |
1538 y += offset.fY; | 1547 y += offset.fY; |
1539 } else { | 1548 } else { |
1540 return; | 1549 return; |
1541 } | 1550 } |
1542 } | 1551 } |
1543 | 1552 |
1544 GrPaint grPaint; | 1553 GrPaint grPaint; |
1545 grPaint.addColorTextureProcessor(devTex, SkMatrix::I()); | 1554 SkAutoTUnref<const GrFragmentProcessor> fp( |
1555 GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager(), devTex, SkMatrix::I())); | |
1556 if (GrPixelConfigIsAlphaOnly(devTex->config())) { | |
robertphillips
2015/09/25 19:52:17
I don't think so
bsalomon
2015/09/25 20:45:07
I thought we sometimes internally created A8 devic
| |
1557 // Can this happen? | |
1558 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | |
1559 } else { | |
1560 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | |
1561 } | |
1546 | 1562 |
1547 if (!SkPaint2GrPaintNoShader(this->context(), paint, | 1563 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { |
1548 SkColor2GrColorJustAlpha(paint.getColor()), fal se, &grPaint)) { | |
1549 return; | 1564 return; |
1550 } | 1565 } |
1551 | 1566 |
1552 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), | 1567 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
1553 SkIntToScalar(y), | 1568 SkIntToScalar(y), |
1554 SkIntToScalar(w), | 1569 SkIntToScalar(w), |
1555 SkIntToScalar(h)); | 1570 SkIntToScalar(h)); |
1556 | 1571 |
1557 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate | 1572 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate |
1558 // scratch texture). | 1573 // scratch texture). |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1659 | 1674 |
1660 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1675 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
1661 int vertexCount, const SkPoint vertices[], | 1676 int vertexCount, const SkPoint vertices[], |
1662 const SkPoint texs[], const SkColor colors[], | 1677 const SkPoint texs[], const SkColor colors[], |
1663 SkXfermode* xmode, | 1678 SkXfermode* xmode, |
1664 const uint16_t indices[], int indexCount, | 1679 const uint16_t indices[], int indexCount, |
1665 const SkPaint& paint) { | 1680 const SkPaint& paint) { |
1666 CHECK_SHOULD_DRAW(draw); | 1681 CHECK_SHOULD_DRAW(draw); |
1667 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); | 1682 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); |
1668 | 1683 |
1669 const uint16_t* outIndices; | |
1670 SkAutoTDeleteArray<uint16_t> outAlloc(nullptr); | |
1671 GrPrimitiveType primType; | |
1672 GrPaint grPaint; | |
1673 | |
1674 // If both textures and vertex-colors are nullptr, strokes hairlines with th e paint's color. | 1684 // If both textures and vertex-colors are nullptr, strokes hairlines with th e paint's color. |
1675 if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) { | 1685 if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) { |
1676 | 1686 |
1677 texs = nullptr; | 1687 texs = nullptr; |
1678 | 1688 |
1679 SkPaint copy(paint); | 1689 SkPaint copy(paint); |
1680 copy.setStyle(SkPaint::kStroke_Style); | 1690 copy.setStyle(SkPaint::kStroke_Style); |
1681 copy.setStrokeWidth(0); | 1691 copy.setStrokeWidth(0); |
1682 | 1692 |
1693 GrPaint grPaint; | |
1683 // we ignore the shader if texs is null. | 1694 // we ignore the shader if texs is null. |
1684 if (!SkPaint2GrPaintNoShader(this->context(), copy, | 1695 if (!SkPaintToGrPaintNoShader(this->context(), copy, &grPaint)) { |
1685 SkColor2GrColor(copy.getColor()), nullptr = = colors, &grPaint)) { | |
1686 return; | 1696 return; |
1687 } | 1697 } |
1688 | 1698 |
1689 primType = kLines_GrPrimitiveType; | |
1690 int triangleCount = 0; | 1699 int triangleCount = 0; |
1691 int n = (nullptr == indices) ? vertexCount : indexCount; | 1700 int n = (nullptr == indices) ? vertexCount : indexCount; |
1692 switch (vmode) { | 1701 switch (vmode) { |
1693 case SkCanvas::kTriangles_VertexMode: | 1702 case SkCanvas::kTriangles_VertexMode: |
1694 triangleCount = n / 3; | 1703 triangleCount = n / 3; |
1695 break; | 1704 break; |
1696 case SkCanvas::kTriangleStrip_VertexMode: | 1705 case SkCanvas::kTriangleStrip_VertexMode: |
1697 case SkCanvas::kTriangleFan_VertexMode: | 1706 case SkCanvas::kTriangleFan_VertexMode: |
1698 triangleCount = n - 2; | 1707 triangleCount = n - 2; |
1699 break; | 1708 break; |
1700 } | 1709 } |
1701 | 1710 |
1702 VertState state(vertexCount, indices, indexCount); | 1711 VertState state(vertexCount, indices, indexCount); |
1703 VertState::Proc vertProc = state.chooseProc(vmode); | 1712 VertState::Proc vertProc = state.chooseProc(vmode); |
1704 | 1713 |
1705 //number of indices for lines per triangle with kLines | 1714 //number of indices for lines per triangle with kLines |
1706 indexCount = triangleCount * 6; | 1715 indexCount = triangleCount * 6; |
1707 | 1716 |
1708 outAlloc.reset(new uint16_t[indexCount]); | 1717 SkAutoTDeleteArray<uint16_t> lineIndices(new uint16_t[indexCount]); |
1709 outIndices = outAlloc.get(); | |
1710 uint16_t* auxIndices = outAlloc.get(); | |
1711 int i = 0; | 1718 int i = 0; |
1712 while (vertProc(&state)) { | 1719 while (vertProc(&state)) { |
1713 auxIndices[i] = state.f0; | 1720 lineIndices[i] = state.f0; |
1714 auxIndices[i + 1] = state.f1; | 1721 lineIndices[i + 1] = state.f1; |
1715 auxIndices[i + 2] = state.f1; | 1722 lineIndices[i + 2] = state.f1; |
1716 auxIndices[i + 3] = state.f2; | 1723 lineIndices[i + 3] = state.f2; |
1717 auxIndices[i + 4] = state.f2; | 1724 lineIndices[i + 4] = state.f2; |
1718 auxIndices[i + 5] = state.f0; | 1725 lineIndices[i + 5] = state.f0; |
1719 i += 6; | 1726 i += 6; |
1720 } | 1727 } |
1721 } else { | 1728 fDrawContext->drawVertices(fRenderTarget, |
1722 outIndices = indices; | 1729 fClip, |
1723 primType = gVertexMode2PrimitiveType[vmode]; | 1730 grPaint, |
1724 | 1731 *draw.fMatrix, |
1725 if (nullptr == texs || nullptr == paint.getShader()) { | 1732 kLines_GrPrimitiveType, |
1726 if (!SkPaint2GrPaintNoShader(this->context(), paint, | 1733 vertexCount, |
1727 SkColor2GrColor(paint.getColor()), | 1734 vertices, |
1728 nullptr == colors, &grPaint)) { | 1735 texs, |
1729 return; | 1736 colors, |
1730 } | 1737 lineIndices.get(), |
1731 } else { | 1738 indexCount); |
1732 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, | 1739 return; |
1733 nullptr == colors, &grPaint)) { | |
1734 return; | |
1735 } | |
1736 } | |
1737 } | 1740 } |
1738 | 1741 |
1739 #if 0 | 1742 GrPrimitiveType primType = gVertexMode2PrimitiveType[vmode]; |
1740 if (xmode && texs && colors) { | |
1741 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { | |
1742 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); | |
1743 return; | |
1744 } | |
1745 } | |
1746 #endif | |
1747 | 1743 |
1748 SkAutoSTMalloc<128, GrColor> convertedColors(0); | 1744 SkAutoSTMalloc<128, GrColor> convertedColors(0); |
1749 if (colors) { | 1745 if (colors) { |
1750 // need to convert byte order and from non-PM to PM | 1746 // need to convert byte order and from non-PM to PM |
1751 convertedColors.reset(vertexCount); | 1747 convertedColors.reset(vertexCount); |
1752 SkColor color; | 1748 SkColor color; |
1753 for (int i = 0; i < vertexCount; ++i) { | 1749 for (int i = 0; i < vertexCount; ++i) { |
1754 color = colors[i]; | 1750 color = colors[i]; |
1755 if (paint.getAlpha() != 255) { | 1751 if (paint.getAlpha() != 255) { |
1756 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); | 1752 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); |
1757 } | 1753 } |
1758 convertedColors[i] = SkColor2GrColor(color); | 1754 /// TODO: Perform the premul after interpolating |
1755 convertedColors[i] = SkColorToPremulGrColor(color); | |
1759 } | 1756 } |
1760 colors = convertedColors.get(); | 1757 colors = convertedColors.get(); |
1761 } | 1758 } |
1759 GrPaint grPaint; | |
1760 if (texs && colors && paint.getShader()) { | |
robertphillips
2015/09/25 19:52:17
Missing period before 'A' ?
bsalomon
2015/09/25 20:45:07
Done.
| |
1761 // When there are texs and colors the shader and colors are combined usi ng xmode A null | |
1762 // xmode is defined to mean modulate. | |
1763 SkXfermode::Mode colorMode; | |
1764 if (xmode) { | |
1765 if (!xmode->asMode(&colorMode)) { | |
1766 return; | |
1767 } | |
1768 } else { | |
1769 colorMode = SkXfermode::kModulate_Mode; | |
1770 } | |
1771 if (!SkPaintToGrPaintWithXfermode(this->context(), paint, *draw.fMatrix, colorMode, false, | |
1772 &grPaint)) { | |
1773 return; | |
1774 } | |
1775 } else if (!texs) { | |
1776 // Defined to ignore the shader unless texs is provided. | |
1777 if (!SkPaintToGrPaintNoShader(this->context(), paint, &grPaint)) { | |
1778 return; | |
1779 } | |
1780 } else if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint )) { | |
1781 return; | |
1782 } | |
1783 | |
1762 fDrawContext->drawVertices(fRenderTarget, | 1784 fDrawContext->drawVertices(fRenderTarget, |
1763 fClip, | 1785 fClip, |
1764 grPaint, | 1786 grPaint, |
1765 *draw.fMatrix, | 1787 *draw.fMatrix, |
1766 primType, | 1788 primType, |
1767 vertexCount, | 1789 vertexCount, |
1768 vertices, | 1790 vertices, |
1769 texs, | 1791 texs, |
1770 colors, | 1792 colors, |
1771 outIndices, | 1793 indices, |
1772 indexCount); | 1794 indexCount); |
1773 } | 1795 } |
1774 | 1796 |
1775 /////////////////////////////////////////////////////////////////////////////// | 1797 /////////////////////////////////////////////////////////////////////////////// |
1776 | 1798 |
1777 void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS Xform xform[], | 1799 void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS Xform xform[], |
1778 const SkRect texRect[], const SkColor colors[], int count, | 1800 const SkRect texRect[], const SkColor colors[], int count, |
1779 SkXfermode::Mode mode, const SkPaint& paint) { | 1801 SkXfermode::Mode mode, const SkPaint& paint) { |
1780 if (paint.isAntiAlias()) { | 1802 if (paint.isAntiAlias()) { |
1781 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, m ode, paint); | 1803 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, m ode, paint); |
1782 return; | 1804 return; |
1783 } | 1805 } |
1784 | 1806 |
1785 CHECK_SHOULD_DRAW(draw); | 1807 CHECK_SHOULD_DRAW(draw); |
1786 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1808 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
1787 | 1809 |
1788 SkPaint p(paint); | 1810 SkPaint p(paint); |
1789 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode))->unref(); | 1811 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode))->unref(); |
1790 | 1812 |
1791 GrPaint grPaint; | 1813 GrPaint grPaint; |
1792 if (!SkPaint2GrPaint(this->context(), p, *draw.fMatrix, !colors, &grPaint)) { | |
1793 return; | |
1794 } | |
1795 | |
1796 SkDEBUGCODE(this->validate();) | |
1797 | |
1798 #if 0 | |
1799 if (colors) { | 1814 if (colors) { |
1800 if (SkXfermode::kModulate_Mode != mode) { | 1815 if (!SkPaintToGrPaintWithXfermode(this->context(), p, *draw.fMatrix, mod e, true, |
1801 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); | 1816 &grPaint)) { |
1817 return; | |
1818 } | |
1819 } else { | |
1820 if (!SkPaintToGrPaint(this->context(), p, *draw.fMatrix, &grPaint)) { | |
1802 return; | 1821 return; |
1803 } | 1822 } |
1804 } | 1823 } |
1805 #endif | 1824 |
1806 | 1825 SkDEBUGCODE(this->validate();) |
1807 fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix, | 1826 fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix, |
1808 count, xform, texRect, colors); | 1827 count, xform, texRect, colors); |
1809 } | 1828 } |
1810 | 1829 |
1811 /////////////////////////////////////////////////////////////////////////////// | 1830 /////////////////////////////////////////////////////////////////////////////// |
1812 | 1831 |
1813 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1832 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1814 size_t byteLength, SkScalar x, SkScalar y, | 1833 size_t byteLength, SkScalar x, SkScalar y, |
1815 const SkPaint& paint) { | 1834 const SkPaint& paint) { |
1816 CHECK_SHOULD_DRAW(draw); | 1835 CHECK_SHOULD_DRAW(draw); |
1817 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1836 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
1818 | 1837 |
1819 GrPaint grPaint; | 1838 GrPaint grPaint; |
1820 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { | 1839 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
1821 return; | 1840 return; |
1822 } | 1841 } |
1823 | 1842 |
1824 SkDEBUGCODE(this->validate();) | 1843 SkDEBUGCODE(this->validate();) |
1825 | 1844 |
1826 fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, | 1845 fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, |
1827 (const char *)text, byteLength, x, y, draw.fClip->get Bounds()); | 1846 (const char *)text, byteLength, x, y, draw.fClip->get Bounds()); |
1828 } | 1847 } |
1829 | 1848 |
1830 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength, | 1849 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength, |
1831 const SkScalar pos[], int scalarsPerPos, | 1850 const SkScalar pos[], int scalarsPerPos, |
1832 const SkPoint& offset, const SkPaint& paint) { | 1851 const SkPoint& offset, const SkPaint& paint) { |
1833 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); | 1852 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); |
1834 CHECK_SHOULD_DRAW(draw); | 1853 CHECK_SHOULD_DRAW(draw); |
1835 | 1854 |
1836 GrPaint grPaint; | 1855 GrPaint grPaint; |
1837 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { | 1856 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
1838 return; | 1857 return; |
1839 } | 1858 } |
1840 | 1859 |
1841 SkDEBUGCODE(this->validate();) | 1860 SkDEBUGCODE(this->validate();) |
1842 | 1861 |
1843 fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x, | 1862 fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x, |
1844 (const char *)text, byteLength, pos, scalarsPerPos , offset, | 1863 (const char *)text, byteLength, pos, scalarsPerPos , offset, |
1845 draw.fClip->getBounds()); | 1864 draw.fClip->getBounds()); |
1846 } | 1865 } |
1847 | 1866 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1975 #endif | 1994 #endif |
1976 } | 1995 } |
1977 | 1996 |
1978 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1997 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1979 // We always return a transient cache, so it is freed after each | 1998 // We always return a transient cache, so it is freed after each |
1980 // filter traversal. | 1999 // filter traversal. |
1981 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2000 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1982 } | 2001 } |
1983 | 2002 |
1984 #endif | 2003 #endif |
OLD | NEW |