blob: 15135a57488058ebbf6bad9a4d4b77c4275890a2 [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
Jamie Madill52b09c22016-04-11 14:12:31 -0400157// static
158std::array<Vector3, 6> ANGLETest::GetQuadVertices()
159{
160 std::array<Vector3, 6> vertices;
161 vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
162 vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
163 vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
164 vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
165 vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
166 vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
167 return vertices;
168}
169
170void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
171{
172 if (mQuadVertexBuffer == 0)
173 {
174 glGenBuffers(1, &mQuadVertexBuffer);
175 }
176
177 auto quadVertices = GetQuadVertices();
178 for (Vector3 &vertex : quadVertices)
179 {
180 vertex.x *= positionAttribXYScale;
181 vertex.y *= positionAttribXYScale;
182 vertex.z = positionAttribZ;
183 }
184
185 glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
186 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
187}
188
189// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200190void ANGLETest::drawQuad(GLuint program,
191 const std::string &positionAttribName,
192 GLfloat positionAttribZ)
193{
194 drawQuad(program, positionAttribName, positionAttribZ, 1.0f);
195}
196
Jamie Madill52b09c22016-04-11 14:12:31 -0400197// static
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200198void ANGLETest::drawQuad(GLuint program,
199 const std::string &positionAttribName,
200 GLfloat positionAttribZ,
201 GLfloat positionAttribXYScale)
Geoff Lang8a079e52013-10-18 16:13:33 -0400202{
Jamie Madill52b09c22016-04-11 14:12:31 -0400203 drawQuad(program, positionAttribName, positionAttribZ, positionAttribXYScale, false);
204}
205
206void ANGLETest::drawQuad(GLuint program,
207 const std::string &positionAttribName,
208 GLfloat positionAttribZ,
209 GLfloat positionAttribXYScale,
210 bool useVertexBuffer)
211{
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200212 GLint previousProgram = 0;
213 glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgram);
214 if (previousProgram != static_cast<GLint>(program))
215 {
216 glUseProgram(program);
217 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400218
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200219 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
Geoff Lang8a079e52013-10-18 16:13:33 -0400220
Jamie Madill52b09c22016-04-11 14:12:31 -0400221 if (useVertexBuffer)
222 {
223 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
224 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
225 glBindBuffer(GL_ARRAY_BUFFER, 0);
226 }
227 else
228 {
229 auto quadVertices = GetQuadVertices();
230 for (Vector3 &vertex : quadVertices)
231 {
232 vertex.x *= positionAttribXYScale;
233 vertex.y *= positionAttribXYScale;
234 vertex.z = positionAttribZ;
235 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400236
Jamie Madill52b09c22016-04-11 14:12:31 -0400237 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices.data());
238 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400239 glEnableVertexAttribArray(positionLocation);
240
241 glDrawArrays(GL_TRIANGLES, 0, 6);
242
243 glDisableVertexAttribArray(positionLocation);
244 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
245
Olli Etuahoc3e55a42016-03-09 16:29:18 +0200246 if (previousProgram != static_cast<GLint>(program))
247 {
248 glUseProgram(previousProgram);
249 }
Geoff Lang8a079e52013-10-18 16:13:33 -0400250}
251
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400252void ANGLETest::drawIndexedQuad(GLuint program,
253 const std::string &positionAttribName,
254 GLfloat positionAttribZ)
255{
256 drawIndexedQuad(program, positionAttribName, positionAttribZ, 1.0f);
257}
258
259void ANGLETest::drawIndexedQuad(GLuint program,
260 const std::string &positionAttribName,
261 GLfloat positionAttribZ,
262 GLfloat positionAttribXYScale)
263{
264 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
265
Jamie Madill52b09c22016-04-11 14:12:31 -0400266 GLint activeProgram = 0;
267 glGetIntegerv(GL_CURRENT_PROGRAM, &activeProgram);
268 if (static_cast<GLuint>(activeProgram) != program)
269 {
270 glUseProgram(program);
271 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400272
273 GLuint prevBinding = 0;
274 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
275
Jamie Madill52b09c22016-04-11 14:12:31 -0400276 setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400277
278 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
279 glEnableVertexAttribArray(positionLocation);
280 glBindBuffer(GL_ARRAY_BUFFER, prevBinding);
281
282 const GLushort indices[] = {
283 0, 1, 2, 0, 2, 3,
284 };
285
286 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
287
288 glDisableVertexAttribArray(positionLocation);
289 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
290
Jamie Madill52b09c22016-04-11 14:12:31 -0400291 if (static_cast<GLuint>(activeProgram) != program)
292 {
293 glUseProgram(static_cast<GLuint>(activeProgram));
294 }
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400295}
296
Geoff Langefc551f2013-10-31 10:20:28 -0400297GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
298{
299 GLuint shader = glCreateShader(type);
300
301 const char *sourceArray[1] = { source.c_str() };
302 glShaderSource(shader, 1, sourceArray, NULL);
303 glCompileShader(shader);
304
305 GLint compileResult;
306 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
307
308 if (compileResult == 0)
309 {
310 GLint infoLogLength;
311 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
312
Jamie Madilld2c52e32015-10-14 17:07:05 -0400313 if (infoLogLength == 0)
314 {
315 std::cerr << "shader compilation failed with empty log." << std::endl;
316 }
317 else
318 {
319 std::vector<GLchar> infoLog(infoLogLength);
320 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400321
Jamie Madilld2c52e32015-10-14 17:07:05 -0400322 std::cerr << "shader compilation failed: " << &infoLog[0];
323 }
Geoff Langefc551f2013-10-31 10:20:28 -0400324
325 glDeleteShader(shader);
326 shader = 0;
327 }
328
329 return shader;
330}
331
Austin Kinrossd544cc92016-01-11 15:26:42 -0800332void ANGLETest::checkD3D11SDKLayersMessages()
333{
334#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(NDEBUG)
335 // In debug D3D11 mode, check ID3D11InfoQueue to see if any D3D11 SDK Layers messages
336 // were outputted by the test
337 if (mIgnoreD3D11SDKLayersWarnings ||
338 mEGLWindow->getPlatform().renderer != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
339 mEGLWindow->getDisplay() == EGL_NO_DISPLAY)
340 {
341 return;
342 }
343
344 const char *extensionString =
345 static_cast<const char *>(eglQueryString(mEGLWindow->getDisplay(), EGL_EXTENSIONS));
346 if (!strstr(extensionString, "EGL_EXT_device_query"))
347 {
348 return;
349 }
350
351 EGLAttrib device = 0;
352 EGLAttrib angleDevice = 0;
353
354 PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
355 PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
356
357 queryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
358 eglGetProcAddress("eglQueryDisplayAttribEXT"));
359 queryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
360 eglGetProcAddress("eglQueryDeviceAttribEXT"));
361 ASSERT_NE(nullptr, queryDisplayAttribEXT);
362 ASSERT_NE(nullptr, queryDeviceAttribEXT);
363
364 ASSERT_EGL_TRUE(queryDisplayAttribEXT(mEGLWindow->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
365 ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
366 EGL_D3D11_DEVICE_ANGLE, &device));
367 ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
368
369 ID3D11InfoQueue *infoQueue = nullptr;
370 HRESULT hr =
371 d3d11Device->QueryInterface(__uuidof(infoQueue), reinterpret_cast<void **>(&infoQueue));
372 if (SUCCEEDED(hr))
373 {
374 UINT64 numStoredD3DDebugMessages =
375 infoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
376
377 if (numStoredD3DDebugMessages > 0)
378 {
379 for (UINT64 i = 0; i < numStoredD3DDebugMessages; i++)
380 {
381 SIZE_T messageLength = 0;
382 hr = infoQueue->GetMessage(i, nullptr, &messageLength);
383
384 if (SUCCEEDED(hr))
385 {
386 D3D11_MESSAGE *pMessage =
387 reinterpret_cast<D3D11_MESSAGE *>(malloc(messageLength));
388 infoQueue->GetMessage(i, pMessage, &messageLength);
389
390 std::cout << "Message " << i << ":"
391 << " " << pMessage->pDescription << "\n";
392 free(pMessage);
393 }
394 }
395
396 FAIL() << numStoredD3DDebugMessages
397 << " D3D11 SDK Layers message(s) detected! Test Failed.\n";
398 }
399 }
400
401 SafeRelease(infoQueue);
402#endif
403}
404
Geoff Lang63046e22015-07-21 12:43:50 -0400405static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
406{
407 return strstr(allExtensions, extName.c_str()) != nullptr;
408}
409
Geoff Lang8a079e52013-10-18 16:13:33 -0400410bool ANGLETest::extensionEnabled(const std::string &extName)
411{
Geoff Lang63046e22015-07-21 12:43:50 -0400412 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
413 extName);
414}
415
416bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
417{
418 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
419}
420
421bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
422{
423 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400424}
425
Geoff Lang8a079e52013-10-18 16:13:33 -0400426void ANGLETest::setWindowWidth(int width)
427{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400428 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400429}
430
431void ANGLETest::setWindowHeight(int height)
432{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400433 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400434}
435
Geoff Langefc551f2013-10-31 10:20:28 -0400436void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400437{
Jamie Madill62af5462014-08-26 13:16:37 -0400438 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400439}
440
Geoff Langefc551f2013-10-31 10:20:28 -0400441void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400442{
Jamie Madill62af5462014-08-26 13:16:37 -0400443 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400444}
445
Geoff Langefc551f2013-10-31 10:20:28 -0400446void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400447{
Jamie Madill62af5462014-08-26 13:16:37 -0400448 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400449}
450
Geoff Langefc551f2013-10-31 10:20:28 -0400451void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400452{
Jamie Madill62af5462014-08-26 13:16:37 -0400453 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400454}
455
Geoff Langefc551f2013-10-31 10:20:28 -0400456void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400457{
Jamie Madill62af5462014-08-26 13:16:37 -0400458 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400459}
460
Geoff Langefc551f2013-10-31 10:20:28 -0400461void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400462{
Jamie Madill62af5462014-08-26 13:16:37 -0400463 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400464}
465
466void ANGLETest::setMultisampleEnabled(bool enabled)
467{
Jamie Madill62af5462014-08-26 13:16:37 -0400468 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400469}
470
Geoff Lang70d0f492015-12-10 17:45:46 -0500471void ANGLETest::setDebugEnabled(bool enabled)
472{
473 mEGLWindow->setDebugEnabled(enabled);
474}
475
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500476void ANGLETest::setNoErrorEnabled(bool enabled)
477{
478 mEGLWindow->setNoErrorEnabled(enabled);
479}
480
Geoff Lang8a079e52013-10-18 16:13:33 -0400481int ANGLETest::getClientVersion() const
482{
Geoff Lang5ade8452015-09-02 11:00:30 -0400483 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400484}
485
Geoff Langb9266272015-01-29 13:25:14 +0000486EGLWindow *ANGLETest::getEGLWindow() const
487{
488 return mEGLWindow;
489}
490
Geoff Lang8a079e52013-10-18 16:13:33 -0400491int ANGLETest::getWindowWidth() const
492{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400493 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400494}
495
496int ANGLETest::getWindowHeight() const
497{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400498 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400499}
500
Geoff Langefc551f2013-10-31 10:20:28 -0400501bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400502{
Jamie Madill62af5462014-08-26 13:16:37 -0400503 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400504}
505
506bool ANGLETest::createEGLContext()
507{
Jamie Madill62af5462014-08-26 13:16:37 -0400508 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400509}
510
511bool ANGLETest::destroyEGLContext()
512{
Jamie Madill62af5462014-08-26 13:16:37 -0400513 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400514 return true;
515}
Geoff Langbb134672013-10-23 13:06:46 -0400516
Geoff Lang0d3683c2014-10-23 11:08:16 -0400517bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400518{
519 mOSWindow = CreateOSWindow();
520 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
521 {
522 return false;
523 }
524
Geoff Lang0d3683c2014-10-23 11:08:16 -0400525 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400526
527 return true;
528}
529
Geoff Lang0d3683c2014-10-23 11:08:16 -0400530bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400531{
532 if (mOSWindow)
533 {
534 mOSWindow->destroy();
535 delete mOSWindow;
536 mOSWindow = NULL;
537 }
538
539 return true;
540}
541
Geoff Lang0d3683c2014-10-23 11:08:16 -0400542void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400543{
Jamie Madill4119ed32014-10-01 10:41:40 -0400544 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400545}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400546
Jamie Madill518b9fa2016-03-02 11:26:02 -0500547bool IsIntel()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500548{
549 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
550 return (rendererString.find("Intel") != std::string::npos);
551}
552
Jamie Madill518b9fa2016-03-02 11:26:02 -0500553bool IsAMD()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500554{
555 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
556 return (rendererString.find("AMD") != std::string::npos) ||
557 (rendererString.find("ATI") != std::string::npos);
558}
559
Jamie Madill518b9fa2016-03-02 11:26:02 -0500560bool IsNVIDIA()
Jamie Madillc3b9b262015-01-30 14:00:51 -0500561{
562 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
563 return (rendererString.find("NVIDIA") != std::string::npos);
564}
565
Jamie Madill518b9fa2016-03-02 11:26:02 -0500566bool IsD3D11()
Jamie Madilld55d2832015-10-27 13:59:19 -0400567{
568 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
569 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
570}
571
Jamie Madill518b9fa2016-03-02 11:26:02 -0500572bool IsD3D11_FL93()
Jamie Madill9fc36822015-11-18 13:08:07 -0500573{
574 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
575 return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
576}
577
Jamie Madill518b9fa2016-03-02 11:26:02 -0500578bool IsD3D9()
Jamie Madill9fc36822015-11-18 13:08:07 -0500579{
580 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
581 return (rendererString.find("Direct3D9") != std::string::npos);
582}
583
Jamie Madill518b9fa2016-03-02 11:26:02 -0500584bool IsD3DSM3()
Jamie Madill9fc36822015-11-18 13:08:07 -0500585{
Jamie Madill518b9fa2016-03-02 11:26:02 -0500586 return IsD3D9() || IsD3D11_FL93();
Jamie Madill9fc36822015-11-18 13:08:07 -0500587}
588
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400589bool IsLinux()
590{
591#if defined(ANGLE_PLATFORM_LINUX)
592 return true;
593#else
594 return false;
595#endif
596}
597
Jamie Madill518b9fa2016-03-02 11:26:02 -0500598bool IsOSX()
Ian Ewell292f0052016-02-04 10:37:32 -0500599{
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400600#if defined(ANGLE_PLATFORM_APPLE)
Ian Ewell292f0052016-02-04 10:37:32 -0500601 return true;
602#else
603 return false;
604#endif
605}
606
Jamie Madill518b9fa2016-03-02 11:26:02 -0500607bool ANGLETest::isOpenGL() const
608{
609 return getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
610}
611
Jamie Madillc3b9b262015-01-30 14:00:51 -0500612EGLint ANGLETest::getPlatformRenderer() const
613{
Jamie Madillf6859912015-01-30 17:05:35 -0500614 assert(mEGLWindow);
615 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500616}
617
Austin Kinrossd544cc92016-01-11 15:26:42 -0800618void ANGLETest::ignoreD3D11SDKLayersWarnings()
619{
620 // Some tests may need to disable the D3D11 SDK Layers Warnings checks
621 mIgnoreD3D11SDKLayersWarnings = true;
622}
623
Geoff Lang0d3683c2014-10-23 11:08:16 -0400624OSWindow *ANGLETest::mOSWindow = NULL;
625
626void ANGLETestEnvironment::SetUp()
627{
628 if (!ANGLETest::InitTestWindow())
629 {
630 FAIL() << "Failed to create ANGLE test window.";
631 }
632}
633
634void ANGLETestEnvironment::TearDown()
635{
636 ANGLETest::DestroyTestWindow();
637}