bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Test.h" |
| 9 | #if SK_SUPPORT_GPU |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 11 | #include "GrContext.h" |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 12 | #include "GrContextPriv.h" |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 13 | #include "GrSurfaceContext.h" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 14 | #include "SkCanvas.h" |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 15 | #include "SkGr.h" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 16 | #include "SkSurface.h" |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 17 | |
| 18 | // using anonymous namespace because these functions are used as template params. |
| 19 | namespace { |
| 20 | /** convert 0..1 srgb value to 0..1 linear */ |
| 21 | float srgb_to_linear(float srgb) { |
| 22 | if (srgb <= 0.04045f) { |
| 23 | return srgb / 12.92f; |
| 24 | } else { |
| 25 | return powf((srgb + 0.055f) / 1.055f, 2.4f); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | /** convert 0..1 linear value to 0..1 srgb */ |
| 30 | float linear_to_srgb(float linear) { |
| 31 | if (linear <= 0.0031308) { |
| 32 | return linear * 12.92f; |
| 33 | } else { |
| 34 | return 1.055f * powf(linear, 1.f / 2.4f) - 0.055f; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** tests a conversion with an error tolerance */ |
| 40 | template <float (*CONVERT)(float)> static bool check_conversion(uint32_t input, uint32_t output, |
| 41 | float error) { |
| 42 | // alpha should always be exactly preserved. |
| 43 | if ((input & 0xff000000) != (output & 0xff000000)) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | for (int c = 0; c < 3; ++c) { |
| 48 | uint8_t inputComponent = (uint8_t) ((input & (0xff << (c*8))) >> (c*8)); |
| 49 | float lower = SkTMax(0.f, (float) inputComponent - error); |
| 50 | float upper = SkTMin(255.f, (float) inputComponent + error); |
| 51 | lower = CONVERT(lower / 255.f); |
| 52 | upper = CONVERT(upper / 255.f); |
| 53 | SkASSERT(lower >= 0.f && lower <= 255.f); |
| 54 | SkASSERT(upper >= 0.f && upper <= 255.f); |
| 55 | uint8_t outputComponent = (output & (0xff << (c*8))) >> (c*8); |
| 56 | if (outputComponent < SkScalarFloorToInt(lower * 255.f) || |
| 57 | outputComponent > SkScalarCeilToInt(upper * 255.f)) { |
| 58 | return false; |
| 59 | } |
| 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | /** tests a forward and backward conversion with an error tolerance */ |
| 65 | template <float (*FORWARD)(float), float (*BACKWARD)(float)> |
| 66 | static bool check_double_conversion(uint32_t input, uint32_t output, float error) { |
| 67 | // alpha should always be exactly preserved. |
| 68 | if ((input & 0xff000000) != (output & 0xff000000)) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | for (int c = 0; c < 3; ++c) { |
| 73 | uint8_t inputComponent = (uint8_t) ((input & (0xff << (c*8))) >> (c*8)); |
| 74 | float lower = SkTMax(0.f, (float) inputComponent - error); |
| 75 | float upper = SkTMin(255.f, (float) inputComponent + error); |
| 76 | lower = FORWARD(lower / 255.f); |
| 77 | upper = FORWARD(upper / 255.f); |
| 78 | SkASSERT(lower >= 0.f && lower <= 255.f); |
| 79 | SkASSERT(upper >= 0.f && upper <= 255.f); |
| 80 | uint8_t upperComponent = SkScalarCeilToInt(upper * 255.f); |
| 81 | uint8_t lowerComponent = SkScalarFloorToInt(lower * 255.f); |
| 82 | lower = SkTMax(0.f, (float) lowerComponent - error); |
| 83 | upper = SkTMin(255.f, (float) upperComponent + error); |
| 84 | lower = BACKWARD(lowerComponent / 255.f); |
| 85 | upper = BACKWARD(upperComponent / 255.f); |
| 86 | SkASSERT(lower >= 0.f && lower <= 255.f); |
| 87 | SkASSERT(upper >= 0.f && upper <= 255.f); |
| 88 | upperComponent = SkScalarCeilToInt(upper * 255.f); |
| 89 | lowerComponent = SkScalarFloorToInt(lower * 255.f); |
| 90 | |
| 91 | uint8_t outputComponent = (output & (0xff << (c*8))) >> (c*8); |
| 92 | if (outputComponent < lowerComponent || outputComponent > upperComponent) { |
| 93 | return false; |
| 94 | } |
| 95 | } |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | static bool check_srgb_to_linear_conversion(uint32_t srgb, uint32_t linear, float error) { |
| 100 | return check_conversion<srgb_to_linear>(srgb, linear, error); |
| 101 | } |
| 102 | |
| 103 | static bool check_linear_to_srgb_conversion(uint32_t linear, uint32_t srgb, float error) { |
| 104 | return check_conversion<linear_to_srgb>(linear, srgb, error); |
| 105 | } |
| 106 | |
| 107 | static bool check_linear_to_srgb_to_linear_conversion(uint32_t input, uint32_t output, float error) { |
| 108 | return check_double_conversion<linear_to_srgb, srgb_to_linear>(input, output, error); |
| 109 | } |
| 110 | |
| 111 | static bool check_srgb_to_linear_to_srgb_conversion(uint32_t input, uint32_t output, float error) { |
| 112 | return check_double_conversion<srgb_to_linear, linear_to_srgb>(input, output, error); |
| 113 | } |
| 114 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 115 | static bool check_no_conversion(uint32_t input, uint32_t output, float error) { |
| 116 | // This is a bit of a hack to check identity transformations that may lose precision. |
| 117 | return check_srgb_to_linear_to_srgb_conversion(input, output, error); |
| 118 | } |
| 119 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 120 | typedef bool (*CheckFn) (uint32_t orig, uint32_t actual, float error); |
| 121 | |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 122 | void read_and_check_pixels(skiatest::Reporter* reporter, GrSurfaceContext* context, |
| 123 | uint32_t* origData, |
| 124 | const SkImageInfo& dstInfo, CheckFn checker, float error, |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 125 | const char* subtestName) { |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 126 | int w = dstInfo.width(); |
| 127 | int h = dstInfo.height(); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 128 | SkAutoTMalloc<uint32_t> readData(w * h); |
| 129 | memset(readData.get(), 0, sizeof(uint32_t) * w * h); |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 130 | |
| 131 | if (!context->readPixels(dstInfo, readData.get(), 0, 0, 0)) { |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 132 | ERRORF(reporter, "Could not read pixels for %s.", subtestName); |
| 133 | return; |
| 134 | } |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 135 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 136 | for (int j = 0; j < h; ++j) { |
| 137 | for (int i = 0; i < w; ++i) { |
| 138 | uint32_t orig = origData[j * w + i]; |
| 139 | uint32_t read = readData[j * w + i]; |
| 140 | |
| 141 | if (!checker(orig, read, error)) { |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 142 | ERRORF(reporter, "Original 0x%08x, read back as 0x%08x in %s at %d, %d).", orig, |
| 143 | read, subtestName, i, j); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 150 | namespace { |
| 151 | enum class Encoding { |
| 152 | kUntagged, |
| 153 | kLinear, |
| 154 | kSRGB, |
| 155 | }; |
| 156 | } |
| 157 | |
| 158 | static sk_sp<SkColorSpace> encoding_as_color_space(Encoding encoding) { |
| 159 | switch (encoding) { |
| 160 | case Encoding::kUntagged: return nullptr; |
| 161 | case Encoding::kLinear: return SkColorSpace::MakeSRGBLinear(); |
| 162 | case Encoding::kSRGB: return SkColorSpace::MakeSRGB(); |
| 163 | } |
| 164 | return nullptr; |
| 165 | } |
| 166 | |
| 167 | static GrPixelConfig encoding_as_pixel_config(Encoding encoding) { |
| 168 | switch (encoding) { |
| 169 | case Encoding::kUntagged: return kRGBA_8888_GrPixelConfig; |
| 170 | case Encoding::kLinear: return kRGBA_8888_GrPixelConfig; |
| 171 | case Encoding::kSRGB: return kSRGBA_8888_GrPixelConfig; |
| 172 | } |
| 173 | return kUnknown_GrPixelConfig; |
| 174 | } |
| 175 | |
| 176 | static const char* encoding_as_str(Encoding encoding) { |
| 177 | switch (encoding) { |
| 178 | case Encoding::kUntagged: return "untagged"; |
| 179 | case Encoding::kLinear: return "linear"; |
| 180 | case Encoding::kSRGB: return "sRGB"; |
| 181 | } |
| 182 | return nullptr; |
| 183 | } |
| 184 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 185 | static constexpr int kW = 255; |
| 186 | static constexpr int kH = 255; |
| 187 | |
| 188 | static std::unique_ptr<uint32_t[]> make_data() { |
| 189 | std::unique_ptr<uint32_t[]> data(new uint32_t[kW * kH]); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 190 | for (int j = 0; j < kH; ++j) { |
| 191 | for (int i = 0; i < kW; ++i) { |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 192 | data[j * kW + i] = (j << 24) | (i << 16) | (i << 8) | i; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 195 | return data; |
| 196 | } |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 197 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 198 | static sk_sp<GrSurfaceContext> make_surface_context(Encoding contextEncoding, GrContext* context, |
| 199 | skiatest::Reporter* reporter) { |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 200 | GrSurfaceDesc desc; |
| 201 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 202 | desc.fWidth = kW; |
| 203 | desc.fHeight = kH; |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 204 | desc.fConfig = encoding_as_pixel_config(contextEncoding); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 205 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 206 | auto surfaceContext = context->contextPriv().makeDeferredSurfaceContext( |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 207 | desc, kBottomLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact, |
| 208 | SkBudgeted::kNo, encoding_as_color_space(contextEncoding)); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 209 | if (!surfaceContext) { |
| 210 | ERRORF(reporter, "Could not create %s surface context.", encoding_as_str(contextEncoding)); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 211 | } |
| 212 | return surfaceContext; |
| 213 | } |
| 214 | |
| 215 | #ifndef SK_LEGACY_GPU_PIXEL_OPS |
| 216 | static void text_write_fails(Encoding contextEncoding, Encoding writeEncoding, GrContext* context, |
| 217 | skiatest::Reporter* reporter) { |
| 218 | auto surfaceContext = make_surface_context(contextEncoding, context, reporter); |
| 219 | if (!surfaceContext) { |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 220 | return; |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 221 | } |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 222 | auto writeII = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 223 | encoding_as_color_space(writeEncoding)); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 224 | auto data = make_data(); |
| 225 | if (surfaceContext->writePixels(writeII, data.get(), 0, 0, 0)) { |
| 226 | ERRORF(reporter, "Expected %s write to %s surface context to fail.", |
| 227 | encoding_as_str(writeEncoding), encoding_as_str(contextEncoding)); |
| 228 | } |
| 229 | } |
| 230 | #endif |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 231 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 232 | static void test_write_read(Encoding contextEncoding, Encoding writeEncoding, Encoding readEncoding, |
| 233 | float error, CheckFn check, GrContext* context, |
| 234 | skiatest::Reporter* reporter) { |
| 235 | auto surfaceContext = make_surface_context(contextEncoding, context, reporter); |
| 236 | if (!surfaceContext) { |
| 237 | return; |
| 238 | } |
| 239 | auto writeII = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 240 | encoding_as_color_space(writeEncoding)); |
| 241 | auto data = make_data(); |
| 242 | if (!surfaceContext->writePixels(writeII, data.get(), 0, 0, 0)) { |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 243 | ERRORF(reporter, "Could not write %s to %s surface context.", |
| 244 | encoding_as_str(writeEncoding), encoding_as_str(contextEncoding)); |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | auto readII = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 249 | encoding_as_color_space(readEncoding)); |
| 250 | SkString testName; |
| 251 | testName.printf("write %s data to a %s context and read as %s.", encoding_as_str(writeEncoding), |
| 252 | encoding_as_str(contextEncoding), encoding_as_str(readEncoding)); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 253 | read_and_check_pixels(reporter, surfaceContext.get(), data.get(), readII, check, error, |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 254 | testName.c_str()); |
| 255 | } |
| 256 | |
| 257 | // Test all combinations of writePixels/readPixels where the surface context/write source/read dst |
| 258 | // are sRGB, linear, or untagged RGBA_8888. |
| 259 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { |
| 260 | GrContext* context = ctxInfo.grContext(); |
| 261 | if (!context->caps()->isConfigRenderable(kSRGBA_8888_GrPixelConfig) && |
| 262 | !context->caps()->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) { |
| 263 | return; |
| 264 | } |
| 265 | // We allow more error on GPUs with lower precision shader variables. |
| 266 | float error = context->caps()->shaderCaps()->halfIs32Bits() ? 0.5f : 1.2f; |
| 267 | // For the all-sRGB case, we allow a small error only for devices that have |
| 268 | // precision variation because the sRGB data gets converted to linear and back in |
| 269 | // the shader. |
| 270 | float smallError = context->caps()->shaderCaps()->halfIs32Bits() ? 0.0f : 1.f; |
| 271 | |
| 272 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 273 | // Write sRGB data to a sRGB context - no conversion on the write. |
| 274 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 275 | // back to sRGB - no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 276 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kSRGB, smallError, |
| 277 | check_no_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 278 | #ifdef SK_LEGACY_GPU_PIXEL_OPS |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 279 | // Untagged read from sRGB is treated as a conversion back to linear. TODO: Fail or don't |
| 280 | // convert? |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 281 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kUntagged, error, |
| 282 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 283 | #else |
| 284 | // Reading back to untagged should be a pass through with no conversion. |
| 285 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kUntagged, error, |
| 286 | check_no_conversion, context, reporter); |
| 287 | #endif |
| 288 | |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 289 | // Converts back to linear |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 290 | test_write_read(Encoding::kSRGB, Encoding::kSRGB, Encoding::kLinear, error, |
| 291 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 292 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 293 | #ifdef SK_LEGACY_GPU_PIXEL_OPS |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 294 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 295 | // Write untagged data to a sRGB context - Currently this treats the untagged data as |
| 296 | // linear and converts to sRGB during the write. TODO: Fail or passthrough? |
| 297 | |
| 298 | // read back to srgb, no additional conversion |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 299 | test_write_read(Encoding::kSRGB, Encoding::kUntagged, Encoding::kSRGB, error, |
| 300 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 301 | // read back to untagged. Currently converts back to linear. TODO: Fail or don't convert? |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 302 | test_write_read(Encoding::kSRGB, Encoding::kUntagged, Encoding::kUntagged, error, |
| 303 | check_linear_to_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 304 | // Converts back to linear. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 305 | test_write_read(Encoding::kSRGB, Encoding::kUntagged, Encoding::kLinear, error, |
| 306 | check_linear_to_srgb_to_linear_conversion, context, reporter); |
| 307 | #else |
| 308 | // Currently writing untagged data to kSRGB fails because SkImageInfoValidConversion fails. |
| 309 | text_write_fails(Encoding::kSRGB, Encoding::kUntagged, context, reporter); |
| 310 | #endif |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 311 | |
| 312 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 313 | // Write linear data to a sRGB context. It gets converted to sRGB on write. The reads |
| 314 | // are all the same as the above cases where the original data was untagged. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 315 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kSRGB, error, |
| 316 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 317 | #ifdef SK_LEGACY_GPU_PIXEL_OPS |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 318 | // TODO: Fail or don't convert? |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 319 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kUntagged, error, |
| 320 | check_linear_to_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 321 | #else |
| 322 | // When the dst buffer is untagged there should be no conversion on the read. |
| 323 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kUntagged, error, |
| 324 | check_linear_to_srgb_conversion, context, reporter); |
| 325 | #endif |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 326 | test_write_read(Encoding::kSRGB, Encoding::kLinear, Encoding::kLinear, error, |
| 327 | check_linear_to_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 328 | |
| 329 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 330 | // Write data to an untagged context. The write does no conversion no matter what encoding the |
| 331 | // src data has. |
| 332 | for (auto writeEncoding : {Encoding::kSRGB, Encoding::kUntagged, Encoding::kLinear}) { |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 333 | // The read from untagged to sRGB also does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 334 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kSRGB, error, |
| 335 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 336 | // Reading untagged back as untagged should do no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 337 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kUntagged, error, |
| 338 | check_no_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 339 | // Reading untagged back as linear does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 340 | test_write_read(Encoding::kUntagged, writeEncoding, Encoding::kLinear, error, |
| 341 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 345 | // Write sRGB data to a linear context - converts to sRGB on the write. |
| 346 | |
| 347 | // converts back to sRGB on read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 348 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kSRGB, error, |
| 349 | check_srgb_to_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 350 | // Reading untagged data from linear currently does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 351 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kUntagged, error, |
| 352 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 353 | // Stays linear when read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 354 | test_write_read(Encoding::kLinear, Encoding::kSRGB, Encoding::kLinear, error, |
| 355 | check_srgb_to_linear_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 356 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 357 | #ifdef SK_LEGACY_GPU_PIXEL_OPS |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 358 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 359 | // Write untagged data to a linear context. Currently does no conversion. TODO: Should this |
| 360 | // fail? |
| 361 | |
| 362 | // Reading to sRGB does a conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 363 | test_write_read(Encoding::kLinear, Encoding::kUntagged, Encoding::kSRGB, error, |
| 364 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 365 | // Reading to untagged does no conversion. TODO: Should it fail? |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 366 | test_write_read(Encoding::kLinear, Encoding::kUntagged, Encoding::kUntagged, error, |
| 367 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 368 | // Stays linear when read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 369 | test_write_read(Encoding::kLinear, Encoding::kUntagged, Encoding::kLinear, error, |
| 370 | check_no_conversion, context, reporter); |
| 371 | #else |
| 372 | // Currently writing untagged data to kLinear fails because SkImageInfoValidConversion fails. |
| 373 | text_write_fails(Encoding::kSRGB, Encoding::kUntagged, context, reporter); |
| 374 | #endif |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 375 | |
| 376 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 377 | // Write linear data to a linear context. Does no conversion. |
| 378 | |
| 379 | // Reading to sRGB does a conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 380 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kSRGB, error, |
| 381 | check_linear_to_srgb_conversion, context, reporter); |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 382 | // Reading to untagged does no conversion. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 383 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kUntagged, error, |
| 384 | check_no_conversion, context, reporter); |
Brian Salomon | f802e75 | 2018-02-13 17:13:31 -0500 | [diff] [blame] | 385 | // Stays linear when read. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 386 | test_write_read(Encoding::kLinear, Encoding::kLinear, Encoding::kLinear, error, |
| 387 | check_no_conversion, context, reporter); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 388 | } |
| 389 | #endif |