xref: /aosp_15_r20/external/angle/src/tests/egl_tests/EGLSurfaceTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // EGLSurfaceTest:
7*8975f5c5SAndroid Build Coastguard Worker //   Tests pertaining to egl::Surface.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker 
10*8975f5c5SAndroid Build Coastguard Worker #include <gtest/gtest.h>
11*8975f5c5SAndroid Build Coastguard Worker 
12*8975f5c5SAndroid Build Coastguard Worker #include <thread>
13*8975f5c5SAndroid Build Coastguard Worker #include <vector>
14*8975f5c5SAndroid Build Coastguard Worker 
15*8975f5c5SAndroid Build Coastguard Worker #include "common/Color.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "common/platform.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "util/EGLWindow.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "util/OSWindow.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "util/Timer.h"
22*8975f5c5SAndroid Build Coastguard Worker 
23*8975f5c5SAndroid Build Coastguard Worker #if defined(ANGLE_ENABLE_D3D11)
24*8975f5c5SAndroid Build Coastguard Worker #    define INITGUID
25*8975f5c5SAndroid Build Coastguard Worker #    include <guiddef.h>
26*8975f5c5SAndroid Build Coastguard Worker 
27*8975f5c5SAndroid Build Coastguard Worker #    include <d3d11.h>
28*8975f5c5SAndroid Build Coastguard Worker #    include <dcomp.h>
29*8975f5c5SAndroid Build Coastguard Worker #endif
30*8975f5c5SAndroid Build Coastguard Worker 
31*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
32*8975f5c5SAndroid Build Coastguard Worker 
33*8975f5c5SAndroid Build Coastguard Worker namespace
34*8975f5c5SAndroid Build Coastguard Worker {
35*8975f5c5SAndroid Build Coastguard Worker 
36*8975f5c5SAndroid Build Coastguard Worker class EGLSurfaceTest : public ANGLETest<>
37*8975f5c5SAndroid Build Coastguard Worker {
38*8975f5c5SAndroid Build Coastguard Worker   protected:
EGLSurfaceTest()39*8975f5c5SAndroid Build Coastguard Worker     EGLSurfaceTest()
40*8975f5c5SAndroid Build Coastguard Worker         : mDisplay(EGL_NO_DISPLAY),
41*8975f5c5SAndroid Build Coastguard Worker           mWindowSurface(EGL_NO_SURFACE),
42*8975f5c5SAndroid Build Coastguard Worker           mPbufferSurface(EGL_NO_SURFACE),
43*8975f5c5SAndroid Build Coastguard Worker           mContext(EGL_NO_CONTEXT),
44*8975f5c5SAndroid Build Coastguard Worker           mSecondContext(EGL_NO_CONTEXT),
45*8975f5c5SAndroid Build Coastguard Worker           mOSWindow(nullptr)
46*8975f5c5SAndroid Build Coastguard Worker     {}
47*8975f5c5SAndroid Build Coastguard Worker 
testSetUp()48*8975f5c5SAndroid Build Coastguard Worker     void testSetUp() override
49*8975f5c5SAndroid Build Coastguard Worker     {
50*8975f5c5SAndroid Build Coastguard Worker         mOSWindow = OSWindow::New();
51*8975f5c5SAndroid Build Coastguard Worker         mOSWindow->initialize("EGLSurfaceTest", 64, 64);
52*8975f5c5SAndroid Build Coastguard Worker     }
53*8975f5c5SAndroid Build Coastguard Worker 
tearDownContextAndSurface()54*8975f5c5SAndroid Build Coastguard Worker     void tearDownContextAndSurface()
55*8975f5c5SAndroid Build Coastguard Worker     {
56*8975f5c5SAndroid Build Coastguard Worker         if (mDisplay == EGL_NO_DISPLAY)
57*8975f5c5SAndroid Build Coastguard Worker         {
58*8975f5c5SAndroid Build Coastguard Worker             return;
59*8975f5c5SAndroid Build Coastguard Worker         }
60*8975f5c5SAndroid Build Coastguard Worker 
61*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
62*8975f5c5SAndroid Build Coastguard Worker 
63*8975f5c5SAndroid Build Coastguard Worker         if (mWindowSurface != EGL_NO_SURFACE)
64*8975f5c5SAndroid Build Coastguard Worker         {
65*8975f5c5SAndroid Build Coastguard Worker             eglDestroySurface(mDisplay, mWindowSurface);
66*8975f5c5SAndroid Build Coastguard Worker             mWindowSurface = EGL_NO_SURFACE;
67*8975f5c5SAndroid Build Coastguard Worker         }
68*8975f5c5SAndroid Build Coastguard Worker 
69*8975f5c5SAndroid Build Coastguard Worker         if (mPbufferSurface != EGL_NO_SURFACE)
70*8975f5c5SAndroid Build Coastguard Worker         {
71*8975f5c5SAndroid Build Coastguard Worker             eglDestroySurface(mDisplay, mPbufferSurface);
72*8975f5c5SAndroid Build Coastguard Worker             mPbufferSurface = EGL_NO_SURFACE;
73*8975f5c5SAndroid Build Coastguard Worker         }
74*8975f5c5SAndroid Build Coastguard Worker 
75*8975f5c5SAndroid Build Coastguard Worker         if (mContext != EGL_NO_CONTEXT)
76*8975f5c5SAndroid Build Coastguard Worker         {
77*8975f5c5SAndroid Build Coastguard Worker             eglDestroyContext(mDisplay, mContext);
78*8975f5c5SAndroid Build Coastguard Worker             mContext = EGL_NO_CONTEXT;
79*8975f5c5SAndroid Build Coastguard Worker         }
80*8975f5c5SAndroid Build Coastguard Worker 
81*8975f5c5SAndroid Build Coastguard Worker         if (mSecondContext != EGL_NO_CONTEXT)
82*8975f5c5SAndroid Build Coastguard Worker         {
83*8975f5c5SAndroid Build Coastguard Worker             eglDestroyContext(mDisplay, mSecondContext);
84*8975f5c5SAndroid Build Coastguard Worker             mSecondContext = EGL_NO_CONTEXT;
85*8975f5c5SAndroid Build Coastguard Worker         }
86*8975f5c5SAndroid Build Coastguard Worker     }
87*8975f5c5SAndroid Build Coastguard Worker 
88*8975f5c5SAndroid Build Coastguard Worker     // Release any resources created in the test body
testTearDown()89*8975f5c5SAndroid Build Coastguard Worker     void testTearDown() override
90*8975f5c5SAndroid Build Coastguard Worker     {
91*8975f5c5SAndroid Build Coastguard Worker         tearDownContextAndSurface();
92*8975f5c5SAndroid Build Coastguard Worker 
93*8975f5c5SAndroid Build Coastguard Worker         if (mDisplay != EGL_NO_DISPLAY)
94*8975f5c5SAndroid Build Coastguard Worker         {
95*8975f5c5SAndroid Build Coastguard Worker             eglTerminate(mDisplay);
96*8975f5c5SAndroid Build Coastguard Worker             mDisplay = EGL_NO_DISPLAY;
97*8975f5c5SAndroid Build Coastguard Worker         }
98*8975f5c5SAndroid Build Coastguard Worker 
99*8975f5c5SAndroid Build Coastguard Worker         mOSWindow->destroy();
100*8975f5c5SAndroid Build Coastguard Worker         OSWindow::Delete(&mOSWindow);
101*8975f5c5SAndroid Build Coastguard Worker 
102*8975f5c5SAndroid Build Coastguard Worker         for (OSWindow *win : mOtherWindows)
103*8975f5c5SAndroid Build Coastguard Worker         {
104*8975f5c5SAndroid Build Coastguard Worker             if (win != nullptr)
105*8975f5c5SAndroid Build Coastguard Worker             {
106*8975f5c5SAndroid Build Coastguard Worker                 win->destroy();
107*8975f5c5SAndroid Build Coastguard Worker                 OSWindow::Delete(&win);
108*8975f5c5SAndroid Build Coastguard Worker             }
109*8975f5c5SAndroid Build Coastguard Worker         }
110*8975f5c5SAndroid Build Coastguard Worker         mOtherWindows.clear();
111*8975f5c5SAndroid Build Coastguard Worker 
112*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(mWindowSurface == EGL_NO_SURFACE && mContext == EGL_NO_CONTEXT);
113*8975f5c5SAndroid Build Coastguard Worker     }
114*8975f5c5SAndroid Build Coastguard Worker 
initializeDisplay()115*8975f5c5SAndroid Build Coastguard Worker     void initializeDisplay()
116*8975f5c5SAndroid Build Coastguard Worker     {
117*8975f5c5SAndroid Build Coastguard Worker         GLenum platformType = GetParam().getRenderer();
118*8975f5c5SAndroid Build Coastguard Worker         GLenum deviceType   = GetParam().getDeviceType();
119*8975f5c5SAndroid Build Coastguard Worker 
120*8975f5c5SAndroid Build Coastguard Worker         std::vector<EGLint> displayAttributes;
121*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
122*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(platformType);
123*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
124*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(EGL_DONT_CARE);
125*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
126*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(EGL_DONT_CARE);
127*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
128*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(deviceType);
129*8975f5c5SAndroid Build Coastguard Worker         displayAttributes.push_back(EGL_NONE);
130*8975f5c5SAndroid Build Coastguard Worker 
131*8975f5c5SAndroid Build Coastguard Worker         mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
132*8975f5c5SAndroid Build Coastguard Worker                                             reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
133*8975f5c5SAndroid Build Coastguard Worker                                             displayAttributes.data());
134*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);
135*8975f5c5SAndroid Build Coastguard Worker 
136*8975f5c5SAndroid Build Coastguard Worker         EGLint majorVersion, minorVersion;
137*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(eglInitialize(mDisplay, &majorVersion, &minorVersion) == EGL_TRUE);
138*8975f5c5SAndroid Build Coastguard Worker 
139*8975f5c5SAndroid Build Coastguard Worker         eglBindAPI(EGL_OPENGL_ES_API);
140*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
141*8975f5c5SAndroid Build Coastguard Worker     }
142*8975f5c5SAndroid Build Coastguard Worker 
initializeSingleContext(EGLContext * context,EGLint virtualizationGroup=EGL_DONT_CARE)143*8975f5c5SAndroid Build Coastguard Worker     void initializeSingleContext(EGLContext *context, EGLint virtualizationGroup = EGL_DONT_CARE)
144*8975f5c5SAndroid Build Coastguard Worker     {
145*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(*context == EGL_NO_CONTEXT);
146*8975f5c5SAndroid Build Coastguard Worker 
147*8975f5c5SAndroid Build Coastguard Worker         EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION, GetParam().majorVersion,
148*8975f5c5SAndroid Build Coastguard Worker                                      EGL_CONTEXT_VIRTUALIZATION_GROUP_ANGLE, virtualizationGroup,
149*8975f5c5SAndroid Build Coastguard Worker                                      EGL_NONE};
150*8975f5c5SAndroid Build Coastguard Worker 
151*8975f5c5SAndroid Build Coastguard Worker         if (!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_context_virtualization"))
152*8975f5c5SAndroid Build Coastguard Worker         {
153*8975f5c5SAndroid Build Coastguard Worker             contextAttibutes[2] = EGL_NONE;
154*8975f5c5SAndroid Build Coastguard Worker         }
155*8975f5c5SAndroid Build Coastguard Worker 
156*8975f5c5SAndroid Build Coastguard Worker         *context = eglCreateContext(mDisplay, mConfig, nullptr, contextAttibutes);
157*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
158*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(*context != EGL_NO_CONTEXT);
159*8975f5c5SAndroid Build Coastguard Worker     }
160*8975f5c5SAndroid Build Coastguard Worker 
initializeMainContext()161*8975f5c5SAndroid Build Coastguard Worker     void initializeMainContext() { initializeSingleContext(&mContext); }
162*8975f5c5SAndroid Build Coastguard Worker 
initializeAllContexts()163*8975f5c5SAndroid Build Coastguard Worker     void initializeAllContexts()
164*8975f5c5SAndroid Build Coastguard Worker     {
165*8975f5c5SAndroid Build Coastguard Worker         initializeSingleContext(&mContext);
166*8975f5c5SAndroid Build Coastguard Worker         initializeSingleContext(&mSecondContext);
167*8975f5c5SAndroid Build Coastguard Worker     }
168*8975f5c5SAndroid Build Coastguard Worker 
initializeWindowSurfaceWithAttribs(EGLConfig config,const std::vector<EGLint> & additionalAttributes,EGLenum expectedResult)169*8975f5c5SAndroid Build Coastguard Worker     void initializeWindowSurfaceWithAttribs(EGLConfig config,
170*8975f5c5SAndroid Build Coastguard Worker                                             const std::vector<EGLint> &additionalAttributes,
171*8975f5c5SAndroid Build Coastguard Worker                                             EGLenum expectedResult)
172*8975f5c5SAndroid Build Coastguard Worker     {
173*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(mWindowSurface == EGL_NO_SURFACE);
174*8975f5c5SAndroid Build Coastguard Worker 
175*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceType = EGL_NONE;
176*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);
177*8975f5c5SAndroid Build Coastguard Worker 
178*8975f5c5SAndroid Build Coastguard Worker         if (surfaceType & EGL_WINDOW_BIT)
179*8975f5c5SAndroid Build Coastguard Worker         {
180*8975f5c5SAndroid Build Coastguard Worker             std::vector<EGLint> windowAttributes = additionalAttributes;
181*8975f5c5SAndroid Build Coastguard Worker             windowAttributes.push_back(EGL_NONE);
182*8975f5c5SAndroid Build Coastguard Worker 
183*8975f5c5SAndroid Build Coastguard Worker             // Create first window surface
184*8975f5c5SAndroid Build Coastguard Worker             mWindowSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(),
185*8975f5c5SAndroid Build Coastguard Worker                                                     windowAttributes.data());
186*8975f5c5SAndroid Build Coastguard Worker         }
187*8975f5c5SAndroid Build Coastguard Worker 
188*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGLENUM_EQ(eglGetError(), expectedResult);
189*8975f5c5SAndroid Build Coastguard Worker     }
190*8975f5c5SAndroid Build Coastguard Worker 
initializeSurfaceWithAttribs(EGLConfig config,const std::vector<EGLint> & additionalAttributes)191*8975f5c5SAndroid Build Coastguard Worker     void initializeSurfaceWithAttribs(EGLConfig config,
192*8975f5c5SAndroid Build Coastguard Worker                                       const std::vector<EGLint> &additionalAttributes)
193*8975f5c5SAndroid Build Coastguard Worker     {
194*8975f5c5SAndroid Build Coastguard Worker         mConfig = config;
195*8975f5c5SAndroid Build Coastguard Worker 
196*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceType = EGL_NONE;
197*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);
198*8975f5c5SAndroid Build Coastguard Worker 
199*8975f5c5SAndroid Build Coastguard Worker         if (surfaceType & EGL_WINDOW_BIT)
200*8975f5c5SAndroid Build Coastguard Worker         {
201*8975f5c5SAndroid Build Coastguard Worker             initializeWindowSurfaceWithAttribs(config, additionalAttributes, EGL_SUCCESS);
202*8975f5c5SAndroid Build Coastguard Worker         }
203*8975f5c5SAndroid Build Coastguard Worker 
204*8975f5c5SAndroid Build Coastguard Worker         if (surfaceType & EGL_PBUFFER_BIT)
205*8975f5c5SAndroid Build Coastguard Worker         {
206*8975f5c5SAndroid Build Coastguard Worker             ASSERT_TRUE(mPbufferSurface == EGL_NO_SURFACE);
207*8975f5c5SAndroid Build Coastguard Worker 
208*8975f5c5SAndroid Build Coastguard Worker             std::vector<EGLint> pbufferAttributes = additionalAttributes;
209*8975f5c5SAndroid Build Coastguard Worker 
210*8975f5c5SAndroid Build Coastguard Worker             // Give pbuffer non-zero dimensions.
211*8975f5c5SAndroid Build Coastguard Worker             pbufferAttributes.push_back(EGL_WIDTH);
212*8975f5c5SAndroid Build Coastguard Worker             pbufferAttributes.push_back(64);
213*8975f5c5SAndroid Build Coastguard Worker             pbufferAttributes.push_back(EGL_HEIGHT);
214*8975f5c5SAndroid Build Coastguard Worker             pbufferAttributes.push_back(64);
215*8975f5c5SAndroid Build Coastguard Worker             pbufferAttributes.push_back(EGL_NONE);
216*8975f5c5SAndroid Build Coastguard Worker 
217*8975f5c5SAndroid Build Coastguard Worker             mPbufferSurface = eglCreatePbufferSurface(mDisplay, mConfig, pbufferAttributes.data());
218*8975f5c5SAndroid Build Coastguard Worker             ASSERT_EGL_SUCCESS();
219*8975f5c5SAndroid Build Coastguard Worker         }
220*8975f5c5SAndroid Build Coastguard Worker     }
221*8975f5c5SAndroid Build Coastguard Worker 
initializeSurface(EGLConfig config)222*8975f5c5SAndroid Build Coastguard Worker     void initializeSurface(EGLConfig config)
223*8975f5c5SAndroid Build Coastguard Worker     {
224*8975f5c5SAndroid Build Coastguard Worker         std::vector<EGLint> additionalAttributes;
225*8975f5c5SAndroid Build Coastguard Worker         initializeSurfaceWithAttribs(config, additionalAttributes);
226*8975f5c5SAndroid Build Coastguard Worker     }
227*8975f5c5SAndroid Build Coastguard Worker 
chooseDefaultConfig(bool requireWindowSurface) const228*8975f5c5SAndroid Build Coastguard Worker     EGLConfig chooseDefaultConfig(bool requireWindowSurface) const
229*8975f5c5SAndroid Build Coastguard Worker     {
230*8975f5c5SAndroid Build Coastguard Worker         const EGLint configAttributes[] = {EGL_RED_SIZE,
231*8975f5c5SAndroid Build Coastguard Worker                                            EGL_DONT_CARE,
232*8975f5c5SAndroid Build Coastguard Worker                                            EGL_GREEN_SIZE,
233*8975f5c5SAndroid Build Coastguard Worker                                            EGL_DONT_CARE,
234*8975f5c5SAndroid Build Coastguard Worker                                            EGL_BLUE_SIZE,
235*8975f5c5SAndroid Build Coastguard Worker                                            EGL_DONT_CARE,
236*8975f5c5SAndroid Build Coastguard Worker                                            EGL_ALPHA_SIZE,
237*8975f5c5SAndroid Build Coastguard Worker                                            EGL_DONT_CARE,
238*8975f5c5SAndroid Build Coastguard Worker                                            EGL_DEPTH_SIZE,
239*8975f5c5SAndroid Build Coastguard Worker                                            EGL_DONT_CARE,
240*8975f5c5SAndroid Build Coastguard Worker                                            EGL_STENCIL_SIZE,
241*8975f5c5SAndroid Build Coastguard Worker                                            EGL_DONT_CARE,
242*8975f5c5SAndroid Build Coastguard Worker                                            EGL_SAMPLE_BUFFERS,
243*8975f5c5SAndroid Build Coastguard Worker                                            0,
244*8975f5c5SAndroid Build Coastguard Worker                                            EGL_SURFACE_TYPE,
245*8975f5c5SAndroid Build Coastguard Worker                                            requireWindowSurface ? EGL_WINDOW_BIT : EGL_DONT_CARE,
246*8975f5c5SAndroid Build Coastguard Worker                                            EGL_NONE};
247*8975f5c5SAndroid Build Coastguard Worker 
248*8975f5c5SAndroid Build Coastguard Worker         EGLint configCount;
249*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config;
250*8975f5c5SAndroid Build Coastguard Worker         if (eglChooseConfig(mDisplay, configAttributes, &config, 1, &configCount) != EGL_TRUE)
251*8975f5c5SAndroid Build Coastguard Worker             return nullptr;
252*8975f5c5SAndroid Build Coastguard Worker         if (configCount != 1)
253*8975f5c5SAndroid Build Coastguard Worker             return nullptr;
254*8975f5c5SAndroid Build Coastguard Worker         return config;
255*8975f5c5SAndroid Build Coastguard Worker     }
256*8975f5c5SAndroid Build Coastguard Worker 
initializeSurfaceWithDefaultConfig(bool requireWindowSurface)257*8975f5c5SAndroid Build Coastguard Worker     void initializeSurfaceWithDefaultConfig(bool requireWindowSurface)
258*8975f5c5SAndroid Build Coastguard Worker     {
259*8975f5c5SAndroid Build Coastguard Worker         EGLConfig defaultConfig = chooseDefaultConfig(requireWindowSurface);
260*8975f5c5SAndroid Build Coastguard Worker         ASSERT_NE(defaultConfig, nullptr);
261*8975f5c5SAndroid Build Coastguard Worker         initializeSurface(defaultConfig);
262*8975f5c5SAndroid Build Coastguard Worker     }
263*8975f5c5SAndroid Build Coastguard Worker 
createProgram(const char * fs=angle::essl1_shaders::fs::Red ())264*8975f5c5SAndroid Build Coastguard Worker     GLuint createProgram(const char *fs = angle::essl1_shaders::fs::Red())
265*8975f5c5SAndroid Build Coastguard Worker     {
266*8975f5c5SAndroid Build Coastguard Worker         return CompileProgram(angle::essl1_shaders::vs::Simple(), fs);
267*8975f5c5SAndroid Build Coastguard Worker     }
268*8975f5c5SAndroid Build Coastguard Worker 
drawWithProgram(GLuint program)269*8975f5c5SAndroid Build Coastguard Worker     void drawWithProgram(GLuint program)
270*8975f5c5SAndroid Build Coastguard Worker     {
271*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0, 0, 0, 1);
272*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
273*8975f5c5SAndroid Build Coastguard Worker 
274*8975f5c5SAndroid Build Coastguard Worker         GLint positionLocation =
275*8975f5c5SAndroid Build Coastguard Worker             glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib());
276*8975f5c5SAndroid Build Coastguard Worker 
277*8975f5c5SAndroid Build Coastguard Worker         glUseProgram(program);
278*8975f5c5SAndroid Build Coastguard Worker 
279*8975f5c5SAndroid Build Coastguard Worker         const GLfloat vertices[] = {
280*8975f5c5SAndroid Build Coastguard Worker             -1.0f, 1.0f, 0.5f, -1.0f, -1.0f, 0.5f, 1.0f, -1.0f, 0.5f,
281*8975f5c5SAndroid Build Coastguard Worker 
282*8975f5c5SAndroid Build Coastguard Worker             -1.0f, 1.0f, 0.5f, 1.0f,  -1.0f, 0.5f, 1.0f, 1.0f,  0.5f,
283*8975f5c5SAndroid Build Coastguard Worker         };
284*8975f5c5SAndroid Build Coastguard Worker 
285*8975f5c5SAndroid Build Coastguard Worker         glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
286*8975f5c5SAndroid Build Coastguard Worker         glEnableVertexAttribArray(positionLocation);
287*8975f5c5SAndroid Build Coastguard Worker 
288*8975f5c5SAndroid Build Coastguard Worker         glDrawArrays(GL_TRIANGLES, 0, 6);
289*8975f5c5SAndroid Build Coastguard Worker 
290*8975f5c5SAndroid Build Coastguard Worker         glDisableVertexAttribArray(positionLocation);
291*8975f5c5SAndroid Build Coastguard Worker         glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
292*8975f5c5SAndroid Build Coastguard Worker 
293*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(mOSWindow->getWidth() / 2, mOSWindow->getHeight() / 2, 255, 0, 0, 255);
294*8975f5c5SAndroid Build Coastguard Worker     }
295*8975f5c5SAndroid Build Coastguard Worker 
runMessageLoopTest(EGLSurface secondSurface,EGLContext secondContext)296*8975f5c5SAndroid Build Coastguard Worker     void runMessageLoopTest(EGLSurface secondSurface, EGLContext secondContext)
297*8975f5c5SAndroid Build Coastguard Worker     {
298*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
299*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
300*8975f5c5SAndroid Build Coastguard Worker 
301*8975f5c5SAndroid Build Coastguard Worker         // Make a second context current
302*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, secondSurface, secondSurface, secondContext);
303*8975f5c5SAndroid Build Coastguard Worker         eglDestroySurface(mDisplay, mWindowSurface);
304*8975f5c5SAndroid Build Coastguard Worker 
305*8975f5c5SAndroid Build Coastguard Worker         // Create second window surface
306*8975f5c5SAndroid Build Coastguard Worker         std::vector<EGLint> surfaceAttributes;
307*8975f5c5SAndroid Build Coastguard Worker         surfaceAttributes.push_back(EGL_NONE);
308*8975f5c5SAndroid Build Coastguard Worker         surfaceAttributes.push_back(EGL_NONE);
309*8975f5c5SAndroid Build Coastguard Worker 
310*8975f5c5SAndroid Build Coastguard Worker         mWindowSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(),
311*8975f5c5SAndroid Build Coastguard Worker                                                 &surfaceAttributes[0]);
312*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
313*8975f5c5SAndroid Build Coastguard Worker 
314*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
315*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
316*8975f5c5SAndroid Build Coastguard Worker 
317*8975f5c5SAndroid Build Coastguard Worker         mOSWindow->signalTestEvent();
318*8975f5c5SAndroid Build Coastguard Worker         mOSWindow->messageLoop();
319*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(mOSWindow->didTestEventFire());
320*8975f5c5SAndroid Build Coastguard Worker 
321*8975f5c5SAndroid Build Coastguard Worker         // Simple operation to test the FBO is set appropriately
322*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
323*8975f5c5SAndroid Build Coastguard Worker     }
324*8975f5c5SAndroid Build Coastguard Worker 
325*8975f5c5SAndroid Build Coastguard Worker     void runWaitSemaphoreTest(bool useSecondContext);
326*8975f5c5SAndroid Build Coastguard Worker     void runDestroyNotCurrentSurfaceTest(bool testWindowsSurface);
327*8975f5c5SAndroid Build Coastguard Worker 
328*8975f5c5SAndroid Build Coastguard Worker     void drawQuadThenTearDown();
329*8975f5c5SAndroid Build Coastguard Worker 
330*8975f5c5SAndroid Build Coastguard Worker     EGLDisplay mDisplay;
331*8975f5c5SAndroid Build Coastguard Worker     EGLSurface mWindowSurface;
332*8975f5c5SAndroid Build Coastguard Worker     EGLSurface mPbufferSurface;
333*8975f5c5SAndroid Build Coastguard Worker     EGLContext mContext;
334*8975f5c5SAndroid Build Coastguard Worker     EGLContext mSecondContext;
335*8975f5c5SAndroid Build Coastguard Worker     EGLConfig mConfig;
336*8975f5c5SAndroid Build Coastguard Worker     OSWindow *mOSWindow;
337*8975f5c5SAndroid Build Coastguard Worker     std::vector<OSWindow *> mOtherWindows;
338*8975f5c5SAndroid Build Coastguard Worker };
339*8975f5c5SAndroid Build Coastguard Worker 
340*8975f5c5SAndroid Build Coastguard Worker class EGLFloatSurfaceTest : public EGLSurfaceTest
341*8975f5c5SAndroid Build Coastguard Worker {
342*8975f5c5SAndroid Build Coastguard Worker   protected:
EGLFloatSurfaceTest()343*8975f5c5SAndroid Build Coastguard Worker     EGLFloatSurfaceTest() : EGLSurfaceTest()
344*8975f5c5SAndroid Build Coastguard Worker     {
345*8975f5c5SAndroid Build Coastguard Worker         setWindowWidth(512);
346*8975f5c5SAndroid Build Coastguard Worker         setWindowHeight(512);
347*8975f5c5SAndroid Build Coastguard Worker     }
348*8975f5c5SAndroid Build Coastguard Worker 
testSetUp()349*8975f5c5SAndroid Build Coastguard Worker     void testSetUp() override
350*8975f5c5SAndroid Build Coastguard Worker     {
351*8975f5c5SAndroid Build Coastguard Worker         mOSWindow = OSWindow::New();
352*8975f5c5SAndroid Build Coastguard Worker         mOSWindow->initialize("EGLFloatSurfaceTest", 64, 64);
353*8975f5c5SAndroid Build Coastguard Worker     }
354*8975f5c5SAndroid Build Coastguard Worker 
testTearDown()355*8975f5c5SAndroid Build Coastguard Worker     void testTearDown() override
356*8975f5c5SAndroid Build Coastguard Worker     {
357*8975f5c5SAndroid Build Coastguard Worker         EGLSurfaceTest::testTearDown();
358*8975f5c5SAndroid Build Coastguard Worker         glDeleteProgram(mProgram);
359*8975f5c5SAndroid Build Coastguard Worker     }
360*8975f5c5SAndroid Build Coastguard Worker 
createProgram()361*8975f5c5SAndroid Build Coastguard Worker     GLuint createProgram()
362*8975f5c5SAndroid Build Coastguard Worker     {
363*8975f5c5SAndroid Build Coastguard Worker         constexpr char kFS[] =
364*8975f5c5SAndroid Build Coastguard Worker             "precision highp float;\n"
365*8975f5c5SAndroid Build Coastguard Worker             "void main()\n"
366*8975f5c5SAndroid Build Coastguard Worker             "{\n"
367*8975f5c5SAndroid Build Coastguard Worker             "   gl_FragColor = vec4(1.0, 2.0, 3.0, 4.0);\n"
368*8975f5c5SAndroid Build Coastguard Worker             "}\n";
369*8975f5c5SAndroid Build Coastguard Worker         return CompileProgram(angle::essl1_shaders::vs::Simple(), kFS);
370*8975f5c5SAndroid Build Coastguard Worker     }
371*8975f5c5SAndroid Build Coastguard Worker 
initializeSurfaceWithFloatConfig()372*8975f5c5SAndroid Build Coastguard Worker     bool initializeSurfaceWithFloatConfig()
373*8975f5c5SAndroid Build Coastguard Worker     {
374*8975f5c5SAndroid Build Coastguard Worker         const EGLint configAttributes[] = {EGL_SURFACE_TYPE,
375*8975f5c5SAndroid Build Coastguard Worker                                            EGL_WINDOW_BIT,
376*8975f5c5SAndroid Build Coastguard Worker                                            EGL_RED_SIZE,
377*8975f5c5SAndroid Build Coastguard Worker                                            16,
378*8975f5c5SAndroid Build Coastguard Worker                                            EGL_GREEN_SIZE,
379*8975f5c5SAndroid Build Coastguard Worker                                            16,
380*8975f5c5SAndroid Build Coastguard Worker                                            EGL_BLUE_SIZE,
381*8975f5c5SAndroid Build Coastguard Worker                                            16,
382*8975f5c5SAndroid Build Coastguard Worker                                            EGL_ALPHA_SIZE,
383*8975f5c5SAndroid Build Coastguard Worker                                            16,
384*8975f5c5SAndroid Build Coastguard Worker                                            EGL_COLOR_COMPONENT_TYPE_EXT,
385*8975f5c5SAndroid Build Coastguard Worker                                            EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
386*8975f5c5SAndroid Build Coastguard Worker                                            EGL_NONE,
387*8975f5c5SAndroid Build Coastguard Worker                                            EGL_NONE};
388*8975f5c5SAndroid Build Coastguard Worker 
389*8975f5c5SAndroid Build Coastguard Worker         initializeDisplay();
390*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config;
391*8975f5c5SAndroid Build Coastguard Worker         if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config) == EGL_FALSE)
392*8975f5c5SAndroid Build Coastguard Worker         {
393*8975f5c5SAndroid Build Coastguard Worker             std::cout << "EGLConfig for a float surface is not supported, skipping test"
394*8975f5c5SAndroid Build Coastguard Worker                       << std::endl;
395*8975f5c5SAndroid Build Coastguard Worker             return false;
396*8975f5c5SAndroid Build Coastguard Worker         }
397*8975f5c5SAndroid Build Coastguard Worker 
398*8975f5c5SAndroid Build Coastguard Worker         initializeSurface(config);
399*8975f5c5SAndroid Build Coastguard Worker         initializeMainContext();
400*8975f5c5SAndroid Build Coastguard Worker 
401*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
402*8975f5c5SAndroid Build Coastguard Worker         mProgram = createProgram();
403*8975f5c5SAndroid Build Coastguard Worker         return true;
404*8975f5c5SAndroid Build Coastguard Worker     }
405*8975f5c5SAndroid Build Coastguard Worker 
406*8975f5c5SAndroid Build Coastguard Worker     GLuint mProgram;
407*8975f5c5SAndroid Build Coastguard Worker };
408*8975f5c5SAndroid Build Coastguard Worker 
409*8975f5c5SAndroid Build Coastguard Worker class EGLSingleBufferTest : public ANGLETest<>
410*8975f5c5SAndroid Build Coastguard Worker {
411*8975f5c5SAndroid Build Coastguard Worker   protected:
EGLSingleBufferTest()412*8975f5c5SAndroid Build Coastguard Worker     EGLSingleBufferTest() {}
413*8975f5c5SAndroid Build Coastguard Worker 
testSetUp()414*8975f5c5SAndroid Build Coastguard Worker     void testSetUp() override
415*8975f5c5SAndroid Build Coastguard Worker     {
416*8975f5c5SAndroid Build Coastguard Worker         EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};
417*8975f5c5SAndroid Build Coastguard Worker         mDisplay           = eglGetPlatformDisplayEXT(
418*8975f5c5SAndroid Build Coastguard Worker             EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
419*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);
420*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_TRUE(eglInitialize(mDisplay, nullptr, nullptr));
421*8975f5c5SAndroid Build Coastguard Worker         mMajorVersion = GetParam().majorVersion;
422*8975f5c5SAndroid Build Coastguard Worker     }
423*8975f5c5SAndroid Build Coastguard Worker 
testTearDown()424*8975f5c5SAndroid Build Coastguard Worker     void testTearDown() override
425*8975f5c5SAndroid Build Coastguard Worker     {
426*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
427*8975f5c5SAndroid Build Coastguard Worker         eglTerminate(mDisplay);
428*8975f5c5SAndroid Build Coastguard Worker     }
429*8975f5c5SAndroid Build Coastguard Worker 
chooseConfig(EGLConfig * config,bool mutableRenderBuffer) const430*8975f5c5SAndroid Build Coastguard Worker     bool chooseConfig(EGLConfig *config, bool mutableRenderBuffer) const
431*8975f5c5SAndroid Build Coastguard Worker     {
432*8975f5c5SAndroid Build Coastguard Worker         bool result          = false;
433*8975f5c5SAndroid Build Coastguard Worker         EGLint count         = 0;
434*8975f5c5SAndroid Build Coastguard Worker         EGLint clientVersion = mMajorVersion == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT;
435*8975f5c5SAndroid Build Coastguard Worker         EGLint attribs[]     = {
436*8975f5c5SAndroid Build Coastguard Worker             EGL_RED_SIZE,
437*8975f5c5SAndroid Build Coastguard Worker             8,
438*8975f5c5SAndroid Build Coastguard Worker             EGL_GREEN_SIZE,
439*8975f5c5SAndroid Build Coastguard Worker             8,
440*8975f5c5SAndroid Build Coastguard Worker             EGL_BLUE_SIZE,
441*8975f5c5SAndroid Build Coastguard Worker             8,
442*8975f5c5SAndroid Build Coastguard Worker             EGL_ALPHA_SIZE,
443*8975f5c5SAndroid Build Coastguard Worker             0,
444*8975f5c5SAndroid Build Coastguard Worker             EGL_RENDERABLE_TYPE,
445*8975f5c5SAndroid Build Coastguard Worker             clientVersion,
446*8975f5c5SAndroid Build Coastguard Worker             EGL_SURFACE_TYPE,
447*8975f5c5SAndroid Build Coastguard Worker             EGL_WINDOW_BIT | (mutableRenderBuffer ? EGL_MUTABLE_RENDER_BUFFER_BIT_KHR : 0),
448*8975f5c5SAndroid Build Coastguard Worker             EGL_NONE};
449*8975f5c5SAndroid Build Coastguard Worker 
450*8975f5c5SAndroid Build Coastguard Worker         result = eglChooseConfig(mDisplay, attribs, config, 1, &count);
451*8975f5c5SAndroid Build Coastguard Worker         return result && (count > 0);
452*8975f5c5SAndroid Build Coastguard Worker     }
453*8975f5c5SAndroid Build Coastguard Worker 
createContext(EGLConfig config,EGLContext * context)454*8975f5c5SAndroid Build Coastguard Worker     bool createContext(EGLConfig config, EGLContext *context)
455*8975f5c5SAndroid Build Coastguard Worker     {
456*8975f5c5SAndroid Build Coastguard Worker         EXPECT_TRUE(*context == EGL_NO_CONTEXT);
457*8975f5c5SAndroid Build Coastguard Worker 
458*8975f5c5SAndroid Build Coastguard Worker         bool result      = false;
459*8975f5c5SAndroid Build Coastguard Worker         EGLint attribs[] = {EGL_CONTEXT_MAJOR_VERSION, mMajorVersion, EGL_NONE};
460*8975f5c5SAndroid Build Coastguard Worker 
461*8975f5c5SAndroid Build Coastguard Worker         *context = eglCreateContext(mDisplay, config, nullptr, attribs);
462*8975f5c5SAndroid Build Coastguard Worker         result   = (*context != EGL_NO_CONTEXT);
463*8975f5c5SAndroid Build Coastguard Worker         EXPECT_TRUE(result);
464*8975f5c5SAndroid Build Coastguard Worker         return result;
465*8975f5c5SAndroid Build Coastguard Worker     }
466*8975f5c5SAndroid Build Coastguard Worker 
createWindowSurface(EGLConfig config,EGLNativeWindowType win,EGLSurface * surface,EGLint renderBuffer) const467*8975f5c5SAndroid Build Coastguard Worker     bool createWindowSurface(EGLConfig config,
468*8975f5c5SAndroid Build Coastguard Worker                              EGLNativeWindowType win,
469*8975f5c5SAndroid Build Coastguard Worker                              EGLSurface *surface,
470*8975f5c5SAndroid Build Coastguard Worker                              EGLint renderBuffer) const
471*8975f5c5SAndroid Build Coastguard Worker     {
472*8975f5c5SAndroid Build Coastguard Worker         EXPECT_TRUE(*surface == EGL_NO_SURFACE);
473*8975f5c5SAndroid Build Coastguard Worker 
474*8975f5c5SAndroid Build Coastguard Worker         bool result      = false;
475*8975f5c5SAndroid Build Coastguard Worker         EGLint attribs[] = {EGL_RENDER_BUFFER, renderBuffer, EGL_NONE};
476*8975f5c5SAndroid Build Coastguard Worker 
477*8975f5c5SAndroid Build Coastguard Worker         *surface = eglCreateWindowSurface(mDisplay, config, win, attribs);
478*8975f5c5SAndroid Build Coastguard Worker         result   = (*surface != EGL_NO_SURFACE);
479*8975f5c5SAndroid Build Coastguard Worker         EXPECT_TRUE(result);
480*8975f5c5SAndroid Build Coastguard Worker         return result;
481*8975f5c5SAndroid Build Coastguard Worker     }
482*8975f5c5SAndroid Build Coastguard Worker 
483*8975f5c5SAndroid Build Coastguard Worker     uint32_t drawAndSwap(EGLSurface &surface, EGLDisplay &display, uint32_t color, bool flush);
484*8975f5c5SAndroid Build Coastguard Worker 
485*8975f5c5SAndroid Build Coastguard Worker     EGLDisplay mDisplay  = EGL_NO_DISPLAY;
486*8975f5c5SAndroid Build Coastguard Worker     EGLint mMajorVersion = 0;
487*8975f5c5SAndroid Build Coastguard Worker     const EGLint kWidth  = 32;
488*8975f5c5SAndroid Build Coastguard Worker     const EGLint kHeight = 32;
489*8975f5c5SAndroid Build Coastguard Worker };
490*8975f5c5SAndroid Build Coastguard Worker 
491*8975f5c5SAndroid Build Coastguard Worker class EGLAndroidAutoRefreshTest : public EGLSingleBufferTest
492*8975f5c5SAndroid Build Coastguard Worker {};
493*8975f5c5SAndroid Build Coastguard Worker 
494*8975f5c5SAndroid Build Coastguard Worker // Test clearing and checking the color is correct
TEST_P(EGLFloatSurfaceTest,Clearing)495*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLFloatSurfaceTest, Clearing)
496*8975f5c5SAndroid Build Coastguard Worker {
497*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!initializeSurfaceWithFloatConfig());
498*8975f5c5SAndroid Build Coastguard Worker 
499*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, mProgram) << "shader compilation failed.";
500*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
501*8975f5c5SAndroid Build Coastguard Worker 
502*8975f5c5SAndroid Build Coastguard Worker     GLColor32F clearColor(0.0f, 1.0f, 2.0f, 3.0f);
503*8975f5c5SAndroid Build Coastguard Worker     glClearColor(clearColor.R, clearColor.G, clearColor.B, clearColor.A);
504*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
505*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
506*8975f5c5SAndroid Build Coastguard Worker 
507*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR32F_EQ(0, 0, clearColor);
508*8975f5c5SAndroid Build Coastguard Worker }
509*8975f5c5SAndroid Build Coastguard Worker 
510*8975f5c5SAndroid Build Coastguard Worker // Test drawing and checking the color is correct
TEST_P(EGLFloatSurfaceTest,Drawing)511*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLFloatSurfaceTest, Drawing)
512*8975f5c5SAndroid Build Coastguard Worker {
513*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!initializeSurfaceWithFloatConfig());
514*8975f5c5SAndroid Build Coastguard Worker 
515*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, mProgram) << "shader compilation failed.";
516*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
517*8975f5c5SAndroid Build Coastguard Worker 
518*8975f5c5SAndroid Build Coastguard Worker     glUseProgram(mProgram);
519*8975f5c5SAndroid Build Coastguard Worker     drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
520*8975f5c5SAndroid Build Coastguard Worker 
521*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_32F_EQ(0, 0, 1.0f, 2.0f, 3.0f, 4.0f);
522*8975f5c5SAndroid Build Coastguard Worker }
523*8975f5c5SAndroid Build Coastguard Worker 
524*8975f5c5SAndroid Build Coastguard Worker class EGLSurfaceTest3 : public EGLSurfaceTest
525*8975f5c5SAndroid Build Coastguard Worker {};
526*8975f5c5SAndroid Build Coastguard Worker 
527*8975f5c5SAndroid Build Coastguard Worker // Test a surface bug where we could have two Window surfaces active
528*8975f5c5SAndroid Build Coastguard Worker // at one time, blocking message loops. See http://crbug.com/475085
TEST_P(EGLSurfaceTest,MessageLoopBug)529*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, MessageLoopBug)
530*8975f5c5SAndroid Build Coastguard Worker {
531*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42261801
532*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsAndroid());
533*8975f5c5SAndroid Build Coastguard Worker 
534*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42261815
535*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsOzone());
536*8975f5c5SAndroid Build Coastguard Worker 
537*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42264022
538*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsIOS());
539*8975f5c5SAndroid Build Coastguard Worker 
540*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
541*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
542*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
543*8975f5c5SAndroid Build Coastguard Worker 
544*8975f5c5SAndroid Build Coastguard Worker     runMessageLoopTest(EGL_NO_SURFACE, EGL_NO_CONTEXT);
545*8975f5c5SAndroid Build Coastguard Worker }
546*8975f5c5SAndroid Build Coastguard Worker 
547*8975f5c5SAndroid Build Coastguard Worker // Tests the message loop bug, but with setting a second context
548*8975f5c5SAndroid Build Coastguard Worker // instead of null.
TEST_P(EGLSurfaceTest,MessageLoopBugContext)549*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, MessageLoopBugContext)
550*8975f5c5SAndroid Build Coastguard Worker {
551*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42261801
552*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsAndroid());
553*8975f5c5SAndroid Build Coastguard Worker 
554*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42261815
555*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsOzone());
556*8975f5c5SAndroid Build Coastguard Worker 
557*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42264022
558*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsIOS());
559*8975f5c5SAndroid Build Coastguard Worker 
560*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
561*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
562*8975f5c5SAndroid Build Coastguard Worker     initializeAllContexts();
563*8975f5c5SAndroid Build Coastguard Worker 
564*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!mPbufferSurface);
565*8975f5c5SAndroid Build Coastguard Worker     runMessageLoopTest(mPbufferSurface, mSecondContext);
566*8975f5c5SAndroid Build Coastguard Worker }
567*8975f5c5SAndroid Build Coastguard Worker 
568*8975f5c5SAndroid Build Coastguard Worker // Test a bug where calling makeCurrent twice would release the surface
TEST_P(EGLSurfaceTest,MakeCurrentTwice)569*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, MakeCurrentTwice)
570*8975f5c5SAndroid Build Coastguard Worker {
571*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
572*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(false);
573*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
574*8975f5c5SAndroid Build Coastguard Worker 
575*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
576*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
577*8975f5c5SAndroid Build Coastguard Worker 
578*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
579*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
580*8975f5c5SAndroid Build Coastguard Worker 
581*8975f5c5SAndroid Build Coastguard Worker     // Simple operation to test the FBO is set appropriately
582*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
583*8975f5c5SAndroid Build Coastguard Worker }
584*8975f5c5SAndroid Build Coastguard Worker 
585*8975f5c5SAndroid Build Coastguard Worker // Test that we dont crash during a clear when specified scissor is outside render area
586*8975f5c5SAndroid Build Coastguard Worker // due to reducing window size.
TEST_P(EGLSurfaceTest,ShrinkWindowThenScissoredClear)587*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, ShrinkWindowThenScissoredClear)
588*8975f5c5SAndroid Build Coastguard Worker {
589*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
590*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(false);
591*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
592*8975f5c5SAndroid Build Coastguard Worker 
593*8975f5c5SAndroid Build Coastguard Worker     // Create 64x64 window and make it current
594*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
595*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
596*8975f5c5SAndroid Build Coastguard Worker 
597*8975f5c5SAndroid Build Coastguard Worker     // Resize window to 32x32
598*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(32, 32);
599*8975f5c5SAndroid Build Coastguard Worker 
600*8975f5c5SAndroid Build Coastguard Worker     // Perform empty swap
601*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
602*8975f5c5SAndroid Build Coastguard Worker 
603*8975f5c5SAndroid Build Coastguard Worker     // Enable scissor test
604*8975f5c5SAndroid Build Coastguard Worker     glEnable(GL_SCISSOR_TEST);
605*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
606*8975f5c5SAndroid Build Coastguard Worker 
607*8975f5c5SAndroid Build Coastguard Worker     // Set scissor to (50, 50, 10, 10)
608*8975f5c5SAndroid Build Coastguard Worker     glScissor(50, 50, 10, 10);
609*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
610*8975f5c5SAndroid Build Coastguard Worker 
611*8975f5c5SAndroid Build Coastguard Worker     // Clear to specific color
612*8975f5c5SAndroid Build Coastguard Worker     glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
613*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
614*8975f5c5SAndroid Build Coastguard Worker 
615*8975f5c5SAndroid Build Coastguard Worker     // Disable scissor test
616*8975f5c5SAndroid Build Coastguard Worker     glDisable(GL_SCISSOR_TEST);
617*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
618*8975f5c5SAndroid Build Coastguard Worker }
619*8975f5c5SAndroid Build Coastguard Worker 
620*8975f5c5SAndroid Build Coastguard Worker // Test that we dont early return from a clear when specified scissor is outside render area
621*8975f5c5SAndroid Build Coastguard Worker // before increasing window size.
TEST_P(EGLSurfaceTest,GrowWindowThenScissoredClear)622*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, GrowWindowThenScissoredClear)
623*8975f5c5SAndroid Build Coastguard Worker {
624*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
625*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(false);
626*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
627*8975f5c5SAndroid Build Coastguard Worker 
628*8975f5c5SAndroid Build Coastguard Worker     // Create 64x64 window and make it current
629*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
630*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
631*8975f5c5SAndroid Build Coastguard Worker 
632*8975f5c5SAndroid Build Coastguard Worker     // Resize window to 128x128
633*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(128, 128);
634*8975f5c5SAndroid Build Coastguard Worker 
635*8975f5c5SAndroid Build Coastguard Worker     // Perform empty swap
636*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
637*8975f5c5SAndroid Build Coastguard Worker 
638*8975f5c5SAndroid Build Coastguard Worker     // Enable scissor test
639*8975f5c5SAndroid Build Coastguard Worker     glEnable(GL_SCISSOR_TEST);
640*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
641*8975f5c5SAndroid Build Coastguard Worker 
642*8975f5c5SAndroid Build Coastguard Worker     // Set scissor to (64, 64, 10, 10)
643*8975f5c5SAndroid Build Coastguard Worker     glScissor(64, 64, 10, 10);
644*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
645*8975f5c5SAndroid Build Coastguard Worker 
646*8975f5c5SAndroid Build Coastguard Worker     // Clear to specific color
647*8975f5c5SAndroid Build Coastguard Worker     glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
648*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
649*8975f5c5SAndroid Build Coastguard Worker 
650*8975f5c5SAndroid Build Coastguard Worker     // Disable scissor test
651*8975f5c5SAndroid Build Coastguard Worker     glDisable(GL_SCISSOR_TEST);
652*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
653*8975f5c5SAndroid Build Coastguard Worker 
654*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_RECT_EQ(64, 64, 10, 10, GLColor::blue);
655*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
656*8975f5c5SAndroid Build Coastguard Worker }
657*8975f5c5SAndroid Build Coastguard Worker 
658*8975f5c5SAndroid Build Coastguard Worker // Test that just a ClearBuffer* with an invalid scissor doesn't cause an assert.
TEST_P(EGLSurfaceTest3,ShrinkWindowThenScissoredClearBuffer)659*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest3, ShrinkWindowThenScissoredClearBuffer)
660*8975f5c5SAndroid Build Coastguard Worker {
661*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
662*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(false);
663*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
664*8975f5c5SAndroid Build Coastguard Worker 
665*8975f5c5SAndroid Build Coastguard Worker     // Create 64x64 window and make it current
666*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
667*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
668*8975f5c5SAndroid Build Coastguard Worker 
669*8975f5c5SAndroid Build Coastguard Worker     // Resize window to 32x32
670*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(32, 32);
671*8975f5c5SAndroid Build Coastguard Worker 
672*8975f5c5SAndroid Build Coastguard Worker     // Perform empty swap
673*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
674*8975f5c5SAndroid Build Coastguard Worker 
675*8975f5c5SAndroid Build Coastguard Worker     // Enable scissor test
676*8975f5c5SAndroid Build Coastguard Worker     glEnable(GL_SCISSOR_TEST);
677*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
678*8975f5c5SAndroid Build Coastguard Worker 
679*8975f5c5SAndroid Build Coastguard Worker     // Set scissor to (50, 50, 10, 10)
680*8975f5c5SAndroid Build Coastguard Worker     glScissor(50, 50, 10, 10);
681*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
682*8975f5c5SAndroid Build Coastguard Worker 
683*8975f5c5SAndroid Build Coastguard Worker     std::vector<GLint> testInt(4);
684*8975f5c5SAndroid Build Coastguard Worker     glClearBufferiv(GL_COLOR, 0, testInt.data());
685*8975f5c5SAndroid Build Coastguard Worker     std::vector<GLuint> testUint(4);
686*8975f5c5SAndroid Build Coastguard Worker     glClearBufferuiv(GL_COLOR, 0, testUint.data());
687*8975f5c5SAndroid Build Coastguard Worker     std::vector<GLfloat> testFloat(4);
688*8975f5c5SAndroid Build Coastguard Worker     glClearBufferfv(GL_COLOR, 0, testFloat.data());
689*8975f5c5SAndroid Build Coastguard Worker 
690*8975f5c5SAndroid Build Coastguard Worker     // Disable scissor test
691*8975f5c5SAndroid Build Coastguard Worker     glDisable(GL_SCISSOR_TEST);
692*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
693*8975f5c5SAndroid Build Coastguard Worker }
694*8975f5c5SAndroid Build Coastguard Worker 
695*8975f5c5SAndroid Build Coastguard Worker // This is a regression test to verify that surfaces are not prematurely destroyed.
TEST_P(EGLSurfaceTest,SurfaceUseAfterFreeBug)696*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, SurfaceUseAfterFreeBug)
697*8975f5c5SAndroid Build Coastguard Worker {
698*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
699*8975f5c5SAndroid Build Coastguard Worker 
700*8975f5c5SAndroid Build Coastguard Worker     // Initialize an RGBA8 window and pbuffer surface
701*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kSurfaceAttributes[] = {EGL_RED_SIZE,     8,
702*8975f5c5SAndroid Build Coastguard Worker                                              EGL_GREEN_SIZE,   8,
703*8975f5c5SAndroid Build Coastguard Worker                                              EGL_BLUE_SIZE,    8,
704*8975f5c5SAndroid Build Coastguard Worker                                              EGL_ALPHA_SIZE,   8,
705*8975f5c5SAndroid Build Coastguard Worker                                              EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
706*8975f5c5SAndroid Build Coastguard Worker                                              EGL_NONE};
707*8975f5c5SAndroid Build Coastguard Worker 
708*8975f5c5SAndroid Build Coastguard Worker     EGLint configCount      = 0;
709*8975f5c5SAndroid Build Coastguard Worker     EGLConfig surfaceConfig = nullptr;
710*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, kSurfaceAttributes, &surfaceConfig, 1, &configCount));
711*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(configCount, 0);
712*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(surfaceConfig, nullptr);
713*8975f5c5SAndroid Build Coastguard Worker 
714*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(surfaceConfig);
715*8975f5c5SAndroid Build Coastguard Worker     initializeAllContexts();
716*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
717*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
718*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mPbufferSurface, EGL_NO_SURFACE);
719*8975f5c5SAndroid Build Coastguard Worker 
720*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mSecondContext);
721*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
722*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
723*8975f5c5SAndroid Build Coastguard Worker 
724*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mPbufferSurface, mPbufferSurface, mContext);
725*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
726*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
727*8975f5c5SAndroid Build Coastguard Worker 
728*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, mPbufferSurface);
729*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
730*8975f5c5SAndroid Build Coastguard Worker     mPbufferSurface = EGL_NO_SURFACE;
731*8975f5c5SAndroid Build Coastguard Worker 
732*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, mSecondContext);
733*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
734*8975f5c5SAndroid Build Coastguard Worker     mSecondContext = EGL_NO_CONTEXT;
735*8975f5c5SAndroid Build Coastguard Worker }
736*8975f5c5SAndroid Build Coastguard Worker 
737*8975f5c5SAndroid Build Coastguard Worker // Test that the window surface is correctly resized after calling swapBuffers
TEST_P(EGLSurfaceTest,ResizeWindow)738*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, ResizeWindow)
739*8975f5c5SAndroid Build Coastguard Worker {
740*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42263074
741*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
742*8975f5c5SAndroid Build Coastguard Worker     // Flaky on Linux SwANGLE http://anglebug.com/42263074
743*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
744*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42264022
745*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsIOS());
746*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsLinux() && IsARM());
747*8975f5c5SAndroid Build Coastguard Worker 
748*8975f5c5SAndroid Build Coastguard Worker     // Necessary for a window resizing test if there is no per-frame window size query
749*8975f5c5SAndroid Build Coastguard Worker     setWindowVisible(mOSWindow, true);
750*8975f5c5SAndroid Build Coastguard Worker 
751*8975f5c5SAndroid Build Coastguard Worker     GLenum platform               = GetParam().getRenderer();
752*8975f5c5SAndroid Build Coastguard Worker     bool platformSupportsZeroSize = platform == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
753*8975f5c5SAndroid Build Coastguard Worker                                     platform == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE;
754*8975f5c5SAndroid Build Coastguard Worker     int minSize = platformSupportsZeroSize ? 0 : 1;
755*8975f5c5SAndroid Build Coastguard Worker 
756*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
757*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
758*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
759*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
760*8975f5c5SAndroid Build Coastguard Worker 
761*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
762*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
763*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
764*8975f5c5SAndroid Build Coastguard Worker 
765*8975f5c5SAndroid Build Coastguard Worker     EGLint height;
766*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &height);
767*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
768*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(64, height);  // initial size
769*8975f5c5SAndroid Build Coastguard Worker 
770*8975f5c5SAndroid Build Coastguard Worker     // set window's height to 0 (if possible) or 1
771*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(64, minSize);
772*8975f5c5SAndroid Build Coastguard Worker 
773*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
774*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
775*8975f5c5SAndroid Build Coastguard Worker 
776*8975f5c5SAndroid Build Coastguard Worker     // TODO(syoussefi): the GLX implementation still reads the window size as 64x64 through
777*8975f5c5SAndroid Build Coastguard Worker     // XGetGeometry.  http://anglebug.com/42261800
778*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsLinux() && IsOpenGL());
779*8975f5c5SAndroid Build Coastguard Worker 
780*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &height);
781*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
782*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(minSize, height);
783*8975f5c5SAndroid Build Coastguard Worker 
784*8975f5c5SAndroid Build Coastguard Worker     // restore window's height
785*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(64, 64);
786*8975f5c5SAndroid Build Coastguard Worker 
787*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
788*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
789*8975f5c5SAndroid Build Coastguard Worker 
790*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &height);
791*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
792*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(64, height);
793*8975f5c5SAndroid Build Coastguard Worker }
794*8975f5c5SAndroid Build Coastguard Worker 
795*8975f5c5SAndroid Build Coastguard Worker // Test that the backbuffer is correctly resized after calling swapBuffers
TEST_P(EGLSurfaceTest,ResizeWindowWithDraw)796*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, ResizeWindowWithDraw)
797*8975f5c5SAndroid Build Coastguard Worker {
798*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42263074
799*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsLinux());
800*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42264022
801*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsIOS());
802*8975f5c5SAndroid Build Coastguard Worker 
803*8975f5c5SAndroid Build Coastguard Worker     // Necessary for a window resizing test if there is no per-frame window size query
804*8975f5c5SAndroid Build Coastguard Worker     setWindowVisible(mOSWindow, true);
805*8975f5c5SAndroid Build Coastguard Worker 
806*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
807*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
808*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
809*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
810*8975f5c5SAndroid Build Coastguard Worker 
811*8975f5c5SAndroid Build Coastguard Worker     int size      = 64;
812*8975f5c5SAndroid Build Coastguard Worker     EGLint height = 0;
813*8975f5c5SAndroid Build Coastguard Worker     EGLint width  = 0;
814*8975f5c5SAndroid Build Coastguard Worker 
815*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
816*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
817*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
818*8975f5c5SAndroid Build Coastguard Worker 
819*8975f5c5SAndroid Build Coastguard Worker     // Clear to red
820*8975f5c5SAndroid Build Coastguard Worker     glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
821*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
822*8975f5c5SAndroid Build Coastguard Worker 
823*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &height);
824*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_WIDTH, &width);
825*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
826*8975f5c5SAndroid Build Coastguard Worker 
827*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
828*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size - 1, 0, GLColor::red);
829*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size - 1, size - 1, GLColor::red);
830*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, size - 1, GLColor::red);
831*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(-1, -1, GLColor::transparentBlack);
832*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size, 0, GLColor::transparentBlack);
833*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, size, GLColor::transparentBlack);
834*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size, size, GLColor::transparentBlack);
835*8975f5c5SAndroid Build Coastguard Worker 
836*8975f5c5SAndroid Build Coastguard Worker     // set window's size small
837*8975f5c5SAndroid Build Coastguard Worker     size = 1;
838*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(size, size);
839*8975f5c5SAndroid Build Coastguard Worker 
840*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
841*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
842*8975f5c5SAndroid Build Coastguard Worker 
843*8975f5c5SAndroid Build Coastguard Worker     // Clear to green
844*8975f5c5SAndroid Build Coastguard Worker     glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
845*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
846*8975f5c5SAndroid Build Coastguard Worker 
847*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &height);
848*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_WIDTH, &width);
849*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
850*8975f5c5SAndroid Build Coastguard Worker 
851*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
852*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size - 1, 0, GLColor::green);
853*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size - 1, size - 1, GLColor::green);
854*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, size - 1, GLColor::green);
855*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(-1, -1, GLColor::transparentBlack);
856*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size, 0, GLColor::transparentBlack);
857*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, size, GLColor::transparentBlack);
858*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size, size, GLColor::transparentBlack);
859*8975f5c5SAndroid Build Coastguard Worker 
860*8975f5c5SAndroid Build Coastguard Worker     // set window's height large
861*8975f5c5SAndroid Build Coastguard Worker     size = 128;
862*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(size, size);
863*8975f5c5SAndroid Build Coastguard Worker 
864*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
865*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
866*8975f5c5SAndroid Build Coastguard Worker 
867*8975f5c5SAndroid Build Coastguard Worker     // Clear to blue
868*8975f5c5SAndroid Build Coastguard Worker     glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
869*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
870*8975f5c5SAndroid Build Coastguard Worker 
871*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &height);
872*8975f5c5SAndroid Build Coastguard Worker     eglQuerySurface(mDisplay, mWindowSurface, EGL_WIDTH, &width);
873*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
874*8975f5c5SAndroid Build Coastguard Worker 
875*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
876*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size - 1, 0, GLColor::blue);
877*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size - 1, size - 1, GLColor::blue);
878*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, size - 1, GLColor::blue);
879*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(-1, -1, GLColor::transparentBlack);
880*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size, 0, GLColor::transparentBlack);
881*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, size, GLColor::transparentBlack);
882*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(size, size, GLColor::transparentBlack);
883*8975f5c5SAndroid Build Coastguard Worker }
884*8975f5c5SAndroid Build Coastguard Worker 
885*8975f5c5SAndroid Build Coastguard Worker // Test that the window can be reset repeatedly before surface creation.
TEST_P(EGLSurfaceTest,ResetNativeWindow)886*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, ResetNativeWindow)
887*8975f5c5SAndroid Build Coastguard Worker {
888*8975f5c5SAndroid Build Coastguard Worker     setWindowVisible(mOSWindow, true);
889*8975f5c5SAndroid Build Coastguard Worker 
890*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
891*8975f5c5SAndroid Build Coastguard Worker 
892*8975f5c5SAndroid Build Coastguard Worker     for (int i = 0; i < 10; ++i)
893*8975f5c5SAndroid Build Coastguard Worker     {
894*8975f5c5SAndroid Build Coastguard Worker         mOSWindow->resetNativeWindow();
895*8975f5c5SAndroid Build Coastguard Worker     }
896*8975f5c5SAndroid Build Coastguard Worker 
897*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
898*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
899*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
900*8975f5c5SAndroid Build Coastguard Worker 
901*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
902*8975f5c5SAndroid Build Coastguard Worker 
903*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
904*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
905*8975f5c5SAndroid Build Coastguard Worker }
906*8975f5c5SAndroid Build Coastguard Worker 
907*8975f5c5SAndroid Build Coastguard Worker // Test swap buffer without any draw calls.
TEST_P(EGLSurfaceTest,SwapWithoutAnyDraw)908*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, SwapWithoutAnyDraw)
909*8975f5c5SAndroid Build Coastguard Worker {
910*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
911*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
912*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
913*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
914*8975f5c5SAndroid Build Coastguard Worker 
915*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
916*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
917*8975f5c5SAndroid Build Coastguard Worker 
918*8975f5c5SAndroid Build Coastguard Worker     for (int i = 0; i < 10; ++i)
919*8975f5c5SAndroid Build Coastguard Worker     {
920*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, mWindowSurface);
921*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
922*8975f5c5SAndroid Build Coastguard Worker     }
923*8975f5c5SAndroid Build Coastguard Worker }
924*8975f5c5SAndroid Build Coastguard Worker 
925*8975f5c5SAndroid Build Coastguard Worker // Test creating a surface that supports a EGLConfig with 16bit
926*8975f5c5SAndroid Build Coastguard Worker // support GL_RGB565
TEST_P(EGLSurfaceTest,CreateWithEGLConfig5650Support)927*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, CreateWithEGLConfig5650Support)
928*8975f5c5SAndroid Build Coastguard Worker {
929*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {EGL_SURFACE_TYPE,
930*8975f5c5SAndroid Build Coastguard Worker                                        EGL_WINDOW_BIT,
931*8975f5c5SAndroid Build Coastguard Worker                                        EGL_RED_SIZE,
932*8975f5c5SAndroid Build Coastguard Worker                                        5,
933*8975f5c5SAndroid Build Coastguard Worker                                        EGL_GREEN_SIZE,
934*8975f5c5SAndroid Build Coastguard Worker                                        6,
935*8975f5c5SAndroid Build Coastguard Worker                                        EGL_BLUE_SIZE,
936*8975f5c5SAndroid Build Coastguard Worker                                        5,
937*8975f5c5SAndroid Build Coastguard Worker                                        EGL_ALPHA_SIZE,
938*8975f5c5SAndroid Build Coastguard Worker                                        0,
939*8975f5c5SAndroid Build Coastguard Worker                                        EGL_DEPTH_SIZE,
940*8975f5c5SAndroid Build Coastguard Worker                                        0,
941*8975f5c5SAndroid Build Coastguard Worker                                        EGL_STENCIL_SIZE,
942*8975f5c5SAndroid Build Coastguard Worker                                        0,
943*8975f5c5SAndroid Build Coastguard Worker                                        EGL_SAMPLE_BUFFERS,
944*8975f5c5SAndroid Build Coastguard Worker                                        0,
945*8975f5c5SAndroid Build Coastguard Worker                                        EGL_NONE};
946*8975f5c5SAndroid Build Coastguard Worker 
947*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
948*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config;
949*8975f5c5SAndroid Build Coastguard Worker     if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config) == EGL_FALSE)
950*8975f5c5SAndroid Build Coastguard Worker     {
951*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGLConfig for a GL_RGB565 surface is not supported, skipping test"
952*8975f5c5SAndroid Build Coastguard Worker                   << std::endl;
953*8975f5c5SAndroid Build Coastguard Worker         return;
954*8975f5c5SAndroid Build Coastguard Worker     }
955*8975f5c5SAndroid Build Coastguard Worker 
956*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(config);
957*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
958*8975f5c5SAndroid Build Coastguard Worker 
959*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
960*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
961*8975f5c5SAndroid Build Coastguard Worker 
962*8975f5c5SAndroid Build Coastguard Worker     GLuint program = createProgram();
963*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, program);
964*8975f5c5SAndroid Build Coastguard Worker     drawWithProgram(program);
965*8975f5c5SAndroid Build Coastguard Worker     EXPECT_GL_NO_ERROR();
966*8975f5c5SAndroid Build Coastguard Worker     glDeleteProgram(program);
967*8975f5c5SAndroid Build Coastguard Worker }
968*8975f5c5SAndroid Build Coastguard Worker 
969*8975f5c5SAndroid Build Coastguard Worker // Test creating a surface that supports a EGLConfig with 16bit
970*8975f5c5SAndroid Build Coastguard Worker // support GL_RGBA4
TEST_P(EGLSurfaceTest,CreateWithEGLConfig4444Support)971*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, CreateWithEGLConfig4444Support)
972*8975f5c5SAndroid Build Coastguard Worker {
973*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {EGL_SURFACE_TYPE,
974*8975f5c5SAndroid Build Coastguard Worker                                        EGL_WINDOW_BIT,
975*8975f5c5SAndroid Build Coastguard Worker                                        EGL_RED_SIZE,
976*8975f5c5SAndroid Build Coastguard Worker                                        4,
977*8975f5c5SAndroid Build Coastguard Worker                                        EGL_GREEN_SIZE,
978*8975f5c5SAndroid Build Coastguard Worker                                        4,
979*8975f5c5SAndroid Build Coastguard Worker                                        EGL_BLUE_SIZE,
980*8975f5c5SAndroid Build Coastguard Worker                                        4,
981*8975f5c5SAndroid Build Coastguard Worker                                        EGL_ALPHA_SIZE,
982*8975f5c5SAndroid Build Coastguard Worker                                        4,
983*8975f5c5SAndroid Build Coastguard Worker                                        EGL_DEPTH_SIZE,
984*8975f5c5SAndroid Build Coastguard Worker                                        0,
985*8975f5c5SAndroid Build Coastguard Worker                                        EGL_STENCIL_SIZE,
986*8975f5c5SAndroid Build Coastguard Worker                                        0,
987*8975f5c5SAndroid Build Coastguard Worker                                        EGL_SAMPLE_BUFFERS,
988*8975f5c5SAndroid Build Coastguard Worker                                        0,
989*8975f5c5SAndroid Build Coastguard Worker                                        EGL_NONE};
990*8975f5c5SAndroid Build Coastguard Worker 
991*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
992*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config;
993*8975f5c5SAndroid Build Coastguard Worker     if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config) == EGL_FALSE)
994*8975f5c5SAndroid Build Coastguard Worker     {
995*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGLConfig for a GL_RGBA4 surface is not supported, skipping test"
996*8975f5c5SAndroid Build Coastguard Worker                   << std::endl;
997*8975f5c5SAndroid Build Coastguard Worker         return;
998*8975f5c5SAndroid Build Coastguard Worker     }
999*8975f5c5SAndroid Build Coastguard Worker 
1000*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(config);
1001*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1002*8975f5c5SAndroid Build Coastguard Worker 
1003*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1004*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1005*8975f5c5SAndroid Build Coastguard Worker 
1006*8975f5c5SAndroid Build Coastguard Worker     GLuint program = createProgram();
1007*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, program);
1008*8975f5c5SAndroid Build Coastguard Worker     drawWithProgram(program);
1009*8975f5c5SAndroid Build Coastguard Worker     EXPECT_GL_NO_ERROR();
1010*8975f5c5SAndroid Build Coastguard Worker     glDeleteProgram(program);
1011*8975f5c5SAndroid Build Coastguard Worker }
1012*8975f5c5SAndroid Build Coastguard Worker 
1013*8975f5c5SAndroid Build Coastguard Worker // Test creating a surface that supports a EGLConfig with 16bit
1014*8975f5c5SAndroid Build Coastguard Worker // support GL_RGB5_A1
TEST_P(EGLSurfaceTest,CreateWithEGLConfig5551Support)1015*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, CreateWithEGLConfig5551Support)
1016*8975f5c5SAndroid Build Coastguard Worker {
1017*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {EGL_SURFACE_TYPE,
1018*8975f5c5SAndroid Build Coastguard Worker                                        EGL_WINDOW_BIT,
1019*8975f5c5SAndroid Build Coastguard Worker                                        EGL_RED_SIZE,
1020*8975f5c5SAndroid Build Coastguard Worker                                        5,
1021*8975f5c5SAndroid Build Coastguard Worker                                        EGL_GREEN_SIZE,
1022*8975f5c5SAndroid Build Coastguard Worker                                        5,
1023*8975f5c5SAndroid Build Coastguard Worker                                        EGL_BLUE_SIZE,
1024*8975f5c5SAndroid Build Coastguard Worker                                        5,
1025*8975f5c5SAndroid Build Coastguard Worker                                        EGL_ALPHA_SIZE,
1026*8975f5c5SAndroid Build Coastguard Worker                                        1,
1027*8975f5c5SAndroid Build Coastguard Worker                                        EGL_DEPTH_SIZE,
1028*8975f5c5SAndroid Build Coastguard Worker                                        0,
1029*8975f5c5SAndroid Build Coastguard Worker                                        EGL_STENCIL_SIZE,
1030*8975f5c5SAndroid Build Coastguard Worker                                        0,
1031*8975f5c5SAndroid Build Coastguard Worker                                        EGL_SAMPLE_BUFFERS,
1032*8975f5c5SAndroid Build Coastguard Worker                                        0,
1033*8975f5c5SAndroid Build Coastguard Worker                                        EGL_NONE};
1034*8975f5c5SAndroid Build Coastguard Worker 
1035*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1036*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config;
1037*8975f5c5SAndroid Build Coastguard Worker     if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config) == EGL_FALSE)
1038*8975f5c5SAndroid Build Coastguard Worker     {
1039*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGLConfig for a GL_RGB5_A1 surface is not supported, skipping test"
1040*8975f5c5SAndroid Build Coastguard Worker                   << std::endl;
1041*8975f5c5SAndroid Build Coastguard Worker         return;
1042*8975f5c5SAndroid Build Coastguard Worker     }
1043*8975f5c5SAndroid Build Coastguard Worker 
1044*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(config);
1045*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1046*8975f5c5SAndroid Build Coastguard Worker 
1047*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1048*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1049*8975f5c5SAndroid Build Coastguard Worker 
1050*8975f5c5SAndroid Build Coastguard Worker     GLuint program = createProgram();
1051*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, program);
1052*8975f5c5SAndroid Build Coastguard Worker     drawWithProgram(program);
1053*8975f5c5SAndroid Build Coastguard Worker     EXPECT_GL_NO_ERROR();
1054*8975f5c5SAndroid Build Coastguard Worker     glDeleteProgram(program);
1055*8975f5c5SAndroid Build Coastguard Worker }
1056*8975f5c5SAndroid Build Coastguard Worker 
1057*8975f5c5SAndroid Build Coastguard Worker // Test creating a surface that supports a EGLConfig without alpha support
TEST_P(EGLSurfaceTest,CreateWithEGLConfig8880Support)1058*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, CreateWithEGLConfig8880Support)
1059*8975f5c5SAndroid Build Coastguard Worker {
1060*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {EGL_SURFACE_TYPE,
1061*8975f5c5SAndroid Build Coastguard Worker                                        EGL_WINDOW_BIT,
1062*8975f5c5SAndroid Build Coastguard Worker                                        EGL_RED_SIZE,
1063*8975f5c5SAndroid Build Coastguard Worker                                        8,
1064*8975f5c5SAndroid Build Coastguard Worker                                        EGL_GREEN_SIZE,
1065*8975f5c5SAndroid Build Coastguard Worker                                        8,
1066*8975f5c5SAndroid Build Coastguard Worker                                        EGL_BLUE_SIZE,
1067*8975f5c5SAndroid Build Coastguard Worker                                        8,
1068*8975f5c5SAndroid Build Coastguard Worker                                        EGL_ALPHA_SIZE,
1069*8975f5c5SAndroid Build Coastguard Worker                                        0,
1070*8975f5c5SAndroid Build Coastguard Worker                                        EGL_DEPTH_SIZE,
1071*8975f5c5SAndroid Build Coastguard Worker                                        0,
1072*8975f5c5SAndroid Build Coastguard Worker                                        EGL_STENCIL_SIZE,
1073*8975f5c5SAndroid Build Coastguard Worker                                        0,
1074*8975f5c5SAndroid Build Coastguard Worker                                        EGL_SAMPLE_BUFFERS,
1075*8975f5c5SAndroid Build Coastguard Worker                                        0,
1076*8975f5c5SAndroid Build Coastguard Worker                                        EGL_NONE};
1077*8975f5c5SAndroid Build Coastguard Worker 
1078*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1079*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config;
1080*8975f5c5SAndroid Build Coastguard Worker     if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config) == EGL_FALSE)
1081*8975f5c5SAndroid Build Coastguard Worker     {
1082*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGLConfig for a GL_RGB8_OES surface is not supported, skipping test"
1083*8975f5c5SAndroid Build Coastguard Worker                   << std::endl;
1084*8975f5c5SAndroid Build Coastguard Worker         return;
1085*8975f5c5SAndroid Build Coastguard Worker     }
1086*8975f5c5SAndroid Build Coastguard Worker 
1087*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(config);
1088*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1089*8975f5c5SAndroid Build Coastguard Worker 
1090*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1091*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1092*8975f5c5SAndroid Build Coastguard Worker 
1093*8975f5c5SAndroid Build Coastguard Worker     GLuint program = createProgram();
1094*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, program);
1095*8975f5c5SAndroid Build Coastguard Worker     drawWithProgram(program);
1096*8975f5c5SAndroid Build Coastguard Worker     EXPECT_GL_NO_ERROR();
1097*8975f5c5SAndroid Build Coastguard Worker     glDeleteProgram(program);
1098*8975f5c5SAndroid Build Coastguard Worker }
1099*8975f5c5SAndroid Build Coastguard Worker 
1100*8975f5c5SAndroid Build Coastguard Worker // Test creating a surface that supports GL_RGB10_A2 with BT2020 colorspaces
TEST_P(EGLSurfaceTest,CreateWithEGLConfig1010102Support)1101*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, CreateWithEGLConfig1010102Support)
1102*8975f5c5SAndroid Build Coastguard Worker {
1103*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {EGL_SURFACE_TYPE,
1104*8975f5c5SAndroid Build Coastguard Worker                                        EGL_WINDOW_BIT,
1105*8975f5c5SAndroid Build Coastguard Worker                                        EGL_RED_SIZE,
1106*8975f5c5SAndroid Build Coastguard Worker                                        10,
1107*8975f5c5SAndroid Build Coastguard Worker                                        EGL_GREEN_SIZE,
1108*8975f5c5SAndroid Build Coastguard Worker                                        10,
1109*8975f5c5SAndroid Build Coastguard Worker                                        EGL_BLUE_SIZE,
1110*8975f5c5SAndroid Build Coastguard Worker                                        10,
1111*8975f5c5SAndroid Build Coastguard Worker                                        EGL_ALPHA_SIZE,
1112*8975f5c5SAndroid Build Coastguard Worker                                        2,
1113*8975f5c5SAndroid Build Coastguard Worker                                        EGL_DEPTH_SIZE,
1114*8975f5c5SAndroid Build Coastguard Worker                                        0,
1115*8975f5c5SAndroid Build Coastguard Worker                                        EGL_STENCIL_SIZE,
1116*8975f5c5SAndroid Build Coastguard Worker                                        0,
1117*8975f5c5SAndroid Build Coastguard Worker                                        EGL_SAMPLE_BUFFERS,
1118*8975f5c5SAndroid Build Coastguard Worker                                        0,
1119*8975f5c5SAndroid Build Coastguard Worker                                        EGL_NONE};
1120*8975f5c5SAndroid Build Coastguard Worker 
1121*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1122*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
1123*8975f5c5SAndroid Build Coastguard Worker 
1124*8975f5c5SAndroid Build Coastguard Worker     if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &mConfig) == EGL_FALSE)
1125*8975f5c5SAndroid Build Coastguard Worker     {
1126*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGLConfig for a GL_RGB10_A2 surface is not supported, skipping test"
1127*8975f5c5SAndroid Build Coastguard Worker                   << std::endl;
1128*8975f5c5SAndroid Build Coastguard Worker         return;
1129*8975f5c5SAndroid Build Coastguard Worker     }
1130*8975f5c5SAndroid Build Coastguard Worker 
1131*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_gl_colorspace_bt2020_hlg"));
1132*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(
1133*8975f5c5SAndroid Build Coastguard Worker         !IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_gl_colorspace_bt2020_linear"));
1134*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_gl_colorspace_bt2020_pq"));
1135*8975f5c5SAndroid Build Coastguard Worker 
1136*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1137*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mContext, EGL_NO_CONTEXT);
1138*8975f5c5SAndroid Build Coastguard Worker 
1139*8975f5c5SAndroid Build Coastguard Worker     constexpr std::array<EGLint, 3u> kBt2020Colorspaces = {EGL_GL_COLORSPACE_BT2020_HLG_EXT,
1140*8975f5c5SAndroid Build Coastguard Worker                                                            EGL_GL_COLORSPACE_BT2020_LINEAR_EXT,
1141*8975f5c5SAndroid Build Coastguard Worker                                                            EGL_GL_COLORSPACE_BT2020_PQ_EXT};
1142*8975f5c5SAndroid Build Coastguard Worker     for (EGLint bt2020Colorspace : kBt2020Colorspaces)
1143*8975f5c5SAndroid Build Coastguard Worker     {
1144*8975f5c5SAndroid Build Coastguard Worker         std::vector<EGLint> winSurfaceAttribs;
1145*8975f5c5SAndroid Build Coastguard Worker         winSurfaceAttribs.push_back(EGL_GL_COLORSPACE_KHR);
1146*8975f5c5SAndroid Build Coastguard Worker         winSurfaceAttribs.push_back(bt2020Colorspace);
1147*8975f5c5SAndroid Build Coastguard Worker 
1148*8975f5c5SAndroid Build Coastguard Worker         initializeWindowSurfaceWithAttribs(mConfig, winSurfaceAttribs, EGL_SUCCESS);
1149*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1150*8975f5c5SAndroid Build Coastguard Worker         ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
1151*8975f5c5SAndroid Build Coastguard Worker 
1152*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext));
1153*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1154*8975f5c5SAndroid Build Coastguard Worker 
1155*8975f5c5SAndroid Build Coastguard Worker         GLuint program = createProgram();
1156*8975f5c5SAndroid Build Coastguard Worker         ASSERT_NE(0u, program);
1157*8975f5c5SAndroid Build Coastguard Worker         drawWithProgram(program);
1158*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1159*8975f5c5SAndroid Build Coastguard Worker         glDeleteProgram(program);
1160*8975f5c5SAndroid Build Coastguard Worker 
1161*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
1162*8975f5c5SAndroid Build Coastguard Worker         eglDestroySurface(mDisplay, mWindowSurface);
1163*8975f5c5SAndroid Build Coastguard Worker         mWindowSurface = EGL_NO_SURFACE;
1164*8975f5c5SAndroid Build Coastguard Worker     }
1165*8975f5c5SAndroid Build Coastguard Worker }
1166*8975f5c5SAndroid Build Coastguard Worker 
TEST_P(EGLSurfaceTest,FixedSizeWindow)1167*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, FixedSizeWindow)
1168*8975f5c5SAndroid Build Coastguard Worker {
1169*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {EGL_SURFACE_TYPE,
1170*8975f5c5SAndroid Build Coastguard Worker                                        EGL_WINDOW_BIT,
1171*8975f5c5SAndroid Build Coastguard Worker                                        EGL_RED_SIZE,
1172*8975f5c5SAndroid Build Coastguard Worker                                        8,
1173*8975f5c5SAndroid Build Coastguard Worker                                        EGL_GREEN_SIZE,
1174*8975f5c5SAndroid Build Coastguard Worker                                        8,
1175*8975f5c5SAndroid Build Coastguard Worker                                        EGL_BLUE_SIZE,
1176*8975f5c5SAndroid Build Coastguard Worker                                        8,
1177*8975f5c5SAndroid Build Coastguard Worker                                        EGL_ALPHA_SIZE,
1178*8975f5c5SAndroid Build Coastguard Worker                                        0,
1179*8975f5c5SAndroid Build Coastguard Worker                                        EGL_DEPTH_SIZE,
1180*8975f5c5SAndroid Build Coastguard Worker                                        0,
1181*8975f5c5SAndroid Build Coastguard Worker                                        EGL_STENCIL_SIZE,
1182*8975f5c5SAndroid Build Coastguard Worker                                        0,
1183*8975f5c5SAndroid Build Coastguard Worker                                        EGL_SAMPLE_BUFFERS,
1184*8975f5c5SAndroid Build Coastguard Worker                                        0,
1185*8975f5c5SAndroid Build Coastguard Worker                                        EGL_NONE};
1186*8975f5c5SAndroid Build Coastguard Worker 
1187*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1188*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(EGLWindow::FindEGLConfig(mDisplay, configAttributes, &mConfig) == EGL_FALSE);
1189*8975f5c5SAndroid Build Coastguard Worker 
1190*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_window_fixed_size"));
1191*8975f5c5SAndroid Build Coastguard Worker 
1192*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kInitialSize = 64;
1193*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kUpdateSize  = 32;
1194*8975f5c5SAndroid Build Coastguard Worker 
1195*8975f5c5SAndroid Build Coastguard Worker     EGLint surfaceAttributes[] = {
1196*8975f5c5SAndroid Build Coastguard Worker         EGL_FIXED_SIZE_ANGLE, EGL_TRUE, EGL_WIDTH, kInitialSize, EGL_HEIGHT, kInitialSize, EGL_NONE,
1197*8975f5c5SAndroid Build Coastguard Worker     };
1198*8975f5c5SAndroid Build Coastguard Worker 
1199*8975f5c5SAndroid Build Coastguard Worker     // Create first window surface
1200*8975f5c5SAndroid Build Coastguard Worker     mWindowSurface =
1201*8975f5c5SAndroid Build Coastguard Worker         eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(), surfaceAttributes);
1202*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1203*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(EGL_NO_SURFACE, mWindowSurface);
1204*8975f5c5SAndroid Build Coastguard Worker 
1205*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1206*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext));
1207*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1208*8975f5c5SAndroid Build Coastguard Worker 
1209*8975f5c5SAndroid Build Coastguard Worker     EGLint queryIsFixedSize = 0;
1210*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
1211*8975f5c5SAndroid Build Coastguard Worker         eglQuerySurface(mDisplay, mWindowSurface, EGL_FIXED_SIZE_ANGLE, &queryIsFixedSize));
1212*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1213*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(queryIsFixedSize);
1214*8975f5c5SAndroid Build Coastguard Worker 
1215*8975f5c5SAndroid Build Coastguard Worker     EGLint queryWidth = 0;
1216*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglQuerySurface(mDisplay, mWindowSurface, EGL_WIDTH, &queryWidth));
1217*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1218*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EQ(kInitialSize, queryWidth);
1219*8975f5c5SAndroid Build Coastguard Worker 
1220*8975f5c5SAndroid Build Coastguard Worker     EGLint queryHeight = 0;
1221*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &queryHeight));
1222*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1223*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EQ(kInitialSize, queryHeight);
1224*8975f5c5SAndroid Build Coastguard Worker 
1225*8975f5c5SAndroid Build Coastguard Worker     // Update the size
1226*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglSurfaceAttrib(mDisplay, mWindowSurface, EGL_WIDTH, kUpdateSize));
1227*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1228*8975f5c5SAndroid Build Coastguard Worker 
1229*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglWaitNative(EGL_CORE_NATIVE_ENGINE));
1230*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1231*8975f5c5SAndroid Build Coastguard Worker 
1232*8975f5c5SAndroid Build Coastguard Worker     EGLint queryUpdatedWidth = 0;
1233*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglQuerySurface(mDisplay, mWindowSurface, EGL_WIDTH, &queryUpdatedWidth));
1234*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1235*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EQ(kUpdateSize, queryUpdatedWidth);
1236*8975f5c5SAndroid Build Coastguard Worker }
1237*8975f5c5SAndroid Build Coastguard Worker 
TEST_P(EGLSurfaceTest3,MakeCurrentDifferentSurfaces)1238*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest3, MakeCurrentDifferentSurfaces)
1239*8975f5c5SAndroid Build Coastguard Worker {
1240*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {
1241*8975f5c5SAndroid Build Coastguard Worker         EGL_RED_SIZE,   8, EGL_GREEN_SIZE,   8, EGL_BLUE_SIZE,      8, EGL_ALPHA_SIZE, 8,
1242*8975f5c5SAndroid Build Coastguard Worker         EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_SAMPLE_BUFFERS, 0, EGL_NONE};
1243*8975f5c5SAndroid Build Coastguard Worker     EGLSurface firstPbufferSurface;
1244*8975f5c5SAndroid Build Coastguard Worker     EGLSurface secondPbufferSurface;
1245*8975f5c5SAndroid Build Coastguard Worker 
1246*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1247*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(EGLWindow::FindEGLConfig(mDisplay, configAttributes, &mConfig) == EGL_FALSE);
1248*8975f5c5SAndroid Build Coastguard Worker 
1249*8975f5c5SAndroid Build Coastguard Worker     EGLint surfaceType = 0;
1250*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);
1251*8975f5c5SAndroid Build Coastguard Worker     bool supportsPbuffers    = (surfaceType & EGL_PBUFFER_BIT) != 0;
1252*8975f5c5SAndroid Build Coastguard Worker     EGLint bindToTextureRGBA = 0;
1253*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(mDisplay, mConfig, EGL_BIND_TO_TEXTURE_RGBA, &bindToTextureRGBA);
1254*8975f5c5SAndroid Build Coastguard Worker     bool supportsBindTexImage = (bindToTextureRGBA == EGL_TRUE);
1255*8975f5c5SAndroid Build Coastguard Worker 
1256*8975f5c5SAndroid Build Coastguard Worker     const EGLint pBufferAttributes[] = {
1257*8975f5c5SAndroid Build Coastguard Worker         EGL_WIDTH,          64,
1258*8975f5c5SAndroid Build Coastguard Worker         EGL_HEIGHT,         64,
1259*8975f5c5SAndroid Build Coastguard Worker         EGL_TEXTURE_FORMAT, supportsPbuffers ? EGL_TEXTURE_RGBA : EGL_NO_TEXTURE,
1260*8975f5c5SAndroid Build Coastguard Worker         EGL_TEXTURE_TARGET, supportsBindTexImage ? EGL_TEXTURE_2D : EGL_NO_TEXTURE,
1261*8975f5c5SAndroid Build Coastguard Worker         EGL_NONE,           EGL_NONE,
1262*8975f5c5SAndroid Build Coastguard Worker     };
1263*8975f5c5SAndroid Build Coastguard Worker 
1264*8975f5c5SAndroid Build Coastguard Worker     // Create the surfaces
1265*8975f5c5SAndroid Build Coastguard Worker     firstPbufferSurface = eglCreatePbufferSurface(mDisplay, mConfig, pBufferAttributes);
1266*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1267*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(EGL_NO_SURFACE, firstPbufferSurface);
1268*8975f5c5SAndroid Build Coastguard Worker     secondPbufferSurface = eglCreatePbufferSurface(mDisplay, mConfig, pBufferAttributes);
1269*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1270*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(EGL_NO_SURFACE, secondPbufferSurface);
1271*8975f5c5SAndroid Build Coastguard Worker 
1272*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1273*8975f5c5SAndroid Build Coastguard Worker 
1274*8975f5c5SAndroid Build Coastguard Worker     // Use the same surface for both draw and read
1275*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, firstPbufferSurface, firstPbufferSurface, mContext));
1276*8975f5c5SAndroid Build Coastguard Worker 
1277*8975f5c5SAndroid Build Coastguard Worker     // TODO(http://anglebug.com/42264803): Failing with OpenGL ES backend on Android.
1278*8975f5c5SAndroid Build Coastguard Worker     // Must be after the eglMakeCurrent() so the renderer string is initialized.
1279*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsOpenGLES() && IsAndroid());
1280*8975f5c5SAndroid Build Coastguard Worker 
1281*8975f5c5SAndroid Build Coastguard Worker     glClearColor(kFloatRed.R, kFloatRed.G, kFloatRed.B, kFloatRed.A);
1282*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
1283*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1284*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1285*8975f5c5SAndroid Build Coastguard Worker 
1286*8975f5c5SAndroid Build Coastguard Worker     // Use different surfaces for draw and read, read should stay the same
1287*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, secondPbufferSurface, firstPbufferSurface, mContext));
1288*8975f5c5SAndroid Build Coastguard Worker     glClearColor(kFloatBlue.R, kFloatBlue.G, kFloatBlue.B, kFloatBlue.A);
1289*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
1290*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1291*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1292*8975f5c5SAndroid Build Coastguard Worker     // Verify draw surface was cleared
1293*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, secondPbufferSurface, secondPbufferSurface, mContext));
1294*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1295*8975f5c5SAndroid Build Coastguard Worker 
1296*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, firstPbufferSurface, secondPbufferSurface, mContext));
1297*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1298*8975f5c5SAndroid Build Coastguard Worker 
1299*8975f5c5SAndroid Build Coastguard Worker     // Blit the source surface to the destination surface
1300*8975f5c5SAndroid Build Coastguard Worker     glBlitFramebuffer(0, 0, 64, 64, 0, 0, 64, 64, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1301*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1302*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, firstPbufferSurface, firstPbufferSurface, mContext));
1303*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1304*8975f5c5SAndroid Build Coastguard Worker }
1305*8975f5c5SAndroid Build Coastguard Worker 
1306*8975f5c5SAndroid Build Coastguard Worker #if defined(ANGLE_ENABLE_D3D11)
1307*8975f5c5SAndroid Build Coastguard Worker class EGLSurfaceTestD3D11 : public EGLSurfaceTest
1308*8975f5c5SAndroid Build Coastguard Worker {
1309*8975f5c5SAndroid Build Coastguard Worker   protected:
1310*8975f5c5SAndroid Build Coastguard Worker     // offset - draw into the texture at offset (|offset|, |offset|)
1311*8975f5c5SAndroid Build Coastguard Worker     // pix25 - the expected pixel value at (25, 25)
1312*8975f5c5SAndroid Build Coastguard Worker     // pix75 - the expected pixel value at (75, 75)
testTextureOffset(int offset,UINT pix25,UINT pix75)1313*8975f5c5SAndroid Build Coastguard Worker     void testTextureOffset(int offset, UINT pix25, UINT pix75)
1314*8975f5c5SAndroid Build Coastguard Worker     {
1315*8975f5c5SAndroid Build Coastguard Worker         initializeDisplay();
1316*8975f5c5SAndroid Build Coastguard Worker 
1317*8975f5c5SAndroid Build Coastguard Worker         const EGLint configAttributes[] = {
1318*8975f5c5SAndroid Build Coastguard Worker             EGL_RED_SIZE,   8, EGL_GREEN_SIZE,   8, EGL_BLUE_SIZE,      8, EGL_ALPHA_SIZE, 8,
1319*8975f5c5SAndroid Build Coastguard Worker             EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_SAMPLE_BUFFERS, 0, EGL_NONE};
1320*8975f5c5SAndroid Build Coastguard Worker 
1321*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config;
1322*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_TRUE(EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config));
1323*8975f5c5SAndroid Build Coastguard Worker 
1324*8975f5c5SAndroid Build Coastguard Worker         mConfig = config;
1325*8975f5c5SAndroid Build Coastguard Worker         initializeMainContext();
1326*8975f5c5SAndroid Build Coastguard Worker 
1327*8975f5c5SAndroid Build Coastguard Worker         EGLAttrib device       = 0;
1328*8975f5c5SAndroid Build Coastguard Worker         EGLAttrib newEglDevice = 0;
1329*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_TRUE(eglQueryDisplayAttribEXT(mDisplay, EGL_DEVICE_EXT, &newEglDevice));
1330*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_TRUE(eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(newEglDevice),
1331*8975f5c5SAndroid Build Coastguard Worker                                                 EGL_D3D11_DEVICE_ANGLE, &device));
1332*8975f5c5SAndroid Build Coastguard Worker         angle::ComPtr<ID3D11Device> d3d11Device(reinterpret_cast<ID3D11Device *>(device));
1333*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(!!d3d11Device);
1334*8975f5c5SAndroid Build Coastguard Worker 
1335*8975f5c5SAndroid Build Coastguard Worker         constexpr UINT kTextureWidth  = 100;
1336*8975f5c5SAndroid Build Coastguard Worker         constexpr UINT kTextureHeight = 100;
1337*8975f5c5SAndroid Build Coastguard Worker         constexpr Color<uint8_t> kOpaqueBlack(0, 0, 0, 255);
1338*8975f5c5SAndroid Build Coastguard Worker         std::vector<Color<uint8_t>> textureData(kTextureWidth * kTextureHeight, kOpaqueBlack);
1339*8975f5c5SAndroid Build Coastguard Worker 
1340*8975f5c5SAndroid Build Coastguard Worker         D3D11_SUBRESOURCE_DATA initialData = {};
1341*8975f5c5SAndroid Build Coastguard Worker         initialData.pSysMem                = textureData.data();
1342*8975f5c5SAndroid Build Coastguard Worker         initialData.SysMemPitch            = kTextureWidth * sizeof(kOpaqueBlack);
1343*8975f5c5SAndroid Build Coastguard Worker 
1344*8975f5c5SAndroid Build Coastguard Worker         D3D11_TEXTURE2D_DESC desc = {};
1345*8975f5c5SAndroid Build Coastguard Worker         desc.Format               = DXGI_FORMAT_B8G8R8A8_UNORM;
1346*8975f5c5SAndroid Build Coastguard Worker         desc.Width                = kTextureWidth;
1347*8975f5c5SAndroid Build Coastguard Worker         desc.Height               = kTextureHeight;
1348*8975f5c5SAndroid Build Coastguard Worker         desc.ArraySize            = 1;
1349*8975f5c5SAndroid Build Coastguard Worker         desc.MipLevels            = 1;
1350*8975f5c5SAndroid Build Coastguard Worker         desc.SampleDesc.Count     = 1;
1351*8975f5c5SAndroid Build Coastguard Worker         desc.Usage                = D3D11_USAGE_DEFAULT;
1352*8975f5c5SAndroid Build Coastguard Worker         desc.BindFlags            = D3D11_BIND_RENDER_TARGET;
1353*8975f5c5SAndroid Build Coastguard Worker         angle::ComPtr<ID3D11Texture2D> texture;
1354*8975f5c5SAndroid Build Coastguard Worker         HRESULT hr = d3d11Device->CreateTexture2D(&desc, &initialData, &texture);
1355*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(SUCCEEDED(hr));
1356*8975f5c5SAndroid Build Coastguard Worker 
1357*8975f5c5SAndroid Build Coastguard Worker         angle::ComPtr<ID3D11DeviceContext> d3d11Context;
1358*8975f5c5SAndroid Build Coastguard Worker         d3d11Device->GetImmediateContext(&d3d11Context);
1359*8975f5c5SAndroid Build Coastguard Worker 
1360*8975f5c5SAndroid Build Coastguard Worker         // Specify a texture offset of (50, 50) when rendering to the pbuffer surface.
1361*8975f5c5SAndroid Build Coastguard Worker         const EGLint surfaceAttributes[] = {EGL_WIDTH,
1362*8975f5c5SAndroid Build Coastguard Worker                                             kTextureWidth,
1363*8975f5c5SAndroid Build Coastguard Worker                                             EGL_HEIGHT,
1364*8975f5c5SAndroid Build Coastguard Worker                                             kTextureHeight,
1365*8975f5c5SAndroid Build Coastguard Worker                                             EGL_TEXTURE_OFFSET_X_ANGLE,
1366*8975f5c5SAndroid Build Coastguard Worker                                             offset,
1367*8975f5c5SAndroid Build Coastguard Worker                                             EGL_TEXTURE_OFFSET_Y_ANGLE,
1368*8975f5c5SAndroid Build Coastguard Worker                                             offset,
1369*8975f5c5SAndroid Build Coastguard Worker                                             EGL_NONE};
1370*8975f5c5SAndroid Build Coastguard Worker         EGLClientBuffer buffer           = reinterpret_cast<EGLClientBuffer>(texture.Get());
1371*8975f5c5SAndroid Build Coastguard Worker         mPbufferSurface = eglCreatePbufferFromClientBuffer(mDisplay, EGL_D3D_TEXTURE_ANGLE, buffer,
1372*8975f5c5SAndroid Build Coastguard Worker                                                            config, surfaceAttributes);
1373*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1374*8975f5c5SAndroid Build Coastguard Worker 
1375*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, mPbufferSurface, mPbufferSurface, mContext);
1376*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1377*8975f5c5SAndroid Build Coastguard Worker 
1378*8975f5c5SAndroid Build Coastguard Worker         // glClear should only clear subrect at offset (50, 50) without explicit scissor.
1379*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0, 0, 1, 1);  // Blue
1380*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
1381*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(25, 25, 0, 0, pix25, 255);
1382*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(75, 75, 0, 0, pix75, 255);
1383*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1384*8975f5c5SAndroid Build Coastguard Worker 
1385*8975f5c5SAndroid Build Coastguard Worker         // Drawing with a shader should also update the same subrect only without explicit viewport.
1386*8975f5c5SAndroid Build Coastguard Worker         GLuint program = createProgram();  // Red
1387*8975f5c5SAndroid Build Coastguard Worker         ASSERT_NE(0u, program);
1388*8975f5c5SAndroid Build Coastguard Worker         GLint positionLocation =
1389*8975f5c5SAndroid Build Coastguard Worker             glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib());
1390*8975f5c5SAndroid Build Coastguard Worker         glUseProgram(program);
1391*8975f5c5SAndroid Build Coastguard Worker         const GLfloat vertices[] = {
1392*8975f5c5SAndroid Build Coastguard Worker             -1.0f, 1.0f, 0.5f, -1.0f, -1.0f, 0.5f, 1.0f, -1.0f, 0.5f,
1393*8975f5c5SAndroid Build Coastguard Worker             -1.0f, 1.0f, 0.5f, 1.0f,  -1.0f, 0.5f, 1.0f, 1.0f,  0.5f,
1394*8975f5c5SAndroid Build Coastguard Worker         };
1395*8975f5c5SAndroid Build Coastguard Worker         glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
1396*8975f5c5SAndroid Build Coastguard Worker         glEnableVertexAttribArray(positionLocation);
1397*8975f5c5SAndroid Build Coastguard Worker         glDrawArrays(GL_TRIANGLES, 0, 6);
1398*8975f5c5SAndroid Build Coastguard Worker         glDisableVertexAttribArray(positionLocation);
1399*8975f5c5SAndroid Build Coastguard Worker         glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
1400*8975f5c5SAndroid Build Coastguard Worker 
1401*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(25, 25, pix25, 0, 0, 255);
1402*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(75, 75, pix75, 0, 0, 255);
1403*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1404*8975f5c5SAndroid Build Coastguard Worker 
1405*8975f5c5SAndroid Build Coastguard Worker         glDeleteProgram(program);
1406*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1407*8975f5c5SAndroid Build Coastguard Worker 
1408*8975f5c5SAndroid Build Coastguard Worker         // Blit framebuffer should also blit to the same subrect despite the dstX/Y arguments.
1409*8975f5c5SAndroid Build Coastguard Worker         GLRenderbuffer renderBuffer;
1410*8975f5c5SAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
1411*8975f5c5SAndroid Build Coastguard Worker         glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 50, 50);
1412*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1413*8975f5c5SAndroid Build Coastguard Worker 
1414*8975f5c5SAndroid Build Coastguard Worker         GLFramebuffer framebuffer;
1415*8975f5c5SAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1416*8975f5c5SAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
1417*8975f5c5SAndroid Build Coastguard Worker                                   renderBuffer);
1418*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1419*8975f5c5SAndroid Build Coastguard Worker 
1420*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0, 1, 0, 1);  // Green
1421*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
1422*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(25, 25, 0, 255, 0, 255);
1423*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1424*8975f5c5SAndroid Build Coastguard Worker 
1425*8975f5c5SAndroid Build Coastguard Worker         glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0u);
1426*8975f5c5SAndroid Build Coastguard Worker         glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
1427*8975f5c5SAndroid Build Coastguard Worker         glBlitFramebuffer(0, 0, 50, 50, 0, 0, kTextureWidth, kTextureWidth, GL_COLOR_BUFFER_BIT,
1428*8975f5c5SAndroid Build Coastguard Worker                           GL_NEAREST);
1429*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1430*8975f5c5SAndroid Build Coastguard Worker 
1431*8975f5c5SAndroid Build Coastguard Worker         glBindFramebuffer(GL_READ_FRAMEBUFFER, 0u);
1432*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(25, 25, 0, pix25, 0, 255);
1433*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_EQ(75, 75, 0, pix75, 0, 255);
1434*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1435*8975f5c5SAndroid Build Coastguard Worker     }
1436*8975f5c5SAndroid Build Coastguard Worker 
1437*8975f5c5SAndroid Build Coastguard Worker     // Draws into a surface at the specified offset using the values of gl_FragCoord in the
1438*8975f5c5SAndroid Build Coastguard Worker     // fragment shader.
1439*8975f5c5SAndroid Build Coastguard Worker     // texturedimension - dimension of the D3D texture and surface.
1440*8975f5c5SAndroid Build Coastguard Worker     // offset - draw into the texture at offset (|offset|, |offset|)
setupFragCoordOffset(int textureDimension,int offset)1441*8975f5c5SAndroid Build Coastguard Worker     void setupFragCoordOffset(int textureDimension, int offset)
1442*8975f5c5SAndroid Build Coastguard Worker     {
1443*8975f5c5SAndroid Build Coastguard Worker         ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_platform_angle_d3d"));
1444*8975f5c5SAndroid Build Coastguard Worker         initializeDisplay();
1445*8975f5c5SAndroid Build Coastguard Worker 
1446*8975f5c5SAndroid Build Coastguard Worker         EGLAttrib device       = 0;
1447*8975f5c5SAndroid Build Coastguard Worker         EGLAttrib newEglDevice = 0;
1448*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_TRUE(eglQueryDisplayAttribEXT(mDisplay, EGL_DEVICE_EXT, &newEglDevice));
1449*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_TRUE(eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(newEglDevice),
1450*8975f5c5SAndroid Build Coastguard Worker                                                 EGL_D3D11_DEVICE_ANGLE, &device));
1451*8975f5c5SAndroid Build Coastguard Worker         angle::ComPtr<ID3D11Device> d3d11Device(reinterpret_cast<ID3D11Device *>(device));
1452*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(!!d3d11Device);
1453*8975f5c5SAndroid Build Coastguard Worker 
1454*8975f5c5SAndroid Build Coastguard Worker         D3D11_TEXTURE2D_DESC desc = {};
1455*8975f5c5SAndroid Build Coastguard Worker         desc.Format               = DXGI_FORMAT_B8G8R8A8_UNORM;
1456*8975f5c5SAndroid Build Coastguard Worker         desc.Width                = textureDimension;
1457*8975f5c5SAndroid Build Coastguard Worker         desc.Height               = textureDimension;
1458*8975f5c5SAndroid Build Coastguard Worker         desc.ArraySize            = 1;
1459*8975f5c5SAndroid Build Coastguard Worker         desc.MipLevels            = 1;
1460*8975f5c5SAndroid Build Coastguard Worker         desc.SampleDesc.Count     = 1;
1461*8975f5c5SAndroid Build Coastguard Worker         desc.Usage                = D3D11_USAGE_DEFAULT;
1462*8975f5c5SAndroid Build Coastguard Worker         desc.BindFlags            = D3D11_BIND_RENDER_TARGET;
1463*8975f5c5SAndroid Build Coastguard Worker         angle::ComPtr<ID3D11Texture2D> texture;
1464*8975f5c5SAndroid Build Coastguard Worker         HRESULT hr = d3d11Device->CreateTexture2D(&desc, nullptr, &texture);
1465*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(SUCCEEDED(hr));
1466*8975f5c5SAndroid Build Coastguard Worker 
1467*8975f5c5SAndroid Build Coastguard Worker         const EGLint surfaceAttributes[] = {EGL_WIDTH,
1468*8975f5c5SAndroid Build Coastguard Worker                                             textureDimension,
1469*8975f5c5SAndroid Build Coastguard Worker                                             EGL_HEIGHT,
1470*8975f5c5SAndroid Build Coastguard Worker                                             textureDimension,
1471*8975f5c5SAndroid Build Coastguard Worker                                             EGL_TEXTURE_OFFSET_X_ANGLE,
1472*8975f5c5SAndroid Build Coastguard Worker                                             offset,
1473*8975f5c5SAndroid Build Coastguard Worker                                             EGL_TEXTURE_OFFSET_Y_ANGLE,
1474*8975f5c5SAndroid Build Coastguard Worker                                             offset,
1475*8975f5c5SAndroid Build Coastguard Worker                                             EGL_NONE};
1476*8975f5c5SAndroid Build Coastguard Worker         EGLClientBuffer buffer           = reinterpret_cast<EGLClientBuffer>(texture.Get());
1477*8975f5c5SAndroid Build Coastguard Worker 
1478*8975f5c5SAndroid Build Coastguard Worker         const EGLint configAttributes[] = {
1479*8975f5c5SAndroid Build Coastguard Worker             EGL_RED_SIZE,   8, EGL_GREEN_SIZE,   8, EGL_BLUE_SIZE,      8, EGL_ALPHA_SIZE, 8,
1480*8975f5c5SAndroid Build Coastguard Worker             EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_SAMPLE_BUFFERS, 0, EGL_NONE};
1481*8975f5c5SAndroid Build Coastguard Worker 
1482*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config;
1483*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_TRUE(EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config));
1484*8975f5c5SAndroid Build Coastguard Worker         mConfig = config;
1485*8975f5c5SAndroid Build Coastguard Worker 
1486*8975f5c5SAndroid Build Coastguard Worker         mPbufferSurface = eglCreatePbufferFromClientBuffer(mDisplay, EGL_D3D_TEXTURE_ANGLE, buffer,
1487*8975f5c5SAndroid Build Coastguard Worker                                                            config, surfaceAttributes);
1488*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1489*8975f5c5SAndroid Build Coastguard Worker 
1490*8975f5c5SAndroid Build Coastguard Worker         initializeMainContext();
1491*8975f5c5SAndroid Build Coastguard Worker 
1492*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, mPbufferSurface, mPbufferSurface, mContext);
1493*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1494*8975f5c5SAndroid Build Coastguard Worker 
1495*8975f5c5SAndroid Build Coastguard Worker         // Fragment shader that uses the gl_FragCoord values to output the (x, y) position of
1496*8975f5c5SAndroid Build Coastguard Worker         // the current pixel as the color.
1497*8975f5c5SAndroid Build Coastguard Worker         //    - Reverse the offset that was applied to the original coordinates
1498*8975f5c5SAndroid Build Coastguard Worker         //    - 0.5 is subtracted because gl_FragCoord gives the pixel center
1499*8975f5c5SAndroid Build Coastguard Worker         //    - Divided by the size to give a max value of 1
1500*8975f5c5SAndroid Build Coastguard Worker         std::stringstream fs;
1501*8975f5c5SAndroid Build Coastguard Worker         fs << "precision mediump float;" << "void main()" << "{" << "    float dimension = float("
1502*8975f5c5SAndroid Build Coastguard Worker            << textureDimension << ");" << "    float offset = float(" << offset << ");"
1503*8975f5c5SAndroid Build Coastguard Worker            << "    gl_FragColor = vec4((gl_FragCoord.x + offset - 0.5) / dimension,"
1504*8975f5c5SAndroid Build Coastguard Worker            << "                        (gl_FragCoord.y + offset - 0.5) / dimension,"
1505*8975f5c5SAndroid Build Coastguard Worker            << "                         gl_FragCoord.z,"
1506*8975f5c5SAndroid Build Coastguard Worker            << "                         gl_FragCoord.w);" << "}";
1507*8975f5c5SAndroid Build Coastguard Worker 
1508*8975f5c5SAndroid Build Coastguard Worker         GLuint program = createProgram(fs.str().c_str());
1509*8975f5c5SAndroid Build Coastguard Worker         ASSERT_NE(0u, program);
1510*8975f5c5SAndroid Build Coastguard Worker         glUseProgram(program);
1511*8975f5c5SAndroid Build Coastguard Worker 
1512*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0, 0, 0, 1);
1513*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
1514*8975f5c5SAndroid Build Coastguard Worker 
1515*8975f5c5SAndroid Build Coastguard Worker         const GLfloat vertices[] = {
1516*8975f5c5SAndroid Build Coastguard Worker             -1.0f, 1.0f, 0.5f, -1.0f, -1.0f, 0.5f, 1.0f, -1.0f, 0.5f,
1517*8975f5c5SAndroid Build Coastguard Worker             -1.0f, 1.0f, 0.5f, 1.0f,  -1.0f, 0.5f, 1.0f, 1.0f,  0.5f,
1518*8975f5c5SAndroid Build Coastguard Worker         };
1519*8975f5c5SAndroid Build Coastguard Worker 
1520*8975f5c5SAndroid Build Coastguard Worker         GLint positionLocation =
1521*8975f5c5SAndroid Build Coastguard Worker             glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib());
1522*8975f5c5SAndroid Build Coastguard Worker         glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
1523*8975f5c5SAndroid Build Coastguard Worker         glEnableVertexAttribArray(positionLocation);
1524*8975f5c5SAndroid Build Coastguard Worker 
1525*8975f5c5SAndroid Build Coastguard Worker         glDrawArrays(GL_TRIANGLES, 0, 6);
1526*8975f5c5SAndroid Build Coastguard Worker 
1527*8975f5c5SAndroid Build Coastguard Worker         glDisableVertexAttribArray(positionLocation);
1528*8975f5c5SAndroid Build Coastguard Worker 
1529*8975f5c5SAndroid Build Coastguard Worker         glDeleteProgram(program);
1530*8975f5c5SAndroid Build Coastguard Worker 
1531*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
1532*8975f5c5SAndroid Build Coastguard Worker     }
1533*8975f5c5SAndroid Build Coastguard Worker };
1534*8975f5c5SAndroid Build Coastguard Worker 
1535*8975f5c5SAndroid Build Coastguard Worker // Test that rendering to an IDCompositionSurface using a pbuffer works.
TEST_P(EGLSurfaceTestD3D11,CreateDirectCompositionSurface)1536*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTestD3D11, CreateDirectCompositionSurface)
1537*8975f5c5SAndroid Build Coastguard Worker {
1538*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_platform_angle_d3d"));
1539*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1540*8975f5c5SAndroid Build Coastguard Worker 
1541*8975f5c5SAndroid Build Coastguard Worker     EGLAttrib device       = 0;
1542*8975f5c5SAndroid Build Coastguard Worker     EGLAttrib newEglDevice = 0;
1543*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglQueryDisplayAttribEXT(mDisplay, EGL_DEVICE_EXT, &newEglDevice));
1544*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(newEglDevice),
1545*8975f5c5SAndroid Build Coastguard Worker                                             EGL_D3D11_DEVICE_ANGLE, &device));
1546*8975f5c5SAndroid Build Coastguard Worker     angle::ComPtr<ID3D11Device> d3d11Device(reinterpret_cast<ID3D11Device *>(device));
1547*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(!!d3d11Device);
1548*8975f5c5SAndroid Build Coastguard Worker 
1549*8975f5c5SAndroid Build Coastguard Worker     HMODULE dcompLibrary = LoadLibraryA("dcomp.dll");
1550*8975f5c5SAndroid Build Coastguard Worker     if (!dcompLibrary)
1551*8975f5c5SAndroid Build Coastguard Worker     {
1552*8975f5c5SAndroid Build Coastguard Worker         std::cout << "DirectComposition not supported" << std::endl;
1553*8975f5c5SAndroid Build Coastguard Worker         return;
1554*8975f5c5SAndroid Build Coastguard Worker     }
1555*8975f5c5SAndroid Build Coastguard Worker     typedef HRESULT(WINAPI * PFN_DCOMPOSITION_CREATE_DEVICE2)(IUnknown * dxgiDevice, REFIID iid,
1556*8975f5c5SAndroid Build Coastguard Worker                                                               void **dcompositionDevice);
1557*8975f5c5SAndroid Build Coastguard Worker     PFN_DCOMPOSITION_CREATE_DEVICE2 createDComp = reinterpret_cast<PFN_DCOMPOSITION_CREATE_DEVICE2>(
1558*8975f5c5SAndroid Build Coastguard Worker         GetProcAddress(dcompLibrary, "DCompositionCreateDevice2"));
1559*8975f5c5SAndroid Build Coastguard Worker     if (!createDComp)
1560*8975f5c5SAndroid Build Coastguard Worker     {
1561*8975f5c5SAndroid Build Coastguard Worker         std::cout << "DirectComposition2 not supported" << std::endl;
1562*8975f5c5SAndroid Build Coastguard Worker         FreeLibrary(dcompLibrary);
1563*8975f5c5SAndroid Build Coastguard Worker         return;
1564*8975f5c5SAndroid Build Coastguard Worker     }
1565*8975f5c5SAndroid Build Coastguard Worker 
1566*8975f5c5SAndroid Build Coastguard Worker     angle::ComPtr<IDCompositionDevice> dcompDevice;
1567*8975f5c5SAndroid Build Coastguard Worker     HRESULT hr = createDComp(d3d11Device.Get(), IID_PPV_ARGS(dcompDevice.GetAddressOf()));
1568*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(SUCCEEDED(hr));
1569*8975f5c5SAndroid Build Coastguard Worker 
1570*8975f5c5SAndroid Build Coastguard Worker     angle::ComPtr<IDCompositionSurface> dcompSurface;
1571*8975f5c5SAndroid Build Coastguard Worker     hr = dcompDevice->CreateSurface(100, 100, DXGI_FORMAT_B8G8R8A8_UNORM,
1572*8975f5c5SAndroid Build Coastguard Worker                                     DXGI_ALPHA_MODE_PREMULTIPLIED, dcompSurface.GetAddressOf());
1573*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(SUCCEEDED(hr));
1574*8975f5c5SAndroid Build Coastguard Worker 
1575*8975f5c5SAndroid Build Coastguard Worker     angle::ComPtr<ID3D11Texture2D> texture;
1576*8975f5c5SAndroid Build Coastguard Worker     POINT updateOffset;
1577*8975f5c5SAndroid Build Coastguard Worker     hr = dcompSurface->BeginDraw(nullptr, IID_PPV_ARGS(texture.GetAddressOf()), &updateOffset);
1578*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(SUCCEEDED(hr));
1579*8975f5c5SAndroid Build Coastguard Worker 
1580*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] = {
1581*8975f5c5SAndroid Build Coastguard Worker         EGL_RED_SIZE,   8, EGL_GREEN_SIZE,   8, EGL_BLUE_SIZE,      8, EGL_ALPHA_SIZE, 8,
1582*8975f5c5SAndroid Build Coastguard Worker         EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_SAMPLE_BUFFERS, 0, EGL_NONE};
1583*8975f5c5SAndroid Build Coastguard Worker 
1584*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config;
1585*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config));
1586*8975f5c5SAndroid Build Coastguard Worker 
1587*8975f5c5SAndroid Build Coastguard Worker     const EGLint surfaceAttributes[] = {EGL_WIDTH,
1588*8975f5c5SAndroid Build Coastguard Worker                                         100,
1589*8975f5c5SAndroid Build Coastguard Worker                                         EGL_HEIGHT,
1590*8975f5c5SAndroid Build Coastguard Worker                                         100,
1591*8975f5c5SAndroid Build Coastguard Worker                                         EGL_TEXTURE_OFFSET_X_ANGLE,
1592*8975f5c5SAndroid Build Coastguard Worker                                         updateOffset.x,
1593*8975f5c5SAndroid Build Coastguard Worker                                         EGL_TEXTURE_OFFSET_Y_ANGLE,
1594*8975f5c5SAndroid Build Coastguard Worker                                         updateOffset.y,
1595*8975f5c5SAndroid Build Coastguard Worker                                         EGL_NONE};
1596*8975f5c5SAndroid Build Coastguard Worker 
1597*8975f5c5SAndroid Build Coastguard Worker     EGLClientBuffer buffer = reinterpret_cast<EGLClientBuffer>(texture.Get());
1598*8975f5c5SAndroid Build Coastguard Worker     mPbufferSurface = eglCreatePbufferFromClientBuffer(mDisplay, EGL_D3D_TEXTURE_ANGLE, buffer,
1599*8975f5c5SAndroid Build Coastguard Worker                                                        config, surfaceAttributes);
1600*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1601*8975f5c5SAndroid Build Coastguard Worker 
1602*8975f5c5SAndroid Build Coastguard Worker     mConfig = config;
1603*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1604*8975f5c5SAndroid Build Coastguard Worker 
1605*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mPbufferSurface, mPbufferSurface, mContext);
1606*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1607*8975f5c5SAndroid Build Coastguard Worker 
1608*8975f5c5SAndroid Build Coastguard Worker     GLuint program = createProgram();
1609*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, program);
1610*8975f5c5SAndroid Build Coastguard Worker     drawWithProgram(program);
1611*8975f5c5SAndroid Build Coastguard Worker     EXPECT_GL_NO_ERROR();
1612*8975f5c5SAndroid Build Coastguard Worker     glDeleteProgram(program);
1613*8975f5c5SAndroid Build Coastguard Worker }
1614*8975f5c5SAndroid Build Coastguard Worker 
1615*8975f5c5SAndroid Build Coastguard Worker // Tests drawing into a surface created with negative offsets.
TEST_P(EGLSurfaceTestD3D11,CreateSurfaceWithTextureNegativeOffset)1616*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTestD3D11, CreateSurfaceWithTextureNegativeOffset)
1617*8975f5c5SAndroid Build Coastguard Worker {
1618*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_platform_angle_d3d"));
1619*8975f5c5SAndroid Build Coastguard Worker     testTextureOffset(-50, 255, 0);
1620*8975f5c5SAndroid Build Coastguard Worker }
1621*8975f5c5SAndroid Build Coastguard Worker 
1622*8975f5c5SAndroid Build Coastguard Worker // Tests drawing into a surface created with offsets.
TEST_P(EGLSurfaceTestD3D11,CreateSurfaceWithTextureOffset)1623*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTestD3D11, CreateSurfaceWithTextureOffset)
1624*8975f5c5SAndroid Build Coastguard Worker {
1625*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_platform_angle_d3d"));
1626*8975f5c5SAndroid Build Coastguard Worker     testTextureOffset(50, 0, 255);
1627*8975f5c5SAndroid Build Coastguard Worker }
1628*8975f5c5SAndroid Build Coastguard Worker 
TEST_P(EGLSurfaceTestD3D11,CreateSurfaceWithMSAA)1629*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTestD3D11, CreateSurfaceWithMSAA)
1630*8975f5c5SAndroid Build Coastguard Worker {
1631*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_platform_angle_d3d"));
1632*8975f5c5SAndroid Build Coastguard Worker 
1633*8975f5c5SAndroid Build Coastguard Worker     // clang-format off
1634*8975f5c5SAndroid Build Coastguard Worker     const EGLint configAttributes[] =
1635*8975f5c5SAndroid Build Coastguard Worker     {
1636*8975f5c5SAndroid Build Coastguard Worker         EGL_RED_SIZE, 8,
1637*8975f5c5SAndroid Build Coastguard Worker         EGL_GREEN_SIZE, 8,
1638*8975f5c5SAndroid Build Coastguard Worker         EGL_BLUE_SIZE, 8,
1639*8975f5c5SAndroid Build Coastguard Worker         EGL_ALPHA_SIZE, 0,
1640*8975f5c5SAndroid Build Coastguard Worker         EGL_DEPTH_SIZE, 0,
1641*8975f5c5SAndroid Build Coastguard Worker         EGL_STENCIL_SIZE, 0,
1642*8975f5c5SAndroid Build Coastguard Worker         EGL_SAMPLE_BUFFERS, 1,
1643*8975f5c5SAndroid Build Coastguard Worker         EGL_SAMPLES, 4,
1644*8975f5c5SAndroid Build Coastguard Worker         EGL_NONE
1645*8975f5c5SAndroid Build Coastguard Worker     };
1646*8975f5c5SAndroid Build Coastguard Worker     // clang-format on
1647*8975f5c5SAndroid Build Coastguard Worker 
1648*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1649*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config;
1650*8975f5c5SAndroid Build Coastguard Worker     if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config) == EGL_FALSE)
1651*8975f5c5SAndroid Build Coastguard Worker     {
1652*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGLConfig for 4xMSAA is not supported, skipping test" << std::endl;
1653*8975f5c5SAndroid Build Coastguard Worker         return;
1654*8975f5c5SAndroid Build Coastguard Worker     }
1655*8975f5c5SAndroid Build Coastguard Worker 
1656*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(config);
1657*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1658*8975f5c5SAndroid Build Coastguard Worker 
1659*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1660*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1661*8975f5c5SAndroid Build Coastguard Worker 
1662*8975f5c5SAndroid Build Coastguard Worker     GLuint program = createProgram();
1663*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(0u, program);
1664*8975f5c5SAndroid Build Coastguard Worker 
1665*8975f5c5SAndroid Build Coastguard Worker     glClearColor(0, 0, 0, 1);
1666*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
1667*8975f5c5SAndroid Build Coastguard Worker 
1668*8975f5c5SAndroid Build Coastguard Worker     GLint positionLocation = glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib());
1669*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(-1, positionLocation);
1670*8975f5c5SAndroid Build Coastguard Worker 
1671*8975f5c5SAndroid Build Coastguard Worker     glUseProgram(program);
1672*8975f5c5SAndroid Build Coastguard Worker 
1673*8975f5c5SAndroid Build Coastguard Worker     const GLfloat halfPixelOffset = 0.5f * 2.0f / mOSWindow->getWidth();
1674*8975f5c5SAndroid Build Coastguard Worker     // clang-format off
1675*8975f5c5SAndroid Build Coastguard Worker     const GLfloat vertices[] =
1676*8975f5c5SAndroid Build Coastguard Worker     {
1677*8975f5c5SAndroid Build Coastguard Worker         -1.0f + halfPixelOffset,  1.0f, 0.5f,
1678*8975f5c5SAndroid Build Coastguard Worker         -1.0f + halfPixelOffset, -1.0f, 0.5f,
1679*8975f5c5SAndroid Build Coastguard Worker          1.0f,                   -1.0f, 0.5f
1680*8975f5c5SAndroid Build Coastguard Worker     };
1681*8975f5c5SAndroid Build Coastguard Worker     // clang-format on
1682*8975f5c5SAndroid Build Coastguard Worker 
1683*8975f5c5SAndroid Build Coastguard Worker     glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
1684*8975f5c5SAndroid Build Coastguard Worker     glEnableVertexAttribArray(positionLocation);
1685*8975f5c5SAndroid Build Coastguard Worker 
1686*8975f5c5SAndroid Build Coastguard Worker     glDrawArrays(GL_TRIANGLES, 0, 3);
1687*8975f5c5SAndroid Build Coastguard Worker 
1688*8975f5c5SAndroid Build Coastguard Worker     glDisableVertexAttribArray(positionLocation);
1689*8975f5c5SAndroid Build Coastguard Worker     glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
1690*8975f5c5SAndroid Build Coastguard Worker 
1691*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_NEAR(0, 0, 127, 0, 0, 255, 10);
1692*8975f5c5SAndroid Build Coastguard Worker     EXPECT_GL_NO_ERROR();
1693*8975f5c5SAndroid Build Coastguard Worker 
1694*8975f5c5SAndroid Build Coastguard Worker     glDeleteProgram(program);
1695*8975f5c5SAndroid Build Coastguard Worker }
1696*8975f5c5SAndroid Build Coastguard Worker 
1697*8975f5c5SAndroid Build Coastguard Worker // Tests that gl_FragCoord.xy is offset with the EGL_TEXTURE_OFFSET_[X|Y]_ANGLE values specified
1698*8975f5c5SAndroid Build Coastguard Worker // at surface creation, using positive offsets
TEST_P(EGLSurfaceTestD3D11,FragCoordOffset)1699*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTestD3D11, FragCoordOffset)
1700*8975f5c5SAndroid Build Coastguard Worker {
1701*8975f5c5SAndroid Build Coastguard Worker     constexpr int kTextureDimension = 28;
1702*8975f5c5SAndroid Build Coastguard Worker     constexpr int kOffset           = 6;
1703*8975f5c5SAndroid Build Coastguard Worker 
1704*8975f5c5SAndroid Build Coastguard Worker     setupFragCoordOffset(kTextureDimension, kOffset);
1705*8975f5c5SAndroid Build Coastguard Worker 
1706*8975f5c5SAndroid Build Coastguard Worker     // With a positive offset, nothing is drawn in any pixels to the left of and above |kOffset|.
1707*8975f5c5SAndroid Build Coastguard Worker     for (int x = 0; x < kOffset; x++)
1708*8975f5c5SAndroid Build Coastguard Worker     {
1709*8975f5c5SAndroid Build Coastguard Worker         for (int y = 0; y < kOffset; y++)
1710*8975f5c5SAndroid Build Coastguard Worker         {
1711*8975f5c5SAndroid Build Coastguard Worker             EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 0);
1712*8975f5c5SAndroid Build Coastguard Worker         }
1713*8975f5c5SAndroid Build Coastguard Worker     }
1714*8975f5c5SAndroid Build Coastguard Worker 
1715*8975f5c5SAndroid Build Coastguard Worker     // The rest of the texture's color should be the value of the (x, y) coordinates.
1716*8975f5c5SAndroid Build Coastguard Worker     for (int x = kOffset; x < kTextureDimension; x++)
1717*8975f5c5SAndroid Build Coastguard Worker     {
1718*8975f5c5SAndroid Build Coastguard Worker         for (int y = kOffset; y < kTextureDimension; y++)
1719*8975f5c5SAndroid Build Coastguard Worker         {
1720*8975f5c5SAndroid Build Coastguard Worker             EXPECT_PIXEL_NEAR(x, y, x * 255.0 / kTextureDimension, y * 255.0 / kTextureDimension,
1721*8975f5c5SAndroid Build Coastguard Worker                               191, 255, 0.5);
1722*8975f5c5SAndroid Build Coastguard Worker         }
1723*8975f5c5SAndroid Build Coastguard Worker     }
1724*8975f5c5SAndroid Build Coastguard Worker }
1725*8975f5c5SAndroid Build Coastguard Worker 
1726*8975f5c5SAndroid Build Coastguard Worker // Tests that gl_FragCoord.xy is offset with the EGL_TEXTURE_OFFSET_[X|Y]_ANGLE values specified
1727*8975f5c5SAndroid Build Coastguard Worker // at surface creation, using negative offsets.
TEST_P(EGLSurfaceTestD3D11,FragCoordOffsetNegative)1728*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTestD3D11, FragCoordOffsetNegative)
1729*8975f5c5SAndroid Build Coastguard Worker {
1730*8975f5c5SAndroid Build Coastguard Worker     constexpr int kTextureDimension = 28;
1731*8975f5c5SAndroid Build Coastguard Worker     constexpr int kOffset           = 6;
1732*8975f5c5SAndroid Build Coastguard Worker 
1733*8975f5c5SAndroid Build Coastguard Worker     setupFragCoordOffset(kTextureDimension, -kOffset);
1734*8975f5c5SAndroid Build Coastguard Worker 
1735*8975f5c5SAndroid Build Coastguard Worker     // With a negative offset, nothing is drawn in pixels to the right of and below |koffset|.
1736*8975f5c5SAndroid Build Coastguard Worker     for (int x = kTextureDimension - kOffset; x < kTextureDimension; x++)
1737*8975f5c5SAndroid Build Coastguard Worker     {
1738*8975f5c5SAndroid Build Coastguard Worker         for (int y = kTextureDimension - kOffset; y < kTextureDimension; y++)
1739*8975f5c5SAndroid Build Coastguard Worker         {
1740*8975f5c5SAndroid Build Coastguard Worker             EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 0);
1741*8975f5c5SAndroid Build Coastguard Worker         }
1742*8975f5c5SAndroid Build Coastguard Worker     }
1743*8975f5c5SAndroid Build Coastguard Worker 
1744*8975f5c5SAndroid Build Coastguard Worker     // The rest of the texture's color should be the value of the (x, y) coordinates.
1745*8975f5c5SAndroid Build Coastguard Worker     for (int x = 0; x < kTextureDimension - kOffset; x++)
1746*8975f5c5SAndroid Build Coastguard Worker     {
1747*8975f5c5SAndroid Build Coastguard Worker         for (int y = 0; y < kTextureDimension - kOffset; y++)
1748*8975f5c5SAndroid Build Coastguard Worker         {
1749*8975f5c5SAndroid Build Coastguard Worker             EXPECT_PIXEL_NEAR(x, y, x * 255.0 / kTextureDimension, y * 255.0 / kTextureDimension,
1750*8975f5c5SAndroid Build Coastguard Worker                               191, 255, 0.5);
1751*8975f5c5SAndroid Build Coastguard Worker         }
1752*8975f5c5SAndroid Build Coastguard Worker     }
1753*8975f5c5SAndroid Build Coastguard Worker }
1754*8975f5c5SAndroid Build Coastguard Worker 
1755*8975f5c5SAndroid Build Coastguard Worker #endif  // ANGLE_ENABLE_D3D11
1756*8975f5c5SAndroid Build Coastguard Worker 
1757*8975f5c5SAndroid Build Coastguard Worker // Verify bliting between two surfaces works correctly.
TEST_P(EGLSurfaceTest3,BlitBetweenSurfaces)1758*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest3, BlitBetweenSurfaces)
1759*8975f5c5SAndroid Build Coastguard Worker {
1760*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1761*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
1762*8975f5c5SAndroid Build Coastguard Worker 
1763*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
1764*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1765*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
1766*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mContext, EGL_NO_CONTEXT);
1767*8975f5c5SAndroid Build Coastguard Worker 
1768*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface1;
1769*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface2;
1770*8975f5c5SAndroid Build Coastguard Worker 
1771*8975f5c5SAndroid Build Coastguard Worker     const EGLint surfaceAttributes[] = {
1772*8975f5c5SAndroid Build Coastguard Worker         EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE,
1773*8975f5c5SAndroid Build Coastguard Worker     };
1774*8975f5c5SAndroid Build Coastguard Worker 
1775*8975f5c5SAndroid Build Coastguard Worker     surface1 = eglCreatePbufferSurface(mDisplay, mConfig, surfaceAttributes);
1776*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1777*8975f5c5SAndroid Build Coastguard Worker     surface2 = eglCreatePbufferSurface(mDisplay, mConfig, surfaceAttributes);
1778*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1779*8975f5c5SAndroid Build Coastguard Worker 
1780*8975f5c5SAndroid Build Coastguard Worker     // Clear surface1.
1781*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface1, surface1, mContext));
1782*8975f5c5SAndroid Build Coastguard Worker 
1783*8975f5c5SAndroid Build Coastguard Worker     // TODO(http://anglebug.com/42264803): Failing with OpenGL ES backend on Android and
1784*8975f5c5SAndroid Build Coastguard Worker     // Windows. Must be after the eglMakeCurrent() so the renderer string is initialized.
1785*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsOpenGLES() && (IsAndroid() || IsWindows()));
1786*8975f5c5SAndroid Build Coastguard Worker 
1787*8975f5c5SAndroid Build Coastguard Worker     glClearColor(kFloatRed.R, kFloatRed.G, kFloatRed.B, kFloatRed.A);
1788*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
1789*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1790*8975f5c5SAndroid Build Coastguard Worker 
1791*8975f5c5SAndroid Build Coastguard Worker     // Blit from surface1 to surface2.
1792*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface2, surface1, mContext));
1793*8975f5c5SAndroid Build Coastguard Worker     glBlitFramebuffer(0, 0, 64, 64, 0, 0, 64, 64, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1794*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1795*8975f5c5SAndroid Build Coastguard Worker 
1796*8975f5c5SAndroid Build Coastguard Worker     // Confirm surface1 has the clear color.
1797*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface1, surface1, mContext));
1798*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(32, 32, GLColor::red);
1799*8975f5c5SAndroid Build Coastguard Worker 
1800*8975f5c5SAndroid Build Coastguard Worker     // Confirm surface2 has the blited clear color.
1801*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface2, surface2, mContext));
1802*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(32, 32, GLColor::red);
1803*8975f5c5SAndroid Build Coastguard Worker 
1804*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface1);
1805*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface2);
1806*8975f5c5SAndroid Build Coastguard Worker }
1807*8975f5c5SAndroid Build Coastguard Worker 
1808*8975f5c5SAndroid Build Coastguard Worker // Verify bliting between two surfaces works correctly.
TEST_P(EGLSurfaceTest3,BlitBetweenSurfacesWithDeferredClear)1809*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest3, BlitBetweenSurfacesWithDeferredClear)
1810*8975f5c5SAndroid Build Coastguard Worker {
1811*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1812*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
1813*8975f5c5SAndroid Build Coastguard Worker 
1814*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
1815*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1816*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
1817*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mContext, EGL_NO_CONTEXT);
1818*8975f5c5SAndroid Build Coastguard Worker 
1819*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface1;
1820*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface2;
1821*8975f5c5SAndroid Build Coastguard Worker 
1822*8975f5c5SAndroid Build Coastguard Worker     const EGLint surfaceAttributes[] = {
1823*8975f5c5SAndroid Build Coastguard Worker         EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE,
1824*8975f5c5SAndroid Build Coastguard Worker     };
1825*8975f5c5SAndroid Build Coastguard Worker 
1826*8975f5c5SAndroid Build Coastguard Worker     surface1 = eglCreatePbufferSurface(mDisplay, mConfig, surfaceAttributes);
1827*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1828*8975f5c5SAndroid Build Coastguard Worker     surface2 = eglCreatePbufferSurface(mDisplay, mConfig, surfaceAttributes);
1829*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1830*8975f5c5SAndroid Build Coastguard Worker 
1831*8975f5c5SAndroid Build Coastguard Worker     // Clear surface1.
1832*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface1, surface1, mContext));
1833*8975f5c5SAndroid Build Coastguard Worker 
1834*8975f5c5SAndroid Build Coastguard Worker     // TODO(http://anglebug.com/42264803): Failing with OpenGL ES backend on Android and
1835*8975f5c5SAndroid Build Coastguard Worker     // Windows. Must be after the eglMakeCurrent() so the renderer string is initialized.
1836*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsOpenGLES() && (IsAndroid() || IsWindows()));
1837*8975f5c5SAndroid Build Coastguard Worker 
1838*8975f5c5SAndroid Build Coastguard Worker     glClearColor(kFloatRed.R, kFloatRed.G, kFloatRed.B, kFloatRed.A);
1839*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
1840*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1841*8975f5c5SAndroid Build Coastguard Worker     // Force the clear to be flushed
1842*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(32, 32, GLColor::red);
1843*8975f5c5SAndroid Build Coastguard Worker 
1844*8975f5c5SAndroid Build Coastguard Worker     // Clear to green, but don't read it back so the clear is deferred.
1845*8975f5c5SAndroid Build Coastguard Worker     glClearColor(kFloatGreen.R, kFloatGreen.G, kFloatGreen.B, kFloatGreen.A);
1846*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
1847*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1848*8975f5c5SAndroid Build Coastguard Worker 
1849*8975f5c5SAndroid Build Coastguard Worker     // Blit from surface1 to surface2.
1850*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface2, surface1, mContext));
1851*8975f5c5SAndroid Build Coastguard Worker     glBlitFramebuffer(0, 0, 64, 64, 0, 0, 64, 64, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1852*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
1853*8975f5c5SAndroid Build Coastguard Worker 
1854*8975f5c5SAndroid Build Coastguard Worker     // Confirm surface1 has the clear color.
1855*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(32, 32, GLColor::green);
1856*8975f5c5SAndroid Build Coastguard Worker 
1857*8975f5c5SAndroid Build Coastguard Worker     // Confirm surface2 has the blited clear color.
1858*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface2, surface2, mContext));
1859*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(32, 32, GLColor::green);
1860*8975f5c5SAndroid Build Coastguard Worker 
1861*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface1);
1862*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface2);
1863*8975f5c5SAndroid Build Coastguard Worker }
1864*8975f5c5SAndroid Build Coastguard Worker 
1865*8975f5c5SAndroid Build Coastguard Worker // Verify switching between a surface with robust resource init and one without still clears alpha.
TEST_P(EGLSurfaceTest,RobustResourceInitAndEmulatedAlpha)1866*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, RobustResourceInitAndEmulatedAlpha)
1867*8975f5c5SAndroid Build Coastguard Worker {
1868*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/42263827
1869*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsNVIDIA() && isGLRenderer() && IsLinux());
1870*8975f5c5SAndroid Build Coastguard Worker 
1871*8975f5c5SAndroid Build Coastguard Worker     // http://anglebug.com/40644775
1872*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(IsAndroid() && IsNexus5X() && isGLESRenderer());
1873*8975f5c5SAndroid Build Coastguard Worker 
1874*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1875*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
1876*8975f5c5SAndroid Build Coastguard Worker 
1877*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(
1878*8975f5c5SAndroid Build Coastguard Worker         !IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_robust_resource_initialization"));
1879*8975f5c5SAndroid Build Coastguard Worker 
1880*8975f5c5SAndroid Build Coastguard Worker     // Initialize and draw red to a Surface with robust resource init enabled.
1881*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kRGBAAttributes[] = {EGL_RED_SIZE,     8,
1882*8975f5c5SAndroid Build Coastguard Worker                                           EGL_GREEN_SIZE,   8,
1883*8975f5c5SAndroid Build Coastguard Worker                                           EGL_BLUE_SIZE,    8,
1884*8975f5c5SAndroid Build Coastguard Worker                                           EGL_ALPHA_SIZE,   8,
1885*8975f5c5SAndroid Build Coastguard Worker                                           EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
1886*8975f5c5SAndroid Build Coastguard Worker                                           EGL_NONE};
1887*8975f5c5SAndroid Build Coastguard Worker 
1888*8975f5c5SAndroid Build Coastguard Worker     EGLint configCount   = 0;
1889*8975f5c5SAndroid Build Coastguard Worker     EGLConfig rgbaConfig = nullptr;
1890*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, kRGBAAttributes, &rgbaConfig, 1, &configCount));
1891*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(configCount, 1);
1892*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(rgbaConfig, nullptr);
1893*8975f5c5SAndroid Build Coastguard Worker 
1894*8975f5c5SAndroid Build Coastguard Worker     std::vector<EGLint> robustInitAttribs;
1895*8975f5c5SAndroid Build Coastguard Worker     robustInitAttribs.push_back(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
1896*8975f5c5SAndroid Build Coastguard Worker     robustInitAttribs.push_back(EGL_TRUE);
1897*8975f5c5SAndroid Build Coastguard Worker 
1898*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithAttribs(rgbaConfig, robustInitAttribs);
1899*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1900*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
1901*8975f5c5SAndroid Build Coastguard Worker 
1902*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1903*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1904*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mContext, EGL_NO_CONTEXT);
1905*8975f5c5SAndroid Build Coastguard Worker 
1906*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1907*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1908*8975f5c5SAndroid Build Coastguard Worker     eglSwapBuffers(mDisplay, mWindowSurface);
1909*8975f5c5SAndroid Build Coastguard Worker 
1910*8975f5c5SAndroid Build Coastguard Worker     // RGBA robust init setup complete. Draw red and verify.
1911*8975f5c5SAndroid Build Coastguard Worker     {
1912*8975f5c5SAndroid Build Coastguard Worker         ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
1913*8975f5c5SAndroid Build Coastguard Worker         glUseProgram(program);
1914*8975f5c5SAndroid Build Coastguard Worker 
1915*8975f5c5SAndroid Build Coastguard Worker         drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
1916*8975f5c5SAndroid Build Coastguard Worker         ASSERT_GL_NO_ERROR();
1917*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1918*8975f5c5SAndroid Build Coastguard Worker 
1919*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, mWindowSurface);
1920*8975f5c5SAndroid Build Coastguard Worker     }
1921*8975f5c5SAndroid Build Coastguard Worker 
1922*8975f5c5SAndroid Build Coastguard Worker     tearDownContextAndSurface();
1923*8975f5c5SAndroid Build Coastguard Worker 
1924*8975f5c5SAndroid Build Coastguard Worker     // Create second RGB surface with robust resource disabled.
1925*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kRGBAttributes[] = {EGL_RED_SIZE,     8,
1926*8975f5c5SAndroid Build Coastguard Worker                                          EGL_GREEN_SIZE,   8,
1927*8975f5c5SAndroid Build Coastguard Worker                                          EGL_BLUE_SIZE,    8,
1928*8975f5c5SAndroid Build Coastguard Worker                                          EGL_ALPHA_SIZE,   0,
1929*8975f5c5SAndroid Build Coastguard Worker                                          EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
1930*8975f5c5SAndroid Build Coastguard Worker                                          EGL_NONE};
1931*8975f5c5SAndroid Build Coastguard Worker 
1932*8975f5c5SAndroid Build Coastguard Worker     configCount         = 0;
1933*8975f5c5SAndroid Build Coastguard Worker     EGLConfig rgbConfig = nullptr;
1934*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, kRGBAttributes, &rgbConfig, 1, &configCount));
1935*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(configCount, 1);
1936*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(rgbConfig, nullptr);
1937*8975f5c5SAndroid Build Coastguard Worker 
1938*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(rgbConfig);
1939*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1940*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
1941*8975f5c5SAndroid Build Coastguard Worker 
1942*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1943*8975f5c5SAndroid Build Coastguard Worker 
1944*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1945*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1946*8975f5c5SAndroid Build Coastguard Worker 
1947*8975f5c5SAndroid Build Coastguard Worker     // RGB non-robust init setup complete. Draw red and verify.
1948*8975f5c5SAndroid Build Coastguard Worker     {
1949*8975f5c5SAndroid Build Coastguard Worker         ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
1950*8975f5c5SAndroid Build Coastguard Worker         glUseProgram(program);
1951*8975f5c5SAndroid Build Coastguard Worker 
1952*8975f5c5SAndroid Build Coastguard Worker         drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
1953*8975f5c5SAndroid Build Coastguard Worker         ASSERT_GL_NO_ERROR();
1954*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1955*8975f5c5SAndroid Build Coastguard Worker 
1956*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, mWindowSurface);
1957*8975f5c5SAndroid Build Coastguard Worker     }
1958*8975f5c5SAndroid Build Coastguard Worker }
1959*8975f5c5SAndroid Build Coastguard Worker 
drawQuadThenTearDown()1960*8975f5c5SAndroid Build Coastguard Worker void EGLSurfaceTest::drawQuadThenTearDown()
1961*8975f5c5SAndroid Build Coastguard Worker {
1962*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
1963*8975f5c5SAndroid Build Coastguard Worker 
1964*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1965*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
1966*8975f5c5SAndroid Build Coastguard Worker 
1967*8975f5c5SAndroid Build Coastguard Worker     {
1968*8975f5c5SAndroid Build Coastguard Worker         ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
1969*8975f5c5SAndroid Build Coastguard Worker         drawQuad(greenProgram, essl1_shaders::PositionAttrib(), 0.5f);
1970*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1971*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, mWindowSurface);
1972*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1973*8975f5c5SAndroid Build Coastguard Worker     }
1974*8975f5c5SAndroid Build Coastguard Worker 
1975*8975f5c5SAndroid Build Coastguard Worker     tearDownContextAndSurface();
1976*8975f5c5SAndroid Build Coastguard Worker }
1977*8975f5c5SAndroid Build Coastguard Worker 
1978*8975f5c5SAndroid Build Coastguard Worker // Tests the EGL_ANGLE_create_surface_swap_interval extension if available.
TEST_P(EGLSurfaceTest,CreateSurfaceSwapIntervalANGLE)1979*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, CreateSurfaceSwapIntervalANGLE)
1980*8975f5c5SAndroid Build Coastguard Worker {
1981*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
1982*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
1983*8975f5c5SAndroid Build Coastguard Worker 
1984*8975f5c5SAndroid Build Coastguard Worker     mConfig = chooseDefaultConfig(true);
1985*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mConfig, nullptr);
1986*8975f5c5SAndroid Build Coastguard Worker 
1987*8975f5c5SAndroid Build Coastguard Worker     if (IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_surface_swap_interval"))
1988*8975f5c5SAndroid Build Coastguard Worker     {
1989*8975f5c5SAndroid Build Coastguard Worker         // Test error conditions.
1990*8975f5c5SAndroid Build Coastguard Worker         EGLint minSwapInterval = 0;
1991*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, mConfig, EGL_MIN_SWAP_INTERVAL, &minSwapInterval);
1992*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
1993*8975f5c5SAndroid Build Coastguard Worker 
1994*8975f5c5SAndroid Build Coastguard Worker         if (minSwapInterval > 0)
1995*8975f5c5SAndroid Build Coastguard Worker         {
1996*8975f5c5SAndroid Build Coastguard Worker             std::vector<EGLint> min1SwapAttribs = {EGL_SWAP_INTERVAL_ANGLE, minSwapInterval - 1};
1997*8975f5c5SAndroid Build Coastguard Worker             initializeWindowSurfaceWithAttribs(mConfig, min1SwapAttribs, EGL_BAD_ATTRIBUTE);
1998*8975f5c5SAndroid Build Coastguard Worker         }
1999*8975f5c5SAndroid Build Coastguard Worker 
2000*8975f5c5SAndroid Build Coastguard Worker         EGLint maxSwapInterval = 0;
2001*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, mConfig, EGL_MAX_SWAP_INTERVAL, &maxSwapInterval);
2002*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
2003*8975f5c5SAndroid Build Coastguard Worker 
2004*8975f5c5SAndroid Build Coastguard Worker         if (maxSwapInterval < std::numeric_limits<EGLint>::max())
2005*8975f5c5SAndroid Build Coastguard Worker         {
2006*8975f5c5SAndroid Build Coastguard Worker             std::vector<EGLint> max1SwapAttribs = {EGL_SWAP_INTERVAL_ANGLE, maxSwapInterval + 1};
2007*8975f5c5SAndroid Build Coastguard Worker             initializeWindowSurfaceWithAttribs(mConfig, max1SwapAttribs, EGL_BAD_ATTRIBUTE);
2008*8975f5c5SAndroid Build Coastguard Worker         }
2009*8975f5c5SAndroid Build Coastguard Worker 
2010*8975f5c5SAndroid Build Coastguard Worker         // Test valid min/max usage.
2011*8975f5c5SAndroid Build Coastguard Worker         {
2012*8975f5c5SAndroid Build Coastguard Worker             std::vector<EGLint> minSwapAttribs = {EGL_SWAP_INTERVAL_ANGLE, minSwapInterval};
2013*8975f5c5SAndroid Build Coastguard Worker             initializeWindowSurfaceWithAttribs(mConfig, minSwapAttribs, EGL_SUCCESS);
2014*8975f5c5SAndroid Build Coastguard Worker             drawQuadThenTearDown();
2015*8975f5c5SAndroid Build Coastguard Worker         }
2016*8975f5c5SAndroid Build Coastguard Worker 
2017*8975f5c5SAndroid Build Coastguard Worker         if (minSwapInterval != maxSwapInterval)
2018*8975f5c5SAndroid Build Coastguard Worker         {
2019*8975f5c5SAndroid Build Coastguard Worker             std::vector<EGLint> maxSwapAttribs = {EGL_SWAP_INTERVAL_ANGLE, maxSwapInterval};
2020*8975f5c5SAndroid Build Coastguard Worker             initializeWindowSurfaceWithAttribs(mConfig, maxSwapAttribs, EGL_SUCCESS);
2021*8975f5c5SAndroid Build Coastguard Worker             drawQuadThenTearDown();
2022*8975f5c5SAndroid Build Coastguard Worker         }
2023*8975f5c5SAndroid Build Coastguard Worker     }
2024*8975f5c5SAndroid Build Coastguard Worker     else
2025*8975f5c5SAndroid Build Coastguard Worker     {
2026*8975f5c5SAndroid Build Coastguard Worker         // Test extension unavailable error.
2027*8975f5c5SAndroid Build Coastguard Worker         std::vector<EGLint> swapInterval1Attribs = {EGL_SWAP_INTERVAL_ANGLE, 1};
2028*8975f5c5SAndroid Build Coastguard Worker         initializeWindowSurfaceWithAttribs(mConfig, swapInterval1Attribs, EGL_BAD_ATTRIBUTE);
2029*8975f5c5SAndroid Build Coastguard Worker     }
2030*8975f5c5SAndroid Build Coastguard Worker }
2031*8975f5c5SAndroid Build Coastguard Worker 
2032*8975f5c5SAndroid Build Coastguard Worker // Test that setting a surface's timestamp attribute works when the extension
2033*8975f5c5SAndroid Build Coastguard Worker // EGL_ANGLE_timestamp_surface_attribute is supported.
TEST_P(EGLSurfaceTest,TimestampSurfaceAttribute)2034*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, TimestampSurfaceAttribute)
2035*8975f5c5SAndroid Build Coastguard Worker {
2036*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
2037*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
2038*8975f5c5SAndroid Build Coastguard Worker     mConfig = chooseDefaultConfig(true);
2039*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mConfig, nullptr);
2040*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(mConfig);
2041*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
2042*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
2043*8975f5c5SAndroid Build Coastguard Worker 
2044*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext));
2045*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2046*8975f5c5SAndroid Build Coastguard Worker 
2047*8975f5c5SAndroid Build Coastguard Worker     const bool extensionSupported =
2048*8975f5c5SAndroid Build Coastguard Worker         IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANDROID_get_frame_timestamps") ||
2049*8975f5c5SAndroid Build Coastguard Worker         IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_timestamp_surface_attribute");
2050*8975f5c5SAndroid Build Coastguard Worker 
2051*8975f5c5SAndroid Build Coastguard Worker     EGLBoolean setSurfaceAttrib =
2052*8975f5c5SAndroid Build Coastguard Worker         eglSurfaceAttrib(mDisplay, mWindowSurface, EGL_TIMESTAMPS_ANDROID, EGL_TRUE);
2053*8975f5c5SAndroid Build Coastguard Worker 
2054*8975f5c5SAndroid Build Coastguard Worker     if (extensionSupported)
2055*8975f5c5SAndroid Build Coastguard Worker     {
2056*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(setSurfaceAttrib);
2057*8975f5c5SAndroid Build Coastguard Worker 
2058*8975f5c5SAndroid Build Coastguard Worker         // Swap so the swapchain gets created.
2059*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 1.0, 1.0, 1.0);
2060*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2061*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, mWindowSurface));
2062*8975f5c5SAndroid Build Coastguard Worker 
2063*8975f5c5SAndroid Build Coastguard Worker         // Query to confirm the attribute persists across swaps.
2064*8975f5c5SAndroid Build Coastguard Worker         EGLint timestampEnabled = 0;
2065*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(
2066*8975f5c5SAndroid Build Coastguard Worker             eglQuerySurface(mDisplay, mWindowSurface, EGL_TIMESTAMPS_ANDROID, &timestampEnabled));
2067*8975f5c5SAndroid Build Coastguard Worker         EXPECT_NE(timestampEnabled, 0);
2068*8975f5c5SAndroid Build Coastguard Worker 
2069*8975f5c5SAndroid Build Coastguard Worker         // Resize window and swap.
2070*8975f5c5SAndroid Build Coastguard Worker         mOSWindow->resize(256, 256);
2071*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 1.0, 1.0, 1.0);
2072*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2073*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, mWindowSurface));
2074*8975f5c5SAndroid Build Coastguard Worker 
2075*8975f5c5SAndroid Build Coastguard Worker         // Query to confirm the attribute persists across swapchain recreations.
2076*8975f5c5SAndroid Build Coastguard Worker         timestampEnabled = 0;
2077*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(
2078*8975f5c5SAndroid Build Coastguard Worker             eglQuerySurface(mDisplay, mWindowSurface, EGL_TIMESTAMPS_ANDROID, &timestampEnabled));
2079*8975f5c5SAndroid Build Coastguard Worker         EXPECT_NE(timestampEnabled, 0);
2080*8975f5c5SAndroid Build Coastguard Worker     }
2081*8975f5c5SAndroid Build Coastguard Worker     else
2082*8975f5c5SAndroid Build Coastguard Worker     {
2083*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_FALSE(setSurfaceAttrib);
2084*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_ERROR(EGL_BAD_ATTRIBUTE);
2085*8975f5c5SAndroid Build Coastguard Worker     }
2086*8975f5c5SAndroid Build Coastguard Worker 
2087*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
2088*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2089*8975f5c5SAndroid Build Coastguard Worker }
2090*8975f5c5SAndroid Build Coastguard Worker 
TEST_P(EGLSingleBufferTest,OnCreateWindowSurface)2091*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, OnCreateWindowSurface)
2092*8975f5c5SAndroid Build Coastguard Worker {
2093*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2094*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2095*8975f5c5SAndroid Build Coastguard Worker 
2096*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2097*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2098*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2099*8975f5c5SAndroid Build Coastguard Worker 
2100*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2101*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2102*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2103*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2104*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_SINGLE_BUFFER));
2105*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2106*8975f5c5SAndroid Build Coastguard Worker 
2107*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2108*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2109*8975f5c5SAndroid Build Coastguard Worker 
2110*8975f5c5SAndroid Build Coastguard Worker     EGLint actualRenderbuffer;
2111*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglQueryContext(mDisplay, context, EGL_RENDER_BUFFER, &actualRenderbuffer));
2112*8975f5c5SAndroid Build Coastguard Worker     if (actualRenderbuffer == EGL_SINGLE_BUFFER)
2113*8975f5c5SAndroid Build Coastguard Worker     {
2114*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(actualRenderbuffer == EGL_SINGLE_BUFFER);
2115*8975f5c5SAndroid Build Coastguard Worker 
2116*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.0, 1.0, 0.0, 1.0);
2117*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2118*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2119*8975f5c5SAndroid Build Coastguard Worker         ASSERT_GL_NO_ERROR();
2120*8975f5c5SAndroid Build Coastguard Worker         // Flush should result in update of screen. Must be visually confirmed.
2121*8975f5c5SAndroid Build Coastguard Worker         // Pixel test for automation.
2122*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
2123*8975f5c5SAndroid Build Coastguard Worker     }
2124*8975f5c5SAndroid Build Coastguard Worker     else
2125*8975f5c5SAndroid Build Coastguard Worker     {
2126*8975f5c5SAndroid Build Coastguard Worker         std::cout << "SKIP test, no EGL_SINGLE_BUFFER support." << std::endl;
2127*8975f5c5SAndroid Build Coastguard Worker     }
2128*8975f5c5SAndroid Build Coastguard Worker 
2129*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2130*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2131*8975f5c5SAndroid Build Coastguard Worker 
2132*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2133*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2134*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2135*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2136*8975f5c5SAndroid Build Coastguard Worker 
2137*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2138*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2139*8975f5c5SAndroid Build Coastguard Worker }
2140*8975f5c5SAndroid Build Coastguard Worker 
TEST_P(EGLSingleBufferTest,OnSetSurfaceAttrib)2141*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, OnSetSurfaceAttrib)
2142*8975f5c5SAndroid Build Coastguard Worker {
2143*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2144*8975f5c5SAndroid Build Coastguard Worker 
2145*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2146*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2147*8975f5c5SAndroid Build Coastguard Worker 
2148*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2149*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2150*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2151*8975f5c5SAndroid Build Coastguard Worker 
2152*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2153*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2154*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2155*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2156*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2157*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2158*8975f5c5SAndroid Build Coastguard Worker 
2159*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2160*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2161*8975f5c5SAndroid Build Coastguard Worker 
2162*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2163*8975f5c5SAndroid Build Coastguard Worker     {
2164*8975f5c5SAndroid Build Coastguard Worker         // Transition into EGL_SINGLE_BUFFER mode.
2165*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 1.0, 1.0, 1.0);
2166*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2167*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, surface));
2168*8975f5c5SAndroid Build Coastguard Worker 
2169*8975f5c5SAndroid Build Coastguard Worker         EGLint actualRenderbuffer;
2170*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglQueryContext(mDisplay, context, EGL_RENDER_BUFFER, &actualRenderbuffer));
2171*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(actualRenderbuffer == EGL_SINGLE_BUFFER);
2172*8975f5c5SAndroid Build Coastguard Worker 
2173*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.0, 1.0, 0.0, 1.0);
2174*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2175*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2176*8975f5c5SAndroid Build Coastguard Worker         // Flush should result in update of screen. Must be visually confirmed Green window.
2177*8975f5c5SAndroid Build Coastguard Worker 
2178*8975f5c5SAndroid Build Coastguard Worker         // Check color for automation.
2179*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
2180*8975f5c5SAndroid Build Coastguard Worker 
2181*8975f5c5SAndroid Build Coastguard Worker         // Switch back to EGL_BACK_BUFFEr and check.
2182*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_BACK_BUFFER));
2183*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 1.0, 1.0, 1.0);
2184*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2185*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, surface));
2186*8975f5c5SAndroid Build Coastguard Worker 
2187*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglQueryContext(mDisplay, context, EGL_RENDER_BUFFER, &actualRenderbuffer));
2188*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(actualRenderbuffer == EGL_BACK_BUFFER);
2189*8975f5c5SAndroid Build Coastguard Worker 
2190*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 0.0, 0.0, 1.0);
2191*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2192*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red);
2193*8975f5c5SAndroid Build Coastguard Worker     }
2194*8975f5c5SAndroid Build Coastguard Worker     else
2195*8975f5c5SAndroid Build Coastguard Worker     {
2196*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2197*8975f5c5SAndroid Build Coastguard Worker     }
2198*8975f5c5SAndroid Build Coastguard Worker 
2199*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2200*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2201*8975f5c5SAndroid Build Coastguard Worker 
2202*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2203*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2204*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2205*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2206*8975f5c5SAndroid Build Coastguard Worker 
2207*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2208*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2209*8975f5c5SAndroid Build Coastguard Worker }
2210*8975f5c5SAndroid Build Coastguard Worker 
drawAndSwap(EGLSurface & surface,EGLDisplay & display,uint32_t color,bool flush)2211*8975f5c5SAndroid Build Coastguard Worker uint32_t EGLSingleBufferTest::drawAndSwap(EGLSurface &surface,
2212*8975f5c5SAndroid Build Coastguard Worker                                           EGLDisplay &display,
2213*8975f5c5SAndroid Build Coastguard Worker                                           uint32_t color,
2214*8975f5c5SAndroid Build Coastguard Worker                                           bool flush)
2215*8975f5c5SAndroid Build Coastguard Worker {
2216*8975f5c5SAndroid Build Coastguard Worker     ASSERT(color < 256);
2217*8975f5c5SAndroid Build Coastguard Worker 
2218*8975f5c5SAndroid Build Coastguard Worker     glClearColor((float)color / 255.f, (float)color / 255.f, (float)color / 255.f,
2219*8975f5c5SAndroid Build Coastguard Worker                  (float)color / 255.f);
2220*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
2221*8975f5c5SAndroid Build Coastguard Worker 
2222*8975f5c5SAndroid Build Coastguard Worker     if (flush)
2223*8975f5c5SAndroid Build Coastguard Worker     {
2224*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2225*8975f5c5SAndroid Build Coastguard Worker     }
2226*8975f5c5SAndroid Build Coastguard Worker     else
2227*8975f5c5SAndroid Build Coastguard Worker     {
2228*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(display, surface);
2229*8975f5c5SAndroid Build Coastguard Worker     }
2230*8975f5c5SAndroid Build Coastguard Worker 
2231*8975f5c5SAndroid Build Coastguard Worker     return (color | color << 8 | color << 16 | color << 24);
2232*8975f5c5SAndroid Build Coastguard Worker }
2233*8975f5c5SAndroid Build Coastguard Worker 
2234*8975f5c5SAndroid Build Coastguard Worker // Replicate dEQP-EGL.functional.mutable_render_buffer#basic
TEST_P(EGLSingleBufferTest,MutableRenderBuffer)2235*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, MutableRenderBuffer)
2236*8975f5c5SAndroid Build Coastguard Worker {
2237*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2238*8975f5c5SAndroid Build Coastguard Worker 
2239*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config       = EGL_NO_CONFIG_KHR;
2240*8975f5c5SAndroid Build Coastguard Worker     const EGLint attribs[] = {EGL_RED_SIZE,
2241*8975f5c5SAndroid Build Coastguard Worker                               8,
2242*8975f5c5SAndroid Build Coastguard Worker                               EGL_GREEN_SIZE,
2243*8975f5c5SAndroid Build Coastguard Worker                               8,
2244*8975f5c5SAndroid Build Coastguard Worker                               EGL_BLUE_SIZE,
2245*8975f5c5SAndroid Build Coastguard Worker                               8,
2246*8975f5c5SAndroid Build Coastguard Worker                               EGL_ALPHA_SIZE,
2247*8975f5c5SAndroid Build Coastguard Worker                               8,
2248*8975f5c5SAndroid Build Coastguard Worker                               EGL_SURFACE_TYPE,
2249*8975f5c5SAndroid Build Coastguard Worker                               EGL_WINDOW_BIT | EGL_MUTABLE_RENDER_BUFFER_BIT_KHR,
2250*8975f5c5SAndroid Build Coastguard Worker                               EGL_RENDERABLE_TYPE,
2251*8975f5c5SAndroid Build Coastguard Worker                               EGL_OPENGL_ES2_BIT,
2252*8975f5c5SAndroid Build Coastguard Worker                               EGL_NONE};
2253*8975f5c5SAndroid Build Coastguard Worker     EGLint count           = 0;
2254*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!eglChooseConfig(mDisplay, attribs, &config, 1, &count));
2255*8975f5c5SAndroid Build Coastguard Worker 
2256*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2257*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2258*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2259*8975f5c5SAndroid Build Coastguard Worker 
2260*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2261*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2262*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2263*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2264*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2265*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2266*8975f5c5SAndroid Build Coastguard Worker 
2267*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2268*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2269*8975f5c5SAndroid Build Coastguard Worker 
2270*8975f5c5SAndroid Build Coastguard Worker     int frameNumber = 1;
2271*8975f5c5SAndroid Build Coastguard Worker 
2272*8975f5c5SAndroid Build Coastguard Worker     // run a few back-buffered frames
2273*8975f5c5SAndroid Build Coastguard Worker     for (; frameNumber < 5; frameNumber++)
2274*8975f5c5SAndroid Build Coastguard Worker     {
2275*8975f5c5SAndroid Build Coastguard Worker         drawAndSwap(surface, mDisplay, frameNumber, false);
2276*8975f5c5SAndroid Build Coastguard Worker     }
2277*8975f5c5SAndroid Build Coastguard Worker 
2278*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2279*8975f5c5SAndroid Build Coastguard Worker     {
2280*8975f5c5SAndroid Build Coastguard Worker         drawAndSwap(surface, mDisplay, frameNumber, false);
2281*8975f5c5SAndroid Build Coastguard Worker         frameNumber++;
2282*8975f5c5SAndroid Build Coastguard Worker 
2283*8975f5c5SAndroid Build Coastguard Worker         // test a few single-buffered frames
2284*8975f5c5SAndroid Build Coastguard Worker         for (; frameNumber < 10; frameNumber++)
2285*8975f5c5SAndroid Build Coastguard Worker         {
2286*8975f5c5SAndroid Build Coastguard Worker             uint32_t backBufferPixel  = 0xFFFFFFFF;
2287*8975f5c5SAndroid Build Coastguard Worker             uint32_t frontBufferPixel = drawAndSwap(surface, mDisplay, frameNumber, true);
2288*8975f5c5SAndroid Build Coastguard Worker             glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &backBufferPixel);
2289*8975f5c5SAndroid Build Coastguard Worker             EXPECT_EQ(backBufferPixel, frontBufferPixel);
2290*8975f5c5SAndroid Build Coastguard Worker         }
2291*8975f5c5SAndroid Build Coastguard Worker     }
2292*8975f5c5SAndroid Build Coastguard Worker 
2293*8975f5c5SAndroid Build Coastguard Worker     else
2294*8975f5c5SAndroid Build Coastguard Worker     {
2295*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2296*8975f5c5SAndroid Build Coastguard Worker     }
2297*8975f5c5SAndroid Build Coastguard Worker 
2298*8975f5c5SAndroid Build Coastguard Worker     // switch back to back-buffer rendering
2299*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_BACK_BUFFER))
2300*8975f5c5SAndroid Build Coastguard Worker     {
2301*8975f5c5SAndroid Build Coastguard Worker         for (; frameNumber < 14; frameNumber++)
2302*8975f5c5SAndroid Build Coastguard Worker         {
2303*8975f5c5SAndroid Build Coastguard Worker             drawAndSwap(surface, mDisplay, frameNumber, false);
2304*8975f5c5SAndroid Build Coastguard Worker         }
2305*8975f5c5SAndroid Build Coastguard Worker     }
2306*8975f5c5SAndroid Build Coastguard Worker     else
2307*8975f5c5SAndroid Build Coastguard Worker     {
2308*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_BACK_BUFFER mode is not supported." << std::endl;
2309*8975f5c5SAndroid Build Coastguard Worker     }
2310*8975f5c5SAndroid Build Coastguard Worker 
2311*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2312*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2313*8975f5c5SAndroid Build Coastguard Worker 
2314*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2315*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2316*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2317*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2318*8975f5c5SAndroid Build Coastguard Worker 
2319*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2320*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2321*8975f5c5SAndroid Build Coastguard Worker }
2322*8975f5c5SAndroid Build Coastguard Worker 
2323*8975f5c5SAndroid Build Coastguard Worker // Tests bug with incorrect ImageLayout::SharedPresent barrier.
TEST_P(EGLSingleBufferTest,SharedPresentBarrier)2324*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, SharedPresentBarrier)
2325*8975f5c5SAndroid Build Coastguard Worker {
2326*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2327*8975f5c5SAndroid Build Coastguard Worker 
2328*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2329*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2330*8975f5c5SAndroid Build Coastguard Worker 
2331*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2332*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2333*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2334*8975f5c5SAndroid Build Coastguard Worker 
2335*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2336*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2337*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2338*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2339*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2340*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2341*8975f5c5SAndroid Build Coastguard Worker 
2342*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2343*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2344*8975f5c5SAndroid Build Coastguard Worker 
2345*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2346*8975f5c5SAndroid Build Coastguard Worker     {
2347*8975f5c5SAndroid Build Coastguard Worker         // Transition into EGL_SINGLE_BUFFER mode.
2348*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 1.0, 1.0, 1.0);
2349*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2350*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, surface));
2351*8975f5c5SAndroid Build Coastguard Worker 
2352*8975f5c5SAndroid Build Coastguard Worker         EGLint actualRenderbuffer;
2353*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglQueryContext(mDisplay, context, EGL_RENDER_BUFFER, &actualRenderbuffer));
2354*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(actualRenderbuffer == EGL_SINGLE_BUFFER);
2355*8975f5c5SAndroid Build Coastguard Worker 
2356*8975f5c5SAndroid Build Coastguard Worker         for (int i = 0; i < 5; ++i)
2357*8975f5c5SAndroid Build Coastguard Worker         {
2358*8975f5c5SAndroid Build Coastguard Worker             GLColor testColor(rand() % 256, rand() % 256, rand() % 256, 255);
2359*8975f5c5SAndroid Build Coastguard Worker             angle::Vector4 clearColor = testColor.toNormalizedVector();
2360*8975f5c5SAndroid Build Coastguard Worker             glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
2361*8975f5c5SAndroid Build Coastguard Worker             glClear(GL_COLOR_BUFFER_BIT);
2362*8975f5c5SAndroid Build Coastguard Worker             // Skip flush because present operations may add other barriers that will make appear
2363*8975f5c5SAndroid Build Coastguard Worker             // that everything works as expected.
2364*8975f5c5SAndroid Build Coastguard Worker 
2365*8975f5c5SAndroid Build Coastguard Worker             // Check color without flush - may get invalid result if have incorrect barrier bug.
2366*8975f5c5SAndroid Build Coastguard Worker             EXPECT_PIXEL_COLOR_EQ(1, 1, testColor);
2367*8975f5c5SAndroid Build Coastguard Worker         }
2368*8975f5c5SAndroid Build Coastguard Worker     }
2369*8975f5c5SAndroid Build Coastguard Worker     else
2370*8975f5c5SAndroid Build Coastguard Worker     {
2371*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2372*8975f5c5SAndroid Build Coastguard Worker     }
2373*8975f5c5SAndroid Build Coastguard Worker 
2374*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2375*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2376*8975f5c5SAndroid Build Coastguard Worker 
2377*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2378*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2379*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2380*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2381*8975f5c5SAndroid Build Coastguard Worker 
2382*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2383*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2384*8975f5c5SAndroid Build Coastguard Worker }
2385*8975f5c5SAndroid Build Coastguard Worker 
2386*8975f5c5SAndroid Build Coastguard Worker // Tests scissored clear on single buffer surface
TEST_P(EGLSingleBufferTest,ScissoredClear)2387*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, ScissoredClear)
2388*8975f5c5SAndroid Build Coastguard Worker {
2389*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2390*8975f5c5SAndroid Build Coastguard Worker 
2391*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2392*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2393*8975f5c5SAndroid Build Coastguard Worker 
2394*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2395*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2396*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2397*8975f5c5SAndroid Build Coastguard Worker 
2398*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2399*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2400*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2401*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2402*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2403*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2404*8975f5c5SAndroid Build Coastguard Worker 
2405*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2406*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2407*8975f5c5SAndroid Build Coastguard Worker 
2408*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2409*8975f5c5SAndroid Build Coastguard Worker     {
2410*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, surface);
2411*8975f5c5SAndroid Build Coastguard Worker 
2412*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2413*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2414*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2415*8975f5c5SAndroid Build Coastguard Worker 
2416*8975f5c5SAndroid Build Coastguard Worker         glEnable(GL_SCISSOR_TEST);
2417*8975f5c5SAndroid Build Coastguard Worker         glScissor(1, 1, 10, 10);
2418*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
2419*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2420*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2421*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2422*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(2, 2, GLColor::green);
2423*8975f5c5SAndroid Build Coastguard Worker     }
2424*8975f5c5SAndroid Build Coastguard Worker     else
2425*8975f5c5SAndroid Build Coastguard Worker     {
2426*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2427*8975f5c5SAndroid Build Coastguard Worker     }
2428*8975f5c5SAndroid Build Coastguard Worker 
2429*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2430*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2431*8975f5c5SAndroid Build Coastguard Worker 
2432*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2433*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2434*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2435*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2436*8975f5c5SAndroid Build Coastguard Worker 
2437*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2438*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2439*8975f5c5SAndroid Build Coastguard Worker }
2440*8975f5c5SAndroid Build Coastguard Worker 
2441*8975f5c5SAndroid Build Coastguard Worker // Tests scissored clear on single buffer surface
TEST_P(EGLSingleBufferTest,ScissoredDraw)2442*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, ScissoredDraw)
2443*8975f5c5SAndroid Build Coastguard Worker {
2444*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2445*8975f5c5SAndroid Build Coastguard Worker 
2446*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2447*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2448*8975f5c5SAndroid Build Coastguard Worker 
2449*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2450*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2451*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2452*8975f5c5SAndroid Build Coastguard Worker 
2453*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2454*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2455*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2456*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2457*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2458*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2459*8975f5c5SAndroid Build Coastguard Worker 
2460*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2461*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2462*8975f5c5SAndroid Build Coastguard Worker 
2463*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2464*8975f5c5SAndroid Build Coastguard Worker     {
2465*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, surface);
2466*8975f5c5SAndroid Build Coastguard Worker 
2467*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2468*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2469*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2470*8975f5c5SAndroid Build Coastguard Worker 
2471*8975f5c5SAndroid Build Coastguard Worker         glEnable(GL_SCISSOR_TEST);
2472*8975f5c5SAndroid Build Coastguard Worker         glScissor(1, 1, 10, 10);
2473*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
2474*8975f5c5SAndroid Build Coastguard Worker         ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2475*8975f5c5SAndroid Build Coastguard Worker         drawQuad(greenProgram, essl1_shaders::PositionAttrib(), 0.5f);
2476*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2477*8975f5c5SAndroid Build Coastguard Worker         glDisable(GL_SCISSOR_TEST);
2478*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2479*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(2, 2, GLColor::green);
2480*8975f5c5SAndroid Build Coastguard Worker     }
2481*8975f5c5SAndroid Build Coastguard Worker     else
2482*8975f5c5SAndroid Build Coastguard Worker     {
2483*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2484*8975f5c5SAndroid Build Coastguard Worker     }
2485*8975f5c5SAndroid Build Coastguard Worker 
2486*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2487*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2488*8975f5c5SAndroid Build Coastguard Worker 
2489*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2490*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2491*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2492*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2493*8975f5c5SAndroid Build Coastguard Worker 
2494*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2495*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2496*8975f5c5SAndroid Build Coastguard Worker }
2497*8975f5c5SAndroid Build Coastguard Worker 
2498*8975f5c5SAndroid Build Coastguard Worker // Tests that "one off" submission is waited before destroying the surface.
TEST_P(EGLSingleBufferTest,WaitOneOffSubmission)2499*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, WaitOneOffSubmission)
2500*8975f5c5SAndroid Build Coastguard Worker {
2501*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2502*8975f5c5SAndroid Build Coastguard Worker 
2503*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2504*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2505*8975f5c5SAndroid Build Coastguard Worker 
2506*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2507*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2508*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2509*8975f5c5SAndroid Build Coastguard Worker 
2510*8975f5c5SAndroid Build Coastguard Worker     EGLContext context2 = EGL_NO_CONTEXT;
2511*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context2));
2512*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2513*8975f5c5SAndroid Build Coastguard Worker 
2514*8975f5c5SAndroid Build Coastguard Worker     const EGLint pbufferSurfaceAttrs[] = {
2515*8975f5c5SAndroid Build Coastguard Worker         EGL_WIDTH, 1024, EGL_HEIGHT, 1024, EGL_NONE,
2516*8975f5c5SAndroid Build Coastguard Worker     };
2517*8975f5c5SAndroid Build Coastguard Worker     EGLSurface pbufferSurface = eglCreatePbufferSurface(mDisplay, config, pbufferSurfaceAttrs);
2518*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreatePbufferSurface failed.";
2519*8975f5c5SAndroid Build Coastguard Worker 
2520*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2521*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2522*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2523*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2524*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2525*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2526*8975f5c5SAndroid Build Coastguard Worker 
2527*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2528*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2529*8975f5c5SAndroid Build Coastguard Worker 
2530*8975f5c5SAndroid Build Coastguard Worker     // Query age for the first time to avoid submitting debug information a second time.
2531*8975f5c5SAndroid Build Coastguard Worker     EGLint age = 0;
2532*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglQuerySurface(mDisplay, surface, EGL_BUFFER_AGE_EXT, &age));
2533*8975f5c5SAndroid Build Coastguard Worker 
2534*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2535*8975f5c5SAndroid Build Coastguard Worker     {
2536*8975f5c5SAndroid Build Coastguard Worker         // Transition into EGL_SINGLE_BUFFER mode.
2537*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, surface));
2538*8975f5c5SAndroid Build Coastguard Worker 
2539*8975f5c5SAndroid Build Coastguard Worker         // Submit heavy work to the GPU before querying the buffer age.
2540*8975f5c5SAndroid Build Coastguard Worker         std::thread([this, context2, pbufferSurface]() {
2541*8975f5c5SAndroid Build Coastguard Worker             EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, pbufferSurface, pbufferSurface, context2));
2542*8975f5c5SAndroid Build Coastguard Worker             ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2543*8975f5c5SAndroid Build Coastguard Worker 
2544*8975f5c5SAndroid Build Coastguard Worker             ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2545*8975f5c5SAndroid Build Coastguard Worker             drawQuadInstanced(greenProgram, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, false,
2546*8975f5c5SAndroid Build Coastguard Worker                               1000);
2547*8975f5c5SAndroid Build Coastguard Worker 
2548*8975f5c5SAndroid Build Coastguard Worker             EXPECT_EGL_TRUE(
2549*8975f5c5SAndroid Build Coastguard Worker                 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
2550*8975f5c5SAndroid Build Coastguard Worker             ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2551*8975f5c5SAndroid Build Coastguard Worker         }).join();
2552*8975f5c5SAndroid Build Coastguard Worker 
2553*8975f5c5SAndroid Build Coastguard Worker         // Querying the buffer age should perform first acquire of the image and "one off"
2554*8975f5c5SAndroid Build Coastguard Worker         // submission to change image layout to the VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.
2555*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglQuerySurface(mDisplay, surface, EGL_BUFFER_AGE_EXT, &age));
2556*8975f5c5SAndroid Build Coastguard Worker     }
2557*8975f5c5SAndroid Build Coastguard Worker     else
2558*8975f5c5SAndroid Build Coastguard Worker     {
2559*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2560*8975f5c5SAndroid Build Coastguard Worker     }
2561*8975f5c5SAndroid Build Coastguard Worker 
2562*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2563*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2564*8975f5c5SAndroid Build Coastguard Worker 
2565*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2566*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2567*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2568*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2569*8975f5c5SAndroid Build Coastguard Worker 
2570*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, pbufferSurface);
2571*8975f5c5SAndroid Build Coastguard Worker     pbufferSurface = EGL_NO_SURFACE;
2572*8975f5c5SAndroid Build Coastguard Worker 
2573*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2574*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2575*8975f5c5SAndroid Build Coastguard Worker 
2576*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context2);
2577*8975f5c5SAndroid Build Coastguard Worker     context2 = EGL_NO_CONTEXT;
2578*8975f5c5SAndroid Build Coastguard Worker }
2579*8975f5c5SAndroid Build Coastguard Worker 
2580*8975f5c5SAndroid Build Coastguard Worker // Checks that |WindowSurfaceVk::swamImpl| acquires and process next swapchain image in case of
2581*8975f5c5SAndroid Build Coastguard Worker // shared present mode, when called from flush.
TEST_P(EGLSingleBufferTest,AcquireImageFromSwapImpl)2582*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSingleBufferTest, AcquireImageFromSwapImpl)
2583*8975f5c5SAndroid Build Coastguard Worker {
2584*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2585*8975f5c5SAndroid Build Coastguard Worker 
2586*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2587*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2588*8975f5c5SAndroid Build Coastguard Worker 
2589*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2590*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2591*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2592*8975f5c5SAndroid Build Coastguard Worker 
2593*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2594*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2595*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2596*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2597*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2598*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2599*8975f5c5SAndroid Build Coastguard Worker 
2600*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2601*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2602*8975f5c5SAndroid Build Coastguard Worker 
2603*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2604*8975f5c5SAndroid Build Coastguard Worker     {
2605*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, surface);
2606*8975f5c5SAndroid Build Coastguard Worker 
2607*8975f5c5SAndroid Build Coastguard Worker         ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2608*8975f5c5SAndroid Build Coastguard Worker 
2609*8975f5c5SAndroid Build Coastguard Worker         // Draw into the single buffered surface.
2610*8975f5c5SAndroid Build Coastguard Worker         // Acquire next swapchain image should be deferred (Vulkan back-end).
2611*8975f5c5SAndroid Build Coastguard Worker         drawQuad(greenProgram, essl1_shaders::PositionAttrib(), 0.5f);
2612*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2613*8975f5c5SAndroid Build Coastguard Worker 
2614*8975f5c5SAndroid Build Coastguard Worker         // Prepare auxilary framebuffer.
2615*8975f5c5SAndroid Build Coastguard Worker         GLRenderbuffer renderBuffer;
2616*8975f5c5SAndroid Build Coastguard Worker         GLFramebuffer framebuffer;
2617*8975f5c5SAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
2618*8975f5c5SAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
2619*8975f5c5SAndroid Build Coastguard Worker         glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 50, 50);
2620*8975f5c5SAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2621*8975f5c5SAndroid Build Coastguard Worker                                   renderBuffer);
2622*8975f5c5SAndroid Build Coastguard Worker         EXPECT_GL_NO_ERROR();
2623*8975f5c5SAndroid Build Coastguard Worker 
2624*8975f5c5SAndroid Build Coastguard Worker         // Draw into the auxilary framebuffer just to generate commands into the command buffers.
2625*8975f5c5SAndroid Build Coastguard Worker         // Otherwise below flush will be ignored.
2626*8975f5c5SAndroid Build Coastguard Worker         drawQuad(greenProgram, essl1_shaders::PositionAttrib(), 0.5f);
2627*8975f5c5SAndroid Build Coastguard Worker 
2628*8975f5c5SAndroid Build Coastguard Worker         // Switch back to the Windows Surface and perform flush.
2629*8975f5c5SAndroid Build Coastguard Worker         // In Vulkan back-end flush will translate into |swapImpl| call while acquire next swapchain
2630*8975f5c5SAndroid Build Coastguard Worker         // image is still deferred. |swapImpl| must perform the acquire in that case, otherwise
2631*8975f5c5SAndroid Build Coastguard Worker         // ASSERT will trigger in |present|.
2632*8975f5c5SAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, 0);
2633*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2634*8975f5c5SAndroid Build Coastguard Worker     }
2635*8975f5c5SAndroid Build Coastguard Worker     else
2636*8975f5c5SAndroid Build Coastguard Worker     {
2637*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2638*8975f5c5SAndroid Build Coastguard Worker     }
2639*8975f5c5SAndroid Build Coastguard Worker 
2640*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2641*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2642*8975f5c5SAndroid Build Coastguard Worker 
2643*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2644*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2645*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2646*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2647*8975f5c5SAndroid Build Coastguard Worker 
2648*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2649*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2650*8975f5c5SAndroid Build Coastguard Worker }
2651*8975f5c5SAndroid Build Coastguard Worker 
2652*8975f5c5SAndroid Build Coastguard Worker // Test that setting a surface to EGL_SINGLE_BUFFER after enabling
2653*8975f5c5SAndroid Build Coastguard Worker // EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID does not disable auto refresh
TEST_P(EGLAndroidAutoRefreshTest,Basic)2654*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLAndroidAutoRefreshTest, Basic)
2655*8975f5c5SAndroid Build Coastguard Worker {
2656*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(
2657*8975f5c5SAndroid Build Coastguard Worker         !IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANDROID_front_buffer_auto_refresh"));
2658*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2659*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsAndroid());
2660*8975f5c5SAndroid Build Coastguard Worker 
2661*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2662*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2663*8975f5c5SAndroid Build Coastguard Worker 
2664*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2665*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2666*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2667*8975f5c5SAndroid Build Coastguard Worker 
2668*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2669*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2670*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2671*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2672*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_BACK_BUFFER));
2673*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2674*8975f5c5SAndroid Build Coastguard Worker 
2675*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2676*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2677*8975f5c5SAndroid Build Coastguard Worker 
2678*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2679*8975f5c5SAndroid Build Coastguard Worker         eglSurfaceAttrib(mDisplay, surface, EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID, EGL_TRUE));
2680*8975f5c5SAndroid Build Coastguard Worker 
2681*8975f5c5SAndroid Build Coastguard Worker     if (eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER))
2682*8975f5c5SAndroid Build Coastguard Worker     {
2683*8975f5c5SAndroid Build Coastguard Worker         // Transition into EGL_SINGLE_BUFFER mode.
2684*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 1.0, 1.0, 1.0);
2685*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2686*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, surface));
2687*8975f5c5SAndroid Build Coastguard Worker 
2688*8975f5c5SAndroid Build Coastguard Worker         EGLint actualRenderbuffer;
2689*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglQueryContext(mDisplay, context, EGL_RENDER_BUFFER, &actualRenderbuffer));
2690*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(actualRenderbuffer == EGL_SINGLE_BUFFER);
2691*8975f5c5SAndroid Build Coastguard Worker 
2692*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.0, 1.0, 0.0, 1.0);
2693*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2694*8975f5c5SAndroid Build Coastguard Worker         glFlush();
2695*8975f5c5SAndroid Build Coastguard Worker         // Flush should result in update of screen. Must be visually confirmed Green window.
2696*8975f5c5SAndroid Build Coastguard Worker 
2697*8975f5c5SAndroid Build Coastguard Worker         // Check color for automation.
2698*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
2699*8975f5c5SAndroid Build Coastguard Worker 
2700*8975f5c5SAndroid Build Coastguard Worker         // Switch back to EGL_BACK_BUFFER and check.
2701*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSurfaceAttrib(mDisplay, surface, EGL_RENDER_BUFFER, EGL_BACK_BUFFER));
2702*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 1.0, 1.0, 1.0);
2703*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2704*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglSwapBuffers(mDisplay, surface));
2705*8975f5c5SAndroid Build Coastguard Worker 
2706*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(eglQueryContext(mDisplay, context, EGL_RENDER_BUFFER, &actualRenderbuffer));
2707*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(actualRenderbuffer == EGL_BACK_BUFFER);
2708*8975f5c5SAndroid Build Coastguard Worker 
2709*8975f5c5SAndroid Build Coastguard Worker         glClearColor(1.0, 0.0, 0.0, 1.0);
2710*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2711*8975f5c5SAndroid Build Coastguard Worker         EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red);
2712*8975f5c5SAndroid Build Coastguard Worker     }
2713*8975f5c5SAndroid Build Coastguard Worker     else
2714*8975f5c5SAndroid Build Coastguard Worker     {
2715*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2716*8975f5c5SAndroid Build Coastguard Worker     }
2717*8975f5c5SAndroid Build Coastguard Worker 
2718*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2719*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2720*8975f5c5SAndroid Build Coastguard Worker 
2721*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2722*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2723*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2724*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2725*8975f5c5SAndroid Build Coastguard Worker 
2726*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2727*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2728*8975f5c5SAndroid Build Coastguard Worker }
2729*8975f5c5SAndroid Build Coastguard Worker 
2730*8975f5c5SAndroid Build Coastguard Worker // Tests that CPU throttling unlocked call, added in the implicit swap buffers call, is executed.
TEST_P(EGLAndroidAutoRefreshTest,SwapCPUThrottling)2731*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLAndroidAutoRefreshTest, SwapCPUThrottling)
2732*8975f5c5SAndroid Build Coastguard Worker {
2733*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(
2734*8975f5c5SAndroid Build Coastguard Worker         !IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANDROID_front_buffer_auto_refresh"));
2735*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_mutable_render_buffer"));
2736*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsAndroid());
2737*8975f5c5SAndroid Build Coastguard Worker 
2738*8975f5c5SAndroid Build Coastguard Worker     // Use high resolution to increase GPU load.
2739*8975f5c5SAndroid Build Coastguard Worker     const EGLint kWidth  = 2048;
2740*8975f5c5SAndroid Build Coastguard Worker     const EGLint kHeight = 2048;
2741*8975f5c5SAndroid Build Coastguard Worker 
2742*8975f5c5SAndroid Build Coastguard Worker     // These settings are expected to trigger CPU throttling in present.
2743*8975f5c5SAndroid Build Coastguard Worker     constexpr size_t kFrameFlushCount   = 8;
2744*8975f5c5SAndroid Build Coastguard Worker     constexpr GLuint kDrawInstanceCount = 256;
2745*8975f5c5SAndroid Build Coastguard Worker 
2746*8975f5c5SAndroid Build Coastguard Worker     EGLConfig config = EGL_NO_CONFIG_KHR;
2747*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!chooseConfig(&config, true));
2748*8975f5c5SAndroid Build Coastguard Worker 
2749*8975f5c5SAndroid Build Coastguard Worker     EGLContext context = EGL_NO_CONTEXT;
2750*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(createContext(config, &context));
2751*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateContext failed.";
2752*8975f5c5SAndroid Build Coastguard Worker 
2753*8975f5c5SAndroid Build Coastguard Worker     EGLSurface surface = EGL_NO_SURFACE;
2754*8975f5c5SAndroid Build Coastguard Worker     OSWindow *osWindow = OSWindow::New();
2755*8975f5c5SAndroid Build Coastguard Worker     osWindow->initialize("EGLSingleBufferTest", kWidth, kHeight);
2756*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(
2757*8975f5c5SAndroid Build Coastguard Worker         createWindowSurface(config, osWindow->getNativeWindow(), &surface, EGL_SINGLE_BUFFER));
2758*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglCreateWindowSurface failed.";
2759*8975f5c5SAndroid Build Coastguard Worker 
2760*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, context));
2761*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed.";
2762*8975f5c5SAndroid Build Coastguard Worker 
2763*8975f5c5SAndroid Build Coastguard Worker     EGLint actualRenderbuffer;
2764*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglQueryContext(mDisplay, context, EGL_RENDER_BUFFER, &actualRenderbuffer));
2765*8975f5c5SAndroid Build Coastguard Worker     if (actualRenderbuffer == EGL_SINGLE_BUFFER)
2766*8975f5c5SAndroid Build Coastguard Worker     {
2767*8975f5c5SAndroid Build Coastguard Worker         // Enable auto refresh to prevent present from waiting on GPU.
2768*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_TRUE(
2769*8975f5c5SAndroid Build Coastguard Worker             eglSurfaceAttrib(mDisplay, surface, EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID, EGL_TRUE));
2770*8975f5c5SAndroid Build Coastguard Worker 
2771*8975f5c5SAndroid Build Coastguard Worker         ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
2772*8975f5c5SAndroid Build Coastguard Worker         glViewport(0, 0, kWidth, kHeight);
2773*8975f5c5SAndroid Build Coastguard Worker 
2774*8975f5c5SAndroid Build Coastguard Worker         for (size_t i = 0; i < kFrameFlushCount; ++i)
2775*8975f5c5SAndroid Build Coastguard Worker         {
2776*8975f5c5SAndroid Build Coastguard Worker             // Perform heavy draw call to load GPU.
2777*8975f5c5SAndroid Build Coastguard Worker             drawQuadInstanced(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, false,
2778*8975f5c5SAndroid Build Coastguard Worker                               kDrawInstanceCount);
2779*8975f5c5SAndroid Build Coastguard Worker             // This should cause implicit swap and possible CPU throttling in the tail call.
2780*8975f5c5SAndroid Build Coastguard Worker             glFlush();
2781*8975f5c5SAndroid Build Coastguard Worker         }
2782*8975f5c5SAndroid Build Coastguard Worker 
2783*8975f5c5SAndroid Build Coastguard Worker         // Tests same as the glFlush above.
2784*8975f5c5SAndroid Build Coastguard Worker         drawQuadInstanced(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, false,
2785*8975f5c5SAndroid Build Coastguard Worker                           kDrawInstanceCount);
2786*8975f5c5SAndroid Build Coastguard Worker         glFinish();
2787*8975f5c5SAndroid Build Coastguard Worker     }
2788*8975f5c5SAndroid Build Coastguard Worker     else
2789*8975f5c5SAndroid Build Coastguard Worker     {
2790*8975f5c5SAndroid Build Coastguard Worker         std::cout << "EGL_SINGLE_BUFFER mode is not supported." << std::endl;
2791*8975f5c5SAndroid Build Coastguard Worker     }
2792*8975f5c5SAndroid Build Coastguard Worker 
2793*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context));
2794*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS() << "eglMakeCurrent - uncurrent failed.";
2795*8975f5c5SAndroid Build Coastguard Worker 
2796*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, surface);
2797*8975f5c5SAndroid Build Coastguard Worker     surface = EGL_NO_SURFACE;
2798*8975f5c5SAndroid Build Coastguard Worker     osWindow->destroy();
2799*8975f5c5SAndroid Build Coastguard Worker     OSWindow::Delete(&osWindow);
2800*8975f5c5SAndroid Build Coastguard Worker 
2801*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, context);
2802*8975f5c5SAndroid Build Coastguard Worker     context = EGL_NO_CONTEXT;
2803*8975f5c5SAndroid Build Coastguard Worker }
2804*8975f5c5SAndroid Build Coastguard Worker 
runWaitSemaphoreTest(bool useSecondContext)2805*8975f5c5SAndroid Build Coastguard Worker void EGLSurfaceTest::runWaitSemaphoreTest(bool useSecondContext)
2806*8975f5c5SAndroid Build Coastguard Worker {
2807*8975f5c5SAndroid Build Coastguard Worker     // Note: This test requires visual inspection for rendering artifacts.
2808*8975f5c5SAndroid Build Coastguard Worker     // However, absence of artifacts does not guarantee that there is no problem.
2809*8975f5c5SAndroid Build Coastguard Worker 
2810*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
2811*8975f5c5SAndroid Build Coastguard Worker 
2812*8975f5c5SAndroid Build Coastguard Worker     constexpr int kInitialSize   = 64;
2813*8975f5c5SAndroid Build Coastguard Worker     constexpr int kWindowWidth   = 1080;
2814*8975f5c5SAndroid Build Coastguard Worker     constexpr int kWindowWHeight = 1920;
2815*8975f5c5SAndroid Build Coastguard Worker 
2816*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(kWindowWidth, kWindowWHeight);
2817*8975f5c5SAndroid Build Coastguard Worker 
2818*8975f5c5SAndroid Build Coastguard Worker     // Initialize an RGBA8 window and pbuffer surface
2819*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kSurfaceAttributes[] = {EGL_RED_SIZE,     8,
2820*8975f5c5SAndroid Build Coastguard Worker                                              EGL_GREEN_SIZE,   8,
2821*8975f5c5SAndroid Build Coastguard Worker                                              EGL_BLUE_SIZE,    8,
2822*8975f5c5SAndroid Build Coastguard Worker                                              EGL_ALPHA_SIZE,   8,
2823*8975f5c5SAndroid Build Coastguard Worker                                              EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
2824*8975f5c5SAndroid Build Coastguard Worker                                              EGL_NONE};
2825*8975f5c5SAndroid Build Coastguard Worker 
2826*8975f5c5SAndroid Build Coastguard Worker     EGLint configCount      = 0;
2827*8975f5c5SAndroid Build Coastguard Worker     EGLConfig surfaceConfig = nullptr;
2828*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, kSurfaceAttributes, &surfaceConfig, 1, &configCount));
2829*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(configCount, 0);
2830*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(surfaceConfig, nullptr);
2831*8975f5c5SAndroid Build Coastguard Worker 
2832*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(surfaceConfig);
2833*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
2834*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
2835*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mPbufferSurface, EGL_NO_SURFACE);
2836*8975f5c5SAndroid Build Coastguard Worker 
2837*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
2838*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
2839*8975f5c5SAndroid Build Coastguard Worker 
2840*8975f5c5SAndroid Build Coastguard Worker     ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
2841*8975f5c5SAndroid Build Coastguard Worker 
2842*8975f5c5SAndroid Build Coastguard Worker     if (useSecondContext)
2843*8975f5c5SAndroid Build Coastguard Worker     {
2844*8975f5c5SAndroid Build Coastguard Worker         ANGLE_SKIP_TEST_IF(!platformSupportsMultithreading());
2845*8975f5c5SAndroid Build Coastguard Worker         initializeSingleContext(&mSecondContext, 0);
2846*8975f5c5SAndroid Build Coastguard Worker     }
2847*8975f5c5SAndroid Build Coastguard Worker 
2848*8975f5c5SAndroid Build Coastguard Worker     ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
2849*8975f5c5SAndroid Build Coastguard Worker     glUseProgram(program);
2850*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
2851*8975f5c5SAndroid Build Coastguard Worker 
2852*8975f5c5SAndroid Build Coastguard Worker     GLint posAttrib = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
2853*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(posAttrib, -1);
2854*8975f5c5SAndroid Build Coastguard Worker     glEnableVertexAttribArray(posAttrib);
2855*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
2856*8975f5c5SAndroid Build Coastguard Worker 
2857*8975f5c5SAndroid Build Coastguard Worker     GLint colorUniformLocation = glGetUniformLocation(program, essl1_shaders::ColorUniform());
2858*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(colorUniformLocation, -1);
2859*8975f5c5SAndroid Build Coastguard Worker 
2860*8975f5c5SAndroid Build Coastguard Worker     constexpr int kFrameCount = 60 * 4;  // 4 sec @ 60Hz; 2 sec @ 120Hz;
2861*8975f5c5SAndroid Build Coastguard Worker     constexpr int kGridW      = 5;
2862*8975f5c5SAndroid Build Coastguard Worker     constexpr int kGridH      = 5;
2863*8975f5c5SAndroid Build Coastguard Worker     constexpr int kAnimDiv    = 20;
2864*8975f5c5SAndroid Build Coastguard Worker 
2865*8975f5c5SAndroid Build Coastguard Worker     for (int frame = 0; frame < kFrameCount; ++frame)
2866*8975f5c5SAndroid Build Coastguard Worker     {
2867*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
2868*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
2869*8975f5c5SAndroid Build Coastguard Worker         ASSERT_GL_NO_ERROR();
2870*8975f5c5SAndroid Build Coastguard Worker 
2871*8975f5c5SAndroid Build Coastguard Worker         for (int y = 0; y < kGridH; ++y)
2872*8975f5c5SAndroid Build Coastguard Worker         {
2873*8975f5c5SAndroid Build Coastguard Worker             // This should force "flushToPrimary()" each line in ANGLE
2874*8975f5c5SAndroid Build Coastguard Worker             GLuint query;
2875*8975f5c5SAndroid Build Coastguard Worker             glGenQueries(1, &query);
2876*8975f5c5SAndroid Build Coastguard Worker             ASSERT_GL_NO_ERROR();
2877*8975f5c5SAndroid Build Coastguard Worker             glBeginQuery(GL_TIME_ELAPSED_EXT, query);
2878*8975f5c5SAndroid Build Coastguard Worker             ASSERT_GL_NO_ERROR();
2879*8975f5c5SAndroid Build Coastguard Worker 
2880*8975f5c5SAndroid Build Coastguard Worker             for (int x = 0; x < kGridW; ++x)
2881*8975f5c5SAndroid Build Coastguard Worker             {
2882*8975f5c5SAndroid Build Coastguard Worker                 const int xc        = (x + frame / kAnimDiv) % kGridW;
2883*8975f5c5SAndroid Build Coastguard Worker                 const Vector4 color = {(xc + 0.5f) / kGridW, (y + 0.5f) / kGridH, 0.0f, 1.0f};
2884*8975f5c5SAndroid Build Coastguard Worker 
2885*8975f5c5SAndroid Build Coastguard Worker                 const GLfloat x0 = (x + 0.1f) / kGridW * 2.0f - 1.0f;
2886*8975f5c5SAndroid Build Coastguard Worker                 const GLfloat x1 = (x + 0.9f) / kGridW * 2.0f - 1.0f;
2887*8975f5c5SAndroid Build Coastguard Worker                 const GLfloat y0 = (y + 0.1f) / kGridH * 2.0f - 1.0f;
2888*8975f5c5SAndroid Build Coastguard Worker                 const GLfloat y1 = (y + 0.9f) / kGridH * 2.0f - 1.0f;
2889*8975f5c5SAndroid Build Coastguard Worker 
2890*8975f5c5SAndroid Build Coastguard Worker                 std::array<Vector3, 6> vertexData;
2891*8975f5c5SAndroid Build Coastguard Worker                 vertexData[0] = {x0, y1, 0.5f};
2892*8975f5c5SAndroid Build Coastguard Worker                 vertexData[1] = {x0, y0, 0.5f};
2893*8975f5c5SAndroid Build Coastguard Worker                 vertexData[2] = {x1, y1, 0.5f};
2894*8975f5c5SAndroid Build Coastguard Worker                 vertexData[3] = {x1, y1, 0.5f};
2895*8975f5c5SAndroid Build Coastguard Worker                 vertexData[4] = {x0, y0, 0.5f};
2896*8975f5c5SAndroid Build Coastguard Worker                 vertexData[5] = {x1, y0, 0.5f};
2897*8975f5c5SAndroid Build Coastguard Worker 
2898*8975f5c5SAndroid Build Coastguard Worker                 glUniform4f(colorUniformLocation, color.x(), color.y(), color.z(), color.w());
2899*8975f5c5SAndroid Build Coastguard Worker                 glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, vertexData.data());
2900*8975f5c5SAndroid Build Coastguard Worker                 glDrawArrays(GL_TRIANGLES, 0, 6);
2901*8975f5c5SAndroid Build Coastguard Worker                 ASSERT_GL_NO_ERROR();
2902*8975f5c5SAndroid Build Coastguard Worker             }
2903*8975f5c5SAndroid Build Coastguard Worker 
2904*8975f5c5SAndroid Build Coastguard Worker             glEndQuery(GL_TIME_ELAPSED_EXT);
2905*8975f5c5SAndroid Build Coastguard Worker             glDeleteQueries(1, &query);
2906*8975f5c5SAndroid Build Coastguard Worker             ASSERT_GL_NO_ERROR();
2907*8975f5c5SAndroid Build Coastguard Worker         }
2908*8975f5c5SAndroid Build Coastguard Worker 
2909*8975f5c5SAndroid Build Coastguard Worker         if (useSecondContext)
2910*8975f5c5SAndroid Build Coastguard Worker         {
2911*8975f5c5SAndroid Build Coastguard Worker             std::thread([this] {
2912*8975f5c5SAndroid Build Coastguard Worker                 eglBindAPI(EGL_OPENGL_ES_API);
2913*8975f5c5SAndroid Build Coastguard Worker                 ASSERT_EGL_SUCCESS();
2914*8975f5c5SAndroid Build Coastguard Worker                 eglMakeCurrent(mDisplay, mPbufferSurface, mPbufferSurface, mSecondContext);
2915*8975f5c5SAndroid Build Coastguard Worker                 ASSERT_EGL_SUCCESS();
2916*8975f5c5SAndroid Build Coastguard Worker                 glEnable(GL_SCISSOR_TEST);
2917*8975f5c5SAndroid Build Coastguard Worker                 glScissor(0, 0, 1, 1);
2918*8975f5c5SAndroid Build Coastguard Worker                 glClear(GL_COLOR_BUFFER_BIT);
2919*8975f5c5SAndroid Build Coastguard Worker                 ASSERT_GL_NO_ERROR();
2920*8975f5c5SAndroid Build Coastguard Worker                 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
2921*8975f5c5SAndroid Build Coastguard Worker                 ASSERT_EGL_SUCCESS();
2922*8975f5c5SAndroid Build Coastguard Worker             }).join();
2923*8975f5c5SAndroid Build Coastguard Worker         }
2924*8975f5c5SAndroid Build Coastguard Worker         else
2925*8975f5c5SAndroid Build Coastguard Worker         {
2926*8975f5c5SAndroid Build Coastguard Worker             eglMakeCurrent(mDisplay, mPbufferSurface, mPbufferSurface, mContext);
2927*8975f5c5SAndroid Build Coastguard Worker             ASSERT_EGL_SUCCESS();
2928*8975f5c5SAndroid Build Coastguard Worker             eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
2929*8975f5c5SAndroid Build Coastguard Worker             ASSERT_EGL_SUCCESS();
2930*8975f5c5SAndroid Build Coastguard Worker             eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
2931*8975f5c5SAndroid Build Coastguard Worker             ASSERT_EGL_SUCCESS();
2932*8975f5c5SAndroid Build Coastguard Worker         }
2933*8975f5c5SAndroid Build Coastguard Worker 
2934*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, mWindowSurface);
2935*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
2936*8975f5c5SAndroid Build Coastguard Worker     }
2937*8975f5c5SAndroid Build Coastguard Worker 
2938*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(kInitialSize, kInitialSize);
2939*8975f5c5SAndroid Build Coastguard Worker }
2940*8975f5c5SAndroid Build Coastguard Worker 
2941*8975f5c5SAndroid Build Coastguard Worker // Test that there no artifacts because of the bug when wait semaphore could be added after
2942*8975f5c5SAndroid Build Coastguard Worker // rendering commands. This was possible by switching to Pbuffer surface and submit.
TEST_P(EGLSurfaceTest,DISABLED_WaitSemaphoreAddedAfterCommands)2943*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, DISABLED_WaitSemaphoreAddedAfterCommands)
2944*8975f5c5SAndroid Build Coastguard Worker {
2945*8975f5c5SAndroid Build Coastguard Worker     runWaitSemaphoreTest(false);
2946*8975f5c5SAndroid Build Coastguard Worker }
2947*8975f5c5SAndroid Build Coastguard Worker 
2948*8975f5c5SAndroid Build Coastguard Worker // Test that there no artifacts because of the bug when rendering commands could be submitted
2949*8975f5c5SAndroid Build Coastguard Worker // without adding wait semaphore. This was possible if submit commands from other thread.
TEST_P(EGLSurfaceTest,DISABLED_CommandsSubmittedWithoutWaitSemaphore)2950*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, DISABLED_CommandsSubmittedWithoutWaitSemaphore)
2951*8975f5c5SAndroid Build Coastguard Worker {
2952*8975f5c5SAndroid Build Coastguard Worker     runWaitSemaphoreTest(true);
2953*8975f5c5SAndroid Build Coastguard Worker }
2954*8975f5c5SAndroid Build Coastguard Worker 
runDestroyNotCurrentSurfaceTest(bool testWindowsSurface)2955*8975f5c5SAndroid Build Coastguard Worker void EGLSurfaceTest::runDestroyNotCurrentSurfaceTest(bool testWindowsSurface)
2956*8975f5c5SAndroid Build Coastguard Worker {
2957*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
2958*8975f5c5SAndroid Build Coastguard Worker 
2959*8975f5c5SAndroid Build Coastguard Worker     // Initialize an RGBA8 window and pbuffer surface
2960*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kSurfaceAttributes[] = {EGL_RED_SIZE,     8,
2961*8975f5c5SAndroid Build Coastguard Worker                                              EGL_GREEN_SIZE,   8,
2962*8975f5c5SAndroid Build Coastguard Worker                                              EGL_BLUE_SIZE,    8,
2963*8975f5c5SAndroid Build Coastguard Worker                                              EGL_ALPHA_SIZE,   8,
2964*8975f5c5SAndroid Build Coastguard Worker                                              EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
2965*8975f5c5SAndroid Build Coastguard Worker                                              EGL_NONE};
2966*8975f5c5SAndroid Build Coastguard Worker 
2967*8975f5c5SAndroid Build Coastguard Worker     EGLint configCount      = 0;
2968*8975f5c5SAndroid Build Coastguard Worker     EGLConfig surfaceConfig = nullptr;
2969*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, kSurfaceAttributes, &surfaceConfig, 1, &configCount));
2970*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(configCount, 0);
2971*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(surfaceConfig, nullptr);
2972*8975f5c5SAndroid Build Coastguard Worker 
2973*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(surfaceConfig);
2974*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
2975*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
2976*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mPbufferSurface, EGL_NO_SURFACE);
2977*8975f5c5SAndroid Build Coastguard Worker 
2978*8975f5c5SAndroid Build Coastguard Worker     EGLSurface &testSurface  = testWindowsSurface ? mWindowSurface : mPbufferSurface;
2979*8975f5c5SAndroid Build Coastguard Worker     EGLSurface &otherSurface = testWindowsSurface ? mPbufferSurface : mWindowSurface;
2980*8975f5c5SAndroid Build Coastguard Worker 
2981*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, testSurface, testSurface, mContext);
2982*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
2983*8975f5c5SAndroid Build Coastguard Worker 
2984*8975f5c5SAndroid Build Coastguard Worker     // Start RenderPass in the testSurface
2985*8975f5c5SAndroid Build Coastguard Worker     glEnable(GL_SCISSOR_TEST);
2986*8975f5c5SAndroid Build Coastguard Worker     glScissor(0, 0, 4, 4);
2987*8975f5c5SAndroid Build Coastguard Worker     glClearColor(0.5f, 0.0f, 0.0f, 1.0f);
2988*8975f5c5SAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
2989*8975f5c5SAndroid Build Coastguard Worker     glDisable(GL_SCISSOR_TEST);
2990*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
2991*8975f5c5SAndroid Build Coastguard Worker 
2992*8975f5c5SAndroid Build Coastguard Worker     // Make other surface current keeping the context.
2993*8975f5c5SAndroid Build Coastguard Worker     // If bug present, the context may have unflushed work, related to the testSurface.
2994*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, otherSurface, otherSurface, mContext);
2995*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
2996*8975f5c5SAndroid Build Coastguard Worker 
2997*8975f5c5SAndroid Build Coastguard Worker     if (testWindowsSurface)
2998*8975f5c5SAndroid Build Coastguard Worker     {
2999*8975f5c5SAndroid Build Coastguard Worker         // This may flush Window Surface RenderPass
3000*8975f5c5SAndroid Build Coastguard Worker         glEnable(GL_SCISSOR_TEST);
3001*8975f5c5SAndroid Build Coastguard Worker         glScissor(0, 0, 4, 4);
3002*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.5f, 0.0f, 0.0f, 1.0f);
3003*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
3004*8975f5c5SAndroid Build Coastguard Worker         glDisable(GL_SCISSOR_TEST);
3005*8975f5c5SAndroid Build Coastguard Worker         ASSERT_GL_NO_ERROR();
3006*8975f5c5SAndroid Build Coastguard Worker     }
3007*8975f5c5SAndroid Build Coastguard Worker 
3008*8975f5c5SAndroid Build Coastguard Worker     // Destroy the surface
3009*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, testSurface);
3010*8975f5c5SAndroid Build Coastguard Worker     testSurface = EGL_NO_SURFACE;
3011*8975f5c5SAndroid Build Coastguard Worker 
3012*8975f5c5SAndroid Build Coastguard Worker     // This will submit all work (if bug present - include work related to the deleted testSurface).
3013*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, otherSurface, otherSurface, mContext);
3014*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
3015*8975f5c5SAndroid Build Coastguard Worker }
3016*8975f5c5SAndroid Build Coastguard Worker 
3017*8975f5c5SAndroid Build Coastguard Worker // Test that there is no crash because of the bug when not current PBuffer Surface destroyed, while
3018*8975f5c5SAndroid Build Coastguard Worker // there are still unflushed work in the Context.
TEST_P(EGLSurfaceTest,DestroyNotCurrentPbufferSurface)3019*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, DestroyNotCurrentPbufferSurface)
3020*8975f5c5SAndroid Build Coastguard Worker {
3021*8975f5c5SAndroid Build Coastguard Worker     runDestroyNotCurrentSurfaceTest(false);
3022*8975f5c5SAndroid Build Coastguard Worker }
3023*8975f5c5SAndroid Build Coastguard Worker 
3024*8975f5c5SAndroid Build Coastguard Worker // Test that there is no crash because of the bug when not current Window Surface destroyed, while
3025*8975f5c5SAndroid Build Coastguard Worker // there are still unflushed work in the Context.
TEST_P(EGLSurfaceTest,DestroyNotCurrentWindowSurface)3026*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, DestroyNotCurrentWindowSurface)
3027*8975f5c5SAndroid Build Coastguard Worker {
3028*8975f5c5SAndroid Build Coastguard Worker     runDestroyNotCurrentSurfaceTest(true);
3029*8975f5c5SAndroid Build Coastguard Worker }
3030*8975f5c5SAndroid Build Coastguard Worker 
3031*8975f5c5SAndroid Build Coastguard Worker // Test that there is no tearing because of incorrect pipeline barriers
TEST_P(EGLSurfaceTest,DISABLED_RandomClearTearing)3032*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, DISABLED_RandomClearTearing)
3033*8975f5c5SAndroid Build Coastguard Worker {
3034*8975f5c5SAndroid Build Coastguard Worker     // Note: This test requires visual inspection for rendering artifacts.
3035*8975f5c5SAndroid Build Coastguard Worker     // However, absence of artifacts does not guarantee that there is no problem.
3036*8975f5c5SAndroid Build Coastguard Worker 
3037*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
3038*8975f5c5SAndroid Build Coastguard Worker 
3039*8975f5c5SAndroid Build Coastguard Worker     constexpr int kInitialSize   = 64;
3040*8975f5c5SAndroid Build Coastguard Worker     constexpr int kWindowWidth   = 1080;
3041*8975f5c5SAndroid Build Coastguard Worker     constexpr int kWindowWHeight = 1920;
3042*8975f5c5SAndroid Build Coastguard Worker 
3043*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(kWindowWidth, kWindowWHeight);
3044*8975f5c5SAndroid Build Coastguard Worker 
3045*8975f5c5SAndroid Build Coastguard Worker     initializeSurfaceWithDefaultConfig(true);
3046*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
3047*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mWindowSurface, EGL_NO_SURFACE);
3048*8975f5c5SAndroid Build Coastguard Worker 
3049*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
3050*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
3051*8975f5c5SAndroid Build Coastguard Worker 
3052*8975f5c5SAndroid Build Coastguard Worker     constexpr int kFrameCount = 60 * 4;  // 4 sec @ 60Hz; 2 sec @ 120Hz;
3053*8975f5c5SAndroid Build Coastguard Worker 
3054*8975f5c5SAndroid Build Coastguard Worker     for (int frame = 0; frame < kFrameCount; ++frame)
3055*8975f5c5SAndroid Build Coastguard Worker     {
3056*8975f5c5SAndroid Build Coastguard Worker         glClearColor(rand() % 256 / 255.0f, rand() % 256 / 255.0f, rand() % 256 / 255.0f, 1.0f);
3057*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
3058*8975f5c5SAndroid Build Coastguard Worker         ASSERT_GL_NO_ERROR();
3059*8975f5c5SAndroid Build Coastguard Worker 
3060*8975f5c5SAndroid Build Coastguard Worker         eglSwapBuffers(mDisplay, mWindowSurface);
3061*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
3062*8975f5c5SAndroid Build Coastguard Worker     }
3063*8975f5c5SAndroid Build Coastguard Worker 
3064*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->resize(kInitialSize, kInitialSize);
3065*8975f5c5SAndroid Build Coastguard Worker }
3066*8975f5c5SAndroid Build Coastguard Worker 
3067*8975f5c5SAndroid Build Coastguard Worker // Make sure a surface (from the same window) can be recreated after being destroyed, even if it's
3068*8975f5c5SAndroid Build Coastguard Worker // still current.
3069*8975f5c5SAndroid Build Coastguard Worker // This is to recreate the app behavior in https://issuetracker.google.com/292285899, which is
3070*8975f5c5SAndroid Build Coastguard Worker // not the correct spec behavior. It serves as a purpose to test the workaround feature
3071*8975f5c5SAndroid Build Coastguard Worker // uncurrent_egl_surface_upon_surface_destroy that is enabled only on vulkan backend to help
3072*8975f5c5SAndroid Build Coastguard Worker // the app get over the problem.
TEST_P(EGLSurfaceTest,DestroyAndRecreateWhileCurrent)3073*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, DestroyAndRecreateWhileCurrent)
3074*8975f5c5SAndroid Build Coastguard Worker {
3075*8975f5c5SAndroid Build Coastguard Worker     setWindowVisible(mOSWindow, true);
3076*8975f5c5SAndroid Build Coastguard Worker 
3077*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
3078*8975f5c5SAndroid Build Coastguard Worker 
3079*8975f5c5SAndroid Build Coastguard Worker     mConfig = chooseDefaultConfig(true);
3080*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(mConfig, nullptr);
3081*8975f5c5SAndroid Build Coastguard Worker 
3082*8975f5c5SAndroid Build Coastguard Worker     EGLint surfaceType = EGL_NONE;
3083*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);
3084*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE((surfaceType & EGL_WINDOW_BIT), 0);
3085*8975f5c5SAndroid Build Coastguard Worker 
3086*8975f5c5SAndroid Build Coastguard Worker     initializeWindowSurfaceWithAttribs(mConfig, {}, EGL_SUCCESS);
3087*8975f5c5SAndroid Build Coastguard Worker     initializeMainContext();
3088*8975f5c5SAndroid Build Coastguard Worker 
3089*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
3090*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
3091*8975f5c5SAndroid Build Coastguard Worker 
3092*8975f5c5SAndroid Build Coastguard Worker     // Draw with this surface to make sure it's used.
3093*8975f5c5SAndroid Build Coastguard Worker     ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
3094*8975f5c5SAndroid Build Coastguard Worker     glViewport(0, 0, 64, 64);
3095*8975f5c5SAndroid Build Coastguard Worker     drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
3096*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
3097*8975f5c5SAndroid Build Coastguard Worker 
3098*8975f5c5SAndroid Build Coastguard Worker     // Destroy the surface while it's current; it won't actually be destroyed.
3099*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, mWindowSurface);
3100*8975f5c5SAndroid Build Coastguard Worker     mWindowSurface = EGL_NO_SURFACE;
3101*8975f5c5SAndroid Build Coastguard Worker 
3102*8975f5c5SAndroid Build Coastguard Worker     // Create another surface from the same window right away.
3103*8975f5c5SAndroid Build Coastguard Worker     initializeWindowSurfaceWithAttribs(mConfig, {}, EGL_SUCCESS);
3104*8975f5c5SAndroid Build Coastguard Worker 
3105*8975f5c5SAndroid Build Coastguard Worker     // Make the new surface current; this leads to the actual destruction of the previous surface.
3106*8975f5c5SAndroid Build Coastguard Worker     EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext));
3107*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_SUCCESS();
3108*8975f5c5SAndroid Build Coastguard Worker 
3109*8975f5c5SAndroid Build Coastguard Worker     // Verify everything still works
3110*8975f5c5SAndroid Build Coastguard Worker     ANGLE_GL_PROGRAM(program2, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
3111*8975f5c5SAndroid Build Coastguard Worker     drawQuad(program2, essl1_shaders::PositionAttrib(), 0.5f);
3112*8975f5c5SAndroid Build Coastguard Worker     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3113*8975f5c5SAndroid Build Coastguard Worker     ASSERT_GL_NO_ERROR();
3114*8975f5c5SAndroid Build Coastguard Worker }
3115*8975f5c5SAndroid Build Coastguard Worker 
3116*8975f5c5SAndroid Build Coastguard Worker // Regression test for a bug where destroying more than 2 surfaces during termination
3117*8975f5c5SAndroid Build Coastguard Worker // overflowed the unlocked tail call storage.
TEST_P(EGLSurfaceTest,CreateMultiWindowsSurfaceNoDestroy)3118*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLSurfaceTest, CreateMultiWindowsSurfaceNoDestroy)
3119*8975f5c5SAndroid Build Coastguard Worker {
3120*8975f5c5SAndroid Build Coastguard Worker     initializeDisplay();
3121*8975f5c5SAndroid Build Coastguard Worker 
3122*8975f5c5SAndroid Build Coastguard Worker     // Initialize and create multi RGBA8 window surfaces
3123*8975f5c5SAndroid Build Coastguard Worker     constexpr EGLint kSurfaceAttributes[] = {EGL_RED_SIZE,     8,
3124*8975f5c5SAndroid Build Coastguard Worker                                              EGL_GREEN_SIZE,   8,
3125*8975f5c5SAndroid Build Coastguard Worker                                              EGL_BLUE_SIZE,    8,
3126*8975f5c5SAndroid Build Coastguard Worker                                              EGL_ALPHA_SIZE,   8,
3127*8975f5c5SAndroid Build Coastguard Worker                                              EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
3128*8975f5c5SAndroid Build Coastguard Worker                                              EGL_NONE};
3129*8975f5c5SAndroid Build Coastguard Worker 
3130*8975f5c5SAndroid Build Coastguard Worker     EGLint configCount      = 0;
3131*8975f5c5SAndroid Build Coastguard Worker     EGLConfig surfaceConfig = nullptr;
3132*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, kSurfaceAttributes, &surfaceConfig, 1, &configCount));
3133*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(configCount, 0);
3134*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(surfaceConfig, nullptr);
3135*8975f5c5SAndroid Build Coastguard Worker 
3136*8975f5c5SAndroid Build Coastguard Worker     initializeSurface(surfaceConfig);
3137*8975f5c5SAndroid Build Coastguard Worker 
3138*8975f5c5SAndroid Build Coastguard Worker     // Create 3 window surfaces to trigger error
3139*8975f5c5SAndroid Build Coastguard Worker     std::vector<EGLint> windowAttributes;
3140*8975f5c5SAndroid Build Coastguard Worker     windowAttributes.push_back(EGL_NONE);
3141*8975f5c5SAndroid Build Coastguard Worker 
3142*8975f5c5SAndroid Build Coastguard Worker     for (int i = 0; i < 3; i++)
3143*8975f5c5SAndroid Build Coastguard Worker     {
3144*8975f5c5SAndroid Build Coastguard Worker         OSWindow *w = OSWindow::New();
3145*8975f5c5SAndroid Build Coastguard Worker         w->initialize("EGLSurfaceTest", 64, 64);
3146*8975f5c5SAndroid Build Coastguard Worker 
3147*8975f5c5SAndroid Build Coastguard Worker         eglCreateWindowSurface(mDisplay, mConfig, w->getNativeWindow(), windowAttributes.data());
3148*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
3149*8975f5c5SAndroid Build Coastguard Worker         mOtherWindows.push_back(w);
3150*8975f5c5SAndroid Build Coastguard Worker     }
3151*8975f5c5SAndroid Build Coastguard Worker }
3152*8975f5c5SAndroid Build Coastguard Worker 
3153*8975f5c5SAndroid Build Coastguard Worker }  // anonymous namespace
3154*8975f5c5SAndroid Build Coastguard Worker 
3155*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLSingleBufferTest);
3156*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLSingleBufferTest,
3157*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_VULKAN()),
3158*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_VULKAN()));
3159*8975f5c5SAndroid Build Coastguard Worker 
3160*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLAndroidAutoRefreshTest);
3161*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLAndroidAutoRefreshTest, WithNoFixture(ES3_VULKAN()));
3162*8975f5c5SAndroid Build Coastguard Worker 
3163*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLSurfaceTest,
3164*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_D3D9()),
3165*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_D3D11()),
3166*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_D3D11()),
3167*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_METAL()),
3168*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_METAL()),
3169*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_OPENGL()),
3170*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_OPENGL()),
3171*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_OPENGLES()),
3172*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_OPENGLES()),
3173*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_VULKAN()),
3174*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_VULKAN()),
3175*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_VULKAN_SWIFTSHADER()),
3176*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_VULKAN_SWIFTSHADER()));
3177*8975f5c5SAndroid Build Coastguard Worker 
3178*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLFloatSurfaceTest);
3179*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLFloatSurfaceTest,
3180*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_OPENGL()),
3181*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_OPENGL()),
3182*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES2_VULKAN()),
3183*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_VULKAN()));
3184*8975f5c5SAndroid Build Coastguard Worker 
3185*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLSurfaceTest3);
3186*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLSurfaceTest3,
3187*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_D3D11()),
3188*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_OPENGLES()),
3189*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_VULKAN()),
3190*8975f5c5SAndroid Build Coastguard Worker                        WithNoFixture(ES3_VULKAN_SWIFTSHADER()));
3191*8975f5c5SAndroid Build Coastguard Worker 
3192*8975f5c5SAndroid Build Coastguard Worker #if defined(ANGLE_ENABLE_D3D11)
3193*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLSurfaceTestD3D11, WithNoFixture(ES2_D3D11()), WithNoFixture(ES3_D3D11()));
3194*8975f5c5SAndroid Build Coastguard Worker #endif
3195