Path: blob/main_old/src/tests/egl_tests/EGLAndroidFrameBufferTargetTest.cpp
1693 views
//1// Copyright 2019 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// EGLAndroidFrameBufferTargetTest.cpp:6// This test verifies the extension EGL_ANDROID_framebuffer_target7// 1. When the EGLFRAME_BUFFER_TARGET_ANDROID attribute is used with eglChooseConfig8// It should match with configs according to Config selection rules and the extension9//1011#include <gtest/gtest.h>1213#include "common/string_utils.h"14#include "test_utils/ANGLETest.h"1516using namespace angle;1718class EGLAndroidFrameBufferTargetTest : public ANGLETest19{20protected:21EGLAndroidFrameBufferTargetTest() {}2223void testSetUp() override24{25mDisplay = getEGLWindow()->getDisplay();26ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);27}2829EGLDisplay mDisplay = EGL_NO_DISPLAY;30};3132namespace33{34EGLint GetAttrib(EGLDisplay display, EGLConfig config, EGLint attrib)35{36EGLint value = 0;37EXPECT_EGL_TRUE(eglGetConfigAttrib(display, config, attrib, &value));38return value;39}40} // namespace4142// Verify config matching is working.43TEST_P(EGLAndroidFrameBufferTargetTest, MatchFramebufferTargetConfigs)44{45ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANDROID_framebuffer_target"));4647// Get all the configs48EGLint count;49EXPECT_EGL_TRUE(eglGetConfigs(mDisplay, nullptr, 0, &count));50EXPECT_TRUE(count > 0);51std::vector<EGLConfig> configs(count);52EXPECT_EGL_TRUE(eglGetConfigs(mDisplay, configs.data(), count, &count));53ASSERT_EQ(configs.size(), static_cast<size_t>(count));5455// Filter out all non-framebuffertarget configs56std::vector<EGLConfig> filterConfigs(0);57for (auto config : configs)58{59if (GetAttrib(mDisplay, config, EGL_FRAMEBUFFER_TARGET_ANDROID) == EGL_TRUE)60{61filterConfigs.push_back(config);62}63}64// sort configs by increaing ID65std::sort(filterConfigs.begin(), filterConfigs.end(), [this](EGLConfig a, EGLConfig b) -> bool {66return GetAttrib(mDisplay, a, EGL_CONFIG_ID) < GetAttrib(mDisplay, b, EGL_CONFIG_ID);67});6869// Now get configs that selection algorithm identifies70EGLint attribs[] = {EGL_FRAMEBUFFER_TARGET_ANDROID,71EGL_TRUE,72EGL_COLOR_BUFFER_TYPE,73EGL_DONT_CARE,74EGL_COLOR_COMPONENT_TYPE_EXT,75EGL_DONT_CARE,76EGL_NONE};77EXPECT_EGL_TRUE(eglChooseConfig(mDisplay, attribs, nullptr, 0, &count));78std::vector<EGLConfig> matchConfigs(count);79EXPECT_EGL_TRUE(eglChooseConfig(mDisplay, attribs, matchConfigs.data(), count, &count));80matchConfigs.resize(count);81// sort configs by increasing ID82std::sort(matchConfigs.begin(), matchConfigs.end(), [this](EGLConfig a, EGLConfig b) -> bool {83return GetAttrib(mDisplay, a, EGL_CONFIG_ID) < GetAttrib(mDisplay, b, EGL_CONFIG_ID);84});8586EXPECT_EQ(matchConfigs, filterConfigs) << "Filtered configs do not match selection Configs";87}8889ANGLE_INSTANTIATE_TEST(EGLAndroidFrameBufferTargetTest, ES2_VULKAN(), ES3_VULKAN());9091// This test suite is not instantiated on some OSes.92GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLAndroidFrameBufferTargetTest);939495