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