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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
//
// Copyright 2018 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.
//
// EGLDirectCompositionTest.cpp:
// Tests pertaining to DirectComposition and WindowsUIComposition.
#ifdef ANGLE_ENABLE_D3D11_COMPOSITOR_NATIVE_WINDOW
# include <d3d11.h>
# include "test_utils/ANGLETest.h"
# include <DispatcherQueue.h>
# include <VersionHelpers.h>
# include <Windows.Foundation.h>
# include <windows.ui.composition.desktop.h>
# include <windows.ui.composition.h>
# include <windows.ui.composition.interop.h>
# include <wrl.h>
# include <memory>
# include "libANGLE/renderer/d3d/d3d11/converged/CompositorNativeWindow11.h"
# include "util/OSWindow.h"
# include "util/com_utils.h"
# include "util/test_utils.h"
using namespace angle;
using namespace ABI::Windows::System;
using namespace ABI::Windows::UI::Composition;
using namespace ABI::Windows::UI::Composition::Desktop;
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
const int WINDOWWIDTH = 200, WINDOWHEIGHT = 200;
class EGLDirectCompositionTest : public ANGLETest<>
{
protected:
EGLDirectCompositionTest() : mOSWindow(nullptr) {}
void testSetUp() override
{
if (!mRoHelper.SupportedWindowsRelease())
{
return;
}
// Create an OS Window
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLDirectCompositionTest", WINDOWWIDTH, WINDOWHEIGHT);
auto nativeWindow = mOSWindow->getNativeWindow();
setWindowVisible(mOSWindow, true);
// Create DispatcherQueue for window to process compositor callbacks
CreateDispatcherQueue(mDispatcherController);
HSTRING act;
HSTRING_HEADER header;
auto hr = mRoHelper.GetStringReference(RuntimeClass_Windows_UI_Composition_Compositor, &act,
&header);
ASSERT_TRUE(SUCCEEDED(hr));
void *fac = nullptr;
hr = mRoHelper.GetActivationFactory(act, __uuidof(IActivationFactory), &fac);
ASSERT_TRUE(SUCCEEDED(hr));
ComPtr<IActivationFactory> compositorFactory;
compositorFactory.Attach((IActivationFactory *)fac);
hr = compositorFactory->ActivateInstance(&mCompositor);
ASSERT_TRUE(SUCCEEDED(hr));
// Create a DesktopWindowTarget against native window (HWND)
CreateDesktopWindowTarget(mCompositor, static_cast<HWND>(nativeWindow), mDesktopTarget);
ASSERT_TRUE(SUCCEEDED(mCompositor->CreateSpriteVisual(mAngleHost.GetAddressOf())));
ComPtr<IVisual> angleVis;
ASSERT_TRUE(SUCCEEDED(mAngleHost.As(&angleVis)));
ASSERT_TRUE(SUCCEEDED(angleVis->put_Size(
{static_cast<FLOAT>(WINDOWWIDTH), static_cast<FLOAT>(WINDOWHEIGHT)})));
ASSERT_TRUE(SUCCEEDED(angleVis->put_Offset({0, 0, 0})));
ComPtr<ICompositionTarget> compTarget;
ASSERT_TRUE(SUCCEEDED(mDesktopTarget.As(&compTarget)));
ASSERT_TRUE(SUCCEEDED(compTarget->put_Root(angleVis.Get())));
Init();
}
void CreateDispatcherQueue(ComPtr<IDispatcherQueueController> &controller)
{
DispatcherQueueOptions options{sizeof(DispatcherQueueOptions), DQTYPE_THREAD_CURRENT,
DQTAT_COM_STA};
auto hr = mRoHelper.CreateDispatcherQueueController(options, controller.GetAddressOf());
ASSERT_TRUE(SUCCEEDED(hr));
}
void CreateDesktopWindowTarget(ComPtr<ICompositor> const &compositor,
const HWND window,
ComPtr<IDesktopWindowTarget> &target)
{
namespace abi = ABI::Windows::UI::Composition::Desktop;
ComPtr<ICompositorDesktopInterop> interop;
ASSERT_TRUE(SUCCEEDED(compositor.As(&interop)));
ASSERT_TRUE(SUCCEEDED(interop->CreateDesktopWindowTarget(
window, true, reinterpret_cast<abi::IDesktopWindowTarget **>(target.GetAddressOf()))));
}
void Init()
{
if (!mRoHelper.SupportedWindowsRelease())
{
return;
}
DPI_AWARENESS_CONTEXT
WINAPI
SetThreadDpiAwarenessContext(_In_ DPI_AWARENESS_CONTEXT dpiContext);
auto userModule = LoadLibraryA("user32.dll");
if (userModule == nullptr)
{
return;
}
auto temp = GetProcAddress(userModule, "SetThreadDpiAwarenessContext");
mFpSetThreadDpiAwarenessContext = reinterpret_cast<_SetThreadDpiAwarenessContext *>(temp);
const EGLint configAttributes[] = {
EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8, EGL_NONE};
const EGLAttrib defaultDisplayAttributes[] = {
EGL_PLATFORM_ANGLE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
EGL_NONE,
};
PFNEGLGETPLATFORMDISPLAYPROC eglGetPlatformDisplay =
reinterpret_cast<PFNEGLGETPLATFORMDISPLAYPROC>(
eglGetProcAddress("eglGetPlatformDisplay"));
ASSERT_TRUE(eglGetPlatformDisplay != nullptr);
mEglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY),
defaultDisplayAttributes);
ASSERT_TRUE(mEglDisplay != EGL_NO_DISPLAY);
ASSERT_EGL_TRUE(eglInitialize(mEglDisplay, nullptr, nullptr));
EGLint nConfigs = 0;
ASSERT_EGL_TRUE(eglGetConfigs(mEglDisplay, nullptr, 0, &nConfigs));
ASSERT_TRUE(nConfigs != 0);
ASSERT_EGL_TRUE(eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &nConfigs));
}
void CreateSurface(ComPtr<ABI::Windows::UI::Composition::ISpriteVisual> visual,
EGLSurface &surface)
{
auto displayExtensions = eglQueryString(mEglDisplay, EGL_EXTENSIONS);
// Check that the EGL_ANGLE_windows_ui_composition display extension is available
ASSERT_TRUE(strstr(displayExtensions, "EGL_ANGLE_windows_ui_composition") != nullptr);
const EGLint contextAttributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
// Use a spritevisual as the nativewindowtype
surface =
eglCreateWindowSurface(mEglDisplay, mEglConfig,
static_cast<EGLNativeWindowType>((void *)visual.Get()), nullptr);
ASSERT_TRUE(surface != EGL_NO_SURFACE);
mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, contextAttributes);
ASSERT_TRUE(mEglContext != EGL_NO_CONTEXT);
ASSERT_TRUE(eglMakeCurrent(mEglDisplay, surface, surface, mEglContext) != EGL_FALSE);
}
void testTearDown() override
{
if (!mRoHelper.SupportedWindowsRelease())
{
return;
}
if (mEglDisplay != EGL_NO_DISPLAY)
{
ASSERT_EGL_TRUE(eglTerminate(mEglDisplay));
mEglDisplay = EGL_NO_DISPLAY;
}
OSWindow::Delete(&mOSWindow);
}
OSWindow *mOSWindow;
ComPtr<ICompositor> mCompositor;
ComPtr<IDispatcherQueueController> mDispatcherController;
ComPtr<ICompositionColorBrush> mColorBrush;
ComPtr<IDesktopWindowTarget> mDesktopTarget;
ComPtr<ISpriteVisual> mAngleHost;
EGLDisplay mEglDisplay;
EGLContext mEglContext;
EGLConfig mEglConfig;
rx::RoHelper mRoHelper;
using _SetThreadDpiAwarenessContext =
DPI_AWARENESS_CONTEXT WINAPI(DPI_AWARENESS_CONTEXT dpiContext);
_SetThreadDpiAwarenessContext *mFpSetThreadDpiAwarenessContext;
};
// This tests that a surface created using a SpriteVisual as container has the expected dimensions
// which should match the dimensions of the SpriteVisual passed in
TEST_P(EGLDirectCompositionTest, SurfaceSizeFromSpriteSize)
{
// Only attempt this test when on Windows 10 1803+
ANGLE_SKIP_TEST_IF(!mRoHelper.SupportedWindowsRelease());
EGLSurface s{nullptr};
CreateSurface(mAngleHost, s);
EGLint surfacewidth = 0, surfaceheight = 0;
eglQuerySurface(mEglDisplay, s, EGL_WIDTH, &surfacewidth);
eglQuerySurface(mEglDisplay, s, EGL_HEIGHT, &surfaceheight);
ComPtr<IVisual> angleVis;
ASSERT_TRUE(SUCCEEDED(mAngleHost.As(&angleVis)));
ABI::Windows::Foundation::Numerics::Vector2 visualsize{0, 0};
ASSERT_TRUE(SUCCEEDED(angleVis->get_Size(&visualsize)));
ASSERT_TRUE(surfacewidth == static_cast<int>(visualsize.X));
ASSERT_TRUE(surfaceheight == static_cast<int>(visualsize.Y));
ASSERT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) !=
EGL_FALSE);
ASSERT_EGL_TRUE(eglDestroySurface(mEglDisplay, s));
ASSERT_EGL_TRUE(eglDestroyContext(mEglDisplay, mEglContext));
mEglContext = EGL_NO_CONTEXT;
}
// This tests that a WindowSurface can be created using a SpriteVisual as the containing window
// and that pixels can be successfully rendered into the resulting WindowSurface
TEST_P(EGLDirectCompositionTest, RenderSolidColor)
{
// Only attempt this test when on Windows 10 1803+
ANGLE_SKIP_TEST_IF(!mRoHelper.SupportedWindowsRelease());
EGLSurface s{nullptr};
CreateSurface(mAngleHost, s);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glViewport(0, 0, WINDOWWIDTH, WINDOWHEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
ASSERT_EGL_TRUE(eglSwapBuffers(mEglDisplay, s));
// ensure user/DWM have a chance to paint the window and kick it to the top of the desktop
// zorder before we attempt to sample
angle::Sleep(200);
mOSWindow->messageLoop();
uint8_t *pixelBuffer = static_cast<uint8_t *>(malloc(WINDOWWIDTH * WINDOWHEIGHT * 4));
ZeroMemory(pixelBuffer, WINDOWWIDTH * WINDOWHEIGHT * 4);
// In order to accurately capture a bitmap, we need to temporarily shift into per-monitor DPI
// mode in order to get the window offset from desktop correct
auto previous = mFpSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
bool success = mOSWindow->takeScreenshot(pixelBuffer);
mFpSetThreadDpiAwarenessContext(previous);
ASSERT_EGL_TRUE(success);
ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4)] == 255);
ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4) + 1] == 0);
ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4) + 2] == 0);
ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4) + 3] == 255);
ASSERT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) !=
EGL_FALSE);
ASSERT_EGL_TRUE(eglDestroySurface(mEglDisplay, s));
ASSERT_EGL_TRUE(eglDestroyContext(mEglDisplay, mEglContext));
mEglContext = EGL_NO_CONTEXT;
}
ANGLE_INSTANTIATE_TEST(EGLDirectCompositionTest, WithNoFixture(ES2_D3D11()));
#endif // ANGLE_ENABLE_D3D11_COMPOSITOR_NATIVE_WINDOW