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 "GrTracing.h" | 28 #include "GrTracing.h" |
| 29 #include "SkGr.h" |
29 #include "SkRTConf.h" | 30 #include "SkRTConf.h" |
30 #include "SkRRect.h" | 31 #include "SkRRect.h" |
31 #include "SkStrokeRec.h" | 32 #include "SkStrokeRec.h" |
32 #include "SkTLazy.h" | 33 #include "SkTLazy.h" |
33 #include "SkTLS.h" | 34 #include "SkTLS.h" |
34 #include "SkTraceEvent.h" | 35 #include "SkTraceEvent.h" |
35 | 36 |
36 // It can be useful to set this to false to test whether a bug is caused by usin
g the | 37 // It can be useful to set this to false to test whether a bug is caused by usin
g the |
37 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe
r, or to make | 38 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe
r, or to make |
38 // debugging simpler. | 39 // debugging simpler. |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 config, buffer, rowBytes, | 1270 config, buffer, rowBytes, |
1270 flags); | 1271 flags); |
1271 } | 1272 } |
1272 | 1273 |
1273 return false; | 1274 return false; |
1274 } | 1275 } |
1275 } | 1276 } |
1276 | 1277 |
1277 #include "SkConfig8888.h" | 1278 #include "SkConfig8888.h" |
1278 | 1279 |
1279 namespace { | 1280 // toggles between RGBA and BGRA |
1280 /** | 1281 static SkColorType toggle_colortype32(SkColorType ct) { |
1281 * Converts a GrPixelConfig to a SkCanvas::Config8888. Only byte-per-channel | 1282 if (kRGBA_8888_SkColorType == ct) { |
1282 * formats are representable as Config8888 and so the function returns false | 1283 return kBGRA_8888_SkColorType; |
1283 * if the GrPixelConfig has no equivalent Config8888. | 1284 } else { |
1284 */ | 1285 SkASSERT(kBGRA_8888_SkColorType == ct); |
1285 bool grconfig_to_config8888(GrPixelConfig config, | 1286 return kRGBA_8888_SkColorType; |
1286 bool unpremul, | |
1287 SkCanvas::Config8888* config8888) { | |
1288 switch (config) { | |
1289 case kRGBA_8888_GrPixelConfig: | |
1290 if (unpremul) { | |
1291 *config8888 = SkCanvas::kRGBA_Unpremul_Config8888; | |
1292 } else { | |
1293 *config8888 = SkCanvas::kRGBA_Premul_Config8888; | |
1294 } | |
1295 return true; | |
1296 case kBGRA_8888_GrPixelConfig: | |
1297 if (unpremul) { | |
1298 *config8888 = SkCanvas::kBGRA_Unpremul_Config8888; | |
1299 } else { | |
1300 *config8888 = SkCanvas::kBGRA_Premul_Config8888; | |
1301 } | |
1302 return true; | |
1303 default: | |
1304 return false; | |
1305 } | 1287 } |
1306 } | 1288 } |
1307 | 1289 |
1308 // It returns a configuration with where the byte position of the R & B componen
ts are swapped in | |
1309 // relation to the input config. This should only be called with the result of | |
1310 // grconfig_to_config8888 as it will fail for other configs. | |
1311 SkCanvas::Config8888 swap_config8888_red_and_blue(SkCanvas::Config8888 config888
8) { | |
1312 switch (config8888) { | |
1313 case SkCanvas::kBGRA_Premul_Config8888: | |
1314 return SkCanvas::kRGBA_Premul_Config8888; | |
1315 case SkCanvas::kBGRA_Unpremul_Config8888: | |
1316 return SkCanvas::kRGBA_Unpremul_Config8888; | |
1317 case SkCanvas::kRGBA_Premul_Config8888: | |
1318 return SkCanvas::kBGRA_Premul_Config8888; | |
1319 case SkCanvas::kRGBA_Unpremul_Config8888: | |
1320 return SkCanvas::kBGRA_Unpremul_Config8888; | |
1321 default: | |
1322 GrCrash("Unexpected input"); | |
1323 return SkCanvas::kBGRA_Unpremul_Config8888;; | |
1324 } | |
1325 } | |
1326 } | |
1327 | |
1328 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, | 1290 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, |
1329 int left, int top, int width, int height, | 1291 int left, int top, int width, int height, |
1330 GrPixelConfig dstConfig, void* buffer, si
ze_t rowBytes, | 1292 GrPixelConfig dstConfig, void* buffer, si
ze_t rowBytes, |
1331 uint32_t flags) { | 1293 uint32_t flags) { |
1332 ASSERT_OWNED_RESOURCE(target); | 1294 ASSERT_OWNED_RESOURCE(target); |
1333 | 1295 |
1334 if (NULL == target) { | 1296 if (NULL == target) { |
1335 target = fRenderTarget.get(); | 1297 target = fRenderTarget.get(); |
1336 if (NULL == target) { | 1298 if (NULL == target) { |
1337 return false; | 1299 return false; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 } | 1404 } |
1443 } | 1405 } |
1444 } | 1406 } |
1445 if (!fGpu->readPixels(target, | 1407 if (!fGpu->readPixels(target, |
1446 left, top, width, height, | 1408 left, top, width, height, |
1447 readConfig, buffer, rowBytes)) { | 1409 readConfig, buffer, rowBytes)) { |
1448 return false; | 1410 return false; |
1449 } | 1411 } |
1450 // Perform any conversions we weren't able to perform using a scratch textur
e. | 1412 // Perform any conversions we weren't able to perform using a scratch textur
e. |
1451 if (unpremul || swapRAndB) { | 1413 if (unpremul || swapRAndB) { |
1452 // These are initialized to suppress a warning | 1414 SkDstPixelInfo dstPI; |
1453 SkCanvas::Config8888 srcC8888 = SkCanvas::kNative_Premul_Config8888; | 1415 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { |
1454 SkCanvas::Config8888 dstC8888 = SkCanvas::kNative_Premul_Config8888; | 1416 return false; |
| 1417 } |
| 1418 dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1419 dstPI.fPixels = buffer; |
| 1420 dstPI.fRowBytes = rowBytes; |
1455 | 1421 |
1456 SkDEBUGCODE(bool c8888IsValid =) grconfig_to_config8888(dstConfig, false
, &srcC8888); | 1422 SkSrcPixelInfo srcPI; |
1457 grconfig_to_config8888(dstConfig, unpremul, &dstC8888); | 1423 srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : ds
tPI.fColorType; |
| 1424 srcPI.fAlphaType = kPremul_SkAlphaType; |
| 1425 srcPI.fPixels = buffer; |
| 1426 srcPI.fRowBytes = rowBytes; |
1458 | 1427 |
1459 if (swapRAndB) { | 1428 return srcPI.convertPixelsTo(&dstPI, width, height); |
1460 SkASSERT(c8888IsValid); // we should only do r/b swap on 8888 config
s | |
1461 srcC8888 = swap_config8888_red_and_blue(srcC8888); | |
1462 } | |
1463 SkASSERT(c8888IsValid); | |
1464 uint32_t* b32 = reinterpret_cast<uint32_t*>(buffer); | |
1465 SkConvertConfig8888Pixels(b32, rowBytes, dstC8888, | |
1466 b32, rowBytes, srcC8888, | |
1467 width, height); | |
1468 } | 1429 } |
1469 return true; | 1430 return true; |
1470 } | 1431 } |
1471 | 1432 |
1472 void GrContext::resolveRenderTarget(GrRenderTarget* target) { | 1433 void GrContext::resolveRenderTarget(GrRenderTarget* target) { |
1473 SkASSERT(target); | 1434 SkASSERT(target); |
1474 ASSERT_OWNED_RESOURCE(target); | 1435 ASSERT_OWNED_RESOURCE(target); |
1475 // In the future we may track whether there are any pending draws to this | 1436 // In the future we may track whether there are any pending draws to this |
1476 // target. We don't today so we always perform a flush. We don't promise | 1437 // target. We don't today so we always perform a flush. We don't promise |
1477 // this to our clients, though. | 1438 // this to our clients, though. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 // allocate a tmp buffer and sw convert the pixels to premul | 1538 // allocate a tmp buffer and sw convert the pixels to premul |
1578 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 1539 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
1579 | 1540 |
1580 if (kUnpremul_PixelOpsFlag & flags) { | 1541 if (kUnpremul_PixelOpsFlag & flags) { |
1581 if (!GrPixelConfigIs8888(srcConfig)) { | 1542 if (!GrPixelConfigIs8888(srcConfig)) { |
1582 return false; | 1543 return false; |
1583 } | 1544 } |
1584 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix
)); | 1545 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix
)); |
1585 // handle the unpremul step on the CPU if we couldn't create an effect t
o do it. | 1546 // handle the unpremul step on the CPU if we couldn't create an effect t
o do it. |
1586 if (NULL == effect) { | 1547 if (NULL == effect) { |
1587 SkCanvas::Config8888 srcConfig8888, dstConfig8888; | 1548 SkSrcPixelInfo srcPI; |
1588 SkDEBUGCODE(bool success = ) | 1549 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { |
1589 grconfig_to_config8888(srcConfig, true, &srcConfig8888); | 1550 return false; |
1590 SkASSERT(success); | 1551 } |
1591 SkDEBUGCODE(success = ) | 1552 srcPI.fAlphaType = kUnpremul_SkAlphaType; |
1592 grconfig_to_config8888(srcConfig, false, &dstConfig8888); | 1553 srcPI.fPixels = buffer; |
1593 SkASSERT(success); | 1554 srcPI.fRowBytes = rowBytes; |
1594 const uint32_t* src = reinterpret_cast<const uint32_t*>(buffer); | 1555 |
1595 tmpPixels.reset(width * height); | 1556 tmpPixels.reset(width * height); |
1596 SkConvertConfig8888Pixels(tmpPixels.get(), 4 * width, dstConfig8888, | 1557 |
1597 src, rowBytes, srcConfig8888, | 1558 SkDstPixelInfo dstPI; |
1598 width, height); | 1559 dstPI.fColorType = srcPI.fColorType; |
| 1560 dstPI.fAlphaType = kPremul_SkAlphaType; |
| 1561 dstPI.fPixels = tmpPixels.get(); |
| 1562 dstPI.fRowBytes = 4 * width; |
| 1563 |
| 1564 if (!srcPI.convertPixelsTo(&dstPI, width, height)) { |
| 1565 return false; |
| 1566 } |
| 1567 |
1599 buffer = tmpPixels.get(); | 1568 buffer = tmpPixels.get(); |
1600 rowBytes = 4 * width; | 1569 rowBytes = 4 * width; |
1601 } | 1570 } |
1602 } | 1571 } |
1603 if (NULL == effect) { | 1572 if (NULL == effect) { |
1604 effect.reset(GrConfigConversionEffect::Create(texture, | 1573 effect.reset(GrConfigConversionEffect::Create(texture, |
1605 swapRAndB, | 1574 swapRAndB, |
1606 GrConfigConversionEffect::
kNone_PMConversion, | 1575 GrConfigConversionEffect::
kNone_PMConversion, |
1607 textureMatrix)); | 1576 textureMatrix)); |
1608 } | 1577 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 } | 1785 } |
1817 return path; | 1786 return path; |
1818 } | 1787 } |
1819 | 1788 |
1820 /////////////////////////////////////////////////////////////////////////////// | 1789 /////////////////////////////////////////////////////////////////////////////// |
1821 #if GR_CACHE_STATS | 1790 #if GR_CACHE_STATS |
1822 void GrContext::printCacheStats() const { | 1791 void GrContext::printCacheStats() const { |
1823 fTextureCache->printStats(); | 1792 fTextureCache->printStats(); |
1824 } | 1793 } |
1825 #endif | 1794 #endif |
OLD | NEW |