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>
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 59aa14f..8bf6389 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -535,6 +535,9 @@
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 @@
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 @@
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 f7259a5..4a4f085 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -76,6 +76,7 @@
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 e3ae544..5f1d651 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 @@
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 9ba2db6..369ad4c 100644
--- a/src/gpu/gl/GrGLUtil.h
+++ b/src/gpu/gl/GrGLUtil.h
@@ -247,5 +247,6 @@
GrGLenum GrToGLStencilFunc(GrStencilTest test);
+GrPixelConfig GrGLSizedFormatToPixelConfig(GrGLenum sizedFormat);
#endif