diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-20 13:26:45 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-20 13:26:45 +0000 |
commit | 180e36abf6e5da1688c9da5ef614a78c471834d5 (patch) | |
tree | 43708e07ed605d05e29169ef03ad705ce61cf29b /src/gpu | |
parent | be41d38f1c076c9e4dc595a6e1a4eb5ccdbd307b (diff) |
Revert "hide Config8888 entirely". Broke a bunch of builds.
This reverts commit fa11c49cc11a6c9ebafbf9c59e118917f9b3cc56.
Revert "Sanitizing source files in Housekeeper-Nightly" to make the above revert clean.
This reverts commit b5787422c8eb2a27a9576777597fd9e06784acdb.
TBR=reed@google.com
TBR=jcgregorio@google.com
Review URL: https://codereview.chromium.org/205963003
git-svn-id: http://skia.googlecode.com/svn/trunk@13872 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 111 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 21 |
2 files changed, 77 insertions, 55 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index ba53a48725..c480a1f718 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -25,7 +25,6 @@ #include "GrSoftwarePathRenderer.h" #include "GrStencilBuffer.h" #include "GrTextStrike.h" -#include "SkGr.h" #include "SkRTConf.h" #include "SkRRect.h" #include "SkStrokeRec.h" @@ -1269,15 +1268,54 @@ bool GrContext::readTexturePixels(GrTexture* texture, #include "SkConfig8888.h" -// toggles between RGBA and BGRA -static SkColorType toggle_colortype32(SkColorType ct) { - if (kRGBA_8888_SkColorType == ct) { - return kBGRA_8888_SkColorType; - } else { - SkASSERT(kBGRA_8888_SkColorType == ct); - return kRGBA_8888_SkColorType; +namespace { +/** + * Converts a GrPixelConfig to a SkCanvas::Config8888. Only byte-per-channel + * formats are representable as Config8888 and so the function returns false + * if the GrPixelConfig has no equivalent Config8888. + */ +bool grconfig_to_config8888(GrPixelConfig config, + bool unpremul, + SkCanvas::Config8888* config8888) { + switch (config) { + case kRGBA_8888_GrPixelConfig: + if (unpremul) { + *config8888 = SkCanvas::kRGBA_Unpremul_Config8888; + } else { + *config8888 = SkCanvas::kRGBA_Premul_Config8888; + } + return true; + case kBGRA_8888_GrPixelConfig: + if (unpremul) { + *config8888 = SkCanvas::kBGRA_Unpremul_Config8888; + } else { + *config8888 = SkCanvas::kBGRA_Premul_Config8888; + } + return true; + default: + return false; + } +} + +// It returns a configuration with where the byte position of the R & B components are swapped in +// relation to the input config. This should only be called with the result of +// grconfig_to_config8888 as it will fail for other configs. +SkCanvas::Config8888 swap_config8888_red_and_blue(SkCanvas::Config8888 config8888) { + switch (config8888) { + case SkCanvas::kBGRA_Premul_Config8888: + return SkCanvas::kRGBA_Premul_Config8888; + case SkCanvas::kBGRA_Unpremul_Config8888: + return SkCanvas::kRGBA_Unpremul_Config8888; + case SkCanvas::kRGBA_Premul_Config8888: + return SkCanvas::kBGRA_Premul_Config8888; + case SkCanvas::kRGBA_Unpremul_Config8888: + return SkCanvas::kBGRA_Unpremul_Config8888; + default: + GrCrash("Unexpected input"); + return SkCanvas::kBGRA_Unpremul_Config8888;; } } +} bool GrContext::readRenderTargetPixels(GrRenderTarget* target, int left, int top, int width, int height, @@ -1404,21 +1442,22 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target, } // Perform any conversions we weren't able to perform using a scratch texture. if (unpremul || swapRAndB) { - SkDstPixelInfo dstPI; - if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { - return false; - } - dstPI.fAlphaType = kUnpremul_SkAlphaType; - dstPI.fPixels = buffer; - dstPI.fRowBytes = rowBytes; + // These are initialized to suppress a warning + SkCanvas::Config8888 srcC8888 = SkCanvas::kNative_Premul_Config8888; + SkCanvas::Config8888 dstC8888 = SkCanvas::kNative_Premul_Config8888; - SkSrcPixelInfo srcPI; - srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : dstPI.fColorType; - srcPI.fAlphaType = kPremul_SkAlphaType; - srcPI.fPixels = buffer; - srcPI.fRowBytes = rowBytes; + SkDEBUGCODE(bool c8888IsValid =) grconfig_to_config8888(dstConfig, false, &srcC8888); + grconfig_to_config8888(dstConfig, unpremul, &dstC8888); - return srcPI.convertPixelsTo(&dstPI, width, height); + if (swapRAndB) { + SkASSERT(c8888IsValid); // we should only do r/b swap on 8888 configs + srcC8888 = swap_config8888_red_and_blue(srcC8888); + } + SkASSERT(c8888IsValid); + uint32_t* b32 = reinterpret_cast<uint32_t*>(buffer); + SkConvertConfig8888Pixels(b32, rowBytes, dstC8888, + b32, rowBytes, srcC8888, + width, height); } return true; } @@ -1539,24 +1578,18 @@ bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix)); // handle the unpremul step on the CPU if we couldn't create an effect to do it. if (NULL == effect) { - SkSrcPixelInfo srcPI; - if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { - return false; - } - srcPI.fAlphaType = kUnpremul_SkAlphaType; - srcPI.fPixels = buffer; - srcPI.fRowBytes = rowBytes; - - SkDstPixelInfo dstPI; - dstPI.fColorType = srcPI.fColorType; - dstPI.fAlphaType = kPremul_SkAlphaType; - dstPI.fPixels = tmpPixels.get(); - dstPI.fRowBytes = 4 * width; - - if (!srcPI.convertPixelsTo(&dstPI, width, height)) { - return false; - } - + SkCanvas::Config8888 srcConfig8888, dstConfig8888; + SkDEBUGCODE(bool success = ) + grconfig_to_config8888(srcConfig, true, &srcConfig8888); + SkASSERT(success); + SkDEBUGCODE(success = ) + grconfig_to_config8888(srcConfig, false, &dstConfig8888); + SkASSERT(success); + const uint32_t* src = reinterpret_cast<const uint32_t*>(buffer); + tmpPixels.reset(width * height); + SkConvertConfig8888Pixels(tmpPixels.get(), 4 * width, dstConfig8888, + src, rowBytes, srcConfig8888, + width, height); buffer = tmpPixels.get(); rowBytes = 4 * width; } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index db46b86901..94e4c8c35d 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -34,22 +34,11 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { SkColorTable* ctable = bitmap.getColorTable(); char* dst = (char*)buffer; - const int count = ctable->count(); - - SkDstPixelInfo dstPI; - dstPI.fColorType = kRGBA_8888_SkColorType; - dstPI.fAlphaType = kPremul_SkAlphaType; - dstPI.fPixels = buffer; - dstPI.fRowBytes = count * sizeof(SkPMColor); - - SkSrcPixelInfo srcPI; - srcPI.fColorType = kPMColor_SkColorType; - srcPI.fAlphaType = kPremul_SkAlphaType; - srcPI.fPixels = ctable->lockColors(); - srcPI.fRowBytes = count * sizeof(SkPMColor); - - srcPI.convertPixelsTo(&dstPI, count, 1); - + uint32_t* colorTableDst = reinterpret_cast<uint32_t*>(dst); + const uint32_t* colorTableSrc = reinterpret_cast<const uint32_t*>(ctable->lockColors()); + SkConvertConfig8888Pixels(colorTableDst, 0, SkCanvas::kRGBA_Premul_Config8888, + colorTableSrc, 0, SkCanvas::kNative_Premul_Config8888, + ctable->count(), 1); ctable->unlockColors(); // always skip a full 256 number of entries, even if we memcpy'd fewer |