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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // TODO: Need to decide the semantics of this function for color spa
ces. Do we support | 360 // TODO: Need to decide the semantics of this function for color spa
ces. Do we support |
361 // conversion from a passed-in color space? For now, specifying null
ptr means that this | 361 // conversion from a passed-in color space? For now, specifying null
ptr means that this |
362 // path will do no conversion, so it will match the behavior of the
non-draw path. | 362 // path will do no conversion, so it will match the behavior of the
non-draw path. |
363 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderT
arget), nullptr)); | 363 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(ren
derTarget), nullptr)); |
364 if (!drawContext) { | 364 if (!drawContext) { |
365 return false; | 365 return false; |
366 } | 366 } |
367 GrPaint paint; | 367 GrPaint paint; |
368 paint.addColorFragmentProcessor(std::move(fp)); | 368 paint.addColorFragmentProcessor(std::move(fp)); |
369 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 369 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
370 paint.setAllowSRGBInputs(true); | 370 paint.setAllowSRGBInputs(true); |
371 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 371 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
372 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); | 372 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); |
373 | 373 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { | 443 if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { |
444 // We only respect this when the entire src is being read. Otherwise
we can trigger too | 444 // We only respect this when the entire src is being read. Otherwise
we can trigger too |
445 // many odd ball texture sizes and trash the cache. | 445 // many odd ball texture sizes and trash the cache. |
446 if (width != src->width() || height != src->height()) { | 446 if (width != src->width() || height != src->height()) { |
447 tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; | 447 tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; |
448 } | 448 } |
449 } | 449 } |
450 // TODO: Need to decide the semantics of this function for color spaces.
Do we support | 450 // TODO: Need to decide the semantics of this function for color spaces.
Do we support |
451 // conversion to a passed-in color space? For now, specifying nullptr me
ans that this | 451 // conversion to a passed-in color space? For now, specifying nullptr me
ans that this |
452 // path will do no conversion, so it will match the behavior of the non-
draw path. | 452 // path will do no conversion, so it will match the behavior of the non-
draw path. |
453 sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSur
faceFit, | 453 sk_sp<GrDrawContext> tempDC = this->makeDrawContext(tempDrawInfo.fTempSu
rfaceFit, |
454 tempDrawInfo.fTempSur
faceDesc.fWidth, | 454 tempDrawInfo.fTempSur
faceDesc.fWidth, |
455 tempDrawInfo.fTempSur
faceDesc.fHeight, | 455 tempDrawInfo.fTempSur
faceDesc.fHeight, |
456 tempDrawInfo.fTempSur
faceDesc.fConfig, | 456 tempDrawInfo.fTempSur
faceDesc.fConfig, |
457 nullptr, | 457 nullptr, |
458 tempDrawInfo.fTempSur
faceDesc.fSampleCnt, | 458 tempDrawInfo.fTempSur
faceDesc.fSampleCnt, |
459 tempDrawInfo.fTempSur
faceDesc.fOrigin); | 459 tempDrawInfo.fTempSur
faceDesc.fOrigin); |
460 if (tempDC) { | 460 if (tempDC) { |
461 SkMatrix textureMatrix; | 461 SkMatrix textureMatrix; |
462 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 462 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
463 textureMatrix.postIDiv(src->width(), src->height()); | 463 textureMatrix.postIDiv(src->width(), src->height()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 ASSERT_OWNED_RESOURCE(dst); | 533 ASSERT_OWNED_RESOURCE(dst); |
534 ASSERT_OWNED_RESOURCE(src); | 534 ASSERT_OWNED_RESOURCE(src); |
535 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); | 535 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); |
536 | 536 |
537 // Dimensions must match exactly. | 537 // Dimensions must match exactly. |
538 if (dst->width() != src->width() || dst->height() != src->height()) { | 538 if (dst->width() != src->width() || dst->height() != src->height()) { |
539 return false; | 539 return false; |
540 } | 540 } |
541 | 541 |
542 // TODO: Supply color space? | 542 // TODO: Supply color space? |
543 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), nullptr))
; | 543 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(dst), nullp
tr)); |
544 if (!drawContext) { | 544 if (!drawContext) { |
545 return false; | 545 return false; |
546 } | 546 } |
547 | 547 |
548 GrPaint paint; | 548 GrPaint paint; |
549 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText
ureWHMatrix(src)); | 549 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText
ureWHMatrix(src)); |
550 if (!SkScalarNearlyEqual(gamma, 1.0f)) { | 550 if (!SkScalarNearlyEqual(gamma, 1.0f)) { |
551 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); | 551 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); |
552 } | 552 } |
553 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 553 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 return false; | 595 return false; |
596 } | 596 } |
597 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the | 597 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the |
598 // the copy surface into. In the future we plan to have a more limited C
ontext type | 598 // the copy surface into. In the future we plan to have a more limited C
ontext type |
599 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be | 599 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be |
600 // allowed on textures that aren't render targets. | 600 // allowed on textures that aren't render targets. |
601 // For now we just flush any writes to the src and issue an immediate co
py to the dst. | 601 // For now we just flush any writes to the src and issue an immediate co
py to the dst. |
602 src->flushWrites(); | 602 src->flushWrites(); |
603 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); | 603 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); |
604 } | 604 } |
605 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTa
rget()), nullptr)); | 605 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(dst->asRend
erTarget()), nullptr)); |
606 if (!drawContext) { | 606 if (!drawContext) { |
607 return false; | 607 return false; |
608 } | 608 } |
609 | 609 |
610 if (!drawContext->copySurface(src, srcRect, dstPoint)) { | 610 if (!drawContext->copySurface(src, srcRect, dstPoint)) { |
611 return false; | 611 return false; |
612 } | 612 } |
613 return true; | 613 return true; |
614 } | 614 } |
615 | 615 |
(...skipping 18 matching lines...) Expand all Loading... |
634 if (dpi >= 250.0f) { | 634 if (dpi >= 250.0f) { |
635 chosenSampleCount = 4; | 635 chosenSampleCount = 4; |
636 } else { | 636 } else { |
637 chosenSampleCount = 16; | 637 chosenSampleCount = 16; |
638 } | 638 } |
639 } | 639 } |
640 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; | 640 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; |
641 } | 641 } |
642 | 642 |
643 | 643 |
644 sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, | 644 sk_sp<GrDrawContext> GrContext::makeDrawContext(sk_sp<GrRenderTarget> rt, |
645 sk_sp<SkColorSpace> colorSpace, | 645 sk_sp<SkColorSpace> colorSpace, |
646 const SkSurfaceProps* surfaceProps)
{ | 646 const SkSurfaceProps* surfaceProps)
{ |
647 ASSERT_SINGLE_OWNER | 647 ASSERT_SINGLE_OWNER |
648 return fDrawingManager->drawContext(std::move(rt), std::move(colorSpace), su
rfaceProps); | 648 return fDrawingManager->drawContext(std::move(rt), std::move(colorSpace), su
rfaceProps); |
649 } | 649 } |
650 | 650 |
651 sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, | 651 sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit, |
652 int width, int height, | 652 int width, int height, |
653 GrPixelConfig config, | 653 GrPixelConfig config, |
654 sk_sp<SkColorSpace> colorSpace, | 654 sk_sp<SkColorSpace> colorSpace, |
655 int sampleCnt, | 655 int sampleCnt, |
656 GrSurfaceOrigin origin, | 656 GrSurfaceOrigin origin, |
657 const SkSurfaceProps* surfaceProp
s, | 657 const SkSurfaceProps* surfacePro
ps, |
658 SkBudgeted budgeted) { | 658 SkBudgeted budgeted) { |
659 GrSurfaceDesc desc; | 659 GrSurfaceDesc desc; |
660 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 660 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
661 desc.fOrigin = origin; | 661 desc.fOrigin = origin; |
662 desc.fWidth = width; | 662 desc.fWidth = width; |
663 desc.fHeight = height; | 663 desc.fHeight = height; |
664 desc.fConfig = config; | 664 desc.fConfig = config; |
665 desc.fSampleCnt = sampleCnt; | 665 desc.fSampleCnt = sampleCnt; |
666 | 666 |
667 sk_sp<GrTexture> tex; | 667 sk_sp<GrTexture> tex; |
668 if (SkBackingFit::kExact == fit) { | 668 if (SkBackingFit::kExact == fit) { |
669 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); | 669 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); |
670 } else { | 670 } else { |
671 tex.reset(this->textureProvider()->createApproxTexture(desc)); | 671 tex.reset(this->textureProvider()->createApproxTexture(desc)); |
672 } | 672 } |
673 if (!tex) { | 673 if (!tex) { |
674 return nullptr; | 674 return nullptr; |
675 } | 675 } |
676 | 676 |
677 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTa
rget()), | 677 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(tex->asRend
erTarget()), |
678 std::move(colorSpace), su
rfaceProps)); | 678 std::move(colorSpace)
, surfaceProps)); |
679 if (!drawContext) { | 679 if (!drawContext) { |
680 return nullptr; | 680 return nullptr; |
681 } | 681 } |
682 | 682 |
683 return drawContext; | 683 return drawContext; |
684 } | 684 } |
685 | 685 |
686 bool GrContext::abandoned() const { | 686 bool GrContext::abandoned() const { |
687 ASSERT_SINGLE_OWNER | 687 ASSERT_SINGLE_OWNER |
688 return fDrawingManager->wasAbandoned(); | 688 return fDrawingManager->wasAbandoned(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 ASSERT_SINGLE_OWNER | 763 ASSERT_SINGLE_OWNER |
764 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 764 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
765 } | 765 } |
766 | 766 |
767 ////////////////////////////////////////////////////////////////////////////// | 767 ////////////////////////////////////////////////////////////////////////////// |
768 | 768 |
769 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 769 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
770 ASSERT_SINGLE_OWNER | 770 ASSERT_SINGLE_OWNER |
771 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 771 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
772 } | 772 } |
OLD | NEW |