Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: src/image/SkSurface_Gpu.cpp

Issue 2270823002: Some tests around surface creation and snapshotting with color space (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/image/SkSurface_Gpu.cpp
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 1d715705c774351e343049b9144d4775587c4f02..ebe103ac5a7bd3afcc7ede140bbe15e379ed9249 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -133,9 +133,44 @@ void SkSurface_Gpu::onPrepareForExternalIO() {
///////////////////////////////////////////////////////////////////////////////
+bool SkSurface_Gpu::Valid(const SkImageInfo& info) {
+ switch (info.colorType()) {
+ case kRGBA_F16_SkColorType:
+ return info.colorSpace() &&
+ SkColorSpace::kLinear_GammaNamed == info.colorSpace()->gammaNamed();
+ case kRGBA_8888_SkColorType:
+ case kBGRA_8888_SkColorType:
+ return !info.colorSpace() || info.colorSpace()->gammaCloseToSRGB();
+ default:
+ return !info.colorSpace();
+ }
+}
+
+bool SkSurface_Gpu::Valid(GrContext* context, GrPixelConfig config, SkColorSpace* colorSpace) {
+ switch (config) {
+ case kRGBA_half_GrPixelConfig:
+ return colorSpace && SkColorSpace::kLinear_GammaNamed == colorSpace->gammaNamed();
+ case kSRGBA_8888_GrPixelConfig:
+ case kSBGRA_8888_GrPixelConfig:
+ return context->caps()->srgbSupport() && colorSpace && colorSpace->gammaCloseToSRGB();
+ case kRGBA_8888_GrPixelConfig:
+ case kBGRA_8888_GrPixelConfig:
+ // If we don't have sRGB support, we may get here with a color space. It still needs
+ // to be sRGB-like (so that the application will work correctly on sRGB devices.)
+ return !colorSpace ||
+ (!context->caps()->srgbSupport() && colorSpace->gammaCloseToSRGB());
+ default:
+ return !colorSpace;
+ }
+}
+
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted,
const SkImageInfo& info, int sampleCount,
GrSurfaceOrigin origin, const SkSurfaceProps* props) {
+ if (!SkSurface_Gpu::Valid(info)) {
+ return nullptr;
+ }
+
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(
ctx, budgeted, info, sampleCount, origin, props, SkGpuDevice::kClear_InitContents));
if (!device) {
@@ -154,6 +189,9 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) {
return nullptr;
}
+ if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) {
+ return nullptr;
+ }
sk_sp<GrDrawContext> dc(context->contextPriv().makeBackendTextureDrawContext(
desc,
@@ -179,6 +217,9 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
if (!context) {
return nullptr;
}
+ if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) {
+ return nullptr;
+ }
sk_sp<GrDrawContext> dc(context->contextPriv().makeBackendRenderTargetDrawContext(
desc,
@@ -204,6 +245,9 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont
if (!context) {
return nullptr;
}
+ if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) {
+ return nullptr;
+ }
sk_sp<GrDrawContext> dc(context->contextPriv().makeBackendTextureAsRenderTargetDrawContext(
desc,
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | tests/SurfaceTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698