1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2020 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 // EGLPreRotationTest:
7*8975f5c5SAndroid Build Coastguard Worker // Tests pertaining to Android pre-rotation.
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 <vector>
13*8975f5c5SAndroid Build Coastguard Worker
14*8975f5c5SAndroid Build Coastguard Worker #include "common/Color.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "common/platform.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "util/EGLWindow.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "util/OSWindow.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "util/Timer.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "util/test_utils.h"
22*8975f5c5SAndroid Build Coastguard Worker
23*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
24*8975f5c5SAndroid Build Coastguard Worker
25*8975f5c5SAndroid Build Coastguard Worker namespace
26*8975f5c5SAndroid Build Coastguard Worker {
27*8975f5c5SAndroid Build Coastguard Worker
28*8975f5c5SAndroid Build Coastguard Worker using EGLPreRotationSurfaceTestParams = std::tuple<angle::PlatformParameters, bool>;
29*8975f5c5SAndroid Build Coastguard Worker
PrintToStringParamName(const::testing::TestParamInfo<EGLPreRotationSurfaceTestParams> & info)30*8975f5c5SAndroid Build Coastguard Worker std::string PrintToStringParamName(
31*8975f5c5SAndroid Build Coastguard Worker const ::testing::TestParamInfo<EGLPreRotationSurfaceTestParams> &info)
32*8975f5c5SAndroid Build Coastguard Worker {
33*8975f5c5SAndroid Build Coastguard Worker std::stringstream ss;
34*8975f5c5SAndroid Build Coastguard Worker ss << std::get<0>(info.param);
35*8975f5c5SAndroid Build Coastguard Worker if (std::get<1>(info.param))
36*8975f5c5SAndroid Build Coastguard Worker {
37*8975f5c5SAndroid Build Coastguard Worker ss << "__PreRotationEnabled";
38*8975f5c5SAndroid Build Coastguard Worker }
39*8975f5c5SAndroid Build Coastguard Worker else
40*8975f5c5SAndroid Build Coastguard Worker {
41*8975f5c5SAndroid Build Coastguard Worker ss << "__PreRotationDisabled";
42*8975f5c5SAndroid Build Coastguard Worker }
43*8975f5c5SAndroid Build Coastguard Worker return ss.str();
44*8975f5c5SAndroid Build Coastguard Worker }
45*8975f5c5SAndroid Build Coastguard Worker
46*8975f5c5SAndroid Build Coastguard Worker // A class to test various Android pre-rotation cases. In order to make it easier to debug test
47*8975f5c5SAndroid Build Coastguard Worker // failures, the initial window size is 256x256, and each pixel will have a unique and predictable
48*8975f5c5SAndroid Build Coastguard Worker // value. The red channel will increment with the x axis, and the green channel will increment
49*8975f5c5SAndroid Build Coastguard Worker // with the y axis. The four corners will have the following values:
50*8975f5c5SAndroid Build Coastguard Worker //
51*8975f5c5SAndroid Build Coastguard Worker // Where GLES Render & ReadPixels coords Color (in Hex)
52*8975f5c5SAndroid Build Coastguard Worker // Lower-left, which is (-1.0,-1.0) & ( 0, 0) in GLES will be black (0x00, 0x00, 0x00, 0xFF)
53*8975f5c5SAndroid Build Coastguard Worker // Lower-right, which is ( 1.0,-1.0) & (256, 0) in GLES will be red (0xFF, 0x00, 0x00, 0xFF)
54*8975f5c5SAndroid Build Coastguard Worker // Upper-left, which is (-1.0, 1.0) & ( 0, 256) in GLES will be green (0x00, 0xFF, 0x00, 0xFF)
55*8975f5c5SAndroid Build Coastguard Worker // Upper-right, which is ( 1.0, 1.0) & (256, 256) in GLES will be yellow (0xFF, 0xFF, 0x00, 0xFF)
56*8975f5c5SAndroid Build Coastguard Worker class EGLPreRotationSurfaceTest : public ANGLETest<EGLPreRotationSurfaceTestParams>
57*8975f5c5SAndroid Build Coastguard Worker {
58*8975f5c5SAndroid Build Coastguard Worker protected:
EGLPreRotationSurfaceTest()59*8975f5c5SAndroid Build Coastguard Worker EGLPreRotationSurfaceTest()
60*8975f5c5SAndroid Build Coastguard Worker : mDisplay(EGL_NO_DISPLAY),
61*8975f5c5SAndroid Build Coastguard Worker mWindowSurface(EGL_NO_SURFACE),
62*8975f5c5SAndroid Build Coastguard Worker mContext(EGL_NO_CONTEXT),
63*8975f5c5SAndroid Build Coastguard Worker mOSWindow(nullptr),
64*8975f5c5SAndroid Build Coastguard Worker mSize(256)
65*8975f5c5SAndroid Build Coastguard Worker {}
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Worker // Release any resources created in the test body
testTearDown()68*8975f5c5SAndroid Build Coastguard Worker void testTearDown() override
69*8975f5c5SAndroid Build Coastguard Worker {
70*8975f5c5SAndroid Build Coastguard Worker if (mDisplay != EGL_NO_DISPLAY)
71*8975f5c5SAndroid Build Coastguard Worker {
72*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
73*8975f5c5SAndroid Build Coastguard Worker
74*8975f5c5SAndroid Build Coastguard Worker if (mWindowSurface != EGL_NO_SURFACE)
75*8975f5c5SAndroid Build Coastguard Worker {
76*8975f5c5SAndroid Build Coastguard Worker eglDestroySurface(mDisplay, mWindowSurface);
77*8975f5c5SAndroid Build Coastguard Worker mWindowSurface = EGL_NO_SURFACE;
78*8975f5c5SAndroid Build Coastguard Worker }
79*8975f5c5SAndroid Build Coastguard Worker
80*8975f5c5SAndroid Build Coastguard Worker if (mContext != EGL_NO_CONTEXT)
81*8975f5c5SAndroid Build Coastguard Worker {
82*8975f5c5SAndroid Build Coastguard Worker eglDestroyContext(mDisplay, mContext);
83*8975f5c5SAndroid Build Coastguard Worker mContext = EGL_NO_CONTEXT;
84*8975f5c5SAndroid Build Coastguard Worker }
85*8975f5c5SAndroid Build Coastguard Worker
86*8975f5c5SAndroid Build Coastguard Worker eglTerminate(mDisplay);
87*8975f5c5SAndroid Build Coastguard Worker mDisplay = EGL_NO_DISPLAY;
88*8975f5c5SAndroid Build Coastguard Worker }
89*8975f5c5SAndroid Build Coastguard Worker
90*8975f5c5SAndroid Build Coastguard Worker mOSWindow->destroy();
91*8975f5c5SAndroid Build Coastguard Worker OSWindow::Delete(&mOSWindow);
92*8975f5c5SAndroid Build Coastguard Worker
93*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(mWindowSurface == EGL_NO_SURFACE && mContext == EGL_NO_CONTEXT);
94*8975f5c5SAndroid Build Coastguard Worker }
95*8975f5c5SAndroid Build Coastguard Worker
testSetUp()96*8975f5c5SAndroid Build Coastguard Worker void testSetUp() override
97*8975f5c5SAndroid Build Coastguard Worker {
98*8975f5c5SAndroid Build Coastguard Worker mOSWindow = OSWindow::New();
99*8975f5c5SAndroid Build Coastguard Worker mOSWindow->initialize("EGLSurfaceTest", mSize, mSize);
100*8975f5c5SAndroid Build Coastguard Worker }
101*8975f5c5SAndroid Build Coastguard Worker
initializeDisplay()102*8975f5c5SAndroid Build Coastguard Worker void initializeDisplay()
103*8975f5c5SAndroid Build Coastguard Worker {
104*8975f5c5SAndroid Build Coastguard Worker const angle::PlatformParameters platform = ::testing::get<0>(GetParam());
105*8975f5c5SAndroid Build Coastguard Worker GLenum platformType = platform.getRenderer();
106*8975f5c5SAndroid Build Coastguard Worker GLenum deviceType = platform.getDeviceType();
107*8975f5c5SAndroid Build Coastguard Worker
108*8975f5c5SAndroid Build Coastguard Worker std::vector<const char *> enabledFeatures;
109*8975f5c5SAndroid Build Coastguard Worker std::vector<const char *> disabledFeatures;
110*8975f5c5SAndroid Build Coastguard Worker if (::testing::get<1>(GetParam()))
111*8975f5c5SAndroid Build Coastguard Worker {
112*8975f5c5SAndroid Build Coastguard Worker enabledFeatures.push_back("enablePreRotateSurfaces");
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker else
115*8975f5c5SAndroid Build Coastguard Worker {
116*8975f5c5SAndroid Build Coastguard Worker disabledFeatures.push_back("enablePreRotateSurfaces");
117*8975f5c5SAndroid Build Coastguard Worker }
118*8975f5c5SAndroid Build Coastguard Worker enabledFeatures.push_back(nullptr);
119*8975f5c5SAndroid Build Coastguard Worker disabledFeatures.push_back(nullptr);
120*8975f5c5SAndroid Build Coastguard Worker
121*8975f5c5SAndroid Build Coastguard Worker std::vector<EGLAttrib> displayAttributes;
122*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
123*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(platformType);
124*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
125*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_DONT_CARE);
126*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
127*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_DONT_CARE);
128*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
129*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(deviceType);
130*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_FEATURE_OVERRIDES_ENABLED_ANGLE);
131*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(reinterpret_cast<EGLAttrib>(enabledFeatures.data()));
132*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_FEATURE_OVERRIDES_DISABLED_ANGLE);
133*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(reinterpret_cast<EGLAttrib>(disabledFeatures.data()));
134*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_NONE);
135*8975f5c5SAndroid Build Coastguard Worker
136*8975f5c5SAndroid Build Coastguard Worker mDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
137*8975f5c5SAndroid Build Coastguard Worker reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
138*8975f5c5SAndroid Build Coastguard Worker displayAttributes.data());
139*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);
140*8975f5c5SAndroid Build Coastguard Worker
141*8975f5c5SAndroid Build Coastguard Worker EGLint majorVersion, minorVersion;
142*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(eglInitialize(mDisplay, &majorVersion, &minorVersion) == EGL_TRUE);
143*8975f5c5SAndroid Build Coastguard Worker
144*8975f5c5SAndroid Build Coastguard Worker eglBindAPI(EGL_OPENGL_ES_API);
145*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
146*8975f5c5SAndroid Build Coastguard Worker }
147*8975f5c5SAndroid Build Coastguard Worker
initializeContext()148*8975f5c5SAndroid Build Coastguard Worker void initializeContext()
149*8975f5c5SAndroid Build Coastguard Worker {
150*8975f5c5SAndroid Build Coastguard Worker EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION,
151*8975f5c5SAndroid Build Coastguard Worker ::testing::get<0>(GetParam()).majorVersion, EGL_NONE};
152*8975f5c5SAndroid Build Coastguard Worker
153*8975f5c5SAndroid Build Coastguard Worker mContext = eglCreateContext(mDisplay, mConfig, nullptr, contextAttibutes);
154*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
155*8975f5c5SAndroid Build Coastguard Worker }
156*8975f5c5SAndroid Build Coastguard Worker
initializeSurfaceWithRGBA8888Config()157*8975f5c5SAndroid Build Coastguard Worker void initializeSurfaceWithRGBA8888Config()
158*8975f5c5SAndroid Build Coastguard Worker {
159*8975f5c5SAndroid Build Coastguard Worker const EGLint configAttributes[] = {
160*8975f5c5SAndroid Build Coastguard Worker EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
161*8975f5c5SAndroid Build Coastguard Worker EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_SAMPLE_BUFFERS, 0, EGL_NONE};
162*8975f5c5SAndroid Build Coastguard Worker
163*8975f5c5SAndroid Build Coastguard Worker EGLint configCount;
164*8975f5c5SAndroid Build Coastguard Worker EGLConfig config;
165*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(eglChooseConfig(mDisplay, configAttributes, &config, 1, &configCount) ||
166*8975f5c5SAndroid Build Coastguard Worker (configCount != 1) == EGL_TRUE);
167*8975f5c5SAndroid Build Coastguard Worker
168*8975f5c5SAndroid Build Coastguard Worker mConfig = config;
169*8975f5c5SAndroid Build Coastguard Worker
170*8975f5c5SAndroid Build Coastguard Worker EGLint surfaceType = EGL_NONE;
171*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);
172*8975f5c5SAndroid Build Coastguard Worker
173*8975f5c5SAndroid Build Coastguard Worker std::vector<EGLint> windowAttributes;
174*8975f5c5SAndroid Build Coastguard Worker windowAttributes.push_back(EGL_NONE);
175*8975f5c5SAndroid Build Coastguard Worker
176*8975f5c5SAndroid Build Coastguard Worker if (surfaceType & EGL_WINDOW_BIT)
177*8975f5c5SAndroid Build Coastguard Worker {
178*8975f5c5SAndroid Build Coastguard Worker // Create first window surface
179*8975f5c5SAndroid Build Coastguard Worker mWindowSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(),
180*8975f5c5SAndroid Build Coastguard Worker windowAttributes.data());
181*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
182*8975f5c5SAndroid Build Coastguard Worker }
183*8975f5c5SAndroid Build Coastguard Worker
184*8975f5c5SAndroid Build Coastguard Worker initializeContext();
185*8975f5c5SAndroid Build Coastguard Worker }
186*8975f5c5SAndroid Build Coastguard Worker
initializeSurfaceWithRGBA8888d24s8Config()187*8975f5c5SAndroid Build Coastguard Worker void initializeSurfaceWithRGBA8888d24s8Config()
188*8975f5c5SAndroid Build Coastguard Worker {
189*8975f5c5SAndroid Build Coastguard Worker const EGLint configAttributes[] = {
190*8975f5c5SAndroid Build Coastguard Worker EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
191*8975f5c5SAndroid Build Coastguard Worker EGL_DEPTH_SIZE, 24, EGL_STENCIL_SIZE, 8, EGL_SAMPLE_BUFFERS, 0, EGL_NONE};
192*8975f5c5SAndroid Build Coastguard Worker
193*8975f5c5SAndroid Build Coastguard Worker EGLint configCount;
194*8975f5c5SAndroid Build Coastguard Worker EGLConfig config;
195*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(eglChooseConfig(mDisplay, configAttributes, &config, 1, &configCount) ||
196*8975f5c5SAndroid Build Coastguard Worker (configCount != 1) == EGL_TRUE);
197*8975f5c5SAndroid Build Coastguard Worker
198*8975f5c5SAndroid Build Coastguard Worker mConfig = config;
199*8975f5c5SAndroid Build Coastguard Worker
200*8975f5c5SAndroid Build Coastguard Worker EGLint surfaceType = EGL_NONE;
201*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);
202*8975f5c5SAndroid Build Coastguard Worker
203*8975f5c5SAndroid Build Coastguard Worker std::vector<EGLint> windowAttributes;
204*8975f5c5SAndroid Build Coastguard Worker windowAttributes.push_back(EGL_NONE);
205*8975f5c5SAndroid Build Coastguard Worker
206*8975f5c5SAndroid Build Coastguard Worker if (surfaceType & EGL_WINDOW_BIT)
207*8975f5c5SAndroid Build Coastguard Worker {
208*8975f5c5SAndroid Build Coastguard Worker // Create first window surface
209*8975f5c5SAndroid Build Coastguard Worker mWindowSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(),
210*8975f5c5SAndroid Build Coastguard Worker windowAttributes.data());
211*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
212*8975f5c5SAndroid Build Coastguard Worker }
213*8975f5c5SAndroid Build Coastguard Worker
214*8975f5c5SAndroid Build Coastguard Worker initializeContext();
215*8975f5c5SAndroid Build Coastguard Worker }
216*8975f5c5SAndroid Build Coastguard Worker
testDrawingAndReadPixels()217*8975f5c5SAndroid Build Coastguard Worker void testDrawingAndReadPixels()
218*8975f5c5SAndroid Build Coastguard Worker {
219*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
220*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
221*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor::green);
222*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor::red);
223*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor::yellow);
224*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
225*8975f5c5SAndroid Build Coastguard Worker
226*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
227*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
228*8975f5c5SAndroid Build Coastguard Worker
229*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
230*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
231*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor::green);
232*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor::red);
233*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor::yellow);
234*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
235*8975f5c5SAndroid Build Coastguard Worker
236*8975f5c5SAndroid Build Coastguard Worker {
237*8975f5c5SAndroid Build Coastguard Worker // Now, test a 4x4 area in the center of the window, which should tell us if a non-1x1
238*8975f5c5SAndroid Build Coastguard Worker // ReadPixels is oriented correctly for the device's orientation:
239*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 126;
240*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 126;
241*8975f5c5SAndroid Build Coastguard Worker GLsizei width = 4;
242*8975f5c5SAndroid Build Coastguard Worker GLsizei height = 4;
243*8975f5c5SAndroid Build Coastguard Worker std::vector<GLColor> pixels(width * height);
244*8975f5c5SAndroid Build Coastguard Worker glReadPixels(xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
245*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
246*8975f5c5SAndroid Build Coastguard Worker // Expect that all red values equate to x and green values equate to y
247*8975f5c5SAndroid Build Coastguard Worker for (int y = 0; y < height; y++)
248*8975f5c5SAndroid Build Coastguard Worker {
249*8975f5c5SAndroid Build Coastguard Worker for (int x = 0; x < width; x++)
250*8975f5c5SAndroid Build Coastguard Worker {
251*8975f5c5SAndroid Build Coastguard Worker int index = (y * width) + x;
252*8975f5c5SAndroid Build Coastguard Worker GLColor expectedPixel(xOffset + x, yOffset + y, 0, 255);
253*8975f5c5SAndroid Build Coastguard Worker GLColor actualPixel = pixels[index];
254*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(expectedPixel, actualPixel);
255*8975f5c5SAndroid Build Coastguard Worker }
256*8975f5c5SAndroid Build Coastguard Worker }
257*8975f5c5SAndroid Build Coastguard Worker }
258*8975f5c5SAndroid Build Coastguard Worker
259*8975f5c5SAndroid Build Coastguard Worker {
260*8975f5c5SAndroid Build Coastguard Worker // Now, test a 8x4 area off-the-center of the window, just to make sure that works too:
261*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 13;
262*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 26;
263*8975f5c5SAndroid Build Coastguard Worker GLsizei width = 8;
264*8975f5c5SAndroid Build Coastguard Worker GLsizei height = 4;
265*8975f5c5SAndroid Build Coastguard Worker std::vector<GLColor> pixels2(width * height);
266*8975f5c5SAndroid Build Coastguard Worker glReadPixels(xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels2[0]);
267*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
268*8975f5c5SAndroid Build Coastguard Worker // Expect that all red values equate to x and green values equate to y
269*8975f5c5SAndroid Build Coastguard Worker for (int y = 0; y < height; y++)
270*8975f5c5SAndroid Build Coastguard Worker {
271*8975f5c5SAndroid Build Coastguard Worker for (int x = 0; x < width; x++)
272*8975f5c5SAndroid Build Coastguard Worker {
273*8975f5c5SAndroid Build Coastguard Worker int index = (y * width) + x;
274*8975f5c5SAndroid Build Coastguard Worker GLColor expectedPixel(xOffset + x, yOffset + y, 0, 255);
275*8975f5c5SAndroid Build Coastguard Worker GLColor actualPixel = pixels2[index];
276*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(expectedPixel, actualPixel);
277*8975f5c5SAndroid Build Coastguard Worker }
278*8975f5c5SAndroid Build Coastguard Worker }
279*8975f5c5SAndroid Build Coastguard Worker }
280*8975f5c5SAndroid Build Coastguard Worker
281*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
282*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
283*8975f5c5SAndroid Build Coastguard Worker }
284*8975f5c5SAndroid Build Coastguard Worker
285*8975f5c5SAndroid Build Coastguard Worker EGLDisplay mDisplay;
286*8975f5c5SAndroid Build Coastguard Worker EGLSurface mWindowSurface;
287*8975f5c5SAndroid Build Coastguard Worker EGLContext mContext;
288*8975f5c5SAndroid Build Coastguard Worker EGLConfig mConfig;
289*8975f5c5SAndroid Build Coastguard Worker OSWindow *mOSWindow;
290*8975f5c5SAndroid Build Coastguard Worker int mSize;
291*8975f5c5SAndroid Build Coastguard Worker };
292*8975f5c5SAndroid Build Coastguard Worker
293*8975f5c5SAndroid Build Coastguard Worker // Provide a predictable pattern for testing pre-rotation
TEST_P(EGLPreRotationSurfaceTest,OrientedWindowWithDraw)294*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw)
295*8975f5c5SAndroid Build Coastguard Worker {
296*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
297*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
298*8975f5c5SAndroid Build Coastguard Worker
299*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
300*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
301*8975f5c5SAndroid Build Coastguard Worker
302*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
303*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
304*8975f5c5SAndroid Build Coastguard Worker
305*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
306*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
307*8975f5c5SAndroid Build Coastguard Worker
308*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
309*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
310*8975f5c5SAndroid Build Coastguard Worker
311*8975f5c5SAndroid Build Coastguard Worker // Init program
312*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
313*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 position;\n"
314*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 redGreen;\n"
315*8975f5c5SAndroid Build Coastguard Worker "varying vec2 v_data;\n"
316*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
317*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(position, 0, 1);\n"
318*8975f5c5SAndroid Build Coastguard Worker " v_data = redGreen;\n"
319*8975f5c5SAndroid Build Coastguard Worker "}";
320*8975f5c5SAndroid Build Coastguard Worker
321*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
322*8975f5c5SAndroid Build Coastguard Worker "varying highp vec2 v_data;\n"
323*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
324*8975f5c5SAndroid Build Coastguard Worker " gl_FragColor = vec4(v_data, 0, 1);\n"
325*8975f5c5SAndroid Build Coastguard Worker "}";
326*8975f5c5SAndroid Build Coastguard Worker
327*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, kFS);
328*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
329*8975f5c5SAndroid Build Coastguard Worker
330*8975f5c5SAndroid Build Coastguard Worker GLint positionLocation = glGetAttribLocation(program, "position");
331*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, positionLocation);
332*8975f5c5SAndroid Build Coastguard Worker
333*8975f5c5SAndroid Build Coastguard Worker GLint redGreenLocation = glGetAttribLocation(program, "redGreen");
334*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, redGreenLocation);
335*8975f5c5SAndroid Build Coastguard Worker
336*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
337*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
338*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
339*8975f5c5SAndroid Build Coastguard Worker
340*8975f5c5SAndroid Build Coastguard Worker glBindVertexArray(vertexArray);
341*8975f5c5SAndroid Build Coastguard Worker
342*8975f5c5SAndroid Build Coastguard Worker std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0};
343*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
344*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
345*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
346*8975f5c5SAndroid Build Coastguard Worker
347*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> positionData = {// quad vertices
348*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
349*8975f5c5SAndroid Build Coastguard Worker
350*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]);
351*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
352*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
353*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
354*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(positionLocation);
355*8975f5c5SAndroid Build Coastguard Worker
356*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> redGreenData = {// green(0,1), black(0,0), red(1,0), yellow(1,1)
357*8975f5c5SAndroid Build Coastguard Worker 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f};
358*8975f5c5SAndroid Build Coastguard Worker
359*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[1]);
360*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * redGreenData.size(), &redGreenData[0],
361*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
362*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(redGreenLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
363*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(redGreenLocation);
364*8975f5c5SAndroid Build Coastguard Worker
365*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
366*8975f5c5SAndroid Build Coastguard Worker
367*8975f5c5SAndroid Build Coastguard Worker testDrawingAndReadPixels();
368*8975f5c5SAndroid Build Coastguard Worker }
369*8975f5c5SAndroid Build Coastguard Worker
370*8975f5c5SAndroid Build Coastguard Worker // Use dFdx() and dFdy() and still provide a predictable pattern for testing pre-rotation
371*8975f5c5SAndroid Build Coastguard Worker // In this case, the color values will be the following: (dFdx(v_data.x), dFdy(v_data.y), 0, 1).
372*8975f5c5SAndroid Build Coastguard Worker // To help make this meaningful for pre-rotation, the derivatives will vary in the four corners of
373*8975f5c5SAndroid Build Coastguard Worker // the window:
374*8975f5c5SAndroid Build Coastguard Worker //
375*8975f5c5SAndroid Build Coastguard Worker // +------------+------------+ +--------+--------+
376*8975f5c5SAndroid Build Coastguard Worker // | ( 0, 219) | (239, 249) | | Green | Yellow |
377*8975f5c5SAndroid Build Coastguard Worker // +------------+------------+ OR +--------+--------+
378*8975f5c5SAndroid Build Coastguard Worker // | ( 0, 0) | (229, 0) | | Black | Red |
379*8975f5c5SAndroid Build Coastguard Worker // +------------+------------+ +--------+--------+
TEST_P(EGLPreRotationSurfaceTest,OrientedWindowWithDerivativeDraw)380*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDerivativeDraw)
381*8975f5c5SAndroid Build Coastguard Worker {
382*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
383*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
384*8975f5c5SAndroid Build Coastguard Worker
385*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
386*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
387*8975f5c5SAndroid Build Coastguard Worker
388*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
389*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
390*8975f5c5SAndroid Build Coastguard Worker
391*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
392*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
393*8975f5c5SAndroid Build Coastguard Worker
394*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
395*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
396*8975f5c5SAndroid Build Coastguard Worker
397*8975f5c5SAndroid Build Coastguard Worker // Init program
398*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
399*8975f5c5SAndroid Build Coastguard Worker "#version 300 es\n"
400*8975f5c5SAndroid Build Coastguard Worker "in highp vec2 position;\n"
401*8975f5c5SAndroid Build Coastguard Worker "in highp vec2 redGreen;\n"
402*8975f5c5SAndroid Build Coastguard Worker "out highp vec2 v_data;\n"
403*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
404*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(position, 0, 1);\n"
405*8975f5c5SAndroid Build Coastguard Worker " v_data = redGreen;\n"
406*8975f5c5SAndroid Build Coastguard Worker "}";
407*8975f5c5SAndroid Build Coastguard Worker
408*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
409*8975f5c5SAndroid Build Coastguard Worker "#version 300 es\n"
410*8975f5c5SAndroid Build Coastguard Worker "in highp vec2 v_data;\n"
411*8975f5c5SAndroid Build Coastguard Worker "out highp vec4 FragColor;\n"
412*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
413*8975f5c5SAndroid Build Coastguard Worker " FragColor = vec4(dFdx(v_data.x), dFdy(v_data.y), 0, 1);\n"
414*8975f5c5SAndroid Build Coastguard Worker "}";
415*8975f5c5SAndroid Build Coastguard Worker
416*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, kFS);
417*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
418*8975f5c5SAndroid Build Coastguard Worker
419*8975f5c5SAndroid Build Coastguard Worker GLint positionLocation = glGetAttribLocation(program, "position");
420*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, positionLocation);
421*8975f5c5SAndroid Build Coastguard Worker
422*8975f5c5SAndroid Build Coastguard Worker GLint redGreenLocation = glGetAttribLocation(program, "redGreen");
423*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, redGreenLocation);
424*8975f5c5SAndroid Build Coastguard Worker
425*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
426*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
427*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
428*8975f5c5SAndroid Build Coastguard Worker
429*8975f5c5SAndroid Build Coastguard Worker glBindVertexArray(vertexArray);
430*8975f5c5SAndroid Build Coastguard Worker
431*8975f5c5SAndroid Build Coastguard Worker std::vector<GLushort> indices = {// 4 squares each made up of 6 vertices:
432*8975f5c5SAndroid Build Coastguard Worker // 1st square, in the upper-left part of window
433*8975f5c5SAndroid Build Coastguard Worker 0, 1, 2, 2, 3, 0,
434*8975f5c5SAndroid Build Coastguard Worker // 2nd square, in the upper-right part of window
435*8975f5c5SAndroid Build Coastguard Worker 4, 5, 6, 6, 7, 4,
436*8975f5c5SAndroid Build Coastguard Worker // 3rd square, in the lower-left part of window
437*8975f5c5SAndroid Build Coastguard Worker 8, 9, 10, 10, 11, 8,
438*8975f5c5SAndroid Build Coastguard Worker // 4th square, in the lower-right part of window
439*8975f5c5SAndroid Build Coastguard Worker 12, 13, 14, 14, 15, 12};
440*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
441*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
442*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
443*8975f5c5SAndroid Build Coastguard Worker
444*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> positionData = {// 4 squares each made up of quad vertices
445*8975f5c5SAndroid Build Coastguard Worker // 1st square, in the upper-left part of window
446*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
447*8975f5c5SAndroid Build Coastguard Worker // 2nd square, in the upper-right part of window
448*8975f5c5SAndroid Build Coastguard Worker 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
449*8975f5c5SAndroid Build Coastguard Worker // 3rd square, in the lower-left part of window
450*8975f5c5SAndroid Build Coastguard Worker -1.0f, 0.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f,
451*8975f5c5SAndroid Build Coastguard Worker // 4th square, in the lower-right part of window
452*8975f5c5SAndroid Build Coastguard Worker 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.0f};
453*8975f5c5SAndroid Build Coastguard Worker
454*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]);
455*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
456*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
457*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
458*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(positionLocation);
459*8975f5c5SAndroid Build Coastguard Worker
460*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> redGreenData = {// green(0,110), black(0,0), red(115,0), yellow(120,125)
461*8975f5c5SAndroid Build Coastguard Worker // 4 squares each made up of 4 pairs of half-color values:
462*8975f5c5SAndroid Build Coastguard Worker // 1st square, in the upper-left part of window
463*8975f5c5SAndroid Build Coastguard Worker 0.0f, 110.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 110.0f,
464*8975f5c5SAndroid Build Coastguard Worker // 2nd square, in the upper-right part of window
465*8975f5c5SAndroid Build Coastguard Worker 0.0f, 125.0f, 0.0f, 0.0f, 120.0f, 0.0f, 120.0f, 125.0f,
466*8975f5c5SAndroid Build Coastguard Worker // 3rd square, in the lower-left part of window
467*8975f5c5SAndroid Build Coastguard Worker 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
468*8975f5c5SAndroid Build Coastguard Worker // 4th square, in the lower-right part of window
469*8975f5c5SAndroid Build Coastguard Worker 0.0f, 0.0f, 0.0f, 0.0f, 115.0f, 0.0f, 115.0f, 0.0f};
470*8975f5c5SAndroid Build Coastguard Worker
471*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[1]);
472*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * redGreenData.size(), &redGreenData[0],
473*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
474*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(redGreenLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
475*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(redGreenLocation);
476*8975f5c5SAndroid Build Coastguard Worker
477*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
478*8975f5c5SAndroid Build Coastguard Worker
479*8975f5c5SAndroid Build Coastguard Worker // Draw and check the 4 corner pixels, to ensure we're getting the expected "colors"
480*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, nullptr);
481*8975f5c5SAndroid Build Coastguard Worker GLColor expectedPixelLowerLeft(0, 0, 0, 255);
482*8975f5c5SAndroid Build Coastguard Worker GLColor expectedPixelLowerRight(229, 0, 0, 255);
483*8975f5c5SAndroid Build Coastguard Worker GLColor expectedPixelUpperLeft(0, 219, 0, 255);
484*8975f5c5SAndroid Build Coastguard Worker GLColor expectedPixelUpperRight(239, 249, 0, 255);
485*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixelLowerLeft);
486*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, expectedPixelLowerRight);
487*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, expectedPixelUpperLeft);
488*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, expectedPixelUpperRight);
489*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
490*8975f5c5SAndroid Build Coastguard Worker
491*8975f5c5SAndroid Build Coastguard Worker // Make the image visible
492*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
493*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
494*8975f5c5SAndroid Build Coastguard Worker
495*8975f5c5SAndroid Build Coastguard Worker // Draw again and check the 4 center pixels, to ensure we're getting the expected "colors"
496*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, nullptr);
497*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((mSize / 2) - 1, (mSize / 2) - 1, expectedPixelLowerLeft);
498*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((mSize / 2) - 1, (mSize / 2), expectedPixelUpperLeft);
499*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((mSize / 2), (mSize / 2) - 1, expectedPixelLowerRight);
500*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((mSize / 2), (mSize / 2), expectedPixelUpperRight);
501*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
502*8975f5c5SAndroid Build Coastguard Worker }
503*8975f5c5SAndroid Build Coastguard Worker
504*8975f5c5SAndroid Build Coastguard Worker // Android-specific test that changes a window's rotation, which requires ContextVk::syncState() to
505*8975f5c5SAndroid Build Coastguard Worker // handle the new rotation
TEST_P(EGLPreRotationSurfaceTest,ChangeRotationWithDraw)506*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationSurfaceTest, ChangeRotationWithDraw)
507*8975f5c5SAndroid Build Coastguard Worker {
508*8975f5c5SAndroid Build Coastguard Worker // This test uses functionality that is only available on Android
509*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && !IsAndroid());
510*8975f5c5SAndroid Build Coastguard Worker
511*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
512*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
513*8975f5c5SAndroid Build Coastguard Worker
514*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
515*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
516*8975f5c5SAndroid Build Coastguard Worker
517*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
518*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
519*8975f5c5SAndroid Build Coastguard Worker
520*8975f5c5SAndroid Build Coastguard Worker // Init program
521*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
522*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 position;\n"
523*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 redGreen;\n"
524*8975f5c5SAndroid Build Coastguard Worker "varying vec2 v_data;\n"
525*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
526*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(position, 0, 1);\n"
527*8975f5c5SAndroid Build Coastguard Worker " v_data = redGreen;\n"
528*8975f5c5SAndroid Build Coastguard Worker "}";
529*8975f5c5SAndroid Build Coastguard Worker
530*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
531*8975f5c5SAndroid Build Coastguard Worker "varying highp vec2 v_data;\n"
532*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
533*8975f5c5SAndroid Build Coastguard Worker " gl_FragColor = vec4(v_data, 0, 1);\n"
534*8975f5c5SAndroid Build Coastguard Worker "}";
535*8975f5c5SAndroid Build Coastguard Worker
536*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, kFS);
537*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
538*8975f5c5SAndroid Build Coastguard Worker
539*8975f5c5SAndroid Build Coastguard Worker GLint positionLocation = glGetAttribLocation(program, "position");
540*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, positionLocation);
541*8975f5c5SAndroid Build Coastguard Worker
542*8975f5c5SAndroid Build Coastguard Worker GLint redGreenLocation = glGetAttribLocation(program, "redGreen");
543*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, redGreenLocation);
544*8975f5c5SAndroid Build Coastguard Worker
545*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
546*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
547*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
548*8975f5c5SAndroid Build Coastguard Worker
549*8975f5c5SAndroid Build Coastguard Worker glBindVertexArray(vertexArray);
550*8975f5c5SAndroid Build Coastguard Worker
551*8975f5c5SAndroid Build Coastguard Worker std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0};
552*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
553*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
554*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
555*8975f5c5SAndroid Build Coastguard Worker
556*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> positionData = {// quad vertices
557*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
558*8975f5c5SAndroid Build Coastguard Worker
559*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]);
560*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
561*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
562*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
563*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(positionLocation);
564*8975f5c5SAndroid Build Coastguard Worker
565*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> redGreenData = {// green(0,1), black(0,0), red(1,0), yellow(1,1)
566*8975f5c5SAndroid Build Coastguard Worker 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f};
567*8975f5c5SAndroid Build Coastguard Worker
568*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[1]);
569*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * redGreenData.size(), &redGreenData[0],
570*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
571*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(redGreenLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
572*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(redGreenLocation);
573*8975f5c5SAndroid Build Coastguard Worker
574*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
575*8975f5c5SAndroid Build Coastguard Worker
576*8975f5c5SAndroid Build Coastguard Worker // Change the rotation back and forth between landscape and portrait, and make sure that the
577*8975f5c5SAndroid Build Coastguard Worker // drawing and reading happen consistently with the desired rotation.
578*8975f5c5SAndroid Build Coastguard Worker // Last rotation needs to be portrait, since other tests expect it to be the default.
579*8975f5c5SAndroid Build Coastguard Worker for (int i = 0; i < 4; i++)
580*8975f5c5SAndroid Build Coastguard Worker {
581*8975f5c5SAndroid Build Coastguard Worker bool landscape;
582*8975f5c5SAndroid Build Coastguard Worker EGLint actualWidth = 0;
583*8975f5c5SAndroid Build Coastguard Worker EGLint actualHeight = 0;
584*8975f5c5SAndroid Build Coastguard Worker EGLint desiredWidth = 0;
585*8975f5c5SAndroid Build Coastguard Worker EGLint desiredHeight = 0;
586*8975f5c5SAndroid Build Coastguard Worker if ((i % 2) == 0)
587*8975f5c5SAndroid Build Coastguard Worker {
588*8975f5c5SAndroid Build Coastguard Worker landscape = true;
589*8975f5c5SAndroid Build Coastguard Worker desiredWidth = 300;
590*8975f5c5SAndroid Build Coastguard Worker desiredHeight = 200;
591*8975f5c5SAndroid Build Coastguard Worker }
592*8975f5c5SAndroid Build Coastguard Worker else
593*8975f5c5SAndroid Build Coastguard Worker {
594*8975f5c5SAndroid Build Coastguard Worker landscape = false;
595*8975f5c5SAndroid Build Coastguard Worker desiredWidth = 200;
596*8975f5c5SAndroid Build Coastguard Worker desiredHeight = 300;
597*8975f5c5SAndroid Build Coastguard Worker }
598*8975f5c5SAndroid Build Coastguard Worker mOSWindow->resize(desiredWidth, desiredHeight);
599*8975f5c5SAndroid Build Coastguard Worker // setOrientation() uses a reverse-JNI call, which sends data to other parts of Android.
600*8975f5c5SAndroid Build Coastguard Worker // Sometime later (i.e. asynchronously), the window is updated. Sleep a little here, and
601*8975f5c5SAndroid Build Coastguard Worker // then allow for multiple eglSwapBuffers calls to eventually see the new rotation.
602*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(desiredWidth, desiredHeight);
603*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
604*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
605*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
606*8975f5c5SAndroid Build Coastguard Worker
607*8975f5c5SAndroid Build Coastguard Worker while ((actualWidth != desiredWidth) && (actualHeight != desiredHeight))
608*8975f5c5SAndroid Build Coastguard Worker {
609*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
610*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
611*8975f5c5SAndroid Build Coastguard Worker if (landscape)
612*8975f5c5SAndroid Build Coastguard Worker {
613*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor::red);
614*8975f5c5SAndroid Build Coastguard Worker }
615*8975f5c5SAndroid Build Coastguard Worker else
616*8975f5c5SAndroid Build Coastguard Worker {
617*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor::green);
618*8975f5c5SAndroid Build Coastguard Worker }
619*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
620*8975f5c5SAndroid Build Coastguard Worker
621*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
622*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
623*8975f5c5SAndroid Build Coastguard Worker
624*8975f5c5SAndroid Build Coastguard Worker eglQuerySurface(mDisplay, mWindowSurface, EGL_HEIGHT, &actualHeight);
625*8975f5c5SAndroid Build Coastguard Worker eglQuerySurface(mDisplay, mWindowSurface, EGL_WIDTH, &actualWidth);
626*8975f5c5SAndroid Build Coastguard Worker }
627*8975f5c5SAndroid Build Coastguard Worker }
628*8975f5c5SAndroid Build Coastguard Worker }
629*8975f5c5SAndroid Build Coastguard Worker
630*8975f5c5SAndroid Build Coastguard Worker // A slight variation of EGLPreRotationSurfaceTest, where the initial window size is 400x300, yet
631*8975f5c5SAndroid Build Coastguard Worker // the drawing is still 256x256. In addition, gl_FragCoord is used in a "clever" way, as the color
632*8975f5c5SAndroid Build Coastguard Worker // of the 256x256 drawing area, which reproduces an interesting pre-rotation case from the
633*8975f5c5SAndroid Build Coastguard Worker // following dEQP tests:
634*8975f5c5SAndroid Build Coastguard Worker //
635*8975f5c5SAndroid Build Coastguard Worker // - dEQP.GLES31/functional_texture_multisample_samples_*_sample_position
636*8975f5c5SAndroid Build Coastguard Worker //
637*8975f5c5SAndroid Build Coastguard Worker // This will test the rotation of gl_FragCoord, as well as the viewport, scissor, and rendering
638*8975f5c5SAndroid Build Coastguard Worker // area calculations, especially when the Android device is rotated.
639*8975f5c5SAndroid Build Coastguard Worker class EGLPreRotationLargeSurfaceTest : public EGLPreRotationSurfaceTest
640*8975f5c5SAndroid Build Coastguard Worker {
641*8975f5c5SAndroid Build Coastguard Worker protected:
EGLPreRotationLargeSurfaceTest()642*8975f5c5SAndroid Build Coastguard Worker EGLPreRotationLargeSurfaceTest() : mSize(256) {}
643*8975f5c5SAndroid Build Coastguard Worker
testSetUp()644*8975f5c5SAndroid Build Coastguard Worker void testSetUp() override
645*8975f5c5SAndroid Build Coastguard Worker {
646*8975f5c5SAndroid Build Coastguard Worker mOSWindow = OSWindow::New();
647*8975f5c5SAndroid Build Coastguard Worker mOSWindow->initialize("EGLSurfaceTest", 400, 300);
648*8975f5c5SAndroid Build Coastguard Worker }
649*8975f5c5SAndroid Build Coastguard Worker
650*8975f5c5SAndroid Build Coastguard Worker int mSize;
651*8975f5c5SAndroid Build Coastguard Worker };
652*8975f5c5SAndroid Build Coastguard Worker
653*8975f5c5SAndroid Build Coastguard Worker // Provide a predictable pattern for testing pre-rotation
TEST_P(EGLPreRotationLargeSurfaceTest,OrientedWindowWithFragCoordDraw)654*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationLargeSurfaceTest, OrientedWindowWithFragCoordDraw)
655*8975f5c5SAndroid Build Coastguard Worker {
656*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
657*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
658*8975f5c5SAndroid Build Coastguard Worker
659*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
660*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
661*8975f5c5SAndroid Build Coastguard Worker
662*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
663*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
664*8975f5c5SAndroid Build Coastguard Worker
665*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
666*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
667*8975f5c5SAndroid Build Coastguard Worker
668*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
669*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
670*8975f5c5SAndroid Build Coastguard Worker
671*8975f5c5SAndroid Build Coastguard Worker // Init program
672*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
673*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 position;\n"
674*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
675*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(position, 0, 1);\n"
676*8975f5c5SAndroid Build Coastguard Worker "}";
677*8975f5c5SAndroid Build Coastguard Worker
678*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
679*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
680*8975f5c5SAndroid Build Coastguard Worker " gl_FragColor = vec4(gl_FragCoord.x / 256.0, gl_FragCoord.y / 256.0, 0.0, 1.0);\n"
681*8975f5c5SAndroid Build Coastguard Worker "}";
682*8975f5c5SAndroid Build Coastguard Worker
683*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, kFS);
684*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
685*8975f5c5SAndroid Build Coastguard Worker
686*8975f5c5SAndroid Build Coastguard Worker GLint positionLocation = glGetAttribLocation(program, "position");
687*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, positionLocation);
688*8975f5c5SAndroid Build Coastguard Worker
689*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
690*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
691*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffer;
692*8975f5c5SAndroid Build Coastguard Worker
693*8975f5c5SAndroid Build Coastguard Worker glBindVertexArray(vertexArray);
694*8975f5c5SAndroid Build Coastguard Worker
695*8975f5c5SAndroid Build Coastguard Worker std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0};
696*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
697*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
698*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
699*8975f5c5SAndroid Build Coastguard Worker
700*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> positionData = {// quad vertices
701*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
702*8975f5c5SAndroid Build Coastguard Worker
703*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
704*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
705*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
706*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
707*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(positionLocation);
708*8975f5c5SAndroid Build Coastguard Worker
709*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
710*8975f5c5SAndroid Build Coastguard Worker
711*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
712*8975f5c5SAndroid Build Coastguard Worker
713*8975f5c5SAndroid Build Coastguard Worker testDrawingAndReadPixels();
714*8975f5c5SAndroid Build Coastguard Worker }
715*8975f5c5SAndroid Build Coastguard Worker
716*8975f5c5SAndroid Build Coastguard Worker // Pre-rotation tests for glBlitFramebuffer. A slight variation of EGLPreRotationLargeSurfaceTest,
717*8975f5c5SAndroid Build Coastguard Worker // where the initial window size is still 400x300, and the drawing is still 256x256. In addition,
718*8975f5c5SAndroid Build Coastguard Worker // glBlitFramebuffer is tested in a variety of ways. Separate tests are used to make debugging
719*8975f5c5SAndroid Build Coastguard Worker // simpler, but they all share common setup. These tests reproduce interesting pre-rotation cases
720*8975f5c5SAndroid Build Coastguard Worker // from dEQP tests such as the following:
721*8975f5c5SAndroid Build Coastguard Worker //
722*8975f5c5SAndroid Build Coastguard Worker // - dEQP.GLES3/functional_fbo_blit_default_framebuffer_*
723*8975f5c5SAndroid Build Coastguard Worker // - dEQP.GLES3/functional_fbo_invalidate_*
724*8975f5c5SAndroid Build Coastguard Worker constexpr GLuint kCoordMidWayShort = 127;
725*8975f5c5SAndroid Build Coastguard Worker constexpr GLuint kCoordMidWayLong = 128;
726*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorMidWayShortShort = GLColor(127, 127, 0, 255);
727*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorMidWayShortLong = GLColor(127, 128, 0, 255);
728*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorMidWayLongShort = GLColor(128, 127, 0, 255);
729*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorMidWayLongLong = GLColor(128, 128, 0, 255);
730*8975f5c5SAndroid Build Coastguard Worker // When scaling horizontally, the "black" and "green" colors have a 1 in the red component
731*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorScaleHorizBlack = GLColor(1, 0, 0, 255);
732*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorScaleHorizGreen = GLColor(1, 255, 0, 255);
733*8975f5c5SAndroid Build Coastguard Worker // When scaling vertically, the "black" and "red" colors have a 1 in the green component
734*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorScaleVertBlack = GLColor(0, 1, 0, 255);
735*8975f5c5SAndroid Build Coastguard Worker constexpr GLColor kColorScaleVertRed = GLColor(255, 1, 0, 255);
736*8975f5c5SAndroid Build Coastguard Worker
737*8975f5c5SAndroid Build Coastguard Worker class EGLPreRotationBlitFramebufferTest : public EGLPreRotationLargeSurfaceTest
738*8975f5c5SAndroid Build Coastguard Worker {
739*8975f5c5SAndroid Build Coastguard Worker protected:
EGLPreRotationBlitFramebufferTest()740*8975f5c5SAndroid Build Coastguard Worker EGLPreRotationBlitFramebufferTest() {}
741*8975f5c5SAndroid Build Coastguard Worker
createProgram()742*8975f5c5SAndroid Build Coastguard Worker GLuint createProgram()
743*8975f5c5SAndroid Build Coastguard Worker {
744*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
745*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 position;\n"
746*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 redGreen;\n"
747*8975f5c5SAndroid Build Coastguard Worker "varying vec2 v_data;\n"
748*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
749*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(position, 0, 1);\n"
750*8975f5c5SAndroid Build Coastguard Worker " v_data = redGreen;\n"
751*8975f5c5SAndroid Build Coastguard Worker "}";
752*8975f5c5SAndroid Build Coastguard Worker
753*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
754*8975f5c5SAndroid Build Coastguard Worker "varying highp vec2 v_data;\n"
755*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
756*8975f5c5SAndroid Build Coastguard Worker " gl_FragColor = vec4(v_data, 0, 1);\n"
757*8975f5c5SAndroid Build Coastguard Worker "}";
758*8975f5c5SAndroid Build Coastguard Worker
759*8975f5c5SAndroid Build Coastguard Worker return CompileProgram(kVS, kFS);
760*8975f5c5SAndroid Build Coastguard Worker }
761*8975f5c5SAndroid Build Coastguard Worker
initializeGeometry(GLuint program,GLBuffer * indexBuffer,GLVertexArray * vertexArray,GLBuffer * vertexBuffers)762*8975f5c5SAndroid Build Coastguard Worker void initializeGeometry(GLuint program,
763*8975f5c5SAndroid Build Coastguard Worker GLBuffer *indexBuffer,
764*8975f5c5SAndroid Build Coastguard Worker GLVertexArray *vertexArray,
765*8975f5c5SAndroid Build Coastguard Worker GLBuffer *vertexBuffers)
766*8975f5c5SAndroid Build Coastguard Worker {
767*8975f5c5SAndroid Build Coastguard Worker GLint positionLocation = glGetAttribLocation(program, "position");
768*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, positionLocation);
769*8975f5c5SAndroid Build Coastguard Worker
770*8975f5c5SAndroid Build Coastguard Worker GLint redGreenLocation = glGetAttribLocation(program, "redGreen");
771*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, redGreenLocation);
772*8975f5c5SAndroid Build Coastguard Worker
773*8975f5c5SAndroid Build Coastguard Worker glBindVertexArray(*vertexArray);
774*8975f5c5SAndroid Build Coastguard Worker
775*8975f5c5SAndroid Build Coastguard Worker std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0};
776*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
777*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
778*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
779*8975f5c5SAndroid Build Coastguard Worker
780*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> positionData = {// quad vertices
781*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
782*8975f5c5SAndroid Build Coastguard Worker
783*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]);
784*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
785*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
786*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2,
787*8975f5c5SAndroid Build Coastguard Worker nullptr);
788*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(positionLocation);
789*8975f5c5SAndroid Build Coastguard Worker
790*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> redGreenData = {// green(0,1), black(0,0), red(1,0), yellow(1,1)
791*8975f5c5SAndroid Build Coastguard Worker 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f};
792*8975f5c5SAndroid Build Coastguard Worker
793*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[1]);
794*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * redGreenData.size(), &redGreenData[0],
795*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
796*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(redGreenLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2,
797*8975f5c5SAndroid Build Coastguard Worker nullptr);
798*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(redGreenLocation);
799*8975f5c5SAndroid Build Coastguard Worker }
800*8975f5c5SAndroid Build Coastguard Worker
initializeFBO(GLFramebuffer * framebuffer,GLTexture * texture)801*8975f5c5SAndroid Build Coastguard Worker void initializeFBO(GLFramebuffer *framebuffer, GLTexture *texture)
802*8975f5c5SAndroid Build Coastguard Worker {
803*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, *texture);
804*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
805*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
806*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
807*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
808*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mSize, mSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
809*8975f5c5SAndroid Build Coastguard Worker nullptr);
810*8975f5c5SAndroid Build Coastguard Worker
811*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, *framebuffer);
812*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *texture, 0);
813*8975f5c5SAndroid Build Coastguard Worker }
814*8975f5c5SAndroid Build Coastguard Worker
815*8975f5c5SAndroid Build Coastguard Worker // Ensures that the correct colors are where they should be when the entire 256x256 pattern has
816*8975f5c5SAndroid Build Coastguard Worker // been rendered or blitted to a location relative to an x and y offset.
test256x256PredictablePattern(GLint xOffset,GLint yOffset)817*8975f5c5SAndroid Build Coastguard Worker void test256x256PredictablePattern(GLint xOffset, GLint yOffset)
818*8975f5c5SAndroid Build Coastguard Worker {
819*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + 0, GLColor::black);
820*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + mSize - 1, GLColor::green);
821*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + 0, GLColor::red);
822*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + mSize - 1, GLColor::yellow);
823*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + kCoordMidWayShort,
824*8975f5c5SAndroid Build Coastguard Worker kColorMidWayShortShort);
825*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + kCoordMidWayLong,
826*8975f5c5SAndroid Build Coastguard Worker kColorMidWayShortLong);
827*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayLong, yOffset + kCoordMidWayShort,
828*8975f5c5SAndroid Build Coastguard Worker kColorMidWayLongShort);
829*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayLong, yOffset + kCoordMidWayLong,
830*8975f5c5SAndroid Build Coastguard Worker kColorMidWayLongLong);
831*8975f5c5SAndroid Build Coastguard Worker }
832*8975f5c5SAndroid Build Coastguard Worker };
833*8975f5c5SAndroid Build Coastguard Worker
834*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
835*8975f5c5SAndroid Build Coastguard Worker // to blit that pattern into various places within the 400x300 window
TEST_P(EGLPreRotationBlitFramebufferTest,BasicBlitFramebuffer)836*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BasicBlitFramebuffer)
837*8975f5c5SAndroid Build Coastguard Worker {
838*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
839*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
840*8975f5c5SAndroid Build Coastguard Worker
841*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
842*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
843*8975f5c5SAndroid Build Coastguard Worker
844*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
845*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
846*8975f5c5SAndroid Build Coastguard Worker
847*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
848*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
849*8975f5c5SAndroid Build Coastguard Worker
850*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
851*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
852*8975f5c5SAndroid Build Coastguard Worker
853*8975f5c5SAndroid Build Coastguard Worker // Init program
854*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
855*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
856*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
857*8975f5c5SAndroid Build Coastguard Worker
858*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
859*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
860*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
861*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
862*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
863*8975f5c5SAndroid Build Coastguard Worker
864*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
865*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
866*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
867*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
868*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
869*8975f5c5SAndroid Build Coastguard Worker
870*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
871*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
872*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
873*8975f5c5SAndroid Build Coastguard Worker
874*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
875*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
876*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
877*8975f5c5SAndroid Build Coastguard Worker
878*8975f5c5SAndroid Build Coastguard Worker //
879*8975f5c5SAndroid Build Coastguard Worker // Test blitting the entire FBO image to a 256x256 part of the default framebuffer (no scaling)
880*8975f5c5SAndroid Build Coastguard Worker //
881*8975f5c5SAndroid Build Coastguard Worker
882*8975f5c5SAndroid Build Coastguard Worker // Blit from the FBO to the default framebuffer (i.e. the swapchain)
883*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
884*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
885*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
886*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
887*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
888*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, 0, 0, mSize, mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
889*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
890*8975f5c5SAndroid Build Coastguard Worker
891*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
892*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
893*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
894*8975f5c5SAndroid Build Coastguard Worker
895*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
896*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
897*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, 0, 0, mSize, mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
898*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
899*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
900*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
901*8975f5c5SAndroid Build Coastguard Worker
902*8975f5c5SAndroid Build Coastguard Worker // Clear to black and blit to a different part of the window
903*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
904*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 40;
905*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 30;
906*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
907*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
908*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
909*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
910*8975f5c5SAndroid Build Coastguard Worker
911*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
912*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
913*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
914*8975f5c5SAndroid Build Coastguard Worker
915*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
916*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
917*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
918*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
919*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
920*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(xOffset, yOffset);
921*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
922*8975f5c5SAndroid Build Coastguard Worker
923*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
924*8975f5c5SAndroid Build Coastguard Worker }
925*8975f5c5SAndroid Build Coastguard Worker
926*8975f5c5SAndroid Build Coastguard Worker // Blit the ms0 stencil buffer to the default framebuffer with rotation on android.
TEST_P(EGLPreRotationBlitFramebufferTest,BlitStencilWithRotation)927*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BlitStencilWithRotation)
928*8975f5c5SAndroid Build Coastguard Worker {
929*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
930*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
931*8975f5c5SAndroid Build Coastguard Worker
932*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
933*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
934*8975f5c5SAndroid Build Coastguard Worker
935*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
936*8975f5c5SAndroid Build Coastguard Worker
937*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
938*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888d24s8Config();
939*8975f5c5SAndroid Build Coastguard Worker
940*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
941*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
942*8975f5c5SAndroid Build Coastguard Worker
943*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(300, 400);
944*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
945*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
946*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
947*8975f5c5SAndroid Build Coastguard Worker
948*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorbuf;
949*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorbuf.get());
950*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_RGBA8, 64, 128);
951*8975f5c5SAndroid Build Coastguard Worker
952*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer depthstencilbuf;
953*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, depthstencilbuf.get());
954*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_DEPTH24_STENCIL8, 64, 128);
955*8975f5c5SAndroid Build Coastguard Worker
956*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
957*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
958*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
959*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
960*8975f5c5SAndroid Build Coastguard Worker depthstencilbuf);
961*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
962*8975f5c5SAndroid Build Coastguard Worker depthstencilbuf);
963*8975f5c5SAndroid Build Coastguard Worker glCheckFramebufferStatus(GL_FRAMEBUFFER);
964*8975f5c5SAndroid Build Coastguard Worker
965*8975f5c5SAndroid Build Coastguard Worker glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
966*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
967*8975f5c5SAndroid Build Coastguard Worker
968*8975f5c5SAndroid Build Coastguard Worker // Replace stencil to 1.
969*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), essl3_shaders::fs::Red());
970*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
971*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
972*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 1, 255);
973*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.8f);
974*8975f5c5SAndroid Build Coastguard Worker
975*8975f5c5SAndroid Build Coastguard Worker // Blit stencil buffer to default frambuffer.
976*8975f5c5SAndroid Build Coastguard Worker GLenum attachments1[] = {GL_COLOR_ATTACHMENT0};
977*8975f5c5SAndroid Build Coastguard Worker glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments1);
978*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
979*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, 64, 128, 0, 0, 64, 128, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
980*8975f5c5SAndroid Build Coastguard Worker GL_NEAREST);
981*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
982*8975f5c5SAndroid Build Coastguard Worker
983*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawGreen, essl3_shaders::vs::Simple(), essl3_shaders::fs::Green());
984*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_STENCIL_TEST);
985*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawGreen.get(), essl3_shaders::PositionAttrib(), 0.5f);
986*8975f5c5SAndroid Build Coastguard Worker
987*8975f5c5SAndroid Build Coastguard Worker // Draw blue color if the stencil is equal to 1.
988*8975f5c5SAndroid Build Coastguard Worker // If the blit finished successfully, the stencil test should all pass.
989*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawBlue, essl3_shaders::vs::Simple(), essl3_shaders::fs::Blue());
990*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
991*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 1, 255);
992*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawBlue.get(), essl3_shaders::PositionAttrib(), 0.3f);
993*8975f5c5SAndroid Build Coastguard Worker
994*8975f5c5SAndroid Build Coastguard Worker // Check the result, especially the boundaries.
995*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 127, GLColor::blue);
996*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(32, 127, GLColor::blue);
997*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(32, 0, GLColor::blue);
998*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(63, 0, GLColor::blue);
999*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(63, 64, GLColor::blue);
1000*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(32, 64, GLColor::blue);
1001*8975f5c5SAndroid Build Coastguard Worker
1002*8975f5c5SAndroid Build Coastguard Worker // Some pixels around x=0/63 (related to the pre-rotation degree) still fail on android.
1003*8975f5c5SAndroid Build Coastguard Worker // From the image in the window, the failures near one of the image's edge look like "aliasing".
1004*8975f5c5SAndroid Build Coastguard Worker // We need to fix blit with pre-rotation. http://anglebug.com/42263612
1005*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1006*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(0, 64, GLColor::blue);
1007*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(63, 1, GLColor::blue);
1008*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(63, 127, GLColor::blue);
1009*8975f5c5SAndroid Build Coastguard Worker
1010*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1011*8975f5c5SAndroid Build Coastguard Worker
1012*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1013*8975f5c5SAndroid Build Coastguard Worker }
1014*8975f5c5SAndroid Build Coastguard Worker
1015*8975f5c5SAndroid Build Coastguard Worker // Blit the multisample stencil buffer to the default framebuffer with rotation on android.
TEST_P(EGLPreRotationBlitFramebufferTest,BlitMultisampleStencilWithRotation)1016*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BlitMultisampleStencilWithRotation)
1017*8975f5c5SAndroid Build Coastguard Worker {
1018*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1019*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1020*8975f5c5SAndroid Build Coastguard Worker
1021*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1022*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1023*8975f5c5SAndroid Build Coastguard Worker
1024*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1025*8975f5c5SAndroid Build Coastguard Worker
1026*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1027*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888d24s8Config();
1028*8975f5c5SAndroid Build Coastguard Worker
1029*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1030*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1031*8975f5c5SAndroid Build Coastguard Worker
1032*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(300, 400);
1033*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
1034*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1035*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1036*8975f5c5SAndroid Build Coastguard Worker
1037*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorbuf;
1038*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorbuf.get());
1039*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, 128, 64);
1040*8975f5c5SAndroid Build Coastguard Worker
1041*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer depthstencilbuf;
1042*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, depthstencilbuf.get());
1043*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, 128, 64);
1044*8975f5c5SAndroid Build Coastguard Worker
1045*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1046*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1047*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
1048*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
1049*8975f5c5SAndroid Build Coastguard Worker depthstencilbuf);
1050*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1051*8975f5c5SAndroid Build Coastguard Worker depthstencilbuf);
1052*8975f5c5SAndroid Build Coastguard Worker glCheckFramebufferStatus(GL_FRAMEBUFFER);
1053*8975f5c5SAndroid Build Coastguard Worker
1054*8975f5c5SAndroid Build Coastguard Worker glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1055*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1056*8975f5c5SAndroid Build Coastguard Worker
1057*8975f5c5SAndroid Build Coastguard Worker // Replace stencil to 1.
1058*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), essl3_shaders::fs::Red());
1059*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
1060*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
1061*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 1, 255);
1062*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.8f);
1063*8975f5c5SAndroid Build Coastguard Worker
1064*8975f5c5SAndroid Build Coastguard Worker // Blit multisample stencil buffer to default frambuffer.
1065*8975f5c5SAndroid Build Coastguard Worker GLenum attachments1[] = {GL_COLOR_ATTACHMENT0};
1066*8975f5c5SAndroid Build Coastguard Worker glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments1);
1067*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1068*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, 128, 64, 0, 0, 128, 64, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
1069*8975f5c5SAndroid Build Coastguard Worker GL_NEAREST);
1070*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1071*8975f5c5SAndroid Build Coastguard Worker
1072*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawGreen, essl3_shaders::vs::Simple(), essl3_shaders::fs::Green());
1073*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_STENCIL_TEST);
1074*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawGreen.get(), essl3_shaders::PositionAttrib(), 0.5f);
1075*8975f5c5SAndroid Build Coastguard Worker
1076*8975f5c5SAndroid Build Coastguard Worker // Draw blue color if the stencil is equal to 1.
1077*8975f5c5SAndroid Build Coastguard Worker // If the blit finished successfully, the stencil test should all pass.
1078*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawBlue, essl3_shaders::vs::Simple(), essl3_shaders::fs::Blue());
1079*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
1080*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 1, 255);
1081*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawBlue.get(), essl3_shaders::PositionAttrib(), 0.3f);
1082*8975f5c5SAndroid Build Coastguard Worker
1083*8975f5c5SAndroid Build Coastguard Worker // Check the result, especially the boundaries.
1084*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(127, 32, GLColor::blue);
1085*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(64, 32, GLColor::blue);
1086*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 63, GLColor::blue);
1087*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(64, 63, GLColor::blue);
1088*8975f5c5SAndroid Build Coastguard Worker
1089*8975f5c5SAndroid Build Coastguard Worker // Some pixels around x=0/127 or y=0 (related to the pre-rotation degree)still fail on android.
1090*8975f5c5SAndroid Build Coastguard Worker // We need to fix blit with pre-rotation. http://anglebug.com/42263612
1091*8975f5c5SAndroid Build Coastguard Worker // Failures of Rotated90Degrees.
1092*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(127, 1, GLColor::blue);
1093*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(127, 63, GLColor::blue);
1094*8975f5c5SAndroid Build Coastguard Worker // Failures of Rotated180Degrees.
1095*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(64, 0, GLColor::blue);
1096*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(127, 0, GLColor::blue);
1097*8975f5c5SAndroid Build Coastguard Worker // Failures of Rotated270Degrees.
1098*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1099*8975f5c5SAndroid Build Coastguard Worker // EXPECT_PIXEL_COLOR_EQ(0, 32, GLColor::blue);
1100*8975f5c5SAndroid Build Coastguard Worker
1101*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1102*8975f5c5SAndroid Build Coastguard Worker
1103*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1104*8975f5c5SAndroid Build Coastguard Worker }
1105*8975f5c5SAndroid Build Coastguard Worker
1106*8975f5c5SAndroid Build Coastguard Worker // Blit stencil to default framebuffer with flip and prerotation.
TEST_P(EGLPreRotationBlitFramebufferTest,BlitStencilWithFlip)1107*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BlitStencilWithFlip)
1108*8975f5c5SAndroid Build Coastguard Worker {
1109*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1110*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1111*8975f5c5SAndroid Build Coastguard Worker
1112*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1113*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1114*8975f5c5SAndroid Build Coastguard Worker
1115*8975f5c5SAndroid Build Coastguard Worker // We need to fix blit with pre-rotation. http://anglebug.com/42263612
1116*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsPixel4() || IsPixel4XL() || IsWindows());
1117*8975f5c5SAndroid Build Coastguard Worker
1118*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1119*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1120*8975f5c5SAndroid Build Coastguard Worker
1121*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1122*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888d24s8Config();
1123*8975f5c5SAndroid Build Coastguard Worker
1124*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1125*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1126*8975f5c5SAndroid Build Coastguard Worker
1127*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(300, 400);
1128*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
1129*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1130*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1131*8975f5c5SAndroid Build Coastguard Worker
1132*8975f5c5SAndroid Build Coastguard Worker constexpr int kSize = 128;
1133*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, kSize, kSize);
1134*8975f5c5SAndroid Build Coastguard Worker
1135*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorbuf;
1136*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorbuf.get());
1137*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_RGBA8, kSize, kSize);
1138*8975f5c5SAndroid Build Coastguard Worker
1139*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer depthstencilbuf;
1140*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, depthstencilbuf.get());
1141*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_DEPTH24_STENCIL8, kSize, kSize);
1142*8975f5c5SAndroid Build Coastguard Worker
1143*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1144*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1145*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
1146*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
1147*8975f5c5SAndroid Build Coastguard Worker depthstencilbuf);
1148*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1149*8975f5c5SAndroid Build Coastguard Worker depthstencilbuf);
1150*8975f5c5SAndroid Build Coastguard Worker glCheckFramebufferStatus(GL_FRAMEBUFFER);
1151*8975f5c5SAndroid Build Coastguard Worker
1152*8975f5c5SAndroid Build Coastguard Worker glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1153*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1154*8975f5c5SAndroid Build Coastguard Worker
1155*8975f5c5SAndroid Build Coastguard Worker // Replace stencil to 1.
1156*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), essl3_shaders::fs::Red());
1157*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
1158*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
1159*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 1, 255);
1160*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.8f);
1161*8975f5c5SAndroid Build Coastguard Worker
1162*8975f5c5SAndroid Build Coastguard Worker // Blit stencil buffer to default frambuffer with X-flip.
1163*8975f5c5SAndroid Build Coastguard Worker GLenum attachments1[] = {GL_COLOR_ATTACHMENT0};
1164*8975f5c5SAndroid Build Coastguard Worker glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments1);
1165*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1166*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, kSize, 0, 0, kSize,
1167*8975f5c5SAndroid Build Coastguard Worker GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
1168*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1169*8975f5c5SAndroid Build Coastguard Worker
1170*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawGreen, essl3_shaders::vs::Simple(), essl3_shaders::fs::Green());
1171*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_STENCIL_TEST);
1172*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawGreen.get(), essl3_shaders::PositionAttrib(), 0.5f);
1173*8975f5c5SAndroid Build Coastguard Worker
1174*8975f5c5SAndroid Build Coastguard Worker // Draw blue color if the stencil is equal to 1.
1175*8975f5c5SAndroid Build Coastguard Worker // If the blit finished successfully, the stencil test should all pass.
1176*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
1177*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 1, 255);
1178*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(gradientProgram, essl31_shaders::vs::Passthrough(),
1179*8975f5c5SAndroid Build Coastguard Worker essl31_shaders::fs::RedGreenGradient());
1180*8975f5c5SAndroid Build Coastguard Worker drawQuad(gradientProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true);
1181*8975f5c5SAndroid Build Coastguard Worker
1182*8975f5c5SAndroid Build Coastguard Worker // Check the result, especially the boundaries.
1183*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 255, 1.0); // Black
1184*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 253, 0, 0, 255, 1.0); // Red
1185*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 253, 0, 255, 1.0); // Green
1186*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 253, 253, 0, 255, 1.0); // Yellow
1187*8975f5c5SAndroid Build Coastguard Worker
1188*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1189*8975f5c5SAndroid Build Coastguard Worker
1190*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1191*8975f5c5SAndroid Build Coastguard Worker }
1192*8975f5c5SAndroid Build Coastguard Worker
1193*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer to default framebuffer with Y-flip/X-flip.
TEST_P(EGLPreRotationBlitFramebufferTest,BlitColorToDefault)1194*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BlitColorToDefault)
1195*8975f5c5SAndroid Build Coastguard Worker {
1196*8975f5c5SAndroid Build Coastguard Worker // This test uses functionality that is only available on Android
1197*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && !IsAndroid());
1198*8975f5c5SAndroid Build Coastguard Worker
1199*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1200*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1201*8975f5c5SAndroid Build Coastguard Worker
1202*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1203*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1204*8975f5c5SAndroid Build Coastguard Worker
1205*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1206*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1207*8975f5c5SAndroid Build Coastguard Worker
1208*8975f5c5SAndroid Build Coastguard Worker constexpr int kSize = 128;
1209*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, kSize, kSize);
1210*8975f5c5SAndroid Build Coastguard Worker
1211*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorbuf;
1212*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorbuf.get());
1213*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_RGBA8, kSize, kSize);
1214*8975f5c5SAndroid Build Coastguard Worker
1215*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1216*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1217*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
1218*8975f5c5SAndroid Build Coastguard Worker
1219*8975f5c5SAndroid Build Coastguard Worker glCheckFramebufferStatus(GL_FRAMEBUFFER);
1220*8975f5c5SAndroid Build Coastguard Worker
1221*8975f5c5SAndroid Build Coastguard Worker glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1222*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1223*8975f5c5SAndroid Build Coastguard Worker
1224*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(gradientProgram, essl31_shaders::vs::Passthrough(),
1225*8975f5c5SAndroid Build Coastguard Worker essl31_shaders::fs::RedGreenGradient());
1226*8975f5c5SAndroid Build Coastguard Worker
1227*8975f5c5SAndroid Build Coastguard Worker EGLint desiredWidth = 300;
1228*8975f5c5SAndroid Build Coastguard Worker EGLint desiredHeight = 400;
1229*8975f5c5SAndroid Build Coastguard Worker mOSWindow->resize(desiredWidth, desiredHeight);
1230*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(desiredWidth, desiredHeight);
1231*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
1232*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1233*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1234*8975f5c5SAndroid Build Coastguard Worker
1235*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.get());
1236*8975f5c5SAndroid Build Coastguard Worker drawQuad(gradientProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true);
1237*8975f5c5SAndroid Build Coastguard Worker
1238*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer to default frambuffer without flip.
1239*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1240*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1241*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1242*8975f5c5SAndroid Build Coastguard Worker
1243*8975f5c5SAndroid Build Coastguard Worker // Check the result, especially the boundaries.
1244*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 255, 1.0); // Balck
1245*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 253, 0, 0, 255, 1.0); // Red
1246*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 253, 0, 255, 1.0); // Green
1247*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 253, 253, 0, 255, 1.0); // Yellow
1248*8975f5c5SAndroid Build Coastguard Worker
1249*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer to default frambuffer with Y-flip.
1250*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get());
1251*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1252*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, 0, kSize, kSize, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1253*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1254*8975f5c5SAndroid Build Coastguard Worker
1255*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 0, 253, 0, 255, 1.0); // Green
1256*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 253, 253, 0, 255, 1.0); // Yellow
1257*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 0, 0, 255, 1.0); // Balck
1258*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 253, 0, 0, 255, 1.0); // Red
1259*8975f5c5SAndroid Build Coastguard Worker
1260*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer to default frambuffer with X-flip.
1261*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get());
1262*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1263*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, kSize, 0, 0, kSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1264*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1265*8975f5c5SAndroid Build Coastguard Worker
1266*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 253, 0, 0, 255, 1.0); // Red
1267*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 0, 0, 0, 255, 1.0); // Balck
1268*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 253, 253, 0, 255, 1.0); // Yellow
1269*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 0, 253, 0, 255, 1.0); // Green
1270*8975f5c5SAndroid Build Coastguard Worker
1271*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1272*8975f5c5SAndroid Build Coastguard Worker }
1273*8975f5c5SAndroid Build Coastguard Worker
1274*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer from default framebuffer with Y-flip/X-flip.
TEST_P(EGLPreRotationBlitFramebufferTest,BlitColorFromDefault)1275*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BlitColorFromDefault)
1276*8975f5c5SAndroid Build Coastguard Worker {
1277*8975f5c5SAndroid Build Coastguard Worker // This test uses functionality that is only available on Android
1278*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && !IsAndroid());
1279*8975f5c5SAndroid Build Coastguard Worker
1280*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1281*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1282*8975f5c5SAndroid Build Coastguard Worker
1283*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1284*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1285*8975f5c5SAndroid Build Coastguard Worker
1286*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1287*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1288*8975f5c5SAndroid Build Coastguard Worker
1289*8975f5c5SAndroid Build Coastguard Worker constexpr int kSize = 128;
1290*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, kSize, kSize);
1291*8975f5c5SAndroid Build Coastguard Worker
1292*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorbuf;
1293*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorbuf.get());
1294*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_RGBA8, kSize, kSize);
1295*8975f5c5SAndroid Build Coastguard Worker
1296*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1297*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1298*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
1299*8975f5c5SAndroid Build Coastguard Worker glCheckFramebufferStatus(GL_FRAMEBUFFER);
1300*8975f5c5SAndroid Build Coastguard Worker
1301*8975f5c5SAndroid Build Coastguard Worker glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1302*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1303*8975f5c5SAndroid Build Coastguard Worker
1304*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(gradientProgram, essl31_shaders::vs::Passthrough(),
1305*8975f5c5SAndroid Build Coastguard Worker essl31_shaders::fs::RedGreenGradient());
1306*8975f5c5SAndroid Build Coastguard Worker
1307*8975f5c5SAndroid Build Coastguard Worker EGLint desiredWidth = 300;
1308*8975f5c5SAndroid Build Coastguard Worker EGLint desiredHeight = 400;
1309*8975f5c5SAndroid Build Coastguard Worker mOSWindow->resize(desiredWidth, desiredHeight);
1310*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(desiredWidth, desiredHeight);
1311*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
1312*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1313*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1314*8975f5c5SAndroid Build Coastguard Worker
1315*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
1316*8975f5c5SAndroid Build Coastguard Worker drawQuad(gradientProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true);
1317*8975f5c5SAndroid Build Coastguard Worker
1318*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer from default frambuffer without flip.
1319*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.get());
1320*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1321*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get());
1322*8975f5c5SAndroid Build Coastguard Worker
1323*8975f5c5SAndroid Build Coastguard Worker // Check the result, especially the boundaries.
1324*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 255, 1.0); // Balck
1325*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 253, 0, 0, 255, 1.0); // Red
1326*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 253, 0, 255, 1.0); // Green
1327*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 253, 253, 0, 255, 1.0); // Yellow
1328*8975f5c5SAndroid Build Coastguard Worker
1329*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer from default frambuffer with Y-flip.
1330*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1331*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.get());
1332*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, 0, kSize, kSize, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1333*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get());
1334*8975f5c5SAndroid Build Coastguard Worker
1335*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 0, 253, 0, 255, 1.0); // Green
1336*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 253, 253, 0, 255, 1.0); // Yellow
1337*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 0, 0, 255, 1.0); // Balck
1338*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 253, 0, 0, 255, 1.0); // Red
1339*8975f5c5SAndroid Build Coastguard Worker
1340*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer from default frambuffer with X-flip.
1341*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1342*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.get());
1343*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, kSize, 0, 0, kSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1344*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get());
1345*8975f5c5SAndroid Build Coastguard Worker
1346*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 253, 0, 0, 255, 1.0); // Red
1347*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 0, 0, 0, 255, 1.0); // Balck
1348*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 253, 253, 0, 255, 1.0); // Yellow
1349*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 0, 253, 0, 255, 1.0); // Green
1350*8975f5c5SAndroid Build Coastguard Worker
1351*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1352*8975f5c5SAndroid Build Coastguard Worker }
1353*8975f5c5SAndroid Build Coastguard Worker
1354*8975f5c5SAndroid Build Coastguard Worker // Blit multisample color buffer to resolved framebuffer.
TEST_P(EGLPreRotationBlitFramebufferTest,BlitMultisampleColorToResolved)1355*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BlitMultisampleColorToResolved)
1356*8975f5c5SAndroid Build Coastguard Worker {
1357*8975f5c5SAndroid Build Coastguard Worker // This test uses functionality that is only available on Android
1358*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && !IsAndroid());
1359*8975f5c5SAndroid Build Coastguard Worker
1360*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1361*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1362*8975f5c5SAndroid Build Coastguard Worker
1363*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1364*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1365*8975f5c5SAndroid Build Coastguard Worker
1366*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1367*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1368*8975f5c5SAndroid Build Coastguard Worker
1369*8975f5c5SAndroid Build Coastguard Worker constexpr int kSize = 128;
1370*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, kSize, kSize);
1371*8975f5c5SAndroid Build Coastguard Worker
1372*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorMS;
1373*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorMS.get());
1374*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, kSize, kSize);
1375*8975f5c5SAndroid Build Coastguard Worker
1376*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorResolved;
1377*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorResolved.get());
1378*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
1379*8975f5c5SAndroid Build Coastguard Worker
1380*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebufferMS;
1381*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebufferMS.get());
1382*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorMS);
1383*8975f5c5SAndroid Build Coastguard Worker
1384*8975f5c5SAndroid Build Coastguard Worker glCheckFramebufferStatus(GL_FRAMEBUFFER);
1385*8975f5c5SAndroid Build Coastguard Worker
1386*8975f5c5SAndroid Build Coastguard Worker glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1387*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1388*8975f5c5SAndroid Build Coastguard Worker
1389*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(gradientProgram, essl31_shaders::vs::Passthrough(),
1390*8975f5c5SAndroid Build Coastguard Worker essl31_shaders::fs::RedGreenGradient());
1391*8975f5c5SAndroid Build Coastguard Worker drawQuad(gradientProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true);
1392*8975f5c5SAndroid Build Coastguard Worker
1393*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebufferResolved;
1394*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebufferResolved.get());
1395*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
1396*8975f5c5SAndroid Build Coastguard Worker colorResolved.get());
1397*8975f5c5SAndroid Build Coastguard Worker
1398*8975f5c5SAndroid Build Coastguard Worker EGLint desiredWidth = 300;
1399*8975f5c5SAndroid Build Coastguard Worker EGLint desiredHeight = 400;
1400*8975f5c5SAndroid Build Coastguard Worker mOSWindow->resize(desiredWidth, desiredHeight);
1401*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(desiredWidth, desiredHeight);
1402*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
1403*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1404*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1405*8975f5c5SAndroid Build Coastguard Worker
1406*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferMS.get());
1407*8975f5c5SAndroid Build Coastguard Worker drawQuad(gradientProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true);
1408*8975f5c5SAndroid Build Coastguard Worker
1409*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferMS.get());
1410*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferResolved.get());
1411*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1412*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferResolved.get());
1413*8975f5c5SAndroid Build Coastguard Worker
1414*8975f5c5SAndroid Build Coastguard Worker // Check the result, especially the boundaries.
1415*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 255, 1.0); // Balck
1416*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 253, 0, 0, 255, 1.0); // Red
1417*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 253, 0, 255, 1.0); // Green
1418*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 253, 253, 0, 255, 1.0); // Yellow
1419*8975f5c5SAndroid Build Coastguard Worker
1420*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1421*8975f5c5SAndroid Build Coastguard Worker }
1422*8975f5c5SAndroid Build Coastguard Worker
1423*8975f5c5SAndroid Build Coastguard Worker // Blit color buffer to default framebuffer with linear filter.
TEST_P(EGLPreRotationBlitFramebufferTest,BlitColorWithLinearFilter)1424*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, BlitColorWithLinearFilter)
1425*8975f5c5SAndroid Build Coastguard Worker {
1426*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1427*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1428*8975f5c5SAndroid Build Coastguard Worker
1429*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1430*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1431*8975f5c5SAndroid Build Coastguard Worker
1432*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1433*8975f5c5SAndroid Build Coastguard Worker
1434*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1435*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1436*8975f5c5SAndroid Build Coastguard Worker
1437*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1438*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1439*8975f5c5SAndroid Build Coastguard Worker
1440*8975f5c5SAndroid Build Coastguard Worker mOSWindow->setOrientation(300, 400);
1441*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(1000);
1442*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1443*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1444*8975f5c5SAndroid Build Coastguard Worker
1445*8975f5c5SAndroid Build Coastguard Worker constexpr int kSize = 128;
1446*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, kSize, kSize);
1447*8975f5c5SAndroid Build Coastguard Worker
1448*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorbuf;
1449*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorbuf.get());
1450*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_RGBA8, kSize, kSize);
1451*8975f5c5SAndroid Build Coastguard Worker
1452*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1453*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1454*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
1455*8975f5c5SAndroid Build Coastguard Worker
1456*8975f5c5SAndroid Build Coastguard Worker glCheckFramebufferStatus(GL_FRAMEBUFFER);
1457*8975f5c5SAndroid Build Coastguard Worker
1458*8975f5c5SAndroid Build Coastguard Worker glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1459*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1460*8975f5c5SAndroid Build Coastguard Worker
1461*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(gradientProgram, essl31_shaders::vs::Passthrough(),
1462*8975f5c5SAndroid Build Coastguard Worker essl31_shaders::fs::RedGreenGradient());
1463*8975f5c5SAndroid Build Coastguard Worker drawQuad(gradientProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true);
1464*8975f5c5SAndroid Build Coastguard Worker
1465*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1466*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize, GL_COLOR_BUFFER_BIT, GL_LINEAR);
1467*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1468*8975f5c5SAndroid Build Coastguard Worker
1469*8975f5c5SAndroid Build Coastguard Worker // Check the result, especially the boundaries.
1470*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 255, 1.0); // Black
1471*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, 0, 253, 0, 0, 255, 1.0); // Red
1472*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 253, 0, 255, 1.0); // Green
1473*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 253, 253, 0, 255, 1.0); // Yellow
1474*8975f5c5SAndroid Build Coastguard Worker
1475*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1476*8975f5c5SAndroid Build Coastguard Worker
1477*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1478*8975f5c5SAndroid Build Coastguard Worker }
1479*8975f5c5SAndroid Build Coastguard Worker
1480*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
1481*8975f5c5SAndroid Build Coastguard Worker // to blit the left and right halves of that pattern into various places within the 400x300 window
TEST_P(EGLPreRotationBlitFramebufferTest,LeftAndRightBlitFramebuffer)1482*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, LeftAndRightBlitFramebuffer)
1483*8975f5c5SAndroid Build Coastguard Worker {
1484*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1485*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1486*8975f5c5SAndroid Build Coastguard Worker
1487*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1488*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1489*8975f5c5SAndroid Build Coastguard Worker
1490*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1491*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1492*8975f5c5SAndroid Build Coastguard Worker
1493*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1494*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1495*8975f5c5SAndroid Build Coastguard Worker
1496*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1497*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1498*8975f5c5SAndroid Build Coastguard Worker
1499*8975f5c5SAndroid Build Coastguard Worker // Init program
1500*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
1501*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
1502*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
1503*8975f5c5SAndroid Build Coastguard Worker
1504*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
1505*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
1506*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
1507*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
1508*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1509*8975f5c5SAndroid Build Coastguard Worker
1510*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
1511*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
1512*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1513*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
1514*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1515*8975f5c5SAndroid Build Coastguard Worker
1516*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
1517*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
1518*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1519*8975f5c5SAndroid Build Coastguard Worker
1520*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
1521*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
1522*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1523*8975f5c5SAndroid Build Coastguard Worker
1524*8975f5c5SAndroid Build Coastguard Worker // Prepare to blit to the default framebuffer and read from the FBO
1525*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
1526*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1527*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1528*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1529*8975f5c5SAndroid Build Coastguard Worker
1530*8975f5c5SAndroid Build Coastguard Worker // Blit to an offset part of the 400x300 window
1531*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 40;
1532*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 30;
1533*8975f5c5SAndroid Build Coastguard Worker
1534*8975f5c5SAndroid Build Coastguard Worker //
1535*8975f5c5SAndroid Build Coastguard Worker // Test blitting half of the FBO image to a 128x256 or 256x128 part of the default framebuffer
1536*8975f5c5SAndroid Build Coastguard Worker // (no scaling)
1537*8975f5c5SAndroid Build Coastguard Worker //
1538*8975f5c5SAndroid Build Coastguard Worker
1539*8975f5c5SAndroid Build Coastguard Worker // 1st) Clear to black and blit the left and right halves of the texture to the left and right
1540*8975f5c5SAndroid Build Coastguard Worker // halves of that different part of the window
1541*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1542*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1543*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1544*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize / 2, mSize, xOffset, yOffset, xOffset + (mSize / 2),
1545*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1546*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(mSize / 2, 0, mSize, mSize, xOffset + (mSize / 2), yOffset, xOffset + mSize,
1547*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1548*8975f5c5SAndroid Build Coastguard Worker
1549*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1550*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1551*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1552*8975f5c5SAndroid Build Coastguard Worker
1553*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
1554*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1555*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize / 2, mSize, xOffset, yOffset, xOffset + (mSize / 2),
1556*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1557*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(mSize / 2, 0, mSize, mSize, xOffset + (mSize / 2), yOffset, xOffset + mSize,
1558*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1559*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1560*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(xOffset, yOffset);
1561*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1562*8975f5c5SAndroid Build Coastguard Worker
1563*8975f5c5SAndroid Build Coastguard Worker // 2nd) Clear to black and this time blit the left half of the source texture to the right half
1564*8975f5c5SAndroid Build Coastguard Worker // of the destination window, and then blit the right half of the source texture to the left
1565*8975f5c5SAndroid Build Coastguard Worker // half of the destination window
1566*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1567*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1568*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1569*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(mSize / 2, 0, mSize, mSize, xOffset, yOffset, xOffset + (mSize / 2),
1570*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1571*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize / 2, mSize, xOffset + (mSize / 2), yOffset, xOffset + mSize,
1572*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1573*8975f5c5SAndroid Build Coastguard Worker
1574*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1575*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1576*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1577*8975f5c5SAndroid Build Coastguard Worker
1578*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
1579*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1580*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(mSize / 2, 0, mSize, mSize, xOffset, yOffset, xOffset + (mSize / 2),
1581*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1582*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize / 2, mSize, xOffset + (mSize / 2), yOffset, xOffset + mSize,
1583*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1584*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1585*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort + 1, yOffset + 0, GLColor::black);
1586*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort + 1, yOffset + mSize - 1, GLColor::green);
1587*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + 0, GLColor::red);
1588*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + mSize - 1, GLColor::yellow);
1589*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + kCoordMidWayShort, kColorMidWayShortShort);
1590*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + kCoordMidWayLong, kColorMidWayShortLong);
1591*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + kCoordMidWayShort, kColorMidWayLongShort);
1592*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + kCoordMidWayLong, kColorMidWayLongLong);
1593*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1594*8975f5c5SAndroid Build Coastguard Worker
1595*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1596*8975f5c5SAndroid Build Coastguard Worker }
1597*8975f5c5SAndroid Build Coastguard Worker
1598*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
1599*8975f5c5SAndroid Build Coastguard Worker // to blit the top and bottom halves of that pattern into various places within the 400x300 window
TEST_P(EGLPreRotationBlitFramebufferTest,TopAndBottomBlitFramebuffer)1600*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, TopAndBottomBlitFramebuffer)
1601*8975f5c5SAndroid Build Coastguard Worker {
1602*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1603*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1604*8975f5c5SAndroid Build Coastguard Worker
1605*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1606*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1607*8975f5c5SAndroid Build Coastguard Worker
1608*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1609*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1610*8975f5c5SAndroid Build Coastguard Worker
1611*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1612*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1613*8975f5c5SAndroid Build Coastguard Worker
1614*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1615*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1616*8975f5c5SAndroid Build Coastguard Worker
1617*8975f5c5SAndroid Build Coastguard Worker // Init program
1618*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
1619*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
1620*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
1621*8975f5c5SAndroid Build Coastguard Worker
1622*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
1623*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
1624*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
1625*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
1626*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1627*8975f5c5SAndroid Build Coastguard Worker
1628*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
1629*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
1630*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1631*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
1632*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1633*8975f5c5SAndroid Build Coastguard Worker
1634*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
1635*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
1636*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1637*8975f5c5SAndroid Build Coastguard Worker
1638*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
1639*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
1640*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1641*8975f5c5SAndroid Build Coastguard Worker
1642*8975f5c5SAndroid Build Coastguard Worker // Prepare to blit to the default framebuffer and read from the FBO
1643*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
1644*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1645*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1646*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1647*8975f5c5SAndroid Build Coastguard Worker
1648*8975f5c5SAndroid Build Coastguard Worker // Blit to an offset part of the 400x300 window
1649*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 40;
1650*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 30;
1651*8975f5c5SAndroid Build Coastguard Worker
1652*8975f5c5SAndroid Build Coastguard Worker //
1653*8975f5c5SAndroid Build Coastguard Worker // Test blitting half of the FBO image to a 128x256 or 256x128 part of the default framebuffer
1654*8975f5c5SAndroid Build Coastguard Worker // (no scaling)
1655*8975f5c5SAndroid Build Coastguard Worker //
1656*8975f5c5SAndroid Build Coastguard Worker
1657*8975f5c5SAndroid Build Coastguard Worker // 1st) Clear to black and blit the top and bottom halves of the texture to the top and bottom
1658*8975f5c5SAndroid Build Coastguard Worker // halves of that different part of the window
1659*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1660*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1661*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1662*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize / 2, xOffset, yOffset, xOffset + mSize,
1663*8975f5c5SAndroid Build Coastguard Worker yOffset + (mSize / 2), GL_COLOR_BUFFER_BIT, GL_NEAREST);
1664*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, mSize / 2, mSize, mSize, xOffset, yOffset + (mSize / 2), xOffset + mSize,
1665*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1666*8975f5c5SAndroid Build Coastguard Worker
1667*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1668*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1669*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1670*8975f5c5SAndroid Build Coastguard Worker
1671*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
1672*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1673*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize / 2, xOffset, yOffset, xOffset + mSize,
1674*8975f5c5SAndroid Build Coastguard Worker yOffset + (mSize / 2), GL_COLOR_BUFFER_BIT, GL_NEAREST);
1675*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, mSize / 2, mSize, mSize, xOffset, yOffset + (mSize / 2), xOffset + mSize,
1676*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1677*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1678*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(xOffset, yOffset);
1679*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1680*8975f5c5SAndroid Build Coastguard Worker
1681*8975f5c5SAndroid Build Coastguard Worker // 2nd) Clear to black and this time blit the top half of the source texture to the bottom half
1682*8975f5c5SAndroid Build Coastguard Worker // of the destination window, and then blit the bottom half of the source texture to the top
1683*8975f5c5SAndroid Build Coastguard Worker // half of the destination window
1684*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1685*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1686*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1687*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize / 2, xOffset, yOffset + (mSize / 2), xOffset + mSize,
1688*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1689*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, mSize / 2, mSize, mSize, xOffset, yOffset, xOffset + mSize,
1690*8975f5c5SAndroid Build Coastguard Worker yOffset + (mSize / 2), GL_COLOR_BUFFER_BIT, GL_NEAREST);
1691*8975f5c5SAndroid Build Coastguard Worker
1692*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1693*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1694*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1695*8975f5c5SAndroid Build Coastguard Worker
1696*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
1697*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1698*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize / 2, xOffset, yOffset + (mSize / 2), xOffset + mSize,
1699*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1700*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, mSize / 2, mSize, mSize, xOffset, yOffset, xOffset + mSize,
1701*8975f5c5SAndroid Build Coastguard Worker yOffset + (mSize / 2), GL_COLOR_BUFFER_BIT, GL_NEAREST);
1702*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1703*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + kCoordMidWayShort + 1, GLColor::black);
1704*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + kCoordMidWayShort, GLColor::green);
1705*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + kCoordMidWayShort + 1, GLColor::red);
1706*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + kCoordMidWayShort, GLColor::yellow);
1707*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + mSize - 1, kColorMidWayShortShort);
1708*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + 0, kColorMidWayShortLong);
1709*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayLong, yOffset + mSize - 1, kColorMidWayLongShort);
1710*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayLong, yOffset + 0, kColorMidWayLongLong);
1711*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1712*8975f5c5SAndroid Build Coastguard Worker
1713*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1714*8975f5c5SAndroid Build Coastguard Worker }
1715*8975f5c5SAndroid Build Coastguard Worker
1716*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
1717*8975f5c5SAndroid Build Coastguard Worker // to blit that pattern into various places within the 400x300 window, but being scaled to one-half
1718*8975f5c5SAndroid Build Coastguard Worker // size
TEST_P(EGLPreRotationBlitFramebufferTest,ScaledBlitFramebuffer)1719*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, ScaledBlitFramebuffer)
1720*8975f5c5SAndroid Build Coastguard Worker {
1721*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1722*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1723*8975f5c5SAndroid Build Coastguard Worker
1724*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1725*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1726*8975f5c5SAndroid Build Coastguard Worker
1727*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1728*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1729*8975f5c5SAndroid Build Coastguard Worker
1730*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1731*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1732*8975f5c5SAndroid Build Coastguard Worker
1733*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1734*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1735*8975f5c5SAndroid Build Coastguard Worker
1736*8975f5c5SAndroid Build Coastguard Worker // Init program
1737*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
1738*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
1739*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
1740*8975f5c5SAndroid Build Coastguard Worker
1741*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
1742*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
1743*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
1744*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
1745*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1746*8975f5c5SAndroid Build Coastguard Worker
1747*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
1748*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
1749*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1750*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
1751*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1752*8975f5c5SAndroid Build Coastguard Worker
1753*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
1754*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
1755*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1756*8975f5c5SAndroid Build Coastguard Worker
1757*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
1758*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
1759*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1760*8975f5c5SAndroid Build Coastguard Worker
1761*8975f5c5SAndroid Build Coastguard Worker // Prepare to blit to the default framebuffer and read from the FBO
1762*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
1763*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1764*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1765*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1766*8975f5c5SAndroid Build Coastguard Worker
1767*8975f5c5SAndroid Build Coastguard Worker // Blit to an offset part of the 400x300 window
1768*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 40;
1769*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 30;
1770*8975f5c5SAndroid Build Coastguard Worker
1771*8975f5c5SAndroid Build Coastguard Worker //
1772*8975f5c5SAndroid Build Coastguard Worker // Test blitting the entire FBO image to a 128x256 or 256x128 part of the default framebuffer
1773*8975f5c5SAndroid Build Coastguard Worker // (requires scaling)
1774*8975f5c5SAndroid Build Coastguard Worker //
1775*8975f5c5SAndroid Build Coastguard Worker
1776*8975f5c5SAndroid Build Coastguard Worker // 1st) Clear to black and blit the FBO to the left and right halves of that different part of
1777*8975f5c5SAndroid Build Coastguard Worker // the window
1778*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1779*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1780*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1781*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + (mSize / 2), yOffset + mSize,
1782*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1783*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset + (mSize / 2), yOffset, xOffset + mSize,
1784*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1785*8975f5c5SAndroid Build Coastguard Worker
1786*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1787*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1788*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1789*8975f5c5SAndroid Build Coastguard Worker
1790*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
1791*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1792*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + (mSize / 2), yOffset + mSize,
1793*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1794*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset + (mSize / 2), yOffset, xOffset + mSize,
1795*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1796*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1797*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + 0, kColorScaleHorizBlack);
1798*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + mSize - 1, kColorScaleHorizGreen);
1799*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + 0, GLColor::red);
1800*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayShort, yOffset + mSize - 1, GLColor::yellow);
1801*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayLong, yOffset + 0, kColorScaleHorizBlack);
1802*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + kCoordMidWayLong, yOffset + mSize - 1, kColorScaleHorizGreen);
1803*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + 0, GLColor::red);
1804*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + mSize - 1, GLColor::yellow);
1805*8975f5c5SAndroid Build Coastguard Worker
1806*8975f5c5SAndroid Build Coastguard Worker // 2nd) Clear to black and blit the FBO to the top and bottom halves of that different part of
1807*8975f5c5SAndroid Build Coastguard Worker // the window
1808*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1809*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1810*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1811*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + (mSize / 2),
1812*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1813*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset + (mSize / 2), xOffset + mSize,
1814*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1815*8975f5c5SAndroid Build Coastguard Worker
1816*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1817*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1818*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1819*8975f5c5SAndroid Build Coastguard Worker
1820*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
1821*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1822*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + (mSize / 2),
1823*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1824*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset + (mSize / 2), xOffset + mSize,
1825*8975f5c5SAndroid Build Coastguard Worker yOffset + mSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1826*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1827*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + 0, kColorScaleVertBlack);
1828*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + 0, kColorScaleVertRed);
1829*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + kCoordMidWayShort, GLColor::green);
1830*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + kCoordMidWayShort, GLColor::yellow);
1831*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + kCoordMidWayLong, kColorScaleVertBlack);
1832*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + kCoordMidWayLong, kColorScaleVertRed);
1833*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + 0, yOffset + mSize - 1, GLColor::green);
1834*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(xOffset + mSize - 1, yOffset + mSize - 1, GLColor::yellow);
1835*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1836*8975f5c5SAndroid Build Coastguard Worker
1837*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1838*8975f5c5SAndroid Build Coastguard Worker }
1839*8975f5c5SAndroid Build Coastguard Worker
1840*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
1841*8975f5c5SAndroid Build Coastguard Worker // window, and then use glBlitFramebuffer to blit that pattern into an FBO
TEST_P(EGLPreRotationBlitFramebufferTest,FboDestBlitFramebuffer)1842*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, FboDestBlitFramebuffer)
1843*8975f5c5SAndroid Build Coastguard Worker {
1844*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1845*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1846*8975f5c5SAndroid Build Coastguard Worker
1847*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1848*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1849*8975f5c5SAndroid Build Coastguard Worker
1850*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1851*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1852*8975f5c5SAndroid Build Coastguard Worker
1853*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1854*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1855*8975f5c5SAndroid Build Coastguard Worker
1856*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1857*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1858*8975f5c5SAndroid Build Coastguard Worker
1859*8975f5c5SAndroid Build Coastguard Worker // Init program
1860*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
1861*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
1862*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
1863*8975f5c5SAndroid Build Coastguard Worker
1864*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
1865*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
1866*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
1867*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
1868*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1869*8975f5c5SAndroid Build Coastguard Worker
1870*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
1871*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
1872*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1873*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
1874*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1875*8975f5c5SAndroid Build Coastguard Worker
1876*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
1877*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
1878*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1879*8975f5c5SAndroid Build Coastguard Worker
1880*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
1881*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
1882*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1883*8975f5c5SAndroid Build Coastguard Worker
1884*8975f5c5SAndroid Build Coastguard Worker // Prepare to blit to the default framebuffer and read from the FBO
1885*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
1886*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1887*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1888*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1889*8975f5c5SAndroid Build Coastguard Worker
1890*8975f5c5SAndroid Build Coastguard Worker // Blit to an offset part of the 400x300 window
1891*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 40;
1892*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 30;
1893*8975f5c5SAndroid Build Coastguard Worker
1894*8975f5c5SAndroid Build Coastguard Worker //
1895*8975f5c5SAndroid Build Coastguard Worker // Test blitting a 256x256 part of the default framebuffer to the entire FBO (no scaling)
1896*8975f5c5SAndroid Build Coastguard Worker //
1897*8975f5c5SAndroid Build Coastguard Worker
1898*8975f5c5SAndroid Build Coastguard Worker // To get the entire predictable pattern into the default framebuffer at the desired offset,
1899*8975f5c5SAndroid Build Coastguard Worker // blit it from the FBO
1900*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1901*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1902*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1903*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1904*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
1905*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1906*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1907*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1908*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1909*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
1910*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1911*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
1912*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1913*8975f5c5SAndroid Build Coastguard Worker
1914*8975f5c5SAndroid Build Coastguard Worker // Clear the FBO to black and blit from the window to the FBO
1915*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1916*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
1917*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
1918*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1919*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(xOffset, yOffset, xOffset + mSize, yOffset + mSize, 0, 0, mSize, mSize,
1920*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1921*8975f5c5SAndroid Build Coastguard Worker
1922*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
1923*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1924*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
1925*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1926*8975f5c5SAndroid Build Coastguard Worker
1927*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1928*8975f5c5SAndroid Build Coastguard Worker }
1929*8975f5c5SAndroid Build Coastguard Worker
1930*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
1931*8975f5c5SAndroid Build Coastguard Worker // window, and then use glBlitFramebuffer to blit that pattern into an FBO, but with coordinates
1932*8975f5c5SAndroid Build Coastguard Worker // that are partially out-of-bounds of the source
TEST_P(EGLPreRotationBlitFramebufferTest,FboDestOutOfBoundsSourceBlitFramebuffer)1933*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, FboDestOutOfBoundsSourceBlitFramebuffer)
1934*8975f5c5SAndroid Build Coastguard Worker {
1935*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
1936*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
1937*8975f5c5SAndroid Build Coastguard Worker
1938*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
1939*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
1940*8975f5c5SAndroid Build Coastguard Worker
1941*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
1942*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
1943*8975f5c5SAndroid Build Coastguard Worker
1944*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
1945*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
1946*8975f5c5SAndroid Build Coastguard Worker
1947*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
1948*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
1949*8975f5c5SAndroid Build Coastguard Worker
1950*8975f5c5SAndroid Build Coastguard Worker // Init program
1951*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
1952*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
1953*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
1954*8975f5c5SAndroid Build Coastguard Worker
1955*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
1956*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
1957*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
1958*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
1959*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1960*8975f5c5SAndroid Build Coastguard Worker
1961*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
1962*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
1963*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1964*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
1965*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1966*8975f5c5SAndroid Build Coastguard Worker
1967*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
1968*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
1969*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1970*8975f5c5SAndroid Build Coastguard Worker
1971*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
1972*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
1973*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
1974*8975f5c5SAndroid Build Coastguard Worker
1975*8975f5c5SAndroid Build Coastguard Worker // Prepare to blit to the default framebuffer and read from the FBO
1976*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
1977*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1978*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1979*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1980*8975f5c5SAndroid Build Coastguard Worker
1981*8975f5c5SAndroid Build Coastguard Worker // Blit to the origin of the 400x300 window
1982*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 0;
1983*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 0;
1984*8975f5c5SAndroid Build Coastguard Worker
1985*8975f5c5SAndroid Build Coastguard Worker //
1986*8975f5c5SAndroid Build Coastguard Worker // Test blitting a 256x256 part of the default framebuffer to the entire FBO (no scaling)
1987*8975f5c5SAndroid Build Coastguard Worker //
1988*8975f5c5SAndroid Build Coastguard Worker
1989*8975f5c5SAndroid Build Coastguard Worker // To get the entire predictable pattern into the default framebuffer at the desired offset,
1990*8975f5c5SAndroid Build Coastguard Worker // blit it from the FBO
1991*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
1992*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1993*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
1994*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1995*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
1996*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
1997*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
1998*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
1999*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2000*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
2001*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2002*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
2003*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
2004*8975f5c5SAndroid Build Coastguard Worker
2005*8975f5c5SAndroid Build Coastguard Worker // Clear the FBO to black and blit from the window to the FBO, but give source coordinates that
2006*8975f5c5SAndroid Build Coastguard Worker // are partially outside of the window
2007*8975f5c5SAndroid Build Coastguard Worker xOffset = -10;
2008*8975f5c5SAndroid Build Coastguard Worker yOffset = -15;
2009*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
2010*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
2011*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
2012*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2013*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(xOffset, yOffset, xOffset + mSize, yOffset + mSize, 0, 0, mSize, mSize,
2014*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_LINEAR);
2015*8975f5c5SAndroid Build Coastguard Worker
2016*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
2017*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
2018*8975f5c5SAndroid Build Coastguard Worker // NOTE: There is a strip of black on the left and bottom edges of the PBO, corresponding to
2019*8975f5c5SAndroid Build Coastguard Worker // the source coordinates that were outside of the source. The strip of black is xOffset
2020*8975f5c5SAndroid Build Coastguard Worker // pixels wide on the left side, and yOffset pixels tall on the bottom side.
2021*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2022*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 255, GLColor::black);
2023*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset - 1, 0, GLColor::black);
2024*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset - 1, 255, GLColor::black);
2025*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, -yOffset - 1, GLColor::black);
2026*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255, -yOffset - 1, GLColor::black);
2027*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255 + xOffset, 0, GLColor::black);
2028*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255 + xOffset, -yOffset - 1, GLColor::black);
2029*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 255 + yOffset, GLColor::black);
2030*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset - 1, 255 + yOffset, GLColor::black);
2031*8975f5c5SAndroid Build Coastguard Worker
2032*8975f5c5SAndroid Build Coastguard Worker // FBO coordinate (-xOffset, -yOffset) (or (10, 15)) has the values from the bottom-left corner
2033*8975f5c5SAndroid Build Coastguard Worker // of the source (which happens to be black). Thus, the following two tests are equivalent:
2034*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset, -yOffset, GLColor::black);
2035*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(10, 15, GLColor::black);
2036*8975f5c5SAndroid Build Coastguard Worker
2037*8975f5c5SAndroid Build Coastguard Worker // Note: the following is equivalent to (0, 0):
2038*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(10 + xOffset, 15 + yOffset, GLColor::black);
2039*8975f5c5SAndroid Build Coastguard Worker
2040*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset + 1, -yOffset + 1, GLColor(1, 1, 0, 255));
2041*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset + 10, -yOffset + 10, GLColor(10, 10, 0, 255));
2042*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset + 20, -yOffset + 20, GLColor(20, 20, 0, 255));
2043*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset + 100, -yOffset + 100, GLColor(100, 100, 0, 255));
2044*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset + 200, -yOffset + 200, GLColor(200, 200, 0, 255));
2045*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset + 230, -yOffset + 230, GLColor(230, 230, 0, 255));
2046*8975f5c5SAndroid Build Coastguard Worker // Note how the offset works differently when added to the same coordinate value as above. The
2047*8975f5c5SAndroid Build Coastguard Worker // black strip causes the value to be 2X less the offset in each direction. Thus, coordinate
2048*8975f5c5SAndroid Build Coastguard Worker // (230+xOffset, 230+yOffset) yields actual coordinate (220, 215) and red-green values
2049*8975f5c5SAndroid Build Coastguard Worker // (230+(2*xOffset), 230+(2*yOffset)) or (210, 200). The following two tests are equivalent:
2050*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(230 + xOffset, 230 + yOffset,
2051*8975f5c5SAndroid Build Coastguard Worker GLColor(230 + (2 * xOffset), 230 + (2 * yOffset), 0, 255));
2052*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(220, 215, GLColor(210, 200, 0, 255));
2053*8975f5c5SAndroid Build Coastguard Worker // FBO coordinate (245, 240) has the highest pixel values from the source. The value of the
2054*8975f5c5SAndroid Build Coastguard Worker // FBO pixel at (245, 240) is smaller than the same coordinate in the source because of the
2055*8975f5c5SAndroid Build Coastguard Worker // blit's offsets. That is, the value is (245-xOffset, 240-yOffset) or (235, 225). Thus, the
2056*8975f5c5SAndroid Build Coastguard Worker // following two tests are the same:
2057*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255 + xOffset, 255 + yOffset,
2058*8975f5c5SAndroid Build Coastguard Worker GLColor(255 + (2 * xOffset), 255 + (2 * yOffset), 0, 255));
2059*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(245, 240, GLColor(235, 225, 0, 255));
2060*8975f5c5SAndroid Build Coastguard Worker
2061*8975f5c5SAndroid Build Coastguard Worker // Again, the "mid-way" coordinates will get values that aren't truly mid-way:
2062*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(
2063*8975f5c5SAndroid Build Coastguard Worker xOffset + kCoordMidWayShort, yOffset + kCoordMidWayShort,
2064*8975f5c5SAndroid Build Coastguard Worker GLColor(kCoordMidWayShort + (2 * xOffset), kCoordMidWayShort + (2 * yOffset), 0, 255));
2065*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(
2066*8975f5c5SAndroid Build Coastguard Worker xOffset + kCoordMidWayShort, yOffset + kCoordMidWayLong,
2067*8975f5c5SAndroid Build Coastguard Worker GLColor(kCoordMidWayShort + (2 * xOffset), kCoordMidWayLong + (2 * yOffset), 0, 255));
2068*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(
2069*8975f5c5SAndroid Build Coastguard Worker xOffset + kCoordMidWayLong, yOffset + kCoordMidWayShort,
2070*8975f5c5SAndroid Build Coastguard Worker GLColor(kCoordMidWayLong + (2 * xOffset), kCoordMidWayShort + (2 * yOffset), 0, 255));
2071*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(
2072*8975f5c5SAndroid Build Coastguard Worker xOffset + kCoordMidWayLong, yOffset + kCoordMidWayLong,
2073*8975f5c5SAndroid Build Coastguard Worker GLColor(kCoordMidWayLong + (2 * xOffset), kCoordMidWayLong + (2 * yOffset), 0, 255));
2074*8975f5c5SAndroid Build Coastguard Worker
2075*8975f5c5SAndroid Build Coastguard Worker // Almost Red
2076*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255, -yOffset, GLColor(255 + xOffset, 0, 0, 255));
2077*8975f5c5SAndroid Build Coastguard Worker // Almost Green
2078*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset, 255, GLColor(0, 255 + yOffset, 0, 255));
2079*8975f5c5SAndroid Build Coastguard Worker // Almost Yellow
2080*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255, 255, GLColor(255 + xOffset, 255 + yOffset, 0, 255));
2081*8975f5c5SAndroid Build Coastguard Worker
2082*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2083*8975f5c5SAndroid Build Coastguard Worker
2084*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2085*8975f5c5SAndroid Build Coastguard Worker }
2086*8975f5c5SAndroid Build Coastguard Worker
2087*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
2088*8975f5c5SAndroid Build Coastguard Worker // window, and then use glBlitFramebuffer to blit that pattern into an FBO, but with coordinates
2089*8975f5c5SAndroid Build Coastguard Worker // that are partially out-of-bounds of the source, and cause a "stretch" to occur
TEST_P(EGLPreRotationBlitFramebufferTest,FboDestOutOfBoundsSourceWithStretchBlitFramebuffer)2090*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, FboDestOutOfBoundsSourceWithStretchBlitFramebuffer)
2091*8975f5c5SAndroid Build Coastguard Worker {
2092*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
2093*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
2094*8975f5c5SAndroid Build Coastguard Worker
2095*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
2096*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
2097*8975f5c5SAndroid Build Coastguard Worker
2098*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
2099*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
2100*8975f5c5SAndroid Build Coastguard Worker
2101*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
2102*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
2103*8975f5c5SAndroid Build Coastguard Worker
2104*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
2105*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2106*8975f5c5SAndroid Build Coastguard Worker
2107*8975f5c5SAndroid Build Coastguard Worker // Init program
2108*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
2109*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
2110*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
2111*8975f5c5SAndroid Build Coastguard Worker
2112*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
2113*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
2114*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
2115*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
2116*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2117*8975f5c5SAndroid Build Coastguard Worker
2118*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
2119*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
2120*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
2121*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
2122*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2123*8975f5c5SAndroid Build Coastguard Worker
2124*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
2125*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
2126*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2127*8975f5c5SAndroid Build Coastguard Worker
2128*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
2129*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
2130*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2131*8975f5c5SAndroid Build Coastguard Worker
2132*8975f5c5SAndroid Build Coastguard Worker // Prepare to blit to the default framebuffer and read from the FBO
2133*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
2134*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
2135*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
2136*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2137*8975f5c5SAndroid Build Coastguard Worker
2138*8975f5c5SAndroid Build Coastguard Worker // Blit to the origin of the 400x300 window
2139*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 0;
2140*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 0;
2141*8975f5c5SAndroid Build Coastguard Worker
2142*8975f5c5SAndroid Build Coastguard Worker //
2143*8975f5c5SAndroid Build Coastguard Worker // Test blitting a 256x256 part of the default framebuffer to the entire FBO (no scaling)
2144*8975f5c5SAndroid Build Coastguard Worker //
2145*8975f5c5SAndroid Build Coastguard Worker
2146*8975f5c5SAndroid Build Coastguard Worker // To get the entire predictable pattern into the default framebuffer at the desired offset,
2147*8975f5c5SAndroid Build Coastguard Worker // blit it from the FBO
2148*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
2149*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
2150*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
2151*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2152*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
2153*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
2154*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
2155*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
2156*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2157*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
2158*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2159*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
2160*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
2161*8975f5c5SAndroid Build Coastguard Worker
2162*8975f5c5SAndroid Build Coastguard Worker // Clear the FBO to black and blit from the window to the FBO, but give source coordinates that
2163*8975f5c5SAndroid Build Coastguard Worker // are partially outside of the window, but "stretch" the result by 0.5 (i.e. 2X shrink in x)
2164*8975f5c5SAndroid Build Coastguard Worker xOffset = -10;
2165*8975f5c5SAndroid Build Coastguard Worker yOffset = -15;
2166*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
2167*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
2168*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
2169*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2170*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(xOffset, yOffset, xOffset + mSize, yOffset + mSize, 0, 0, mSize / 2, mSize,
2171*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_LINEAR);
2172*8975f5c5SAndroid Build Coastguard Worker
2173*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
2174*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
2175*8975f5c5SAndroid Build Coastguard Worker // NOTE: There is a strip of black on the left and bottom edges of the PBO, corresponding to
2176*8975f5c5SAndroid Build Coastguard Worker // the source coordinates that were outside of the source. The strip of black is xOffset/2
2177*8975f5c5SAndroid Build Coastguard Worker // pixels wide on the left side, and yOffset pixels tall on the bottom side.
2178*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor::black, 1);
2179*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, 255, GLColor::black, 1);
2180*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR((-xOffset / 2) - 1, 0, GLColor::black, 1);
2181*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR((-xOffset / 2) - 1, 255, GLColor::black, 1);
2182*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, -yOffset - 1, GLColor::black, 1);
2183*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(255 / 2, -yOffset - 1, GLColor::black, 1);
2184*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR((255 + xOffset) / 2, 0, GLColor::black, 1);
2185*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR((255 + xOffset) / 2, -yOffset - 1, GLColor::black, 1);
2186*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, 255 + yOffset, GLColor::black, 1);
2187*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR((-xOffset / 2) - 1, 255 + yOffset, GLColor::black, 1);
2188*8975f5c5SAndroid Build Coastguard Worker
2189*8975f5c5SAndroid Build Coastguard Worker // FBO coordinate (-xOffset, -yOffset) (or (10, 15)) has the values from the bottom-left corner
2190*8975f5c5SAndroid Build Coastguard Worker // of the source (which happens to be black). Thus, the following two tests are equivalent:
2191*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(-xOffset / 2, -yOffset, GLColor::black, 1);
2192*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(10 + xOffset, 15 + yOffset, GLColor::black, 1);
2193*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(220 / 2, 215, GLColor(210, 200, 0, 255), 1);
2194*8975f5c5SAndroid Build Coastguard Worker
2195*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR((254 + xOffset) / 2, 255 + yOffset,
2196*8975f5c5SAndroid Build Coastguard Worker GLColor(254 + (2 * xOffset), 255 + (2 * yOffset), 0, 255), 1);
2197*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(254 / 2, 240, GLColor(244, 225, 0, 255), 1);
2198*8975f5c5SAndroid Build Coastguard Worker
2199*8975f5c5SAndroid Build Coastguard Worker // Almost Red
2200*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(254 / 2, -yOffset, GLColor(254 + xOffset, 0, 0, 255), 1);
2201*8975f5c5SAndroid Build Coastguard Worker // Almost Green
2202*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(-xOffset / 2, 255, GLColor(0, 255 + yOffset, 0, 255), 1);
2203*8975f5c5SAndroid Build Coastguard Worker // Almost Yellow
2204*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(254 / 2, 255, GLColor(254 + xOffset, 255 + yOffset, 0, 255), 1);
2205*8975f5c5SAndroid Build Coastguard Worker
2206*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2207*8975f5c5SAndroid Build Coastguard Worker
2208*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2209*8975f5c5SAndroid Build Coastguard Worker }
2210*8975f5c5SAndroid Build Coastguard Worker
2211*8975f5c5SAndroid Build Coastguard Worker // Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
2212*8975f5c5SAndroid Build Coastguard Worker // window, and then use glBlitFramebuffer to blit that pattern into an FBO, but with source and FBO
2213*8975f5c5SAndroid Build Coastguard Worker // coordinates that are partially out-of-bounds of the source
TEST_P(EGLPreRotationBlitFramebufferTest,FboDestOutOfBoundsSourceAndDestBlitFramebuffer)2214*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationBlitFramebufferTest, FboDestOutOfBoundsSourceAndDestBlitFramebuffer)
2215*8975f5c5SAndroid Build Coastguard Worker {
2216*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
2217*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
2218*8975f5c5SAndroid Build Coastguard Worker
2219*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
2220*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
2221*8975f5c5SAndroid Build Coastguard Worker
2222*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
2223*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
2224*8975f5c5SAndroid Build Coastguard Worker
2225*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
2226*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
2227*8975f5c5SAndroid Build Coastguard Worker
2228*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
2229*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2230*8975f5c5SAndroid Build Coastguard Worker
2231*8975f5c5SAndroid Build Coastguard Worker // Init program
2232*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
2233*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
2234*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
2235*8975f5c5SAndroid Build Coastguard Worker
2236*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
2237*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
2238*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers[2];
2239*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, vertexBuffers);
2240*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2241*8975f5c5SAndroid Build Coastguard Worker
2242*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO and render the predictable pattern to it
2243*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
2244*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
2245*8975f5c5SAndroid Build Coastguard Worker initializeFBO(&fbo, &texture);
2246*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2247*8975f5c5SAndroid Build Coastguard Worker
2248*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
2249*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
2250*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2251*8975f5c5SAndroid Build Coastguard Worker
2252*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
2253*8975f5c5SAndroid Build Coastguard Worker test256x256PredictablePattern(0, 0);
2254*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2255*8975f5c5SAndroid Build Coastguard Worker
2256*8975f5c5SAndroid Build Coastguard Worker // Prepare to blit to the default framebuffer and read from the FBO
2257*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, 0);
2258*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
2259*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
2260*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2261*8975f5c5SAndroid Build Coastguard Worker
2262*8975f5c5SAndroid Build Coastguard Worker // Blit to the origin of the 400x300 window
2263*8975f5c5SAndroid Build Coastguard Worker GLint xOffset = 0;
2264*8975f5c5SAndroid Build Coastguard Worker GLint yOffset = 0;
2265*8975f5c5SAndroid Build Coastguard Worker
2266*8975f5c5SAndroid Build Coastguard Worker //
2267*8975f5c5SAndroid Build Coastguard Worker // Test blitting a 256x256 part of the default framebuffer to the entire FBO (no scaling)
2268*8975f5c5SAndroid Build Coastguard Worker //
2269*8975f5c5SAndroid Build Coastguard Worker
2270*8975f5c5SAndroid Build Coastguard Worker // To get the entire predictable pattern into the default framebuffer at the desired offset,
2271*8975f5c5SAndroid Build Coastguard Worker // blit it from the FBO
2272*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
2273*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
2274*8975f5c5SAndroid Build Coastguard Worker glViewport(xOffset, yOffset, mSize, mSize);
2275*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2276*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
2277*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
2278*8975f5c5SAndroid Build Coastguard Worker // Swap buffers to put the image in the window (so the test can be visually checked)
2279*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
2280*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2281*8975f5c5SAndroid Build Coastguard Worker // Blit again to check the colors in the back buffer
2282*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2283*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(0, 0, mSize, mSize, xOffset, yOffset, xOffset + mSize, yOffset + mSize,
2284*8975f5c5SAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT, GL_NEAREST);
2285*8975f5c5SAndroid Build Coastguard Worker
2286*8975f5c5SAndroid Build Coastguard Worker // Clear the FBO to black and blit from the window to the FBO, but give source coordinates that
2287*8975f5c5SAndroid Build Coastguard Worker // are partially outside of the window, and give destination coordinates that are partially
2288*8975f5c5SAndroid Build Coastguard Worker // outside of the FBO
2289*8975f5c5SAndroid Build Coastguard Worker xOffset = -10;
2290*8975f5c5SAndroid Build Coastguard Worker yOffset = -15;
2291*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
2292*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
2293*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
2294*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
2295*8975f5c5SAndroid Build Coastguard Worker glBlitFramebuffer(xOffset, yOffset, (2 * xOffset) + mSize, (2 * yOffset) + mSize, -xOffset,
2296*8975f5c5SAndroid Build Coastguard Worker -yOffset, mSize, mSize, GL_COLOR_BUFFER_BIT, GL_LINEAR);
2297*8975f5c5SAndroid Build Coastguard Worker
2298*8975f5c5SAndroid Build Coastguard Worker // Ensure the predictable pattern seems correct in the FBO
2299*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
2300*8975f5c5SAndroid Build Coastguard Worker // NOTE: There is a strip of black on the left and bottom edges of the PBO, corresponding to
2301*8975f5c5SAndroid Build Coastguard Worker // the source coordinates that were outside of the source. The strip of black is xOffset*2
2302*8975f5c5SAndroid Build Coastguard Worker // pixels wide on the left side, and yOffset*2 pixels tall on the bottom side.
2303*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2304*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 255, GLColor::black);
2305*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) - 1, 0, GLColor::black);
2306*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) - 1, 255, GLColor::black);
2307*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, (-yOffset * 2) - 1, GLColor::black);
2308*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255, (-yOffset * 2) - 1, GLColor::black);
2309*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255 + xOffset, 0, GLColor::black);
2310*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255 + xOffset, (-yOffset * 2) - 1, GLColor::black);
2311*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 255 + yOffset, GLColor::black);
2312*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) - 1, 255 + yOffset, GLColor::black);
2313*8975f5c5SAndroid Build Coastguard Worker
2314*8975f5c5SAndroid Build Coastguard Worker // FBO coordinate (-xOffset*2, -yOffset*2) (or (20, 30)) has the values from the bottom-left
2315*8975f5c5SAndroid Build Coastguard Worker // corner of the source (which happens to be black). Thus, the following two tests are
2316*8975f5c5SAndroid Build Coastguard Worker // equivalent:
2317*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2), (-yOffset * 2), GLColor::black);
2318*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(20, 30, GLColor::black);
2319*8975f5c5SAndroid Build Coastguard Worker
2320*8975f5c5SAndroid Build Coastguard Worker // Note: the following is equivalent to (0, 0):
2321*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(20 + (xOffset * 2), 30 + (yOffset * 2), GLColor::black);
2322*8975f5c5SAndroid Build Coastguard Worker
2323*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) + 1, (-yOffset * 2) + 1, GLColor(1, 1, 0, 255));
2324*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) + 10, (-yOffset * 2) + 10, GLColor(10, 10, 0, 255));
2325*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) + 20, (-yOffset * 2) + 20, GLColor(20, 20, 0, 255));
2326*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) + 100, (-yOffset * 2) + 100, GLColor(100, 100, 0, 255));
2327*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) + 200, (-yOffset * 2) + 200, GLColor(200, 200, 0, 255));
2328*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((-xOffset * 2) + 230, (-yOffset * 2) + 225, GLColor(230, 225, 0, 255));
2329*8975f5c5SAndroid Build Coastguard Worker
2330*8975f5c5SAndroid Build Coastguard Worker // Almost Red
2331*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255, -yOffset * 2, GLColor(255 + (xOffset * 2), 0, 0, 255));
2332*8975f5c5SAndroid Build Coastguard Worker // Almost Green
2333*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(-xOffset * 2, 255, GLColor(0, 255 + (yOffset * 2), 0, 255));
2334*8975f5c5SAndroid Build Coastguard Worker // Almost Yellow
2335*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(255, 255, GLColor(255 + (xOffset * 2), 255 + (yOffset * 2), 0, 255));
2336*8975f5c5SAndroid Build Coastguard Worker
2337*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2338*8975f5c5SAndroid Build Coastguard Worker
2339*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2340*8975f5c5SAndroid Build Coastguard Worker }
2341*8975f5c5SAndroid Build Coastguard Worker
2342*8975f5c5SAndroid Build Coastguard Worker class EGLPreRotationInterpolateAtOffsetTest : public EGLPreRotationSurfaceTest
2343*8975f5c5SAndroid Build Coastguard Worker {
2344*8975f5c5SAndroid Build Coastguard Worker protected:
EGLPreRotationInterpolateAtOffsetTest()2345*8975f5c5SAndroid Build Coastguard Worker EGLPreRotationInterpolateAtOffsetTest() {}
2346*8975f5c5SAndroid Build Coastguard Worker
createProgram()2347*8975f5c5SAndroid Build Coastguard Worker GLuint createProgram()
2348*8975f5c5SAndroid Build Coastguard Worker {
2349*8975f5c5SAndroid Build Coastguard Worker // Init program
2350*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
2351*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
2352*8975f5c5SAndroid Build Coastguard Worker "#extension GL_OES_shader_multisample_interpolation : require\n"
2353*8975f5c5SAndroid Build Coastguard Worker "in highp vec2 position;\n"
2354*8975f5c5SAndroid Build Coastguard Worker "uniform float screen_width;\n"
2355*8975f5c5SAndroid Build Coastguard Worker "uniform float screen_height;\n"
2356*8975f5c5SAndroid Build Coastguard Worker "out highp vec2 v_screenPosition;\n"
2357*8975f5c5SAndroid Build Coastguard Worker "out highp vec2 v_offset;\n"
2358*8975f5c5SAndroid Build Coastguard Worker "void main (void)\n"
2359*8975f5c5SAndroid Build Coastguard Worker "{\n"
2360*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(position, 0, 1);\n"
2361*8975f5c5SAndroid Build Coastguard Worker " v_screenPosition = (position.xy + vec2(1.0, 1.0)) / 2.0 * vec2(screen_width, "
2362*8975f5c5SAndroid Build Coastguard Worker "screen_height);\n"
2363*8975f5c5SAndroid Build Coastguard Worker " v_offset = position.xy * 0.5f;\n"
2364*8975f5c5SAndroid Build Coastguard Worker "}";
2365*8975f5c5SAndroid Build Coastguard Worker
2366*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
2367*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
2368*8975f5c5SAndroid Build Coastguard Worker "#extension GL_OES_shader_multisample_interpolation : require\n"
2369*8975f5c5SAndroid Build Coastguard Worker "in highp vec2 v_screenPosition;\n"
2370*8975f5c5SAndroid Build Coastguard Worker "in highp vec2 v_offset;\n"
2371*8975f5c5SAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 FragColor;\n"
2372*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
2373*8975f5c5SAndroid Build Coastguard Worker " const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits "
2374*8975f5c5SAndroid Build Coastguard Worker "+ 0.03125 for other errors\n"
2375*8975f5c5SAndroid Build Coastguard Worker "\n"
2376*8975f5c5SAndroid Build Coastguard Worker " highp vec2 pixelCenter = floor(v_screenPosition) + vec2(0.5, 0.5);\n"
2377*8975f5c5SAndroid Build Coastguard Worker " highp vec2 offsetValue = interpolateAtOffset(v_screenPosition, v_offset);\n"
2378*8975f5c5SAndroid Build Coastguard Worker " highp vec2 refValue = pixelCenter + v_offset;\n"
2379*8975f5c5SAndroid Build Coastguard Worker "\n"
2380*8975f5c5SAndroid Build Coastguard Worker " bool valuesEqual = all(lessThan(abs(offsetValue - refValue), vec2(threshold)));\n"
2381*8975f5c5SAndroid Build Coastguard Worker " if (valuesEqual)\n"
2382*8975f5c5SAndroid Build Coastguard Worker " FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
2383*8975f5c5SAndroid Build Coastguard Worker " else\n"
2384*8975f5c5SAndroid Build Coastguard Worker " FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
2385*8975f5c5SAndroid Build Coastguard Worker "}";
2386*8975f5c5SAndroid Build Coastguard Worker
2387*8975f5c5SAndroid Build Coastguard Worker return CompileProgram(kVS, kFS);
2388*8975f5c5SAndroid Build Coastguard Worker }
initializeGeometry(GLuint program,GLBuffer * indexBuffer,GLVertexArray * vertexArray,GLBuffer * vertexBuffers)2389*8975f5c5SAndroid Build Coastguard Worker void initializeGeometry(GLuint program,
2390*8975f5c5SAndroid Build Coastguard Worker GLBuffer *indexBuffer,
2391*8975f5c5SAndroid Build Coastguard Worker GLVertexArray *vertexArray,
2392*8975f5c5SAndroid Build Coastguard Worker GLBuffer *vertexBuffers)
2393*8975f5c5SAndroid Build Coastguard Worker {
2394*8975f5c5SAndroid Build Coastguard Worker GLint positionLocation = glGetAttribLocation(program, "position");
2395*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, positionLocation);
2396*8975f5c5SAndroid Build Coastguard Worker
2397*8975f5c5SAndroid Build Coastguard Worker GLuint screenWidthId = glGetUniformLocation(program, "screen_width");
2398*8975f5c5SAndroid Build Coastguard Worker GLuint screenHeightId = glGetUniformLocation(program, "screen_height");
2399*8975f5c5SAndroid Build Coastguard Worker
2400*8975f5c5SAndroid Build Coastguard Worker glUniform1f(screenWidthId, (GLfloat)mSize);
2401*8975f5c5SAndroid Build Coastguard Worker glUniform1f(screenHeightId, (GLfloat)mSize);
2402*8975f5c5SAndroid Build Coastguard Worker
2403*8975f5c5SAndroid Build Coastguard Worker glBindVertexArray(*vertexArray);
2404*8975f5c5SAndroid Build Coastguard Worker
2405*8975f5c5SAndroid Build Coastguard Worker std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0};
2406*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
2407*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
2408*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
2409*8975f5c5SAndroid Build Coastguard Worker
2410*8975f5c5SAndroid Build Coastguard Worker std::vector<GLfloat> positionData = {// quad vertices
2411*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
2412*8975f5c5SAndroid Build Coastguard Worker
2413*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]);
2414*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
2415*8975f5c5SAndroid Build Coastguard Worker GL_STATIC_DRAW);
2416*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2,
2417*8975f5c5SAndroid Build Coastguard Worker nullptr);
2418*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(positionLocation);
2419*8975f5c5SAndroid Build Coastguard Worker }
2420*8975f5c5SAndroid Build Coastguard Worker };
2421*8975f5c5SAndroid Build Coastguard Worker
2422*8975f5c5SAndroid Build Coastguard Worker // Draw with interpolateAtOffset() builtin function to pre-rotated default FBO
TEST_P(EGLPreRotationInterpolateAtOffsetTest,InterpolateAtOffsetWithDefaultFBO)2423*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationInterpolateAtOffsetTest, InterpolateAtOffsetWithDefaultFBO)
2424*8975f5c5SAndroid Build Coastguard Worker {
2425*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
2426*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
2427*8975f5c5SAndroid Build Coastguard Worker
2428*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
2429*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
2430*8975f5c5SAndroid Build Coastguard Worker
2431*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
2432*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
2433*8975f5c5SAndroid Build Coastguard Worker
2434*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
2435*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
2436*8975f5c5SAndroid Build Coastguard Worker
2437*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
2438*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2439*8975f5c5SAndroid Build Coastguard Worker
2440*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_shader_multisample_interpolation"));
2441*8975f5c5SAndroid Build Coastguard Worker
2442*8975f5c5SAndroid Build Coastguard Worker // Init program
2443*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
2444*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
2445*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
2446*8975f5c5SAndroid Build Coastguard Worker
2447*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
2448*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
2449*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers;
2450*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, &vertexBuffers);
2451*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2452*8975f5c5SAndroid Build Coastguard Worker
2453*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
2454*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
2455*8975f5c5SAndroid Build Coastguard Worker
2456*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(0, 255, 0, 255));
2457*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor(0, 255, 0, 255));
2458*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor(0, 255, 0, 255));
2459*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor(0, 255, 0, 255));
2460*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2461*8975f5c5SAndroid Build Coastguard Worker
2462*8975f5c5SAndroid Build Coastguard Worker // Make the image visible
2463*8975f5c5SAndroid Build Coastguard Worker eglSwapBuffers(mDisplay, mWindowSurface);
2464*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2465*8975f5c5SAndroid Build Coastguard Worker }
2466*8975f5c5SAndroid Build Coastguard Worker
2467*8975f5c5SAndroid Build Coastguard Worker // Draw with interpolateAtOffset() builtin function to pre-rotated custom FBO
TEST_P(EGLPreRotationInterpolateAtOffsetTest,InterpolateAtOffsetWithCustomFBO)2468*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLPreRotationInterpolateAtOffsetTest, InterpolateAtOffsetWithCustomFBO)
2469*8975f5c5SAndroid Build Coastguard Worker {
2470*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263074
2471*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
2472*8975f5c5SAndroid Build Coastguard Worker
2473*8975f5c5SAndroid Build Coastguard Worker // Flaky on Linux SwANGLE http://anglebug.com/42263074
2474*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
2475*8975f5c5SAndroid Build Coastguard Worker
2476*8975f5c5SAndroid Build Coastguard Worker // To aid in debugging, we want this window visible
2477*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
2478*8975f5c5SAndroid Build Coastguard Worker
2479*8975f5c5SAndroid Build Coastguard Worker initializeDisplay();
2480*8975f5c5SAndroid Build Coastguard Worker initializeSurfaceWithRGBA8888Config();
2481*8975f5c5SAndroid Build Coastguard Worker
2482*8975f5c5SAndroid Build Coastguard Worker eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
2483*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
2484*8975f5c5SAndroid Build Coastguard Worker
2485*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_shader_multisample_interpolation"));
2486*8975f5c5SAndroid Build Coastguard Worker
2487*8975f5c5SAndroid Build Coastguard Worker // Init program
2488*8975f5c5SAndroid Build Coastguard Worker GLuint program = createProgram();
2489*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
2490*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
2491*8975f5c5SAndroid Build Coastguard Worker
2492*8975f5c5SAndroid Build Coastguard Worker GLBuffer indexBuffer;
2493*8975f5c5SAndroid Build Coastguard Worker GLVertexArray vertexArray;
2494*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffers;
2495*8975f5c5SAndroid Build Coastguard Worker initializeGeometry(program, &indexBuffer, &vertexArray, &vertexBuffers);
2496*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2497*8975f5c5SAndroid Build Coastguard Worker
2498*8975f5c5SAndroid Build Coastguard Worker // Create a texture-backed FBO
2499*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
2500*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
2501*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
2502*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2503*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2504*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2505*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2506*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mSize, mSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2507*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2508*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
2509*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2510*8975f5c5SAndroid Build Coastguard Worker
2511*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, mSize, mSize);
2512*8975f5c5SAndroid Build Coastguard Worker glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
2513*8975f5c5SAndroid Build Coastguard Worker
2514*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(0, 255, 0, 255));
2515*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor(0, 255, 0, 255));
2516*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor(0, 255, 0, 255));
2517*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor(0, 255, 0, 255));
2518*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
2519*8975f5c5SAndroid Build Coastguard Worker }
2520*8975f5c5SAndroid Build Coastguard Worker
2521*8975f5c5SAndroid Build Coastguard Worker } // anonymous namespace
2522*8975f5c5SAndroid Build Coastguard Worker
2523*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLPreRotationInterpolateAtOffsetTest);
2524*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_COMBINE_1(EGLPreRotationInterpolateAtOffsetTest,
2525*8975f5c5SAndroid Build Coastguard Worker PrintToStringParamName,
2526*8975f5c5SAndroid Build Coastguard Worker testing::Bool(),
2527*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES31_VULKAN()));
2528*8975f5c5SAndroid Build Coastguard Worker
2529*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLPreRotationSurfaceTest);
2530*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_COMBINE_1(EGLPreRotationSurfaceTest,
2531*8975f5c5SAndroid Build Coastguard Worker PrintToStringParamName,
2532*8975f5c5SAndroid Build Coastguard Worker testing::Bool(),
2533*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES2_VULKAN()),
2534*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES3_VULKAN()),
2535*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES3_VULKAN_SWIFTSHADER()));
2536*8975f5c5SAndroid Build Coastguard Worker
2537*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLPreRotationLargeSurfaceTest);
2538*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_COMBINE_1(EGLPreRotationLargeSurfaceTest,
2539*8975f5c5SAndroid Build Coastguard Worker PrintToStringParamName,
2540*8975f5c5SAndroid Build Coastguard Worker testing::Bool(),
2541*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES2_VULKAN()),
2542*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES3_VULKAN()),
2543*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES3_VULKAN_SWIFTSHADER()));
2544*8975f5c5SAndroid Build Coastguard Worker
2545*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLPreRotationBlitFramebufferTest);
2546*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_COMBINE_1(EGLPreRotationBlitFramebufferTest,
2547*8975f5c5SAndroid Build Coastguard Worker PrintToStringParamName,
2548*8975f5c5SAndroid Build Coastguard Worker testing::Bool(),
2549*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES2_VULKAN()),
2550*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES3_VULKAN()),
2551*8975f5c5SAndroid Build Coastguard Worker WithNoFixture(ES3_VULKAN_SWIFTSHADER()));
2552