blob: b308e11dad289fa54f75ee966ee3e39b81aa9274 [file] [log] [blame]
Jamie Madill508a5b72015-12-08 11:26:14 -05001//
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 Lang8a079e52013-10-18 16:13:33 -040010#include "ANGLETest.h"
Jamie Madill62af5462014-08-26 13:16:37 -040011#include "EGLWindow.h"
Jamie Madill8add0eb2014-08-26 13:16:35 -040012#include "OSWindow.h"
Jamie Madill508a5b72015-12-08 11:26:14 -050013#include "system_utils.h"
Jamie Madill8add0eb2014-08-26 13:16:35 -040014
Jamie Madill0dfa8072016-01-22 15:27:21 -050015namespace angle
16{
17
Jamie Madill1fbc59f2016-02-24 15:25:51 -050018namespace
19{
20float ColorNorm(GLubyte channelValue)
21{
22 return static_cast<float>(channelValue) / 255.0f;
23}
24} // anonymous namespace
25
Jamie Madill0dfa8072016-01-22 15:27:21 -050026GLColor::GLColor() : R(0), G(0), B(0), A(0)
27{
28}
29
30GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
31{
32}
33
Jamie Madille2509a32016-02-01 14:09:05 -050034GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
35{
36 memcpy(&R, &colorValue, sizeof(GLuint));
37}
38
Jamie Madill1fbc59f2016-02-24 15:25:51 -050039Vector4 GLColor::toNormalizedVector() const
40{
41 return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
42}
43
Jamie Madill0dfa8072016-01-22 15:27:21 -050044GLColor 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
52bool 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
57std::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 Madillfa05f602015-05-07 13:47:11 -040067ANGLETest::ANGLETest()
Jamie Madillfb57c042016-03-10 11:35:17 -050068 : mEGLWindow(nullptr),
69 mWidth(16),
70 mHeight(16),
71 mIgnoreD3D11SDKLayersWarnings(false),
72 mQuadVertexBuffer(0)
Geoff Lang8a079e52013-10-18 16:13:33 -040073{
Geoff Lang5ade8452015-09-02 11:00:30 -040074 mEGLWindow =
75 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -040076}
77
78ANGLETest::~ANGLETest()
79{
Jamie Madillfb57c042016-03-10 11:35:17 -050080 if (mQuadVertexBuffer)
81 {
82 glDeleteBuffers(1, &mQuadVertexBuffer);
83 }
Jamie Madill77a72f62015-04-14 11:18:32 -040084 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -040085}
86
Geoff Lang8a079e52013-10-18 16:13:33 -040087void ANGLETest::SetUp()
88{
Corentin Wallezb44440d2015-07-22 17:54:20 -040089 // 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 Lang7f8dc492015-07-23 21:29:33 +000093 {
Corentin Wallezb44440d2015-07-22 17:54:20 -040094 if (!mOSWindow->resize(mWidth, mHeight))
95 {
96 FAIL() << "Failed to resize ANGLE test window.";
97 }
98 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +000099 }
100
Geoff Lang8a079e52013-10-18 16:13:33 -0400101 if (!createEGLContext())
102 {
103 FAIL() << "egl context creation failed.";
104 }
Corentin Wallezb828b322015-07-16 17:51:30 -0400105
Corentin Wallezb44440d2015-07-22 17:54:20 -0400106 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 Wallez096725b2015-07-20 16:58:57 -0400113
Geoff Lang7f8dc492015-07-23 21:29:33 +0000114 // 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 Madill508a5b72015-12-08 11:26:14 -0500118
119 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
120 angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name());
Geoff Lang8a079e52013-10-18 16:13:33 -0400121}
122
123void ANGLETest::TearDown()
124{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800125 checkD3D11SDKLayersMessages();
126
Jamie Madill508a5b72015-12-08 11:26:14 -0500127 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
128 angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
129
Geoff Lang8a079e52013-10-18 16:13:33 -0400130 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -0400131 mOSWindow->messageLoop();
132
Geoff Lang8a079e52013-10-18 16:13:33 -0400133 if (!destroyEGLContext())
134 {
135 FAIL() << "egl context destruction failed.";
136 }
Jamie Madill8add0eb2014-08-26 13:16:35 -0400137
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 Lang8a079e52013-10-18 16:13:33 -0400147}
148
149void ANGLETest::swapBuffers()
150{
Jamie Madill77a72f62015-04-14 11:18:32 -0400151 if (mEGLWindow->isGLInitialized())
152 {
153 mEGLWindow->swap();
154 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400155}
156
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200157void ANGLETest::drawQuad(GLuint program,
158 const std::string &positionAttribName,
159 GLfloat positionAttribZ)
160{
161 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
162}
163
164void ANGLETest::drawQuad(GLuint program,
165 const std::string &positionAttribName,
166 GLfloat positionAttribZ,
167 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400168{
169 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
170
171 glUseProgram(program);
172
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200173 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 Lang8a079e52013-10-18 16:13:33 -0400177
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200178 -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ,
179 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ,
180 1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ,
Geoff Lang8a079e52013-10-18 16:13:33 -0400181 };
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 Madillfb57c042016-03-10 11:35:17 -0500194void ANGLETest::drawIndexedQuad(GLuint program,
195 const std::string &positionAttribName,
196 GLfloat positionAttribZ)
197{
198 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
199}
200
201void 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 Langefc551f2013-10-31 10:20:28 -0400246GLuint 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 Madilld2c52e32015-10-14 17:07:05 -0400262 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 Langefc551f2013-10-31 10:20:28 -0400270
Jamie Madilld2c52e32015-10-14 17:07:05 -0400271 std::cerr << "shader compilation failed: " << &infoLog[0];
272 }
Geoff Langefc551f2013-10-31 10:20:28 -0400273
274 glDeleteShader(shader);
275 shader = 0;
276 }
277
278 return shader;
279}
280
Austin Kinrossd544cc92016-01-11 15:26:42 -0800281void 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 Lang63046e22015-07-21 12:43:50 -0400354static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
355{
356 return strstr(allExtensions, extName.c_str()) != nullptr;
357}
358
Geoff Lang8a079e52013-10-18 16:13:33 -0400359bool ANGLETest::extensionEnabled(const std::string &extName)
360{
Geoff Lang63046e22015-07-21 12:43:50 -0400361 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
362 extName);
363}
364
365bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
366{
367 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
368}
369
370bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
371{
372 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400373}
374
Geoff Lang8a079e52013-10-18 16:13:33 -0400375void ANGLETest::setWindowWidth(int width)
376{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400377 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400378}
379
380void ANGLETest::setWindowHeight(int height)
381{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400382 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400383}
384
Geoff Langefc551f2013-10-31 10:20:28 -0400385void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400386{
Jamie Madill62af5462014-08-26 13:16:37 -0400387 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400388}
389
Geoff Langefc551f2013-10-31 10:20:28 -0400390void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400391{
Jamie Madill62af5462014-08-26 13:16:37 -0400392 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400393}
394
Geoff Langefc551f2013-10-31 10:20:28 -0400395void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400396{
Jamie Madill62af5462014-08-26 13:16:37 -0400397 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400398}
399
Geoff Langefc551f2013-10-31 10:20:28 -0400400void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400401{
Jamie Madill62af5462014-08-26 13:16:37 -0400402 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400403}
404
Geoff Langefc551f2013-10-31 10:20:28 -0400405void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400406{
Jamie Madill62af5462014-08-26 13:16:37 -0400407 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400408}
409
Geoff Langefc551f2013-10-31 10:20:28 -0400410void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400411{
Jamie Madill62af5462014-08-26 13:16:37 -0400412 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400413}
414
415void ANGLETest::setMultisampleEnabled(bool enabled)
416{
Jamie Madill62af5462014-08-26 13:16:37 -0400417 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400418}
419
Geoff Lang70d0f492015-12-10 17:45:46 -0500420void ANGLETest::setDebugEnabled(bool enabled)
421{
422 mEGLWindow->setDebugEnabled(enabled);
423}
424
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500425void ANGLETest::setNoErrorEnabled(bool enabled)
426{
427 mEGLWindow->setNoErrorEnabled(enabled);
428}
429
Geoff Lang8a079e52013-10-18 16:13:33 -0400430int ANGLETest::getClientVersion() const
431{
Geoff Lang5ade8452015-09-02 11:00:30 -0400432 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400433}
434
Geoff Langb9266272015-01-29 13:25:14 +0000435EGLWindow *ANGLETest::getEGLWindow() const
436{
437 return mEGLWindow;
438}
439
Geoff Lang8a079e52013-10-18 16:13:33 -0400440int ANGLETest::getWindowWidth() const
441{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400442 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400443}
444
445int ANGLETest::getWindowHeight() const
446{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400447 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400448}
449
Geoff Langefc551f2013-10-31 10:20:28 -0400450bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400451{
Jamie Madill62af5462014-08-26 13:16:37 -0400452 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400453}
454
455bool ANGLETest::createEGLContext()
456{
Jamie Madill62af5462014-08-26 13:16:37 -0400457 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400458}
459
460bool ANGLETest::destroyEGLContext()
461{
Jamie Madill62af5462014-08-26 13:16:37 -0400462 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400463 return true;
464}
Geoff Langbb134672013-10-23 13:06:46 -0400465
Geoff Lang0d3683c2014-10-23 11:08:16 -0400466bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400467{
468 mOSWindow = CreateOSWindow();
469 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
470 {
471 return false;
472 }
473
Geoff Lang0d3683c2014-10-23 11:08:16 -0400474 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400475
476 return true;
477}
478
Geoff Lang0d3683c2014-10-23 11:08:16 -0400479bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400480{
481 if (mOSWindow)
482 {
483 mOSWindow->destroy();
484 delete mOSWindow;
485 mOSWindow = NULL;
486 }
487
488 return true;
489}
490
Geoff Lang0d3683c2014-10-23 11:08:16 -0400491void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400492{
Jamie Madill4119ed32014-10-01 10:41:40 -0400493 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400494}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400495
Jamie Madill518b9fa2016-03-02 11:26:02 -0500496bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500497{
498 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
499 return (rendererString.find("Intel") != std::string::npos);
500}
501
Jamie Madill518b9fa2016-03-02 11:26:02 -0500502bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500503{
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 Madill518b9fa2016-03-02 11:26:02 -0500509bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500510{
511 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
512 return (rendererString.find("NVIDIA") != std::string::npos);
513}
514
Jamie Madill518b9fa2016-03-02 11:26:02 -0500515bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400516{
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 Madill518b9fa2016-03-02 11:26:02 -0500521bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500522{
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 Madill518b9fa2016-03-02 11:26:02 -0500527bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500528{
529 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
530 return (rendererString.find("Direct3D9") != std::string::npos);
531}
532
Jamie Madill518b9fa2016-03-02 11:26:02 -0500533bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500534{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500535 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500536}
537
Jamie Madill518b9fa2016-03-02 11:26:02 -0500538bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500539{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500540#if defined(__APPLE__)
Ian Ewell292f0052016-02-04 10:37:32 -0500541 return true;
542#else
543 return false;
544#endif
545}
546
Jamie Madill518b9fa2016-03-02 11:26:02 -0500547bool ANGLETest::isOpenGL() const
548{
549 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
550}
551
Jamie Madillc3b9b262015-01-30 14:00:51 -0500552EGLint ANGLETest::getPlatformRenderer() const
553{
Jamie Madillf6859912015-01-30 17:05:35 -0500554 assert(mEGLWindow);
555 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500556}
557
Austin Kinrossd544cc92016-01-11 15:26:42 -0800558void ANGLETest::ignoreD3D11SDKLayersWarnings()
559{
560 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
561 mIgnoreD3D11SDKLayersWarnings = true;
562}
563
Geoff Lang0d3683c2014-10-23 11:08:16 -0400564OSWindow *ANGLETest::mOSWindow = NULL;
565
566void ANGLETestEnvironment::SetUp()
567{
568 if (!ANGLETest::InitTestWindow())
569 {
570 FAIL() << "Failed to create ANGLE test window.";
571 }
572}
573
574void ANGLETestEnvironment::TearDown()
575{
576 ANGLETest::DestroyTestWindow();
577}