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

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

Issue 205963003: Revert "hide Config8888 entirely". Broke a bunch of builds. (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 "SkTrace.h" 33 #include "SkTrace.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 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 config, buffer, rowBytes, 1261 config, buffer, rowBytes,
1263 flags); 1262 flags);
1264 } 1263 }
1265 1264
1266 return false; 1265 return false;
1267 } 1266 }
1268 } 1267 }
1269 1268
1270 #include "SkConfig8888.h" 1269 #include "SkConfig8888.h"
1271 1270
1272 // toggles between RGBA and BGRA 1271 namespace {
1273 static SkColorType toggle_colortype32(SkColorType ct) { 1272 /**
1274 if (kRGBA_8888_SkColorType == ct) { 1273 * Converts a GrPixelConfig to a SkCanvas::Config8888. Only byte-per-channel
1275 return kBGRA_8888_SkColorType; 1274 * formats are representable as Config8888 and so the function returns false
1276 } else { 1275 * if the GrPixelConfig has no equivalent Config8888.
1277 SkASSERT(kBGRA_8888_SkColorType == ct); 1276 */
1278 return kRGBA_8888_SkColorType; 1277 bool grconfig_to_config8888(GrPixelConfig config,
1278 bool unpremul,
1279 SkCanvas::Config8888* config8888) {
1280 switch (config) {
1281 case kRGBA_8888_GrPixelConfig:
1282 if (unpremul) {
1283 *config8888 = SkCanvas::kRGBA_Unpremul_Config8888;
1284 } else {
1285 *config8888 = SkCanvas::kRGBA_Premul_Config8888;
1286 }
1287 return true;
1288 case kBGRA_8888_GrPixelConfig:
1289 if (unpremul) {
1290 *config8888 = SkCanvas::kBGRA_Unpremul_Config8888;
1291 } else {
1292 *config8888 = SkCanvas::kBGRA_Premul_Config8888;
1293 }
1294 return true;
1295 default:
1296 return false;
1279 } 1297 }
1280 } 1298 }
1281 1299
1300 // It returns a configuration with where the byte position of the R & B componen ts are swapped in
1301 // relation to the input config. This should only be called with the result of
1302 // grconfig_to_config8888 as it will fail for other configs.
1303 SkCanvas::Config8888 swap_config8888_red_and_blue(SkCanvas::Config8888 config888 8) {
1304 switch (config8888) {
1305 case SkCanvas::kBGRA_Premul_Config8888:
1306 return SkCanvas::kRGBA_Premul_Config8888;
1307 case SkCanvas::kBGRA_Unpremul_Config8888:
1308 return SkCanvas::kRGBA_Unpremul_Config8888;
1309 case SkCanvas::kRGBA_Premul_Config8888:
1310 return SkCanvas::kBGRA_Premul_Config8888;
1311 case SkCanvas::kRGBA_Unpremul_Config8888:
1312 return SkCanvas::kBGRA_Unpremul_Config8888;
1313 default:
1314 GrCrash("Unexpected input");
1315 return SkCanvas::kBGRA_Unpremul_Config8888;;
1316 }
1317 }
1318 }
1319
1282 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, 1320 bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
1283 int left, int top, int width, int height, 1321 int left, int top, int width, int height,
1284 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes, 1322 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes,
1285 uint32_t flags) { 1323 uint32_t flags) {
1286 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels"); 1324 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels");
1287 ASSERT_OWNED_RESOURCE(target); 1325 ASSERT_OWNED_RESOURCE(target);
1288 1326
1289 if (NULL == target) { 1327 if (NULL == target) {
1290 target = fRenderTarget.get(); 1328 target = fRenderTarget.get();
1291 if (NULL == target) { 1329 if (NULL == target) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 } 1435 }
1398 } 1436 }
1399 } 1437 }
1400 if (!fGpu->readPixels(target, 1438 if (!fGpu->readPixels(target,
1401 left, top, width, height, 1439 left, top, width, height,
1402 readConfig, buffer, rowBytes)) { 1440 readConfig, buffer, rowBytes)) {
1403 return false; 1441 return false;
1404 } 1442 }
1405 // Perform any conversions we weren't able to perform using a scratch textur e. 1443 // Perform any conversions we weren't able to perform using a scratch textur e.
1406 if (unpremul || swapRAndB) { 1444 if (unpremul || swapRAndB) {
1407 SkDstPixelInfo dstPI; 1445 // These are initialized to suppress a warning
1408 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { 1446 SkCanvas::Config8888 srcC8888 = SkCanvas::kNative_Premul_Config8888;
1409 return false; 1447 SkCanvas::Config8888 dstC8888 = SkCanvas::kNative_Premul_Config8888;
1448
1449 SkDEBUGCODE(bool c8888IsValid =) grconfig_to_config8888(dstConfig, false , &srcC8888);
1450 grconfig_to_config8888(dstConfig, unpremul, &dstC8888);
1451
1452 if (swapRAndB) {
1453 SkASSERT(c8888IsValid); // we should only do r/b swap on 8888 config s
1454 srcC8888 = swap_config8888_red_and_blue(srcC8888);
1410 } 1455 }
1411 dstPI.fAlphaType = kUnpremul_SkAlphaType; 1456 SkASSERT(c8888IsValid);
1412 dstPI.fPixels = buffer; 1457 uint32_t* b32 = reinterpret_cast<uint32_t*>(buffer);
1413 dstPI.fRowBytes = rowBytes; 1458 SkConvertConfig8888Pixels(b32, rowBytes, dstC8888,
1414 1459 b32, rowBytes, srcC8888,
1415 SkSrcPixelInfo srcPI; 1460 width, height);
1416 srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : ds tPI.fColorType;
1417 srcPI.fAlphaType = kPremul_SkAlphaType;
1418 srcPI.fPixels = buffer;
1419 srcPI.fRowBytes = rowBytes;
1420
1421 return srcPI.convertPixelsTo(&dstPI, width, height);
1422 } 1461 }
1423 return true; 1462 return true;
1424 } 1463 }
1425 1464
1426 void GrContext::resolveRenderTarget(GrRenderTarget* target) { 1465 void GrContext::resolveRenderTarget(GrRenderTarget* target) {
1427 SkASSERT(target); 1466 SkASSERT(target);
1428 ASSERT_OWNED_RESOURCE(target); 1467 ASSERT_OWNED_RESOURCE(target);
1429 // In the future we may track whether there are any pending draws to this 1468 // In the future we may track whether there are any pending draws to this
1430 // target. We don't today so we always perform a flush. We don't promise 1469 // target. We don't today so we always perform a flush. We don't promise
1431 // this to our clients, though. 1470 // this to our clients, though.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 // allocate a tmp buffer and sw convert the pixels to premul 1571 // allocate a tmp buffer and sw convert the pixels to premul
1533 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); 1572 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0);
1534 1573
1535 if (kUnpremul_PixelOpsFlag & flags) { 1574 if (kUnpremul_PixelOpsFlag & flags) {
1536 if (!GrPixelConfigIs8888(srcConfig)) { 1575 if (!GrPixelConfigIs8888(srcConfig)) {
1537 return false; 1576 return false;
1538 } 1577 }
1539 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix )); 1578 effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix ));
1540 // handle the unpremul step on the CPU if we couldn't create an effect t o do it. 1579 // handle the unpremul step on the CPU if we couldn't create an effect t o do it.
1541 if (NULL == effect) { 1580 if (NULL == effect) {
1542 SkSrcPixelInfo srcPI; 1581 SkCanvas::Config8888 srcConfig8888, dstConfig8888;
1543 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { 1582 SkDEBUGCODE(bool success = )
1544 return false; 1583 grconfig_to_config8888(srcConfig, true, &srcConfig8888);
1545 } 1584 SkASSERT(success);
1546 srcPI.fAlphaType = kUnpremul_SkAlphaType; 1585 SkDEBUGCODE(success = )
1547 srcPI.fPixels = buffer; 1586 grconfig_to_config8888(srcConfig, false, &dstConfig8888);
1548 srcPI.fRowBytes = rowBytes; 1587 SkASSERT(success);
1549 1588 const uint32_t* src = reinterpret_cast<const uint32_t*>(buffer);
1550 SkDstPixelInfo dstPI; 1589 tmpPixels.reset(width * height);
1551 dstPI.fColorType = srcPI.fColorType; 1590 SkConvertConfig8888Pixels(tmpPixels.get(), 4 * width, dstConfig8888,
1552 dstPI.fAlphaType = kPremul_SkAlphaType; 1591 src, rowBytes, srcConfig8888,
1553 dstPI.fPixels = tmpPixels.get(); 1592 width, height);
1554 dstPI.fRowBytes = 4 * width;
1555
1556 if (!srcPI.convertPixelsTo(&dstPI, width, height)) {
1557 return false;
1558 }
1559
1560 buffer = tmpPixels.get(); 1593 buffer = tmpPixels.get();
1561 rowBytes = 4 * width; 1594 rowBytes = 4 * width;
1562 } 1595 }
1563 } 1596 }
1564 if (NULL == effect) { 1597 if (NULL == effect) {
1565 effect.reset(GrConfigConversionEffect::Create(texture, 1598 effect.reset(GrConfigConversionEffect::Create(texture,
1566 swapRAndB, 1599 swapRAndB,
1567 GrConfigConversionEffect:: kNone_PMConversion, 1600 GrConfigConversionEffect:: kNone_PMConversion,
1568 textureMatrix)); 1601 textureMatrix));
1569 } 1602 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 } 1810 }
1778 return path; 1811 return path;
1779 } 1812 }
1780 1813
1781 /////////////////////////////////////////////////////////////////////////////// 1814 ///////////////////////////////////////////////////////////////////////////////
1782 #if GR_CACHE_STATS 1815 #if GR_CACHE_STATS
1783 void GrContext::printCacheStats() const { 1816 void GrContext::printCacheStats() const {
1784 fTextureCache->printStats(); 1817 fTextureCache->printStats();
1785 } 1818 }
1786 #endif 1819 #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