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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 , fContext(SkRef(rt->getContext())) | 164 , fContext(SkRef(rt->getContext())) |
165 , fRenderTarget(SkRef(rt)) { | 165 , fRenderTarget(SkRef(rt)) { |
166 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 166 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
167 | 167 |
168 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 168 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
169 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); | 169 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); |
170 SkPixelRef* pr = new SkGrPixelRef(info, rt); | 170 SkPixelRef* pr = new SkGrPixelRef(info, rt); |
171 fLegacyBitmap.setInfo(info); | 171 fLegacyBitmap.setInfo(info); |
172 fLegacyBitmap.setPixelRef(pr)->unref(); | 172 fLegacyBitmap.setPixelRef(pr)->unref(); |
173 | 173 |
174 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); | 174 fDrawContext = this->context()->drawContext(sk_ref_sp(rt), &this->surfacePro
ps()); |
175 if (flags & kNeedClear_Flag) { | 175 if (flags & kNeedClear_Flag) { |
176 this->clearAll(); | 176 this->clearAll(); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkBudgeted b
udgeted, | 180 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkBudgeted b
udgeted, |
181 const SkImageInfo& origInfo, int
sampleCount) { | 181 const SkImageInfo& origInfo, int
sampleCount) { |
182 if (kUnknown_SkColorType == origInfo.colorType() || | 182 if (kUnknown_SkColorType == origInfo.colorType() || |
183 origInfo.width() < 0 || origInfo.height() < 0) { | 183 origInfo.width() < 0 || origInfo.height() < 0) { |
184 return nullptr; | 184 return nullptr; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 fRenderTarget.reset(newRT.release()); | 377 fRenderTarget.reset(newRT.release()); |
378 | 378 |
379 #ifdef SK_DEBUG | 379 #ifdef SK_DEBUG |
380 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : | 380 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : |
381 kPremul_SkAlp
haType); | 381 kPremul_SkAlp
haType); |
382 SkASSERT(info == fLegacyBitmap.info()); | 382 SkASSERT(info == fLegacyBitmap.info()); |
383 #endif | 383 #endif |
384 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); | 384 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); |
385 fLegacyBitmap.setPixelRef(pr)->unref(); | 385 fLegacyBitmap.setPixelRef(pr)->unref(); |
386 | 386 |
387 fDrawContext.reset(this->context()->drawContext(fRenderTarget, &this->surfac
eProps())); | 387 fDrawContext = this->context()->drawContext(sk_ref_sp(fRenderTarget.get()), |
| 388 &this->surfaceProps()); |
388 } | 389 } |
389 | 390 |
390 /////////////////////////////////////////////////////////////////////////////// | 391 /////////////////////////////////////////////////////////////////////////////// |
391 | 392 |
392 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 393 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
393 ASSERT_SINGLE_OWNER | 394 ASSERT_SINGLE_OWNER |
394 CHECK_SHOULD_DRAW(draw); | 395 CHECK_SHOULD_DRAW(draw); |
395 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); | 396 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); |
396 | 397 |
397 GrPaint grPaint; | 398 GrPaint grPaint; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 // a few other reasons we might need to call drawPath... | 506 // a few other reasons we might need to call drawPath... |
506 if (paint.getMaskFilter() || paint.getPathEffect() || | 507 if (paint.getMaskFilter() || paint.getPathEffect() || |
507 paint.getStyle() == SkPaint::kStrokeAndFill_Style) { // we can't both st
roke and fill rects | 508 paint.getStyle() == SkPaint::kStrokeAndFill_Style) { // we can't both st
roke and fill rects |
508 usePath = true; | 509 usePath = true; |
509 } | 510 } |
510 | 511 |
511 if (usePath) { | 512 if (usePath) { |
512 SkPath path; | 513 SkPath path; |
513 path.setIsVolatile(true); | 514 path.setIsVolatile(true); |
514 path.addRect(rect); | 515 path.addRect(rect); |
515 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, | 516 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), |
516 fClip, path, paint, | 517 fClip, path, paint, |
517 *draw.fMatrix, nullptr, | 518 *draw.fMatrix, nullptr, |
518 draw.fClip->getBounds(), true); | 519 draw.fClip->getBounds(), true); |
519 return; | 520 return; |
520 } | 521 } |
521 | 522 |
522 GrPaint grPaint; | 523 GrPaint grPaint; |
523 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, | 524 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, |
524 this->surfaceProps().isGammaCorrect(), &grPaint)) { | 525 this->surfaceProps().isGammaCorrect(), &grPaint)) { |
525 return; | 526 return; |
(...skipping 30 matching lines...) Expand all Loading... |
556 draw.fClip->getBound
s(), | 557 draw.fClip->getBound
s(), |
557 *draw.fMatrix, | 558 *draw.fMatrix, |
558 &maskRect)) { | 559 &maskRect)) { |
559 SkIRect finalIRect; | 560 SkIRect finalIRect; |
560 maskRect.roundOut(&finalIRect); | 561 maskRect.roundOut(&finalIRect); |
561 if (draw.fClip->quickReject(finalIRect)) { | 562 if (draw.fClip->quickReject(finalIRect)) { |
562 // clipped out | 563 // clipped out |
563 return; | 564 return; |
564 } | 565 } |
565 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), | 566 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), |
566 fDrawCon
text, | 567 fDrawCon
text.get(), |
567 &grPaint
, | 568 &grPaint
, |
568 fClip, | 569 fClip, |
569 *draw.fM
atrix, | 570 *draw.fM
atrix, |
570 strokeIn
fo, | 571 strokeIn
fo, |
571 devRRect
)) { | 572 devRRect
)) { |
572 return; | 573 return; |
573 } | 574 } |
574 } | 575 } |
575 | 576 |
576 } | 577 } |
577 } | 578 } |
578 } | 579 } |
579 | 580 |
580 if (paint.getMaskFilter() || paint.getPathEffect()) { | 581 if (paint.getMaskFilter() || paint.getPathEffect()) { |
581 // The only mask filter the native rrect drawing code could've handle wa
s taken | 582 // The only mask filter the native rrect drawing code could've handle wa
s taken |
582 // care of above. | 583 // care of above. |
583 // A path effect will presumably transform this rrect into something els
e. | 584 // A path effect will presumably transform this rrect into something els
e. |
584 SkPath path; | 585 SkPath path; |
585 path.setIsVolatile(true); | 586 path.setIsVolatile(true); |
586 path.addRRect(rect); | 587 path.addRRect(rect); |
587 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, | 588 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), |
588 fClip, path, paint, | 589 fClip, path, paint, |
589 *draw.fMatrix, nullptr, | 590 *draw.fMatrix, nullptr, |
590 draw.fClip->getBounds(), true); | 591 draw.fClip->getBounds(), true); |
591 return; | 592 return; |
592 } | 593 } |
593 | 594 |
594 SkASSERT(!strokeInfo.isDashed()); | 595 SkASSERT(!strokeInfo.isDashed()); |
595 | 596 |
596 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); | 597 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); |
597 } | 598 } |
(...skipping 25 matching lines...) Expand all Loading... |
623 fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner); | 624 fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner); |
624 return; | 625 return; |
625 } | 626 } |
626 | 627 |
627 SkPath path; | 628 SkPath path; |
628 path.setIsVolatile(true); | 629 path.setIsVolatile(true); |
629 path.addRRect(outer); | 630 path.addRRect(outer); |
630 path.addRRect(inner); | 631 path.addRRect(inner); |
631 path.setFillType(SkPath::kEvenOdd_FillType); | 632 path.setFillType(SkPath::kEvenOdd_FillType); |
632 | 633 |
633 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, | 634 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), |
634 fClip, path, paint, | 635 fClip, path, paint, |
635 *draw.fMatrix, nullptr, | 636 *draw.fMatrix, nullptr, |
636 draw.fClip->getBounds(), true); | 637 draw.fClip->getBounds(), true); |
637 } | 638 } |
638 | 639 |
639 | 640 |
640 ///////////////////////////////////////////////////////////////////////////// | 641 ///////////////////////////////////////////////////////////////////////////// |
641 | 642 |
642 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
& paint) { | 643 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
& paint) { |
643 ASSERT_SINGLE_OWNER | 644 ASSERT_SINGLE_OWNER |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 SkRRect rrect; | 694 SkRRect rrect; |
694 if (origSrcPath.isRRect(&rrect)) { | 695 if (origSrcPath.isRRect(&rrect)) { |
695 this->drawRRect(draw, rrect, paint); | 696 this->drawRRect(draw, rrect, paint); |
696 return; | 697 return; |
697 } | 698 } |
698 } | 699 } |
699 | 700 |
700 CHECK_SHOULD_DRAW(draw); | 701 CHECK_SHOULD_DRAW(draw); |
701 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); | 702 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); |
702 | 703 |
703 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, | 704 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), |
704 fClip, origSrcPath, paint, | 705 fClip, origSrcPath, paint, |
705 *draw.fMatrix, prePathMatrix, | 706 *draw.fMatrix, prePathMatrix, |
706 draw.fClip->getBounds(), pathIsMutable); | 707 draw.fClip->getBounds(), pathIsMutable); |
707 } | 708 } |
708 | 709 |
709 static const int kBmpSmallTileSize = 1 << 10; | 710 static const int kBmpSmallTileSize = 1 << 10; |
710 | 711 |
711 static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { | 712 static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { |
712 int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; | 713 int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; |
713 int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1; | 714 int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1; |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 } | 1839 } |
1839 | 1840 |
1840 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1841 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1841 ASSERT_SINGLE_OWNER | 1842 ASSERT_SINGLE_OWNER |
1842 // We always return a transient cache, so it is freed after each | 1843 // We always return a transient cache, so it is freed after each |
1843 // filter traversal. | 1844 // filter traversal. |
1844 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1845 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1845 } | 1846 } |
1846 | 1847 |
1847 #endif | 1848 #endif |
OLD | NEW |