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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 do { \ | 61 do { \ |
62 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 62 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
63 this->prepareDraw(draw); \ | 63 this->prepareDraw(draw); \ |
64 } while (0) | 64 } while (0) |
65 #else | 65 #else |
66 #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) | 66 #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) |
67 #endif | 67 #endif |
68 | 68 |
69 /////////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////////// |
70 | 70 |
| 71 #define CHECK_FOR_ANNOTATION(paint) \ |
| 72 do { if (paint.getAnnotation()) { return; } } while (0) |
| 73 |
| 74 /////////////////////////////////////////////////////////////////////////////// |
| 75 |
71 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed
this | 76 // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed
this |
72 // just accesses the backing GrTexture. Otherwise, it creates a cached texture | 77 // just accesses the backing GrTexture. Otherwise, it creates a cached texture |
73 // representation and releases it in the destructor. | 78 // representation and releases it in the destructor. |
74 class AutoBitmapTexture : public SkNoncopyable { | 79 class AutoBitmapTexture : public SkNoncopyable { |
75 public: | 80 public: |
76 AutoBitmapTexture() {} | 81 AutoBitmapTexture() {} |
77 | 82 |
78 AutoBitmapTexture(GrContext* context, | 83 AutoBitmapTexture(GrContext* context, |
79 const SkBitmap& bitmap, | 84 const SkBitmap& bitmap, |
80 const GrTextureParams& params, | 85 const GrTextureParams& params, |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 return ((int) pts[0].fY) != pts[0].fY; | 394 return ((int) pts[0].fY) != pts[0].fY; |
390 } | 395 } |
391 } | 396 } |
392 return true; | 397 return true; |
393 } | 398 } |
394 | 399 |
395 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, | 400 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
396 size_t count, const SkPoint pts[], const SkPaint& p
aint) { | 401 size_t count, const SkPoint pts[], const SkPaint& p
aint) { |
397 ASSERT_SINGLE_OWNER | 402 ASSERT_SINGLE_OWNER |
398 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext); | 403 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext); |
| 404 CHECK_FOR_ANNOTATION(paint); |
399 CHECK_SHOULD_DRAW(draw); | 405 CHECK_SHOULD_DRAW(draw); |
400 | 406 |
401 SkScalar width = paint.getStrokeWidth(); | 407 SkScalar width = paint.getStrokeWidth(); |
402 if (width < 0) { | 408 if (width < 0) { |
403 return; | 409 return; |
404 } | 410 } |
405 | 411 |
406 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { | 412 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { |
407 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); | 413 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
408 GrPaint grPaint; | 414 GrPaint grPaint; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 nullptr, | 446 nullptr, |
441 nullptr, | 447 nullptr, |
442 0); | 448 0); |
443 } | 449 } |
444 | 450 |
445 /////////////////////////////////////////////////////////////////////////////// | 451 /////////////////////////////////////////////////////////////////////////////// |
446 | 452 |
447 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
& paint) { | 453 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
& paint) { |
448 ASSERT_SINGLE_OWNER | 454 ASSERT_SINGLE_OWNER |
449 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext); | 455 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext); |
| 456 CHECK_FOR_ANNOTATION(paint); |
450 CHECK_SHOULD_DRAW(draw); | 457 CHECK_SHOULD_DRAW(draw); |
451 | 458 |
452 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; | 459 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; |
453 SkScalar width = paint.getStrokeWidth(); | 460 SkScalar width = paint.getStrokeWidth(); |
454 | 461 |
455 /* | 462 /* |
456 We have special code for hairline strokes, miter-strokes, bevel-stroke | 463 We have special code for hairline strokes, miter-strokes, bevel-stroke |
457 and fills. Anything else we just call our path code. | 464 and fills. Anything else we just call our path code. |
458 */ | 465 */ |
459 bool usePath = doStroke && width > 0 && | 466 bool usePath = doStroke && width > 0 && |
(...skipping 26 matching lines...) Expand all Loading... |
486 | 493 |
487 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); | 494 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); |
488 } | 495 } |
489 | 496 |
490 /////////////////////////////////////////////////////////////////////////////// | 497 /////////////////////////////////////////////////////////////////////////////// |
491 | 498 |
492 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 499 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
493 const SkPaint& paint) { | 500 const SkPaint& paint) { |
494 ASSERT_SINGLE_OWNER | 501 ASSERT_SINGLE_OWNER |
495 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); | 502 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext); |
| 503 CHECK_FOR_ANNOTATION(paint); |
496 CHECK_SHOULD_DRAW(draw); | 504 CHECK_SHOULD_DRAW(draw); |
497 | 505 |
498 GrPaint grPaint; | 506 GrPaint grPaint; |
499 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 507 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
500 return; | 508 return; |
501 } | 509 } |
502 | 510 |
503 GrStrokeInfo strokeInfo(paint); | 511 GrStrokeInfo strokeInfo(paint); |
504 if (paint.getMaskFilter()) { | 512 if (paint.getMaskFilter()) { |
505 // try to hit the fast path for drawing filtered round rects | 513 // try to hit the fast path for drawing filtered round rects |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 SkASSERT(!strokeInfo.isDashed()); | 558 SkASSERT(!strokeInfo.isDashed()); |
551 | 559 |
552 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); | 560 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); |
553 } | 561 } |
554 | 562 |
555 | 563 |
556 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 564 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
557 const SkRRect& inner, const SkPaint& paint) { | 565 const SkRRect& inner, const SkPaint& paint) { |
558 ASSERT_SINGLE_OWNER | 566 ASSERT_SINGLE_OWNER |
559 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); | 567 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); |
| 568 CHECK_FOR_ANNOTATION(paint); |
560 CHECK_SHOULD_DRAW(draw); | 569 CHECK_SHOULD_DRAW(draw); |
561 | 570 |
562 if (outer.isEmpty()) { | 571 if (outer.isEmpty()) { |
563 return; | 572 return; |
564 } | 573 } |
565 | 574 |
566 if (inner.isEmpty()) { | 575 if (inner.isEmpty()) { |
567 return this->drawRRect(draw, outer, paint); | 576 return this->drawRRect(draw, outer, paint); |
568 } | 577 } |
569 | 578 |
(...skipping 20 matching lines...) Expand all Loading... |
590 *draw.fMatrix, nullptr, | 599 *draw.fMatrix, nullptr, |
591 draw.fClip->getBounds(), true); | 600 draw.fClip->getBounds(), true); |
592 } | 601 } |
593 | 602 |
594 | 603 |
595 ///////////////////////////////////////////////////////////////////////////// | 604 ///////////////////////////////////////////////////////////////////////////// |
596 | 605 |
597 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
& paint) { | 606 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
& paint) { |
598 ASSERT_SINGLE_OWNER | 607 ASSERT_SINGLE_OWNER |
599 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext); | 608 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext); |
| 609 CHECK_FOR_ANNOTATION(paint); |
600 CHECK_SHOULD_DRAW(draw); | 610 CHECK_SHOULD_DRAW(draw); |
601 | 611 |
602 // Presumably the path effect warps this to something other than an oval | 612 // Presumably the path effect warps this to something other than an oval |
603 if (paint.getPathEffect()) { | 613 if (paint.getPathEffect()) { |
604 SkPath path; | 614 SkPath path; |
605 path.setIsVolatile(true); | 615 path.setIsVolatile(true); |
606 path.addOval(oval); | 616 path.addOval(oval); |
607 this->drawPath(draw, path, paint, nullptr, true); | 617 this->drawPath(draw, path, paint, nullptr, true); |
608 return; | 618 return; |
609 } | 619 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 this->drawOval(draw, rect, paint); | 654 this->drawOval(draw, rect, paint); |
645 return; | 655 return; |
646 } | 656 } |
647 SkRRect rrect; | 657 SkRRect rrect; |
648 if (origSrcPath.isRRect(&rrect)) { | 658 if (origSrcPath.isRRect(&rrect)) { |
649 this->drawRRect(draw, rrect, paint); | 659 this->drawRRect(draw, rrect, paint); |
650 return; | 660 return; |
651 } | 661 } |
652 } | 662 } |
653 | 663 |
| 664 CHECK_FOR_ANNOTATION(paint); |
654 CHECK_SHOULD_DRAW(draw); | 665 CHECK_SHOULD_DRAW(draw); |
655 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); | 666 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); |
656 | 667 |
657 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, | 668 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, |
658 fClip, origSrcPath, paint, | 669 fClip, origSrcPath, paint, |
659 *draw.fMatrix, prePathMatrix, | 670 *draw.fMatrix, prePathMatrix, |
660 draw.fClip->getBounds(), pathIsMutable); | 671 draw.fClip->getBounds(), pathIsMutable); |
661 } | 672 } |
662 | 673 |
663 static const int kBmpSmallTileSize = 1 << 10; | 674 static const int kBmpSmallTileSize = 1 << 10; |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 this->drawTextureProducer(&maker, src, &dst, constraint, *draw.fMatrix,
fClip, paint); | 1465 this->drawTextureProducer(&maker, src, &dst, constraint, *draw.fMatrix,
fClip, paint); |
1455 } else if (as_IB(image)->getROPixels(&bm)) { | 1466 } else if (as_IB(image)->getROPixels(&bm)) { |
1456 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); | 1467 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
1457 } | 1468 } |
1458 } | 1469 } |
1459 | 1470 |
1460 void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
er, | 1471 void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
er, |
1461 const SkIRect& center, const SkRect& dst, con
st SkPaint& paint) { | 1472 const SkIRect& center, const SkRect& dst, con
st SkPaint& paint) { |
1462 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext); | 1473 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext); |
1463 | 1474 |
| 1475 CHECK_FOR_ANNOTATION(paint); |
1464 CHECK_SHOULD_DRAW(draw); | 1476 CHECK_SHOULD_DRAW(draw); |
1465 | 1477 |
1466 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || | 1478 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || |
1467 fRenderTarget->isUnifiedMultisampled(); | 1479 fRenderTarget->isUnifiedMultisampled(); |
1468 bool doBicubic; | 1480 bool doBicubic; |
1469 GrTextureParams::FilterMode textureFilterMode = | 1481 GrTextureParams::FilterMode textureFilterMode = |
1470 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), | 1482 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), |
1471 &doBicubic); | 1483 &doBicubic); |
1472 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { | 1484 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { |
1473 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; | 1485 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1878 } | 1890 } |
1879 | 1891 |
1880 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1892 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1881 ASSERT_SINGLE_OWNER | 1893 ASSERT_SINGLE_OWNER |
1882 // We always return a transient cache, so it is freed after each | 1894 // We always return a transient cache, so it is freed after each |
1883 // filter traversal. | 1895 // filter traversal. |
1884 return SkGpuDevice::NewImageFilterCache(); | 1896 return SkGpuDevice::NewImageFilterCache(); |
1885 } | 1897 } |
1886 | 1898 |
1887 #endif | 1899 #endif |
OLD | NEW |