blob: 183c37bf30ad117631e3d44672faac10112f7a7d [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
Olli Etuahoa314b612016-03-10 16:43:00 +020018const GLColor GLColor::red = GLColor(255u, 0u, 0u, 255u);
19const GLColor GLColor::green = GLColor(0u, 255u, 0u, 255u);
20const GLColor GLColor::blue = GLColor(0u, 0u, 255u, 255u);
21const GLColor GLColor::cyan = GLColor(0u, 255u, 255u, 255u);
22const GLColor GLColor::black = GLColor(0u, 0u, 0u, 255u);
23
Jamie Madill1fbc59f2016-02-24 15:25:51 -050024namespace
25{
26float ColorNorm(GLubyte channelValue)
27{
28 return static_cast<float>(channelValue) / 255.0f;
29}
30} // anonymous namespace
31
Jamie Madill0dfa8072016-01-22 15:27:21 -050032GLColor::GLColor() : R(0), G(0), B(0), A(0)
33{
34}
35
36GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
37{
38}
39
Jamie Madille2509a32016-02-01 14:09:05 -050040GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
41{
42 memcpy(&R, &colorValue, sizeof(GLuint));
43}
44
Jamie Madill1fbc59f2016-02-24 15:25:51 -050045Vector4 GLColor::toNormalizedVector() const
46{
47 return Vector4(ColorNorm(R), ColorNorm(G), ColorNorm(B), ColorNorm(A));
48}
49
Jamie Madill0dfa8072016-01-22 15:27:21 -050050GLColor ReadColor(GLint x, GLint y)
51{
52 GLColor actual;
53 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
54 EXPECT_GL_NO_ERROR();
55 return actual;
56}
57
58bool operator==(const GLColor &a, const GLColor &b)
59{
60 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
61}
62
63std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
64{
65 ostream << "(" << static_cast<unsigned int>(color.R) << ", "
66 << static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
67 << ", " << static_cast<unsigned int>(color.A) << ")";
68 return ostream;
69}
70
71} // namespace angle
72
Jamie Madillfa05f602015-05-07 13:47:11 -040073ANGLETest::ANGLETest()
Jamie Madillbc4c4bc2016-03-23 21:04:43 -040074 : mEGLWindow(nullptr),
75 mWidth(16),
76 mHeight(16),
77 mIgnoreD3D11SDKLayersWarnings(false),
78 mQuadVertexBuffer(0)
Geoff Lang8a079e52013-10-18 16:13:33 -040079{
Geoff Lang5ade8452015-09-02 11:00:30 -040080 mEGLWindow =
81 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -040082}
83
84ANGLETest::~ANGLETest()
85{
Jamie Madillbc4c4bc2016-03-23 21:04:43 -040086 if (mQuadVertexBuffer)
87 {
88 glDeleteBuffers(1, &mQuadVertexBuffer);
89 }
Jamie Madill77a72f62015-04-14 11:18:32 -040090 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -040091}
92
Geoff Lang8a079e52013-10-18 16:13:33 -040093void ANGLETest::SetUp()
94{
Corentin Wallezb44440d2015-07-22 17:54:20 -040095 // Resize the window before creating the context so that the first make current
96 // sets the viewport and scissor box to the right size.
97 bool needSwap = false;
98 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +000099 {
Corentin Wallezb44440d2015-07-22 17:54:20 -0400100 if (!mOSWindow->resize(mWidth, mHeight))
101 {
102 FAIL() << "Failed to resize ANGLE test window.";
103 }
104 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +0000105 }
106
Geoff Lang8a079e52013-10-18 16:13:33 -0400107 if (!createEGLContext())
108 {
109 FAIL() << "egl context creation failed.";
110 }
Corentin Wallezb828b322015-07-16 17:51:30 -0400111
Corentin Wallezb44440d2015-07-22 17:54:20 -0400112 if (needSwap)
113 {
114 // Swap the buffers so that the default framebuffer picks up the resize
115 // which will allow follow-up test code to assume the framebuffer covers
116 // the whole window.
117 swapBuffers();
118 }
Corentin Wallez096725b2015-07-20 16:58:57 -0400119
Geoff Lang7f8dc492015-07-23 21:29:33 +0000120 // This Viewport command is not strictly necessary but we add it so that programs
121 // taking OpenGL traces can guess the size of the default framebuffer and show it
122 // in their UIs
123 glViewport(0, 0, mWidth, mHeight);
Jamie Madill508a5b72015-12-08 11:26:14 -0500124
125 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
126 angle::WriteDebugMessage("Entering %s.%s\n", info->test_case_name(), info->name());
Geoff Lang8a079e52013-10-18 16:13:33 -0400127}
128
129void ANGLETest::TearDown()
130{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800131 checkD3D11SDKLayersMessages();
132
Jamie Madill508a5b72015-12-08 11:26:14 -0500133 const auto &info = testing::UnitTest::GetInstance()->current_test_info();
134 angle::WriteDebugMessage("Exiting %s.%s\n", info->test_case_name(), info->name());
135
Geoff Lang8a079e52013-10-18 16:13:33 -0400136 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -0400137 mOSWindow->messageLoop();
138
Geoff Lang8a079e52013-10-18 16:13:33 -0400139 if (!destroyEGLContext())
140 {
141 FAIL() << "egl context destruction failed.";
142 }
Jamie Madill8add0eb2014-08-26 13:16:35 -0400143
144 // Check for quit message
145 Event myEvent;
146 while (mOSWindow->popEvent(&myEvent))
147 {
148 if (myEvent.Type == Event::EVENT_CLOSED)
149 {
150 exit(0);
151 }
152 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400153}
154
155void ANGLETest::swapBuffers()
156{
Jamie Madill77a72f62015-04-14 11:18:32 -0400157 if (mEGLWindow->isGLInitialized())
158 {
159 mEGLWindow->swap();
160 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400161}
162
Jamie Madill52b09c22016-04-11 14:12:31 -0400163// static
164std::array<Vector3, 6> ANGLETest::GetQuadVertices()
165{
166 std::array<Vector3, 6> vertices;
167 vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
168 vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
169 vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
170 vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
171 vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
172 vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
173 return vertices;
174}
175
176void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
177{
178 if (mQuadVertexBuffer == 0)
179 {
180 glGenBuffers(1, &mQuadVertexBuffer);
181 }
182
183 auto quadVertices = GetQuadVertices();
184 for (Vector3 &vertex : quadVertices)
185 {
186 vertex.x *= positionAttribXYScale;
187 vertex.y *= positionAttribXYScale;
188 vertex.z = positionAttribZ;
189 }
190
191 glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
192 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
193}
194
195// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200196void ANGLETest::drawQuad(GLuint program,
197 const std::string &positionAttribName,
198 GLfloat positionAttribZ)
199{
200 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
201}
202
Jamie Madill52b09c22016-04-11 14:12:31 -0400203// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200204void ANGLETest::drawQuad(GLuint program,
205 const std::string &positionAttribName,
206 GLfloat positionAttribZ,
207 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400208{
Jamie Madill52b09c22016-04-11 14:12:31 -0400209 drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
210}
211
212void ANGLETest::drawQuad(GLuint program,
213 const std::string &positionAttribName,
214 GLfloat positionAttribZ,
215 GLfloat positionAttribXYScale,
216 bool useVertexBuffer)
217{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200218 GLint previousProgram = 0;
219 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
220 if (previousProgram != static_cast<GLint>(program))
221 {
222 glUseProgram(program);
223 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400224
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200225 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400226
Jamie Madill52b09c22016-04-11 14:12:31 -0400227 if (useVertexBuffer)
228 {
229 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
230 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
231 glBindBuffer(GL_ARRAY_BUFFER, 0);
232 }
233 else
234 {
235 auto quadVertices = GetQuadVertices();
236 for (Vector3 &vertex : quadVertices)
237 {
238 vertex.x *= positionAttribXYScale;
239 vertex.y *= positionAttribXYScale;
240 vertex.z = positionAttribZ;
241 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400242
Jamie Madill52b09c22016-04-11 14:12:31 -0400243 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
244 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400245 glEnableVertexAttribArray(positionLocation);
246
247 glDrawArrays(GL_TRIANGLES, 0, 6);
248
249 glDisableVertexAttribArray(positionLocation);
250 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
251
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200252 if (previousProgram != static_cast<GLint>(program))
253 {
254 glUseProgram(previousProgram);
255 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400256}
257
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400258void ANGLETest::drawIndexedQuad(GLuint program,
259 const std::string &positionAttribName,
260 GLfloat positionAttribZ)
261{
262 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
263}
264
265void ANGLETest::drawIndexedQuad(GLuint program,
266 const std::string &positionAttribName,
267 GLfloat positionAttribZ,
268 GLfloat positionAttribXYScale)
269{
270 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
271
Jamie Madill52b09c22016-04-11 14:12:31 -0400272 GLint activeProgram = 0;
273 glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
274 if (static_cast<GLuint>(activeProgram) != program)
275 {
276 glUseProgram(program);
277 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400278
279 GLuint prevBinding = 0;
280 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
281
Jamie Madill52b09c22016-04-11 14:12:31 -0400282 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400283
284 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
285 glEnableVertexAttribArray(positionLocation);
286 glBindBuffer(GL_ARRAY_BUFFER, prevBinding);
287
288 const GLushort indices[] = {
289 0, 1, 2, 0, 2, 3,
290 };
291
292 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
293
294 glDisableVertexAttribArray(positionLocation);
295 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
296
Jamie Madill52b09c22016-04-11 14:12:31 -0400297 if (static_cast<GLuint>(activeProgram) != program)
298 {
299 glUseProgram(static_cast<GLuint>(activeProgram));
300 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400301}
302
Geoff Langefc551f2013-10-31 10:20:28 -0400303GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
304{
305 GLuint shader = glCreateShader(type);
306
307 const char *sourceArray[1] = { source.c_str() };
308 glShaderSource(shader, 1, sourceArray, NULL);
309 glCompileShader(shader);
310
311 GLint compileResult;
312 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
313
314 if (compileResult == 0)
315 {
316 GLint infoLogLength;
317 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
318
Jamie Madilld2c52e32015-10-14 17:07:05 -0400319 if (infoLogLength == 0)
320 {
321 std::cerr << "shader compilation failed with empty log." << std::endl;
322 }
323 else
324 {
325 std::vector<GLchar> infoLog(infoLogLength);
326 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400327
Jamie Madilld2c52e32015-10-14 17:07:05 -0400328 std::cerr << "shader compilation failed: " << &infoLog[0];
329 }
Geoff Langefc551f2013-10-31 10:20:28 -0400330
331 glDeleteShader(shader);
332 shader = 0;
333 }
334
335 return shader;
336}
337
Austin Kinrossd544cc92016-01-11 15:26:42 -0800338void ANGLETest::checkD3D11SDKLayersMessages()
339{
340#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG)
341 // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
342 // were outputted by the test
343 if (mIgnoreD3D11SDKLayersWarnings ||
344 mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
345 mEGLWindow->getDisplay() == EGL_NO_DISPLAY)
346 {
347 return;
348 }
349
350 const char *extensionString =
351 static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS));
352 if (!strstr(extensionString, "EGL_EXT_device_query"))
353 {
354 return;
355 }
356
357 EGLAttrib device = 0;
358 EGLAttrib angleDevice = 0;
359
360 PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
361 PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
362
363 queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
364 eglGetProcAddress("eglQueryDisplayAttribEXT"));
365 queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
366 eglGetProcAddress("eglQueryDeviceAttribEXT"));
367 ASSERT_NE(nullptr, queryDisplayAttribEXT);
368 ASSERT_NE(nullptr, queryDeviceAttribEXT);
369
370 ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
371 ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
372 EGL_D3D11_DEVICE_ANGLE, &device));
373 ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
374
375 ID3D11InfoQueue *infoQueue = nullptr;
376 HRESULT hr =
377 d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
378 if (SUCCEEDED(hr))
379 {
380 UINT64 numStoredD3DDebugMessages =
381 infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
382
383 if (numStoredD3DDebugMessages > 0)
384 {
385 for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
386 {
387 SIZE_T messageLength = 0;
388 hr = infoQueue->GetMessage(i, nullptr, &messageLength);
389
390 if (SUCCEEDED(hr))
391 {
392 D3D11_MESSAGE *pMessage =
393 reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
394 infoQueue->GetMessage(i, pMessage, &messageLength);
395
396 std::cout << "Message " << i << ":"
397 << " " << pMessage->pDescription << "\n";
398 free(pMessage);
399 }
400 }
401
402 FAIL() << numStoredD3DDebugMessages
403 << " D3D11 SDK Layers message(s) detected! Test Failed.\n";
404 }
405 }
406
407 SafeRelease(infoQueue);
408#endif
409}
410
Geoff Lang63046e22015-07-21 12:43:50 -0400411static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
412{
413 return strstr(allExtensions, extName.c_str()) != nullptr;
414}
415
Geoff Lang8a079e52013-10-18 16:13:33 -0400416bool ANGLETest::extensionEnabled(const std::string &extName)
417{
Geoff Lang63046e22015-07-21 12:43:50 -0400418 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
419 extName);
420}
421
422bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
423{
424 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
425}
426
427bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
428{
429 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400430}
431
Geoff Lang8a079e52013-10-18 16:13:33 -0400432void ANGLETest::setWindowWidth(int width)
433{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400434 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400435}
436
437void ANGLETest::setWindowHeight(int height)
438{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400439 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400440}
441
Geoff Langefc551f2013-10-31 10:20:28 -0400442void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400443{
Jamie Madill62af5462014-08-26 13:16:37 -0400444 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400445}
446
Geoff Langefc551f2013-10-31 10:20:28 -0400447void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400448{
Jamie Madill62af5462014-08-26 13:16:37 -0400449 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400450}
451
Geoff Langefc551f2013-10-31 10:20:28 -0400452void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400453{
Jamie Madill62af5462014-08-26 13:16:37 -0400454 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400455}
456
Geoff Langefc551f2013-10-31 10:20:28 -0400457void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400458{
Jamie Madill62af5462014-08-26 13:16:37 -0400459 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400460}
461
Geoff Langefc551f2013-10-31 10:20:28 -0400462void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400463{
Jamie Madill62af5462014-08-26 13:16:37 -0400464 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400465}
466
Geoff Langefc551f2013-10-31 10:20:28 -0400467void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400468{
Jamie Madill62af5462014-08-26 13:16:37 -0400469 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400470}
471
472void ANGLETest::setMultisampleEnabled(bool enabled)
473{
Jamie Madill62af5462014-08-26 13:16:37 -0400474 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400475}
476
Geoff Lang70d0f492015-12-10 17:45:46 -0500477void ANGLETest::setDebugEnabled(bool enabled)
478{
479 mEGLWindow->setDebugEnabled(enabled);
480}
481
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500482void ANGLETest::setNoErrorEnabled(bool enabled)
483{
484 mEGLWindow->setNoErrorEnabled(enabled);
485}
486
Geoff Lang8a079e52013-10-18 16:13:33 -0400487int ANGLETest::getClientVersion() const
488{
Geoff Lang5ade8452015-09-02 11:00:30 -0400489 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400490}
491
Geoff Langb9266272015-01-29 13:25:14 +0000492EGLWindow *ANGLETest::getEGLWindow() const
493{
494 return mEGLWindow;
495}
496
Geoff Lang8a079e52013-10-18 16:13:33 -0400497int ANGLETest::getWindowWidth() const
498{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400499 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400500}
501
502int ANGLETest::getWindowHeight() const
503{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400504 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400505}
506
Geoff Langefc551f2013-10-31 10:20:28 -0400507bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400508{
Jamie Madill62af5462014-08-26 13:16:37 -0400509 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400510}
511
512bool ANGLETest::createEGLContext()
513{
Jamie Madill62af5462014-08-26 13:16:37 -0400514 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400515}
516
517bool ANGLETest::destroyEGLContext()
518{
Jamie Madill62af5462014-08-26 13:16:37 -0400519 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400520 return true;
521}
Geoff Langbb134672013-10-23 13:06:46 -0400522
Geoff Lang0d3683c2014-10-23 11:08:16 -0400523bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400524{
525 mOSWindow = CreateOSWindow();
526 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
527 {
528 return false;
529 }
530
Geoff Lang0d3683c2014-10-23 11:08:16 -0400531 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400532
533 return true;
534}
535
Geoff Lang0d3683c2014-10-23 11:08:16 -0400536bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400537{
538 if (mOSWindow)
539 {
540 mOSWindow->destroy();
541 delete mOSWindow;
542 mOSWindow = NULL;
543 }
544
545 return true;
546}
547
Geoff Lang0d3683c2014-10-23 11:08:16 -0400548void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400549{
Jamie Madill4119ed32014-10-01 10:41:40 -0400550 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400551}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400552
Jamie Madill518b9fa2016-03-02 11:26:02 -0500553bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500554{
555 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
556 return (rendererString.find("Intel") != std::string::npos);
557}
558
Jamie Madill518b9fa2016-03-02 11:26:02 -0500559bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500560{
561 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
562 return (rendererString.find("AMD") != std::string::npos) ||
563 (rendererString.find("ATI") != std::string::npos);
564}
565
Jamie Madill518b9fa2016-03-02 11:26:02 -0500566bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500567{
568 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
569 return (rendererString.find("NVIDIA") != std::string::npos);
570}
571
Jamie Madill518b9fa2016-03-02 11:26:02 -0500572bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400573{
574 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
575 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
576}
577
Jamie Madill518b9fa2016-03-02 11:26:02 -0500578bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500579{
580 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
581 return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
582}
583
Jamie Madill518b9fa2016-03-02 11:26:02 -0500584bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500585{
586 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
587 return (rendererString.find("Direct3D9") != std::string::npos);
588}
589
Jamie Madill518b9fa2016-03-02 11:26:02 -0500590bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500591{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500592 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500593}
594
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400595bool IsLinux()
596{
597#if defined(ANGLE_PLATFORM_LINUX)
598 return true;
599#else
600 return false;
601#endif
602}
603
Jamie Madill518b9fa2016-03-02 11:26:02 -0500604bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500605{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400606#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500607 return true;
608#else
609 return false;
610#endif
611}
612
Jamie Madill518b9fa2016-03-02 11:26:02 -0500613bool ANGLETest::isOpenGL() const
614{
615 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
616}
617
Olli Etuaho87fc71c2016-05-11 14:25:21 +0300618bool ANGLETest::isGLES() const
619{
620 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
621}
622
Jamie Madillc3b9b262015-01-30 14:00:51 -0500623EGLint ANGLETest::getPlatformRenderer() const
624{
Jamie Madillf6859912015-01-30 17:05:35 -0500625 assert(mEGLWindow);
626 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500627}
628
Austin Kinrossd544cc92016-01-11 15:26:42 -0800629void ANGLETest::ignoreD3D11SDKLayersWarnings()
630{
631 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
632 mIgnoreD3D11SDKLayersWarnings = true;
633}
634
Geoff Lang0d3683c2014-10-23 11:08:16 -0400635OSWindow *ANGLETest::mOSWindow = NULL;
636
637void ANGLETestEnvironment::SetUp()
638{
639 if (!ANGLETest::InitTestWindow())
640 {
641 FAIL() << "Failed to create ANGLE test window.";
642 }
643}
644
645void ANGLETestEnvironment::TearDown()
646{
647 ANGLETest::DestroyTestWindow();
648}