From f5d8758f29390fd5c135df12bc8a5e196854eda2 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Mon, 18 Dec 2017 14:48:15 -0500 Subject: Add new SkImage factory to create from GrBackendTexture with SkColorType Bug: skia: Change-Id: I46bdc54b6d9cdacc8f5a06644aa6b110837879f0 Reviewed-on: https://skia-review.googlesource.com/84342 Commit-Queue: Greg Daniel Reviewed-by: Brian Salomon --- src/gpu/gl/GrGLCaps.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ src/gpu/gl/GrGLCaps.h | 2 ++ src/gpu/gl/GrGLGpu.cpp | 4 +++- 3 files changed, 60 insertions(+), 1 deletion(-) (limited to 'src/gpu/gl') diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index efc6628266..05e3268dc9 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -2361,3 +2361,58 @@ int GrGLCaps::getSampleCount(int requestedCount, GrPixelConfig config) const { return fConfigTable[config].fColorSampleCounts[count-1]; } +bool GrGLCaps::onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const { + const GrGLTextureInfo* texInfo = tex->getGLTextureInfo(); + if (!texInfo) { + return false; + } + GrGLenum format = texInfo->fFormat; + tex->fConfig = kUnknown_GrPixelConfig; + + switch (ct) { + case kUnknown_SkColorType: + return false; + case kAlpha_8_SkColorType: + if (GR_GL_ALPHA8 == format) { + tex->fConfig = kAlpha_8_as_Alpha_GrPixelConfig; + } else if (GR_GL_R8 == format) { + tex->fConfig = kAlpha_8_as_Red_GrPixelConfig; + } + break; + case kRGB_565_SkColorType: + if (GR_GL_RGB565 == format) { + tex->fConfig = kRGB_565_GrPixelConfig; + } + break; + case kARGB_4444_SkColorType: + if (GR_GL_RGBA4 == format) { + tex->fConfig = kRGBA_4444_GrPixelConfig; + } + break; + case kRGBA_8888_SkColorType: + if (GR_GL_RGBA8 == format) { + tex->fConfig = kRGBA_8888_GrPixelConfig; + } + break; + case kBGRA_8888_SkColorType: + if (GR_GL_BGRA8 == format) { + tex->fConfig = kBGRA_8888_GrPixelConfig; + } + break; + case kGray_8_SkColorType: + if (GR_GL_LUMINANCE8 == format) { + tex->fConfig = kGray_8_as_Lum_GrPixelConfig; + } else if (GR_GL_R8 == format) { + tex->fConfig = kGray_8_as_Red_GrPixelConfig; + } + break; + case kRGBA_F16_SkColorType: + if (GR_GL_RGBA16F == format) { + tex->fConfig = kRGBA_half_GrPixelConfig; + } + break; + } + + return kUnknown_GrPixelConfig != tex->fConfig; +} + diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index 3a50e8a393..38cbfe8747 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -416,6 +416,8 @@ public: } private: + bool onValidateBackendTexture(GrBackendTexture*, SkColorType) const override; + enum ExternalFormatUsage { kTexImage_ExternalFormatUsage, kOther_ExternalFormatUsage, diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 95eb339db8..7b66bcc8a1 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -4421,6 +4421,8 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, i return GrBackendTexture(); // invalid } + info.fFormat = this->glCaps().configSizedInternalFormat(config); + this->unbindCpuToGpuXferBuffer(); // Figure out the number of mip levels. @@ -4447,7 +4449,7 @@ GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, i height = SkTMax(1, height / 2); } - return GrBackendTexture(w, h, config, mipMapped, info); + return GrBackendTexture(w, h, mipMapped, info); } bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { -- cgit v1.2.3