Path: blob/main_old/src/libANGLE/Config_unittest.cpp
1693 views
//1// Copyright 2014 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//56#include "gmock/gmock.h"7#include "gtest/gtest.h"89#include "libANGLE/AttributeMap.h"10#include "libANGLE/Config.h"1112// Create a generic, valid EGL config that can be modified to test sorting and13// filtering routines14static egl::Config GenerateGenericConfig()15{16egl::Config config;1718config.bufferSize = 24;19config.redSize = 8;20config.greenSize = 8;21config.blueSize = 8;22config.luminanceSize = 0;23config.alphaSize = 8;24config.alphaMaskSize = 0;25config.bindToTextureRGB = EGL_TRUE;26config.bindToTextureRGBA = EGL_TRUE;27config.colorBufferType = EGL_RGB_BUFFER;28config.configCaveat = EGL_NONE;29config.configID = 0;30config.conformant = EGL_OPENGL_ES2_BIT;31config.depthSize = 24;32config.level = 0;33config.matchNativePixmap = EGL_NONE;34config.maxPBufferWidth = 1024;35config.maxPBufferHeight = 1024;36config.maxPBufferPixels = config.maxPBufferWidth * config.maxPBufferWidth;37config.maxSwapInterval = 0;38config.minSwapInterval = 4;39config.nativeRenderable = EGL_OPENGL_ES2_BIT;40config.nativeVisualID = 0;41config.nativeVisualType = 0;42config.renderableType = EGL_FALSE;43config.sampleBuffers = 0;44config.samples = 0;45config.stencilSize = 8;46config.surfaceType = EGL_PBUFFER_BIT | EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT;47config.transparentType = EGL_NONE;48config.transparentRedValue = 0;49config.transparentGreenValue = 0;50config.transparentBlueValue = 0;5152return config;53}5455static std::vector<egl::Config> GenerateUniqueConfigs(size_t count)56{57std::vector<egl::Config> configs;5859for (size_t i = 0; i < count; i++)60{61egl::Config config = GenerateGenericConfig();62config.samples = static_cast<EGLint>(i);63configs.push_back(config);64}6566return configs;67}6869// Add unique configs to a ConfigSet and expect that the size of the70// set is equal to the number of configs added.71TEST(ConfigSetTest, Size)72{73egl::ConfigSet set;7475std::vector<egl::Config> uniqueConfigs = GenerateUniqueConfigs(16);76for (size_t i = 0; i < uniqueConfigs.size(); i++)77{78set.add(uniqueConfigs[i]);79EXPECT_EQ(set.size(), i + 1);80}81}8283// [EGL 1.5] section 3.4:84// EGL_CONFIG_ID is a unique integer identifying different EGLConfigs. Configuration IDs85// must be small positive integers starting at 1 and ID assignment should be compact;86// that is, if there are N EGLConfigs defined by the EGL implementation, their87// configuration IDs should be in the range [1, N].88TEST(ConfigSetTest, IDs)89{90egl::ConfigSet set;9192std::set<EGLint> ids;9394std::vector<egl::Config> uniqueConfigs = GenerateUniqueConfigs(16);95for (size_t i = 0; i < uniqueConfigs.size(); i++)96{97EGLint id = set.add(uniqueConfigs[i]);9899// Check that the config that was inserted has the ID that was returned100// by ConfigSet::add101EXPECT_EQ(id, set.get(id).configID);102103ids.insert(id);104}105106// Verify configCount unique IDs107EXPECT_EQ(ids.size(), set.size());108109// Check that there are no gaps and the IDs are in the range [1, N].110EXPECT_EQ(*std::min_element(ids.begin(), ids.end()), 1);111EXPECT_EQ(*std::max_element(ids.begin(), ids.end()), static_cast<EGLint>(set.size()));112}113114TEST(ConfigSetTest, Filtering_BitSizes)115{116egl::ConfigSet set;117118struct VariableConfigBitSize119{120EGLint Name;121EGLint(egl::Config::*ConfigMember);122};123124VariableConfigBitSize testMembers[] = {125{EGL_RED_SIZE, &egl::Config::redSize}, {EGL_GREEN_SIZE, &egl::Config::greenSize},126{EGL_BLUE_SIZE, &egl::Config::blueSize}, {EGL_ALPHA_SIZE, &egl::Config::alphaSize},127{EGL_DEPTH_SIZE, &egl::Config::depthSize}, {EGL_STENCIL_SIZE, &egl::Config::stencilSize},128};129130// Generate configsPerType configs with varying bit sizes of each type131size_t configsPerType = 4;132for (size_t i = 0; i < ArraySize(testMembers); i++)133{134for (size_t j = 0; j < configsPerType; j++)135{136egl::Config config = GenerateGenericConfig();137138// Set all the other tested members of this config to 0139for (size_t k = 0; k < ArraySize(testMembers); k++)140{141config.*(testMembers[k].ConfigMember) = 0;142}143144// Set the tested member of this config to i so it ranges from145// [1, configsPerType]146config.*(testMembers[i].ConfigMember) = static_cast<EGLint>(j) + 1;147148set.add(config);149}150}151152// for each tested member, filter by it's type and verify that the correct number153// of results are returned154for (size_t i = 0; i < ArraySize(testMembers); i++)155{156// Start with a filter of 1 to not grab the other members157for (EGLint j = 0; j < static_cast<EGLint>(configsPerType); j++)158{159egl::AttributeMap filter;160filter.insert(testMembers[i].Name, j + 1);161162std::vector<const egl::Config *> filteredConfigs = set.filter(filter);163164EXPECT_EQ(filteredConfigs.size(), configsPerType - j);165}166}167}168169// Verify the sorting, [EGL 1.5] section 3.4.1.2 pg 30:170// [configs are sorted] by larger total number of color bits (for an RGB171// color buffer this is the sum of EGL_RED_SIZE, EGL_GREEN_SIZE, EGL_BLUE_SIZE,172// and EGL_ALPHA_SIZE; for a luminance color buffer, the sum of EGL_LUMINANCE_SIZE173// and EGL_ALPHA_SIZE).If the requested number of bits in attrib list for a174// particular color component is 0 or EGL_DONT_CARE, then the number of bits175// for that component is not considered.176TEST(ConfigSetTest, Sorting_BitSizes)177{178egl::ConfigSet set;179size_t testConfigCount = 64;180for (size_t i = 0; i < testConfigCount; i++)181{182egl::Config config = GenerateGenericConfig();183184// Give random-ish bit sizes to the config185config.redSize = (i * 2) % 3;186config.greenSize = (i + 5) % 7;187config.blueSize = (i + 7) % 11;188config.alphaSize = (i + 13) % 17;189190set.add(config);191}192193egl::AttributeMap greaterThan1BitFilter;194greaterThan1BitFilter.insert(EGL_RED_SIZE, 1);195greaterThan1BitFilter.insert(EGL_GREEN_SIZE, 1);196greaterThan1BitFilter.insert(EGL_BLUE_SIZE, 1);197greaterThan1BitFilter.insert(EGL_ALPHA_SIZE, 1);198199std::vector<const egl::Config *> filteredConfigs = set.filter(greaterThan1BitFilter);200for (size_t i = 1; i < filteredConfigs.size(); i++)201{202const egl::Config &prevConfig = *filteredConfigs[i - 1];203size_t prevBitCount =204prevConfig.redSize + prevConfig.greenSize + prevConfig.blueSize + prevConfig.alphaSize;205206const egl::Config &curConfig = *filteredConfigs[i];207size_t curBitCount =208curConfig.redSize + curConfig.greenSize + curConfig.blueSize + curConfig.alphaSize;209210EXPECT_GE(prevBitCount, curBitCount);211}212}213214215