| 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" |
| 11 | 11 |
| 12 #include "effects/GrSingleTextureEffect.h" | 12 #include "effects/GrSingleTextureEffect.h" |
| 13 #include "effects/GrConfigConversionEffect.h" | 13 #include "effects/GrConfigConversionEffect.h" |
| 14 | 14 |
| 15 #include "GrAARectRenderer.h" | 15 #include "GrAARectRenderer.h" |
| 16 #include "GrBufferAllocPool.h" | 16 #include "GrBufferAllocPool.h" |
| 17 #include "GrGpu.h" | 17 #include "GrGpu.h" |
| 18 #include "GrDrawTargetCaps.h" | 18 #include "GrDrawTargetCaps.h" |
| 19 #include "GrIndexBuffer.h" | 19 #include "GrIndexBuffer.h" |
| 20 #include "GrInOrderDrawBuffer.h" | 20 #include "GrInOrderDrawBuffer.h" |
| 21 #include "GrOvalRenderer.h" | 21 #include "GrOvalRenderer.h" |
| 22 #include "GrPathRenderer.h" | 22 #include "GrPathRenderer.h" |
| 23 #include "GrPathUtils.h" | 23 #include "GrPathUtils.h" |
| 24 #include "GrResourceCache.h" | 24 #include "GrResourceCache.h" |
| 25 #include "GrSoftwarePathRenderer.h" | 25 #include "GrSoftwarePathRenderer.h" |
| 26 #include "GrStencilBuffer.h" | 26 #include "GrStencilBuffer.h" |
| 27 #include "GrTextStrike.h" | 27 #include "GrTextStrike.h" |
| 28 #include "SkGr.h" |
| 28 #include "SkRTConf.h" | 29 #include "SkRTConf.h" |
| 29 #include "SkRRect.h" | 30 #include "SkRRect.h" |
| 30 #include "SkStrokeRec.h" | 31 #include "SkStrokeRec.h" |
| 31 #include "SkTLazy.h" | 32 #include "SkTLazy.h" |
| 32 #include "SkTLS.h" | 33 #include "SkTLS.h" |
| 33 #include "SkTrace.h" | 34 #include "SkTrace.h" |
| 34 | 35 |
| 35 // It can be useful to set this to false to test whether a bug is caused by usin
g the | 36 // It can be useful to set this to false to test whether a bug is caused by usin
g the |
| 36 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe
r, or to make | 37 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe
r, or to make |
| 37 // debugging simpler. | 38 // debugging simpler. |
| (...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 config, buffer, rowBytes, | 1258 config, buffer, rowBytes, |
| 1258 flags); | 1259 flags); |
| 1259 } | 1260 } |
| 1260 | 1261 |
| 1261 return false; | 1262 return false; |
| 1262 } | 1263 } |
| 1263 } | 1264 } |
| 1264 | 1265 |
| 1265 #include "SkConfig8888.h" | 1266 #include "SkConfig8888.h" |
| 1266 | 1267 |
| 1267 namespace { | 1268 // toggles between RGBA and BGRA |
| 1268 /** | 1269 static SkColorType toggle_colortype32(SkColorType ct) { |
| 1269 * Converts a GrPixelConfig to a SkCanvas::Config8888. Only byte-per-channel | 1270 if (kRGBA_8888_SkColorType == ct) { |
| 1270 * formats are representable as Config8888 and so the function returns false | 1271 return kBGRA_8888_SkColorType; |
| 1271 * if the GrPixelConfig has no equivalent Config8888. | 1272 } else { |
| 1272 */ | 1273 SkASSERT(kBGRA_8888_SkColorType == ct); |
| 1273 bool grconfig_to_config8888(GrPixelConfig config, | 1274 return kRGBA_8888_SkColorType; |
| 1274 bool unpremul, | |
| 1275 SkCanvas::Config8888* config8888) { | |
| 1276 switch (config) { | |
| 1277 case kRGBA_8888_GrPixelConfig: | |
| 1278 if (unpremul) { | |
| 1279 *config8888 = SkCanvas::kRGBA_Unpremul_Config8888; | |
| 1280 } else { | |
| 1281 *config8888 = SkCanvas::kRGBA_Premul_Config8888; | |
| 1282 } | |
| 1283 return true; | |
| 1284 case kBGRA_8888_GrPixelConfig: | |
| 1285 if (unpremul) { | |
| 1286 *config8888 = SkCanvas::kBGRA_Unpremul_Config8888; | |
| 1287 } else { | |
| 1288 *config8888 = SkCanvas::kBGRA_Premul_Config8888; | |
| 1289 } | |
| 1290 return true; | |
| 1291 default: | |
| 1292 return false; | |
| 1293 } | 1275 } |
| 1294 } | 1276 } |
| 1295 | 1277 |
| 1296 // It returns a configuration with where the byte position of the R & B componen
ts are swapped in | |
| 1297 // relation to the input config. This should only be called with the result of | |
| 1298 // grconfig_to_config8888 as it will fail for other configs. | |
| 1299 SkCanvas::Config8888 swap_config8888_red_and_blue(SkCanvas::Config8888 config888
8) { | |
| 1300 switch (config8888) { | |
| 1301 case SkCanvas::kBGRA_Premul_Config8888: | |
| 1302 return SkCanvas::kRGBA_Premul_Config8888; | |
| 1303 case SkCanvas::kBGRA_Unpremul_Config8888: | |
| 1304 return SkCanvas::kRGBA_Unpremul_Config8888; | |
| 1305 case SkCanvas::kRGBA_Premul_Config8888: | |
| 1306 return SkCanvas::kBGRA_Premul_Config8888; | |
| 1307 case SkCanvas::kRGBA_Unpremul_Config8888: | |
| 1308 return SkCanvas::kBGRA_Unpremul_Config8888; | |
| 1309 default: | |
| 1310 GrCrash("Unexpected input"); | |
| 1311 return SkCanvas::kBGRA_Unpremul_Config8888;; | |
| 1312 } | |
| 1313 } | |
| 1314 } | |
| 1315 | |
| 1316 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, | 1278 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, |
| 1317 int left, int top, int width, int height, | 1279 int left, int top, int width, int height, |
| 1318 GrPixelConfig dstConfig, void* buffer, si
ze_t rowBytes, | 1280 GrPixelConfig dstConfig, void* buffer, si
ze_t rowBytes, |
| 1319 uint32_t flags) { | 1281 uint32_t flags) { |
| 1320 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels"); | 1282 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels"); |
| 1321 ASSERT_OWNED_RESOURCE(target); | 1283 ASSERT_OWNED_RESOURCE(target); |
| 1322 | 1284 |
| 1323 if (NULL == target) { | 1285 if (NULL == target) { |
| 1324 target = fRenderTarget.get(); | 1286 target = fRenderTarget.get(); |
| 1325 if (NULL == target) { | 1287 if (NULL == target) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 } | 1393 } |
| 1432 } | 1394 } |
| 1433 } | 1395 } |
| 1434 if (!fGpu->readPixels(target, | 1396 if (!fGpu->readPixels(target, |
| 1435 left, top, width, height, | 1397 left, top, width, height, |
| 1436 readConfig, buffer, rowBytes)) { | 1398 readConfig, buffer, rowBytes)) { |
| 1437 return false; | 1399 return false; |
| 1438 } | 1400 } |
| 1439 // Perform any conversions we weren't able to perform using a scratch textur
e. | 1401 // Perform any conversions we weren't able to perform using a scratch textur
e. |
| 1440 if (unpremul || swapRAndB) { | 1402 if (unpremul || swapRAndB) { |
| 1441 // These are initialized to suppress a warning | 1403 SkDstPixelInfo dstPI; |
| 1442 SkCanvas::Config8888 srcC8888 = SkCanvas::kNative_Premul_Config8888; | 1404 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { |
| 1443 SkCanvas::Config8888 dstC8888 = SkCanvas::kNative_Premul_Config8888; | 1405 return false; |
| 1444 | |
| 1445 SkDEBUGCODE(bool c8888IsValid =) grconfig_to_config8888(dstConfig, false
, &srcC8888); | |
| 1446 grconfig_to_config8888(dstConfig, unpremul, &dstC8888); | |
| 1447 | |
| 1448 if (swapRAndB) { | |
| 1449 SkASSERT(c8888IsValid); // we should only do r/b swap on 8888 config
s | |
| 1450 srcC8888 = swap_config8888_red_and_blue(srcC8888); | |
| 1451 } | 1406 } |
| 1452 SkASSERT(c8888IsValid); | 1407 dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1453 uint32_t* b32 = reinterpret_cast<uint32_t*>(buffer); | 1408 dstPI.fPixels = buffer; |
| 1454 SkConvertConfig8888Pixels(b32, rowBytes, dstC8888, | 1409 dstPI.fRowBytes = rowBytes; |
| 1455 b32, rowBytes, srcC8888, | 1410 |
| 1456 width, height); | 1411 SkSrcPixelInfo srcPI; |
| 1412 srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : ds
tPI.fColorType; |
| 1413 srcPI.fAlphaType = kPremul_SkAlphaType; |
| 1414 srcPI.fPixels = buffer; |
| 1415 srcPI.fRowBytes = rowBytes; |
| 1416 |
| 1417 return srcPI.convertPixelsTo(&dstPI, width, height); |
| 1457 } | 1418 } |
| 1458 return true; | 1419 return true; |
| 1459 } | 1420 } |
| 1460 | 1421 |
| 1461 void GrContext::resolveRenderTarget(GrRenderTarget* target) { | 1422 void GrContext::resolveRenderTarget(GrRenderTarget* target) { |
| 1462 SkASSERT(target); | 1423 SkASSERT(target); |
| 1463 ASSERT_OWNED_RESOURCE(target); | 1424 ASSERT_OWNED_RESOURCE(target); |
| 1464 // In the future we may track whether there are any pending draws to this | 1425 // In the future we may track whether there are any pending draws to this |
| 1465 // target. We don't today so we always perform a flush. We don't promise | 1426 // target. We don't today so we always perform a flush. We don't promise |
| 1466 // this to our clients, though. | 1427 // this to our clients, though. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 // allocate a tmp buffer and sw convert the pixels to premul | 1528 // allocate a tmp buffer and sw convert the pixels to premul |
| 1568 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 1529 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 1569 | 1530 |
| 1570 if (kUnpremul_PixelOpsFlag & flags) { | 1531 if (kUnpremul_PixelOpsFlag & flags) { |
| 1571 if (!GrPixelConfigIs8888(srcConfig)) { | 1532 if (!GrPixelConfigIs8888(srcConfig)) { |
| 1572 return false; | 1533 return false; |
| 1573 } | 1534 } |
| 1574 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix
)); | 1535 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix
)); |
| 1575 // handle the unpremul step on the CPU if we couldn't create an effect t
o do it. | 1536 // handle the unpremul step on the CPU if we couldn't create an effect t
o do it. |
| 1576 if (NULL == effect) { | 1537 if (NULL == effect) { |
| 1577 SkCanvas::Config8888 srcConfig8888, dstConfig8888; | 1538 SkSrcPixelInfo srcPI; |
| 1578 SkDEBUGCODE(bool success = ) | 1539 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { |
| 1579 grconfig_to_config8888(srcConfig, true, &srcConfig8888); | 1540 return false; |
| 1580 SkASSERT(success); | 1541 } |
| 1581 SkDEBUGCODE(success = ) | 1542 srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1582 grconfig_to_config8888(srcConfig, false, &dstConfig8888); | 1543 srcPI.fPixels = buffer; |
| 1583 SkASSERT(success); | 1544 srcPI.fRowBytes = rowBytes; |
| 1584 const uint32_t* src = reinterpret_cast<const uint32_t*>(buffer); | 1545 |
| 1585 tmpPixels.reset(width * height); | 1546 SkDstPixelInfo dstPI; |
| 1586 SkConvertConfig8888Pixels(tmpPixels.get(), 4 * width, dstConfig8888, | 1547 dstPI.fColorType = srcPI.fColorType; |
| 1587 src, rowBytes, srcConfig8888, | 1548 dstPI.fAlphaType = kPremul_SkAlphaType; |
| 1588 width, height); | 1549 dstPI.fPixels = tmpPixels.get(); |
| 1550 dstPI.fRowBytes = 4 * width; |
| 1551 |
| 1552 if (!srcPI.convertPixelsTo(&dstPI, width, height)) { |
| 1553 return false; |
| 1554 } |
| 1555 |
| 1589 buffer = tmpPixels.get(); | 1556 buffer = tmpPixels.get(); |
| 1590 rowBytes = 4 * width; | 1557 rowBytes = 4 * width; |
| 1591 } | 1558 } |
| 1592 } | 1559 } |
| 1593 if (NULL == effect) { | 1560 if (NULL == effect) { |
| 1594 effect.reset(GrConfigConversionEffect::Create(texture, | 1561 effect.reset(GrConfigConversionEffect::Create(texture, |
| 1595 swapRAndB, | 1562 swapRAndB, |
| 1596 GrConfigConversionEffect::
kNone_PMConversion, | 1563 GrConfigConversionEffect::
kNone_PMConversion, |
| 1597 textureMatrix)); | 1564 textureMatrix)); |
| 1598 } | 1565 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 } | 1773 } |
| 1807 return path; | 1774 return path; |
| 1808 } | 1775 } |
| 1809 | 1776 |
| 1810 /////////////////////////////////////////////////////////////////////////////// | 1777 /////////////////////////////////////////////////////////////////////////////// |
| 1811 #if GR_CACHE_STATS | 1778 #if GR_CACHE_STATS |
| 1812 void GrContext::printCacheStats() const { | 1779 void GrContext::printCacheStats() const { |
| 1813 fTextureCache->printStats(); | 1780 fTextureCache->printStats(); |
| 1814 } | 1781 } |
| 1815 #endif | 1782 #endif |
| OLD | NEW |