| 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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 do { \ | 62 do { \ |
| 63 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 63 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
| 64 this->prepareDraw(draw); \ | 64 this->prepareDraw(draw); \ |
| 65 } while (0) | 65 } while (0) |
| 66 #else | 66 #else |
| 67 #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) | 67 #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 /////////////////////////////////////////////////////////////////////////////// | 70 /////////////////////////////////////////////////////////////////////////////// |
| 71 | 71 |
| 72 #define CHECK_FOR_ANNOTATION(paint) \ | |
| 73 do { if (paint.getAnnotation()) { return; } } while (0) | |
| 74 | |
| 75 /////////////////////////////////////////////////////////////////////////////// | |
| 76 | |
| 77 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed
this | 72 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed
this |
| 78 // just accesses the backing GrTexture. Otherwise, it creates a cached texture | 73 // just accesses the backing GrTexture. Otherwise, it creates a cached texture |
| 79 // representation and releases it in the destructor. | 74 // representation and releases it in the destructor. |
| 80 class AutoBitmapTexture : public SkNoncopyable { | 75 class AutoBitmapTexture : public SkNoncopyable { |
| 81 public: | 76 public: |
| 82 AutoBitmapTexture() {} | 77 AutoBitmapTexture() {} |
| 83 | 78 |
| 84 AutoBitmapTexture(GrContext* context, | 79 AutoBitmapTexture(GrContext* context, |
| 85 const SkBitmap& bitmap, | 80 const SkBitmap& bitmap, |
| 86 const GrTextureParams& params, | 81 const GrTextureParams& params, |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 return ((int) pts[0].fY) != pts[0].fY; | 390 return ((int) pts[0].fY) != pts[0].fY; |
| 396 } | 391 } |
| 397 } | 392 } |
| 398 return true; | 393 return true; |
| 399 } | 394 } |
| 400 | 395 |
| 401 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, | 396 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
| 402 size_t count, const SkPoint pts[], const SkPaint& p
aint) { | 397 size_t count, const SkPoint pts[], const SkPaint& p
aint) { |
| 403 ASSERT_SINGLE_OWNER | 398 ASSERT_SINGLE_OWNER |
| 404 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext); | 399 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext); |
| 405 CHECK_FOR_ANNOTATION(paint); | |
| 406 CHECK_SHOULD_DRAW(draw); | 400 CHECK_SHOULD_DRAW(draw); |
| 407 | 401 |
| 408 SkScalar width = paint.getStrokeWidth(); | 402 SkScalar width = paint.getStrokeWidth(); |
| 409 if (width < 0) { | 403 if (width < 0) { |
| 410 return; | 404 return; |
| 411 } | 405 } |
| 412 | 406 |
| 413 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { | 407 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { |
| 414 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); | 408 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
| 415 GrPaint grPaint; | 409 GrPaint grPaint; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 nullptr, | 441 nullptr, |
| 448 nullptr, | 442 nullptr, |
| 449 0); | 443 0); |
| 450 } | 444 } |
| 451 | 445 |
| 452 /////////////////////////////////////////////////////////////////////////////// | 446 /////////////////////////////////////////////////////////////////////////////// |
| 453 | 447 |
| 454 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
& paint) { | 448 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
& paint) { |
| 455 ASSERT_SINGLE_OWNER | 449 ASSERT_SINGLE_OWNER |
| 456 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext); | 450 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext); |
| 457 CHECK_FOR_ANNOTATION(paint); | |
| 458 CHECK_SHOULD_DRAW(draw); | 451 CHECK_SHOULD_DRAW(draw); |
| 459 | 452 |
| 460 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; | 453 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; |
| 461 SkScalar width = paint.getStrokeWidth(); | 454 SkScalar width = paint.getStrokeWidth(); |
| 462 | 455 |
| 463 /* | 456 /* |
| 464 We have special code for hairline strokes, miter-strokes, bevel-stroke | 457 We have special code for hairline strokes, miter-strokes, bevel-stroke |
| 465 and fills. Anything else we just call our path code. | 458 and fills. Anything else we just call our path code. |
| 466 */ | 459 */ |
| 467 bool usePath = doStroke && width > 0 && | 460 bool usePath = doStroke && width > 0 && |
| (...skipping 26 matching lines...) Expand all Loading... |
| 494 | 487 |
| 495 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); | 488 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); |
| 496 } | 489 } |
| 497 | 490 |
| 498 /////////////////////////////////////////////////////////////////////////////// | 491 /////////////////////////////////////////////////////////////////////////////// |
| 499 | 492 |
| 500 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 493 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
| 501 const SkPaint& paint) { | 494 const SkPaint& paint) { |
| 502 ASSERT_SINGLE_OWNER | 495 ASSERT_SINGLE_OWNER |
| 503 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); | 496 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); |
| 504 CHECK_FOR_ANNOTATION(paint); | |
| 505 CHECK_SHOULD_DRAW(draw); | 497 CHECK_SHOULD_DRAW(draw); |
| 506 | 498 |
| 507 GrPaint grPaint; | 499 GrPaint grPaint; |
| 508 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 500 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
| 509 return; | 501 return; |
| 510 } | 502 } |
| 511 | 503 |
| 512 GrStrokeInfo strokeInfo(paint); | 504 GrStrokeInfo strokeInfo(paint); |
| 513 if (paint.getMaskFilter()) { | 505 if (paint.getMaskFilter()) { |
| 514 // try to hit the fast path for drawing filtered round rects | 506 // try to hit the fast path for drawing filtered round rects |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 610 |
| 619 fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, SkMatrix::I(), bounds,
inverseVM); | 611 fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, SkMatrix::I(), bounds,
inverseVM); |
| 620 return true; | 612 return true; |
| 621 } | 613 } |
| 622 | 614 |
| 623 | 615 |
| 624 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 616 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
| 625 const SkRRect& inner, const SkPaint& paint) { | 617 const SkRRect& inner, const SkPaint& paint) { |
| 626 ASSERT_SINGLE_OWNER | 618 ASSERT_SINGLE_OWNER |
| 627 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); | 619 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); |
| 628 CHECK_FOR_ANNOTATION(paint); | |
| 629 CHECK_SHOULD_DRAW(draw); | 620 CHECK_SHOULD_DRAW(draw); |
| 630 | 621 |
| 631 if (outer.isEmpty()) { | 622 if (outer.isEmpty()) { |
| 632 return; | 623 return; |
| 633 } | 624 } |
| 634 | 625 |
| 635 if (inner.isEmpty()) { | 626 if (inner.isEmpty()) { |
| 636 return this->drawRRect(draw, outer, paint); | 627 return this->drawRRect(draw, outer, paint); |
| 637 } | 628 } |
| 638 | 629 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 655 *draw.fMatrix, nullptr, | 646 *draw.fMatrix, nullptr, |
| 656 draw.fClip->getBounds(), true); | 647 draw.fClip->getBounds(), true); |
| 657 } | 648 } |
| 658 | 649 |
| 659 | 650 |
| 660 ///////////////////////////////////////////////////////////////////////////// | 651 ///////////////////////////////////////////////////////////////////////////// |
| 661 | 652 |
| 662 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
& paint) { | 653 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
& paint) { |
| 663 ASSERT_SINGLE_OWNER | 654 ASSERT_SINGLE_OWNER |
| 664 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext); | 655 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext); |
| 665 CHECK_FOR_ANNOTATION(paint); | |
| 666 CHECK_SHOULD_DRAW(draw); | 656 CHECK_SHOULD_DRAW(draw); |
| 667 | 657 |
| 668 // Presumably the path effect warps this to something other than an oval | 658 // Presumably the path effect warps this to something other than an oval |
| 669 if (paint.getPathEffect()) { | 659 if (paint.getPathEffect()) { |
| 670 SkPath path; | 660 SkPath path; |
| 671 path.setIsVolatile(true); | 661 path.setIsVolatile(true); |
| 672 path.addOval(oval); | 662 path.addOval(oval); |
| 673 this->drawPath(draw, path, paint, nullptr, true); | 663 this->drawPath(draw, path, paint, nullptr, true); |
| 674 return; | 664 return; |
| 675 } | 665 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 this->drawOval(draw, rect, paint); | 700 this->drawOval(draw, rect, paint); |
| 711 return; | 701 return; |
| 712 } | 702 } |
| 713 SkRRect rrect; | 703 SkRRect rrect; |
| 714 if (origSrcPath.isRRect(&rrect)) { | 704 if (origSrcPath.isRRect(&rrect)) { |
| 715 this->drawRRect(draw, rrect, paint); | 705 this->drawRRect(draw, rrect, paint); |
| 716 return; | 706 return; |
| 717 } | 707 } |
| 718 } | 708 } |
| 719 | 709 |
| 720 CHECK_FOR_ANNOTATION(paint); | |
| 721 CHECK_SHOULD_DRAW(draw); | 710 CHECK_SHOULD_DRAW(draw); |
| 722 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); | 711 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); |
| 723 | 712 |
| 724 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, | 713 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, |
| 725 fClip, origSrcPath, paint, | 714 fClip, origSrcPath, paint, |
| 726 *draw.fMatrix, prePathMatrix, | 715 *draw.fMatrix, prePathMatrix, |
| 727 draw.fClip->getBounds(), pathIsMutable); | 716 draw.fClip->getBounds(), pathIsMutable); |
| 728 } | 717 } |
| 729 | 718 |
| 730 static const int kBmpSmallTileSize = 1 << 10; | 719 static const int kBmpSmallTileSize = 1 << 10; |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 this->drawTextureProducer(&maker, src, &dst, constraint, *draw.fMatrix,
fClip, paint); | 1510 this->drawTextureProducer(&maker, src, &dst, constraint, *draw.fMatrix,
fClip, paint); |
| 1522 } else if (as_IB(image)->getROPixels(&bm)) { | 1511 } else if (as_IB(image)->getROPixels(&bm)) { |
| 1523 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); | 1512 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
| 1524 } | 1513 } |
| 1525 } | 1514 } |
| 1526 | 1515 |
| 1527 void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
er, | 1516 void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
er, |
| 1528 const SkIRect& center, const SkRect& dst, con
st SkPaint& paint) { | 1517 const SkIRect& center, const SkRect& dst, con
st SkPaint& paint) { |
| 1529 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext); | 1518 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext); |
| 1530 | 1519 |
| 1531 CHECK_FOR_ANNOTATION(paint); | |
| 1532 CHECK_SHOULD_DRAW(draw); | 1520 CHECK_SHOULD_DRAW(draw); |
| 1533 | 1521 |
| 1534 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || | 1522 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || |
| 1535 fRenderTarget->isUnifiedMultisampled(); | 1523 fRenderTarget->isUnifiedMultisampled(); |
| 1536 bool doBicubic; | 1524 bool doBicubic; |
| 1537 GrTextureParams::FilterMode textureFilterMode = | 1525 GrTextureParams::FilterMode textureFilterMode = |
| 1538 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), | 1526 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), |
| 1539 &doBicubic); | 1527 &doBicubic); |
| 1540 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { | 1528 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { |
| 1541 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; | 1529 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 } | 1934 } |
| 1947 | 1935 |
| 1948 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1936 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1949 ASSERT_SINGLE_OWNER | 1937 ASSERT_SINGLE_OWNER |
| 1950 // We always return a transient cache, so it is freed after each | 1938 // We always return a transient cache, so it is freed after each |
| 1951 // filter traversal. | 1939 // filter traversal. |
| 1952 return SkGpuDevice::NewImageFilterCache(); | 1940 return SkGpuDevice::NewImageFilterCache(); |
| 1953 } | 1941 } |
| 1954 | 1942 |
| 1955 #endif | 1943 #endif |
| OLD | NEW |