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 "GrStrokeInfo.h" | 18 #include "GrStyle.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 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); | 457 GrStyle style(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, strokeInfo); | 467 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, style); |
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 GrStrokeInfo strokeInfo(paint); | 538 GrStyle style(paint); |
539 | 539 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &style); |
540 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); | |
541 } | 540 } |
542 | 541 |
543 /////////////////////////////////////////////////////////////////////////////// | 542 /////////////////////////////////////////////////////////////////////////////// |
544 | 543 |
545 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 544 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
546 const SkPaint& paint) { | 545 const SkPaint& paint) { |
547 ASSERT_SINGLE_OWNER | 546 ASSERT_SINGLE_OWNER |
548 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); | 547 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); |
549 CHECK_SHOULD_DRAW(draw); | 548 CHECK_SHOULD_DRAW(draw); |
550 | 549 |
551 GrPaint grPaint; | 550 GrPaint grPaint; |
552 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, | 551 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, |
553 this->surfaceProps().isGammaCorrect(), &grPaint)) { | 552 this->surfaceProps().isGammaCorrect(), &grPaint)) { |
554 return; | 553 return; |
555 } | 554 } |
556 | 555 |
557 GrStrokeInfo strokeInfo(paint); | 556 GrStyle style(paint); |
558 if (paint.getMaskFilter()) { | 557 if (paint.getMaskFilter()) { |
559 // try to hit the fast path for drawing filtered round rects | 558 // try to hit the fast path for drawing filtered round rects |
560 | 559 |
561 SkRRect devRRect; | 560 SkRRect devRRect; |
562 if (rect.transform(*draw.fMatrix, &devRRect)) { | 561 if (rect.transform(*draw.fMatrix, &devRRect)) { |
563 if (devRRect.allCornersCircular()) { | 562 if (devRRect.allCornersCircular()) { |
564 SkRect maskRect; | 563 SkRect maskRect; |
565 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect, | 564 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect, |
566 draw.fRC->getBounds(
), | 565 draw.fRC->getBounds(
), |
567 *draw.fMatrix, | 566 *draw.fMatrix, |
568 &maskRect)) { | 567 &maskRect)) { |
569 SkIRect finalIRect; | 568 SkIRect finalIRect; |
570 maskRect.roundOut(&finalIRect); | 569 maskRect.roundOut(&finalIRect); |
571 if (draw.fRC->quickReject(finalIRect)) { | 570 if (draw.fRC->quickReject(finalIRect)) { |
572 // clipped out | 571 // clipped out |
573 return; | 572 return; |
574 } | 573 } |
575 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), | 574 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), |
576 fDrawCon
text.get(), | 575 fDrawCon
text.get(), |
577 &grPaint
, | 576 &grPaint
, |
578 fClip, | 577 fClip, |
579 *draw.fM
atrix, | 578 *draw.fM
atrix, |
580 strokeIn
fo, | 579 style.st
rokeRec(), |
581 devRRect
)) { | 580 devRRect
)) { |
582 return; | 581 return; |
583 } | 582 } |
584 } | 583 } |
585 | 584 |
586 } | 585 } |
587 } | 586 } |
588 } | 587 } |
589 | 588 |
590 if (paint.getMaskFilter() || paint.getPathEffect()) { | 589 if (paint.getMaskFilter() || style.pathEffect()) { |
591 // The only mask filter the native rrect drawing code could've handle wa
s taken | 590 // The only mask filter the native rrect drawing code could've handle wa
s taken |
592 // care of above. | 591 // care of above. |
593 // A path effect will presumably transform this rrect into something els
e. | 592 // A path effect will presumably transform this rrect into something els
e. |
594 SkPath path; | 593 SkPath path; |
595 path.setIsVolatile(true); | 594 path.setIsVolatile(true); |
596 path.addRRect(rect); | 595 path.addRRect(rect); |
597 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), | 596 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), |
598 fClip, path, paint, | 597 fClip, path, paint, |
599 *draw.fMatrix, nullptr, | 598 *draw.fMatrix, nullptr, |
600 draw.fRC->getBounds(), true); | 599 draw.fRC->getBounds(), true); |
601 return; | 600 return; |
602 } | 601 } |
603 | 602 |
604 SkASSERT(!strokeInfo.isDashed()); | 603 SkASSERT(!style.pathEffect()); |
605 | 604 |
606 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); | 605 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, style); |
607 } | 606 } |
608 | 607 |
609 | 608 |
610 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 609 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
611 const SkRRect& inner, const SkPaint& paint) { | 610 const SkRRect& inner, const SkPaint& paint) { |
612 ASSERT_SINGLE_OWNER | 611 ASSERT_SINGLE_OWNER |
613 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); | 612 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); |
614 CHECK_SHOULD_DRAW(draw); | 613 CHECK_SHOULD_DRAW(draw); |
615 | 614 |
616 if (outer.isEmpty()) { | 615 if (outer.isEmpty()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 SkRRect rr = SkRRect::MakeOval(oval); | 667 SkRRect rr = SkRRect::MakeOval(oval); |
669 return this->drawRRect(draw, rr, paint); | 668 return this->drawRRect(draw, rr, paint); |
670 } | 669 } |
671 | 670 |
672 GrPaint grPaint; | 671 GrPaint grPaint; |
673 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, | 672 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, |
674 this->surfaceProps().isGammaCorrect(), &grPaint)) { | 673 this->surfaceProps().isGammaCorrect(), &grPaint)) { |
675 return; | 674 return; |
676 } | 675 } |
677 | 676 |
678 GrStrokeInfo strokeInfo(paint); | 677 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, GrStyle(paint)); |
679 SkASSERT(!strokeInfo.isDashed()); | |
680 | |
681 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, strokeInfo); | |
682 } | 678 } |
683 | 679 |
684 #include "SkMaskFilter.h" | 680 #include "SkMaskFilter.h" |
685 | 681 |
686 /////////////////////////////////////////////////////////////////////////////// | 682 /////////////////////////////////////////////////////////////////////////////// |
687 | 683 |
688 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 684 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
689 const SkPaint& paint, const SkMatrix* prePathMatrix, | 685 const SkPaint& paint, const SkMatrix* prePathMatrix, |
690 bool pathIsMutable) { | 686 bool pathIsMutable) { |
691 ASSERT_SINGLE_OWNER | 687 ASSERT_SINGLE_OWNER |
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 } | 1847 } |
1852 | 1848 |
1853 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1849 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1854 ASSERT_SINGLE_OWNER | 1850 ASSERT_SINGLE_OWNER |
1855 // We always return a transient cache, so it is freed after each | 1851 // We always return a transient cache, so it is freed after each |
1856 // filter traversal. | 1852 // filter traversal. |
1857 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1853 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1858 } | 1854 } |
1859 | 1855 |
1860 #endif | 1856 #endif |
OLD | NEW |