blob: 9aa3dfec19c8b4b0d31c2dc6ca08419258102224 [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 Madillbc4c4bc2016-03-23 21:04:43 -040068 : 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 Madillbc4c4bc2016-03-23 21:04:43 -040080 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{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200169 GLint previousProgram = 0;
170 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
171 if (previousProgram != static_cast<GLint>(program))
172 {
173 glUseProgram(program);
174 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400175
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200176 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400177
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200178 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 Lang8a079e52013-10-18 16:13:33 -0400182
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200183 -1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ,
184 1.0f * positionAttribXYScale, -1.0f * positionAttribXYScale, positionAttribZ,
185 1.0f * positionAttribXYScale, 1.0f * positionAttribXYScale, positionAttribZ,
Geoff Lang8a079e52013-10-18 16:13:33 -0400186 };
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 Etuahoc3e55a42016-03-09 16:29:18 +0200196 if (previousProgram != static_cast<GLint>(program))
197 {
198 glUseProgram(previousProgram);
199 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400200}
201
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400202void ANGLETest::drawIndexedQuad(GLuint program,
203 const std::string &positionAttribName,
204 GLfloat positionAttribZ)
205{
206 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
207}
208
209void 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 Langefc551f2013-10-31 10:20:28 -0400254GLuint 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 Madilld2c52e32015-10-14 17:07:05 -0400270 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 Langefc551f2013-10-31 10:20:28 -0400278
Jamie Madilld2c52e32015-10-14 17:07:05 -0400279 std::cerr << "shader compilation failed: " << &infoLog[0];
280 }
Geoff Langefc551f2013-10-31 10:20:28 -0400281
282 glDeleteShader(shader);
283 shader = 0;
284 }
285
286 return shader;
287}
288
Austin Kinrossd544cc92016-01-11 15:26:42 -0800289void 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 Lang63046e22015-07-21 12:43:50 -0400362static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
363{
364 return strstr(allExtensions, extName.c_str()) != nullptr;
365}
366
Geoff Lang8a079e52013-10-18 16:13:33 -0400367bool ANGLETest::extensionEnabled(const std::string &extName)
368{
Geoff Lang63046e22015-07-21 12:43:50 -0400369 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
370 extName);
371}
372
373bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
374{
375 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
376}
377
378bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
379{
380 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400381}
382
Geoff Lang8a079e52013-10-18 16:13:33 -0400383void ANGLETest::setWindowWidth(int width)
384{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400385 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400386}
387
388void ANGLETest::setWindowHeight(int height)
389{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400390 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400391}
392
Geoff Langefc551f2013-10-31 10:20:28 -0400393void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400394{
Jamie Madill62af5462014-08-26 13:16:37 -0400395 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400396}
397
Geoff Langefc551f2013-10-31 10:20:28 -0400398void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400399{
Jamie Madill62af5462014-08-26 13:16:37 -0400400 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400401}
402
Geoff Langefc551f2013-10-31 10:20:28 -0400403void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400404{
Jamie Madill62af5462014-08-26 13:16:37 -0400405 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400406}
407
Geoff Langefc551f2013-10-31 10:20:28 -0400408void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400409{
Jamie Madill62af5462014-08-26 13:16:37 -0400410 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400411}
412
Geoff Langefc551f2013-10-31 10:20:28 -0400413void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400414{
Jamie Madill62af5462014-08-26 13:16:37 -0400415 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400416}
417
Geoff Langefc551f2013-10-31 10:20:28 -0400418void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400419{
Jamie Madill62af5462014-08-26 13:16:37 -0400420 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400421}
422
423void ANGLETest::setMultisampleEnabled(bool enabled)
424{
Jamie Madill62af5462014-08-26 13:16:37 -0400425 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400426}
427
Geoff Lang70d0f492015-12-10 17:45:46 -0500428void ANGLETest::setDebugEnabled(bool enabled)
429{
430 mEGLWindow->setDebugEnabled(enabled);
431}
432
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500433void ANGLETest::setNoErrorEnabled(bool enabled)
434{
435 mEGLWindow->setNoErrorEnabled(enabled);
436}
437
Geoff Lang8a079e52013-10-18 16:13:33 -0400438int ANGLETest::getClientVersion() const
439{
Geoff Lang5ade8452015-09-02 11:00:30 -0400440 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400441}
442
Geoff Langb9266272015-01-29 13:25:14 +0000443EGLWindow *ANGLETest::getEGLWindow() const
444{
445 return mEGLWindow;
446}
447
Geoff Lang8a079e52013-10-18 16:13:33 -0400448int ANGLETest::getWindowWidth() const
449{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400450 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400451}
452
453int ANGLETest::getWindowHeight() const
454{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400455 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400456}
457
Geoff Langefc551f2013-10-31 10:20:28 -0400458bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400459{
Jamie Madill62af5462014-08-26 13:16:37 -0400460 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400461}
462
463bool ANGLETest::createEGLContext()
464{
Jamie Madill62af5462014-08-26 13:16:37 -0400465 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400466}
467
468bool ANGLETest::destroyEGLContext()
469{
Jamie Madill62af5462014-08-26 13:16:37 -0400470 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400471 return true;
472}
Geoff Langbb134672013-10-23 13:06:46 -0400473
Geoff Lang0d3683c2014-10-23 11:08:16 -0400474bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400475{
476 mOSWindow = CreateOSWindow();
477 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
478 {
479 return false;
480 }
481
Geoff Lang0d3683c2014-10-23 11:08:16 -0400482 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400483
484 return true;
485}
486
Geoff Lang0d3683c2014-10-23 11:08:16 -0400487bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400488{
489 if (mOSWindow)
490 {
491 mOSWindow->destroy();
492 delete mOSWindow;
493 mOSWindow = NULL;
494 }
495
496 return true;
497}
498
Geoff Lang0d3683c2014-10-23 11:08:16 -0400499void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400500{
Jamie Madill4119ed32014-10-01 10:41:40 -0400501 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400502}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400503
Jamie Madill518b9fa2016-03-02 11:26:02 -0500504bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500505{
506 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
507 return (rendererString.find("Intel") != std::string::npos);
508}
509
Jamie Madill518b9fa2016-03-02 11:26:02 -0500510bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500511{
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 Madill518b9fa2016-03-02 11:26:02 -0500517bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500518{
519 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
520 return (rendererString.find("NVIDIA") != std::string::npos);
521}
522
Jamie Madill518b9fa2016-03-02 11:26:02 -0500523bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400524{
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 Madill518b9fa2016-03-02 11:26:02 -0500529bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500530{
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 Madill518b9fa2016-03-02 11:26:02 -0500535bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500536{
537 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
538 return (rendererString.find("Direct3D9") != std::string::npos);
539}
540
Jamie Madill518b9fa2016-03-02 11:26:02 -0500541bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500542{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500543 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500544}
545
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400546bool IsLinux()
547{
548#if defined(ANGLE_PLATFORM_LINUX)
549 return true;
550#else
551 return false;
552#endif
553}
554
Jamie Madill518b9fa2016-03-02 11:26:02 -0500555bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500556{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400557#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500558 return true;
559#else
560 return false;
561#endif
562}
563
Jamie Madill518b9fa2016-03-02 11:26:02 -0500564bool ANGLETest::isOpenGL() const
565{
566 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
567}
568
Jamie Madillc3b9b262015-01-30 14:00:51 -0500569EGLint ANGLETest::getPlatformRenderer() const
570{
Jamie Madillf6859912015-01-30 17:05:35 -0500571 assert(mEGLWindow);
572 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500573}
574
Austin Kinrossd544cc92016-01-11 15:26:42 -0800575void ANGLETest::ignoreD3D11SDKLayersWarnings()
576{
577 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
578 mIgnoreD3D11SDKLayersWarnings = true;
579}
580
Geoff Lang0d3683c2014-10-23 11:08:16 -0400581OSWindow *ANGLETest::mOSWindow = NULL;
582
583void ANGLETestEnvironment::SetUp()
584{
585 if (!ANGLETest::InitTestWindow())
586 {
587 FAIL() << "Failed to create ANGLE test window.";
588 }
589}
590
591void ANGLETestEnvironment::TearDown()
592{
593 ANGLETest::DestroyTestWindow();
594}