1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2018 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
7*8975f5c5SAndroid Build Coastguard Worker // EGLDirectCompositionTest.cpp:
8*8975f5c5SAndroid Build Coastguard Worker // Tests pertaining to DirectComposition and WindowsUIComposition.
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #ifdef ANGLE_ENABLE_D3D11_COMPOSITOR_NATIVE_WINDOW
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker # include <d3d11.h>
13*8975f5c5SAndroid Build Coastguard Worker # include "test_utils/ANGLETest.h"
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard Worker # include <DispatcherQueue.h>
16*8975f5c5SAndroid Build Coastguard Worker # include <VersionHelpers.h>
17*8975f5c5SAndroid Build Coastguard Worker # include <Windows.Foundation.h>
18*8975f5c5SAndroid Build Coastguard Worker # include <windows.ui.composition.Desktop.h>
19*8975f5c5SAndroid Build Coastguard Worker # include <windows.ui.composition.h>
20*8975f5c5SAndroid Build Coastguard Worker # include <windows.ui.composition.interop.h>
21*8975f5c5SAndroid Build Coastguard Worker # include <wrl.h>
22*8975f5c5SAndroid Build Coastguard Worker # include <memory>
23*8975f5c5SAndroid Build Coastguard Worker
24*8975f5c5SAndroid Build Coastguard Worker # include "libANGLE/renderer/d3d/d3d11/converged/CompositorNativeWindow11.h"
25*8975f5c5SAndroid Build Coastguard Worker # include "util/OSWindow.h"
26*8975f5c5SAndroid Build Coastguard Worker # include "util/com_utils.h"
27*8975f5c5SAndroid Build Coastguard Worker # include "util/test_utils.h"
28*8975f5c5SAndroid Build Coastguard Worker
29*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
30*8975f5c5SAndroid Build Coastguard Worker using namespace ABI::Windows::System;
31*8975f5c5SAndroid Build Coastguard Worker using namespace ABI::Windows::UI::Composition;
32*8975f5c5SAndroid Build Coastguard Worker using namespace ABI::Windows::UI::Composition::Desktop;
33*8975f5c5SAndroid Build Coastguard Worker using namespace ABI::Windows::Foundation;
34*8975f5c5SAndroid Build Coastguard Worker using namespace Microsoft::WRL;
35*8975f5c5SAndroid Build Coastguard Worker using namespace Microsoft::WRL::Wrappers;
36*8975f5c5SAndroid Build Coastguard Worker
37*8975f5c5SAndroid Build Coastguard Worker const int WINDOWWIDTH = 200, WINDOWHEIGHT = 200;
38*8975f5c5SAndroid Build Coastguard Worker
39*8975f5c5SAndroid Build Coastguard Worker class EGLDirectCompositionTest : public ANGLETest<>
40*8975f5c5SAndroid Build Coastguard Worker {
41*8975f5c5SAndroid Build Coastguard Worker protected:
EGLDirectCompositionTest()42*8975f5c5SAndroid Build Coastguard Worker EGLDirectCompositionTest() : mOSWindow(nullptr) {}
43*8975f5c5SAndroid Build Coastguard Worker
testSetUp()44*8975f5c5SAndroid Build Coastguard Worker void testSetUp() override
45*8975f5c5SAndroid Build Coastguard Worker {
46*8975f5c5SAndroid Build Coastguard Worker if (!mRoHelper.SupportedWindowsRelease())
47*8975f5c5SAndroid Build Coastguard Worker {
48*8975f5c5SAndroid Build Coastguard Worker return;
49*8975f5c5SAndroid Build Coastguard Worker }
50*8975f5c5SAndroid Build Coastguard Worker
51*8975f5c5SAndroid Build Coastguard Worker // Create an OS Window
52*8975f5c5SAndroid Build Coastguard Worker mOSWindow = OSWindow::New();
53*8975f5c5SAndroid Build Coastguard Worker
54*8975f5c5SAndroid Build Coastguard Worker mOSWindow->initialize("EGLDirectCompositionTest", WINDOWWIDTH, WINDOWHEIGHT);
55*8975f5c5SAndroid Build Coastguard Worker auto nativeWindow = mOSWindow->getNativeWindow();
56*8975f5c5SAndroid Build Coastguard Worker setWindowVisible(mOSWindow, true);
57*8975f5c5SAndroid Build Coastguard Worker
58*8975f5c5SAndroid Build Coastguard Worker // Create DispatcherQueue for window to process compositor callbacks
59*8975f5c5SAndroid Build Coastguard Worker CreateDispatcherQueue(mDispatcherController);
60*8975f5c5SAndroid Build Coastguard Worker
61*8975f5c5SAndroid Build Coastguard Worker HSTRING act;
62*8975f5c5SAndroid Build Coastguard Worker HSTRING_HEADER header;
63*8975f5c5SAndroid Build Coastguard Worker
64*8975f5c5SAndroid Build Coastguard Worker auto hr = mRoHelper.GetStringReference(RuntimeClass_Windows_UI_Composition_Compositor, &act,
65*8975f5c5SAndroid Build Coastguard Worker &header);
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(hr));
68*8975f5c5SAndroid Build Coastguard Worker
69*8975f5c5SAndroid Build Coastguard Worker void *fac = nullptr;
70*8975f5c5SAndroid Build Coastguard Worker hr = mRoHelper.GetActivationFactory(act, __uuidof(IActivationFactory), &fac);
71*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(hr));
72*8975f5c5SAndroid Build Coastguard Worker
73*8975f5c5SAndroid Build Coastguard Worker ComPtr<IActivationFactory> compositorFactory;
74*8975f5c5SAndroid Build Coastguard Worker
75*8975f5c5SAndroid Build Coastguard Worker compositorFactory.Attach((IActivationFactory *)fac);
76*8975f5c5SAndroid Build Coastguard Worker
77*8975f5c5SAndroid Build Coastguard Worker hr = compositorFactory->ActivateInstance(&mCompositor);
78*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(hr));
79*8975f5c5SAndroid Build Coastguard Worker
80*8975f5c5SAndroid Build Coastguard Worker // Create a DesktopWindowTarget against native window (HWND)
81*8975f5c5SAndroid Build Coastguard Worker CreateDesktopWindowTarget(mCompositor, static_cast<HWND>(nativeWindow), mDesktopTarget);
82*8975f5c5SAndroid Build Coastguard Worker
83*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(mCompositor->CreateSpriteVisual(mAngleHost.GetAddressOf())));
84*8975f5c5SAndroid Build Coastguard Worker
85*8975f5c5SAndroid Build Coastguard Worker ComPtr<IVisual> angleVis;
86*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(mAngleHost.As(&angleVis)));
87*8975f5c5SAndroid Build Coastguard Worker
88*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(angleVis->put_Size(
89*8975f5c5SAndroid Build Coastguard Worker {static_cast<FLOAT>(WINDOWWIDTH), static_cast<FLOAT>(WINDOWHEIGHT)})));
90*8975f5c5SAndroid Build Coastguard Worker
91*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(angleVis->put_Offset({0, 0, 0})));
92*8975f5c5SAndroid Build Coastguard Worker
93*8975f5c5SAndroid Build Coastguard Worker ComPtr<ICompositionTarget> compTarget;
94*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(mDesktopTarget.As(&compTarget)));
95*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(compTarget->put_Root(angleVis.Get())));
96*8975f5c5SAndroid Build Coastguard Worker
97*8975f5c5SAndroid Build Coastguard Worker Init();
98*8975f5c5SAndroid Build Coastguard Worker }
99*8975f5c5SAndroid Build Coastguard Worker
CreateDispatcherQueue(ComPtr<IDispatcherQueueController> & controller)100*8975f5c5SAndroid Build Coastguard Worker void CreateDispatcherQueue(ComPtr<IDispatcherQueueController> &controller)
101*8975f5c5SAndroid Build Coastguard Worker {
102*8975f5c5SAndroid Build Coastguard Worker DispatcherQueueOptions options{sizeof(DispatcherQueueOptions), DQTYPE_THREAD_CURRENT,
103*8975f5c5SAndroid Build Coastguard Worker DQTAT_COM_STA};
104*8975f5c5SAndroid Build Coastguard Worker
105*8975f5c5SAndroid Build Coastguard Worker auto hr = mRoHelper.CreateDispatcherQueueController(options, controller.GetAddressOf());
106*8975f5c5SAndroid Build Coastguard Worker
107*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(hr));
108*8975f5c5SAndroid Build Coastguard Worker }
109*8975f5c5SAndroid Build Coastguard Worker
CreateDesktopWindowTarget(ComPtr<ICompositor> const & compositor,const HWND window,ComPtr<IDesktopWindowTarget> & target)110*8975f5c5SAndroid Build Coastguard Worker void CreateDesktopWindowTarget(ComPtr<ICompositor> const &compositor,
111*8975f5c5SAndroid Build Coastguard Worker const HWND window,
112*8975f5c5SAndroid Build Coastguard Worker ComPtr<IDesktopWindowTarget> &target)
113*8975f5c5SAndroid Build Coastguard Worker {
114*8975f5c5SAndroid Build Coastguard Worker namespace abi = ABI::Windows::UI::Composition::Desktop;
115*8975f5c5SAndroid Build Coastguard Worker
116*8975f5c5SAndroid Build Coastguard Worker ComPtr<ICompositorDesktopInterop> interop;
117*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(compositor.As(&interop)));
118*8975f5c5SAndroid Build Coastguard Worker
119*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(interop->CreateDesktopWindowTarget(
120*8975f5c5SAndroid Build Coastguard Worker window, true, reinterpret_cast<abi::IDesktopWindowTarget **>(target.GetAddressOf()))));
121*8975f5c5SAndroid Build Coastguard Worker }
122*8975f5c5SAndroid Build Coastguard Worker
Init()123*8975f5c5SAndroid Build Coastguard Worker void Init()
124*8975f5c5SAndroid Build Coastguard Worker {
125*8975f5c5SAndroid Build Coastguard Worker if (!mRoHelper.SupportedWindowsRelease())
126*8975f5c5SAndroid Build Coastguard Worker {
127*8975f5c5SAndroid Build Coastguard Worker return;
128*8975f5c5SAndroid Build Coastguard Worker }
129*8975f5c5SAndroid Build Coastguard Worker
130*8975f5c5SAndroid Build Coastguard Worker DPI_AWARENESS_CONTEXT
131*8975f5c5SAndroid Build Coastguard Worker WINAPI
132*8975f5c5SAndroid Build Coastguard Worker SetThreadDpiAwarenessContext(_In_ DPI_AWARENESS_CONTEXT dpiContext);
133*8975f5c5SAndroid Build Coastguard Worker
134*8975f5c5SAndroid Build Coastguard Worker auto userModule = LoadLibraryA("user32.dll");
135*8975f5c5SAndroid Build Coastguard Worker
136*8975f5c5SAndroid Build Coastguard Worker if (userModule == nullptr)
137*8975f5c5SAndroid Build Coastguard Worker {
138*8975f5c5SAndroid Build Coastguard Worker return;
139*8975f5c5SAndroid Build Coastguard Worker }
140*8975f5c5SAndroid Build Coastguard Worker
141*8975f5c5SAndroid Build Coastguard Worker auto temp = GetProcAddress(userModule, "SetThreadDpiAwarenessContext");
142*8975f5c5SAndroid Build Coastguard Worker
143*8975f5c5SAndroid Build Coastguard Worker mFpSetThreadDpiAwarenessContext = reinterpret_cast<_SetThreadDpiAwarenessContext *>(temp);
144*8975f5c5SAndroid Build Coastguard Worker
145*8975f5c5SAndroid Build Coastguard Worker const EGLint configAttributes[] = {
146*8975f5c5SAndroid Build Coastguard Worker EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
147*8975f5c5SAndroid Build Coastguard Worker EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8, EGL_NONE};
148*8975f5c5SAndroid Build Coastguard Worker
149*8975f5c5SAndroid Build Coastguard Worker const EGLint defaultDisplayAttributes[] = {
150*8975f5c5SAndroid Build Coastguard Worker EGL_PLATFORM_ANGLE_TYPE_ANGLE,
151*8975f5c5SAndroid Build Coastguard Worker EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
152*8975f5c5SAndroid Build Coastguard Worker EGL_NONE,
153*8975f5c5SAndroid Build Coastguard Worker };
154*8975f5c5SAndroid Build Coastguard Worker
155*8975f5c5SAndroid Build Coastguard Worker PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT =
156*8975f5c5SAndroid Build Coastguard Worker reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
157*8975f5c5SAndroid Build Coastguard Worker eglGetProcAddress("eglGetPlatformDisplayEXT"));
158*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(eglGetPlatformDisplayEXT != nullptr);
159*8975f5c5SAndroid Build Coastguard Worker
160*8975f5c5SAndroid Build Coastguard Worker mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
161*8975f5c5SAndroid Build Coastguard Worker reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY),
162*8975f5c5SAndroid Build Coastguard Worker defaultDisplayAttributes);
163*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(mEglDisplay != EGL_NO_DISPLAY);
164*8975f5c5SAndroid Build Coastguard Worker
165*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglInitialize(mEglDisplay, nullptr, nullptr));
166*8975f5c5SAndroid Build Coastguard Worker
167*8975f5c5SAndroid Build Coastguard Worker EGLint nConfigs = 0;
168*8975f5c5SAndroid Build Coastguard Worker
169*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglGetConfigs(mEglDisplay, nullptr, 0, &nConfigs));
170*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(nConfigs != 0);
171*8975f5c5SAndroid Build Coastguard Worker
172*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &nConfigs));
173*8975f5c5SAndroid Build Coastguard Worker }
174*8975f5c5SAndroid Build Coastguard Worker
CreateSurface(ComPtr<ABI::Windows::UI::Composition::ISpriteVisual> visual,EGLSurface & surface)175*8975f5c5SAndroid Build Coastguard Worker void CreateSurface(ComPtr<ABI::Windows::UI::Composition::ISpriteVisual> visual,
176*8975f5c5SAndroid Build Coastguard Worker EGLSurface &surface)
177*8975f5c5SAndroid Build Coastguard Worker {
178*8975f5c5SAndroid Build Coastguard Worker auto displayExtensions = eglQueryString(mEglDisplay, EGL_EXTENSIONS);
179*8975f5c5SAndroid Build Coastguard Worker
180*8975f5c5SAndroid Build Coastguard Worker // Check that the EGL_ANGLE_windows_ui_composition display extension is available
181*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(strstr(displayExtensions, "EGL_ANGLE_windows_ui_composition") != nullptr);
182*8975f5c5SAndroid Build Coastguard Worker
183*8975f5c5SAndroid Build Coastguard Worker const EGLint contextAttributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
184*8975f5c5SAndroid Build Coastguard Worker
185*8975f5c5SAndroid Build Coastguard Worker // Use a spritevisual as the nativewindowtype
186*8975f5c5SAndroid Build Coastguard Worker surface =
187*8975f5c5SAndroid Build Coastguard Worker eglCreateWindowSurface(mEglDisplay, mEglConfig,
188*8975f5c5SAndroid Build Coastguard Worker static_cast<EGLNativeWindowType>((void *)visual.Get()), nullptr);
189*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(surface != EGL_NO_SURFACE);
190*8975f5c5SAndroid Build Coastguard Worker
191*8975f5c5SAndroid Build Coastguard Worker mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, contextAttributes);
192*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(mEglContext != EGL_NO_CONTEXT);
193*8975f5c5SAndroid Build Coastguard Worker
194*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(eglMakeCurrent(mEglDisplay, surface, surface, mEglContext) != EGL_FALSE);
195*8975f5c5SAndroid Build Coastguard Worker }
196*8975f5c5SAndroid Build Coastguard Worker
testTearDown()197*8975f5c5SAndroid Build Coastguard Worker void testTearDown() override
198*8975f5c5SAndroid Build Coastguard Worker {
199*8975f5c5SAndroid Build Coastguard Worker if (!mRoHelper.SupportedWindowsRelease())
200*8975f5c5SAndroid Build Coastguard Worker {
201*8975f5c5SAndroid Build Coastguard Worker return;
202*8975f5c5SAndroid Build Coastguard Worker }
203*8975f5c5SAndroid Build Coastguard Worker if (mEglDisplay != EGL_NO_DISPLAY)
204*8975f5c5SAndroid Build Coastguard Worker {
205*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglTerminate(mEglDisplay));
206*8975f5c5SAndroid Build Coastguard Worker mEglDisplay = EGL_NO_DISPLAY;
207*8975f5c5SAndroid Build Coastguard Worker }
208*8975f5c5SAndroid Build Coastguard Worker
209*8975f5c5SAndroid Build Coastguard Worker OSWindow::Delete(&mOSWindow);
210*8975f5c5SAndroid Build Coastguard Worker }
211*8975f5c5SAndroid Build Coastguard Worker
212*8975f5c5SAndroid Build Coastguard Worker OSWindow *mOSWindow;
213*8975f5c5SAndroid Build Coastguard Worker ComPtr<ICompositor> mCompositor;
214*8975f5c5SAndroid Build Coastguard Worker ComPtr<IDispatcherQueueController> mDispatcherController;
215*8975f5c5SAndroid Build Coastguard Worker ComPtr<ICompositionColorBrush> mColorBrush;
216*8975f5c5SAndroid Build Coastguard Worker ComPtr<IDesktopWindowTarget> mDesktopTarget;
217*8975f5c5SAndroid Build Coastguard Worker ComPtr<ISpriteVisual> mAngleHost;
218*8975f5c5SAndroid Build Coastguard Worker
219*8975f5c5SAndroid Build Coastguard Worker EGLDisplay mEglDisplay;
220*8975f5c5SAndroid Build Coastguard Worker EGLContext mEglContext;
221*8975f5c5SAndroid Build Coastguard Worker EGLConfig mEglConfig;
222*8975f5c5SAndroid Build Coastguard Worker rx::RoHelper mRoHelper;
223*8975f5c5SAndroid Build Coastguard Worker
224*8975f5c5SAndroid Build Coastguard Worker using _SetThreadDpiAwarenessContext =
225*8975f5c5SAndroid Build Coastguard Worker DPI_AWARENESS_CONTEXT WINAPI(DPI_AWARENESS_CONTEXT dpiContext);
226*8975f5c5SAndroid Build Coastguard Worker
227*8975f5c5SAndroid Build Coastguard Worker _SetThreadDpiAwarenessContext *mFpSetThreadDpiAwarenessContext;
228*8975f5c5SAndroid Build Coastguard Worker };
229*8975f5c5SAndroid Build Coastguard Worker
230*8975f5c5SAndroid Build Coastguard Worker // This tests that a surface created using a SpriteVisual as container has the expected dimensions
231*8975f5c5SAndroid Build Coastguard Worker // which should match the dimensions of the SpriteVisual passed in
TEST_P(EGLDirectCompositionTest,SurfaceSizeFromSpriteSize)232*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLDirectCompositionTest, SurfaceSizeFromSpriteSize)
233*8975f5c5SAndroid Build Coastguard Worker {
234*8975f5c5SAndroid Build Coastguard Worker // Only attempt this test when on Windows 10 1803+
235*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!mRoHelper.SupportedWindowsRelease());
236*8975f5c5SAndroid Build Coastguard Worker
237*8975f5c5SAndroid Build Coastguard Worker EGLSurface s{nullptr};
238*8975f5c5SAndroid Build Coastguard Worker CreateSurface(mAngleHost, s);
239*8975f5c5SAndroid Build Coastguard Worker
240*8975f5c5SAndroid Build Coastguard Worker EGLint surfacewidth = 0, surfaceheight = 0;
241*8975f5c5SAndroid Build Coastguard Worker eglQuerySurface(mEglDisplay, s, EGL_WIDTH, &surfacewidth);
242*8975f5c5SAndroid Build Coastguard Worker eglQuerySurface(mEglDisplay, s, EGL_HEIGHT, &surfaceheight);
243*8975f5c5SAndroid Build Coastguard Worker
244*8975f5c5SAndroid Build Coastguard Worker ComPtr<IVisual> angleVis;
245*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(mAngleHost.As(&angleVis)));
246*8975f5c5SAndroid Build Coastguard Worker
247*8975f5c5SAndroid Build Coastguard Worker ABI::Windows::Foundation::Numerics::Vector2 visualsize{0, 0};
248*8975f5c5SAndroid Build Coastguard Worker
249*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(SUCCEEDED(angleVis->get_Size(&visualsize)));
250*8975f5c5SAndroid Build Coastguard Worker
251*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(surfacewidth == static_cast<int>(visualsize.X));
252*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(surfaceheight == static_cast<int>(visualsize.Y));
253*8975f5c5SAndroid Build Coastguard Worker
254*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) !=
255*8975f5c5SAndroid Build Coastguard Worker EGL_FALSE);
256*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglDestroySurface(mEglDisplay, s));
257*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglDestroyContext(mEglDisplay, mEglContext));
258*8975f5c5SAndroid Build Coastguard Worker mEglContext = EGL_NO_CONTEXT;
259*8975f5c5SAndroid Build Coastguard Worker }
260*8975f5c5SAndroid Build Coastguard Worker
261*8975f5c5SAndroid Build Coastguard Worker // This tests that a WindowSurface can be created using a SpriteVisual as the containing window
262*8975f5c5SAndroid Build Coastguard Worker // and that pixels can be successfully rendered into the resulting WindowSurface
TEST_P(EGLDirectCompositionTest,RenderSolidColor)263*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLDirectCompositionTest, RenderSolidColor)
264*8975f5c5SAndroid Build Coastguard Worker {
265*8975f5c5SAndroid Build Coastguard Worker // Only attempt this test when on Windows 10 1803+
266*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!mRoHelper.SupportedWindowsRelease());
267*8975f5c5SAndroid Build Coastguard Worker
268*8975f5c5SAndroid Build Coastguard Worker EGLSurface s{nullptr};
269*8975f5c5SAndroid Build Coastguard Worker CreateSurface(mAngleHost, s);
270*8975f5c5SAndroid Build Coastguard Worker
271*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
272*8975f5c5SAndroid Build Coastguard Worker
273*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, WINDOWWIDTH, WINDOWHEIGHT);
274*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
275*8975f5c5SAndroid Build Coastguard Worker
276*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglSwapBuffers(mEglDisplay, s));
277*8975f5c5SAndroid Build Coastguard Worker
278*8975f5c5SAndroid Build Coastguard Worker // ensure user/DWM have a chance to paint the window and kick it to the top of the desktop
279*8975f5c5SAndroid Build Coastguard Worker // zorder before we attempt to sample
280*8975f5c5SAndroid Build Coastguard Worker angle::Sleep(200);
281*8975f5c5SAndroid Build Coastguard Worker mOSWindow->messageLoop();
282*8975f5c5SAndroid Build Coastguard Worker
283*8975f5c5SAndroid Build Coastguard Worker uint8_t *pixelBuffer = static_cast<uint8_t *>(malloc(WINDOWWIDTH * WINDOWHEIGHT * 4));
284*8975f5c5SAndroid Build Coastguard Worker ZeroMemory(pixelBuffer, WINDOWWIDTH * WINDOWHEIGHT * 4);
285*8975f5c5SAndroid Build Coastguard Worker
286*8975f5c5SAndroid Build Coastguard Worker // In order to accurately capture a bitmap, we need to temporarily shift into per-monitor DPI
287*8975f5c5SAndroid Build Coastguard Worker // mode in order to get the window offset from desktop correct
288*8975f5c5SAndroid Build Coastguard Worker auto previous = mFpSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
289*8975f5c5SAndroid Build Coastguard Worker bool success = mOSWindow->takeScreenshot(pixelBuffer);
290*8975f5c5SAndroid Build Coastguard Worker mFpSetThreadDpiAwarenessContext(previous);
291*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(success);
292*8975f5c5SAndroid Build Coastguard Worker
293*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4)] == 255);
294*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4) + 1] == 0);
295*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4) + 2] == 0);
296*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(pixelBuffer[(50 * 50 * 4) + 3] == 255);
297*8975f5c5SAndroid Build Coastguard Worker
298*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) !=
299*8975f5c5SAndroid Build Coastguard Worker EGL_FALSE);
300*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglDestroySurface(mEglDisplay, s));
301*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglDestroyContext(mEglDisplay, mEglContext));
302*8975f5c5SAndroid Build Coastguard Worker mEglContext = EGL_NO_CONTEXT;
303*8975f5c5SAndroid Build Coastguard Worker }
304*8975f5c5SAndroid Build Coastguard Worker
305*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLDirectCompositionTest, WithNoFixture(ES2_D3D11()));
306*8975f5c5SAndroid Build Coastguard Worker
307*8975f5c5SAndroid Build Coastguard Worker #endif // ANGLE_ENABLE_D3D11_COMPOSITOR_NATIVE_WINDOW
308