1 //
2 // Copyright 2019 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 // EGLAndroidFrameBufferTargetTest.cpp:
7 // This test verifies the extension EGL_ANDROID_framebuffer_target
8 // 1. When the EGLFRAME_BUFFER_TARGET_ANDROID attribute is used with eglChooseConfig
9 // It should match with configs according to Config selection rules and the extension
10 //
11
12 #include <gtest/gtest.h>
13
14 #include "common/string_utils.h"
15 #include "test_utils/ANGLETest.h"
16
17 using namespace angle;
18
19 class EGLAndroidFrameBufferTargetTest : public ANGLETest
20 {
21 protected:
EGLAndroidFrameBufferTargetTest()22 EGLAndroidFrameBufferTargetTest() {}
23
testSetUp()24 void testSetUp() override
25 {
26 mDisplay = getEGLWindow()->getDisplay();
27 ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);
28 }
29
30 EGLDisplay mDisplay = EGL_NO_DISPLAY;
31 };
32
33 namespace
34 {
GetAttrib(EGLDisplay display,EGLConfig config,EGLint attrib)35 EGLint GetAttrib(EGLDisplay display, EGLConfig config, EGLint attrib)
36 {
37 EGLint value = 0;
38 EXPECT_EGL_TRUE(eglGetConfigAttrib(display, config, attrib, &value));
39 return value;
40 }
41 } // namespace
42
43 // Verify config matching is working.
TEST_P(EGLAndroidFrameBufferTargetTest,MatchFramebufferTargetConfigs)44 TEST_P(EGLAndroidFrameBufferTargetTest, MatchFramebufferTargetConfigs)
45 {
46 ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANDROID_framebuffer_target"));
47
48 // Get all the configs
49 EGLint count;
50 EXPECT_EGL_TRUE(eglGetConfigs(mDisplay, nullptr, 0, &count));
51 EXPECT_TRUE(count > 0);
52 std::vector<EGLConfig> configs(count);
53 EXPECT_EGL_TRUE(eglGetConfigs(mDisplay, configs.data(), count, &count));
54 ASSERT_EQ(configs.size(), static_cast<size_t>(count));
55
56 // Filter out all non-framebuffertarget configs
57 std::vector<EGLConfig> filterConfigs(0);
58 for (auto config : configs)
59 {
60 if (GetAttrib(mDisplay, config, EGL_FRAMEBUFFER_TARGET_ANDROID) == EGL_TRUE)
61 {
62 filterConfigs.push_back(config);
63 }
64 }
65 // sort configs by increaing ID
66 std::sort(filterConfigs.begin(), filterConfigs.end(), [this](EGLConfig a, EGLConfig b) -> bool {
67 return GetAttrib(mDisplay, a, EGL_CONFIG_ID) < GetAttrib(mDisplay, b, EGL_CONFIG_ID);
68 });
69
70 // Now get configs that selection algorithm identifies
71 EGLint attribs[] = {EGL_FRAMEBUFFER_TARGET_ANDROID,
72 EGL_TRUE,
73 EGL_COLOR_BUFFER_TYPE,
74 EGL_DONT_CARE,
75 EGL_COLOR_COMPONENT_TYPE_EXT,
76 EGL_DONT_CARE,
77 EGL_NONE};
78 EXPECT_EGL_TRUE(eglChooseConfig(mDisplay, attribs, nullptr, 0, &count));
79 std::vector<EGLConfig> matchConfigs(count);
80 EXPECT_EGL_TRUE(eglChooseConfig(mDisplay, attribs, matchConfigs.data(), count, &count));
81 matchConfigs.resize(count);
82 // sort configs by increasing ID
83 std::sort(matchConfigs.begin(), matchConfigs.end(), [this](EGLConfig a, EGLConfig b) -> bool {
84 return GetAttrib(mDisplay, a, EGL_CONFIG_ID) < GetAttrib(mDisplay, b, EGL_CONFIG_ID);
85 });
86
87 EXPECT_EQ(matchConfigs, filterConfigs) << "Filtered configs do not match selection Configs";
88 }
89
90 ANGLE_INSTANTIATE_TEST(EGLAndroidFrameBufferTargetTest, ES2_VULKAN(), ES3_VULKAN());
91