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 | fb57c04 | 2016-03-10 11:35:17 -0500 | [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 | fb57c04 | 2016-03-10 11:35:17 -0500 | [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 | { |
| 169 | GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str()); |
| 170 | |
| 171 | glUseProgram(program); |
| 172 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 173 | const GLfloat vertices[] = { |
| 174 | -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 175 | -1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 176 | 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
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 | -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 179 | 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 180 | 1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices); |
| 184 | glEnableVertexAttribArray(positionLocation); |
| 185 | |
| 186 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 187 | |
| 188 | glDisableVertexAttribArray(positionLocation); |
| 189 | glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 190 | |
| 191 | glUseProgram(0); |
| 192 | } |
| 193 | |
Jamie Madill | fb57c04 | 2016-03-10 11:35:17 -0500 | [diff] [blame^] | 194 | void ANGLETest::drawIndexedQuad(GLuint program, |
| 195 | const std::string &positionAttribName, |
| 196 | GLfloat positionAttribZ) |
| 197 | { |
| 198 | drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f); |
| 199 | } |
| 200 | |
| 201 | void ANGLETest::drawIndexedQuad(GLuint program, |
| 202 | const std::string &positionAttribName, |
| 203 | GLfloat positionAttribZ, |
| 204 | GLfloat positionAttribXYScale) |
| 205 | { |
| 206 | GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str()); |
| 207 | |
| 208 | glUseProgram(program); |
| 209 | |
| 210 | GLuint prevBinding = 0; |
| 211 | glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding)); |
| 212 | |
| 213 | if (mQuadVertexBuffer == 0) |
| 214 | { |
| 215 | glGenBuffers(1, &mQuadVertexBuffer); |
| 216 | const GLfloat vertices[] = { |
| 217 | -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 218 | -1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 219 | 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ, |
| 220 | 1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ, |
| 221 | }; |
| 222 | glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer); |
| 223 | glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 4, vertices, GL_STATIC_DRAW); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer); |
| 228 | } |
| 229 | |
| 230 | glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr); |
| 231 | glEnableVertexAttribArray(positionLocation); |
| 232 | glBindBuffer(GL_ARRAY_BUFFER, prevBinding); |
| 233 | |
| 234 | const GLushort indices[] = { |
| 235 | 0, 1, 2, 0, 2, 3, |
| 236 | }; |
| 237 | |
| 238 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); |
| 239 | |
| 240 | glDisableVertexAttribArray(positionLocation); |
| 241 | glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 242 | |
| 243 | glUseProgram(0); |
| 244 | } |
| 245 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 246 | GLuint ANGLETest::compileShader(GLenum type, const std::string &source) |
| 247 | { |
| 248 | GLuint shader = glCreateShader(type); |
| 249 | |
| 250 | const char *sourceArray[1] = { source.c_str() }; |
| 251 | glShaderSource(shader, 1, sourceArray, NULL); |
| 252 | glCompileShader(shader); |
| 253 | |
| 254 | GLint compileResult; |
| 255 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 256 | |
| 257 | if (compileResult == 0) |
| 258 | { |
| 259 | GLint infoLogLength; |
| 260 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 261 | |
Jamie Madill | d2c52e3 | 2015-10-14 17:07:05 -0400 | [diff] [blame] | 262 | if (infoLogLength == 0) |
| 263 | { |
| 264 | std::cerr << "shader compilation failed with empty log." << std::endl; |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | std::vector<GLchar> infoLog(infoLogLength); |
| 269 | glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 270 | |
Jamie Madill | d2c52e3 | 2015-10-14 17:07:05 -0400 | [diff] [blame] | 271 | std::cerr << "shader compilation failed: " << &infoLog[0]; |
| 272 | } |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 273 | |
| 274 | glDeleteShader(shader); |
| 275 | shader = 0; |
| 276 | } |
| 277 | |
| 278 | return shader; |
| 279 | } |
| 280 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 281 | void ANGLETest::checkD3D11SDKLayersMessages() |
| 282 | { |
| 283 | #if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG) |
| 284 | // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages |
| 285 | // were outputted by the test |
| 286 | if (mIgnoreD3D11SDKLayersWarnings || |
| 287 | mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE || |
| 288 | mEGLWindow->getDisplay() == EGL_NO_DISPLAY) |
| 289 | { |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | const char *extensionString = |
| 294 | static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS)); |
| 295 | if (!strstr(extensionString, "EGL_EXT_device_query")) |
| 296 | { |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | EGLAttrib device = 0; |
| 301 | EGLAttrib angleDevice = 0; |
| 302 | |
| 303 | PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT; |
| 304 | PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT; |
| 305 | |
| 306 | queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>( |
| 307 | eglGetProcAddress("eglQueryDisplayAttribEXT")); |
| 308 | queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>( |
| 309 | eglGetProcAddress("eglQueryDeviceAttribEXT")); |
| 310 | ASSERT_NE(nullptr, queryDisplayAttribEXT); |
| 311 | ASSERT_NE(nullptr, queryDeviceAttribEXT); |
| 312 | |
| 313 | ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice)); |
| 314 | ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice), |
| 315 | EGL_D3D11_DEVICE_ANGLE, &device)); |
| 316 | ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device); |
| 317 | |
| 318 | ID3D11InfoQueue *infoQueue = nullptr; |
| 319 | HRESULT hr = |
| 320 | d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue)); |
| 321 | if (SUCCEEDED(hr)) |
| 322 | { |
| 323 | UINT64 numStoredD3DDebugMessages = |
| 324 | infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter(); |
| 325 | |
| 326 | if (numStoredD3DDebugMessages > 0) |
| 327 | { |
| 328 | for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++) |
| 329 | { |
| 330 | SIZE_T messageLength = 0; |
| 331 | hr = infoQueue->GetMessage(i, nullptr, &messageLength); |
| 332 | |
| 333 | if (SUCCEEDED(hr)) |
| 334 | { |
| 335 | D3D11_MESSAGE *pMessage = |
| 336 | reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength)); |
| 337 | infoQueue->GetMessage(i, pMessage, &messageLength); |
| 338 | |
| 339 | std::cout << "Message " << i << ":" |
| 340 | << " " << pMessage->pDescription << "\n"; |
| 341 | free(pMessage); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | FAIL() << numStoredD3DDebugMessages |
| 346 | << " D3D11 SDK Layers message(s) detected! Test Failed.\n"; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | SafeRelease(infoQueue); |
| 351 | #endif |
| 352 | } |
| 353 | |
Geoff Lang | 63046e2 | 2015-07-21 12:43:50 -0400 | [diff] [blame] | 354 | static bool checkExtensionExists(const char *allExtensions, const std::string &extName) |
| 355 | { |
| 356 | return strstr(allExtensions, extName.c_str()) != nullptr; |
| 357 | } |
| 358 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 359 | bool ANGLETest::extensionEnabled(const std::string &extName) |
| 360 | { |
Geoff Lang | 63046e2 | 2015-07-21 12:43:50 -0400 | [diff] [blame] | 361 | return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)), |
| 362 | extName); |
| 363 | } |
| 364 | |
| 365 | bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName) |
| 366 | { |
| 367 | return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName); |
| 368 | } |
| 369 | |
| 370 | bool ANGLETest::eglClientExtensionEnabled(const std::string &extName) |
| 371 | { |
| 372 | return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 373 | } |
| 374 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 375 | void ANGLETest::setWindowWidth(int width) |
| 376 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 377 | mWidth = width; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void ANGLETest::setWindowHeight(int height) |
| 381 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 382 | mHeight = height; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 385 | void ANGLETest::setConfigRedBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 386 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 387 | mEGLWindow->setConfigRedBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 390 | void ANGLETest::setConfigGreenBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 391 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 392 | mEGLWindow->setConfigGreenBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 395 | void ANGLETest::setConfigBlueBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 396 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 397 | mEGLWindow->setConfigBlueBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 398 | } |
| 399 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 400 | void ANGLETest::setConfigAlphaBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 401 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 402 | mEGLWindow->setConfigAlphaBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 403 | } |
| 404 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 405 | void ANGLETest::setConfigDepthBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 406 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 407 | mEGLWindow->setConfigDepthBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 408 | } |
| 409 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 410 | void ANGLETest::setConfigStencilBits(int bits) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 411 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 412 | mEGLWindow->setConfigStencilBits(bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void ANGLETest::setMultisampleEnabled(bool enabled) |
| 416 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 417 | mEGLWindow->setMultisample(enabled); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 420 | void ANGLETest::setDebugEnabled(bool enabled) |
| 421 | { |
| 422 | mEGLWindow->setDebugEnabled(enabled); |
| 423 | } |
| 424 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 425 | void ANGLETest::setNoErrorEnabled(bool enabled) |
| 426 | { |
| 427 | mEGLWindow->setNoErrorEnabled(enabled); |
| 428 | } |
| 429 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 430 | int ANGLETest::getClientVersion() const |
| 431 | { |
Geoff Lang | 5ade845 | 2015-09-02 11:00:30 -0400 | [diff] [blame] | 432 | return mEGLWindow->getClientMajorVersion(); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Geoff Lang | b926627 | 2015-01-29 13:25:14 +0000 | [diff] [blame] | 435 | EGLWindow *ANGLETest::getEGLWindow() const |
| 436 | { |
| 437 | return mEGLWindow; |
| 438 | } |
| 439 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 440 | int ANGLETest::getWindowWidth() const |
| 441 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 442 | return mWidth; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | int ANGLETest::getWindowHeight() const |
| 446 | { |
Corentin Wallez | f3357ee | 2015-07-22 14:10:19 -0400 | [diff] [blame] | 447 | return mHeight; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 448 | } |
| 449 | |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 450 | bool ANGLETest::isMultisampleEnabled() const |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 451 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 452 | return mEGLWindow->isMultisample(); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | bool ANGLETest::createEGLContext() |
| 456 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 457 | return mEGLWindow->initializeGL(mOSWindow); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | bool ANGLETest::destroyEGLContext() |
| 461 | { |
Jamie Madill | 62af546 | 2014-08-26 13:16:37 -0400 | [diff] [blame] | 462 | mEGLWindow->destroyGL(); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 463 | return true; |
| 464 | } |
Geoff Lang | bb13467 | 2013-10-23 13:06:46 -0400 | [diff] [blame] | 465 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 466 | bool ANGLETest::InitTestWindow() |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 467 | { |
| 468 | mOSWindow = CreateOSWindow(); |
| 469 | if (!mOSWindow->initialize("ANGLE_TEST", 128, 128)) |
| 470 | { |
| 471 | return false; |
| 472 | } |
| 473 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 474 | mOSWindow->setVisible(true); |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 475 | |
| 476 | return true; |
| 477 | } |
| 478 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 479 | bool ANGLETest::DestroyTestWindow() |
Jamie Madill | 8add0eb | 2014-08-26 13:16:35 -0400 | [diff] [blame] | 480 | { |
| 481 | if (mOSWindow) |
| 482 | { |
| 483 | mOSWindow->destroy(); |
| 484 | delete mOSWindow; |
| 485 | mOSWindow = NULL; |
| 486 | } |
| 487 | |
| 488 | return true; |
| 489 | } |
| 490 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 491 | void ANGLETest::SetWindowVisible(bool isVisible) |
Geoff Lang | bb13467 | 2013-10-23 13:06:46 -0400 | [diff] [blame] | 492 | { |
Jamie Madill | 4119ed3 | 2014-10-01 10:41:40 -0400 | [diff] [blame] | 493 | mOSWindow->setVisible(isVisible); |
Geoff Lang | bb13467 | 2013-10-23 13:06:46 -0400 | [diff] [blame] | 494 | } |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 495 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 496 | bool IsIntel() |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 497 | { |
| 498 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 499 | return (rendererString.find("Intel") != std::string::npos); |
| 500 | } |
| 501 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 502 | bool IsAMD() |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 503 | { |
| 504 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 505 | return (rendererString.find("AMD") != std::string::npos) || |
| 506 | (rendererString.find("ATI") != std::string::npos); |
| 507 | } |
| 508 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 509 | bool IsNVIDIA() |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 510 | { |
| 511 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 512 | return (rendererString.find("NVIDIA") != std::string::npos); |
| 513 | } |
| 514 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 515 | bool IsD3D11() |
Jamie Madill | d55d283 | 2015-10-27 13:59:19 -0400 | [diff] [blame] | 516 | { |
| 517 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 518 | return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos); |
| 519 | } |
| 520 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 521 | bool IsD3D11_FL93() |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 522 | { |
| 523 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 524 | return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos); |
| 525 | } |
| 526 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 527 | bool IsD3D9() |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 528 | { |
| 529 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 530 | return (rendererString.find("Direct3D9") != std::string::npos); |
| 531 | } |
| 532 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 533 | bool IsD3DSM3() |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 534 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 535 | return IsD3D9() || IsD3D11_FL93(); |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 536 | } |
| 537 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 538 | bool IsOSX() |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 539 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 540 | #if defined(__APPLE__) |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 541 | return true; |
| 542 | #else |
| 543 | return false; |
| 544 | #endif |
| 545 | } |
| 546 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 547 | bool ANGLETest::isOpenGL() const |
| 548 | { |
| 549 | return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE; |
| 550 | } |
| 551 | |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 552 | EGLint ANGLETest::getPlatformRenderer() const |
| 553 | { |
Jamie Madill | f685991 | 2015-01-30 17:05:35 -0500 | [diff] [blame] | 554 | assert(mEGLWindow); |
| 555 | return mEGLWindow->getPlatform().renderer; |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 556 | } |
| 557 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 558 | void ANGLETest::ignoreD3D11SDKLayersWarnings() |
| 559 | { |
| 560 | // Some tests may need to disable the D3D11 SDK Layers Warnings checks |
| 561 | mIgnoreD3D11SDKLayersWarnings = true; |
| 562 | } |
| 563 | |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 564 | OSWindow *ANGLETest::mOSWindow = NULL; |
| 565 | |
| 566 | void ANGLETestEnvironment::SetUp() |
| 567 | { |
| 568 | if (!ANGLETest::InitTestWindow()) |
| 569 | { |
| 570 | FAIL() << "Failed to create ANGLE test window."; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | void ANGLETestEnvironment::TearDown() |
| 575 | { |
| 576 | ANGLETest::DestroyTestWindow(); |
| 577 | } |