aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkSurface_Gpu.cpp
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-12-19 13:15:02 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-19 18:41:36 +0000
commitfaa095e9842b924c20de84dce1bcc1adad7fe2e4 (patch)
tree9651cd2720ae39bad1c364338540902b7910655c /src/image/SkSurface_Gpu.cpp
parent040238bded7b932b916c84912cbaec1207aa29c0 (diff)
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>
Diffstat (limited to 'src/image/SkSurface_Gpu.cpp')
-rw-r--r--src/image/SkSurface_Gpu.cpp104
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