daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Config.cpp: Implements the egl::Config class, describing the format, type |
| 8 | // and size for an egl::Surface. Implements EGLConfig and related functionality. |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 9 | // [EGL 1.5] section 3.4 page 19. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 10 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 11 | #include "libANGLE/Config.h" |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 12 | #include "libANGLE/AttributeMap.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 13 | |
| 14 | #include <algorithm> |
| 15 | #include <vector> |
| 16 | |
Jamie Madill | f51639a | 2014-06-25 16:04:57 -0400 | [diff] [blame] | 17 | #include "angle_gl.h" |
shannon.woods%transgaming.com@gtempaccount.com | dcf33d5 | 2013-04-13 03:33:11 +0000 | [diff] [blame] | 18 | #include <EGL/eglext.h> |
daniel@transgaming.com | 106e1f7 | 2012-10-31 18:38:36 +0000 | [diff] [blame] | 19 | |
alokp@chromium.org | ea0e1af | 2010-03-22 19:33:14 +0000 | [diff] [blame] | 20 | #include "common/debug.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 22 | namespace egl |
| 23 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 24 | |
| 25 | Config::Config() |
Geoff Lang | f21a108 | 2015-01-09 14:41:27 -0500 | [diff] [blame] | 26 | : renderTargetFormat(GL_NONE), |
| 27 | depthStencilFormat(GL_NONE), |
| 28 | bufferSize(0), |
| 29 | redSize(0), |
| 30 | greenSize(0), |
| 31 | blueSize(0), |
| 32 | luminanceSize(0), |
| 33 | alphaSize(0), |
| 34 | alphaMaskSize(0), |
| 35 | bindToTextureRGB(EGL_FALSE), |
| 36 | bindToTextureRGBA(EGL_FALSE), |
| 37 | colorBufferType(EGL_NONE), |
| 38 | configCaveat(EGL_NONE), |
| 39 | configID(0), |
| 40 | conformant(0), |
| 41 | depthSize(0), |
| 42 | level(0), |
| 43 | matchNativePixmap(EGL_FALSE), |
| 44 | maxPBufferWidth(0), |
| 45 | maxPBufferHeight(0), |
| 46 | maxPBufferPixels(0), |
| 47 | maxSwapInterval(0), |
| 48 | minSwapInterval(0), |
| 49 | nativeRenderable(EGL_FALSE), |
| 50 | nativeVisualID(0), |
| 51 | nativeVisualType(0), |
| 52 | renderableType(0), |
| 53 | sampleBuffers(0), |
| 54 | samples(0), |
| 55 | stencilSize(0), |
| 56 | surfaceType(0), |
| 57 | transparentType(EGL_NONE), |
| 58 | transparentRedValue(0), |
| 59 | transparentGreenValue(0), |
Geoff Lang | 7f448b5 | 2015-12-16 13:31:57 -0500 | [diff] [blame] | 60 | transparentBlueValue(0), |
Geoff Lang | c5a2a17 | 2017-01-13 15:55:07 -0500 | [diff] [blame] | 61 | optimalOrientation(0), |
| 62 | colorComponentType(EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 66 | EGLint ConfigSet::add(const Config &config) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 67 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 68 | // Set the config's ID to a small number that starts at 1 ([EGL 1.5] section 3.4) |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 69 | EGLint id = static_cast<EGLint>(mConfigs.size()) + 1; |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 70 | |
| 71 | Config copyConfig(config); |
Geoff Lang | c223dc6 | 2015-01-09 13:10:01 -0500 | [diff] [blame] | 72 | copyConfig.configID = id; |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 73 | mConfigs.insert(std::make_pair(id, copyConfig)); |
| 74 | |
| 75 | return id; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 78 | const Config &ConfigSet::get(EGLint id) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 79 | { |
Jamie Madill | 73edef0 | 2015-02-17 18:58:21 -0500 | [diff] [blame] | 80 | ASSERT(mConfigs.find(id) != mConfigs.end()); |
| 81 | return mConfigs.find(id)->second; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 84 | void ConfigSet::clear() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 85 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 86 | mConfigs.clear(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 87 | } |
| 88 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 89 | size_t ConfigSet::size() const |
| 90 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 91 | return mConfigs.size(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 94 | bool ConfigSet::contains(const Config *config) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 95 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 96 | for (auto i = mConfigs.begin(); i != mConfigs.end(); i++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 97 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 98 | const Config &item = i->second; |
| 99 | if (config == &item) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 100 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 101 | return true; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | // Function object used by STL sorting routines for ordering Configs according to [EGL 1.5] section 3.4.1.2 page 28. |
| 109 | class ConfigSorter |
| 110 | { |
| 111 | public: |
| 112 | explicit ConfigSorter(const AttributeMap &attributeMap) |
Jamie Madill | 5659619 | 2015-03-19 10:23:13 -0400 | [diff] [blame] | 113 | : mWantRed(false), |
| 114 | mWantGreen(false), |
| 115 | mWantBlue(false), |
| 116 | mWantAlpha(false), |
| 117 | mWantLuminance(false) |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 118 | { |
| 119 | scanForWantedComponents(attributeMap); |
| 120 | } |
| 121 | |
| 122 | bool operator()(const Config *x, const Config *y) const |
| 123 | { |
| 124 | return (*this)(*x, *y); |
| 125 | } |
| 126 | |
| 127 | bool operator()(const Config &x, const Config &y) const |
| 128 | { |
| 129 | #define SORT(attribute) \ |
| 130 | if (x.attribute != y.attribute) \ |
| 131 | { \ |
| 132 | return x.attribute < y.attribute; \ |
| 133 | } |
| 134 | |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 135 | static_assert(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG, "Unexpected EGL enum value."); |
Geoff Lang | c223dc6 | 2015-01-09 13:10:01 -0500 | [diff] [blame] | 136 | SORT(configCaveat); |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 137 | |
Geoff Lang | c5a2a17 | 2017-01-13 15:55:07 -0500 | [diff] [blame] | 138 | static_assert(EGL_COLOR_COMPONENT_TYPE_FIXED_EXT < EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT, |
| 139 | "Unexpected order of EGL enums."); |
| 140 | SORT(colorComponentType); |
| 141 | |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 142 | static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "Unexpected EGL enum value."); |
Geoff Lang | c223dc6 | 2015-01-09 13:10:01 -0500 | [diff] [blame] | 143 | SORT(colorBufferType); |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 144 | |
| 145 | // By larger total number of color bits, only considering those that are requested to be > 0. |
| 146 | EGLint xComponentsSize = wantedComponentsSize(x); |
| 147 | EGLint yComponentsSize = wantedComponentsSize(y); |
| 148 | if (xComponentsSize != yComponentsSize) |
| 149 | { |
| 150 | return xComponentsSize > yComponentsSize; |
| 151 | } |
| 152 | |
Geoff Lang | c223dc6 | 2015-01-09 13:10:01 -0500 | [diff] [blame] | 153 | SORT(bufferSize); |
| 154 | SORT(sampleBuffers); |
| 155 | SORT(samples); |
| 156 | SORT(depthSize); |
| 157 | SORT(stencilSize); |
| 158 | SORT(alphaMaskSize); |
| 159 | SORT(nativeVisualType); |
| 160 | SORT(configID); |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 161 | |
| 162 | #undef SORT |
| 163 | |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | private: |
| 168 | void scanForWantedComponents(const AttributeMap &attributeMap) |
| 169 | { |
| 170 | // [EGL 1.5] section 3.4.1.2 page 30 |
| 171 | // Sorting rule #3: by larger total number of color bits, not considering |
| 172 | // components that are 0 or don't-care. |
| 173 | for (auto attribIter = attributeMap.begin(); attribIter != attributeMap.end(); attribIter++) |
| 174 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 175 | EGLAttrib attributeKey = attribIter->first; |
| 176 | EGLAttrib attributeValue = attribIter->second; |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 177 | if (attributeKey != 0 && attributeValue != EGL_DONT_CARE) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 178 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 179 | switch (attributeKey) |
| 180 | { |
| 181 | case EGL_RED_SIZE: mWantRed = true; break; |
| 182 | case EGL_GREEN_SIZE: mWantGreen = true; break; |
| 183 | case EGL_BLUE_SIZE: mWantBlue = true; break; |
| 184 | case EGL_ALPHA_SIZE: mWantAlpha = true; break; |
| 185 | case EGL_LUMINANCE_SIZE: mWantLuminance = true; break; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | EGLint wantedComponentsSize(const Config &config) const |
| 192 | { |
| 193 | EGLint total = 0; |
| 194 | |
Geoff Lang | c223dc6 | 2015-01-09 13:10:01 -0500 | [diff] [blame] | 195 | if (mWantRed) total += config.redSize; |
| 196 | if (mWantGreen) total += config.greenSize; |
| 197 | if (mWantBlue) total += config.blueSize; |
| 198 | if (mWantAlpha) total += config.alphaSize; |
| 199 | if (mWantLuminance) total += config.luminanceSize; |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 200 | |
| 201 | return total; |
| 202 | } |
| 203 | |
| 204 | bool mWantRed; |
| 205 | bool mWantGreen; |
| 206 | bool mWantBlue; |
| 207 | bool mWantAlpha; |
| 208 | bool mWantLuminance; |
| 209 | }; |
| 210 | |
| 211 | std::vector<const Config*> ConfigSet::filter(const AttributeMap &attributeMap) const |
| 212 | { |
| 213 | std::vector<const Config*> result; |
| 214 | result.reserve(mConfigs.size()); |
| 215 | |
| 216 | for (auto configIter = mConfigs.begin(); configIter != mConfigs.end(); configIter++) |
| 217 | { |
| 218 | const Config &config = configIter->second; |
| 219 | bool match = true; |
| 220 | |
| 221 | for (auto attribIter = attributeMap.begin(); attribIter != attributeMap.end(); attribIter++) |
| 222 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 223 | EGLAttrib attributeKey = attribIter->first; |
| 224 | EGLAttrib attributeValue = attribIter->second; |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 225 | |
| 226 | switch (attributeKey) |
| 227 | { |
Geoff Lang | c223dc6 | 2015-01-09 13:10:01 -0500 | [diff] [blame] | 228 | case EGL_BUFFER_SIZE: match = config.bufferSize >= attributeValue; break; |
| 229 | case EGL_ALPHA_SIZE: match = config.alphaSize >= attributeValue; break; |
| 230 | case EGL_BLUE_SIZE: match = config.blueSize >= attributeValue; break; |
| 231 | case EGL_GREEN_SIZE: match = config.greenSize >= attributeValue; break; |
| 232 | case EGL_RED_SIZE: match = config.redSize >= attributeValue; break; |
| 233 | case EGL_DEPTH_SIZE: match = config.depthSize >= attributeValue; break; |
| 234 | case EGL_STENCIL_SIZE: match = config.stencilSize >= attributeValue; break; |
| 235 | case EGL_CONFIG_CAVEAT: match = config.configCaveat == (EGLenum)attributeValue; break; |
| 236 | case EGL_CONFIG_ID: match = config.configID == attributeValue; break; |
| 237 | case EGL_LEVEL: match = config.level >= attributeValue; break; |
| 238 | case EGL_NATIVE_RENDERABLE: match = config.nativeRenderable == (EGLBoolean)attributeValue; break; |
| 239 | case EGL_NATIVE_VISUAL_TYPE: match = config.nativeVisualType == attributeValue; break; |
| 240 | case EGL_SAMPLES: match = config.samples >= attributeValue; break; |
| 241 | case EGL_SAMPLE_BUFFERS: match = config.sampleBuffers >= attributeValue; break; |
| 242 | case EGL_SURFACE_TYPE: match = (config.surfaceType & attributeValue) == attributeValue; break; |
| 243 | case EGL_TRANSPARENT_TYPE: match = config.transparentType == (EGLenum)attributeValue; break; |
| 244 | case EGL_TRANSPARENT_BLUE_VALUE: match = config.transparentBlueValue == attributeValue; break; |
| 245 | case EGL_TRANSPARENT_GREEN_VALUE: match = config.transparentGreenValue == attributeValue; break; |
| 246 | case EGL_TRANSPARENT_RED_VALUE: match = config.transparentRedValue == attributeValue; break; |
| 247 | case EGL_BIND_TO_TEXTURE_RGB: match = config.bindToTextureRGB == (EGLBoolean)attributeValue; break; |
| 248 | case EGL_BIND_TO_TEXTURE_RGBA: match = config.bindToTextureRGBA == (EGLBoolean)attributeValue; break; |
| 249 | case EGL_MIN_SWAP_INTERVAL: match = config.minSwapInterval == attributeValue; break; |
| 250 | case EGL_MAX_SWAP_INTERVAL: match = config.maxSwapInterval == attributeValue; break; |
| 251 | case EGL_LUMINANCE_SIZE: match = config.luminanceSize >= attributeValue; break; |
| 252 | case EGL_ALPHA_MASK_SIZE: match = config.alphaMaskSize >= attributeValue; break; |
| 253 | case EGL_COLOR_BUFFER_TYPE: match = config.colorBufferType == (EGLenum)attributeValue; break; |
| 254 | case EGL_RENDERABLE_TYPE: match = (config.renderableType & attributeValue) == attributeValue; break; |
| 255 | case EGL_MATCH_NATIVE_PIXMAP: match = false; UNIMPLEMENTED(); break; |
| 256 | case EGL_CONFORMANT: match = (config.conformant & attributeValue) == attributeValue; break; |
| 257 | case EGL_MAX_PBUFFER_WIDTH: match = config.maxPBufferWidth >= attributeValue; break; |
| 258 | case EGL_MAX_PBUFFER_HEIGHT: match = config.maxPBufferHeight >= attributeValue; break; |
| 259 | case EGL_MAX_PBUFFER_PIXELS: match = config.maxPBufferPixels >= attributeValue; break; |
Geoff Lang | 7f448b5 | 2015-12-16 13:31:57 -0500 | [diff] [blame] | 260 | case EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE: |
| 261 | match = config.optimalOrientation == attributeValue; |
| 262 | break; |
Geoff Lang | c5a2a17 | 2017-01-13 15:55:07 -0500 | [diff] [blame] | 263 | case EGL_COLOR_COMPONENT_TYPE_EXT: |
| 264 | match = config.colorComponentType == static_cast<EGLenum>(attributeValue); |
| 265 | break; |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 266 | default: UNREACHABLE(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 267 | } |
| 268 | |
daniel@transgaming.com | 6a94b97 | 2010-05-13 02:02:34 +0000 | [diff] [blame] | 269 | if (!match) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 270 | { |
daniel@transgaming.com | 6a94b97 | 2010-05-13 02:02:34 +0000 | [diff] [blame] | 271 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
daniel@transgaming.com | 6a94b97 | 2010-05-13 02:02:34 +0000 | [diff] [blame] | 275 | if (match) |
| 276 | { |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 277 | result.push_back(&config); |
daniel@transgaming.com | 6a94b97 | 2010-05-13 02:02:34 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 281 | // Sort the result |
| 282 | std::sort(result.begin(), result.end(), ConfigSorter(attributeMap)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 283 | |
Geoff Lang | 6812a55 | 2015-01-06 17:26:42 -0500 | [diff] [blame] | 284 | return result; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 285 | } |
| 286 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 287 | } |