Hash :
9e8b104e
Author :
Date :
2024-10-14T00:00:00
Do not test OpenGL backend on iOS Added Metal platform to tests that require instantiation. Bug: angleproject:40050022 Bug: angleproject:42264029 Bug: angleproject:42266119 Bug: angleproject:42266226 Bug: angleproject:42266239 Bug: angleproject:42266249 Bug: angleproject:359136169 Fixed: angleproject:373478551 Change-Id: I915f09c7f24acce27bf0d489932645338ac3fbe8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5932659 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include <gtest/gtest.h>
#include <vector>
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/OSWindow.h"
using namespace angle;
class EGLDisplayTest : public ANGLETest<>
{
protected:
EGLConfig chooseConfig(EGLDisplay display)
{
const EGLint attribs[] = {EGL_RED_SIZE,
8,
EGL_GREEN_SIZE,
8,
EGL_BLUE_SIZE,
8,
EGL_ALPHA_SIZE,
8,
EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE,
EGL_PBUFFER_BIT | EGL_WINDOW_BIT,
EGL_NONE};
EGLConfig config = EGL_NO_CONFIG_KHR;
EGLint count = 0;
EXPECT_EGL_TRUE(eglChooseConfig(display, attribs, &config, 1, &count));
EXPECT_EGL_TRUE(count > 0);
return config;
}
EGLContext createContext(EGLDisplay display, EGLConfig config)
{
const EGLint attribs[] = {EGL_CONTEXT_MAJOR_VERSION, 2, EGL_NONE};
EGLContext context = eglCreateContext(display, config, nullptr, attribs);
EXPECT_NE(context, EGL_NO_CONTEXT);
return context;
}
EGLSurface createSurface(EGLDisplay display, EGLConfig config)
{
const EGLint attribs[] = {EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
EGLSurface surface = eglCreatePbufferSurface(display, config, attribs);
EXPECT_NE(surface, EGL_NO_SURFACE);
return surface;
}
};
// Tests that an eglInitialize can be re-initialized. The spec says:
//
// > Initializing an already-initialized display is allowed, but the only effect of such a call is
// to return EGL_TRUE and update the EGL version numbers
TEST_P(EGLDisplayTest, InitializeMultipleTimes)
{
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EGLint major = 0, minor = 0;
EXPECT_EGL_TRUE(eglInitialize(display, &major, &minor) != EGL_FALSE);
for (uint32_t i = 0; i < 10; ++i)
{
EGLint retryMajor = 123456, retryMinor = -1;
EXPECT_EGL_TRUE(eglInitialize(display, &retryMajor, &retryMinor) != EGL_FALSE);
EXPECT_EQ(major, retryMajor) << i;
EXPECT_EQ(minor, retryMinor) << i;
}
}
// Test that call eglInitialize() in parallel in multiple threads works
// > Initializing an already-initialized display is allowed, but the only effect
// of such a call is to return EGL_TRUE and update the EGL version numbers
TEST_P(EGLDisplayTest, InitializeMultipleTimesInDifferentThreads)
{
std::array<std::thread, 10> threads;
for (std::thread &thread : threads)
{
thread = std::thread([&]() {
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
const int INVALID_GL_MAJOR_VERSION = -1;
const int INVALID_GL_MINOR_VERSION = -1;
EGLint threadMajor = INVALID_GL_MAJOR_VERSION;
EGLint threadMinor = INVALID_GL_MINOR_VERSION;
EXPECT_EGL_TRUE(eglInitialize(display, &threadMajor, &threadMinor) != EGL_FALSE);
EXPECT_NE(threadMajor, INVALID_GL_MAJOR_VERSION);
EXPECT_NE(threadMinor, INVALID_GL_MINOR_VERSION);
});
}
for (std::thread &thread : threads)
{
thread.join();
}
}
// Tests that an EGLDisplay can be re-initialized.
TEST_P(EGLDisplayTest, InitializeTerminateInitialize)
{
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EXPECT_EGL_TRUE(eglInitialize(display, nullptr, nullptr) != EGL_FALSE);
EXPECT_EGL_TRUE(eglTerminate(display) != EGL_FALSE);
EXPECT_EGL_TRUE(eglInitialize(display, nullptr, nullptr) != EGL_FALSE);
}
// Tests that an EGLDisplay can be re-initialized after it was used to draw into a window surface.
TEST_P(EGLDisplayTest, InitializeDrawSwapTerminateLoop)
{
constexpr int kLoopCount = 2;
constexpr EGLint kWidth = 64;
constexpr EGLint kHeight = 64;
OSWindow *osWindow = OSWindow::New();
osWindow->initialize("LockSurfaceTest", kWidth, kHeight);
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
for (int i = 0; i < kLoopCount; ++i)
{
EXPECT_EGL_TRUE(eglInitialize(display, nullptr, nullptr) != EGL_FALSE);
EGLConfig config = chooseConfig(display);
EGLContext context = createContext(display, config);
EGLSurface surface =
eglCreateWindowSurface(display, config, osWindow->getNativeWindow(), nullptr);
EXPECT_NE(surface, EGL_NO_SURFACE);
EXPECT_EGL_TRUE(eglMakeCurrent(display, surface, surface, context));
ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
drawQuad(greenProgram, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_EGL_TRUE(eglSwapBuffers(display, surface));
EXPECT_EGL_TRUE(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
EXPECT_EGL_TRUE(eglTerminate(display) != EGL_FALSE);
}
osWindow->destroy();
OSWindow::Delete(&osWindow);
}
// Tests current Context leaking when call eglTerminate() while it is current.
TEST_P(EGLDisplayTest, ContextLeakAfterTerminate)
{
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EXPECT_EGL_TRUE(eglInitialize(display, nullptr, nullptr));
EGLConfig config = chooseConfig(display);
EGLContext context = createContext(display, config);
EGLSurface surface = createSurface(display, config);
// Make "context" current.
EXPECT_EGL_TRUE(eglMakeCurrent(display, surface, surface, context));
// Terminate display while "context" is current.
EXPECT_EGL_TRUE(eglTerminate(display));
// Unmake "context" from current and allow Display to actually terminate.
(void)eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
// Get EGLDisplay again.
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// Check if Display was actually terminated.
EGLint val;
EXPECT_EGL_FALSE(eglQueryContext(display, context, EGL_CONTEXT_CLIENT_TYPE, &val));
EXPECT_EQ(eglGetError(), EGL_NOT_INITIALIZED);
}
ANGLE_INSTANTIATE_TEST(EGLDisplayTest,
WithNoFixture(ES2_D3D9()),
WithNoFixture(ES2_D3D11()),
WithNoFixture(ES2_METAL()),
WithNoFixture(ES2_OPENGL()),
WithNoFixture(ES2_VULKAN()),
WithNoFixture(ES3_D3D11()),
WithNoFixture(ES3_METAL()),
WithNoFixture(ES3_OPENGL()),
WithNoFixture(ES3_VULKAN()));