Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 209233004: Revert of implement readPixels and writePixels natively, w/o using the (deprecated) (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
29 #include "SkRTConf.h" 28 #include "SkRTConf.h"
30 #include "SkRRect.h" 29 #include "SkRRect.h"
31 #include "SkStrokeRec.h" 30 #include "SkStrokeRec.h"
32 #include "SkTLazy.h" 31 #include "SkTLazy.h"
33 #include "SkTLS.h" 32 #include "SkTLS.h"
34 #include "SkTraceEvent.h" 33 #include "SkTraceEvent.h"
35 34
36 // It can be useful to set this to false to test whether a bug is caused by usin g the 35 // 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 36 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe r, or to make
38 // debugging simpler. 37 // debugging simpler.
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 config, buffer, rowBytes, 1252 config, buffer, rowBytes,
1254 flags); 1253 flags);
1255 } 1254 }
1256 1255
1257 return false; 1256 return false;
1258 } 1257 }
1259 } 1258 }
1260 1259
1261 #include "SkConfig8888.h" 1260 #include "SkConfig8888.h"
1262 1261
1263 // toggles between RGBA and BGRA 1262 namespace {
1264 static SkColorType toggle_colortype32(SkColorType ct) { 1263 /**
1265 if (kRGBA_8888_SkColorType == ct) { 1264 * Converts a GrPixelConfig to a SkCanvas::Config8888. Only byte-per-channel
1266 return kBGRA_8888_SkColorType; 1265 * formats are representable as Config8888 and so the function returns false
1267 } else { 1266 * if the GrPixelConfig has no equivalent Config8888.
1268 SkASSERT(kBGRA_8888_SkColorType == ct); 1267 */
1269 return kRGBA_8888_SkColorType; 1268 bool grconfig_to_config8888(GrPixelConfig config,
1269 bool unpremul,
1270 SkCanvas::Config8888* config8888) {
1271 switch (config) {
1272 case kRGBA_8888_GrPixelConfig:
1273 if (unpremul) {
1274 *config8888 = SkCanvas::kRGBA_Unpremul_Config8888;
1275 } else {
1276 *config8888 = SkCanvas::kRGBA_Premul_Config8888;
1277 }
1278 return true;
1279 case kBGRA_8888_GrPixelConfig:
1280 if (unpremul) {
1281 *config8888 = SkCanvas::kBGRA_Unpremul_Config8888;
1282 } else {
1283 *config8888 = SkCanvas::kBGRA_Premul_Config8888;
1284 }
1285 return true;
1286 default:
1287 return false;
1270 } 1288 }
1271 } 1289 }
1272 1290
1291 // It returns a configuration with where the byte position of the R & B componen ts are swapped in
1292 // relation to the input config. This should only be called with the result of
1293 // grconfig_to_config8888 as it will fail for other configs.
1294 SkCanvas::Config8888 swap_config8888_red_and_blue(SkCanvas::Config8888 config888 8) {
1295 switch (config8888) {
1296 case SkCanvas::kBGRA_Premul_Config8888:
1297 return SkCanvas::kRGBA_Premul_Config8888;
1298 case SkCanvas::kBGRA_Unpremul_Config8888:
1299 return SkCanvas::kRGBA_Unpremul_Config8888;
1300 case SkCanvas::kRGBA_Premul_Config8888:
1301 return SkCanvas::kBGRA_Premul_Config8888;
1302 case SkCanvas::kRGBA_Unpremul_Config8888:
1303 return SkCanvas::kBGRA_Unpremul_Config8888;
1304 default:
1305 GrCrash("Unexpected input");
1306 return SkCanvas::kBGRA_Unpremul_Config8888;;
1307 }
1308 }
1309 }
1310
1273 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, 1311 bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
1274 int left, int top, int width, int height, 1312 int left, int top, int width, int height,
1275 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes, 1313 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes,
1276 uint32_t flags) { 1314 uint32_t flags) {
1277 ASSERT_OWNED_RESOURCE(target); 1315 ASSERT_OWNED_RESOURCE(target);
1278 1316
1279 if (NULL == target) { 1317 if (NULL == target) {
1280 target = fRenderTarget.get(); 1318 target = fRenderTarget.get();
1281 if (NULL == target) { 1319 if (NULL == target) {
1282 return false; 1320 return false;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 } 1425 }
1388 } 1426 }
1389 } 1427 }
1390 if (!fGpu->readPixels(target, 1428 if (!fGpu->readPixels(target,
1391 left, top, width, height, 1429 left, top, width, height,
1392 readConfig, buffer, rowBytes)) { 1430 readConfig, buffer, rowBytes)) {
1393 return false; 1431 return false;
1394 } 1432 }
1395 // Perform any conversions we weren't able to perform using a scratch textur e. 1433 // Perform any conversions we weren't able to perform using a scratch textur e.
1396 if (unpremul || swapRAndB) { 1434 if (unpremul || swapRAndB) {
1397 SkDstPixelInfo dstPI; 1435 // These are initialized to suppress a warning
1398 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { 1436 SkCanvas::Config8888 srcC8888 = SkCanvas::kNative_Premul_Config8888;
1399 return false; 1437 SkCanvas::Config8888 dstC8888 = SkCanvas::kNative_Premul_Config8888;
1438
1439 SkDEBUGCODE(bool c8888IsValid =) grconfig_to_config8888(dstConfig, false , &srcC8888);
1440 grconfig_to_config8888(dstConfig, unpremul, &dstC8888);
1441
1442 if (swapRAndB) {
1443 SkASSERT(c8888IsValid); // we should only do r/b swap on 8888 config s
1444 srcC8888 = swap_config8888_red_and_blue(srcC8888);
1400 } 1445 }
1401 dstPI.fAlphaType = kUnpremul_SkAlphaType; 1446 SkASSERT(c8888IsValid);
1402 dstPI.fPixels = buffer; 1447 uint32_t* b32 = reinterpret_cast<uint32_t*>(buffer);
1403 dstPI.fRowBytes = rowBytes; 1448 SkConvertConfig8888Pixels(b32, rowBytes, dstC8888,
1404 1449 b32, rowBytes, srcC8888,
1405 SkSrcPixelInfo srcPI; 1450 width, height);
1406 srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : ds tPI.fColorType;
1407 srcPI.fAlphaType = kPremul_SkAlphaType;
1408 srcPI.fPixels = buffer;
1409 srcPI.fRowBytes = rowBytes;
1410
1411 return srcPI.convertPixelsTo(&dstPI, width, height);
1412 } 1451 }
1413 return true; 1452 return true;
1414 } 1453 }
1415 1454
1416 void GrContext::resolveRenderTarget(GrRenderTarget* target) { 1455 void GrContext::resolveRenderTarget(GrRenderTarget* target) {
1417 SkASSERT(target); 1456 SkASSERT(target);
1418 ASSERT_OWNED_RESOURCE(target); 1457 ASSERT_OWNED_RESOURCE(target);
1419 // In the future we may track whether there are any pending draws to this 1458 // In the future we may track whether there are any pending draws to this
1420 // target. We don't today so we always perform a flush. We don't promise 1459 // target. We don't today so we always perform a flush. We don't promise
1421 // this to our clients, though. 1460 // this to our clients, though.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 // allocate a tmp buffer and sw convert the pixels to premul 1560 // allocate a tmp buffer and sw convert the pixels to premul
1522 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); 1561 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0);
1523 1562
1524 if (kUnpremul_PixelOpsFlag & flags) { 1563 if (kUnpremul_PixelOpsFlag & flags) {
1525 if (!GrPixelConfigIs8888(srcConfig)) { 1564 if (!GrPixelConfigIs8888(srcConfig)) {
1526 return false; 1565 return false;
1527 } 1566 }
1528 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix )); 1567 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix ));
1529 // handle the unpremul step on the CPU if we couldn't create an effect t o do it. 1568 // handle the unpremul step on the CPU if we couldn't create an effect t o do it.
1530 if (NULL == effect) { 1569 if (NULL == effect) {
1531 SkSrcPixelInfo srcPI; 1570 SkCanvas::Config8888 srcConfig8888, dstConfig8888;
1532 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { 1571 SkDEBUGCODE(bool success = )
1533 return false; 1572 grconfig_to_config8888(srcConfig, true, &srcConfig8888);
1534 } 1573 SkASSERT(success);
1535 srcPI.fAlphaType = kUnpremul_SkAlphaType; 1574 SkDEBUGCODE(success = )
1536 srcPI.fPixels = buffer; 1575 grconfig_to_config8888(srcConfig, false, &dstConfig8888);
1537 srcPI.fRowBytes = rowBytes; 1576 SkASSERT(success);
1538 1577 const uint32_t* src = reinterpret_cast<const uint32_t*>(buffer);
1539 SkDstPixelInfo dstPI; 1578 tmpPixels.reset(width * height);
1540 dstPI.fColorType = srcPI.fColorType; 1579 SkConvertConfig8888Pixels(tmpPixels.get(), 4 * width, dstConfig8888,
1541 dstPI.fAlphaType = kPremul_SkAlphaType; 1580 src, rowBytes, srcConfig8888,
1542 dstPI.fPixels = tmpPixels.get(); 1581 width, height);
1543 dstPI.fRowBytes = 4 * width;
1544
1545 if (!srcPI.convertPixelsTo(&dstPI, width, height)) {
1546 return false;
1547 }
1548
1549 buffer = tmpPixels.get(); 1582 buffer = tmpPixels.get();
1550 rowBytes = 4 * width; 1583 rowBytes = 4 * width;
1551 } 1584 }
1552 } 1585 }
1553 if (NULL == effect) { 1586 if (NULL == effect) {
1554 effect.reset(GrConfigConversionEffect::Create(texture, 1587 effect.reset(GrConfigConversionEffect::Create(texture,
1555 swapRAndB, 1588 swapRAndB,
1556 GrConfigConversionEffect:: kNone_PMConversion, 1589 GrConfigConversionEffect:: kNone_PMConversion,
1557 textureMatrix)); 1590 textureMatrix));
1558 } 1591 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 } 1799 }
1767 return path; 1800 return path;
1768 } 1801 }
1769 1802
1770 /////////////////////////////////////////////////////////////////////////////// 1803 ///////////////////////////////////////////////////////////////////////////////
1771 #if GR_CACHE_STATS 1804 #if GR_CACHE_STATS
1772 void GrContext::printCacheStats() const { 1805 void GrContext::printCacheStats() const {
1773 fTextureCache->printStats(); 1806 fTextureCache->printStats();
1774 } 1807 }
1775 #endif 1808 #endif
OLDNEW
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698