Hash :
dcbcee8a
Author :
Date :
2025-05-15T10:39:55
Tests: Use eglGetPlatformDisplay()
From the EGL 1.5 spec:
Appendix F
Version 1.5
EGL version 1.5 was voted out of the Khronos Technical Working Group
on January 31, 2014, and formally approved by the Khronos Board of
Promoters on March 14, 2014.
EGL 1.5 is the sixth release of EGL. It introduces the following new
features (the EGL extension(s) each feature is based on are also shown
parenthetically):
* Platform support:
– Providing a mechanism for support of multiple platforms (such as
window systems or offscreen rendering frameworks) in a single EGL
implementation at runtime (EGL_EXT_platform_base).
Many tests use eglGetPlatformDisplayEXT() which is provided by the EGL
extension EGL_EXT_platform_base. With the promotion of the
EGL_EXT_platform_base functions to core EGL in version 1.5 and ANGLE
supporting EGL 1.5 (as of at least 2019), update the calls to use
eglGetPlatformDisplay().
This is in preparation for running the ANGLE end2end tests in Android,
which only exposes the EGL 1.5 functions, and not the
EGL_EXT_platform_base functions.
Bug: b/391967165
Test: angle_end2end_tests
Change-Id: I58109c3afe270f46db952e124ee3f5c11200ca35
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6552257
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com>
Commit-Queue: Tim Van Patten <timvp@google.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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
//
// 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;
}
};
class EGLDisplayTestES3 : public EGLDisplayTest
{};
// 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);
}
// Tests eglGetPlatformDisplayEXT() when EGL_EXT_platform_base is enabled.
TEST_P(EGLDisplayTest, GetPlatformDisplayEXT)
{
// eglGetPlatformDisplayEXT() requires EGL_EXT_platform_base.
ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_EXT_platform_base"));
ASSERT_TRUE(eglGetPlatformDisplayEXT != nullptr);
EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};
EGLDisplay display = eglGetPlatformDisplayEXT(
EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
ASSERT_NE(EGL_NO_DISPLAY, display);
ASSERT_EGL_SUCCESS();
}
// Tests current Context leaking when call eglTerminate() while it is current.
TEST_P(EGLDisplayTestES3, GetPlatformDisplayAndroidValidation)
{
ANGLE_SKIP_TEST_IF(!IsAndroid());
// Get an EGLDisplay on GBM platform, expect EGL_BAD_PARAMETER
EGLDisplay display1 = eglGetPlatformDisplay(
EGL_PLATFORM_GBM_KHR, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), nullptr);
ASSERT_EQ(EGL_NO_DISPLAY, display1);
ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
// Get an EGLDisplay on Android platform, expect EGL_SUCCESS
EGLDisplay display2 = eglGetPlatformDisplay(
EGL_PLATFORM_ANDROID_KHR, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), nullptr);
ASSERT_NE(EGL_NO_DISPLAY, display2);
ASSERT_EGL_SUCCESS();
}
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()));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLDisplayTestES3);
ANGLE_INSTANTIATE_TEST(EGLDisplayTestES3, WithNoFixture(ES3_EGL()));