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

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

Issue 199733016: implement readPixels and writePixels natively, w/o using the (deprecated) (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase 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"
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 "SkTraceEvent.h" 34 #include "SkTraceEvent.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 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 config, buffer, rowBytes, 1253 config, buffer, rowBytes,
1253 flags); 1254 flags);
1254 } 1255 }
1255 1256
1256 return false; 1257 return false;
1257 } 1258 }
1258 } 1259 }
1259 1260
1260 #include "SkConfig8888.h" 1261 #include "SkConfig8888.h"
1261 1262
1262 namespace { 1263 // toggles between RGBA and BGRA
1263 /** 1264 static SkColorType toggle_colortype32(SkColorType ct) {
1264 * Converts a GrPixelConfig to a SkCanvas::Config8888. Only byte-per-channel 1265 if (kRGBA_8888_SkColorType == ct) {
1265 * formats are representable as Config8888 and so the function returns false 1266 return kBGRA_8888_SkColorType;
1266 * if the GrPixelConfig has no equivalent Config8888. 1267 } else {
1267 */ 1268 SkASSERT(kBGRA_8888_SkColorType == ct);
1268 bool grconfig_to_config8888(GrPixelConfig config, 1269 return kRGBA_8888_SkColorType;
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;
1288 } 1270 }
1289 } 1271 }
1290 1272
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
1311 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, 1273 bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
1312 int left, int top, int width, int height, 1274 int left, int top, int width, int height,
1313 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes, 1275 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes,
1314 uint32_t flags) { 1276 uint32_t flags) {
1315 ASSERT_OWNED_RESOURCE(target); 1277 ASSERT_OWNED_RESOURCE(target);
1316 1278
1317 if (NULL == target) { 1279 if (NULL == target) {
1318 target = fRenderTarget.get(); 1280 target = fRenderTarget.get();
1319 if (NULL == target) { 1281 if (NULL == target) {
1320 return false; 1282 return false;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 } 1387 }
1426 } 1388 }
1427 } 1389 }
1428 if (!fGpu->readPixels(target, 1390 if (!fGpu->readPixels(target,
1429 left, top, width, height, 1391 left, top, width, height,
1430 readConfig, buffer, rowBytes)) { 1392 readConfig, buffer, rowBytes)) {
1431 return false; 1393 return false;
1432 } 1394 }
1433 // Perform any conversions we weren't able to perform using a scratch textur e. 1395 // Perform any conversions we weren't able to perform using a scratch textur e.
1434 if (unpremul || swapRAndB) { 1396 if (unpremul || swapRAndB) {
1435 // These are initialized to suppress a warning 1397 SkDstPixelInfo dstPI;
1436 SkCanvas::Config8888 srcC8888 = SkCanvas::kNative_Premul_Config8888; 1398 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) {
1437 SkCanvas::Config8888 dstC8888 = SkCanvas::kNative_Premul_Config8888; 1399 return false;
1400 }
1401 dstPI.fAlphaType = kUnpremul_SkAlphaType;
1402 dstPI.fPixels = buffer;
1403 dstPI.fRowBytes = rowBytes;
1438 1404
1439 SkDEBUGCODE(bool c8888IsValid =) grconfig_to_config8888(dstConfig, false , &srcC8888); 1405 SkSrcPixelInfo srcPI;
1440 grconfig_to_config8888(dstConfig, unpremul, &dstC8888); 1406 srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : ds tPI.fColorType;
1407 srcPI.fAlphaType = kPremul_SkAlphaType;
1408 srcPI.fPixels = buffer;
1409 srcPI.fRowBytes = rowBytes;
1441 1410
1442 if (swapRAndB) { 1411 return srcPI.convertPixelsTo(&dstPI, width, height);
1443 SkASSERT(c8888IsValid); // we should only do r/b swap on 8888 config s
1444 srcC8888 = swap_config8888_red_and_blue(srcC8888);
1445 }
1446 SkASSERT(c8888IsValid);
1447 uint32_t* b32 = reinterpret_cast<uint32_t*>(buffer);
1448 SkConvertConfig8888Pixels(b32, rowBytes, dstC8888,
1449 b32, rowBytes, srcC8888,
1450 width, height);
1451 } 1412 }
1452 return true; 1413 return true;
1453 } 1414 }
1454 1415
1455 void GrContext::resolveRenderTarget(GrRenderTarget* target) { 1416 void GrContext::resolveRenderTarget(GrRenderTarget* target) {
1456 SkASSERT(target); 1417 SkASSERT(target);
1457 ASSERT_OWNED_RESOURCE(target); 1418 ASSERT_OWNED_RESOURCE(target);
1458 // In the future we may track whether there are any pending draws to this 1419 // In the future we may track whether there are any pending draws to this
1459 // target. We don't today so we always perform a flush. We don't promise 1420 // target. We don't today so we always perform a flush. We don't promise
1460 // this to our clients, though. 1421 // this to our clients, though.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 // allocate a tmp buffer and sw convert the pixels to premul 1521 // allocate a tmp buffer and sw convert the pixels to premul
1561 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); 1522 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0);
1562 1523
1563 if (kUnpremul_PixelOpsFlag & flags) { 1524 if (kUnpremul_PixelOpsFlag & flags) {
1564 if (!GrPixelConfigIs8888(srcConfig)) { 1525 if (!GrPixelConfigIs8888(srcConfig)) {
1565 return false; 1526 return false;
1566 } 1527 }
1567 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix )); 1528 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix ));
1568 // handle the unpremul step on the CPU if we couldn't create an effect t o do it. 1529 // handle the unpremul step on the CPU if we couldn't create an effect t o do it.
1569 if (NULL == effect) { 1530 if (NULL == effect) {
1570 SkCanvas::Config8888 srcConfig8888, dstConfig8888; 1531 SkSrcPixelInfo srcPI;
1571 SkDEBUGCODE(bool success = ) 1532 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) {
1572 grconfig_to_config8888(srcConfig, true, &srcConfig8888); 1533 return false;
1573 SkASSERT(success); 1534 }
1574 SkDEBUGCODE(success = ) 1535 srcPI.fAlphaType = kUnpremul_SkAlphaType;
1575 grconfig_to_config8888(srcConfig, false, &dstConfig8888); 1536 srcPI.fPixels = buffer;
1576 SkASSERT(success); 1537 srcPI.fRowBytes = rowBytes;
1577 const uint32_t* src = reinterpret_cast<const uint32_t*>(buffer); 1538
1578 tmpPixels.reset(width * height); 1539 SkDstPixelInfo dstPI;
1579 SkConvertConfig8888Pixels(tmpPixels.get(), 4 * width, dstConfig8888, 1540 dstPI.fColorType = srcPI.fColorType;
1580 src, rowBytes, srcConfig8888, 1541 dstPI.fAlphaType = kPremul_SkAlphaType;
1581 width, height); 1542 dstPI.fPixels = tmpPixels.get();
1543 dstPI.fRowBytes = 4 * width;
1544
1545 if (!srcPI.convertPixelsTo(&dstPI, width, height)) {
1546 return false;
1547 }
1548
1582 buffer = tmpPixels.get(); 1549 buffer = tmpPixels.get();
1583 rowBytes = 4 * width; 1550 rowBytes = 4 * width;
1584 } 1551 }
1585 } 1552 }
1586 if (NULL == effect) { 1553 if (NULL == effect) {
1587 effect.reset(GrConfigConversionEffect::Create(texture, 1554 effect.reset(GrConfigConversionEffect::Create(texture,
1588 swapRAndB, 1555 swapRAndB,
1589 GrConfigConversionEffect:: kNone_PMConversion, 1556 GrConfigConversionEffect:: kNone_PMConversion,
1590 textureMatrix)); 1557 textureMatrix));
1591 } 1558 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 } 1766 }
1800 return path; 1767 return path;
1801 } 1768 }
1802 1769
1803 /////////////////////////////////////////////////////////////////////////////// 1770 ///////////////////////////////////////////////////////////////////////////////
1804 #if GR_CACHE_STATS 1771 #if GR_CACHE_STATS
1805 void GrContext::printCacheStats() const { 1772 void GrContext::printCacheStats() const {
1806 fTextureCache->printStats(); 1773 fTextureCache->printStats();
1807 } 1774 }
1808 #endif 1775 #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