| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 static const FormatType kSupportedFormatTypes[] = { | 130 static const FormatType kSupportedFormatTypes[] = { |
| 131 // ES2. | 131 // ES2. |
| 132 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | 132 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, |
| 133 {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, | 133 {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, |
| 134 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | 134 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, |
| 135 {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4}, | 135 {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4}, |
| 136 {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, | 136 {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, |
| 137 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | 137 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, |
| 138 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | 138 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
| 139 {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE}, | 139 {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE}, |
| 140 // Exposed by GL_OES_texture_float and GL_OES_texture_half_float | |
| 141 {GL_RGB, GL_RGB, GL_FLOAT}, | |
| 142 {GL_RGBA, GL_RGBA, GL_FLOAT}, | |
| 143 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT}, | |
| 144 {GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT}, | |
| 145 {GL_ALPHA, GL_ALPHA, GL_FLOAT}, | |
| 146 {GL_RGB, GL_RGB, GL_HALF_FLOAT_OES}, | |
| 147 {GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES}, | |
| 148 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES}, | |
| 149 {GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES}, | |
| 150 {GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES}, | |
| 151 // Exposed by GL_ANGLE_depth_texture | |
| 152 {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, | |
| 153 {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, | |
| 154 {GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, | |
| 155 // Exposed by GL_EXT_sRGB | |
| 156 {GL_SRGB, GL_SRGB, GL_UNSIGNED_BYTE}, | |
| 157 {GL_SRGB_ALPHA, GL_SRGB_ALPHA, GL_UNSIGNED_BYTE}, | |
| 158 // Exposed by GL_EXT_texture_format_BGRA8888 | |
| 159 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
| 160 // Exposed by GL_EXT_texture_rg | |
| 161 {GL_RED, GL_RED, GL_UNSIGNED_BYTE}, | |
| 162 {GL_RG, GL_RG, GL_UNSIGNED_BYTE}, | |
| 163 {GL_RED, GL_RED, GL_FLOAT}, | |
| 164 {GL_RG, GL_RG, GL_FLOAT}, | |
| 165 {GL_RED, GL_RED, GL_HALF_FLOAT_OES}, | |
| 166 {GL_RG, GL_RG, GL_HALF_FLOAT_OES}, | |
| 167 | 140 |
| 168 // ES3. | 141 // ES3. |
| 169 {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, | 142 {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, |
| 170 {GL_R8_SNORM, GL_RED, GL_BYTE}, | 143 {GL_R8_SNORM, GL_RED, GL_BYTE}, |
| 171 {GL_R16F, GL_RED, GL_HALF_FLOAT}, | 144 {GL_R16F, GL_RED, GL_HALF_FLOAT}, |
| 172 {GL_R16F, GL_RED, GL_FLOAT}, | 145 {GL_R16F, GL_RED, GL_FLOAT}, |
| 173 {GL_R32F, GL_RED, GL_FLOAT}, | 146 {GL_R32F, GL_RED, GL_FLOAT}, |
| 174 {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, | 147 {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, |
| 175 {GL_R8I, GL_RED_INTEGER, GL_BYTE}, | 148 {GL_R8I, GL_RED_INTEGER, GL_BYTE}, |
| 176 {GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT}, | 149 {GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT}, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, | 200 {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, |
| 228 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, | 201 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, |
| 229 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, | 202 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, |
| 230 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, | 203 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, |
| 231 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, | 204 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, |
| 232 {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, | 205 {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, |
| 233 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, | 206 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, |
| 234 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, | 207 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, |
| 235 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, | 208 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, |
| 236 GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, | 209 GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, |
| 237 // Exposed by GL_APPLE_texture_format_BGRA8888 | 210 |
| 211 // Exposed by GL_APPLE_texture_format_BGRA8888 for TexStorage* |
| 212 // TODO(kainino): this actually exposes it for (Copy)TexImage* as well, |
| 213 // which is incorrect. crbug.com/663086 |
| 238 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | 214 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, |
| 215 |
| 216 // Exposed by GL_APPLE_texture_format_BGRA8888 and |
| 217 // GL_EXT_texture_format_BGRA8888 |
| 218 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, |
| 219 }; |
| 220 |
| 221 static const FormatType kSupportedFormatTypesES2Only[] = { |
| 222 // Exposed by GL_OES_texture_float and GL_OES_texture_half_float |
| 223 {GL_RGB, GL_RGB, GL_FLOAT}, |
| 224 {GL_RGBA, GL_RGBA, GL_FLOAT}, |
| 225 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT}, |
| 226 {GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT}, |
| 227 {GL_ALPHA, GL_ALPHA, GL_FLOAT}, |
| 228 {GL_RGB, GL_RGB, GL_HALF_FLOAT_OES}, |
| 229 {GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES}, |
| 230 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES}, |
| 231 {GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES}, |
| 232 {GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES}, |
| 233 |
| 234 // Exposed by GL_ANGLE_depth_texture |
| 235 {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, |
| 236 {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, |
| 237 {GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, |
| 238 |
| 239 // Exposed by GL_EXT_sRGB |
| 240 {GL_SRGB, GL_SRGB, GL_UNSIGNED_BYTE}, |
| 241 {GL_SRGB_ALPHA, GL_SRGB_ALPHA, GL_UNSIGNED_BYTE}, |
| 242 |
| 243 // Exposed by GL_EXT_texture_rg |
| 244 {GL_RED, GL_RED, GL_UNSIGNED_BYTE}, |
| 245 {GL_RG, GL_RG, GL_UNSIGNED_BYTE}, |
| 246 {GL_RED, GL_RED, GL_FLOAT}, |
| 247 {GL_RG, GL_RG, GL_FLOAT}, |
| 248 {GL_RED, GL_RED, GL_HALF_FLOAT_OES}, |
| 249 {GL_RG, GL_RG, GL_HALF_FLOAT_OES}, |
| 239 }; | 250 }; |
| 240 | 251 |
| 241 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) { | 252 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) { |
| 242 supported_combinations_.insert(kSupportedFormatTypes[ii]); | 253 supported_combinations_.insert(kSupportedFormatTypes[ii]); |
| 243 } | 254 } |
| 255 |
| 256 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypesES2Only); ++ii) { |
| 257 supported_combinations_es2_only_.insert(kSupportedFormatTypesES2Only[ii]); |
| 258 } |
| 244 } | 259 } |
| 245 | 260 |
| 246 // This may be accessed from multiple threads. | 261 // This may be accessed from multiple threads. |
| 247 bool IsValid(GLenum internal_format, GLenum format, GLenum type) const { | 262 bool IsValid(ContextType context_type, GLenum internal_format, GLenum format, |
| 263 GLenum type) const { |
| 248 FormatType query = { internal_format, format, type }; | 264 FormatType query = { internal_format, format, type }; |
| 249 return supported_combinations_.find(query) != supported_combinations_.end(); | 265 if (supported_combinations_.find(query) != supported_combinations_.end()) { |
| 266 return true; |
| 267 } |
| 268 if (context_type == CONTEXT_TYPE_OPENGLES2 || |
| 269 context_type == CONTEXT_TYPE_WEBGL1) { |
| 270 if (supported_combinations_es2_only_.find(query) != |
| 271 supported_combinations_es2_only_.end()) { |
| 272 return true; |
| 273 } |
| 274 } |
| 275 return false; |
| 250 } | 276 } |
| 251 | 277 |
| 252 private: | 278 private: |
| 253 // TODO(zmo): once std::tuple is allowed, switch over to that. | 279 // TODO(zmo): once std::tuple is allowed, switch over to that. |
| 254 struct FormatType { | 280 struct FormatType { |
| 255 GLenum internal_format; | 281 GLenum internal_format; |
| 256 GLenum format; | 282 GLenum format; |
| 257 GLenum type; | 283 GLenum type; |
| 258 }; | 284 }; |
| 259 | 285 |
| 260 struct FormatTypeCompare { | 286 struct FormatTypeCompare { |
| 261 bool operator() (const FormatType& lhs, const FormatType& rhs) const { | 287 bool operator() (const FormatType& lhs, const FormatType& rhs) const { |
| 262 return (lhs.internal_format < rhs.internal_format || | 288 return (lhs.internal_format < rhs.internal_format || |
| 263 ((lhs.internal_format == rhs.internal_format) && | 289 ((lhs.internal_format == rhs.internal_format) && |
| 264 (lhs.format < rhs.format)) || | 290 (lhs.format < rhs.format)) || |
| 265 ((lhs.internal_format == rhs.internal_format) && | 291 ((lhs.internal_format == rhs.internal_format) && |
| 266 (lhs.format == rhs.format) && | 292 (lhs.format == rhs.format) && |
| 267 (lhs.type < rhs.type))); | 293 (lhs.type < rhs.type))); |
| 268 } | 294 } |
| 269 }; | 295 }; |
| 270 | 296 |
| 271 // This class needs to be thread safe, so once supported_combinations_ | 297 // This class needs to be thread safe, so once supported_combinations_ |
| 272 // are initialized in the constructor, it should never be modified later. | 298 // are initialized in the constructor, it should never be modified later. |
| 273 std::set<FormatType, FormatTypeCompare> supported_combinations_; | 299 std::set<FormatType, FormatTypeCompare> supported_combinations_; |
| 300 std::set<FormatType, FormatTypeCompare> supported_combinations_es2_only_; |
| 274 }; | 301 }; |
| 275 | 302 |
| 276 static const Texture::CompatibilitySwizzle kSwizzledFormats[] = { | 303 static const Texture::CompatibilitySwizzle kSwizzledFormats[] = { |
| 277 {GL_ALPHA, GL_RED, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED}, | 304 {GL_ALPHA, GL_RED, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED}, |
| 278 {GL_LUMINANCE, GL_RED, GL_RED, GL_RED, GL_RED, GL_ONE}, | 305 {GL_LUMINANCE, GL_RED, GL_RED, GL_RED, GL_RED, GL_ONE}, |
| 279 {GL_LUMINANCE_ALPHA, GL_RG, GL_RED, GL_RED, GL_RED, GL_GREEN}, | 306 {GL_LUMINANCE_ALPHA, GL_RG, GL_RED, GL_RED, GL_RED, GL_GREEN}, |
| 280 }; | 307 }; |
| 281 | 308 |
| 282 // static | 309 // static |
| 283 const Texture::CompatibilitySwizzle* GetCompatibilitySwizzle(GLenum format) { | 310 const Texture::CompatibilitySwizzle* GetCompatibilitySwizzle(GLenum format) { |
| (...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2297 // For TexSubImage calls, internal_format isn't part of the parameters. | 2324 // For TexSubImage calls, internal_format isn't part of the parameters. |
| 2298 // So the validation is not necessary for TexSubImage. | 2325 // So the validation is not necessary for TexSubImage. |
| 2299 if (tex_image_call && | 2326 if (tex_image_call && |
| 2300 !validators->texture_internal_format.IsValid(internal_format)) { | 2327 !validators->texture_internal_format.IsValid(internal_format)) { |
| 2301 std::string msg = std::string("invalid internal_format ") + | 2328 std::string msg = std::string("invalid internal_format ") + |
| 2302 GLES2Util::GetStringEnum(internal_format); | 2329 GLES2Util::GetStringEnum(internal_format); |
| 2303 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, | 2330 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 2304 msg.c_str()); | 2331 msg.c_str()); |
| 2305 return false; | 2332 return false; |
| 2306 } | 2333 } |
| 2307 if (!g_format_type_validator.Get().IsValid(internal_format, format, type)) { | 2334 if (!g_format_type_validator.Get().IsValid(feature_info_->context_type(), |
| 2335 internal_format, format, type)) { |
| 2308 std::string msg = std::string( | 2336 std::string msg = std::string( |
| 2309 "invalid internalformat/format/type combination ") + | 2337 "invalid internalformat/format/type combination ") + |
| 2310 GLES2Util::GetStringEnum(internal_format) + std::string("/") + | 2338 GLES2Util::GetStringEnum(internal_format) + std::string("/") + |
| 2311 GLES2Util::GetStringEnum(format) + std::string("/") + | 2339 GLES2Util::GetStringEnum(format) + std::string("/") + |
| 2312 GLES2Util::GetStringEnum(type); | 2340 GLES2Util::GetStringEnum(type); |
| 2313 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, | 2341 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 2314 msg.c_str()); | 2342 msg.c_str()); |
| 2315 return false; | 2343 return false; |
| 2316 } | 2344 } |
| 2317 if (!feature_info_->IsWebGL2OrES3Context()) { | 2345 if (!feature_info_->IsWebGL2OrES3Context()) { |
| (...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3620 uint32_t TextureManager::GetServiceIdGeneration() const { | 3648 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3621 return current_service_id_generation_; | 3649 return current_service_id_generation_; |
| 3622 } | 3650 } |
| 3623 | 3651 |
| 3624 void TextureManager::IncrementServiceIdGeneration() { | 3652 void TextureManager::IncrementServiceIdGeneration() { |
| 3625 current_service_id_generation_++; | 3653 current_service_id_generation_++; |
| 3626 } | 3654 } |
| 3627 | 3655 |
| 3628 } // namespace gles2 | 3656 } // namespace gles2 |
| 3629 } // namespace gpu | 3657 } // namespace gpu |
| OLD | NEW |