1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 #include <gtest/gtest.h>
8
9 #include "test_utils/ANGLETest.h"
10
11 using namespace angle;
12
13 class EGLQueryContextTest : public ANGLETest
14 {
15 public:
testSetUp()16 void testSetUp() override
17 {
18 int clientVersion = GetParam().majorVersion;
19
20 EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};
21 mDisplay = eglGetPlatformDisplayEXT(
22 EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
23 EXPECT_TRUE(mDisplay != EGL_NO_DISPLAY);
24 EXPECT_TRUE(eglInitialize(mDisplay, nullptr, nullptr) != EGL_FALSE);
25
26 EGLint ncfg;
27 EGLint cfgattrs[] = {EGL_RED_SIZE,
28 8,
29 EGL_GREEN_SIZE,
30 8,
31 EGL_BLUE_SIZE,
32 8,
33 EGL_RENDERABLE_TYPE,
34 clientVersion == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT,
35 EGL_NONE};
36 EXPECT_TRUE(eglChooseConfig(mDisplay, cfgattrs, &mConfig, 1, &ncfg) != EGL_FALSE);
37 EXPECT_TRUE(ncfg == 1);
38
39 EGLint ctxattrs[] = {EGL_CONTEXT_CLIENT_VERSION, clientVersion, EGL_NONE};
40 mContext = eglCreateContext(mDisplay, mConfig, nullptr, ctxattrs);
41 EXPECT_TRUE(mContext != EGL_NO_CONTEXT);
42
43 EGLint surfaceType = EGL_NONE;
44 eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);
45 if (surfaceType & EGL_PBUFFER_BIT)
46 {
47 EGLint surfattrs[] = {EGL_WIDTH, 16, EGL_HEIGHT, 16, EGL_NONE};
48 mSurface = eglCreatePbufferSurface(mDisplay, mConfig, surfattrs);
49 EXPECT_TRUE(mSurface != EGL_NO_SURFACE);
50 }
51 }
52
testTearDown()53 void testTearDown() override
54 {
55 if (mDisplay != EGL_NO_DISPLAY)
56 {
57 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
58 eglDestroyContext(mDisplay, mContext);
59 if (mSurface)
60 {
61 eglDestroySurface(mDisplay, mSurface);
62 }
63 eglTerminate(mDisplay);
64 }
65 ASSERT_EGL_SUCCESS() << "Error during test TearDown";
66 }
67
68 EGLDisplay mDisplay = EGL_NO_DISPLAY;
69 EGLConfig mConfig = EGL_NO_CONFIG_KHR;
70 EGLContext mContext = EGL_NO_CONTEXT;
71 EGLSurface mSurface = EGL_NO_SURFACE;
72 };
73
TEST_P(EGLQueryContextTest,GetConfigID)74 TEST_P(EGLQueryContextTest, GetConfigID)
75 {
76 EGLint configId, contextConfigId;
77 EXPECT_TRUE(eglGetConfigAttrib(mDisplay, mConfig, EGL_CONFIG_ID, &configId) != EGL_FALSE);
78 EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_CONFIG_ID, &contextConfigId) != EGL_FALSE);
79 EXPECT_TRUE(configId == contextConfigId);
80 }
81
TEST_P(EGLQueryContextTest,GetClientType)82 TEST_P(EGLQueryContextTest, GetClientType)
83 {
84 EGLint clientType;
85 EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_CONTEXT_CLIENT_TYPE, &clientType) !=
86 EGL_FALSE);
87 EXPECT_TRUE(clientType == EGL_OPENGL_ES_API);
88 }
89
TEST_P(EGLQueryContextTest,GetClientVersion)90 TEST_P(EGLQueryContextTest, GetClientVersion)
91 {
92 EGLint clientVersion;
93 EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_CONTEXT_CLIENT_VERSION, &clientVersion) !=
94 EGL_FALSE);
95 EXPECT_GE(clientVersion, GetParam().majorVersion);
96 }
97
TEST_P(EGLQueryContextTest,GetRenderBufferNoSurface)98 TEST_P(EGLQueryContextTest, GetRenderBufferNoSurface)
99 {
100 EGLint renderBuffer;
101 EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_RENDER_BUFFER, &renderBuffer) != EGL_FALSE);
102 EXPECT_TRUE(renderBuffer == EGL_NONE);
103 }
104
TEST_P(EGLQueryContextTest,GetRenderBufferBoundSurface)105 TEST_P(EGLQueryContextTest, GetRenderBufferBoundSurface)
106 {
107 ANGLE_SKIP_TEST_IF(!mSurface);
108
109 EGLint renderBuffer, contextRenderBuffer;
110 EXPECT_TRUE(eglQuerySurface(mDisplay, mSurface, EGL_RENDER_BUFFER, &renderBuffer) != EGL_FALSE);
111 EXPECT_TRUE(eglMakeCurrent(mDisplay, mSurface, mSurface, mContext) != EGL_FALSE);
112 EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_RENDER_BUFFER, &contextRenderBuffer) !=
113 EGL_FALSE);
114 EXPECT_TRUE(renderBuffer == contextRenderBuffer);
115 ASSERT_EGL_SUCCESS();
116 }
117
TEST_P(EGLQueryContextTest,BadDisplay)118 TEST_P(EGLQueryContextTest, BadDisplay)
119 {
120 EGLint val;
121 EXPECT_TRUE(eglQueryContext(EGL_NO_DISPLAY, mContext, EGL_CONTEXT_CLIENT_TYPE, &val) ==
122 EGL_FALSE);
123 EXPECT_TRUE(eglGetError() == EGL_BAD_DISPLAY);
124 }
125
TEST_P(EGLQueryContextTest,NotInitialized)126 TEST_P(EGLQueryContextTest, NotInitialized)
127 {
128 EGLint val;
129 testTearDown();
130 EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_CONTEXT_CLIENT_TYPE, &val) == EGL_FALSE);
131 EXPECT_TRUE(eglGetError() == EGL_NOT_INITIALIZED);
132
133 mDisplay = EGL_NO_DISPLAY;
134 mSurface = EGL_NO_SURFACE;
135 mContext = EGL_NO_CONTEXT;
136 }
137
TEST_P(EGLQueryContextTest,BadContext)138 TEST_P(EGLQueryContextTest, BadContext)
139 {
140 EGLint val;
141 EXPECT_TRUE(eglQueryContext(mDisplay, EGL_NO_CONTEXT, EGL_CONTEXT_CLIENT_TYPE, &val) ==
142 EGL_FALSE);
143 EXPECT_TRUE(eglGetError() == EGL_BAD_CONTEXT);
144 }
145
TEST_P(EGLQueryContextTest,BadAttribute)146 TEST_P(EGLQueryContextTest, BadAttribute)
147 {
148 EGLint val;
149 EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_HEIGHT, &val) == EGL_FALSE);
150 EXPECT_TRUE(eglGetError() == EGL_BAD_ATTRIBUTE);
151 }
152
153 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLQueryContextTest);
154 ANGLE_INSTANTIATE_TEST(EGLQueryContextTest,
155 WithNoFixture(ES2_D3D9()),
156 WithNoFixture(ES2_D3D11()),
157 WithNoFixture(ES2_OPENGL()),
158 WithNoFixture(ES2_VULKAN()),
159 WithNoFixture(ES3_D3D11()),
160 WithNoFixture(ES3_OPENGL()));
161