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