diff options
Diffstat (limited to 'src/image/SkSurface_Gpu.cpp')
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index fc66e43e6c..2bc782b775 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -294,6 +294,52 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrB return sk_make_sp<SkSurface_Gpu>(std::move(device)); } +bool validate_backend_texture(GrContext* ctx, const GrBackendTexture& tex, GrPixelConfig* config, + int sampleCnt, SkColorType ct, sk_sp<SkColorSpace> cs, + bool texturable) { + // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to + // create a fake image info here. + SkImageInfo info = SkImageInfo::Make(1, 1, ct, kPremul_SkAlphaType, cs); + + if (!SkSurface_Gpu::Valid(info)) { + return false; + } + + if (!ctx->caps()->validateBackendTexture(tex, ct, config)) { + return false; + } + + if (!ctx->caps()->isConfigRenderable(*config, sampleCnt > 0)) { + return false; + } + + if (ctx->caps()->getSampleCount(sampleCnt, *config) != sampleCnt) { + return false; + } + + if (texturable && !ctx->caps()->isConfigTexturable(*config)) { + return false; + } + return true; +} + +sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex, + GrSurfaceOrigin origin, int sampleCnt, + SkColorType colorType, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* props) { + if (!context) { + return nullptr; + } + GrBackendTexture texCopy = tex; + if (!validate_backend_texture(context, texCopy, &texCopy.fConfig, + sampleCnt, colorType, colorSpace, true)) { + return nullptr; + } + + return MakeFromBackendTexture(context, texCopy, origin, sampleCnt, colorSpace, props); +} + sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin, @@ -325,6 +371,44 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, return sk_make_sp<SkSurface_Gpu>(std::move(device)); } +bool validate_backend_render_target(GrContext* ctx, const GrBackendRenderTarget& rt, + GrPixelConfig* config, SkColorType ct, sk_sp<SkColorSpace> cs) { + // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to + // create a fake image info here. + SkImageInfo info = SkImageInfo::Make(1, 1, ct, kPremul_SkAlphaType, cs); + + if (!SkSurface_Gpu::Valid(info)) { + return false; + } + + if (!ctx->caps()->validateBackendRenderTarget(rt, ct, config)) { + return false; + } + + if (!ctx->caps()->isConfigRenderable(*config, false)) { + return false; + } + + return true; +} + +sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, + const GrBackendRenderTarget& rt, + GrSurfaceOrigin origin, + SkColorType colorType, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* props) { + if (!context) { + return nullptr; + } + GrBackendRenderTarget rtCopy = rt; + if (!validate_backend_render_target(context, rtCopy, &rtCopy.fConfig, colorType, colorSpace)) { + return nullptr; + } + + return MakeFromBackendRenderTarget(context, rtCopy, origin, colorSpace, props); +} + sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, const GrBackendTexture& tex, GrSurfaceOrigin origin, @@ -357,4 +441,24 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont return sk_make_sp<SkSurface_Gpu>(std::move(device)); } +sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, + const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt, + SkColorType colorType, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* props) { + if (!context) { + return nullptr; + } + GrBackendTexture texCopy = tex; + if (!validate_backend_texture(context, texCopy, &texCopy.fConfig, + sampleCnt, colorType, colorSpace, false)) { + return nullptr; + } + + return MakeFromBackendTextureAsRenderTarget(context, texCopy, origin, sampleCnt, colorSpace, + props); +} + #endif |