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

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

Issue 203993002: hide Config8888 entirely (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
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 "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
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 static SkColorType swapColorType32(SkColorType ct) {
bsalomon 2014/03/19 12:36:48 In the Gr code we're mostly consistent about namin
reed1 2014/03/19 17:59:58 I think that's true in general everywhere, so I'll
1268 /** 1269 if (kRGBA_8888_SkColorType == ct) {
1269 * Converts a GrPixelConfig to a SkCanvas::Config8888. Only byte-per-channel 1270 return kBGRA_8888_SkColorType;
1270 * formats are representable as Config8888 and so the function returns false 1271 } else {
1271 * if the GrPixelConfig has no equivalent Config8888. 1272 SkASSERT(kBGRA_8888_SkColorType == ct);
1272 */ 1273 return kRGBA_8888_SkColorType;
1273 bool grconfig_to_config8888(GrPixelConfig config,
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 } 1274 }
1294 } 1275 }
1295 1276
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, 1277 bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
1317 int left, int top, int width, int height, 1278 int left, int top, int width, int height,
1318 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes, 1279 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes,
1319 uint32_t flags) { 1280 uint32_t flags) {
1320 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels"); 1281 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels");
1321 ASSERT_OWNED_RESOURCE(target); 1282 ASSERT_OWNED_RESOURCE(target);
1322 1283
1323 if (NULL == target) { 1284 if (NULL == target) {
1324 target = fRenderTarget.get(); 1285 target = fRenderTarget.get();
1325 if (NULL == target) { 1286 if (NULL == target) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 } 1392 }
1432 } 1393 }
1433 } 1394 }
1434 if (!fGpu->readPixels(target, 1395 if (!fGpu->readPixels(target,
1435 left, top, width, height, 1396 left, top, width, height,
1436 readConfig, buffer, rowBytes)) { 1397 readConfig, buffer, rowBytes)) {
1437 return false; 1398 return false;
1438 } 1399 }
1439 // Perform any conversions we weren't able to perform using a scratch textur e. 1400 // Perform any conversions we weren't able to perform using a scratch textur e.
1440 if (unpremul || swapRAndB) { 1401 if (unpremul || swapRAndB) {
1441 // These are initialized to suppress a warning 1402 SkPixelInfo dstPI;
1442 SkCanvas::Config8888 srcC8888 = SkCanvas::kNative_Premul_Config8888; 1403 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) {
1443 SkCanvas::Config8888 dstC8888 = SkCanvas::kNative_Premul_Config8888; 1404 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 } 1405 }
1452 SkASSERT(c8888IsValid); 1406 dstPI.fAlphaType = kUnpremul_SkAlphaType;
1453 uint32_t* b32 = reinterpret_cast<uint32_t*>(buffer); 1407 dstPI.fPixels = buffer;
1454 SkConvertConfig8888Pixels(b32, rowBytes, dstC8888, 1408 dstPI.fRowBytes = rowBytes;
1455 b32, rowBytes, srcC8888, 1409
1456 width, height); 1410 SkPixelInfo srcPI;
1411 srcPI.fColorType = swapRAndB ? swapColorType32(dstPI.fColorType) : dstPI .fColorType;
1412 srcPI.fAlphaType = kPremul_SkAlphaType;
1413 dstPI.fPixels = buffer;
1414 dstPI.fRowBytes = rowBytes;
1415
1416 return srcPI.convertPixelsTo(&dstPI, width, height);
1457 } 1417 }
1458 return true; 1418 return true;
1459 } 1419 }
1460 1420
1461 void GrContext::resolveRenderTarget(GrRenderTarget* target) { 1421 void GrContext::resolveRenderTarget(GrRenderTarget* target) {
1462 SkASSERT(target); 1422 SkASSERT(target);
1463 ASSERT_OWNED_RESOURCE(target); 1423 ASSERT_OWNED_RESOURCE(target);
1464 // In the future we may track whether there are any pending draws to this 1424 // 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 1425 // target. We don't today so we always perform a flush. We don't promise
1466 // this to our clients, though. 1426 // this to our clients, though.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 // allocate a tmp buffer and sw convert the pixels to premul 1527 // allocate a tmp buffer and sw convert the pixels to premul
1568 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); 1528 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0);
1569 1529
1570 if (kUnpremul_PixelOpsFlag & flags) { 1530 if (kUnpremul_PixelOpsFlag & flags) {
1571 if (!GrPixelConfigIs8888(srcConfig)) { 1531 if (!GrPixelConfigIs8888(srcConfig)) {
1572 return false; 1532 return false;
1573 } 1533 }
1574 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix )); 1534 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. 1535 // handle the unpremul step on the CPU if we couldn't create an effect t o do it.
1576 if (NULL == effect) { 1536 if (NULL == effect) {
1577 SkCanvas::Config8888 srcConfig8888, dstConfig8888; 1537 SkPixelInfo srcPI;
1578 SkDEBUGCODE(bool success = ) 1538 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) {
1579 grconfig_to_config8888(srcConfig, true, &srcConfig8888); 1539 return false;
1580 SkASSERT(success); 1540 }
1581 SkDEBUGCODE(success = ) 1541 srcPI.fAlphaType = kUnpremul_SkAlphaType;
1582 grconfig_to_config8888(srcConfig, false, &dstConfig8888); 1542 srcPI.fPixels = const_cast<void*>(buffer); // we promist not to cha nge this
1583 SkASSERT(success); 1543 srcPI.fRowBytes = rowBytes;
1584 const uint32_t* src = reinterpret_cast<const uint32_t*>(buffer); 1544
1585 tmpPixels.reset(width * height); 1545 SkPixelInfo dstPI;
1586 SkConvertConfig8888Pixels(tmpPixels.get(), 4 * width, dstConfig8888, 1546 dstPI.fColorType = srcPI.fColorType;
1587 src, rowBytes, srcConfig8888, 1547 dstPI.fAlphaType = kPremul_SkAlphaType;
1588 width, height); 1548 dstPI.fPixels = tmpPixels.get();
1549 dstPI.fRowBytes = 4 * width;
1550
1551 if (!srcPI.convertPixelsTo(&dstPI, width, height)) {
1552 return false;
1553 }
1554
1589 buffer = tmpPixels.get(); 1555 buffer = tmpPixels.get();
1590 rowBytes = 4 * width; 1556 rowBytes = 4 * width;
1591 } 1557 }
1592 } 1558 }
1593 if (NULL == effect) { 1559 if (NULL == effect) {
1594 effect.reset(GrConfigConversionEffect::Create(texture, 1560 effect.reset(GrConfigConversionEffect::Create(texture,
1595 swapRAndB, 1561 swapRAndB,
1596 GrConfigConversionEffect:: kNone_PMConversion, 1562 GrConfigConversionEffect:: kNone_PMConversion,
1597 textureMatrix)); 1563 textureMatrix));
1598 } 1564 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 } 1772 }
1807 return path; 1773 return path;
1808 } 1774 }
1809 1775
1810 /////////////////////////////////////////////////////////////////////////////// 1776 ///////////////////////////////////////////////////////////////////////////////
1811 #if GR_CACHE_STATS 1777 #if GR_CACHE_STATS
1812 void GrContext::printCacheStats() const { 1778 void GrContext::printCacheStats() const {
1813 fTextureCache->printStats(); 1779 fTextureCache->printStats();
1814 } 1780 }
1815 #endif 1781 #endif
OLDNEW
« src/core/SkConfig8888.h ('K') | « src/core/SkDevice.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698