diff options
author | Brian Salomon <bsalomon@google.com> | 2018-03-22 10:01:16 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-22 14:49:44 +0000 |
commit | 5fba7ad39a96d02c8a23cc20e47c5021b6a85baa (patch) | |
tree | 17840b99fbcec0957762a06f3952552466e74ddc /src/gpu/GrContext.cpp | |
parent | 9eded2c211773133b86a964b357404ae6b021d7d (diff) |
Support GL_RGB textures and render targets.
Bug= skia:7533
Change-Id: Iba30e90dbf2574368b773bb5cf2ebd5219559717
Reviewed-on: https://skia-review.googlesource.com/108188
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrContext.cpp')
-rw-r--r-- | src/gpu/GrContext.cpp | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 626b3f6ecd..3baf0b9737 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -358,6 +358,7 @@ static bool valid_premul_config(GrPixelConfig config) { case kRGB_565_GrPixelConfig: return false; case kRGBA_4444_GrPixelConfig: return true; case kRGBA_8888_GrPixelConfig: return true; + case kRGB_888_GrPixelConfig: return false; case kBGRA_8888_GrPixelConfig: return true; case kSRGBA_8888_GrPixelConfig: return true; case kSBGRA_8888_GrPixelConfig: return true; @@ -383,6 +384,7 @@ static bool valid_premul_color_type(GrColorType ct) { case GrColorType::kRGB_565: return false; case GrColorType::kABGR_4444: return true; case GrColorType::kRGBA_8888: return true; + case GrColorType::kRGB_888x: return false; case GrColorType::kBGRA_8888: return true; case GrColorType::kRGBA_1010102: return true; case GrColorType::kGray_8: return false; @@ -402,7 +404,6 @@ static bool valid_pixel_conversion(GrColorType cpuColorType, GrPixelConfig gpuCo (!valid_premul_color_type(cpuColorType) || !valid_premul_config(gpuConfig))) { return false; } - return true; } @@ -471,10 +472,20 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top, int height, GrColorType srcColorType, SkColorSpace* srcColorSpace, const void* buffer, size_t rowBytes, uint32_t pixelOpsFlags) { -#ifndef SK_LEGACY_GPU_PIXEL_OPS - return this->writeSurfacePixels2(dst, left, top, width, height, srcColorType, srcColorSpace, - buffer, rowBytes, pixelOpsFlags); + bool useLegacyPath = false; +#ifdef SK_LEGACY_GPU_PIXEL_OPS + useLegacyPath = true; #endif + // Newly added color types/configs are only supported by the new code path. + if (srcColorType == GrColorType::kRGB_888x || + dst->asSurfaceProxy()->config() == kRGB_888_GrPixelConfig) { + useLegacyPath = false; + } + + if (!useLegacyPath) { + return this->writeSurfacePixels2(dst, left, top, width, height, srcColorType, srcColorSpace, + buffer, rowBytes, pixelOpsFlags); + } // TODO: Color space conversion @@ -497,6 +508,14 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top, if (!valid_pixel_conversion(srcColorType, dstProxy->config(), premul)) { return false; } + // There is no way to store alpha values in the dst. + if (GrColorTypeHasAlpha(srcColorType) && GrPixelConfigIsOpaque(dstProxy->config())) { + return false; + } + // The source has no alpha value and the dst is only alpha + if (!GrColorTypeHasAlpha(srcColorType) && GrPixelConfigIsAlphaOnly(dstProxy->config())) { + return false; + } // We need to guarantee round-trip conversion if we are reading and writing 8888 non-sRGB data, // without any color spaces attached, and the caller wants us to premul. @@ -612,10 +631,21 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top, int height, GrColorType dstColorType, SkColorSpace* dstColorSpace, void* buffer, size_t rowBytes, uint32_t flags) { -#ifndef SK_LEGACY_GPU_PIXEL_OPS - return this->readSurfacePixels2(src, left, top, width, height, dstColorType, dstColorSpace, - buffer, rowBytes, flags); + bool useLegacyPath = false; +#ifdef SK_LEGACY_GPU_PIXEL_OPS + useLegacyPath = true; #endif + // Newly added color types/configs are only supported by the new code path. + if (dstColorType == GrColorType::kRGB_888x || + src->asSurfaceProxy()->config() == kRGB_888_GrPixelConfig) { + useLegacyPath = false; + } + + if (!useLegacyPath) { + return this->readSurfacePixels2(src, left, top, width, height, dstColorType, dstColorSpace, + buffer, rowBytes, flags); + } + // TODO: Color space conversion ASSERT_SINGLE_OWNER_PRIV @@ -642,6 +672,18 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top, if (!valid_pixel_conversion(dstColorType, srcProxy->config(), unpremul)) { return false; } + // The source is alpha-only but the dst is not. TODO: Make non-alpha channels in the dst be 0? + if (GrPixelConfigIsAlphaOnly(srcProxy->config()) && !GrColorTypeIsAlphaOnly(dstColorType)) { + return false; + } + // The source has no alpha, the dst is alpha-only. TODO: set all values in dst to 1? + if (GrPixelConfigIsOpaque(srcProxy->config()) && GrColorTypeIsAlphaOnly(dstColorType)) { + return false; + } + // Not clear if we should unpremul in this case. + if (!GrPixelConfigIsOpaque(srcProxy->config()) && !GrColorTypeHasAlpha(dstColorType)) { + return false; + } // We need to guarantee round-trip conversion if we are reading and writing 8888 non-sRGB data, // without any color spaces attached, and the caller wants us to unpremul. @@ -913,10 +955,6 @@ bool GrContextPriv::readSurfacePixels2(GrSurfaceContext* src, int left, int top, int height, GrColorType dstColorType, SkColorSpace* dstColorSpace, void* buffer, size_t rowBytes, uint32_t flags) { - SkASSERT(!(flags & kDontFlush_PixelOpsFlag)); - if (flags & kDontFlush_PixelOpsFlag){ - return false; - } ASSERT_SINGLE_OWNER_PRIV RETURN_FALSE_IF_ABANDONED_PRIV SkASSERT(src); @@ -924,6 +962,11 @@ bool GrContextPriv::readSurfacePixels2(GrSurfaceContext* src, int left, int top, ASSERT_OWNED_PROXY_PRIV(src->asSurfaceProxy()); GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "readSurfacePixels2", fContext); + SkASSERT(!(flags & kDontFlush_PixelOpsFlag)); + if (flags & kDontFlush_PixelOpsFlag) { + return false; + } + // MDB TODO: delay this instantiation until later in the method if (!src->asSurfaceProxy()->instantiate(this->resourceProvider())) { return false; |