blob: da2add716e2caf315b00691e1b7bd2c1846e4d00 [file] [log] [blame]
Dan Stoza3ed4e0b2013-12-11 15:21:11 -08001/*
2 * Copyright 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SRGB_test"
18//#define LOG_NDEBUG 0
19
20#include "GLTest.h"
21
Dan Albert0d1c7002014-11-07 09:33:44 -080022#include <math.h>
23
Dan Stoza3ed4e0b2013-12-11 15:21:11 -080024#include <gui/CpuConsumer.h>
25#include <gui/Surface.h>
26#include <gui/SurfaceComposerClient.h>
27
28#include <EGL/egl.h>
29#include <EGL/eglext.h>
30#include <GLES3/gl3.h>
31
32#include <android/native_window.h>
33
34#include <gtest/gtest.h>
35
36namespace android {
37
38class SRGBTest : public ::testing::Test {
39protected:
40 // Class constants
41 enum {
42 DISPLAY_WIDTH = 512,
43 DISPLAY_HEIGHT = 512,
Dan Stoza6a5d35d2014-01-07 15:25:02 -080044 PIXEL_SIZE = 4, // bytes or components
Dan Stoza3ed4e0b2013-12-11 15:21:11 -080045 DISPLAY_SIZE = DISPLAY_WIDTH * DISPLAY_HEIGHT * PIXEL_SIZE,
46 ALPHA_VALUE = 223, // should be in [0, 255]
47 TOLERANCE = 1,
48 };
49 static const char SHOW_DEBUG_STRING[];
50
51 SRGBTest() :
52 mInputSurface(), mCpuConsumer(), mLockedBuffer(),
53 mEglDisplay(EGL_NO_DISPLAY), mEglConfig(),
54 mEglContext(EGL_NO_CONTEXT), mEglSurface(EGL_NO_SURFACE),
55 mComposerClient(), mSurfaceControl(), mOutputSurface() {
56 }
57
58 virtual ~SRGBTest() {
59 if (mEglDisplay != EGL_NO_DISPLAY) {
60 if (mEglSurface != EGL_NO_SURFACE) {
61 eglDestroySurface(mEglDisplay, mEglSurface);
62 }
63 if (mEglContext != EGL_NO_CONTEXT) {
64 eglDestroyContext(mEglDisplay, mEglContext);
65 }
66 eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
67 EGL_NO_CONTEXT);
68 eglTerminate(mEglDisplay);
69 }
70 }
71
72 virtual void SetUp() {
Dan Stoza5603a2f2014-04-07 13:41:37 -070073 sp<IGraphicBufferProducer> producer;
74 sp<IGraphicBufferConsumer> consumer;
75 BufferQueue::createBufferQueue(&producer, &consumer);
76 ASSERT_EQ(NO_ERROR, consumer->setDefaultBufferSize(
Dan Stoza3ed4e0b2013-12-11 15:21:11 -080077 DISPLAY_WIDTH, DISPLAY_HEIGHT));
Dan Stoza5603a2f2014-04-07 13:41:37 -070078 mCpuConsumer = new CpuConsumer(consumer, 1);
Dan Stoza3ed4e0b2013-12-11 15:21:11 -080079 String8 name("CpuConsumer_for_SRGBTest");
80 mCpuConsumer->setName(name);
Dan Stoza5603a2f2014-04-07 13:41:37 -070081 mInputSurface = new Surface(producer);
Dan Stoza3ed4e0b2013-12-11 15:21:11 -080082
83 ASSERT_NO_FATAL_FAILURE(createEGLSurface(mInputSurface.get()));
84 ASSERT_NO_FATAL_FAILURE(createDebugSurface());
85 }
86
87 virtual void TearDown() {
88 ASSERT_NO_FATAL_FAILURE(copyToDebugSurface());
Dan Stozab8072d82014-01-29 14:33:57 -080089 ASSERT_TRUE(mLockedBuffer.data != NULL);
Dan Stoza6a5d35d2014-01-07 15:25:02 -080090 ASSERT_EQ(NO_ERROR, mCpuConsumer->unlockBuffer(mLockedBuffer));
Dan Stoza3ed4e0b2013-12-11 15:21:11 -080091 }
92
93 static float linearToSRGB(float l) {
94 if (l <= 0.0031308f) {
95 return l * 12.92f;
96 } else {
97 return 1.055f * pow(l, (1 / 2.4f)) - 0.055f;
98 }
99 }
100
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800101 static float srgbToLinear(float s) {
102 if (s <= 0.04045) {
103 return s / 12.92f;
104 } else {
105 return pow(((s + 0.055f) / 1.055f), 2.4f);
106 }
107 }
108
109 static uint8_t srgbToLinear(uint8_t u) {
110 float f = u / 255.0f;
111 return static_cast<uint8_t>(srgbToLinear(f) * 255.0f + 0.5f);
112 }
113
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800114 void fillTexture(bool writeAsSRGB) {
115 uint8_t* textureData = new uint8_t[DISPLAY_SIZE];
116
117 for (int y = 0; y < DISPLAY_HEIGHT; ++y) {
118 for (int x = 0; x < DISPLAY_WIDTH; ++x) {
119 float realValue = static_cast<float>(x) / (DISPLAY_WIDTH - 1);
120 realValue *= ALPHA_VALUE / 255.0f; // Premultiply by alpha
121 if (writeAsSRGB) {
122 realValue = linearToSRGB(realValue);
123 }
124
125 int offset = (y * DISPLAY_WIDTH + x) * PIXEL_SIZE;
126 for (int c = 0; c < 3; ++c) {
127 uint8_t intValue = static_cast<uint8_t>(
128 realValue * 255.0f + 0.5f);
129 textureData[offset + c] = intValue;
130 }
131 textureData[offset + 3] = ALPHA_VALUE;
132 }
133 }
134
135 glTexImage2D(GL_TEXTURE_2D, 0, writeAsSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA8,
136 DISPLAY_WIDTH, DISPLAY_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE,
137 textureData);
138 ASSERT_EQ(GL_NO_ERROR, glGetError());
139
140 delete[] textureData;
141 }
142
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800143 void initShaders() {
144 static const char vertexSource[] =
145 "attribute vec4 vPosition;\n"
146 "varying vec2 texCoords;\n"
147 "void main() {\n"
148 " texCoords = 0.5 * (vPosition.xy + vec2(1.0, 1.0));\n"
149 " gl_Position = vPosition;\n"
150 "}\n";
151
152 static const char fragmentSource[] =
153 "precision mediump float;\n"
154 "uniform sampler2D texSampler;\n"
155 "varying vec2 texCoords;\n"
156 "void main() {\n"
157 " gl_FragColor = texture2D(texSampler, texCoords);\n"
158 "}\n";
159
160 GLuint program;
161 {
162 SCOPED_TRACE("Creating shader program");
163 ASSERT_NO_FATAL_FAILURE(GLTest::createProgram(
164 vertexSource, fragmentSource, &program));
165 }
166
167 GLint positionHandle = glGetAttribLocation(program, "vPosition");
168 ASSERT_EQ(GL_NO_ERROR, glGetError());
169 ASSERT_NE(-1, positionHandle);
170
171 GLint samplerHandle = glGetUniformLocation(program, "texSampler");
172 ASSERT_EQ(GL_NO_ERROR, glGetError());
173 ASSERT_NE(-1, samplerHandle);
174
175 static const GLfloat vertices[] = {
176 -1.0f, 1.0f,
177 -1.0f, -1.0f,
178 1.0f, -1.0f,
179 1.0f, 1.0f,
180 };
181
182 glVertexAttribPointer(positionHandle, 2, GL_FLOAT, GL_FALSE, 0, vertices);
183 ASSERT_EQ(GL_NO_ERROR, glGetError());
184 glEnableVertexAttribArray(positionHandle);
185 ASSERT_EQ(GL_NO_ERROR, glGetError());
186
187 glUseProgram(program);
188 ASSERT_EQ(GL_NO_ERROR, glGetError());
189 glUniform1i(samplerHandle, 0);
190 ASSERT_EQ(GL_NO_ERROR, glGetError());
191
192 GLuint textureHandle;
193 glGenTextures(1, &textureHandle);
194 ASSERT_EQ(GL_NO_ERROR, glGetError());
195 glBindTexture(GL_TEXTURE_2D, textureHandle);
196 ASSERT_EQ(GL_NO_ERROR, glGetError());
197
198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
199 ASSERT_EQ(GL_NO_ERROR, glGetError());
200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
201 ASSERT_EQ(GL_NO_ERROR, glGetError());
202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
203 ASSERT_EQ(GL_NO_ERROR, glGetError());
204 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
205 ASSERT_EQ(GL_NO_ERROR, glGetError());
206 }
207
208 void drawTexture(bool asSRGB, GLint x, GLint y, GLsizei width,
209 GLsizei height) {
210 ASSERT_NO_FATAL_FAILURE(fillTexture(asSRGB));
211 glViewport(x, y, width, height);
212 ASSERT_EQ(GL_NO_ERROR, glGetError());
213 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
214 ASSERT_EQ(GL_NO_ERROR, glGetError());
215 }
216
217 void checkLockedBuffer(PixelFormat format) {
218 ASSERT_EQ(mLockedBuffer.format, format);
219 ASSERT_EQ(mLockedBuffer.width, DISPLAY_WIDTH);
220 ASSERT_EQ(mLockedBuffer.height, DISPLAY_HEIGHT);
221 }
222
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800223 static bool withinTolerance(int a, int b) {
224 int diff = a - b;
225 return diff >= 0 ? diff <= TOLERANCE : -diff <= TOLERANCE;
226 }
227
228 // Primary producer and consumer
229 sp<Surface> mInputSurface;
230 sp<CpuConsumer> mCpuConsumer;
231 CpuConsumer::LockedBuffer mLockedBuffer;
232
233 EGLDisplay mEglDisplay;
234 EGLConfig mEglConfig;
235 EGLContext mEglContext;
236 EGLSurface mEglSurface;
237
238 // Auxiliary display output
239 sp<SurfaceComposerClient> mComposerClient;
240 sp<SurfaceControl> mSurfaceControl;
241 sp<Surface> mOutputSurface;
242
243private:
244 void createEGLSurface(Surface* inputSurface) {
245 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
246 ASSERT_EQ(EGL_SUCCESS, eglGetError());
247 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
248
249 EXPECT_TRUE(eglInitialize(mEglDisplay, NULL, NULL));
250 ASSERT_EQ(EGL_SUCCESS, eglGetError());
251
252 static const EGLint configAttribs[] = {
253 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
254 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
255 EGL_RED_SIZE, 8,
256 EGL_GREEN_SIZE, 8,
257 EGL_BLUE_SIZE, 8,
258 EGL_ALPHA_SIZE, 8,
259 EGL_NONE };
260
261 EGLint numConfigs = 0;
262 EXPECT_TRUE(eglChooseConfig(mEglDisplay, configAttribs, &mEglConfig, 1,
263 &numConfigs));
264 ASSERT_EQ(EGL_SUCCESS, eglGetError());
Dan Stozab8072d82014-01-29 14:33:57 -0800265 ASSERT_GT(numConfigs, 0);
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800266
267 static const EGLint contextAttribs[] = {
268 EGL_CONTEXT_CLIENT_VERSION, 3,
269 EGL_NONE } ;
270
271 mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT,
272 contextAttribs);
273 ASSERT_EQ(EGL_SUCCESS, eglGetError());
274 ASSERT_NE(EGL_NO_CONTEXT, mEglContext);
275
276 mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig,
277 inputSurface, NULL);
278 ASSERT_EQ(EGL_SUCCESS, eglGetError());
279 ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
280
281 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
282 mEglContext));
283 ASSERT_EQ(EGL_SUCCESS, eglGetError());
284 }
285
286 void createDebugSurface() {
287 if (getenv(SHOW_DEBUG_STRING) == NULL) return;
288
289 mComposerClient = new SurfaceComposerClient;
290 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
291
292 mSurfaceControl = mComposerClient->createSurface(
293 String8("SRGBTest Surface"), DISPLAY_WIDTH, DISPLAY_HEIGHT,
294 PIXEL_FORMAT_RGBA_8888);
295
296 ASSERT_TRUE(mSurfaceControl != NULL);
297 ASSERT_TRUE(mSurfaceControl->isValid());
298
299 SurfaceComposerClient::openGlobalTransaction();
300 ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(0x7FFFFFFF));
301 ASSERT_EQ(NO_ERROR, mSurfaceControl->show());
302 SurfaceComposerClient::closeGlobalTransaction();
303
304 ANativeWindow_Buffer outBuffer;
305 ARect inOutDirtyBounds;
306 mOutputSurface = mSurfaceControl->getSurface();
307 mOutputSurface->lock(&outBuffer, &inOutDirtyBounds);
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800308 uint8_t* bytePointer = reinterpret_cast<uint8_t*>(outBuffer.bits);
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800309 for (int y = 0; y < outBuffer.height; ++y) {
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800310 int rowOffset = y * outBuffer.stride; // pixels
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800311 for (int x = 0; x < outBuffer.width; ++x) {
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800312 int colOffset = (rowOffset + x) * PIXEL_SIZE; // bytes
313 for (int c = 0; c < PIXEL_SIZE; ++c) {
314 int offset = colOffset + c;
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800315 bytePointer[offset] = ((c + 1) * 56) - 1;
316 }
317 }
318 }
319 mOutputSurface->unlockAndPost();
320 }
321
322 void copyToDebugSurface() {
323 if (!mOutputSurface.get()) return;
324
325 size_t bufferSize = mLockedBuffer.height * mLockedBuffer.stride *
326 PIXEL_SIZE;
327
328 ANativeWindow_Buffer outBuffer;
329 ARect outBufferBounds;
330 mOutputSurface->lock(&outBuffer, &outBufferBounds);
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800331 ASSERT_EQ(mLockedBuffer.width, outBuffer.width);
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800332 ASSERT_EQ(mLockedBuffer.height, outBuffer.height);
333 ASSERT_EQ(mLockedBuffer.stride, outBuffer.stride);
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800334
335 if (mLockedBuffer.format == outBuffer.format) {
336 memcpy(outBuffer.bits, mLockedBuffer.data, bufferSize);
337 } else {
338 ASSERT_EQ(mLockedBuffer.format, PIXEL_FORMAT_sRGB_A_8888);
339 ASSERT_EQ(outBuffer.format, PIXEL_FORMAT_RGBA_8888);
340 uint8_t* outPointer = reinterpret_cast<uint8_t*>(outBuffer.bits);
341 for (int y = 0; y < outBuffer.height; ++y) {
342 int rowOffset = y * outBuffer.stride; // pixels
343 for (int x = 0; x < outBuffer.width; ++x) {
344 int colOffset = (rowOffset + x) * PIXEL_SIZE; // bytes
345
346 // RGB are converted
347 for (int c = 0; c < (PIXEL_SIZE - 1); ++c) {
348 outPointer[colOffset + c] = srgbToLinear(
349 mLockedBuffer.data[colOffset + c]);
350 }
351
352 // Alpha isn't converted
353 outPointer[colOffset + 3] =
354 mLockedBuffer.data[colOffset + 3];
355 }
356 }
357 }
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800358 mOutputSurface->unlockAndPost();
359
360 int sleepSeconds = atoi(getenv(SHOW_DEBUG_STRING));
361 sleep(sleepSeconds);
362 }
363};
364
365const char SRGBTest::SHOW_DEBUG_STRING[] = "DEBUG_OUTPUT_SECONDS";
366
367TEST_F(SRGBTest, GLRenderFromSRGBTexture) {
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800368 ASSERT_NO_FATAL_FAILURE(initShaders());
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800369
370 // The RGB texture is displayed in the top half
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800371 ASSERT_NO_FATAL_FAILURE(drawTexture(false, 0, DISPLAY_HEIGHT / 2,
372 DISPLAY_WIDTH, DISPLAY_HEIGHT / 2));
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800373
374 // The SRGB texture is displayed in the bottom half
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800375 ASSERT_NO_FATAL_FAILURE(drawTexture(true, 0, 0,
376 DISPLAY_WIDTH, DISPLAY_HEIGHT / 2));
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800377
378 eglSwapBuffers(mEglDisplay, mEglSurface);
379 ASSERT_EQ(EGL_SUCCESS, eglGetError());
380
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800381 // Lock
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800382 ASSERT_EQ(NO_ERROR, mCpuConsumer->lockNextBuffer(&mLockedBuffer));
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800383 ASSERT_NO_FATAL_FAILURE(checkLockedBuffer(PIXEL_FORMAT_RGBA_8888));
384
385 // Compare a pixel in the middle of each texture
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800386 int midSRGBOffset = (DISPLAY_HEIGHT / 4) * mLockedBuffer.stride *
387 PIXEL_SIZE;
388 int midRGBOffset = midSRGBOffset * 3;
389 midRGBOffset += (DISPLAY_WIDTH / 2) * PIXEL_SIZE;
390 midSRGBOffset += (DISPLAY_WIDTH / 2) * PIXEL_SIZE;
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800391 for (int c = 0; c < PIXEL_SIZE; ++c) {
392 int expectedValue = mLockedBuffer.data[midRGBOffset + c];
393 int actualValue = mLockedBuffer.data[midSRGBOffset + c];
394 ASSERT_PRED2(withinTolerance, expectedValue, actualValue);
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800395 }
Dan Stoza6a5d35d2014-01-07 15:25:02 -0800396
397 // mLockedBuffer is unlocked in TearDown so we can copy data from it to
398 // the debug surface if necessary
399}
400
401TEST_F(SRGBTest, RenderToSRGBSurface) {
402 ASSERT_NO_FATAL_FAILURE(initShaders());
403
404 // By default, the first buffer we write into will be RGB
405
406 // Render an RGB texture across the whole surface
407 ASSERT_NO_FATAL_FAILURE(drawTexture(false, 0, 0,
408 DISPLAY_WIDTH, DISPLAY_HEIGHT));
409 eglSwapBuffers(mEglDisplay, mEglSurface);
410 ASSERT_EQ(EGL_SUCCESS, eglGetError());
411
412 // Lock
413 ASSERT_EQ(NO_ERROR, mCpuConsumer->lockNextBuffer(&mLockedBuffer));
414 ASSERT_NO_FATAL_FAILURE(checkLockedBuffer(PIXEL_FORMAT_RGBA_8888));
415
416 // Save the values of the middle pixel for later comparison against SRGB
417 uint8_t values[PIXEL_SIZE] = {};
418 int middleOffset = (DISPLAY_HEIGHT / 2) * mLockedBuffer.stride *
419 PIXEL_SIZE;
420 middleOffset += (DISPLAY_WIDTH / 2) * PIXEL_SIZE;
421 for (int c = 0; c < PIXEL_SIZE; ++c) {
422 values[c] = mLockedBuffer.data[middleOffset + c];
423 }
424
425 // Unlock
426 ASSERT_EQ(NO_ERROR, mCpuConsumer->unlockBuffer(mLockedBuffer));
427
428 // Switch to SRGB window surface
429#define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE
430#define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB
431
432 static const int srgbAttribs[] = {
433 EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR,
434 EGL_NONE,
435 };
436
437 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
438 mEglContext));
439 ASSERT_EQ(EGL_SUCCESS, eglGetError());
440
441 EXPECT_TRUE(eglDestroySurface(mEglDisplay, mEglSurface));
442 ASSERT_EQ(EGL_SUCCESS, eglGetError());
443
444 mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig,
445 mInputSurface.get(), srgbAttribs);
446 ASSERT_EQ(EGL_SUCCESS, eglGetError());
447 ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
448
449 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
450 mEglContext));
451 ASSERT_EQ(EGL_SUCCESS, eglGetError());
452
453 // Render the texture again
454 ASSERT_NO_FATAL_FAILURE(drawTexture(false, 0, 0,
455 DISPLAY_WIDTH, DISPLAY_HEIGHT));
456 eglSwapBuffers(mEglDisplay, mEglSurface);
457 ASSERT_EQ(EGL_SUCCESS, eglGetError());
458
459 // Lock
460 ASSERT_EQ(NO_ERROR, mCpuConsumer->lockNextBuffer(&mLockedBuffer));
461
462 // Make sure we actually got the SRGB buffer on the consumer side
463 ASSERT_NO_FATAL_FAILURE(checkLockedBuffer(PIXEL_FORMAT_sRGB_A_8888));
464
465 // Verify that the stored value is the same, accounting for RGB/SRGB
466 for (int c = 0; c < PIXEL_SIZE; ++c) {
467 // The alpha value should be equivalent before linear->SRGB
468 float rgbAsSRGB = (c == 3) ? values[c] / 255.0f :
469 linearToSRGB(values[c] / 255.0f);
470 int expectedValue = rgbAsSRGB * 255.0f + 0.5f;
471 int actualValue = mLockedBuffer.data[middleOffset + c];
472 ASSERT_PRED2(withinTolerance, expectedValue, actualValue);
473 }
474
Dan Stoza3ed4e0b2013-12-11 15:21:11 -0800475 // mLockedBuffer is unlocked in TearDown so we can copy data from it to
476 // the debug surface if necessary
477}
478
479} // namespace android