Index: src/gpu/SkGpuDevice.cpp |
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
index a6c8a1fc74fceb34ff86038324c78d25368c2fa0..491c58810ef43c801fea3ef25fcc421b7c187985 100644 |
--- a/src/gpu/SkGpuDevice.cpp |
+++ b/src/gpu/SkGpuDevice.cpp |
@@ -68,10 +68,31 @@ enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
/////////////////////////////////////////////////////////////////////////////// |
-/** Checks that the alpha type is legal and gets constructor flags. Returns false if device creation |
- should fail. */ |
-bool SkGpuDevice::CheckAlphaTypeAndGetFlags( |
+/** Checks that the alpha type, color space, etc... is legal and gets constructor flags. |
+ Returns false if device creation should fail. */ |
+bool SkGpuDevice::CheckInfoAndGetFlags( |
const SkImageInfo* info, SkGpuDevice::InitContents init, unsigned* flags) { |
+ if (info) { |
+ switch (info->colorType()) { |
+ case kRGBA_F16_SkColorType: |
+ if (!info->colorSpace() || |
+ SkColorSpace::kLinear_GammaNamed != info->colorSpace()->gammaNamed()) { |
+ return false; |
+ } |
+ break; |
+ case kRGBA_8888_SkColorType: |
+ case kBGRA_8888_SkColorType: |
+ if (info->colorSpace() && !info->colorSpace()->gammaCloseToSRGB()) { |
+ return false; |
+ } |
+ break; |
+ default: |
+ if (info->colorSpace()) { |
+ return false; |
+ } |
+ } |
+ } |
+ |
*flags = 0; |
if (info) { |
switch (info->alphaType()) { |
@@ -97,7 +118,7 @@ sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, |
return nullptr; |
} |
unsigned flags; |
- if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
+ if (!CheckInfoAndGetFlags(nullptr, init, &flags)) { |
return nullptr; |
} |
return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, height, flags)); |
@@ -108,7 +129,7 @@ sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
GrSurfaceOrigin origin, |
const SkSurfaceProps* props, InitContents init) { |
unsigned flags; |
- if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
+ if (!CheckInfoAndGetFlags(&info, init, &flags)) { |
return nullptr; |
} |