diff options
author | Greg Daniel <egdaniel@google.com> | 2017-12-04 11:23:19 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-04 16:43:39 +0000 |
commit | e7d8da4b20babbe17abc8f95dd2dea56ee8f9af5 (patch) | |
tree | 100e00396f82be2352ff064763f657be9806f8f6 /src | |
parent | 8da3655c6e077c2977a0d3b92aef1de6701277ba (diff) |
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 <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrBackendSurface.cpp | 13 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 7 | ||||
-rw-r--r-- | src/gpu/gl/GrGLTexture.cpp | 1 | ||||
-rw-r--r-- | src/gpu/gl/GrGLUtil.cpp | 37 | ||||
-rw-r--r-- | src/gpu/gl/GrGLUtil.h | 1 |
5 files changed, 59 insertions, 0 deletions
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp index 02e909b118..a9fd57fac0 100644 --- a/src/gpu/GrBackendSurface.cpp +++ b/src/gpu/GrBackendSurface.cpp @@ -7,6 +7,8 @@ #include "GrBackendSurface.h" +#include "gl/GrGLUtil.h" + #ifdef SK_VULKAN #include "vk/GrVkTypes.h" #include "vk/GrVkUtil.h" @@ -44,6 +46,17 @@ GrBackendTexture::GrBackendTexture(int width, GrBackendTexture::GrBackendTexture(int width, int height, + GrMipMapped mipMapped, + const GrGLTextureInfo& glInfo) + : fWidth(width) + , fHeight(height) + , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat)) + , fMipMapped(mipMapped) + , fBackend(kOpenGL_GrBackend) + , fGLInfo(glInfo) {} + +GrBackendTexture::GrBackendTexture(int width, + int height, GrPixelConfig config, const GrMockTextureInfo& mockInfo) : GrBackendTexture(width, height, config, GrMipMapped::kNo, mockInfo) {} 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<GrTexture> 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<GrTexture> 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 <stdio.h> @@ -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 |