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 <initializer_list> | 8 #include <initializer_list> |
9 #include "Test.h" | 9 #include "Test.h" |
10 | 10 |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrDrawContext.h" | |
14 #include "GrTexture.h" | |
15 #include "GrTextureProvider.h" | |
16 | 13 |
17 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
| 15 #include "SkGammaColorFilter.h" |
18 #include "SkPixmap.h" | 16 #include "SkPixmap.h" |
19 #include "SkSurface.h" | 17 #include "SkSurface.h" |
20 #include "SkUtils.h" | 18 #include "SkUtils.h" |
21 | 19 |
22 // using anonymous namespace because these functions are used as template param
s. | 20 // using anonymous namespace because these functions are used as template param
s. |
23 namespace { | 21 namespace { |
24 /** convert 0..1 linear value to 0..1 srgb */ | 22 /** convert 0..1 linear value to 0..1 srgb */ |
25 float linear_to_srgb(float linear) { | 23 float linear_to_srgb(float linear) { |
26 if (linear <= 0.0031308) { | 24 if (linear <= 0.0031308) { |
27 return linear * 12.92f; | 25 return linear * 12.92f; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (!src || !dst) { | 104 if (!src || !dst) { |
107 ERRORF(reporter, "Could not create surfaces for copy surface tes
t."); | 105 ERRORF(reporter, "Could not create surfaces for copy surface tes
t."); |
108 continue; | 106 continue; |
109 } | 107 } |
110 | 108 |
111 SkCanvas* dstCanvas = dst->getCanvas(); | 109 SkCanvas* dstCanvas = dst->getCanvas(); |
112 | 110 |
113 dstCanvas->clear(SK_ColorRED); | 111 dstCanvas->clear(SK_ColorRED); |
114 dstCanvas->flush(); | 112 dstCanvas->flush(); |
115 | 113 |
116 // Temporary code until applyGamma is replaced | 114 SkPaint gammaPaint; |
117 GrDrawContext* dc = dstCanvas->internal_private_accessTopLayerDrawCo
ntext(); | 115 gammaPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
118 GrRenderTarget* rt = dc->accessRenderTarget(); | 116 gammaPaint.setColorFilter(SkGammaColorFilter::Make(gamma)); |
119 GrTexture* texture = src->getTexture(); | |
120 SkASSERT(texture); | |
121 | 117 |
122 bool result = context->applyGamma(rt, texture, gamma); | 118 dstCanvas->drawImage(src, 0, 0, &gammaPaint); |
123 | 119 dstCanvas->flush(); |
124 // To make the copied src rect correct we would apply any dst clippi
ng | |
125 // back to the src rect, but we don't use it again so don't bother. | |
126 if (!result) { | |
127 ERRORF(reporter, "Unexpected failure from applyGamma."); | |
128 continue; | |
129 } | |
130 | 120 |
131 sk_memset32(read.get(), 0, kW * kH); | 121 sk_memset32(read.get(), 0, kW * kH); |
132 if (!dstCanvas->readPixels(ii, read.get(), kRowBytes, 0, 0)) { | 122 if (!dstCanvas->readPixels(ii, read.get(), kRowBytes, 0, 0)) { |
133 ERRORF(reporter, "Error calling readPixels"); | 123 ERRORF(reporter, "Error calling readPixels"); |
134 continue; | 124 continue; |
135 } | 125 } |
136 | 126 |
137 bool abort = false; | 127 bool abort = false; |
138 // Validate that pixels were copied/transformed correctly. | 128 // Validate that pixels were copied/transformed correctly. |
139 for (int y = 0; y < kH && !abort; ++y) { | 129 for (int y = 0; y < kH && !abort; ++y) { |
140 for (int x = 0; x < kW && !abort; ++x) { | 130 for (int x = 0; x < kW && !abort; ++x) { |
141 uint32_t r = read.get()[y * kW + x]; | 131 uint32_t r = read.get()[y * kW + x]; |
142 uint32_t s = srcPixels.get()[y * kW + x]; | 132 uint32_t s = srcPixels.get()[y * kW + x]; |
143 uint32_t expected; | 133 uint32_t expected; |
144 if (!check_gamma(s, r, gamma, error, &expected)) { | 134 if (!check_gamma(s, r, gamma, error, &expected)) { |
145 ERRORF(reporter, "Expected dst %d,%d to contain 0x%08x " | 135 ERRORF(reporter, "Expected dst %d,%d to contain 0x%08x " |
146 "from src 0x%08x and gamma %f. Got %08x", | 136 "from src 0x%08x and gamma %f. Got %08x", |
147 x, y, expected, s, gamma, r); | 137 x, y, expected, s, gamma, r); |
148 abort = true; | 138 abort = true; |
149 break; | 139 break; |
150 } | 140 } |
151 } | 141 } |
152 } | 142 } |
153 } | 143 } |
154 } | 144 } |
155 } | 145 } |
156 #endif | 146 #endif |
OLD | NEW |