Hash :
db8e5617
Author :
Date :
2024-10-23T15:21:33
Reland "Add check for some EGL API attrbute values" This is a reland of commit 9481eb625b358897583f8adeca5fc520f8c215ae Original change's description: > Add check for some EGL API attrbute values > > EGL validation in ANGLE lacks of some error handlings mentioned > in EGL spec. Those error handlings are added, and we need to > make sure angle end2end tests are not influenced. > > Bug: angleproject:375528200 > Change-Id: Ic0686d9ccc70e18b0cf3449184452771c77c06b7 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6034532 > Reviewed-by: Charlie Lao <cclao@google.com> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Bug: angleproject:375528200 Change-Id: I6db890a95825156848d7da8ebc15f7e30b0902ba Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6088519 Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// EGLChooseConfigTest.cpp:
// Tests of proper default-value semantics for eglChooseConfig
#include <gtest/gtest.h>
#include "test_utils/ANGLETest.h"
#include "test_utils/angle_test_configs.h"
#include "util/EGLWindow.h"
using namespace angle;
namespace angle
{
class EGLChooseConfigTest : public ANGLETest<>
{
protected:
EGLChooseConfigTest() {}
};
// Test that the EGL_COLOR_BUFFER_TYPE is defaulted to EGL_RGB_BUFFER
TEST_P(EGLChooseConfigTest, Defaults)
{
EGLDisplay display = getEGLWindow()->getDisplay();
EGLint nConfigs = 0;
EGLint allConfigCount = 0;
ASSERT_EGL_TRUE(eglGetConfigs(display, nullptr, 0, &nConfigs));
ASSERT_NE(nConfigs, 0);
std::vector<EGLConfig> allConfigs(nConfigs);
ASSERT_EGL_TRUE(eglGetConfigs(display, allConfigs.data(), nConfigs, &allConfigCount));
ASSERT_EQ(nConfigs, allConfigCount);
// Choose configs that have the default attribute values:
const EGLint defaultConfigAttributes[] = {EGL_NONE};
EGLint defaultConfigCount;
std::vector<EGLConfig> defaultConfigs(allConfigCount);
ASSERT_EGL_TRUE(eglChooseConfig(display, defaultConfigAttributes, defaultConfigs.data(),
defaultConfigs.size(), &defaultConfigCount));
ASSERT_EGL_SUCCESS();
ASSERT_LE(defaultConfigCount, allConfigCount);
defaultConfigs.resize(defaultConfigCount);
// Check that the default configs all have the default attribute values we care about:
for (EGLConfig config : defaultConfigs)
{
EGLint colorBufferType, level, renderableType, surfaceType, transparentType;
EGLint colorComponentType;
eglGetConfigAttrib(display, config, EGL_COLOR_BUFFER_TYPE, &colorBufferType);
ASSERT_EQ(colorBufferType, EGL_RGB_BUFFER);
eglGetConfigAttrib(display, config, EGL_LEVEL, &level);
ASSERT_EQ(level, 0);
eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType);
ASSERT_EQ(renderableType & EGL_OPENGL_ES_BIT, EGL_OPENGL_ES_BIT);
eglGetConfigAttrib(display, config, EGL_SURFACE_TYPE, &surfaceType);
ASSERT_EQ(surfaceType & EGL_WINDOW_BIT, EGL_WINDOW_BIT);
eglGetConfigAttrib(display, config, EGL_TRANSPARENT_TYPE, &transparentType);
ASSERT_EQ(transparentType, EGL_NONE);
if (IsEGLDisplayExtensionEnabled(display, "EGL_EXT_pixel_format_float"))
{
eglGetConfigAttrib(display, config, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType);
ASSERT_EQ(colorComponentType, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT);
}
}
// Check that all of the configs that have the default attribute values are are defaultConfigs,
// and all that don't aren't:
for (EGLConfig config : allConfigs)
{
EGLint colorBufferType, level, renderableType, surfaceType, transparentType;
EGLint colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
eglGetConfigAttrib(display, config, EGL_COLOR_BUFFER_TYPE, &colorBufferType);
eglGetConfigAttrib(display, config, EGL_LEVEL, &level);
eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType);
eglGetConfigAttrib(display, config, EGL_SURFACE_TYPE, &surfaceType);
eglGetConfigAttrib(display, config, EGL_TRANSPARENT_TYPE, &transparentType);
if (IsEGLDisplayExtensionEnabled(display, "EGL_EXT_pixel_format_float"))
{
eglGetConfigAttrib(display, config, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType);
}
bool isADefault =
((colorBufferType == EGL_RGB_BUFFER) && (level == 0) &&
((renderableType & EGL_OPENGL_ES_BIT) == EGL_OPENGL_ES_BIT) &&
((surfaceType & EGL_WINDOW_BIT) == EGL_WINDOW_BIT) && (transparentType == EGL_NONE) &&
(colorComponentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT));
EGLint thisConfigID;
eglGetConfigAttrib(display, config, EGL_CONFIG_ID, &thisConfigID);
bool foundInDefaultConfigs = false;
// Attempt to find this config ID in defaultConfigs:
for (EGLConfig defaultConfig : defaultConfigs)
{
EGLint defaultConfigID;
eglGetConfigAttrib(display, defaultConfig, EGL_CONFIG_ID, &defaultConfigID);
if (defaultConfigID == thisConfigID)
{
foundInDefaultConfigs = true;
}
}
ASSERT_EQ(isADefault, foundInDefaultConfigs);
}
}
// Test the validation errors for bad parameters for eglChooseConfig
TEST_P(EGLChooseConfigTest, NegativeValidationBadAttributes)
{
EGLDisplay display = getEGLWindow()->getDisplay();
// Choose configs using invalid attributes:
const EGLint invalidConfigAttributeList[][3] = {
{EGL_CONFIG_CAVEAT, 0, EGL_NONE},
{EGL_SURFACE_TYPE, ~EGL_VG_COLORSPACE_LINEAR_BIT, EGL_NONE},
{EGL_CONFORMANT, (EGL_OPENGL_ES_BIT | 0x0020), EGL_NONE},
{EGL_RENDERABLE_TYPE, (EGL_OPENGL_ES_BIT | 0x0020), EGL_NONE},
};
EGLint configCount;
EGLConfig config;
for (size_t i = 0; i < 4; i++)
{
ASSERT_EGL_FALSE(
eglChooseConfig(display, &invalidConfigAttributeList[i][0], &config, 1, &configCount));
ASSERT_EGL_ERROR(EGL_BAD_ATTRIBUTE);
}
}
} // namespace angle
ANGLE_INSTANTIATE_TEST(EGLChooseConfigTest,
ES2_D3D11(),
ES2_D3D9(),
ES2_METAL(),
ES2_OPENGL(),
ES2_OPENGLES(),
ES2_VULKAN());