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

Side by Side Diff: tests/SRGBReadWritePixelsTest.cpp

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « tests/ResourceCacheTest.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkCanvas.h" 10 #include "SkCanvas.h"
11 11
12 #include "SkSurface.h" 12 #include "SkSurface.h"
13 #include "GrContextFactory.h" 13 #include "GrContextFactory.h"
14 #include "GrCaps.h" 14 #include "GrCaps.h"
15 #include "GrDrawContext.h"
15 16
16 // using anonymous namespace because these functions are used as template params . 17 // using anonymous namespace because these functions are used as template params .
17 namespace { 18 namespace {
18 /** convert 0..1 srgb value to 0..1 linear */ 19 /** convert 0..1 srgb value to 0..1 linear */
19 float srgb_to_linear(float srgb) { 20 float srgb_to_linear(float srgb) {
20 if (srgb <= 0.04045f) { 21 if (srgb <= 0.04045f) {
21 return srgb / 12.92f; 22 return srgb / 12.92f;
22 } else { 23 } else {
23 return powf((srgb + 0.055f) / 1.055f, 2.4f); 24 return powf((srgb + 0.055f) / 1.055f, 2.4f);
24 } 25 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 131
131 if (!checker(orig, read, error)) { 132 if (!checker(orig, read, error)) {
132 ERRORF(reporter, "Expected 0x%08x, read back as 0x%08x in %s at %d, %d).", 133 ERRORF(reporter, "Expected 0x%08x, read back as 0x%08x in %s at %d, %d).",
133 orig, read, subtestName, i, j); 134 orig, read, subtestName, i, j);
134 return; 135 return;
135 } 136 }
136 } 137 }
137 } 138 }
138 } 139 }
139 140
141 #include "GrDrawTarget.h"
142
140 // TODO: Add tests for copySurface between srgb/linear textures. Add tests for u npremul/premul 143 // TODO: Add tests for copySurface between srgb/linear textures. Add tests for u npremul/premul
141 // conversion during read/write along with srgb/linear conversions. 144 // conversion during read/write along with srgb/linear conversions.
142 DEF_GPUTEST(SRGBReadWritePixels, reporter, factory) { 145 DEF_GPUTEST(SRGBReadWritePixels, reporter, factory) {
143 #if defined(GOOGLE3) 146 #if defined(GOOGLE3)
144 // Stack frame size is limited in GOOGLE3. 147 // Stack frame size is limited in GOOGLE3.
145 static const int kW = 63; 148 static const int kW = 63;
146 static const int kH = 63; 149 static const int kH = 63;
147 #else 150 #else
148 static const int kW = 255; 151 static const int kW = 255;
149 static const int kH = 255; 152 static const int kH = 255;
(...skipping 18 matching lines...) Expand all
168 desc.fWidth = kW; 171 desc.fWidth = kW;
169 desc.fHeight = kH; 172 desc.fHeight = kH;
170 desc.fConfig = kSRGBA_8888_GrPixelConfig; 173 desc.fConfig = kSRGBA_8888_GrPixelConfig;
171 if (context->caps()->isConfigRenderable(desc.fConfig, false) && 174 if (context->caps()->isConfigRenderable(desc.fConfig, false) &&
172 context->caps()->isConfigTexturable(desc.fConfig)) { 175 context->caps()->isConfigTexturable(desc.fConfig)) {
173 SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTextur e(desc, false)); 176 SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTextur e(desc, false));
174 if (!tex) { 177 if (!tex) {
175 ERRORF(reporter, "Could not create SRGBA texture."); 178 ERRORF(reporter, "Could not create SRGBA texture.");
176 continue; 179 continue;
177 } 180 }
181 SkAutoTUnref<GrDrawContext> dc(context->drawContext(tex->asRenderTar get()));
182 if (!dc) {
183 ERRORF(reporter, "Could not create SRGBA texture.");
184 continue;
185 }
178 186
179 float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f; 187 float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f;
180 188
181 // Write srgba data and read as srgba and then as rgba 189 // Write srgba data and read as srgba and then as rgba
182 if (tex->writePixels(0, 0, kW, kH, kSRGBA_8888_GrPixelConfig, origDa ta)) { 190 if (tex->writePixels(dc, 0, 0, kW, kH, kSRGBA_8888_GrPixelConfig, or igData)) {
183 // For the all-srgba case, we allow a small error only for devic es that have 191 // For the all-srgba case, we allow a small error only for devic es that have
184 // precision variation because the srgba data gets converted to linear and back in 192 // precision variation because the srgba data gets converted to linear and back in
185 // the shader. 193 // the shader.
186 float smallError = context->caps()->shaderCaps()->floatPrecision Varies() ? 1.f : 194 float smallError = context->caps()->shaderCaps()->floatPrecision Varies() ? 1.f :
187 0.0f; 195 0.0f;
188 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPix elConfig, 196 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPix elConfig,
189 check_srgb_to_linear_to_srgb_conversion, s mallError, 197 check_srgb_to_linear_to_srgb_conversion, s mallError,
190 "write/read srgba to srgba texture"); 198 "write/read srgba to srgba texture");
191 read_and_check_pixels(reporter, tex, origData, kRGBA_8888_GrPixe lConfig, 199 read_and_check_pixels(reporter, tex, origData, kRGBA_8888_GrPixe lConfig,
192 check_srgb_to_linear_conversion, error, 200 check_srgb_to_linear_conversion, error,
193 "write srgba/read rgba with srgba texture" ); 201 "write srgba/read rgba with srgba texture" );
194 } else { 202 } else {
195 ERRORF(reporter, "Could not write srgba data to srgba texture.") ; 203 ERRORF(reporter, "Could not write srgba data to srgba texture.") ;
196 } 204 }
197 205
198 // Now verify that we can write linear data 206 // Now verify that we can write linear data
199 if (tex->writePixels(0, 0, kW, kH, kRGBA_8888_GrPixelConfig, origDat a)) { 207 if (tex->writePixels(dc, 0, 0, kW, kH, kRGBA_8888_GrPixelConfig, ori gData)) {
200 // We allow more error on GPUs with lower precision shader varia bles. 208 // We allow more error on GPUs with lower precision shader varia bles.
201 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPix elConfig, 209 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPix elConfig,
202 check_linear_to_srgb_conversion, error, 210 check_linear_to_srgb_conversion, error,
203 "write rgba/read srgba with srgba texture" ); 211 "write rgba/read srgba with srgba texture" );
204 read_and_check_pixels(reporter, tex, origData, kRGBA_8888_GrPixe lConfig, 212 read_and_check_pixels(reporter, tex, origData, kRGBA_8888_GrPixe lConfig,
205 check_linear_to_srgb_to_linear_conversion, error, 213 check_linear_to_srgb_to_linear_conversion, error,
206 "write/read rgba with srgba texture"); 214 "write/read rgba with srgba texture");
207 } else { 215 } else {
208 ERRORF(reporter, "Could not write rgba data to srgba texture."); 216 ERRORF(reporter, "Could not write rgba data to srgba texture.");
209 } 217 }
210 218
211 desc.fConfig = kRGBA_8888_GrPixelConfig; 219 desc.fConfig = kRGBA_8888_GrPixelConfig;
212 tex.reset(context->textureProvider()->createTexture(desc, false)); 220 tex.reset(context->textureProvider()->createTexture(desc, false));
213 if (!tex) { 221 if (!tex) {
214 ERRORF(reporter, "Could not create RGBA texture."); 222 ERRORF(reporter, "Could not create RGBA texture.");
215 continue; 223 continue;
216 } 224 }
225 dc.reset(context->drawContext(tex->asRenderTarget()));
226 if (!dc) {
227 ERRORF(reporter, "Could not create SRGBA texture.");
228 continue;
229 }
217 230
218 // Write srgba data to a rgba texture and read back as srgba and rgb a 231 // Write srgba data to a rgba texture and read back as srgba and rgb a
219 if (tex->writePixels(0, 0, kW, kH, kSRGBA_8888_GrPixelConfig, origDa ta)) { 232 if (tex->writePixels(dc, 0, 0, kW, kH, kSRGBA_8888_GrPixelConfig, or igData)) {
220 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPixe lConfig, 233 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPixe lConfig,
221 check_srgb_to_linear_to_srgb_conversion, e rror, 234 check_srgb_to_linear_to_srgb_conversion, e rror,
222 "write/read srgba to rgba texture"); 235 "write/read srgba to rgba texture");
223 read_and_check_pixels(reporter, tex, origData, kRGBA_8888_GrPixel Config, 236 read_and_check_pixels(reporter, tex, origData, kRGBA_8888_GrPixel Config,
224 check_srgb_to_linear_conversion, error, 237 check_srgb_to_linear_conversion, error,
225 "write srgba/read rgba to rgba texture"); 238 "write srgba/read rgba to rgba texture");
226 } else { 239 } else {
227 ERRORF(reporter, "Could not write srgba data to rgba texture."); 240 ERRORF(reporter, "Could not write srgba data to rgba texture.");
228 } 241 }
229 242
230 // Write rgba data to a rgba texture and read back as srgba 243 // Write rgba data to a rgba texture and read back as srgba
231 if (tex->writePixels(0, 0, kW, kH, kRGBA_8888_GrPixelConfig, origDat a)) { 244 if (tex->writePixels(dc, 0, 0, kW, kH, kRGBA_8888_GrPixelConfig, ori gData)) {
232 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPix elConfig, 245 read_and_check_pixels(reporter, tex, origData, kSRGBA_8888_GrPix elConfig,
233 check_linear_to_srgb_conversion, 1.2f, 246 check_linear_to_srgb_conversion, 1.2f,
234 "write rgba/read srgba to rgba texture"); 247 "write rgba/read srgba to rgba texture");
235 } else { 248 } else {
236 ERRORF(reporter, "Could not write rgba data to rgba texture."); 249 ERRORF(reporter, "Could not write rgba data to rgba texture.");
237 } 250 }
238 } 251 }
239 } 252 }
240 } 253 }
241 #endif 254 #endif
OLDNEW
« no previous file with comments | « tests/ResourceCacheTest.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698