1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // EGLDisplayLuidTest.cpp:
7 //   Tests for the EGL_ANGLE_platform_angle_d3d_luid extension.
8 //
9 
10 #include "test_utils/ANGLETest.h"
11 
12 using namespace angle;
13 
14 class EGLDisplayLuidTest : public ANGLETest
15 {
16   protected:
EGLDisplayLuidTest()17     EGLDisplayLuidTest() : mDisplay(EGL_NO_DISPLAY) {}
18 
testTearDown()19     void testTearDown() override
20     {
21         if (mDisplay != EGL_NO_DISPLAY)
22         {
23             EXPECT_EGL_TRUE(eglTerminate(mDisplay));
24             EXPECT_EGL_SUCCESS();
25         }
26     }
27 
testInvalidAttribs(const EGLint displayAttribs[])28     void testInvalidAttribs(const EGLint displayAttribs[])
29     {
30         EXPECT_EQ(
31             eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttribs),
32             EGL_NO_DISPLAY);
33         EXPECT_EGL_ERROR(EGL_BAD_ATTRIBUTE);
34     }
35 
testValidAttribs(const EGLint displayAttribs[])36     void testValidAttribs(const EGLint displayAttribs[])
37     {
38         mDisplay =
39             eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttribs);
40 
41         EXPECT_EGL_SUCCESS();
42         EXPECT_NE(mDisplay, EGL_NO_DISPLAY);
43 
44         // eglInitialize should succeed even if the LUID doesn't match an actual
45         // adapter on the system. The behavior in this case is that the default
46         // adapter is used.
47         EXPECT_EGL_TRUE(eglInitialize(mDisplay, nullptr, nullptr));
48         EXPECT_EGL_SUCCESS();
49     }
50 
51   private:
52     EGLDisplay mDisplay;
53 };
54 
55 // EGL_ANGLE_platform_angle_d3d_luid is only supported on D3D11. Verify failure
56 // if D3D9 is specified in the attributes.
TEST_P(EGLDisplayLuidTest,D3D9Failure)57 TEST_P(EGLDisplayLuidTest, D3D9Failure)
58 {
59     EGLint displayAttribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE,
60                                EGL_PLATFORM_ANGLE_D3D_LUID_HIGH_ANGLE, 1, EGL_NONE};
61     testInvalidAttribs(displayAttribs);
62 }
63 
64 // Verify failure if the specified LUID is zero.
TEST_P(EGLDisplayLuidTest,ZeroLuidFailure)65 TEST_P(EGLDisplayLuidTest, ZeroLuidFailure)
66 {
67     EGLint displayAttribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE,
68                                EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
69                                EGL_PLATFORM_ANGLE_D3D_LUID_HIGH_ANGLE,
70                                0,
71                                EGL_PLATFORM_ANGLE_D3D_LUID_LOW_ANGLE,
72                                0,
73                                EGL_NONE};
74     testInvalidAttribs(displayAttribs);
75 }
76 
TEST_P(EGLDisplayLuidTest,D3D11)77 TEST_P(EGLDisplayLuidTest, D3D11)
78 {
79     EGLint displayAttribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
80                                EGL_PLATFORM_ANGLE_D3D_LUID_HIGH_ANGLE, 1, EGL_NONE};
81     testValidAttribs(displayAttribs);
82 }
83 
84 ANGLE_INSTANTIATE_TEST(EGLDisplayLuidTest, WithNoFixture(ES2_D3D9()), WithNoFixture(ES2_D3D11()));
85