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 #include "base/bits.h" | 6 #include "base/bits.h" |
7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
8 #include "gpu/command_buffer/service/feature_info.h" | 8 #include "gpu/command_buffer/service/feature_info.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
10 #include "gpu/command_buffer/service/mailbox_manager.h" | 10 #include "gpu/command_buffer/service/mailbox_manager.h" |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 ++num_unsafe_textures_; | 854 ++num_unsafe_textures_; |
855 } | 855 } |
856 } | 856 } |
857 | 857 |
858 TextureDefinition* TextureManager::Save(TextureInfo* info) { | 858 TextureDefinition* TextureManager::Save(TextureInfo* info) { |
859 DCHECK(info->owned_); | 859 DCHECK(info->owned_); |
860 | 860 |
861 if (info->IsAttachedToFramebuffer()) | 861 if (info->IsAttachedToFramebuffer()) |
862 return NULL; | 862 return NULL; |
863 | 863 |
864 if (info->IsImmutable()) | |
865 return NULL; | |
866 | |
867 TextureDefinition::LevelInfos level_infos(info->level_infos_.size()); | 864 TextureDefinition::LevelInfos level_infos(info->level_infos_.size()); |
868 for (size_t face = 0; face < level_infos.size(); ++face) { | 865 for (size_t face = 0; face < level_infos.size(); ++face) { |
869 GLenum target = info->target() == GL_TEXTURE_2D ? | 866 GLenum target = info->target() == GL_TEXTURE_2D ? |
870 GL_TEXTURE_2D : FaceIndexToGLTarget(face); | 867 GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
871 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { | 868 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { |
872 const TextureInfo::LevelInfo& level_info = | 869 const TextureInfo::LevelInfo& level_info = |
873 info->level_infos_[face][level]; | 870 info->level_infos_[face][level]; |
874 level_infos[face].push_back( | 871 level_infos[face].push_back( |
875 TextureDefinition::LevelInfo(target, | 872 TextureDefinition::LevelInfo(target, |
876 level_info.internal_format, | 873 level_info.internal_format, |
(...skipping 13 matching lines...) Expand all Loading... |
890 0, | 887 0, |
891 0, | 888 0, |
892 0, | 889 0, |
893 GL_RGBA, | 890 GL_RGBA, |
894 GL_UNSIGNED_BYTE, | 891 GL_UNSIGNED_BYTE, |
895 true); | 892 true); |
896 } | 893 } |
897 } | 894 } |
898 | 895 |
899 GLuint old_service_id = info->service_id(); | 896 GLuint old_service_id = info->service_id(); |
| 897 bool immutable = info->IsImmutable(); |
900 | 898 |
901 GLuint new_service_id = 0; | 899 GLuint new_service_id = 0; |
902 glGenTextures(1, &new_service_id); | 900 glGenTextures(1, &new_service_id); |
903 info->SetServiceId(new_service_id); | 901 info->SetServiceId(new_service_id); |
| 902 info->SetImmutable(false); |
904 | 903 |
905 return new TextureDefinition(info->target(), | 904 return new TextureDefinition(info->target(), |
906 old_service_id, | 905 old_service_id, |
| 906 immutable, |
907 level_infos); | 907 level_infos); |
908 } | 908 } |
909 | 909 |
910 bool TextureManager::Restore(TextureInfo* info, | 910 bool TextureManager::Restore(TextureInfo* info, |
911 TextureDefinition* definition) { | 911 TextureDefinition* definition) { |
912 DCHECK(info->owned_); | 912 DCHECK(info->owned_); |
913 | 913 |
914 scoped_ptr<TextureDefinition> scoped_definition(definition); | 914 scoped_ptr<TextureDefinition> scoped_definition(definition); |
915 | 915 |
916 if (info->IsAttachedToFramebuffer()) | 916 if (info->IsAttachedToFramebuffer()) |
917 return false; | 917 return false; |
918 | 918 |
919 if (info->IsImmutable()) | |
920 return false; | |
921 | |
922 if (info->target() != definition->target()) | 919 if (info->target() != definition->target()) |
923 return false; | 920 return false; |
924 | 921 |
925 if (info->level_infos_.size() != definition->level_infos().size()) | 922 if (info->level_infos_.size() != definition->level_infos().size()) |
926 return false; | 923 return false; |
927 | 924 |
928 if (info->level_infos_[0].size() != definition->level_infos()[0].size()) | 925 if (info->level_infos_[0].size() != definition->level_infos()[0].size()) |
929 return false; | 926 return false; |
930 | 927 |
931 for (size_t face = 0; face < info->level_infos_.size(); ++face) { | 928 for (size_t face = 0; face < info->level_infos_.size(); ++face) { |
(...skipping 12 matching lines...) Expand all Loading... |
944 level_info.border, | 941 level_info.border, |
945 level_info.format, | 942 level_info.format, |
946 level_info.type, | 943 level_info.type, |
947 level_info.cleared); | 944 level_info.cleared); |
948 } | 945 } |
949 } | 946 } |
950 | 947 |
951 GLuint old_service_id = info->service_id(); | 948 GLuint old_service_id = info->service_id(); |
952 glDeleteTextures(1, &old_service_id); | 949 glDeleteTextures(1, &old_service_id); |
953 info->SetServiceId(definition->ReleaseServiceId()); | 950 info->SetServiceId(definition->ReleaseServiceId()); |
| 951 info->SetImmutable(definition->immutable()); |
954 | 952 |
955 return true; | 953 return true; |
956 } | 954 } |
957 | 955 |
958 bool TextureManager::SetParameter( | 956 bool TextureManager::SetParameter( |
959 TextureManager::TextureInfo* info, GLenum pname, GLint param) { | 957 TextureManager::TextureInfo* info, GLenum pname, GLint param) { |
960 DCHECK(info); | 958 DCHECK(info); |
961 if (!info->CanRender(feature_info_)) { | 959 if (!info->CanRender(feature_info_)) { |
962 DCHECK_NE(0, num_unrenderable_textures_); | 960 DCHECK_NE(0, num_unrenderable_textures_); |
963 --num_unrenderable_textures_; | 961 --num_unrenderable_textures_; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 return false; | 1065 return false; |
1068 } | 1066 } |
1069 | 1067 |
1070 GLsizei TextureManager::ComputeMipMapCount( | 1068 GLsizei TextureManager::ComputeMipMapCount( |
1071 GLsizei width, GLsizei height, GLsizei depth) { | 1069 GLsizei width, GLsizei height, GLsizei depth) { |
1072 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1070 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
1073 } | 1071 } |
1074 | 1072 |
1075 } // namespace gles2 | 1073 } // namespace gles2 |
1076 } // namespace gpu | 1074 } // namespace gpu |
OLD | NEW |