| 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 "SkDraw.h" | 12 #include "SkDraw.h" |
| 13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 14 #include "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
| 15 #include "GrImageIDTextureAdjuster.h" | 15 #include "GrImageIDTextureAdjuster.h" |
| 16 #include "GrLayerHoister.h" | 16 #include "GrLayerHoister.h" |
| 17 #include "GrRecordReplaceDraw.h" | 17 #include "GrRecordReplaceDraw.h" |
| 18 #include "GrStyle.h" | 18 #include "GrStrokeInfo.h" |
| 19 #include "GrTracing.h" | 19 #include "GrTracing.h" |
| 20 #include "SkCanvasPriv.h" | 20 #include "SkCanvasPriv.h" |
| 21 #include "SkErrorInternals.h" | 21 #include "SkErrorInternals.h" |
| 22 #include "SkGlyphCache.h" | 22 #include "SkGlyphCache.h" |
| 23 #include "SkGrTexturePixelRef.h" | 23 #include "SkGrTexturePixelRef.h" |
| 24 #include "SkGr.h" | 24 #include "SkGr.h" |
| 25 #include "SkGrPriv.h" | 25 #include "SkGrPriv.h" |
| 26 #include "SkImage_Base.h" | 26 #include "SkImage_Base.h" |
| 27 #include "SkImageCacherator.h" | 27 #include "SkImageCacherator.h" |
| 28 #include "SkImageFilter.h" | 28 #include "SkImageFilter.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 ASSERT_SINGLE_OWNER | 447 ASSERT_SINGLE_OWNER |
| 448 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext); | 448 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext); |
| 449 CHECK_SHOULD_DRAW(draw); | 449 CHECK_SHOULD_DRAW(draw); |
| 450 | 450 |
| 451 SkScalar width = paint.getStrokeWidth(); | 451 SkScalar width = paint.getStrokeWidth(); |
| 452 if (width < 0) { | 452 if (width < 0) { |
| 453 return; | 453 return; |
| 454 } | 454 } |
| 455 | 455 |
| 456 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { | 456 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { |
| 457 GrStyle style(paint, SkPaint::kStroke_Style); | 457 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
| 458 GrPaint grPaint; | 458 GrPaint grPaint; |
| 459 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, | 459 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, |
| 460 this->surfaceProps().isGammaCorrect(), &grPaint))
{ | 460 this->surfaceProps().isGammaCorrect(), &grPaint))
{ |
| 461 return; | 461 return; |
| 462 } | 462 } |
| 463 SkPath path; | 463 SkPath path; |
| 464 path.setIsVolatile(true); | 464 path.setIsVolatile(true); |
| 465 path.moveTo(pts[0]); | 465 path.moveTo(pts[0]); |
| 466 path.lineTo(pts[1]); | 466 path.lineTo(pts[1]); |
| 467 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, style); | 467 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, strokeInfo); |
| 468 return; | 468 return; |
| 469 } | 469 } |
| 470 | 470 |
| 471 // we only handle non-antialiased hairlines and paints without path effects
or mask filters, | 471 // we only handle non-antialiased hairlines and paints without path effects
or mask filters, |
| 472 // else we let the SkDraw call our drawPath() | 472 // else we let the SkDraw call our drawPath() |
| 473 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || | 473 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || |
| 474 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { | 474 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { |
| 475 draw.drawPoints(mode, count, pts, paint, true); | 475 draw.drawPoints(mode, count, pts, paint, true); |
| 476 return; | 476 return; |
| 477 } | 477 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 draw.fRC->getBounds(), true); | 528 draw.fRC->getBounds(), true); |
| 529 return; | 529 return; |
| 530 } | 530 } |
| 531 | 531 |
| 532 GrPaint grPaint; | 532 GrPaint grPaint; |
| 533 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, | 533 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, |
| 534 this->surfaceProps().isGammaCorrect(), &grPaint)) { | 534 this->surfaceProps().isGammaCorrect(), &grPaint)) { |
| 535 return; | 535 return; |
| 536 } | 536 } |
| 537 | 537 |
| 538 GrStyle style(paint); | 538 GrStrokeInfo strokeInfo(paint); |
| 539 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &style); | 539 |
| 540 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); |
| 540 } | 541 } |
| 541 | 542 |
| 542 /////////////////////////////////////////////////////////////////////////////// | 543 /////////////////////////////////////////////////////////////////////////////// |
| 543 | 544 |
| 544 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 545 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
| 545 const SkPaint& paint) { | 546 const SkPaint& paint) { |
| 546 ASSERT_SINGLE_OWNER | 547 ASSERT_SINGLE_OWNER |
| 547 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); | 548 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); |
| 548 CHECK_SHOULD_DRAW(draw); | 549 CHECK_SHOULD_DRAW(draw); |
| 549 | 550 |
| 550 GrPaint grPaint; | 551 GrPaint grPaint; |
| 551 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, | 552 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, |
| 552 this->surfaceProps().isGammaCorrect(), &grPaint)) { | 553 this->surfaceProps().isGammaCorrect(), &grPaint)) { |
| 553 return; | 554 return; |
| 554 } | 555 } |
| 555 | 556 |
| 556 GrStyle style(paint); | 557 GrStrokeInfo strokeInfo(paint); |
| 557 if (paint.getMaskFilter()) { | 558 if (paint.getMaskFilter()) { |
| 558 // try to hit the fast path for drawing filtered round rects | 559 // try to hit the fast path for drawing filtered round rects |
| 559 | 560 |
| 560 SkRRect devRRect; | 561 SkRRect devRRect; |
| 561 if (rect.transform(*draw.fMatrix, &devRRect)) { | 562 if (rect.transform(*draw.fMatrix, &devRRect)) { |
| 562 if (devRRect.allCornersCircular()) { | 563 if (devRRect.allCornersCircular()) { |
| 563 SkRect maskRect; | 564 SkRect maskRect; |
| 564 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect, | 565 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect, |
| 565 draw.fRC->getBounds(
), | 566 draw.fRC->getBounds(
), |
| 566 *draw.fMatrix, | 567 *draw.fMatrix, |
| 567 &maskRect)) { | 568 &maskRect)) { |
| 568 SkIRect finalIRect; | 569 SkIRect finalIRect; |
| 569 maskRect.roundOut(&finalIRect); | 570 maskRect.roundOut(&finalIRect); |
| 570 if (draw.fRC->quickReject(finalIRect)) { | 571 if (draw.fRC->quickReject(finalIRect)) { |
| 571 // clipped out | 572 // clipped out |
| 572 return; | 573 return; |
| 573 } | 574 } |
| 574 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), | 575 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), |
| 575 fDrawCon
text.get(), | 576 fDrawCon
text.get(), |
| 576 &grPaint
, | 577 &grPaint
, |
| 577 fClip, | 578 fClip, |
| 578 *draw.fM
atrix, | 579 *draw.fM
atrix, |
| 579 style.st
rokeRec(), | 580 strokeIn
fo, |
| 580 devRRect
)) { | 581 devRRect
)) { |
| 581 return; | 582 return; |
| 582 } | 583 } |
| 583 } | 584 } |
| 584 | 585 |
| 585 } | 586 } |
| 586 } | 587 } |
| 587 } | 588 } |
| 588 | 589 |
| 589 if (paint.getMaskFilter() || style.pathEffect()) { | 590 if (paint.getMaskFilter() || paint.getPathEffect()) { |
| 590 // The only mask filter the native rrect drawing code could've handle wa
s taken | 591 // The only mask filter the native rrect drawing code could've handle wa
s taken |
| 591 // care of above. | 592 // care of above. |
| 592 // A path effect will presumably transform this rrect into something els
e. | 593 // A path effect will presumably transform this rrect into something els
e. |
| 593 SkPath path; | 594 SkPath path; |
| 594 path.setIsVolatile(true); | 595 path.setIsVolatile(true); |
| 595 path.addRRect(rect); | 596 path.addRRect(rect); |
| 596 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), | 597 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), |
| 597 fClip, path, paint, | 598 fClip, path, paint, |
| 598 *draw.fMatrix, nullptr, | 599 *draw.fMatrix, nullptr, |
| 599 draw.fRC->getBounds(), true); | 600 draw.fRC->getBounds(), true); |
| 600 return; | 601 return; |
| 601 } | 602 } |
| 602 | 603 |
| 603 SkASSERT(!style.pathEffect()); | 604 SkASSERT(!strokeInfo.isDashed()); |
| 604 | 605 |
| 605 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, style); | 606 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); |
| 606 } | 607 } |
| 607 | 608 |
| 608 | 609 |
| 609 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 610 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
| 610 const SkRRect& inner, const SkPaint& paint) { | 611 const SkRRect& inner, const SkPaint& paint) { |
| 611 ASSERT_SINGLE_OWNER | 612 ASSERT_SINGLE_OWNER |
| 612 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); | 613 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); |
| 613 CHECK_SHOULD_DRAW(draw); | 614 CHECK_SHOULD_DRAW(draw); |
| 614 | 615 |
| 615 if (outer.isEmpty()) { | 616 if (outer.isEmpty()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 SkRRect rr = SkRRect::MakeOval(oval); | 668 SkRRect rr = SkRRect::MakeOval(oval); |
| 668 return this->drawRRect(draw, rr, paint); | 669 return this->drawRRect(draw, rr, paint); |
| 669 } | 670 } |
| 670 | 671 |
| 671 GrPaint grPaint; | 672 GrPaint grPaint; |
| 672 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, | 673 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, |
| 673 this->surfaceProps().isGammaCorrect(), &grPaint)) { | 674 this->surfaceProps().isGammaCorrect(), &grPaint)) { |
| 674 return; | 675 return; |
| 675 } | 676 } |
| 676 | 677 |
| 677 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, GrStyle(paint)); | 678 GrStrokeInfo strokeInfo(paint); |
| 679 SkASSERT(!strokeInfo.isDashed()); |
| 680 |
| 681 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, strokeInfo); |
| 678 } | 682 } |
| 679 | 683 |
| 680 #include "SkMaskFilter.h" | 684 #include "SkMaskFilter.h" |
| 681 | 685 |
| 682 /////////////////////////////////////////////////////////////////////////////// | 686 /////////////////////////////////////////////////////////////////////////////// |
| 683 | 687 |
| 684 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 688 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 685 const SkPaint& paint, const SkMatrix* prePathMatrix, | 689 const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 686 bool pathIsMutable) { | 690 bool pathIsMutable) { |
| 687 ASSERT_SINGLE_OWNER | 691 ASSERT_SINGLE_OWNER |
| (...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 } | 1851 } |
| 1848 | 1852 |
| 1849 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1853 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
| 1850 ASSERT_SINGLE_OWNER | 1854 ASSERT_SINGLE_OWNER |
| 1851 // We always return a transient cache, so it is freed after each | 1855 // We always return a transient cache, so it is freed after each |
| 1852 // filter traversal. | 1856 // filter traversal. |
| 1853 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1857 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
| 1854 } | 1858 } |
| 1855 | 1859 |
| 1856 #endif | 1860 #endif |
| OLD | NEW |