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/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 3147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3158 caps.minor_version = 0; | 3158 caps.minor_version = 0; |
3159 } | 3159 } |
3160 if (feature_info_->feature_flags().multisampled_render_to_texture || | 3160 if (feature_info_->feature_flags().multisampled_render_to_texture || |
3161 feature_info_->feature_flags().chromium_framebuffer_multisample || | 3161 feature_info_->feature_flags().chromium_framebuffer_multisample || |
3162 unsafe_es3_apis_enabled()) { | 3162 unsafe_es3_apis_enabled()) { |
3163 DoGetIntegerv(GL_MAX_SAMPLES, &caps.max_samples); | 3163 DoGetIntegerv(GL_MAX_SAMPLES, &caps.max_samples); |
3164 } | 3164 } |
3165 | 3165 |
3166 caps.egl_image_external = | 3166 caps.egl_image_external = |
3167 feature_info_->feature_flags().oes_egl_image_external; | 3167 feature_info_->feature_flags().oes_egl_image_external; |
3168 caps.texture_format_astc = | |
3169 feature_info_->feature_flags().ext_texture_format_astc; | |
3168 caps.texture_format_atc = | 3170 caps.texture_format_atc = |
3169 feature_info_->feature_flags().ext_texture_format_atc; | 3171 feature_info_->feature_flags().ext_texture_format_atc; |
3170 caps.texture_format_bgra8888 = | 3172 caps.texture_format_bgra8888 = |
3171 feature_info_->feature_flags().ext_texture_format_bgra8888; | 3173 feature_info_->feature_flags().ext_texture_format_bgra8888; |
3172 caps.texture_format_dxt1 = | 3174 caps.texture_format_dxt1 = |
3173 feature_info_->feature_flags().ext_texture_format_dxt1; | 3175 feature_info_->feature_flags().ext_texture_format_dxt1; |
3174 caps.texture_format_dxt5 = | 3176 caps.texture_format_dxt5 = |
3175 feature_info_->feature_flags().ext_texture_format_dxt5; | 3177 feature_info_->feature_flags().ext_texture_format_dxt5; |
3176 caps.texture_format_etc1 = | 3178 caps.texture_format_etc1 = |
3177 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; | 3179 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; |
(...skipping 3752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6930 } | 6932 } |
6931 } | 6933 } |
6932 } | 6934 } |
6933 | 6935 |
6934 bool GLES2DecoderImpl::PrepareTexturesForRender() { | 6936 bool GLES2DecoderImpl::PrepareTexturesForRender() { |
6935 DCHECK(state_.current_program.get()); | 6937 DCHECK(state_.current_program.get()); |
6936 if (!texture_manager()->HaveUnrenderableTextures() && | 6938 if (!texture_manager()->HaveUnrenderableTextures() && |
6937 !texture_manager()->HaveImages()) { | 6939 !texture_manager()->HaveImages()) { |
6938 return true; | 6940 return true; |
6939 } | 6941 } |
6940 | |
6941 bool textures_set = false; | 6942 bool textures_set = false; |
6942 const Program::SamplerIndices& sampler_indices = | 6943 const Program::SamplerIndices& sampler_indices = |
6943 state_.current_program->sampler_indices(); | 6944 state_.current_program->sampler_indices(); |
6944 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { | 6945 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
6945 const Program::UniformInfo* uniform_info = | 6946 const Program::UniformInfo* uniform_info = |
6946 state_.current_program->GetUniformInfo(sampler_indices[ii]); | 6947 state_.current_program->GetUniformInfo(sampler_indices[ii]); |
6947 DCHECK(uniform_info); | 6948 DCHECK(uniform_info); |
6948 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { | 6949 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
6949 GLuint texture_unit_index = uniform_info->texture_units[jj]; | 6950 GLuint texture_unit_index = uniform_info->texture_units[jj]; |
6950 if (texture_unit_index < state_.texture_units.size()) { | 6951 if (texture_unit_index < state_.texture_units.size()) { |
(...skipping 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9207 } | 9208 } |
9208 TextureRef* bound_texture = | 9209 TextureRef* bound_texture = |
9209 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); | 9210 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); |
9210 glBindTexture(texture->target(), | 9211 glBindTexture(texture->target(), |
9211 bound_texture ? bound_texture->service_id() : 0); | 9212 bound_texture ? bound_texture->service_id() : 0); |
9212 return true; | 9213 return true; |
9213 } | 9214 } |
9214 | 9215 |
9215 namespace { | 9216 namespace { |
9216 | 9217 |
9218 const int kASTCBlockSize = 16; | |
9217 const int kS3TCBlockWidth = 4; | 9219 const int kS3TCBlockWidth = 4; |
9218 const int kS3TCBlockHeight = 4; | 9220 const int kS3TCBlockHeight = 4; |
9219 const int kS3TCDXT1BlockSize = 8; | 9221 const int kS3TCDXT1BlockSize = 8; |
9220 const int kS3TCDXT3AndDXT5BlockSize = 16; | 9222 const int kS3TCDXT3AndDXT5BlockSize = 16; |
9221 const int kEACAndETC2BlockSize = 4; | 9223 const int kEACAndETC2BlockSize = 4; |
9222 | 9224 |
9225 typedef struct { | |
9226 int blockWidth; | |
9227 int blockHeight; | |
9228 } ASTCBlockArray; | |
9229 | |
9230 const ASTCBlockArray kASTCBlockArray[] = | |
9231 { | |
Zhenyao Mo
2015/08/25 14:15:16
nit: this is against code style. see https://goog
| |
9232 4, 4, /* GL_COMPRESSED_RGBA_ASTC_4x4_KHR */ | |
9233 5, 4, /* and GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR */ | |
9234 5, 5, | |
9235 6, 5, | |
9236 6, 6, | |
9237 8, 5, | |
9238 8, 6, | |
9239 8, 8, | |
9240 10, 5, | |
9241 10, 6, | |
9242 10, 8, | |
9243 10, 10, | |
9244 12, 10, | |
9245 12, 12, | |
9246 }; | |
9247 | |
9248 | |
9223 bool IsValidDXTSize(GLint level, GLsizei size) { | 9249 bool IsValidDXTSize(GLint level, GLsizei size) { |
9224 return (size == 1) || | 9250 return (size == 1) || |
9225 (size == 2) || !(size % kS3TCBlockWidth); | 9251 (size == 2) || !(size % kS3TCBlockWidth); |
9226 } | 9252 } |
9227 | 9253 |
9228 bool IsValidPVRTCSize(GLint level, GLsizei size) { | 9254 bool IsValidPVRTCSize(GLint level, GLsizei size) { |
9229 return GLES2Util::IsPOT(size); | 9255 return GLES2Util::IsPOT(size); |
9230 } | 9256 } |
9231 | 9257 |
9232 } // anonymous namespace. | 9258 } // anonymous namespace. |
9233 | 9259 |
9234 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes( | 9260 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes( |
9235 const char* function_name, GLsizei width, GLsizei height, GLsizei depth, | 9261 const char* function_name, GLsizei width, GLsizei height, GLsizei depth, |
9236 GLenum format, GLsizei* size_in_bytes) { | 9262 GLenum format, GLsizei* size_in_bytes) { |
9237 base::CheckedNumeric<GLsizei> bytes_required(0); | 9263 base::CheckedNumeric<GLsizei> bytes_required(0); |
9238 | 9264 |
9239 switch (format) { | 9265 switch (format) { |
9240 case GL_ATC_RGB_AMD: | 9266 case GL_ATC_RGB_AMD: |
9241 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | 9267 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
9242 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | 9268 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
9243 case GL_ETC1_RGB8_OES: | 9269 case GL_ETC1_RGB8_OES: |
9244 bytes_required = | 9270 bytes_required = |
9245 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; | 9271 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
9246 bytes_required *= | 9272 bytes_required *= |
9247 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; | 9273 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
9248 bytes_required *= kS3TCDXT1BlockSize; | 9274 bytes_required *= kS3TCDXT1BlockSize; |
9249 break; | 9275 break; |
9276 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: | |
9277 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR: | |
9278 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR: | |
9279 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR: | |
9280 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR: | |
9281 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR: | |
9282 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR: | |
9283 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR: | |
9284 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR: | |
9285 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR: | |
9286 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR: | |
9287 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR: | |
9288 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR: | |
9289 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR: | |
9290 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: | |
9291 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: | |
9292 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: | |
9293 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: | |
9294 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: | |
9295 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: | |
9296 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: | |
9297 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: | |
9298 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: | |
9299 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: | |
9300 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: | |
9301 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: | |
9302 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: | |
9303 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: { | |
9304 const int index = (format < GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) ? | |
9305 static_cast<int>(format - GL_COMPRESSED_RGBA_ASTC_4x4_KHR) : | |
Zhenyao Mo
2015/08/25 14:15:16
nit: 4 space indent here and next line
| |
9306 static_cast<int>(format - GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR); | |
9307 | |
9308 const int kBlockWidth = kASTCBlockArray[index].blockWidth; | |
9309 const int kBlockHeight = kASTCBlockArray[index].blockHeight; | |
9310 | |
9311 bytes_required = | |
9312 (width + kBlockWidth - 1) / kBlockWidth; | |
9313 bytes_required *= | |
9314 (height + kBlockHeight - 1) / kBlockHeight; | |
9315 | |
9316 bytes_required *= kASTCBlockSize; | |
9317 break; | |
9318 } | |
9250 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: | 9319 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
9251 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: | 9320 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
9252 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: | 9321 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
9253 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: | 9322 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
9254 bytes_required = | 9323 bytes_required = |
9255 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; | 9324 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
9256 bytes_required *= | 9325 bytes_required *= |
9257 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; | 9326 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
9258 bytes_required *= kS3TCDXT3AndDXT5BlockSize; | 9327 bytes_required *= kS3TCDXT3AndDXT5BlockSize; |
9259 break; | 9328 break; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9340 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: | 9409 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
9341 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: | 9410 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
9342 DCHECK_EQ(1, depth); // 2D formats. | 9411 DCHECK_EQ(1, depth); // 2D formats. |
9343 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { | 9412 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { |
9344 LOCAL_SET_GL_ERROR( | 9413 LOCAL_SET_GL_ERROR( |
9345 GL_INVALID_OPERATION, function_name, | 9414 GL_INVALID_OPERATION, function_name, |
9346 "width or height invalid for level"); | 9415 "width or height invalid for level"); |
9347 return false; | 9416 return false; |
9348 } | 9417 } |
9349 return true; | 9418 return true; |
9419 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: | |
9420 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR: | |
9421 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR: | |
9422 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR: | |
9423 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR: | |
9424 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR: | |
9425 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR: | |
9426 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR: | |
9427 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR: | |
9428 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR: | |
9429 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR: | |
9430 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR: | |
9431 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR: | |
9432 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR: | |
9433 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: | |
9434 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: | |
9435 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: | |
9436 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: | |
9437 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: | |
9438 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: | |
9439 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: | |
9440 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: | |
9441 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: | |
9442 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: | |
9443 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: | |
9444 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: | |
9445 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: | |
9446 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: | |
9350 case GL_ATC_RGB_AMD: | 9447 case GL_ATC_RGB_AMD: |
9351 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: | 9448 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
9352 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: | 9449 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
9353 case GL_ETC1_RGB8_OES: | 9450 case GL_ETC1_RGB8_OES: |
9354 DCHECK_EQ(1, depth); // 2D formats. | 9451 DCHECK_EQ(1, depth); // 2D formats. |
9355 if (width <= 0 || height <= 0) { | 9452 if (width <= 0 || height <= 0) { |
9356 LOCAL_SET_GL_ERROR( | 9453 LOCAL_SET_GL_ERROR( |
9357 GL_INVALID_OPERATION, function_name, | 9454 GL_INVALID_OPERATION, function_name, |
9358 "width or height invalid for level"); | 9455 "width or height invalid for level"); |
9359 return false; | 9456 return false; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9545 "glCompressedTexImage2D", "unknown texture target"); | 9642 "glCompressedTexImage2D", "unknown texture target"); |
9546 return error::kNoError; | 9643 return error::kNoError; |
9547 } | 9644 } |
9548 Texture* texture = texture_ref->texture(); | 9645 Texture* texture = texture_ref->texture(); |
9549 if (texture->IsImmutable()) { | 9646 if (texture->IsImmutable()) { |
9550 LOCAL_SET_GL_ERROR( | 9647 LOCAL_SET_GL_ERROR( |
9551 GL_INVALID_OPERATION, | 9648 GL_INVALID_OPERATION, |
9552 "glCompressedTexImage2D", "texture is immutable"); | 9649 "glCompressedTexImage2D", "texture is immutable"); |
9553 return error::kNoError; | 9650 return error::kNoError; |
9554 } | 9651 } |
9555 | |
9556 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level, | 9652 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level, |
9557 width, height, 1, internal_format) || | 9653 width, height, 1, internal_format) || |
9558 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height, | 9654 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height, |
9559 1, internal_format, image_size)) { | 9655 1, internal_format, image_size)) { |
9560 return error::kNoError; | 9656 return error::kNoError; |
9561 } | 9657 } |
9562 | 9658 |
9563 if (!EnsureGPUMemoryAvailable(image_size)) { | 9659 if (!EnsureGPUMemoryAvailable(image_size)) { |
9564 LOCAL_SET_GL_ERROR( | 9660 LOCAL_SET_GL_ERROR( |
9565 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); | 9661 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); |
(...skipping 5217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14783 return error::kNoError; | 14879 return error::kNoError; |
14784 } | 14880 } |
14785 | 14881 |
14786 // Include the auto-generated part of this file. We split this because it means | 14882 // Include the auto-generated part of this file. We split this because it means |
14787 // we can easily edit the non-auto generated parts right here in this file | 14883 // we can easily edit the non-auto generated parts right here in this file |
14788 // instead of having to edit some template or the code generator. | 14884 // instead of having to edit some template or the code generator. |
14789 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 14885 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
14790 | 14886 |
14791 } // namespace gles2 | 14887 } // namespace gles2 |
14792 } // namespace gpu | 14888 } // namespace gpu |
OLD | NEW |