Path: blob/main_old/src/tests/egl_tests/EGLChooseConfigTest.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// EGLChooseConfigTest.cpp:6// Tests of proper default-value semantics for eglChooseConfig78#include <gtest/gtest.h>910#include "test_utils/ANGLETest.h"11#include "test_utils/angle_test_configs.h"12#include "util/EGLWindow.h"1314using namespace angle;1516namespace angle17{18class EGLChooseConfigTest : public ANGLETest19{20protected:21EGLChooseConfigTest() {}22};2324// Test that the EGL_COLOR_BUFFER_TYPE is defaulted to EGL_RGB_BUFFER25TEST_P(EGLChooseConfigTest, Defaults)26{27EGLDisplay display = getEGLWindow()->getDisplay();2829EGLint nConfigs = 0;30EGLint allConfigCount = 0;31ASSERT_EGL_TRUE(eglGetConfigs(display, nullptr, 0, &nConfigs));32ASSERT_NE(nConfigs, 0);3334std::vector<EGLConfig> allConfigs(nConfigs);35ASSERT_EGL_TRUE(eglGetConfigs(display, allConfigs.data(), nConfigs, &allConfigCount));36ASSERT_EQ(nConfigs, allConfigCount);3738// Choose configs that have the default attribute values:39const EGLint defaultConfigAttributes[] = {EGL_NONE};40EGLint defaultConfigCount;41std::vector<EGLConfig> defaultConfigs(allConfigCount);42ASSERT_EGL_TRUE(eglChooseConfig(display, defaultConfigAttributes, defaultConfigs.data(),43defaultConfigs.size(), &defaultConfigCount));44ASSERT_EGL_SUCCESS();45ASSERT_LE(defaultConfigCount, allConfigCount);46defaultConfigs.resize(defaultConfigCount);4748// Check that the default configs all have the default attribute values we care about:49for (EGLConfig config : defaultConfigs)50{51EGLint colorBufferType, level, renderableType, surfaceType, transparentType;52EGLint colorComponentType;5354eglGetConfigAttrib(display, config, EGL_COLOR_BUFFER_TYPE, &colorBufferType);55ASSERT_EQ(colorBufferType, EGL_RGB_BUFFER);5657eglGetConfigAttrib(display, config, EGL_LEVEL, &level);58ASSERT_EQ(level, 0);5960eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType);61ASSERT_EQ(renderableType & EGL_OPENGL_ES_BIT, EGL_OPENGL_ES_BIT);6263eglGetConfigAttrib(display, config, EGL_SURFACE_TYPE, &surfaceType);64ASSERT_EQ(surfaceType & EGL_WINDOW_BIT, EGL_WINDOW_BIT);6566eglGetConfigAttrib(display, config, EGL_TRANSPARENT_TYPE, &transparentType);67ASSERT_EQ(transparentType, EGL_NONE);6869if (IsEGLDisplayExtensionEnabled(display, "EGL_EXT_pixel_format_float"))70{71eglGetConfigAttrib(display, config, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType);72ASSERT_EQ(colorComponentType, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT);73}74}7576// Check that all of the configs that have the default attribute values are are defaultConfigs,77// and all that don't aren't:78for (EGLConfig config : allConfigs)79{80EGLint colorBufferType, level, renderableType, surfaceType, transparentType;81EGLint colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;8283eglGetConfigAttrib(display, config, EGL_COLOR_BUFFER_TYPE, &colorBufferType);84eglGetConfigAttrib(display, config, EGL_LEVEL, &level);85eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType);86eglGetConfigAttrib(display, config, EGL_SURFACE_TYPE, &surfaceType);87eglGetConfigAttrib(display, config, EGL_TRANSPARENT_TYPE, &transparentType);88if (IsEGLDisplayExtensionEnabled(display, "EGL_EXT_pixel_format_float"))89{90eglGetConfigAttrib(display, config, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType);91}9293bool isADefault =94((colorBufferType == EGL_RGB_BUFFER) && (level == 0) &&95((renderableType & EGL_OPENGL_ES_BIT) == EGL_OPENGL_ES_BIT) &&96((surfaceType & EGL_WINDOW_BIT) == EGL_WINDOW_BIT) && (transparentType == EGL_NONE) &&97(colorComponentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT));98EGLint thisConfigID;99eglGetConfigAttrib(display, config, EGL_CONFIG_ID, &thisConfigID);100bool foundInDefaultConfigs = false;101// Attempt to find this config ID in defaultConfigs:102for (EGLConfig defaultConfig : defaultConfigs)103{104EGLint defaultConfigID;105eglGetConfigAttrib(display, defaultConfig, EGL_CONFIG_ID, &defaultConfigID);106if (defaultConfigID == thisConfigID)107{108foundInDefaultConfigs = true;109}110}111ASSERT_EQ(isADefault, foundInDefaultConfigs);112}113}114115} // namespace angle116117ANGLE_INSTANTIATE_TEST(EGLChooseConfigTest,118ES2_D3D11(),119ES2_D3D9(),120ES2_METAL(),121ES2_OPENGL(),122ES2_OPENGLES(),123ES2_VULKAN());124125126