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 "GrContext.h" | 8 #include "GrContext.h" |
9 #include "GrContextOptions.h" | 9 #include "GrContextOptions.h" |
10 #include "GrDrawingManager.h" | 10 #include "GrDrawingManager.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 buffer = tmpPixels.get(); | 350 buffer = tmpPixels.get(); |
351 applyPremulToSrc = false; | 351 applyPremulToSrc = false; |
352 } | 352 } |
353 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, | 353 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
354 tempDrawInfo.fWriteConfig, buffer, | 354 tempDrawInfo.fWriteConfig, buffer, |
355 rowBytes)) { | 355 rowBytes)) { |
356 return false; | 356 return false; |
357 } | 357 } |
358 SkMatrix matrix; | 358 SkMatrix matrix; |
359 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 359 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
360 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderT
arget))); | 360 sk_sp<GrDrawContext> drawContext(this->drawContext(surface->width(),
surface->height(), |
| 361 sk_ref_sp(renderT
arget))); |
361 if (!drawContext) { | 362 if (!drawContext) { |
362 return false; | 363 return false; |
363 } | 364 } |
364 GrPaint paint; | 365 GrPaint paint; |
365 paint.addColorFragmentProcessor(std::move(fp)); | 366 paint.addColorFragmentProcessor(std::move(fp)); |
366 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 367 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
367 paint.setAllowSRGBInputs(true); | 368 paint.setAllowSRGBInputs(true); |
368 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 369 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
369 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); | 370 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); |
370 | 371 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 ASSERT_OWNED_RESOURCE(src); | 528 ASSERT_OWNED_RESOURCE(src); |
528 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); | 529 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); |
529 | 530 |
530 // Dimensions must match exactly. | 531 // Dimensions must match exactly. |
531 if (dst->width() != src->width() || dst->height() != src->height()) { | 532 if (dst->width() != src->width() || dst->height() != src->height()) { |
532 return false; | 533 return false; |
533 } | 534 } |
534 | 535 |
535 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, | 536 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, |
536 SkSurfaceProps::kLegacyFontHost_InitType); | 537 SkSurfaceProps::kLegacyFontHost_InitType); |
537 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); | 538 sk_sp<GrDrawContext> drawContext(this->drawContext(dst->width(), dst->height
(), |
| 539 sk_ref_sp(dst), &props)); |
538 if (!drawContext) { | 540 if (!drawContext) { |
539 return false; | 541 return false; |
540 } | 542 } |
541 | 543 |
542 GrPaint paint; | 544 GrPaint paint; |
543 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText
ureWHMatrix(src)); | 545 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText
ureWHMatrix(src)); |
544 if (!SkScalarNearlyEqual(gamma, 1.0f)) { | 546 if (!SkScalarNearlyEqual(gamma, 1.0f)) { |
545 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); | 547 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); |
546 } | 548 } |
547 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 549 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 return false; | 591 return false; |
590 } | 592 } |
591 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the | 593 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the |
592 // the copy surface into. In the future we plan to have a more limited C
ontext type | 594 // the copy surface into. In the future we plan to have a more limited C
ontext type |
593 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be | 595 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be |
594 // allowed on textures that aren't render targets. | 596 // allowed on textures that aren't render targets. |
595 // For now we just flush any writes to the src and issue an immediate co
py to the dst. | 597 // For now we just flush any writes to the src and issue an immediate co
py to the dst. |
596 src->flushWrites(); | 598 src->flushWrites(); |
597 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); | 599 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); |
598 } | 600 } |
599 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTa
rget()))); | 601 sk_sp<GrDrawContext> drawContext(this->drawContext(dst->width(), dst->height
(), |
| 602 sk_ref_sp(dst->asRenderTa
rget()))); |
600 if (!drawContext) { | 603 if (!drawContext) { |
601 return false; | 604 return false; |
602 } | 605 } |
603 | 606 |
604 if (!drawContext->copySurface(src, srcRect, dstPoint)) { | 607 if (!drawContext->copySurface(src, srcRect, dstPoint)) { |
605 return false; | 608 return false; |
606 } | 609 } |
607 return true; | 610 return true; |
608 } | 611 } |
609 | 612 |
(...skipping 18 matching lines...) Expand all Loading... |
628 if (dpi >= 250.0f) { | 631 if (dpi >= 250.0f) { |
629 chosenSampleCount = 4; | 632 chosenSampleCount = 4; |
630 } else { | 633 } else { |
631 chosenSampleCount = 16; | 634 chosenSampleCount = 16; |
632 } | 635 } |
633 } | 636 } |
634 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; | 637 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; |
635 } | 638 } |
636 | 639 |
637 | 640 |
638 sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, | 641 sk_sp<GrDrawContext> GrContext::drawContext(int width, int height, sk_sp<GrRende
rTarget> rt, |
639 const SkSurfaceProps* surfaceProps)
{ | 642 const SkSurfaceProps* surfaceProps)
{ |
640 ASSERT_SINGLE_OWNER | 643 ASSERT_SINGLE_OWNER |
641 return fDrawingManager->drawContext(std::move(rt), surfaceProps); | 644 return fDrawingManager->drawContext(width, height, std::move(rt), surfacePro
ps); |
642 } | 645 } |
643 | 646 |
644 sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, | 647 sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, |
645 int width, int height, | 648 int width, int height, |
646 GrPixelConfig config, | 649 GrPixelConfig config, |
647 int sampleCnt, | 650 int sampleCnt, |
648 GrSurfaceOrigin origin, | 651 GrSurfaceOrigin origin, |
649 const SkSurfaceProps* surfaceProp
s, | 652 const SkSurfaceProps* surfaceProp
s, |
650 SkBudgeted budgeted) { | 653 SkBudgeted budgeted) { |
651 GrSurfaceDesc desc; | 654 GrSurfaceDesc desc; |
652 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 655 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
653 desc.fOrigin = origin; | 656 desc.fOrigin = origin; |
654 desc.fWidth = width; | 657 desc.fWidth = width; |
655 desc.fHeight = height; | 658 desc.fHeight = height; |
656 desc.fConfig = config; | 659 desc.fConfig = config; |
657 desc.fSampleCnt = sampleCnt; | 660 desc.fSampleCnt = sampleCnt; |
658 | 661 |
659 sk_sp<GrTexture> tex; | 662 sk_sp<GrTexture> tex; |
660 if (SkBackingFit::kExact == fit) { | 663 if (SkBackingFit::kExact == fit) { |
661 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); | 664 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); |
662 } else { | 665 } else { |
663 tex.reset(this->textureProvider()->createApproxTexture(desc)); | 666 tex.reset(this->textureProvider()->createApproxTexture(desc)); |
664 } | 667 } |
665 if (!tex) { | 668 if (!tex) { |
666 return nullptr; | 669 return nullptr; |
667 } | 670 } |
668 | 671 |
669 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTa
rget()), | 672 sk_sp<GrDrawContext> drawContext(fDrawingManager->drawContext(width, height, |
670 surfaceProps)); | 673 sk_ref_sp(tex-
>asRenderTarget()), |
| 674 surfaceProps))
; |
671 if (!drawContext) { | 675 if (!drawContext) { |
672 return nullptr; | 676 return nullptr; |
673 } | 677 } |
674 | 678 |
675 return drawContext; | 679 return drawContext; |
676 } | 680 } |
677 | 681 |
678 bool GrContext::abandoned() const { | 682 bool GrContext::abandoned() const { |
679 ASSERT_SINGLE_OWNER | 683 ASSERT_SINGLE_OWNER |
680 return fDrawingManager->wasAbandoned(); | 684 return fDrawingManager->wasAbandoned(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 ASSERT_SINGLE_OWNER | 759 ASSERT_SINGLE_OWNER |
756 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 760 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
757 } | 761 } |
758 | 762 |
759 ////////////////////////////////////////////////////////////////////////////// | 763 ////////////////////////////////////////////////////////////////////////////// |
760 | 764 |
761 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 765 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
762 ASSERT_SINGLE_OWNER | 766 ASSERT_SINGLE_OWNER |
763 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 767 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
764 } | 768 } |
OLD | NEW |