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 2015 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.
//
// EGLX11VisualTest.cpp: tests for EGL_ANGLE_x11_visual extension
#include <gtest/gtest.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
#include "test_utils/ANGLETest.h"
#include "util/OSWindow.h"
#include "util/linux/x11/X11Window.h"
using namespace angle;
namespace
{
const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
}
class EGLX11VisualHintTest : public ANGLETest<>
{
public:
void testSetUp() override { mDisplay = XOpenDisplay(nullptr); }
std::vector<EGLAttrib> getDisplayAttributes(int visualId) const
{
std::vector<EGLAttrib> attribs;
attribs.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
attribs.push_back(GetParam().getRenderer());
attribs.push_back(EGL_X11_VISUAL_ID_ANGLE);
attribs.push_back(visualId);
attribs.push_back(EGL_NONE);
return attribs;
}
unsigned int chooseDifferentVisual(unsigned int visualId)
{
int numVisuals;
XVisualInfo visualTemplate;
visualTemplate.screen = DefaultScreen(mDisplay);
XVisualInfo *visuals =
XGetVisualInfo(mDisplay, VisualScreenMask, &visualTemplate, &numVisuals);
EXPECT_TRUE(numVisuals >= 2);
for (int i = 0; i < numVisuals; ++i)
{
if (visuals[i].visualid != visualId)
{
int result = visuals[i].visualid;
XFree(visuals);
return result;
}
}
EXPECT_TRUE(false);
return -1;
}
protected:
Display *mDisplay;
};
// Test that display creation fails if the visual ID passed in invalid.
TEST_P(EGLX11VisualHintTest, InvalidVisualID)
{
static const int gInvalidVisualId = -1;
auto attributes = getDisplayAttributes(gInvalidVisualId);
EGLDisplay display = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<_XDisplay *>(EGL_DEFAULT_DISPLAY),
attributes.data());
ASSERT_TRUE(display != EGL_NO_DISPLAY);
ASSERT_TRUE(EGL_FALSE == eglInitialize(display, nullptr, nullptr));
ASSERT_EGL_ERROR(EGL_NOT_INITIALIZED);
}
// Test that context creation with a visual ID succeeds, that the context exposes
// only one config, and that a clear on a surface with this config works.
TEST_P(EGLX11VisualHintTest, ValidVisualIDAndClear)
{
// We'll test the extension with one visual ID but we don't care which one. This means we
// can use OSWindow to create a window and just grab its visual.
OSWindow *osWindow = OSWindow::New();
osWindow->initialize("EGLX11VisualHintTest", 500, 500);
setWindowVisible(osWindow, true);
Window xWindow = osWindow->getNativeWindow();
XWindowAttributes windowAttributes;
ASSERT_NE(0, XGetWindowAttributes(mDisplay, xWindow, &windowAttributes));
int visualId = windowAttributes.visual->visualid;
auto attributes = getDisplayAttributes(visualId);
EGLDisplay display = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<_XDisplay *>(EGL_DEFAULT_DISPLAY),
attributes.data());
ASSERT_NE(EGL_NO_DISPLAY, display);
ASSERT_TRUE(EGL_TRUE == eglInitialize(display, nullptr, nullptr));
int nConfigs = 0;
ASSERT_TRUE(EGL_TRUE == eglGetConfigs(display, nullptr, 0, &nConfigs));
ASSERT_GE(nConfigs, 1);
int nReturnedConfigs = 0;
std::vector<EGLConfig> configs(nConfigs);
ASSERT_TRUE(EGL_TRUE == eglGetConfigs(display, configs.data(), nConfigs, &nReturnedConfigs));
ASSERT_EQ(nConfigs, nReturnedConfigs);
for (EGLConfig config : configs)
{
EGLint eglNativeId;
ASSERT_TRUE(EGL_TRUE ==
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &eglNativeId));
ASSERT_EQ(visualId, eglNativeId);
// Finally, try to do a clear on the window.
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
ASSERT_NE(EGL_NO_CONTEXT, context);
EGLSurface window = eglCreateWindowSurface(display, config, xWindow, nullptr);
ASSERT_EGL_SUCCESS();
eglMakeCurrent(display, window, window, context);
ASSERT_EGL_SUCCESS();
glViewport(0, 0, 500, 500);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(250, 250, 0, 0, 255, 255);
// Teardown
eglDestroySurface(display, window);
ASSERT_EGL_SUCCESS();
eglDestroyContext(display, context);
ASSERT_EGL_SUCCESS();
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
ASSERT_EGL_SUCCESS();
}
OSWindow::Delete(&osWindow);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglTerminate(display);
}
// Test that a child window is created when trying to create an EGL window from
// an X11 window whose visual ID doesn't match the visual ID passed at display creation.
TEST_P(EGLX11VisualHintTest, InvalidWindowVisualID)
{
// Get the default visual ID, as a good guess of a visual id for which display
// creation will succeed.
int visualId;
{
OSWindow *osWindow = OSWindow::New();
osWindow->initialize("EGLX11VisualHintTest", 500, 500);
setWindowVisible(osWindow, true);
Window xWindow = osWindow->getNativeWindow();
XWindowAttributes windowAttributes;
ASSERT_NE(0, XGetWindowAttributes(mDisplay, xWindow, &windowAttributes));
visualId = windowAttributes.visual->visualid;
OSWindow::Delete(&osWindow);
}
auto attributes = getDisplayAttributes(visualId);
EGLDisplay display = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<_XDisplay *>(EGL_DEFAULT_DISPLAY),
attributes.data());
ASSERT_NE(EGL_NO_DISPLAY, display);
ASSERT_TRUE(EGL_TRUE == eglInitialize(display, nullptr, nullptr));
// Initialize the window with a visual id different from the display's visual id
int otherVisualId = chooseDifferentVisual(visualId);
ASSERT_NE(visualId, otherVisualId);
OSWindow *osWindow = CreateX11WindowWithVisualId(otherVisualId);
osWindow->initialize("EGLX11VisualHintTest", 500, 500);
setWindowVisible(osWindow, true);
Window xWindow = osWindow->getNativeWindow();
// Creating the EGL window should succeed
int nReturnedConfigs = 0;
EGLConfig config;
ASSERT_TRUE(EGL_TRUE == eglGetConfigs(display, &config, 1, &nReturnedConfigs));
ASSERT_EQ(1, nReturnedConfigs);
EGLSurface window = eglCreateWindowSurface(display, config, xWindow, nullptr);
ASSERT_TRUE(window);
ASSERT_EGL_SUCCESS();
// When trying to create a window with a visual other than the one specified
// with EGL_X11_VISUAL_ID_ANGLE, ANGLE should fallback to using a child window.
Window root;
Window parent;
Window *children;
unsigned int nchildren;
XQueryTree(mDisplay, xWindow, &root, &parent, &children, &nchildren);
EXPECT_EQ(nchildren, 1U);
XFree(children);
OSWindow::Delete(&osWindow);
}
ANGLE_INSTANTIATE_TEST(EGLX11VisualHintTest, WithNoFixture(ES2_OPENGL()));