1 /*------------------------------------------------------------------------- 2 * drawElements Quality Program EGL Module 3 * --------------------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 *//*! 20 * \file 21 * \brief Test for mapping client color values to native surface colors 22 *//*--------------------------------------------------------------------*/ 23 24 #include "teglNativeColorMappingTests.hpp" 25 26 #include "teglSimpleConfigCase.hpp" 27 28 #include "tcuTexture.hpp" 29 30 #include "egluNativeDisplay.hpp" 31 #include "egluNativeWindow.hpp" 32 #include "egluNativePixmap.hpp" 33 #include "egluUnique.hpp" 34 #include "egluUtil.hpp" 35 36 #include "eglwLibrary.hpp" 37 #include "eglwEnums.hpp" 38 39 #include "gluDefs.hpp" 40 #include "glwFunctions.hpp" 41 #include "glwEnums.hpp" 42 43 #include "tcuImageCompare.hpp" 44 #include "tcuTestLog.hpp" 45 #include "tcuTexture.hpp" 46 #include "tcuTextureUtil.hpp" 47 48 #include "deUniquePtr.hpp" 49 #include "deStringUtil.hpp" 50 51 #include "deThread.hpp" 52 53 #include <vector> 54 #include <string> 55 #include <limits> 56 57 using tcu::TestLog; 58 using std::vector; 59 using std::string; 60 61 using namespace eglw; 62 63 namespace deqp 64 { 65 namespace egl 66 { 67 namespace 68 { 69 70 EGLContext createGLES2Context (const Library& egl, EGLDisplay display, EGLConfig config) 71 { 72 EGLContext context = EGL_NO_CONTEXT; 73 const EGLint attribList[] = 74 { 75 EGL_CONTEXT_CLIENT_VERSION, 2, 76 EGL_NONE 77 }; 78 79 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API)); 80 81 context = egl.createContext(display, config, EGL_NO_CONTEXT, attribList); 82 EGLU_CHECK_MSG(egl, "eglCreateContext() failed"); 83 TCU_CHECK(context); 84 85 return context; 86 } 87 88 deUint32 createGLES2Program (const glw::Functions& gl, TestLog& log) 89 { 90 const char* const vertexShaderSource = 91 "attribute highp vec2 a_pos;\n" 92 "void main (void)\n" 93 "{\n" 94 "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n" 95 "}"; 96 97 const char* const fragmentShaderSource = 98 "uniform mediump vec4 u_color;\n" 99 "void main (void)\n" 100 "{\n" 101 "\tgl_FragColor = u_color;\n" 102 "}"; 103 104 deUint32 program = 0; 105 deUint32 vertexShader = 0; 106 deUint32 fragmentShader = 0; 107 108 deInt32 vertexCompileStatus; 109 string vertexInfoLog; 110 deInt32 fragmentCompileStatus; 111 string fragmentInfoLog; 112 deInt32 linkStatus; 113 string programInfoLog; 114 115 try 116 { 117 program = gl.createProgram(); 118 vertexShader = gl.createShader(GL_VERTEX_SHADER); 119 fragmentShader = gl.createShader(GL_FRAGMENT_SHADER); 120 121 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create shaders and program"); 122 123 gl.shaderSource(vertexShader, 1, &vertexShaderSource, DE_NULL); 124 gl.compileShader(vertexShader); 125 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup vertex shader"); 126 127 gl.shaderSource(fragmentShader, 1, &fragmentShaderSource, DE_NULL); 128 gl.compileShader(fragmentShader); 129 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup fragment shader"); 130 131 { 132 deInt32 infoLogLength = 0; 133 134 gl.getShaderiv(vertexShader, GL_COMPILE_STATUS, &vertexCompileStatus); 135 gl.getShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength); 136 137 vertexInfoLog.resize(infoLogLength, '\0'); 138 139 gl.getShaderInfoLog(vertexShader, (glw::GLsizei)vertexInfoLog.length(), &infoLogLength, &(vertexInfoLog[0])); 140 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get vertex shader compile info"); 141 142 vertexInfoLog.resize(infoLogLength); 143 } 144 145 { 146 deInt32 infoLogLength = 0; 147 148 gl.getShaderiv(fragmentShader, GL_COMPILE_STATUS, &fragmentCompileStatus); 149 gl.getShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength); 150 151 fragmentInfoLog.resize(infoLogLength, '\0'); 152 153 gl.getShaderInfoLog(fragmentShader, (glw::GLsizei)fragmentInfoLog.length(), &infoLogLength, &(fragmentInfoLog[0])); 154 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get fragment shader compile info"); 155 156 fragmentInfoLog.resize(infoLogLength); 157 } 158 159 gl.attachShader(program, vertexShader); 160 gl.attachShader(program, fragmentShader); 161 gl.linkProgram(program); 162 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup program"); 163 164 { 165 deInt32 infoLogLength = 0; 166 167 gl.getProgramiv(program, GL_LINK_STATUS, &linkStatus); 168 gl.getProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength); 169 170 programInfoLog.resize(infoLogLength, '\0'); 171 172 gl.getProgramInfoLog(program, (glw::GLsizei)programInfoLog.length(), &infoLogLength, &(programInfoLog[0])); 173 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get program link info"); 174 175 programInfoLog.resize(infoLogLength); 176 } 177 178 if (linkStatus == 0 || vertexCompileStatus == 0 || fragmentCompileStatus == 0) 179 { 180 181 log.startShaderProgram(linkStatus != 0, programInfoLog.c_str()); 182 183 log << TestLog::Shader(QP_SHADER_TYPE_VERTEX, vertexShaderSource, vertexCompileStatus != 0, vertexInfoLog); 184 log << TestLog::Shader(QP_SHADER_TYPE_FRAGMENT, fragmentShaderSource, fragmentCompileStatus != 0, fragmentInfoLog); 185 186 log.endShaderProgram(); 187 } 188 189 gl.deleteShader(vertexShader); 190 gl.deleteShader(fragmentShader); 191 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to delete shaders"); 192 193 TCU_CHECK(linkStatus != 0 && vertexCompileStatus != 0 && fragmentCompileStatus != 0); 194 } 195 catch (...) 196 { 197 if (program) 198 gl.deleteProgram(program); 199 200 if (vertexShader) 201 gl.deleteShader(vertexShader); 202 203 if (fragmentShader) 204 gl.deleteShader(fragmentShader); 205 206 throw; 207 } 208 209 return program; 210 } 211 212 void clear (const glw::Functions& gl, const tcu::Vec4& color) 213 { 214 gl.clearColor(color.x(), color.y(), color.z(), color.w()); 215 gl.clear(GL_COLOR_BUFFER_BIT); 216 GLU_EXPECT_NO_ERROR(gl.getError(), "Color clear failed"); 217 } 218 219 void render (const glw::Functions& gl, deUint32 program, const tcu::Vec4& color) 220 { 221 const float positions[] = 222 { 223 -1.0f, -1.0f, 224 1.0f, -1.0f, 225 1.0f, 1.0f, 226 227 1.0f, 1.0f, 228 -1.0f, 1.0f, 229 -1.0f, -1.0f 230 }; 231 232 deUint32 posLocation; 233 deUint32 colorLocation; 234 235 gl.useProgram(program); 236 posLocation = gl.getAttribLocation(program, "a_pos"); 237 gl.enableVertexAttribArray(posLocation); 238 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup shader program for rendering"); 239 240 colorLocation = gl.getUniformLocation(program, "u_color"); 241 gl.uniform4fv(colorLocation, 1, color.getPtr()); 242 243 gl.vertexAttribPointer(posLocation, 2, GL_FLOAT, GL_FALSE, 0, positions); 244 gl.drawArrays(GL_TRIANGLES, 0, 6); 245 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render"); 246 } 247 248 bool validate (TestLog& log, const Library& egl, EGLDisplay display, EGLConfig config, const tcu::TextureLevel& result, const tcu::Vec4& color) 249 { 250 const tcu::UVec4 eglBitDepth((deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_RED_SIZE), 251 (deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_GREEN_SIZE), 252 (deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_BLUE_SIZE), 253 (deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_ALPHA_SIZE)); 254 255 const tcu::UVec4 nativeBitDepth(tcu::getTextureFormatBitDepth(result.getFormat()).asUint()); 256 const tcu::UVec4 bitDepth(deMinu32(nativeBitDepth.x(), eglBitDepth.x()), 257 deMinu32(nativeBitDepth.y(), eglBitDepth.y()), 258 deMinu32(nativeBitDepth.z(), eglBitDepth.z()), 259 deMinu32(nativeBitDepth.w(), eglBitDepth.w())); 260 261 const tcu::UVec4 uColor = tcu::UVec4((deUint32)((float)((1u << bitDepth.x()) - 1u) * color.x()), 262 (deUint32)((float)((1u << bitDepth.y()) - 1u) * color.y()), 263 (deUint32)((float)((1u << bitDepth.z()) - 1u) * color.z()), 264 (deUint32)((float)((1u << bitDepth.w()) - 1u) * color.w())); 265 266 tcu::TextureLevel reference(result.getFormat(), result.getWidth(), result.getHeight()); 267 268 for (int y = 0; y < result.getHeight(); y++) 269 { 270 for (int x = 0; x < result.getWidth(); x++) 271 reference.getAccess().setPixel(uColor, x, y); 272 } 273 274 return tcu::intThresholdCompare(log, "Result compare", "Compare results", reference.getAccess(), result.getAccess(), tcu::UVec4(1u, 1u, 1u, (bitDepth.w() > 0 ? 1u : std::numeric_limits<deUint32>::max())), tcu::COMPARE_LOG_RESULT); 275 } 276 277 class NativeColorMappingCase : public SimpleConfigCase 278 { 279 public: 280 enum NativeType 281 { 282 NATIVETYPE_WINDOW = 0, 283 NATIVETYPE_PIXMAP, 284 NATIVETYPE_PBUFFER_COPY_TO_PIXMAP 285 }; 286 287 NativeColorMappingCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool render, NativeType nativeType, const eglu::FilterList& filters); 288 ~NativeColorMappingCase (void); 289 290 private: 291 void executeForConfig (EGLDisplay display, EGLConfig config); 292 293 NativeType m_nativeType; 294 bool m_render; 295 }; 296 297 NativeColorMappingCase::NativeColorMappingCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool render, NativeType nativeType, const eglu::FilterList& filters) 298 : SimpleConfigCase (eglTestCtx, name, description, filters) 299 , m_nativeType (nativeType) 300 , m_render (render) 301 { 302 } 303 304 NativeColorMappingCase::~NativeColorMappingCase (void) 305 { 306 deinit(); 307 } 308 309 void logConfigInfo (TestLog& log, const Library& egl, EGLDisplay display, EGLConfig config, NativeColorMappingCase::NativeType nativeType, int waitFrames) 310 { 311 log << TestLog::Message << "EGL_RED_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_RED_SIZE) << TestLog::EndMessage; 312 log << TestLog::Message << "EGL_GREEN_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_GREEN_SIZE) << TestLog::EndMessage; 313 log << TestLog::Message << "EGL_BLUE_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_BLUE_SIZE) << TestLog::EndMessage; 314 log << TestLog::Message << "EGL_ALPHA_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_ALPHA_SIZE) << TestLog::EndMessage; 315 log << TestLog::Message << "EGL_DEPTH_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_DEPTH_SIZE) << TestLog::EndMessage; 316 log << TestLog::Message << "EGL_STENCIL_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_STENCIL_SIZE) << TestLog::EndMessage; 317 log << TestLog::Message << "EGL_SAMPLES: " << eglu::getConfigAttribInt(egl, display, config, EGL_SAMPLES) << TestLog::EndMessage; 318 319 if (nativeType == NativeColorMappingCase::NATIVETYPE_WINDOW) 320 log << TestLog::Message << "Waiting " << waitFrames * 16 << "ms after eglSwapBuffers() and glFinish() for frame to become visible" << TestLog::EndMessage; 321 } 322 323 bool testNativeWindow (TestLog& log, eglu::NativeDisplay& nativeDisplay, eglu::NativeWindow& nativeWindow, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, int waitFrames, size_t colorCount, const tcu::Vec4* colors) 324 { 325 const Library& egl = nativeDisplay.getLibrary(); 326 eglu::UniqueSurface surface (egl, display, eglu::createWindowSurface(nativeDisplay, nativeWindow, display, config, DE_NULL)); 327 tcu::TextureLevel result; 328 deUint32 program = 0; 329 bool isOk = true; 330 331 try 332 { 333 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, context)); 334 335 if (renderColor) 336 program = createGLES2Program(gl, log); 337 338 for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++) 339 { 340 if (renderColor) 341 render(gl, program, colors[colorNdx]); 342 else 343 clear(gl, colors[colorNdx]); 344 345 EGLU_CHECK_CALL(egl, swapBuffers(display, *surface)); 346 EGLU_CHECK_CALL(egl, waitClient()); 347 deSleep(waitFrames*16); 348 nativeWindow.readScreenPixels(&result); 349 350 if (!validate(log, egl, display, config, result, colors[colorNdx])) 351 isOk = false; 352 } 353 354 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); 355 } 356 catch (...) 357 { 358 if (program) 359 gl.deleteProgram(program); 360 throw; 361 } 362 363 return isOk; 364 } 365 366 bool testNativePixmap (TestLog& log, eglu::NativeDisplay& nativeDisplay, eglu::NativePixmap& nativePixmap, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, size_t colorCount, const tcu::Vec4* colors) 367 { 368 const Library& egl = nativeDisplay.getLibrary(); 369 eglu::UniqueSurface surface (egl, display, eglu::createPixmapSurface(nativeDisplay, nativePixmap, display, config, DE_NULL)); 370 tcu::TextureLevel result; 371 deUint32 program = 0; 372 bool isOk = true; 373 374 try 375 { 376 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, context)); 377 378 if (renderColor) 379 program = createGLES2Program(gl, log); 380 381 for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++) 382 { 383 if (renderColor) 384 render(gl, program, colors[colorNdx]); 385 else 386 clear(gl, colors[colorNdx]); 387 388 EGLU_CHECK_CALL(egl, waitClient()); 389 nativePixmap.readPixels(&result); 390 391 if (!validate(log, egl, display, config, result, colors[colorNdx])) 392 isOk = false; 393 } 394 395 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); 396 } 397 catch (...) 398 { 399 if (program) 400 gl.deleteProgram(program); 401 throw; 402 } 403 404 return isOk; 405 } 406 407 bool testNativePixmapCopy (TestLog& log, const Library& egl, eglu::NativePixmap& nativePixmap, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, size_t colorCount, const tcu::Vec4* colors) 408 { 409 eglu::UniqueSurface surface (egl, display, egl.createPbufferSurface(display, config, DE_NULL)); 410 tcu::TextureLevel result; 411 deUint32 program = 0; 412 bool isOk = true; 413 414 try 415 { 416 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, context)); 417 418 if (renderColor) 419 program = createGLES2Program(gl, log); 420 421 for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++) 422 { 423 if (renderColor) 424 render(gl, program, colors[colorNdx]); 425 else 426 clear(gl, colors[colorNdx]); 427 428 EGLU_CHECK_CALL(egl, copyBuffers(display, *surface, nativePixmap.getLegacyNative())); 429 EGLU_CHECK_CALL(egl, waitClient()); 430 nativePixmap.readPixels(&result); 431 432 if (!validate(log, egl, display, config, result, colors[colorNdx])) 433 isOk = false; 434 } 435 436 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); 437 } 438 catch (...) 439 { 440 if (program) 441 gl.deleteProgram(program); 442 throw; 443 } 444 445 return isOk; 446 } 447 448 void NativeColorMappingCase::executeForConfig (EGLDisplay display, EGLConfig config) 449 { 450 const int width = 128; 451 const int height = 128; 452 453 const tcu::Vec4 colors[] = 454 { 455 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), 456 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), 457 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), 458 tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f), 459 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), 460 tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f), 461 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), 462 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), 463 464 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), 465 tcu::Vec4(0.0f, 0.0f, 0.5f, 1.0f), 466 tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f), 467 tcu::Vec4(0.0f, 0.5f, 0.5f, 1.0f), 468 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f), 469 tcu::Vec4(0.5f, 0.0f, 0.5f, 1.0f), 470 tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f), 471 tcu::Vec4(0.5f, 0.5f, 0.5f, 1.0f) 472 }; 473 474 const Library& egl = m_eglTestCtx.getLibrary(); 475 const string configIdStr (de::toString(eglu::getConfigAttribInt(egl, display, config, EGL_CONFIG_ID))); 476 tcu::ScopedLogSection logSection (m_testCtx.getLog(), ("Config ID " + configIdStr).c_str(), ("Config ID " + configIdStr).c_str()); 477 const int waitFrames = 5; 478 const eglu::NativeWindowFactory* windowFactory; 479 const eglu::NativePixmapFactory* pixmapFactory; 480 481 logConfigInfo(m_testCtx.getLog(), egl, display, config, m_nativeType, waitFrames); 482 483 try 484 { 485 windowFactory = &eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine()); 486 487 if ((windowFactory->getCapabilities() & eglu::NativeWindow::CAPABILITY_READ_SCREEN_PIXELS) == 0) 488 TCU_THROW(NotSupportedError, "Native window doesn't support readPixels()"); 489 } 490 catch (const tcu::NotSupportedError&) 491 { 492 if (m_nativeType == NATIVETYPE_WINDOW) 493 throw; 494 else 495 windowFactory = DE_NULL; 496 } 497 498 try 499 { 500 pixmapFactory = &eglu::selectNativePixmapFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine()); 501 502 if (m_nativeType == NATIVETYPE_PIXMAP) 503 { 504 if ((pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_READ_PIXELS) == 0) 505 TCU_THROW(NotSupportedError, "Native pixmap doesn't support readPixels()"); 506 } 507 else if (m_nativeType == NATIVETYPE_PBUFFER_COPY_TO_PIXMAP) 508 { 509 if ((pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_READ_PIXELS) == 0 || 510 (pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_CREATE_SURFACE_LEGACY) == 0) 511 TCU_THROW(NotSupportedError, "Native pixmap doesn't support readPixels() or legacy create surface"); 512 } 513 } 514 catch (const tcu::NotSupportedError&) 515 { 516 if (m_nativeType == NATIVETYPE_PIXMAP || m_nativeType == NATIVETYPE_PBUFFER_COPY_TO_PIXMAP) 517 throw; 518 else 519 pixmapFactory = DE_NULL; 520 } 521 522 DE_ASSERT(m_nativeType != NATIVETYPE_WINDOW || windowFactory); 523 DE_ASSERT((m_nativeType != NATIVETYPE_PIXMAP && m_nativeType != NATIVETYPE_PBUFFER_COPY_TO_PIXMAP) || pixmapFactory); 524 525 eglu::UniqueContext context (egl, display, createGLES2Context(egl, display, config)); 526 glw::Functions gl; 527 528 m_eglTestCtx.initGLFunctions(&gl, glu::ApiType::es(2,0)); 529 530 switch (m_nativeType) 531 { 532 case NATIVETYPE_WINDOW: 533 { 534 de::UniquePtr<eglu::NativeWindow> nativeWindow (windowFactory->createWindow(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, eglu::WindowParams(width, height, eglu::WindowParams::VISIBILITY_VISIBLE))); 535 536 if (!testNativeWindow(m_testCtx.getLog(), m_eglTestCtx.getNativeDisplay(), *nativeWindow, display, *context, config, gl, m_render, waitFrames, DE_LENGTH_OF_ARRAY(colors), colors)) 537 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered"); 538 break; 539 } 540 541 case NATIVETYPE_PIXMAP: 542 { 543 de::UniquePtr<eglu::NativePixmap> nativePixmap (pixmapFactory->createPixmap(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, width, height)); 544 545 if (!testNativePixmap(m_testCtx.getLog(), m_eglTestCtx.getNativeDisplay(), *nativePixmap, display, *context, config, gl, m_render, DE_LENGTH_OF_ARRAY(colors), colors)) 546 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered"); 547 break; 548 } 549 550 case NATIVETYPE_PBUFFER_COPY_TO_PIXMAP: 551 { 552 de::UniquePtr<eglu::NativePixmap> nativePixmap (pixmapFactory->createPixmap(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, width, height)); 553 554 if (!testNativePixmapCopy(m_testCtx.getLog(), egl, *nativePixmap, display, *context, config, gl, m_render, DE_LENGTH_OF_ARRAY(colors), colors)) 555 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered"); 556 break; 557 } 558 559 default: 560 DE_ASSERT(DE_FALSE); 561 } 562 } 563 564 template<deUint32 Type> 565 static bool surfaceType (const eglu::CandidateConfig& c) 566 { 567 return (c.surfaceType() & Type) == Type; 568 } 569 570 void addTestGroups (EglTestContext& eglTestCtx, TestCaseGroup* group, NativeColorMappingCase::NativeType type) 571 { 572 eglu::FilterList baseFilters; 573 574 switch (type) 575 { 576 case NativeColorMappingCase::NATIVETYPE_WINDOW: 577 baseFilters << surfaceType<EGL_WINDOW_BIT>; 578 break; 579 580 case NativeColorMappingCase::NATIVETYPE_PIXMAP: 581 baseFilters << surfaceType<EGL_PIXMAP_BIT>; 582 break; 583 584 case NativeColorMappingCase::NATIVETYPE_PBUFFER_COPY_TO_PIXMAP: 585 baseFilters << surfaceType<EGL_PBUFFER_BIT>; 586 break; 587 588 default: 589 DE_ASSERT(DE_FALSE); 590 } 591 592 vector<NamedFilterList> filterLists; 593 getDefaultFilterLists(filterLists, baseFilters); 594 595 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++) 596 { 597 group->addChild(new NativeColorMappingCase(eglTestCtx, (string(i->getName()) + "_clear").c_str(), i->getDescription(), false, type, *i)); 598 group->addChild(new NativeColorMappingCase(eglTestCtx, (string(i->getName()) + "_render").c_str(), i->getDescription(), true, type, *i)); 599 } 600 } 601 602 } // anonymous 603 604 NativeColorMappingTests::NativeColorMappingTests (EglTestContext& eglTestCtx) 605 : TestCaseGroup(eglTestCtx, "native_color_mapping", "Tests for mapping client colors to native surface") 606 { 607 } 608 609 void NativeColorMappingTests::init (void) 610 { 611 { 612 TestCaseGroup* windowGroup = new TestCaseGroup(m_eglTestCtx, "native_window", "Tests for mapping client color to native window"); 613 addTestGroups(m_eglTestCtx, windowGroup, NativeColorMappingCase::NATIVETYPE_WINDOW); 614 addChild(windowGroup); 615 } 616 617 { 618 TestCaseGroup* pixmapGroup = new TestCaseGroup(m_eglTestCtx, "native_pixmap", "Tests for mapping client color to native pixmap"); 619 addTestGroups(m_eglTestCtx, pixmapGroup, NativeColorMappingCase::NATIVETYPE_PIXMAP); 620 addChild(pixmapGroup); 621 } 622 623 { 624 TestCaseGroup* pbufferGroup = new TestCaseGroup(m_eglTestCtx, "pbuffer_to_native_pixmap", "Tests for mapping client color to native pixmap with eglCopyBuffers()"); 625 addTestGroups(m_eglTestCtx, pbufferGroup, NativeColorMappingCase::NATIVETYPE_PBUFFER_COPY_TO_PIXMAP); 626 addChild(pbufferGroup); 627 } 628 } 629 630 } // egl 631 } // deqp 632