| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 328 |
| 329 // TODO(dshwang): check if it's possible to remove | 329 // TODO(dshwang): check if it's possible to remove |
| 330 // CHROMIUM_color_buffer_float_rgb. crbug.com/329605 | 330 // CHROMIUM_color_buffer_float_rgb. crbug.com/329605 |
| 331 if ((feature_info->feature_flags().chromium_color_buffer_float_rgb && | 331 if ((feature_info->feature_flags().chromium_color_buffer_float_rgb && |
| 332 internal_format == GL_RGB32F) || | 332 internal_format == GL_RGB32F) || |
| 333 (feature_info->feature_flags().chromium_color_buffer_float_rgba && | 333 (feature_info->feature_flags().chromium_color_buffer_float_rgba && |
| 334 internal_format == GL_RGBA32F)) { | 334 internal_format == GL_RGBA32F)) { |
| 335 return true; | 335 return true; |
| 336 } | 336 } |
| 337 | 337 |
| 338 return feature_info->IsES3Enabled(); | 338 return feature_info->IsWebGL2OrES3Context(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. | 341 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. |
| 342 GLuint ToGLuint(const void* ptr) { | 342 GLuint ToGLuint(const void* ptr) { |
| 343 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); | 343 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator = | 346 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator = |
| 347 LAZY_INSTANCE_INITIALIZER; | 347 LAZY_INSTANCE_INITIALIZER; |
| 348 | 348 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 sampler_state.mag_filter != GL_NEAREST) { | 615 sampler_state.mag_filter != GL_NEAREST) { |
| 616 DCHECK(!face_infos_.empty()); | 616 DCHECK(!face_infos_.empty()); |
| 617 DCHECK_LT(static_cast<size_t>(base_level_), | 617 DCHECK_LT(static_cast<size_t>(base_level_), |
| 618 face_infos_[0].level_infos.size()); | 618 face_infos_[0].level_infos.size()); |
| 619 const Texture::LevelInfo& first_level = | 619 const Texture::LevelInfo& first_level = |
| 620 face_infos_[0].level_infos[base_level_]; | 620 face_infos_[0].level_infos[base_level_]; |
| 621 if ((GLES2Util::GetChannelsForFormat(first_level.internal_format) & | 621 if ((GLES2Util::GetChannelsForFormat(first_level.internal_format) & |
| 622 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { | 622 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
| 623 if (sampler_state.compare_mode == GL_NONE) { | 623 if (sampler_state.compare_mode == GL_NONE) { |
| 624 // In ES2 with OES_depth_texture, such limitation isn't specified. | 624 // In ES2 with OES_depth_texture, such limitation isn't specified. |
| 625 if (feature_info->IsES3Enabled()) { | 625 if (feature_info->IsWebGL2OrES3Context()) { |
| 626 return false; | 626 return false; |
| 627 } | 627 } |
| 628 } | 628 } |
| 629 } else if (feature_info->validators()->compressed_texture_format.IsValid( | 629 } else if (feature_info->validators()->compressed_texture_format.IsValid( |
| 630 first_level.internal_format)) { | 630 first_level.internal_format)) { |
| 631 // TODO(zmo): The assumption that compressed textures are all filterable | 631 // TODO(zmo): The assumption that compressed textures are all filterable |
| 632 // may not be true in the future. | 632 // may not be true in the future. |
| 633 } else { | 633 } else { |
| 634 if (!Texture::TextureFilterable(feature_info, first_level.internal_format, | 634 if (!Texture::TextureFilterable(feature_info, first_level.internal_format, |
| 635 first_level.type, immutable_)) { | 635 first_level.type, immutable_)) { |
| 636 return false; | 636 return false; |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 | 640 |
| 641 if (!feature_info->IsES3Enabled()) { | 641 if (!feature_info->IsWebGL2OrES3Context()) { |
| 642 bool is_npot_compatible = !needs_mips && | 642 bool is_npot_compatible = !needs_mips && |
| 643 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && | 643 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && |
| 644 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; | 644 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; |
| 645 | 645 |
| 646 if (!is_npot_compatible) { | 646 if (!is_npot_compatible) { |
| 647 if (target_ == GL_TEXTURE_RECTANGLE_ARB) | 647 if (target_ == GL_TEXTURE_RECTANGLE_ARB) |
| 648 return false; | 648 return false; |
| 649 else if (npot()) | 649 else if (npot()) |
| 650 return feature_info->feature_flags().npot_ok; | 650 return feature_info->feature_flags().npot_ok; |
| 651 } | 651 } |
| (...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 | 1876 |
| 1877 // TODO(gman): The default textures have to be real textures, not the 0 | 1877 // TODO(gman): The default textures have to be real textures, not the 0 |
| 1878 // texture because we simulate non shared resources on top of shared | 1878 // texture because we simulate non shared resources on top of shared |
| 1879 // resources and all contexts that share resource share the same default | 1879 // resources and all contexts that share resource share the same default |
| 1880 // texture. | 1880 // texture. |
| 1881 default_textures_[kTexture2D] = CreateDefaultAndBlackTextures( | 1881 default_textures_[kTexture2D] = CreateDefaultAndBlackTextures( |
| 1882 GL_TEXTURE_2D, &black_texture_ids_[kTexture2D]); | 1882 GL_TEXTURE_2D, &black_texture_ids_[kTexture2D]); |
| 1883 default_textures_[kCubeMap] = CreateDefaultAndBlackTextures( | 1883 default_textures_[kCubeMap] = CreateDefaultAndBlackTextures( |
| 1884 GL_TEXTURE_CUBE_MAP, &black_texture_ids_[kCubeMap]); | 1884 GL_TEXTURE_CUBE_MAP, &black_texture_ids_[kCubeMap]); |
| 1885 | 1885 |
| 1886 if (feature_info_->IsES3Enabled()) { | 1886 if (feature_info_->IsWebGL2OrES3Context()) { |
| 1887 default_textures_[kTexture3D] = CreateDefaultAndBlackTextures( | 1887 default_textures_[kTexture3D] = CreateDefaultAndBlackTextures( |
| 1888 GL_TEXTURE_3D, &black_texture_ids_[kTexture3D]); | 1888 GL_TEXTURE_3D, &black_texture_ids_[kTexture3D]); |
| 1889 default_textures_[kTexture2DArray] = CreateDefaultAndBlackTextures( | 1889 default_textures_[kTexture2DArray] = CreateDefaultAndBlackTextures( |
| 1890 GL_TEXTURE_2D_ARRAY, &black_texture_ids_[kTexture2DArray]); | 1890 GL_TEXTURE_2D_ARRAY, &black_texture_ids_[kTexture2DArray]); |
| 1891 } | 1891 } |
| 1892 | 1892 |
| 1893 if (feature_info_->feature_flags().oes_egl_image_external || | 1893 if (feature_info_->feature_flags().oes_egl_image_external || |
| 1894 feature_info_->feature_flags().nv_egl_stream_consumer_external) { | 1894 feature_info_->feature_flags().nv_egl_stream_consumer_external) { |
| 1895 default_textures_[kExternalOES] = CreateDefaultAndBlackTextures( | 1895 default_textures_[kExternalOES] = CreateDefaultAndBlackTextures( |
| 1896 GL_TEXTURE_EXTERNAL_OES, &black_texture_ids_[kExternalOES]); | 1896 GL_TEXTURE_EXTERNAL_OES, &black_texture_ids_[kExternalOES]); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2307 if (!g_format_type_validator.Get().IsValid(internal_format, format, type)) { | 2307 if (!g_format_type_validator.Get().IsValid(internal_format, format, type)) { |
| 2308 std::string msg = std::string( | 2308 std::string msg = std::string( |
| 2309 "invalid internalformat/format/type combination ") + | 2309 "invalid internalformat/format/type combination ") + |
| 2310 GLES2Util::GetStringEnum(internal_format) + std::string("/") + | 2310 GLES2Util::GetStringEnum(internal_format) + std::string("/") + |
| 2311 GLES2Util::GetStringEnum(format) + std::string("/") + | 2311 GLES2Util::GetStringEnum(format) + std::string("/") + |
| 2312 GLES2Util::GetStringEnum(type); | 2312 GLES2Util::GetStringEnum(type); |
| 2313 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, | 2313 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 2314 msg.c_str()); | 2314 msg.c_str()); |
| 2315 return false; | 2315 return false; |
| 2316 } | 2316 } |
| 2317 if (!feature_info_->IsES3Enabled()) { | 2317 if (!feature_info_->IsWebGL2OrES3Context()) { |
| 2318 uint32_t channels = GLES2Util::GetChannelsForFormat(format); | 2318 uint32_t channels = GLES2Util::GetChannelsForFormat(format); |
| 2319 if ((channels & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && level) { | 2319 if ((channels & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && level) { |
| 2320 ERRORSTATE_SET_GL_ERROR( | 2320 ERRORSTATE_SET_GL_ERROR( |
| 2321 error_state, GL_INVALID_OPERATION, function_name, | 2321 error_state, GL_INVALID_OPERATION, function_name, |
| 2322 (std::string("invalid format ") + GLES2Util::GetStringEnum(format) + | 2322 (std::string("invalid format ") + GLES2Util::GetStringEnum(format) + |
| 2323 " for level != 0").c_str()); | 2323 " for level != 0").c_str()); |
| 2324 return false; | 2324 return false; |
| 2325 } | 2325 } |
| 2326 } | 2326 } |
| 2327 return true; | 2327 return true; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2405 if (!ValidForTarget(args.target, args.level, | 2405 if (!ValidForTarget(args.target, args.level, |
| 2406 args.width, args.height, args.depth) || | 2406 args.width, args.height, args.depth) || |
| 2407 args.border != 0) { | 2407 args.border != 0) { |
| 2408 ERRORSTATE_SET_GL_ERROR( | 2408 ERRORSTATE_SET_GL_ERROR( |
| 2409 error_state, GL_INVALID_VALUE, function_name, | 2409 error_state, GL_INVALID_VALUE, function_name, |
| 2410 "dimensions out of range"); | 2410 "dimensions out of range"); |
| 2411 return false; | 2411 return false; |
| 2412 } | 2412 } |
| 2413 if ((GLES2Util::GetChannelsForFormat(args.format) & | 2413 if ((GLES2Util::GetChannelsForFormat(args.format) & |
| 2414 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && args.pixels | 2414 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && args.pixels |
| 2415 && !feature_info_->IsES3Enabled()) { | 2415 && !feature_info_->IsWebGL2OrES3Context()) { |
| 2416 ERRORSTATE_SET_GL_ERROR( | 2416 ERRORSTATE_SET_GL_ERROR( |
| 2417 error_state, GL_INVALID_OPERATION, | 2417 error_state, GL_INVALID_OPERATION, |
| 2418 function_name, "can not supply data for depth or stencil textures"); | 2418 function_name, "can not supply data for depth or stencil textures"); |
| 2419 return false; | 2419 return false; |
| 2420 } | 2420 } |
| 2421 | 2421 |
| 2422 TextureRef* local_texture_ref = GetTextureInfoForTarget(state, args.target); | 2422 TextureRef* local_texture_ref = GetTextureInfoForTarget(state, args.target); |
| 2423 if (!local_texture_ref) { | 2423 if (!local_texture_ref) { |
| 2424 ERRORSTATE_SET_GL_ERROR( | 2424 ERRORSTATE_SET_GL_ERROR( |
| 2425 error_state, GL_INVALID_OPERATION, function_name, | 2425 error_state, GL_INVALID_OPERATION, function_name, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2536 TextureRef* texture_ref; | 2536 TextureRef* texture_ref; |
| 2537 if (!ValidateTexImage(state, function_name, args, &texture_ref)) { | 2537 if (!ValidateTexImage(state, function_name, args, &texture_ref)) { |
| 2538 return; | 2538 return; |
| 2539 } | 2539 } |
| 2540 | 2540 |
| 2541 Buffer* buffer = state->bound_pixel_unpack_buffer.get(); | 2541 Buffer* buffer = state->bound_pixel_unpack_buffer.get(); |
| 2542 | 2542 |
| 2543 // ValidateTexImage is passed already. | 2543 // ValidateTexImage is passed already. |
| 2544 Texture* texture = texture_ref->texture(); | 2544 Texture* texture = texture_ref->texture(); |
| 2545 bool need_cube_map_workaround = | 2545 bool need_cube_map_workaround = |
| 2546 !feature_info_->IsES3Enabled() && | 2546 !feature_info_->IsWebGL2OrES3Context() && |
| 2547 texture->target() == GL_TEXTURE_CUBE_MAP && | 2547 texture->target() == GL_TEXTURE_CUBE_MAP && |
| 2548 (texture_state->force_cube_complete || | 2548 (texture_state->force_cube_complete || |
| 2549 (texture_state->force_cube_map_positive_x_allocation && | 2549 (texture_state->force_cube_map_positive_x_allocation && |
| 2550 args.target != GL_TEXTURE_CUBE_MAP_POSITIVE_X)); | 2550 args.target != GL_TEXTURE_CUBE_MAP_POSITIVE_X)); |
| 2551 if (need_cube_map_workaround && !buffer) { | 2551 if (need_cube_map_workaround && !buffer) { |
| 2552 DoCubeMapWorkaround(texture_state, state, framebuffer_state, | 2552 DoCubeMapWorkaround(texture_state, state, framebuffer_state, |
| 2553 texture_ref, function_name, args); | 2553 texture_ref, function_name, args); |
| 2554 } | 2554 } |
| 2555 | 2555 |
| 2556 if (texture_state->unpack_overlapping_rows_separately_unpack_buffer && | 2556 if (texture_state->unpack_overlapping_rows_separately_unpack_buffer && |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 std::string msg = base::StringPrintf( | 2688 std::string msg = base::StringPrintf( |
| 2689 "level %d does not exist", args.level); | 2689 "level %d does not exist", args.level); |
| 2690 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, | 2690 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 2691 msg.c_str()); | 2691 msg.c_str()); |
| 2692 return false; | 2692 return false; |
| 2693 } | 2693 } |
| 2694 if (!ValidateTextureParameters(error_state, function_name, false, args.format, | 2694 if (!ValidateTextureParameters(error_state, function_name, false, args.format, |
| 2695 args.type, internal_format, args.level)) { | 2695 args.type, internal_format, args.level)) { |
| 2696 return false; | 2696 return false; |
| 2697 } | 2697 } |
| 2698 if (args.type != current_type && !feature_info_->IsES3Enabled()) { | 2698 if (args.type != current_type && !feature_info_->IsWebGL2OrES3Context()) { |
| 2699 // It isn't explicitly required in the ES2 spec, but some drivers generate | 2699 // It isn't explicitly required in the ES2 spec, but some drivers generate |
| 2700 // an error. It is better to be consistent across drivers. | 2700 // an error. It is better to be consistent across drivers. |
| 2701 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, | 2701 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 2702 "type does not match type of texture."); | 2702 "type does not match type of texture."); |
| 2703 return false; | 2703 return false; |
| 2704 } | 2704 } |
| 2705 if (!texture->ValidForTexture(args.target, args.level, | 2705 if (!texture->ValidForTexture(args.target, args.level, |
| 2706 args.xoffset, args.yoffset, args.zoffset, | 2706 args.xoffset, args.yoffset, args.zoffset, |
| 2707 args.width, args.height, args.depth)) { | 2707 args.width, args.height, args.depth)) { |
| 2708 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, | 2708 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 2709 "bad dimensions."); | 2709 "bad dimensions."); |
| 2710 return false; | 2710 return false; |
| 2711 } | 2711 } |
| 2712 if ((GLES2Util::GetChannelsForFormat(args.format) & | 2712 if ((GLES2Util::GetChannelsForFormat(args.format) & |
| 2713 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && | 2713 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && |
| 2714 !feature_info_->IsES3Enabled()) { | 2714 !feature_info_->IsWebGL2OrES3Context()) { |
| 2715 ERRORSTATE_SET_GL_ERROR( | 2715 ERRORSTATE_SET_GL_ERROR( |
| 2716 error_state, GL_INVALID_OPERATION, function_name, | 2716 error_state, GL_INVALID_OPERATION, function_name, |
| 2717 "can not supply data for depth or stencil textures"); | 2717 "can not supply data for depth or stencil textures"); |
| 2718 return false; | 2718 return false; |
| 2719 } | 2719 } |
| 2720 | 2720 |
| 2721 Buffer* buffer = state->bound_pixel_unpack_buffer.get(); | 2721 Buffer* buffer = state->bound_pixel_unpack_buffer.get(); |
| 2722 if (buffer) { | 2722 if (buffer) { |
| 2723 if (buffer->GetMappedRange()) { | 2723 if (buffer->GetMappedRange()) { |
| 2724 ERRORSTATE_SET_GL_ERROR( | 2724 ERRORSTATE_SET_GL_ERROR( |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3620 uint32_t TextureManager::GetServiceIdGeneration() const { | 3620 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3621 return current_service_id_generation_; | 3621 return current_service_id_generation_; |
| 3622 } | 3622 } |
| 3623 | 3623 |
| 3624 void TextureManager::IncrementServiceIdGeneration() { | 3624 void TextureManager::IncrementServiceIdGeneration() { |
| 3625 current_service_id_generation_++; | 3625 current_service_id_generation_++; |
| 3626 } | 3626 } |
| 3627 | 3627 |
| 3628 } // namespace gles2 | 3628 } // namespace gles2 |
| 3629 } // namespace gpu | 3629 } // namespace gpu |
| OLD | NEW |