aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
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
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')
-rw-r--r--src/gpu/GrBackendSurface.cpp13
-rw-r--r--src/gpu/GrCaps.cpp8
-rw-r--r--src/gpu/gl/GrGLCaps.cpp60
-rw-r--r--src/gpu/gl/GrGLCaps.h7
-rw-r--r--src/gpu/gl/GrGLRenderTarget.cpp9
-rw-r--r--src/gpu/gl/GrGLRenderTarget.h8
-rw-r--r--src/gpu/gl/GrGLTexture.cpp3
-rw-r--r--src/gpu/mock/GrMockCaps.h12
-rw-r--r--src/gpu/mtl/GrMtlCaps.h9
-rw-r--r--src/gpu/vk/GrVkCaps.cpp34
-rw-r--r--src/gpu/vk/GrVkCaps.h7
-rw-r--r--src/image/SkImage_Gpu.cpp14
-rw-r--r--src/image/SkSurface.cpp26
-rw-r--r--src/image/SkSurface_Gpu.cpp104
14 files changed, 251 insertions, 63 deletions
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index a9fd57fac0..406cb228ea 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -127,6 +127,19 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
, fBackend(kOpenGL_GrBackend)
, fGLInfo(glInfo) {}
+GrBackendRenderTarget::GrBackendRenderTarget(int width,
+ int height,
+ int sampleCnt,
+ int stencilBits,
+ const GrGLFramebufferInfo& glInfo)
+ : fWidth(width)
+ , fHeight(height)
+ , fSampleCnt(sampleCnt)
+ , fStencilBits(stencilBits)
+ , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
+ , fBackend(kOpenGL_GrBackend)
+ , fGLInfo(glInfo) {}
+
#ifdef SK_VULKAN
const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) {
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 598cb0a3e7..da32ebfbd9 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -218,11 +218,3 @@ void GrCaps::dumpJSON(SkJSONWriter* writer) const {
writer->endObject();
}
-bool GrCaps::validateBackendTexture(GrBackendTexture* tex, SkColorType ct) const {
- if (!this->onValidateBackendTexture(tex, ct)) {
- return false;
- }
- return this->isConfigTexturable(tex->fConfig);
-}
-
-
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 86c8f92b0d..60ecfd2b32 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -2361,62 +2361,82 @@ 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;
+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 38cbfe8747..6efcc21059 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -415,9 +415,12 @@ public:
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 3aa632c44f..443128d4d4 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -82,6 +82,15 @@ sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu,
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 28c6e3d741..a44884846c 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -63,13 +63,7 @@ public:
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 597c213eda..9c7fe2295c 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -107,8 +107,7 @@ GrBackendObject GrGLTexture::getTextureHandle() const {
}
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,
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index 37bde8201c..edec5563c4 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -51,11 +51,17 @@ public:
return false;
}
-private:
- bool onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const override {
- return SkToBool(tex->getMockTextureInfo());
+ bool validateBackendTexture(const GrBackendTexture& tex, SkColorType,
+ GrPixelConfig*) const override {
+ return SkToBool(tex.getMockTextureInfo());
}
+ bool validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType,
+ GrPixelConfig*) const override {
+ return false;
+ }
+
+private:
GrMockOptions fOptions;
typedef GrCaps INHERITED;
};
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index bc8aac9f8e..70ff74fe59 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -56,11 +56,16 @@ public:
return false;
}
-private:
- bool onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const override {
+ bool validateBackendTexture(const GrBackendTexture&, SkColorType,
+ GrPixelConfig*) const override {
+ return false;
+ }
+ bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
+ GrPixelConfig*) const override {
return false;
}
+private:
void initFeatureSet(MTLFeatureSet featureSet);
void initGrCaps(const id<MTLDevice> device);
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index e6a018b2ba..40cb38f0e6 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -415,59 +415,67 @@ int GrVkCaps::getSampleCount(int requestedCount, GrPixelConfig config) const {
return fConfigTable[config].fColorSampleCounts[count-1];
}
-bool GrVkCaps::onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const {
- const GrVkImageInfo* imageInfo = tex->getVkImageInfo();
+bool validate_image_info(const GrVkImageInfo* imageInfo, SkColorType ct, GrPixelConfig* config) {
if (!imageInfo) {
return false;
}
VkFormat format = imageInfo->fFormat;
- tex->fConfig = kUnknown_GrPixelConfig;
+ *config = kUnknown_GrPixelConfig;
switch (ct) {
case kUnknown_SkColorType:
return false;
case kAlpha_8_SkColorType:
if (VK_FORMAT_R8_UNORM == format) {
- tex->fConfig = kAlpha_8_as_Red_GrPixelConfig;
+ *config = kAlpha_8_as_Red_GrPixelConfig;
}
break;
case kRGB_565_SkColorType:
if (VK_FORMAT_R5G6B5_UNORM_PACK16 == format) {
- tex->fConfig = kRGB_565_GrPixelConfig;
+ *config = kRGB_565_GrPixelConfig;
}
break;
case kARGB_4444_SkColorType:
if (VK_FORMAT_B4G4R4A4_UNORM_PACK16 == format) {
- tex->fConfig = kRGBA_4444_GrPixelConfig;
+ *config = kRGBA_4444_GrPixelConfig;
}
break;
case kRGBA_8888_SkColorType:
if (VK_FORMAT_R8G8B8A8_UNORM == format) {
- tex->fConfig = kRGBA_8888_GrPixelConfig;
+ *config = kRGBA_8888_GrPixelConfig;
} else if (VK_FORMAT_R8G8B8A8_SRGB == format) {
- tex->fConfig = kSRGBA_8888_GrPixelConfig;
+ *config = kSRGBA_8888_GrPixelConfig;
}
break;
case kBGRA_8888_SkColorType:
if (VK_FORMAT_B8G8R8A8_UNORM == format) {
- tex->fConfig = kBGRA_8888_GrPixelConfig;
+ *config = kBGRA_8888_GrPixelConfig;
} else if (VK_FORMAT_B8G8R8A8_SRGB == format) {
- tex->fConfig = kSBGRA_8888_GrPixelConfig;
+ *config = kSBGRA_8888_GrPixelConfig;
}
break;
case kGray_8_SkColorType:
if (VK_FORMAT_R8_UNORM == format) {
- tex->fConfig = kGray_8_as_Red_GrPixelConfig;
+ *config = kGray_8_as_Red_GrPixelConfig;
}
break;
case kRGBA_F16_SkColorType:
if (VK_FORMAT_R16G16B16A16_SFLOAT == format) {
- tex->fConfig = kRGBA_half_GrPixelConfig;
+ *config = kRGBA_half_GrPixelConfig;
}
break;
}
- return kUnknown_GrPixelConfig != tex->fConfig;
+ return kUnknown_GrPixelConfig != *config;
}
+bool GrVkCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
+ GrPixelConfig* config) const {
+ return validate_image_info(tex.getVkImageInfo(), ct, config);
+}
+
+bool GrVkCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
+ GrPixelConfig* config) const {
+ return validate_image_info(rt.getVkImageInfo(), ct, config);
+}
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 8d0ab5dd8a..ad0faf1596 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -111,9 +111,12 @@ public:
bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
bool* rectsMustMatch, bool* disallowSubrect) const override;
-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 VkVendor {
kAMD_VkVendor = 4098,
kImagination_VkVendor = 4112,
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index bf80ac0743..9d2b9490de 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -297,11 +297,14 @@ sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
const GrBackendTexture& tex, GrSurfaceOrigin origin,
SkAlphaType at, sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP, ReleaseContext releaseC) {
+ if (!ctx) {
+ return nullptr;
+ }
return new_wrapped_texture_common(ctx, tex, origin, at, std::move(cs), kBorrow_GrWrapOwnership,
releaseP, releaseC);
}
-bool validate_backend_texture(GrContext* ctx, GrBackendTexture* tex,
+bool validate_backend_texture(GrContext* ctx, const GrBackendTexture& tex, GrPixelConfig* config,
SkColorType ct, SkAlphaType at, 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.
@@ -310,15 +313,18 @@ bool validate_backend_texture(GrContext* ctx, GrBackendTexture* tex,
return false;
}
- return ctx->caps()->validateBackendTexture(tex, ct);
+ return ctx->caps()->validateBackendTexture(tex, ct, config);
}
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
const GrBackendTexture& tex, GrSurfaceOrigin origin,
SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP, ReleaseContext releaseC) {
+ if (!ctx) {
+ return nullptr;
+ }
GrBackendTexture texCopy = tex;
- if (!validate_backend_texture(ctx, &texCopy, ct, at, cs)) {
+ if (!validate_backend_texture(ctx, texCopy, &texCopy.fConfig, ct, at, cs)) {
return nullptr;
}
return MakeFromTexture(ctx, texCopy, origin, at, cs, releaseP, releaseC);
@@ -336,7 +342,7 @@ sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx,
SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs) {
GrBackendTexture texCopy = tex;
- if (!validate_backend_texture(ctx, &texCopy, ct, at, cs)) {
+ if (!validate_backend_texture(ctx, texCopy, &texCopy.fConfig, ct, at, cs)) {
return nullptr;
}
return MakeFromAdoptedTexture(ctx, texCopy, origin, at, cs);
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index 9cef76f236..0a684cce60 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -258,9 +258,25 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTe
return nullptr;
}
+sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTexture&,
+ GrSurfaceOrigin origin, int sampleCnt,
+ SkColorType, sk_sp<SkColorSpace>,
+ const SkSurfaceProps*) {
+ return nullptr;
+}
+
+sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
+ const GrBackendRenderTarget&,
+ GrSurfaceOrigin origin,
+ sk_sp<SkColorSpace>,
+ const SkSurfaceProps*) {
+ return nullptr;
+}
+
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTarget&,
GrSurfaceOrigin origin,
+ SkColorType,
sk_sp<SkColorSpace>,
const SkSurfaceProps*) {
return nullptr;
@@ -275,4 +291,14 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext*,
return nullptr;
}
+sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext*,
+ const GrBackendTexture&,
+ GrSurfaceOrigin origin,
+ int sampleCnt,
+ SkColorType,
+ sk_sp<SkColorSpace>,
+ const SkSurfaceProps*) {
+ return nullptr;
+}
+
#endif
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