Jamie Madill | 508a5b7 | 2015-12-08 11:26:14 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // ANGLETest: |
| 7 | // Implementation of common ANGLE testing fixture. |
| 8 | // |
| 9 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 10 | #include "ANGLETest.h" |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 11 | #include "EGLWindow.h" |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 12 | #include "OSWindow.h" |
Jamie Madill | 508a5b7 | 2015-12-08 11:26:14 -0500 | [diff] [blame] | 13 | #include "system_utils.h" |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 14 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 15 | namespace angle |
| 16 | { |
| 17 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 18 | namespace |
| 19 | { |
| 20 | float ColorNorm(GLubyte channelValue) |
| 21 | { |
| 22 | return static_cast<float>(channelValue) / 255.0f; |
| 23 | } |
| 24 | } // anonymous namespace |
| 25 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 26 | GLColor::GLColor() : R(0), G(0), B(0), A(0) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a) |
| 31 | { |
| 32 | } |
| 33 | |
Jamie Madill | e2509a3 | 2016-02-01 14:09:05 -0500 | [diff] [blame] | 34 | GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0) |
| 35 | { |
| 36 | memcpy(&R, &colorValue, sizeof(GLuint)); |
| 37 | } |
| 38 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 39 | Vector4 GLColor::toNormalizedVector() const |
| 40 | { |
| 41 | return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A)); |
| 42 | } |
| 43 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 44 | GLColor ReadColor(GLint x, GLint y) |
| 45 | { |
| 46 | GLColor actual; |
| 47 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R); |
| 48 | EXPECT_GL_NO_ERROR(); |
| 49 | return actual; |
| 50 | } |
| 51 | |
| 52 | bool operator==(const GLColor &a, const GLColor &b) |
| 53 | { |
| 54 | return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A; |
| 55 | } |
| 56 | |
| 57 | std::ostream &operator<<(std::ostream &ostream, const GLColor &color) |
| 58 | { |
| 59 | ostream << "(" << static_cast<unsigned int>(color.R) << ", " |
| 60 | << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B) |
| 61 | << ", " << static_cast<unsigned int>(color.A) << ")"; |
| 62 | return ostream; |
| 63 | } |
| 64 | |
| 65 | } // namespace angle |
| 66 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 67 | ANGLETest::ANGLETest() |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 68 | : mEGLWindow(nullptr), |
| 69 | mWidth(16), |
| 70 | mHeight(16), |
| 71 | mIgnoreD3D11SDKLayersWarnings(false), |
| 72 | mQuadVertexBuffer(0) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 73 | { |
Geoff Lang | 5ade845 | 2015-09-02 11:00:30 -0400 | [diff] [blame] | 74 | mEGLWindow = |
| 75 | new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters); |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | ANGLETest::~ANGLETest() |
| 79 | { |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 80 | if (mQuadVertexBuffer) |
| 81 | { |
| 82 | glDeleteBuffers(1, &mQuadVertexBuffer); |
| 83 | } |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 84 | SafeDelete(mEGLWindow); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 85 | } |
| 86 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 87 | void ANGLETest::SetUp() |
| 88 | { |
Corentin Wallez | b44440d | 2015-07-22 17:54:20 -0400 | [diff] [blame] | 89 | // Resize the window before creating the context so that the first make current |
| 90 | // sets the viewport and scissor box to the right size. |
| 91 | bool needSwap = false; |
| 92 | if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight) |
Geoff Lang | 7f8dc49 | 2015-07-23 21:29:33 +0000 | [diff] [blame] | 93 | { |
Corentin Wallez | b44440d | 2015-07-22 17:54:20 -0400 | [diff] [blame] | 94 | if (!mOSWindow->resize(mWidth, mHeight)) |
| 95 | { |
| 96 | FAIL() << "Failed to resize ANGLE test window."; |
| 97 | } |
| 98 | needSwap = true; |
Geoff Lang | 7f8dc49 | 2015-07-23 21:29:33 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 101 | if (!createEGLContext()) |
| 102 | { |
| 103 | FAIL() << "egl context creation failed."; |
| 104 | } |
Corentin Wallez | b828b32 | 2015-07-16 17:51:30 -0400 | [diff] [blame] | 105 | |
Corentin Wallez | b44440d | 2015-07-22 17:54:20 -0400 | [diff] [blame] | 106 | if (needSwap) |
| 107 | { |
| 108 | // Swap the buffers so that the default framebuffer picks up the resize |
| 109 | // which will allow follow-up test code to assume the framebuffer covers |
| 110 | // the whole window. |
| 111 | swapBuffers(); |
| 112 | } |
Corentin Wallez | 096725b | 2015-07-20 16:58:57 -0400 | [diff] [blame] | 113 | |
Geoff Lang | 7f8dc49 | 2015-07-23 21:29:33 +0000 | [diff] [blame] | 114 | // This Viewport command is not strictly necessary but we add it so that programs |
| 115 | // taking OpenGL traces can guess the size of the default framebuffer and show it |
| 116 | // in their UIs |
| 117 | glViewport(0, 0, mWidth, mHeight); |
Jamie Madill | 508a5b7 | 2015-12-08 11:26:14 -0500 | [diff] [blame] | 118 | |
| 119 | const auto &info = testing::UnitTest::GetInstance()->current_test_info(); |
| 120 | angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name()); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void ANGLETest::TearDown() |
| 124 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 125 | checkD3D11SDKLayersMessages(); |
| 126 | |
Jamie Madill | 508a5b7 | 2015-12-08 11:26:14 -0500 | [diff] [blame] | 127 | const auto &info = testing::UnitTest::GetInstance()->current_test_info(); |
| 128 | angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name()); |
| 129 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 130 | swapBuffers(); |
Jamie Madill | 9e16d40 | 2014-09-08 17:36:33 -0400 | [diff] [blame] | 131 | mOSWindow->messageLoop(); |
| 132 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 133 | if (!destroyEGLContext()) |
| 134 | { |
| 135 | FAIL() << "egl context destruction failed."; |
| 136 | } |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 137 | |
| 138 | // Check for quit message |
| 139 | Event myEvent; |
| 140 | while (mOSWindow->popEvent(&myEvent)) |
| 141 | { |
| 142 | if (myEvent.Type == Event::EVENT_CLOSED) |
| 143 | { |
| 144 | exit(0); |
| 145 | } |
| 146 | } |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void ANGLETest::swapBuffers() |
| 150 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 151 | if (mEGLWindow->isGLInitialized()) |
| 152 | { |
| 153 | mEGLWindow->swap(); |
| 154 | } |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 157 | void ANGLETest::drawQuad(GLuint program, |
| 158 | const std::string &positionAttribName, |
| 159 | GLfloat positionAttribZ) |
| 160 | { |
| 161 | drawQuad(program, positionAttribName, positionAttribZ, 1.0f); |
| 162 | } |
| 163 | |
| 164 | void ANGLETest::drawQuad(GLuint program, |
| 165 | const std::string &positionAttribName, |
| 166 | GLfloat positionAttribZ, |
| 167 | GLfloat positionAttribXYScale) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 168 | { |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 169 | GLint previousProgram = 0; |
| 170 | glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram); |
| 171 | if (previousProgram != static_cast<GLint>(program)) |
| 172 | { |
| 173 | glUseProgram(program); |
| 174 | } |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 175 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 176 | GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str()); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 177 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 178 | const GLfloat vertices[] = { |
| 179 | -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 180 | -1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 181 | 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 182 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 183 | -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 184 | 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 185 | 1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices); |
| 189 | glEnableVertexAttribArray(positionLocation); |
| 190 | |
| 191 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 192 | |
| 193 | glDisableVertexAttribArray(positionLocation); |
| 194 | glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 195 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 196 | if (previousProgram != static_cast<GLint>(program)) |
| 197 | { |
| 198 | glUseProgram(previousProgram); |
| 199 | } |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 202 | void ANGLETest::drawIndexedQuad(GLuint program, |
| 203 | const std::string &positionAttribName, |
| 204 | GLfloat positionAttribZ) |
| 205 | { |
| 206 | drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f); |
| 207 | } |
| 208 | |
| 209 | void ANGLETest::drawIndexedQuad(GLuint program, |
| 210 | const std::string &positionAttribName, |
| 211 | GLfloat positionAttribZ, |
| 212 | GLfloat positionAttribXYScale) |
| 213 | { |
| 214 | GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str()); |
| 215 | |
| 216 | glUseProgram(program); |
| 217 | |
| 218 | GLuint prevBinding = 0; |
| 219 | glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding)); |
| 220 | |
| 221 | if (mQuadVertexBuffer == 0) |
| 222 | { |
| 223 | glGenBuffers(1, &mQuadVertexBuffer); |
| 224 | const GLfloat vertices[] = { |
| 225 | -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 226 | -1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 227 | 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 228 | 1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 229 | }; |
| 230 | glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer); |
| 231 | glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 4, vertices, GL_STATIC_DRAW); |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer); |
| 236 | } |
| 237 | |
| 238 | glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr); |
| 239 | glEnableVertexAttribArray(positionLocation); |
| 240 | glBindBuffer(GL_ARRAY_BUFFER, prevBinding); |
| 241 | |
| 242 | const GLushort indices[] = { |
| 243 | 0, 1, 2, 0, 2, 3, |
| 244 | }; |
| 245 | |
| 246 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); |
| 247 | |
| 248 | glDisableVertexAttribArray(positionLocation); |
| 249 | glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 250 | |
| 251 | glUseProgram(0); |
| 252 | } |
| 253 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 254 | GLuint ANGLETest::compileShader(GLenum type, const std::string &source) |
| 255 | { |
| 256 | GLuint shader = glCreateShader(type); |
| 257 | |
| 258 | const char *sourceArray[1] = { source.c_str() }; |
| 259 | glShaderSource(shader, 1, sourceArray, NULL); |
| 260 | glCompileShader(shader); |
| 261 | |
| 262 | GLint compileResult; |
| 263 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 264 | |
| 265 | if (compileResult == 0) |
| 266 | { |
| 267 | GLint infoLogLength; |
| 268 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 269 | |
Jamie Madill | d2c52e3 | 2015-10-14 17:07:05 -0400 | [diff] [blame] | 270 | if (infoLogLength == 0) |
| 271 | { |
| 272 | std::cerr << "shader compilation failed with empty log." << std::endl; |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | std::vector<GLchar> infoLog(infoLogLength); |
| 277 | glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 278 | |
Jamie Madill | d2c52e3 | 2015-10-14 17:07:05 -0400 | [diff] [blame] | 279 | std::cerr << "shader compilation failed: " << &infoLog[0]; |
| 280 | } |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 281 | |
| 282 | glDeleteShader(shader); |
| 283 | shader = 0; |
| 284 | } |
| 285 | |
| 286 | return shader; |
| 287 | } |
| 288 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 289 | void ANGLETest::checkD3D11SDKLayersMessages() |
| 290 | { |
| 291 | #if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG) |
| 292 | // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages |
| 293 | // were outputted by the test |
| 294 | if (mIgnoreD3D11SDKLayersWarnings || |
| 295 | mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE || |
| 296 | mEGLWindow->getDisplay() == EGL_NO_DISPLAY) |
| 297 | { |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | const char *extensionString = |
| 302 | static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS)); |
| 303 | if (!strstr(extensionString, "EGL_EXT_device_query")) |
| 304 | { |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | EGLAttrib device = 0; |
| 309 | EGLAttrib angleDevice = 0; |
| 310 | |
| 311 | PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT; |
| 312 | PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT; |
| 313 | |
| 314 | queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>( |
| 315 | eglGetProcAddress("eglQueryDisplayAttribEXT")); |
| 316 | queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>( |
| 317 | eglGetProcAddress("eglQueryDeviceAttribEXT")); |
| 318 | ASSERT_NE(nullptr, queryDisplayAttribEXT); |
| 319 | ASSERT_NE(nullptr, queryDeviceAttribEXT); |
| 320 | |
| 321 | ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice)); |
| 322 | ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice), |
| 323 | EGL_D3D11_DEVICE_ANGLE, &device)); |
| 324 | ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device); |
| 325 | |
| 326 | ID3D11InfoQueue *infoQueue = nullptr; |
| 327 | HRESULT hr = |
| 328 | d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue)); |
| 329 | if (SUCCEEDED(hr)) |
| 330 | { |
| 331 | UINT64 numStoredD3DDebugMessages = |
| 332 | infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter(); |
| 333 | |
| 334 | if (numStoredD3DDebugMessages > 0) |
| 335 | { |
| 336 | for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++) |
| 337 | { |
| 338 | SIZE_T messageLength = 0; |
| 339 | hr = infoQueue->GetMessage(i, nullptr, &messageLength); |
| 340 | |
| 341 | if (SUCCEEDED(hr)) |
| 342 | { |
| 343 | D3D11_MESSAGE *pMessage = |
| 344 | reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength)); |
| 345 | infoQueue->GetMessage(i, pMessage, &messageLength); |
| 346 | |
| 347 | std::cout << "Message " << i << ":" |
| 348 | << " " << pMessage->pDescription << "\n"; |
| 349 | free(pMessage); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | FAIL() << numStoredD3DDebugMessages |
| 354 | << " D3D11 SDK Layers message(s) detected! Test Failed.\n"; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | SafeRelease(infoQueue); |
| 359 | #endif |
| 360 | } |
| 361 | |
Geoff Lang | 63046e2 | 2015-07-21 12:43:50 -0400 | [diff] [blame] | 362 | static bool checkExtensionExists(const char *allExtensions, const std::string &extName) |
| 363 | { |
| 364 | return strstr(allExtensions, extName.c_str()) != nullptr; |
| 365 | } |
| 366 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 367 | bool ANGLETest::extensionEnabled(const std::string &extName) |
| 368 | { |
Geoff Lang | 63046e2 | 2015-07-21 12:43:50 -0400 | [diff] [blame] | 369 | return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)), |
| 370 | extName); |
| 371 | } |
| 372 | |
| 373 | bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName) |
| 374 | { |
| 375 | return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName); |
| 376 | } |
| 377 | |
| 378 | bool ANGLETest::eglClientExtensionEnabled(const std::string &extName) |
| 379 | { |
| 380 | return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 381 | } |
| 382 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 383 | void ANGLETest::setWindowWidth(int width) |
| 384 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 385 | mWidth = width; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | void ANGLETest::setWindowHeight(int height) |
| 389 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 390 | mHeight = height; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 391 | } |
| 392 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 393 | void ANGLETest::setConfigRedBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 394 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 395 | mEGLWindow->setConfigRedBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 398 | void ANGLETest::setConfigGreenBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 399 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 400 | mEGLWindow->setConfigGreenBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 403 | void ANGLETest::setConfigBlueBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 404 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 405 | mEGLWindow->setConfigBlueBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 406 | } |
| 407 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 408 | void ANGLETest::setConfigAlphaBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 409 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 410 | mEGLWindow->setConfigAlphaBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 411 | } |
| 412 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 413 | void ANGLETest::setConfigDepthBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 414 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 415 | mEGLWindow->setConfigDepthBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 418 | void ANGLETest::setConfigStencilBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 419 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 420 | mEGLWindow->setConfigStencilBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void ANGLETest::setMultisampleEnabled(bool enabled) |
| 424 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 425 | mEGLWindow->setMultisample(enabled); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 426 | } |
| 427 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 428 | void ANGLETest::setDebugEnabled(bool enabled) |
| 429 | { |
| 430 | mEGLWindow->setDebugEnabled(enabled); |
| 431 | } |
| 432 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 433 | void ANGLETest::setNoErrorEnabled(bool enabled) |
| 434 | { |
| 435 | mEGLWindow->setNoErrorEnabled(enabled); |
| 436 | } |
| 437 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 438 | int ANGLETest::getClientVersion() const |
| 439 | { |
Geoff Lang | 5ade845 | 2015-09-02 11:00:30 -0400 | [diff] [blame] | 440 | return mEGLWindow->getClientMajorVersion(); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 441 | } |
| 442 | |
Geoff Lang | b926627 | 2015-01-29 13:25:14 +0000 | [diff] [blame] | 443 | EGLWindow *ANGLETest::getEGLWindow() const |
| 444 | { |
| 445 | return mEGLWindow; |
| 446 | } |
| 447 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 448 | int ANGLETest::getWindowWidth() const |
| 449 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 450 | return mWidth; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | int ANGLETest::getWindowHeight() const |
| 454 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 455 | return mHeight; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 458 | bool ANGLETest::isMultisampleEnabled() const |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 459 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 460 | return mEGLWindow->isMultisample(); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | bool ANGLETest::createEGLContext() |
| 464 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 465 | return mEGLWindow->initializeGL(mOSWindow); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | bool ANGLETest::destroyEGLContext() |
| 469 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 470 | mEGLWindow->destroyGL(); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 471 | return true; |
| 472 | } |
Geoff Lang | bb13467 | 2013-10-23 13:06:46 -0400 | [diff] [blame] | 473 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 474 | bool ANGLETest::InitTestWindow() |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 475 | { |
| 476 | mOSWindow = CreateOSWindow(); |
| 477 | if (!mOSWindow->initialize("ANGLE_TEST", 128, 128)) |
| 478 | { |
| 479 | return false; |
| 480 | } |
| 481 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 482 | mOSWindow->setVisible(true); |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 483 | |
| 484 | return true; |
| 485 | } |
| 486 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 487 | bool ANGLETest::DestroyTestWindow() |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 488 | { |
| 489 | if (mOSWindow) |
| 490 | { |
| 491 | mOSWindow->destroy(); |
| 492 | delete mOSWindow; |
| 493 | mOSWindow = NULL; |
| 494 | } |
| 495 | |
| 496 | return true; |
| 497 | } |
| 498 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 499 | void ANGLETest::SetWindowVisible(bool isVisible) |
Geoff Lang | bb13467 | 2013-10-23 13:06:46 -0400 | [diff] [blame] | 500 | { |
Jamie Madill | 4119ed3 | 2014-10-01 10:41:40 -0400 | [diff] [blame] | 501 | mOSWindow->setVisible(isVisible); |
Geoff Lang | bb13467 | 2013-10-23 13:06:46 -0400 | [diff] [blame] | 502 | } |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 503 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 504 | bool IsIntel() |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 505 | { |
| 506 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 507 | return (rendererString.find("Intel") != std::string::npos); |
| 508 | } |
| 509 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 510 | bool IsAMD() |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 511 | { |
| 512 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 513 | return (rendererString.find("AMD") != std::string::npos) || |
| 514 | (rendererString.find("ATI") != std::string::npos); |
| 515 | } |
| 516 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 517 | bool IsNVIDIA() |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 518 | { |
| 519 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 520 | return (rendererString.find("NVIDIA") != std::string::npos); |
| 521 | } |
| 522 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 523 | bool IsD3D11() |
Jamie Madill | d55d283 | 2015-10-27 13:59:19 -0400 | [diff] [blame] | 524 | { |
| 525 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 526 | return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos); |
| 527 | } |
| 528 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 529 | bool IsD3D11_FL93() |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 530 | { |
| 531 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 532 | return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos); |
| 533 | } |
| 534 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 535 | bool IsD3D9() |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 536 | { |
| 537 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 538 | return (rendererString.find("Direct3D9") != std::string::npos); |
| 539 | } |
| 540 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 541 | bool IsD3DSM3() |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 542 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 543 | return IsD3D9() || IsD3D11_FL93(); |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 544 | } |
| 545 | |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame^] | 546 | bool IsLinux() |
| 547 | { |
| 548 | #if defined(ANGLE_PLATFORM_LINUX) |
| 549 | return true; |
| 550 | #else |
| 551 | return false; |
| 552 | #endif |
| 553 | } |
| 554 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 555 | bool IsOSX() |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 556 | { |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame^] | 557 | #if defined(ANGLE_PLATFORM_APPLE) |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 558 | return true; |
| 559 | #else |
| 560 | return false; |
| 561 | #endif |
| 562 | } |
| 563 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 564 | bool ANGLETest::isOpenGL() const |
| 565 | { |
| 566 | return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE; |
| 567 | } |
| 568 | |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 569 | EGLint ANGLETest::getPlatformRenderer() const |
| 570 | { |
Jamie Madill | f685991 | 2015-01-30 17:05:35 -0500 | [diff] [blame] | 571 | assert(mEGLWindow); |
| 572 | return mEGLWindow->getPlatform().renderer; |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 573 | } |
| 574 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 575 | void ANGLETest::ignoreD3D11SDKLayersWarnings() |
| 576 | { |
| 577 | // Some tests may need to disable the D3D11 SDK Layers Warnings checks |
| 578 | mIgnoreD3D11SDKLayersWarnings = true; |
| 579 | } |
| 580 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 581 | OSWindow *ANGLETest::mOSWindow = NULL; |
| 582 | |
| 583 | void ANGLETestEnvironment::SetUp() |
| 584 | { |
| 585 | if (!ANGLETest::InitTestWindow()) |
| 586 | { |
| 587 | FAIL() << "Failed to create ANGLE test window."; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | void ANGLETestEnvironment::TearDown() |
| 592 | { |
| 593 | ANGLETest::DestroyTestWindow(); |
| 594 | } |