Update SkSurface MakeFromBackend* factories to take an SkColorType.
Bug: skia:
Change-Id: Ib1b03b1181ec937843eac2e8d8cb03ebe53e32c1
Reviewed-on: https://skia-review.googlesource.com/86760
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 86c8f92..60ecfd2 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -2361,62 +2361,82 @@
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;
+bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
+ GrGLStandard standard) {
+ *config = 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;
+ *config = kAlpha_8_as_Alpha_GrPixelConfig;
} else if (GR_GL_R8 == format) {
- tex->fConfig = kAlpha_8_as_Red_GrPixelConfig;
+ *config = kAlpha_8_as_Red_GrPixelConfig;
}
break;
case kRGB_565_SkColorType:
if (GR_GL_RGB565 == format) {
- tex->fConfig = kRGB_565_GrPixelConfig;
+ *config = kRGB_565_GrPixelConfig;
}
break;
case kARGB_4444_SkColorType:
if (GR_GL_RGBA4 == format) {
- tex->fConfig = kRGBA_4444_GrPixelConfig;
+ *config = kRGBA_4444_GrPixelConfig;
}
break;
case kRGBA_8888_SkColorType:
if (GR_GL_RGBA8 == format) {
- tex->fConfig = kRGBA_8888_GrPixelConfig;
+ *config = kRGBA_8888_GrPixelConfig;
} else if (GR_GL_SRGB8_ALPHA8 == format) {
- tex->fConfig = kSRGBA_8888_GrPixelConfig;
+ *config = kSRGBA_8888_GrPixelConfig;
}
break;
case kBGRA_8888_SkColorType:
- if (GR_GL_BGRA8 == format) {
- tex->fConfig = kBGRA_8888_GrPixelConfig;
+ if (GR_GL_RGBA8 == format) {
+ if (kGL_GrGLStandard == standard) {
+ *config = kBGRA_8888_GrPixelConfig;
+ }
+ } else if (GR_GL_BGRA8 == format) {
+ if (kGLES_GrGLStandard == standard) {
+ *config = kBGRA_8888_GrPixelConfig;
+ }
} else if (GR_GL_SRGB8_ALPHA8 == format) {
- tex->fConfig = kSBGRA_8888_GrPixelConfig;
+ *config = kSBGRA_8888_GrPixelConfig;
}
break;
case kGray_8_SkColorType:
if (GR_GL_LUMINANCE8 == format) {
- tex->fConfig = kGray_8_as_Lum_GrPixelConfig;
+ *config = kGray_8_as_Lum_GrPixelConfig;
} else if (GR_GL_R8 == format) {
- tex->fConfig = kGray_8_as_Red_GrPixelConfig;
+ *config = kGray_8_as_Red_GrPixelConfig;
}
break;
case kRGBA_F16_SkColorType:
if (GR_GL_RGBA16F == format) {
- tex->fConfig = kRGBA_half_GrPixelConfig;
+ *config = kRGBA_half_GrPixelConfig;
}
break;
}
- return kUnknown_GrPixelConfig != tex->fConfig;
+ return kUnknown_GrPixelConfig != *config;
+}
+
+bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
+ GrPixelConfig* config) const {
+ const GrGLTextureInfo* texInfo = tex.getGLTextureInfo();
+ if (!texInfo) {
+ return false;
+ }
+ return validate_sized_format(texInfo->fFormat, ct, config, fStandard);
+}
+
+bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
+ GrPixelConfig* config) const {
+ const GrGLFramebufferInfo* fbInfo = rt.getGLFramebufferInfo();
+ if (!fbInfo) {
+ return false;
+ }
+ return validate_sized_format(fbInfo->fFormat, ct, config, fStandard);
}
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 38cbfe8..6efcc21 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -415,9 +415,12 @@
return fProgramBinarySupport;
}
-private:
- bool onValidateBackendTexture(GrBackendTexture*, SkColorType) const override;
+ bool validateBackendTexture(const GrBackendTexture&, SkColorType,
+ GrPixelConfig*) const override;
+ bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
+ GrPixelConfig*) const override;
+private:
enum ExternalFormatUsage {
kTexImage_ExternalFormatUsage,
kOther_ExternalFormatUsage,
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 3aa632c..443128d 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -82,6 +82,15 @@
return sk_sp<GrGLRenderTarget>(new GrGLRenderTarget(gpu, desc, idDesc, sb));
}
+GrBackendRenderTarget GrGLRenderTarget::getBackendRenderTarget() const {
+ GrGLFramebufferInfo fbi;
+ fbi.fFBOID = fRTFBOID;
+ fbi.fFormat = this->getGLGpu()->glCaps().configSizedInternalFormat(this->config());
+
+ return GrBackendRenderTarget(this->width(), this->height(), this->numColorSamples(),
+ this->numStencilSamples(), fbi);
+}
+
size_t GrGLRenderTarget::onGpuMemorySize() const {
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
fNumSamplesOwnedPerPixel, GrMipMapped::kNo);
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index 28c6e3d..a448848 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -63,13 +63,7 @@
GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; }
- GrBackendRenderTarget getBackendRenderTarget() const override {
- GrGLFramebufferInfo fbi;
- fbi.fFBOID = fRTFBOID;
-
- return GrBackendRenderTarget(this->width(), this->height(), this->numColorSamples(),
- this->numStencilSamples(), this->config(), fbi);
- }
+ GrBackendRenderTarget getBackendRenderTarget() const override;
bool canAttemptStencilAttachment() const override;
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 597c213..9c7fe22 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -107,8 +107,7 @@
}
GrBackendTexture GrGLTexture::getBackendTexture() const {
- return GrBackendTexture(this->width(), this->height(), this->config(),
- this->texturePriv().mipMapped(), fInfo);
+ return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(), fInfo);
}
void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,