| 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 "GrContextPriv.h" |
| 9 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
| 10 #include "GrDrawingManager.h" | 11 #include "GrDrawingManager.h" |
| 11 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
| 12 #include "GrResourceCache.h" | 13 #include "GrResourceCache.h" |
| 13 #include "GrResourceProvider.h" | 14 #include "GrResourceProvider.h" |
| 14 #include "GrSoftwarePathRenderer.h" | 15 #include "GrSoftwarePathRenderer.h" |
| 15 #include "GrSurfacePriv.h" | 16 #include "GrSurfacePriv.h" |
| 16 | 17 |
| 17 #include "SkConfig8888.h" | 18 #include "SkConfig8888.h" |
| 18 #include "SkGrPriv.h" | 19 #include "SkGrPriv.h" |
| 19 | 20 |
| 20 #include "batches/GrCopySurfaceBatch.h" | 21 #include "batches/GrCopySurfaceBatch.h" |
| 21 #include "effects/GrConfigConversionEffect.h" | 22 #include "effects/GrConfigConversionEffect.h" |
| 22 #include "effects/GrGammaEffect.h" | 23 #include "effects/GrGammaEffect.h" |
| 23 #include "text/GrTextBlobCache.h" | 24 #include "text/GrTextBlobCache.h" |
| 24 | 25 |
| 25 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 26 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| 26 #define ASSERT_SINGLE_OWNER \ | 27 #define ASSERT_SINGLE_OWNER \ |
| 27 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) | 28 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) |
| 29 #define ASSERT_SINGLE_OWNER_PRIV \ |
| 30 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fContext->fSingleO
wner);) |
| 28 #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; } | 31 #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; } |
| 29 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return
false; } | 32 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return
false; } |
| 30 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return n
ullptr; } | 33 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return n
ullptr; } |
| 31 | 34 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
| 33 | 36 |
| 34 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ | 37 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ |
| 35 GrContextOptions defaultOptions; | 38 GrContextOptions defaultOptions; |
| 36 return Create(backend, backendContext, defaultOptions); | 39 return Create(backend, backendContext, defaultOptions); |
| 37 } | 40 } |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, | 356 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
| 354 tempDrawInfo.fWriteConfig, buffer, | 357 tempDrawInfo.fWriteConfig, buffer, |
| 355 rowBytes)) { | 358 rowBytes)) { |
| 356 return false; | 359 return false; |
| 357 } | 360 } |
| 358 SkMatrix matrix; | 361 SkMatrix matrix; |
| 359 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 362 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 360 // TODO: Need to decide the semantics of this function for color spa
ces. Do we support | 363 // 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 | 364 // 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. | 365 // path will do no conversion, so it will match the behavior of the
non-draw path. |
| 363 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(ren
derTarget), nullptr)); | 366 sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDraw
Context( |
| 367 sk_ref_s
p(renderTarget), |
| 368 nullptr)
); |
| 364 if (!drawContext) { | 369 if (!drawContext) { |
| 365 return false; | 370 return false; |
| 366 } | 371 } |
| 367 GrPaint paint; | 372 GrPaint paint; |
| 368 paint.addColorFragmentProcessor(std::move(fp)); | 373 paint.addColorFragmentProcessor(std::move(fp)); |
| 369 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 374 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 370 paint.setAllowSRGBInputs(true); | 375 paint.setAllowSRGBInputs(true); |
| 371 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 376 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
| 372 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); | 377 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); |
| 373 | 378 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 return false; | 566 return false; |
| 562 } | 567 } |
| 563 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the | 568 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the |
| 564 // the copy surface into. In the future we plan to have a more limited C
ontext type | 569 // the copy surface into. In the future we plan to have a more limited C
ontext type |
| 565 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be | 570 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be |
| 566 // allowed on textures that aren't render targets. | 571 // allowed on textures that aren't render targets. |
| 567 // For now we just flush any writes to the src and issue an immediate co
py to the dst. | 572 // For now we just flush any writes to the src and issue an immediate co
py to the dst. |
| 568 src->flushWrites(); | 573 src->flushWrites(); |
| 569 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); | 574 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); |
| 570 } | 575 } |
| 571 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(dst->asRend
erTarget()), nullptr)); | 576 sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( |
| 577 sk_ref_sp(dst->a
sRenderTarget()), |
| 578 nullptr)); |
| 572 if (!drawContext) { | 579 if (!drawContext) { |
| 573 return false; | 580 return false; |
| 574 } | 581 } |
| 575 | 582 |
| 576 if (!drawContext->copySurface(src, srcRect, dstPoint)) { | 583 if (!drawContext->copySurface(src, srcRect, dstPoint)) { |
| 577 return false; | 584 return false; |
| 578 } | 585 } |
| 579 return true; | 586 return true; |
| 580 } | 587 } |
| 581 | 588 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 599 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { | 606 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
| 600 if (dpi >= 250.0f) { | 607 if (dpi >= 250.0f) { |
| 601 chosenSampleCount = 4; | 608 chosenSampleCount = 4; |
| 602 } else { | 609 } else { |
| 603 chosenSampleCount = 16; | 610 chosenSampleCount = 16; |
| 604 } | 611 } |
| 605 } | 612 } |
| 606 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; | 613 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; |
| 607 } | 614 } |
| 608 | 615 |
| 616 sk_sp<GrDrawContext> GrContextPriv::makeWrappedDrawContext(sk_sp<GrRenderTarget>
rt, |
| 617 sk_sp<SkColorSpace> c
olorSpace, |
| 618 const SkSurfaceProps*
surfaceProps) { |
| 619 ASSERT_SINGLE_OWNER_PRIV |
| 620 return fContext->drawingManager()->drawContext(std::move(rt), std::move(colo
rSpace), |
| 621 surfaceProps); |
| 622 } |
| 609 | 623 |
| 610 sk_sp<GrDrawContext> GrContext::makeDrawContext(sk_sp<GrRenderTarget> rt, | 624 sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureDrawContext(const GrBacken
dTextureDesc& desc, |
| 611 sk_sp<SkColorSpace> colorSpace, | 625 sk_sp<SkColorS
pace> colorSpace, |
| 612 const SkSurfaceProps* surfaceProps)
{ | 626 const SkSurfac
eProps* props, |
| 613 ASSERT_SINGLE_OWNER | 627 GrWrapOwnershi
p ownership) { |
| 614 return fDrawingManager->drawContext(std::move(rt), std::move(colorSpace), su
rfaceProps); | 628 ASSERT_SINGLE_OWNER_PRIV |
| 629 SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); |
| 630 |
| 631 sk_sp<GrSurface> surface(fContext->textureProvider()->wrapBackendTexture(des
c, ownership)); |
| 632 if (!surface) { |
| 633 return nullptr; |
| 634 } |
| 635 |
| 636 return fContext->drawingManager()->drawContext(sk_ref_sp(surface->asRenderTa
rget()), |
| 637 std::move(colorSpace), props)
; |
| 638 } |
| 639 |
| 640 sk_sp<GrDrawContext> GrContextPriv::makeBackendRenderTargetDrawContext( |
| 641 const GrBackendRenderTargetDesc&
desc, |
| 642 sk_sp<SkColorSpace> colorSpace, |
| 643 const SkSurfaceProps* surfacePro
ps) { |
| 644 ASSERT_SINGLE_OWNER_PRIV |
| 645 |
| 646 sk_sp<GrRenderTarget> rt(fContext->textureProvider()->wrapBackendRenderTarge
t(desc)); |
| 647 if (!rt) { |
| 648 return nullptr; |
| 649 } |
| 650 |
| 651 return fContext->drawingManager()->drawContext(std::move(rt), std::move(colo
rSpace), |
| 652 surfaceProps); |
| 653 } |
| 654 |
| 655 sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureAsRenderTargetDrawContext( |
| 656 const GrBackendTextureDesc&
desc, |
| 657 sk_sp<SkColorSpace> colorSp
ace, |
| 658 const SkSurfaceProps* surfa
ceProps) { |
| 659 ASSERT_SINGLE_OWNER_PRIV |
| 660 SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); |
| 661 |
| 662 sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsR
enderTarget(desc)); |
| 663 if (!surface) { |
| 664 return nullptr; |
| 665 } |
| 666 |
| 667 return fContext->drawingManager()->drawContext(sk_ref_sp(surface->asRenderTa
rget()), |
| 668 std::move(colorSpace), surfac
eProps); |
| 615 } | 669 } |
| 616 | 670 |
| 617 sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit, | 671 sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit, |
| 618 int width, int height, | 672 int width, int height, |
| 619 GrPixelConfig config, | 673 GrPixelConfig config, |
| 620 sk_sp<SkColorSpace> colorSpace, | 674 sk_sp<SkColorSpace> colorSpace, |
| 621 int sampleCnt, | 675 int sampleCnt, |
| 622 GrSurfaceOrigin origin, | 676 GrSurfaceOrigin origin, |
| 623 const SkSurfaceProps* surfacePro
ps, | 677 const SkSurfaceProps* surfacePro
ps, |
| 624 SkBudgeted budgeted) { | 678 SkBudgeted budgeted) { |
| 625 GrSurfaceDesc desc; | 679 GrSurfaceDesc desc; |
| 626 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 680 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 627 desc.fOrigin = origin; | 681 desc.fOrigin = origin; |
| 628 desc.fWidth = width; | 682 desc.fWidth = width; |
| 629 desc.fHeight = height; | 683 desc.fHeight = height; |
| 630 desc.fConfig = config; | 684 desc.fConfig = config; |
| 631 desc.fSampleCnt = sampleCnt; | 685 desc.fSampleCnt = sampleCnt; |
| 632 | 686 |
| 633 sk_sp<GrTexture> tex; | 687 sk_sp<GrTexture> tex; |
| 634 if (SkBackingFit::kExact == fit) { | 688 if (SkBackingFit::kExact == fit) { |
| 635 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); | 689 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); |
| 636 } else { | 690 } else { |
| 637 tex.reset(this->textureProvider()->createApproxTexture(desc)); | 691 tex.reset(this->textureProvider()->createApproxTexture(desc)); |
| 638 } | 692 } |
| 639 if (!tex) { | 693 if (!tex) { |
| 640 return nullptr; | 694 return nullptr; |
| 641 } | 695 } |
| 642 | 696 |
| 643 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(tex->asRend
erTarget()), | 697 sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( |
| 698 sk_ref_sp(tex->asRend
erTarget()), |
| 644 std::move(colorSpace)
, surfaceProps)); | 699 std::move(colorSpace)
, surfaceProps)); |
| 645 if (!drawContext) { | 700 if (!drawContext) { |
| 646 return nullptr; | 701 return nullptr; |
| 647 } | 702 } |
| 648 | 703 |
| 649 return drawContext; | 704 return drawContext; |
| 650 } | 705 } |
| 651 | 706 |
| 652 bool GrContext::abandoned() const { | 707 bool GrContext::abandoned() const { |
| 653 ASSERT_SINGLE_OWNER | 708 ASSERT_SINGLE_OWNER |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 ASSERT_SINGLE_OWNER | 784 ASSERT_SINGLE_OWNER |
| 730 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 785 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 731 } | 786 } |
| 732 | 787 |
| 733 ////////////////////////////////////////////////////////////////////////////// | 788 ////////////////////////////////////////////////////////////////////////////// |
| 734 | 789 |
| 735 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 790 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 736 ASSERT_SINGLE_OWNER | 791 ASSERT_SINGLE_OWNER |
| 737 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 792 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 738 } | 793 } |
| OLD | NEW |