| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 | 10 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 dstPI.fRowBytes = outRowBytes; | 322 dstPI.fRowBytes = outRowBytes; |
| 323 | 323 |
| 324 return srcPI.convertPixelsTo(&dstPI, width, height); | 324 return srcPI.convertPixelsTo(&dstPI, width, height); |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool GrContext::writeSurfacePixels(GrSurface* surface, | 327 bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 328 int left, int top, int width, int height, | 328 int left, int top, int width, int height, |
| 329 GrPixelConfig srcConfig, const void* buffer,
size_t rowBytes, | 329 GrPixelConfig srcConfig, const void* buffer,
size_t rowBytes, |
| 330 uint32_t pixelOpsFlags) { | 330 uint32_t pixelOpsFlags) { |
| 331 RETURN_FALSE_IF_ABANDONED | 331 RETURN_FALSE_IF_ABANDONED |
| 332 ASSERT_OWNED_RESOURCE(surface); |
| 333 SkASSERT(surface); |
| 334 |
| 335 this->testPMConversionsIfNecessary(pixelOpsFlags); |
| 332 | 336 |
| 333 // Trim the params here so that if we wind up making a temporary surface it
can be as small as | 337 // Trim the params here so that if we wind up making a temporary surface it
can be as small as |
| 334 // necessary and because GrGpu::getWritePixelsInfo requires it. | 338 // necessary and because GrGpu::getWritePixelsInfo requires it. |
| 335 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height
(), | 339 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height
(), |
| 336 GrBytesPerPixel(srcConfig), &left
, &top, &width, | 340 GrBytesPerPixel(srcConfig), &left
, &top, &width, |
| 337 &height, &buffer, &rowBytes)) { | 341 &height, &buffer, &rowBytes)) { |
| 338 return false; | 342 return false; |
| 339 } | 343 } |
| 340 | 344 |
| 341 bool applyPremulToSrc = false; | 345 bool applyPremulToSrc = false; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 458 } |
| 455 | 459 |
| 456 bool GrContext::readSurfacePixels(GrSurface* src, | 460 bool GrContext::readSurfacePixels(GrSurface* src, |
| 457 int left, int top, int width, int height, | 461 int left, int top, int width, int height, |
| 458 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, | 462 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, |
| 459 uint32_t flags) { | 463 uint32_t flags) { |
| 460 RETURN_FALSE_IF_ABANDONED | 464 RETURN_FALSE_IF_ABANDONED |
| 461 ASSERT_OWNED_RESOURCE(src); | 465 ASSERT_OWNED_RESOURCE(src); |
| 462 SkASSERT(src); | 466 SkASSERT(src); |
| 463 | 467 |
| 468 this->testPMConversionsIfNecessary(flags); |
| 469 SkAutoMutexAcquire ama(fReadPixelsMutex); |
| 470 |
| 464 // Adjust the params so that if we wind up using an intermediate surface we'
ve already done | 471 // Adjust the params so that if we wind up using an intermediate surface we'
ve already done |
| 465 // all the trimming and the temporary can be the min size required. | 472 // all the trimming and the temporary can be the min size required. |
| 466 if (!GrSurfacePriv::AdjustReadPixelParams(src->width(), src->height(), | 473 if (!GrSurfacePriv::AdjustReadPixelParams(src->width(), src->height(), |
| 467 GrBytesPerPixel(dstConfig), &left, | 474 GrBytesPerPixel(dstConfig), &left, |
| 468 &top, &width, &height, &buffer, &r
owBytes)) { | 475 &top, &width, &height, &buffer, &r
owBytes)) { |
| 469 return false; | 476 return false; |
| 470 } | 477 } |
| 471 | 478 |
| 472 if (!(kDontFlush_PixelOpsFlag & flags) && src->surfacePriv().hasPendingWrite
()) { | 479 if (!(kDontFlush_PixelOpsFlag & flags) && src->surfacePriv().hasPendingWrite
()) { |
| 473 this->flush(); | 480 this->flush(); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 namespace { | 694 namespace { |
| 688 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 695 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 689 GrConfigConversionEffect::PMConversion pmToUPM; | 696 GrConfigConversionEffect::PMConversion pmToUPM; |
| 690 GrConfigConversionEffect::PMConversion upmToPM; | 697 GrConfigConversionEffect::PMConversion upmToPM; |
| 691 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); | 698 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); |
| 692 *pmToUPMValue = pmToUPM; | 699 *pmToUPMValue = pmToUPM; |
| 693 *upmToPMValue = upmToPM; | 700 *upmToPMValue = upmToPM; |
| 694 } | 701 } |
| 695 } | 702 } |
| 696 | 703 |
| 704 void GrContext::testPMConversionsIfNecessary(uint32_t flags) { |
| 705 if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { |
| 706 SkAutoMutexAcquire ama(fTestPMConversionsMutex); |
| 707 if (!fDidTestPMConversions) { |
| 708 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 709 fDidTestPMConversions = true; |
| 710 } |
| 711 } |
| 712 } |
| 713 |
| 697 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrProcessorDataManager
* procDataManager, | 714 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrProcessorDataManager
* procDataManager, |
| 698 GrTexture* texture, | 715 GrTexture* texture, |
| 699 bool swapRAndB, | 716 bool swapRAndB, |
| 700 const SkMatrix& matrix
) { | 717 const SkMatrix& matrix
) const { |
| 701 if (!fDidTestPMConversions) { | 718 // We should have already called this->testPMConversionsIfNecessary(). |
| 702 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 719 SkASSERT(fDidTestPMConversions); |
| 703 fDidTestPMConversions = true; | |
| 704 } | |
| 705 GrConfigConversionEffect::PMConversion pmToUPM = | 720 GrConfigConversionEffect::PMConversion pmToUPM = |
| 706 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); | 721 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 707 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { | 722 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
| 708 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, pmToUPM, | 723 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, pmToUPM, |
| 709 matrix); | 724 matrix); |
| 710 } else { | 725 } else { |
| 711 return nullptr; | 726 return nullptr; |
| 712 } | 727 } |
| 713 } | 728 } |
| 714 | 729 |
| 715 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrProcessorDataManager
* procDataManager, | 730 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrProcessorDataManager
* procDataManager, |
| 716 GrTexture* texture, | 731 GrTexture* texture, |
| 717 bool swapRAndB, | 732 bool swapRAndB, |
| 718 const SkMatrix& matrix
) { | 733 const SkMatrix& matrix
) const { |
| 719 if (!fDidTestPMConversions) { | 734 // We should have already called this->testPMConversionsIfNecessary(). |
| 720 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 735 SkASSERT(fDidTestPMConversions); |
| 721 fDidTestPMConversions = true; | |
| 722 } | |
| 723 GrConfigConversionEffect::PMConversion upmToPM = | 736 GrConfigConversionEffect::PMConversion upmToPM = |
| 724 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); | 737 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 725 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { | 738 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
| 726 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, upmToPM, | 739 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, upmToPM, |
| 727 matrix); | 740 matrix); |
| 728 } else { | 741 } else { |
| 729 return nullptr; | 742 return nullptr; |
| 730 } | 743 } |
| 731 } | 744 } |
| 732 | 745 |
| 733 bool GrContext::didFailPMUPMConversionTest() const { | 746 bool GrContext::didFailPMUPMConversionTest() const { |
| 747 // We should have already called this->testPMConversionsIfNecessary(). |
| 748 SkASSERT(fDidTestPMConversions); |
| 734 // The PM<->UPM tests fail or succeed together so we only need to check one. | 749 // The PM<->UPM tests fail or succeed together so we only need to check one. |
| 735 return fDidTestPMConversions && | 750 return GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; |
| 736 GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; | |
| 737 } | 751 } |
| 738 | 752 |
| 739 ////////////////////////////////////////////////////////////////////////////// | 753 ////////////////////////////////////////////////////////////////////////////// |
| 740 | 754 |
| 741 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { | 755 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { |
| 742 if (maxTextures) { | 756 if (maxTextures) { |
| 743 *maxTextures = fResourceCache->getMaxResourceCount(); | 757 *maxTextures = fResourceCache->getMaxResourceCount(); |
| 744 } | 758 } |
| 745 if (maxTextureBytes) { | 759 if (maxTextureBytes) { |
| 746 *maxTextureBytes = fResourceCache->getMaxResourceBytes(); | 760 *maxTextureBytes = fResourceCache->getMaxResourceBytes(); |
| 747 } | 761 } |
| 748 } | 762 } |
| 749 | 763 |
| 750 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 764 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
| 751 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 765 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 752 } | 766 } |
| 753 | 767 |
| OLD | NEW |