| 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 440 |
| 441 GrTexture* GrContext::createNewScratchTexture(const GrTextureDesc& desc) { | 441 GrTexture* GrContext::createNewScratchTexture(const GrTextureDesc& desc) { |
| 442 GrTexture* texture = fGpu->createTexture(desc, NULL, 0); | 442 GrTexture* texture = fGpu->createTexture(desc, NULL, 0); |
| 443 if (!texture) { | 443 if (!texture) { |
| 444 return NULL; | 444 return NULL; |
| 445 } | 445 } |
| 446 fResourceCache->addResource(texture->getScratchKey(), texture); | 446 fResourceCache->addResource(texture->getScratchKey(), texture); |
| 447 return texture; | 447 return texture; |
| 448 } | 448 } |
| 449 | 449 |
| 450 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
tchTexMatch match, | 450 GrTexture* GrContext::refScratchTexture(const GrTextureDesc& inDesc, ScratchTexM
atch match, |
| 451 bool calledDuringFlush) { | 451 bool calledDuringFlush) { |
| 452 | |
| 453 // kNoStencil has no meaning if kRT isn't set. | 452 // kNoStencil has no meaning if kRT isn't set. |
| 454 SkASSERT((inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || | 453 SkASSERT((inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || |
| 455 !(inDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 454 !(inDesc.fFlags & kNoStencil_GrTextureFlagBit)); |
| 456 | 455 |
| 457 // Make sure caller has checked for renderability if kRT is set. | 456 // Make sure caller has checked for renderability if kRT is set. |
| 458 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || | 457 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || |
| 459 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); | 458 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); |
| 460 | 459 |
| 461 SkTCopyOnFirstWrite<GrTextureDesc> desc(inDesc); | 460 SkTCopyOnFirstWrite<GrTextureDesc> desc(inDesc); |
| 462 | 461 |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 if (GrPixelConfigSwapRAndB(srcConfig) == | 1299 if (GrPixelConfigSwapRAndB(srcConfig) == |
| 1301 fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) { | 1300 fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) { |
| 1302 writeConfig = GrPixelConfigSwapRAndB(srcConfig); | 1301 writeConfig = GrPixelConfigSwapRAndB(srcConfig); |
| 1303 swapRAndB = true; | 1302 swapRAndB = true; |
| 1304 } | 1303 } |
| 1305 | 1304 |
| 1306 GrTextureDesc desc; | 1305 GrTextureDesc desc; |
| 1307 desc.fWidth = width; | 1306 desc.fWidth = width; |
| 1308 desc.fHeight = height; | 1307 desc.fHeight = height; |
| 1309 desc.fConfig = writeConfig; | 1308 desc.fConfig = writeConfig; |
| 1310 GrAutoScratchTexture ast(this, desc); | 1309 SkAutoTUnref<GrTexture> texture(this->refScratchTexture(desc, kApprox_Scratc
hTexMatch)); |
| 1311 GrTexture* texture = ast.texture(); | 1310 if (!texture) { |
| 1312 if (NULL == texture) { | |
| 1313 return false; | 1311 return false; |
| 1314 } | 1312 } |
| 1315 | 1313 |
| 1316 SkAutoTUnref<const GrFragmentProcessor> fp; | 1314 SkAutoTUnref<const GrFragmentProcessor> fp; |
| 1317 SkMatrix textureMatrix; | 1315 SkMatrix textureMatrix; |
| 1318 textureMatrix.setIDiv(texture->width(), texture->height()); | 1316 textureMatrix.setIDiv(texture->width(), texture->height()); |
| 1319 | 1317 |
| 1320 // allocate a tmp buffer and sw convert the pixels to premul | 1318 // allocate a tmp buffer and sw convert the pixels to premul |
| 1321 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 1319 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 1322 | 1320 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 if (unpremul && !GrPixelConfigIs8888(dstConfig)) { | 1430 if (unpremul && !GrPixelConfigIs8888(dstConfig)) { |
| 1433 // The unpremul flag is only allowed for these two configs. | 1431 // The unpremul flag is only allowed for these two configs. |
| 1434 return false; | 1432 return false; |
| 1435 } | 1433 } |
| 1436 | 1434 |
| 1437 // If the src is a texture and we would have to do conversions after read pi
xels, we instead | 1435 // If the src is a texture and we would have to do conversions after read pi
xels, we instead |
| 1438 // do the conversions by drawing the src to a scratch texture. If we handle
any of the | 1436 // do the conversions by drawing the src to a scratch texture. If we handle
any of the |
| 1439 // conversions in the draw we set the corresponding bool to false so that we
don't reapply it | 1437 // conversions in the draw we set the corresponding bool to false so that we
don't reapply it |
| 1440 // on the read back pixels. | 1438 // on the read back pixels. |
| 1441 GrTexture* src = target->asTexture(); | 1439 GrTexture* src = target->asTexture(); |
| 1442 GrAutoScratchTexture ast; | |
| 1443 if (src && (swapRAndB || unpremul || flipY)) { | 1440 if (src && (swapRAndB || unpremul || flipY)) { |
| 1444 // Make the scratch a render so we can read its pixels. | 1441 // Make the scratch a render so we can read its pixels. |
| 1445 GrTextureDesc desc; | 1442 GrTextureDesc desc; |
| 1446 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 1443 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1447 desc.fWidth = width; | 1444 desc.fWidth = width; |
| 1448 desc.fHeight = height; | 1445 desc.fHeight = height; |
| 1449 desc.fConfig = readConfig; | 1446 desc.fConfig = readConfig; |
| 1450 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1447 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1451 | 1448 |
| 1452 // When a full read back is faster than a partial we could always make t
he scratch exactly | 1449 // When a full read back is faster than a partial we could always make t
he scratch exactly |
| 1453 // match the passed rect. However, if we see many different size rectang
les we will trash | 1450 // match the passed rect. However, if we see many different size rectang
les we will trash |
| 1454 // our texture cache and pay the cost of creating and destroying many te
xtures. So, we only | 1451 // our texture cache and pay the cost of creating and destroying many te
xtures. So, we only |
| 1455 // request an exact match when the caller is reading an entire RT. | 1452 // request an exact match when the caller is reading an entire RT. |
| 1456 ScratchTexMatch match = kApprox_ScratchTexMatch; | 1453 ScratchTexMatch match = kApprox_ScratchTexMatch; |
| 1457 if (0 == left && | 1454 if (0 == left && |
| 1458 0 == top && | 1455 0 == top && |
| 1459 target->width() == width && | 1456 target->width() == width && |
| 1460 target->height() == height && | 1457 target->height() == height && |
| 1461 fGpu->fullReadPixelsIsFasterThanPartial()) { | 1458 fGpu->fullReadPixelsIsFasterThanPartial()) { |
| 1462 match = kExact_ScratchTexMatch; | 1459 match = kExact_ScratchTexMatch; |
| 1463 } | 1460 } |
| 1464 ast.set(this, desc, match); | 1461 SkAutoTUnref<GrTexture> texture(this->refScratchTexture(desc, match)); |
| 1465 GrTexture* texture = ast.texture(); | |
| 1466 if (texture) { | 1462 if (texture) { |
| 1467 // compute a matrix to perform the draw | 1463 // compute a matrix to perform the draw |
| 1468 SkMatrix textureMatrix; | 1464 SkMatrix textureMatrix; |
| 1469 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); | 1465 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); |
| 1470 textureMatrix.postIDiv(src->width(), src->height()); | 1466 textureMatrix.postIDiv(src->width(), src->height()); |
| 1471 | 1467 |
| 1472 SkAutoTUnref<const GrFragmentProcessor> fp; | 1468 SkAutoTUnref<const GrFragmentProcessor> fp; |
| 1473 if (unpremul) { | 1469 if (unpremul) { |
| 1474 fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix
)); | 1470 fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix
)); |
| 1475 if (fp) { | 1471 if (fp) { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 fResourceCache->printStats(); | 1788 fResourceCache->printStats(); |
| 1793 } | 1789 } |
| 1794 #endif | 1790 #endif |
| 1795 | 1791 |
| 1796 #if GR_GPU_STATS | 1792 #if GR_GPU_STATS |
| 1797 const GrContext::GPUStats* GrContext::gpuStats() const { | 1793 const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1798 return fGpu->gpuStats(); | 1794 return fGpu->gpuStats(); |
| 1799 } | 1795 } |
| 1800 #endif | 1796 #endif |
| 1801 | 1797 |
| OLD | NEW |