| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrRenderTargetContext.h" | 12 #include "GrRenderTargetContext.h" |
| 13 #include "GrTextureProxy.h" |
| 14 |
| 13 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 14 #include "SkSurface.h" | 16 #include "SkSurface.h" |
| 15 | 17 |
| 16 // using anonymous namespace because these functions are used as template params
. | 18 // using anonymous namespace because these functions are used as template params
. |
| 17 namespace { | 19 namespace { |
| 18 /** convert 0..1 srgb value to 0..1 linear */ | 20 /** convert 0..1 srgb value to 0..1 linear */ |
| 19 float srgb_to_linear(float srgb) { | 21 float srgb_to_linear(float srgb) { |
| 20 if (srgb <= 0.04045f) { | 22 if (srgb <= 0.04045f) { |
| 21 return srgb / 12.92f; | 23 return srgb / 12.92f; |
| 22 } else { | 24 } else { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 } | 37 } |
| 36 | 38 |
| 37 static bool check_value(U8CPU value, U8CPU expected, U8CPU error) { | 39 static bool check_value(U8CPU value, U8CPU expected, U8CPU error) { |
| 38 if (value >= expected) { | 40 if (value >= expected) { |
| 39 return (value - expected) <= error; | 41 return (value - expected) <= error; |
| 40 } else { | 42 } else { |
| 41 return (expected - value) <= error; | 43 return (expected - value) <= error; |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 void read_and_check_pixels(skiatest::Reporter* reporter, GrTexture* texture, U8C
PU expected, | 47 void read_and_check_pixels(skiatest::Reporter* reporter, GrTextureProxy* texture
, U8CPU expected, |
| 46 U8CPU error, const char* subtestName) { | 48 U8CPU error, const char* subtestName) { |
| 47 int w = texture->width(); | 49 int w = texture->width(); |
| 48 int h = texture->height(); | 50 int h = texture->height(); |
| 49 SkAutoTMalloc<uint32_t> readData(w * h); | 51 SkAutoTMalloc<uint32_t> readData(w * h); |
| 50 memset(readData.get(), 0, sizeof(uint32_t) * w * h); | 52 memset(readData.get(), 0, sizeof(uint32_t) * w * h); |
| 51 if (!texture->readPixels(0, 0, w, h, texture->config(), readData.get())) { | 53 if (!texture->readPixels2(0, 0, w, h, texture->config(), readData.get())) { |
| 52 ERRORF(reporter, "Could not read pixels for %s.", subtestName); | 54 ERRORF(reporter, "Could not read pixels for %s.", subtestName); |
| 53 return; | 55 return; |
| 54 } | 56 } |
| 55 for (int j = 0; j < h; ++j) { | 57 for (int j = 0; j < h; ++j) { |
| 56 for (int i = 0; i < w; ++i) { | 58 for (int i = 0; i < w; ++i) { |
| 57 uint32_t read = readData[j * w + i]; | 59 uint32_t read = readData[j * w + i]; |
| 58 | 60 |
| 59 bool success = | 61 bool success = |
| 60 check_value(read & 0xff, expected, error) && | 62 check_value(read & 0xff, expected, error) && |
| 61 check_value((read >> 8) & 0xff, expected, error) && | 63 check_value((read >> 8) & 0xff, expected, error) && |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtS), SkIntToScalar(rtS)); | 131 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtS), SkIntToScalar(rtS)); |
| 130 GrNoClip noClip; | 132 GrNoClip noClip; |
| 131 GrPaint paint; | 133 GrPaint paint; |
| 132 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); | 134 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 133 GrTextureParams mipMapParams(SkShader::kRepeat_TileMode, GrTextureParams::kM
ipMap_FilterMode); | 135 GrTextureParams mipMapParams(SkShader::kRepeat_TileMode, GrTextureParams::kM
ipMap_FilterMode); |
| 134 paint.addColorTextureProcessor(texture.get(), nullptr, SkMatrix::MakeScale(0
.5f), mipMapParams); | 136 paint.addColorTextureProcessor(texture.get(), nullptr, SkMatrix::MakeScale(0
.5f), mipMapParams); |
| 135 | 137 |
| 136 // 1) Draw texture to S32 surface (should generate/use sRGB mips) | 138 // 1) Draw texture to S32 surface (should generate/use sRGB mips) |
| 137 paint.setGammaCorrect(true); | 139 paint.setGammaCorrect(true); |
| 138 s32RenderTargetContext->drawRect(noClip, paint, SkMatrix::I(), rect); | 140 s32RenderTargetContext->drawRect(noClip, paint, SkMatrix::I(), rect); |
| 139 read_and_check_pixels(reporter, s32RenderTargetContext->asTexture().get(), e
xpectedSRGB, error, | 141 read_and_check_pixels(reporter, s32RenderTargetContext->asDeferredTexture().
get(), expectedSRGB, error, |
| 140 "first render of sRGB"); | 142 "first render of sRGB"); |
| 141 | 143 |
| 142 // 2) Draw texture to L32 surface (should generate/use linear mips) | 144 // 2) Draw texture to L32 surface (should generate/use linear mips) |
| 143 paint.setGammaCorrect(false); | 145 paint.setGammaCorrect(false); |
| 144 l32RenderTargetContext->drawRect(noClip, paint, SkMatrix::I(), rect); | 146 l32RenderTargetContext->drawRect(noClip, paint, SkMatrix::I(), rect); |
| 145 read_and_check_pixels(reporter, l32RenderTargetContext->asTexture().get(), e
xpectedLinear, | 147 read_and_check_pixels(reporter, l32RenderTargetContext->asDeferredTexture().
get(), expectedLinear, |
| 146 error, "re-render as linear"); | 148 error, "re-render as linear"); |
| 147 | 149 |
| 148 // 3) Go back to sRGB | 150 // 3) Go back to sRGB |
| 149 paint.setGammaCorrect(true); | 151 paint.setGammaCorrect(true); |
| 150 s32RenderTargetContext->drawRect(noClip, paint, SkMatrix::I(), rect); | 152 s32RenderTargetContext->drawRect(noClip, paint, SkMatrix::I(), rect); |
| 151 read_and_check_pixels(reporter, s32RenderTargetContext->asTexture().get(), e
xpectedSRGB, error, | 153 read_and_check_pixels(reporter, s32RenderTargetContext->asDeferredTexture().
get(), expectedSRGB, error, |
| 152 "re-render as sRGB"); | 154 "re-render as sRGB"); |
| 153 } | 155 } |
| 154 #endif | 156 #endif |
| OLD | NEW |