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