diff options
-rw-r--r-- | include/gpu/GrBackendSurface.h | 10 | ||||
-rw-r--r-- | include/gpu/gl/GrGLTypes.h | 6 | ||||
-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 |
7 files changed, 73 insertions, 2 deletions
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index ce6ad194ac..1eab3577b1 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -21,17 +21,27 @@ public: // Creates an invalid backend texture. GrBackendTexture() : fConfig(kUnknown_GrPixelConfig) {} + // GrGLTextureInfo::fFormat is ignored + // Deprecated: Should use version that does not take a GrPixelConfig instead GrBackendTexture(int width, int height, GrPixelConfig config, const GrGLTextureInfo& glInfo); + // GrGLTextureInfo::fFormat is ignored + // Deprecated: Should use version that does not take a GrPixelConfig instead GrBackendTexture(int width, int height, GrPixelConfig config, GrMipMapped, const GrGLTextureInfo& glInfo); + // The GrGLTextureInfo must have a valid fFormat. + GrBackendTexture(int width, + int height, + GrMipMapped, + const GrGLTextureInfo& glInfo); + #ifdef SK_VULKAN GrBackendTexture(int width, int height, diff --git a/include/gpu/gl/GrGLTypes.h b/include/gpu/gl/GrGLTypes.h index a615888980..24e50d833e 100644 --- a/include/gpu/gl/GrGLTypes.h +++ b/include/gpu/gl/GrGLTypes.h @@ -105,12 +105,14 @@ typedef unsigned int GrEGLBoolean; /////////////////////////////////////////////////////////////////////////////// /** * Types for interacting with GL resources created externally to Skia. GrBackendObjects for GL - * textures are really const GrGLTexture* + * textures are really const GrGLTexture*. The fFormat here should be a sized, internal format + * for the texture. We will try to use the sized format if the GL Context supports it, otherwise + * we will internally fall back to using the base internal formats. */ - struct GrGLTextureInfo { GrGLenum fTarget; GrGLuint fID; + GrGLenum fFormat = 0; }; GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLTextureInfo*)); 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 |