| 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 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 match = kExact_ScratchTexMatch; | 1475 match = kExact_ScratchTexMatch; |
| 1476 } | 1476 } |
| 1477 ast.set(this, desc, match); | 1477 ast.set(this, desc, match); |
| 1478 GrTexture* texture = ast.texture(); | 1478 GrTexture* texture = ast.texture(); |
| 1479 if (texture) { | 1479 if (texture) { |
| 1480 // compute a matrix to perform the draw | 1480 // compute a matrix to perform the draw |
| 1481 SkMatrix textureMatrix; | 1481 SkMatrix textureMatrix; |
| 1482 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); | 1482 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); |
| 1483 textureMatrix.postIDiv(src->width(), src->height()); | 1483 textureMatrix.postIDiv(src->width(), src->height()); |
| 1484 | 1484 |
| 1485 SkAutoTUnref<const GrEffectRef> effect; | 1485 SkAutoTUnref<const GrEffect> effect; |
| 1486 if (unpremul) { | 1486 if (unpremul) { |
| 1487 effect.reset(this->createPMToUPMEffect(src, swapRAndB, textureMa
trix)); | 1487 effect.reset(this->createPMToUPMEffect(src, swapRAndB, textureMa
trix)); |
| 1488 if (NULL != effect) { | 1488 if (NULL != effect) { |
| 1489 unpremul = false; // we no longer need to do this on CPU aft
er the read back. | 1489 unpremul = false; // we no longer need to do this on CPU aft
er the read back. |
| 1490 } | 1490 } |
| 1491 } | 1491 } |
| 1492 // If we failed to create a PM->UPM effect and have no other convers
ions to perform then | 1492 // If we failed to create a PM->UPM effect and have no other convers
ions to perform then |
| 1493 // there is no longer any point to using the scratch. | 1493 // there is no longer any point to using the scratch. |
| 1494 if (NULL != effect || flipY || swapRAndB) { | 1494 if (NULL != effect || flipY || swapRAndB) { |
| 1495 if (!effect) { | 1495 if (!effect) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1647 GrTextureDesc desc; | 1647 GrTextureDesc desc; |
| 1648 desc.fWidth = width; | 1648 desc.fWidth = width; |
| 1649 desc.fHeight = height; | 1649 desc.fHeight = height; |
| 1650 desc.fConfig = writeConfig; | 1650 desc.fConfig = writeConfig; |
| 1651 GrAutoScratchTexture ast(this, desc); | 1651 GrAutoScratchTexture ast(this, desc); |
| 1652 GrTexture* texture = ast.texture(); | 1652 GrTexture* texture = ast.texture(); |
| 1653 if (NULL == texture) { | 1653 if (NULL == texture) { |
| 1654 return false; | 1654 return false; |
| 1655 } | 1655 } |
| 1656 | 1656 |
| 1657 SkAutoTUnref<const GrEffectRef> effect; | 1657 SkAutoTUnref<const GrEffect> effect; |
| 1658 SkMatrix textureMatrix; | 1658 SkMatrix textureMatrix; |
| 1659 textureMatrix.setIDiv(texture->width(), texture->height()); | 1659 textureMatrix.setIDiv(texture->width(), texture->height()); |
| 1660 | 1660 |
| 1661 // allocate a tmp buffer and sw convert the pixels to premul | 1661 // allocate a tmp buffer and sw convert the pixels to premul |
| 1662 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 1662 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 1663 | 1663 |
| 1664 if (kUnpremul_PixelOpsFlag & flags) { | 1664 if (kUnpremul_PixelOpsFlag & flags) { |
| 1665 if (!GrPixelConfigIs8888(srcConfig)) { | 1665 if (!GrPixelConfigIs8888(srcConfig)) { |
| 1666 return false; | 1666 return false; |
| 1667 } | 1667 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 namespace { | 1854 namespace { |
| 1855 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 1855 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 1856 GrConfigConversionEffect::PMConversion pmToUPM; | 1856 GrConfigConversionEffect::PMConversion pmToUPM; |
| 1857 GrConfigConversionEffect::PMConversion upmToPM; | 1857 GrConfigConversionEffect::PMConversion upmToPM; |
| 1858 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); | 1858 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); |
| 1859 *pmToUPMValue = pmToUPM; | 1859 *pmToUPMValue = pmToUPM; |
| 1860 *upmToPMValue = upmToPM; | 1860 *upmToPMValue = upmToPM; |
| 1861 } | 1861 } |
| 1862 } | 1862 } |
| 1863 | 1863 |
| 1864 const GrEffectRef* GrContext::createPMToUPMEffect(GrTexture* texture, | 1864 const GrEffect* GrContext::createPMToUPMEffect(GrTexture* texture, |
| 1865 bool swapRAndB, | 1865 bool swapRAndB, |
| 1866 const SkMatrix& matrix) { | 1866 const SkMatrix& matrix) { |
| 1867 if (!fDidTestPMConversions) { | 1867 if (!fDidTestPMConversions) { |
| 1868 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 1868 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 1869 fDidTestPMConversions = true; | 1869 fDidTestPMConversions = true; |
| 1870 } | 1870 } |
| 1871 GrConfigConversionEffect::PMConversion pmToUPM = | 1871 GrConfigConversionEffect::PMConversion pmToUPM = |
| 1872 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); | 1872 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 1873 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { | 1873 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
| 1874 return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, mat
rix); | 1874 return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, mat
rix); |
| 1875 } else { | 1875 } else { |
| 1876 return NULL; | 1876 return NULL; |
| 1877 } | 1877 } |
| 1878 } | 1878 } |
| 1879 | 1879 |
| 1880 const GrEffectRef* GrContext::createUPMToPMEffect(GrTexture* texture, | 1880 const GrEffect* GrContext::createUPMToPMEffect(GrTexture* texture, |
| 1881 bool swapRAndB, | 1881 bool swapRAndB, |
| 1882 const SkMatrix& matrix) { | 1882 const SkMatrix& matrix) { |
| 1883 if (!fDidTestPMConversions) { | 1883 if (!fDidTestPMConversions) { |
| 1884 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 1884 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 1885 fDidTestPMConversions = true; | 1885 fDidTestPMConversions = true; |
| 1886 } | 1886 } |
| 1887 GrConfigConversionEffect::PMConversion upmToPM = | 1887 GrConfigConversionEffect::PMConversion upmToPM = |
| 1888 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); | 1888 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 1889 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { | 1889 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
| 1890 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); | 1890 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); |
| 1891 } else { | 1891 } else { |
| 1892 return NULL; | 1892 return NULL; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1933 fDrawBuffer->removeGpuTraceMarker(marker); | 1933 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1934 } | 1934 } |
| 1935 } | 1935 } |
| 1936 | 1936 |
| 1937 /////////////////////////////////////////////////////////////////////////////// | 1937 /////////////////////////////////////////////////////////////////////////////// |
| 1938 #if GR_CACHE_STATS | 1938 #if GR_CACHE_STATS |
| 1939 void GrContext::printCacheStats() const { | 1939 void GrContext::printCacheStats() const { |
| 1940 fResourceCache->printStats(); | 1940 fResourceCache->printStats(); |
| 1941 } | 1941 } |
| 1942 #endif | 1942 #endif |
| OLD | NEW |