From e7d8da4b20babbe17abc8f95dd2dea56ee8f9af5 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Mon, 4 Dec 2017 11:23:19 -0500 Subject: Add support for internal gl format in GrGLTextureInfo This gives clients the ability to wrap GL textures with just the GL Format. This enables us to distinquish between wrapping in Alpha8 texture that is implented with Alpha or Red format Bug: skia: Change-Id: Iacbea60a149c436c270b7ff9ce5d019947678793 Reviewed-on: https://skia-review.googlesource.com/72600 Commit-Queue: Greg Daniel Reviewed-by: Brian Salomon Reviewed-by: Robert Phillips --- src/gpu/gl/GrGLGpu.cpp | 7 +++++++ src/gpu/gl/GrGLTexture.cpp | 1 + src/gpu/gl/GrGLUtil.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/gpu/gl/GrGLUtil.h | 1 + 4 files changed, 46 insertions(+) (limited to 'src/gpu/gl') diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 59aa14f37c..8bf6389fb6 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -535,6 +535,9 @@ sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe if (!check_backend_texture(backendTex, this->glCaps(), &idDesc)) { return nullptr; } + if (!idDesc.fInfo.fFormat) { + idDesc.fInfo.fFormat = this->glCaps().configSizedInternalFormat(backendTex.config()); + } if (kBorrow_GrWrapOwnership == ownership) { idDesc.fOwnership = GrBackendObjectOwnership::kBorrowed; } else { @@ -562,6 +565,9 @@ sk_sp GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& if (!check_backend_texture(backendTex, this->glCaps(), &idDesc)) { return nullptr; } + if (!idDesc.fInfo.fFormat) { + idDesc.fInfo.fFormat = this->glCaps().configSizedInternalFormat(backendTex.config()); + } // We don't support rendering to a EXTERNAL texture. if (GR_GL_TEXTURE_EXTERNAL == idDesc.fInfo.fTarget) { @@ -1663,6 +1669,7 @@ bool GrGLGpu::createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info GL_CALL(DeleteTextures(1, &(info->fID))); return false; } + info->fFormat = this->glCaps().configSizedInternalFormat(desc.fConfig); return true; } diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index f7259a57ad..4a4f085081 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -76,6 +76,7 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { SkASSERT(0 != idDesc.fInfo.fID); + SkASSERT(0 != idDesc.fInfo.fFormat); fTexParams.invalidate(); fTexParamsTimestamp = GrGpu::kExpiredTimestamp; fInfo = idDesc.fInfo; diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp index e3ae5447e2..5f1d6519d7 100644 --- a/src/gpu/gl/GrGLUtil.cpp +++ b/src/gpu/gl/GrGLUtil.cpp @@ -7,6 +7,7 @@ #include "GrGLUtil.h" +#include "GrTypesPriv.h" #include "SkMatrix.h" #include @@ -456,3 +457,39 @@ GrGLenum GrToGLStencilFunc(GrStencilTest test) { return gTable[(int)test]; } + +GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat) { + switch (sizedFormat) { + case GR_GL_R8: + return kAlpha_8_as_Red_GrPixelConfig; + case GR_GL_ALPHA8: + return kAlpha_8_as_Alpha_GrPixelConfig; + case GR_GL_RGBA8: + return kRGBA_8888_GrPixelConfig; + case GR_GL_BGRA8: + return kBGRA_8888_GrPixelConfig; + case GR_GL_SRGB8_ALPHA8: + return kSRGBA_8888_GrPixelConfig; + case GR_GL_RGBA8I: + return kRGBA_8888_sint_GrPixelConfig; + case GR_GL_RGB565: + return kRGB_565_GrPixelConfig; + case GR_GL_RGB5: + return kRGB_565_GrPixelConfig; + case GR_GL_RGBA4: + return kRGBA_4444_GrPixelConfig; + case GR_GL_LUMINANCE8: + return kGray_8_GrPixelConfig; + case GR_GL_RGBA32F: + return kRGBA_float_GrPixelConfig; + case GR_GL_RG32F: + return kRG_float_GrPixelConfig; + case GR_GL_R16F: + return kAlpha_half_as_Red_GrPixelConfig; + case GR_GL_RGBA16F: + return kRGBA_half_GrPixelConfig; + default: + return kUnknown_GrPixelConfig; + } +} + diff --git a/src/gpu/gl/GrGLUtil.h b/src/gpu/gl/GrGLUtil.h index 9ba2db6dc0..369ad4c43c 100644 --- a/src/gpu/gl/GrGLUtil.h +++ b/src/gpu/gl/GrGLUtil.h @@ -247,5 +247,6 @@ void GrGLClearErr(const GrGLInterface* gl); GrGLenum GrToGLStencilFunc(GrStencilTest test); +GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat); #endif -- cgit v1.2.3