| 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 "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 9 #include "gpu/command_buffer/service/feature_info.h" | 9 #include "gpu/command_buffer/service/feature_info.h" |
| 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 11 #include "gpu/command_buffer/service/mailbox_manager.h" | 11 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 12 #include "gpu/command_buffer/service/memory_tracking.h" | 12 #include "gpu/command_buffer/service/memory_tracking.h" |
| 13 #include "gpu/command_buffer/service/texture_definition.h" | |
| 14 | 13 |
| 15 namespace gpu { | 14 namespace gpu { |
| 16 namespace gles2 { | 15 namespace gles2 { |
| 17 | 16 |
| 18 static size_t GLTargetToFaceIndex(GLenum target) { | 17 static size_t GLTargetToFaceIndex(GLenum target) { |
| 19 switch (target) { | 18 switch (target) { |
| 20 case GL_TEXTURE_2D: | 19 case GL_TEXTURE_2D: |
| 21 case GL_TEXTURE_EXTERNAL_OES: | 20 case GL_TEXTURE_EXTERNAL_OES: |
| 22 case GL_TEXTURE_RECTANGLE_ARB: | 21 case GL_TEXTURE_RECTANGLE_ARB: |
| 23 return 0; | 22 return 0; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), | 100 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), |
| 102 max_level_set_(-1), | 101 max_level_set_(-1), |
| 103 texture_complete_(false), | 102 texture_complete_(false), |
| 104 cube_complete_(false), | 103 cube_complete_(false), |
| 105 npot_(false), | 104 npot_(false), |
| 106 has_been_bound_(false), | 105 has_been_bound_(false), |
| 107 framebuffer_attachment_count_(0), | 106 framebuffer_attachment_count_(0), |
| 108 owned_(true), | 107 owned_(true), |
| 109 stream_texture_(false), | 108 stream_texture_(false), |
| 110 immutable_(false), | 109 immutable_(false), |
| 111 estimated_size_(0) { | 110 estimated_size_(0), |
| 111 shared_texture_(NULL) { |
| 112 if (manager_) { | 112 if (manager_) { |
| 113 manager_->StartTracking(this); | 113 manager_->StartTracking(this); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 Texture::~Texture() { | 117 Texture::~Texture() { |
| 118 if (shared_texture_) { |
| 119 bool have_context = manager_ && manager_->have_context_; |
| 120 owned_ = shared_texture_->service_id() != service_id(); |
| 121 StopUsingSharedTexture(have_context); |
| 122 } |
| 123 |
| 118 if (manager_) { | 124 if (manager_) { |
| 119 if (owned_ && manager_->have_context_) { | 125 if (owned_ && manager_->have_context_) { |
| 120 GLuint id = service_id(); | 126 GLuint id = service_id(); |
| 121 glDeleteTextures(1, &id); | 127 glDeleteTextures(1, &id); |
| 122 } | 128 } |
| 123 MarkAsDeleted(); | 129 MarkAsDeleted(); |
| 124 manager_->StopTracking(this); | 130 manager_->StopTracking(this); |
| 125 manager_ = NULL; | 131 manager_ = NULL; |
| 126 } | 132 } |
| 127 } | 133 } |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 if (level >= 0 && face_index < level_infos_.size() && | 693 if (level >= 0 && face_index < level_infos_.size() && |
| 688 static_cast<size_t>(level) < level_infos_[face_index].size()) { | 694 static_cast<size_t>(level) < level_infos_[face_index].size()) { |
| 689 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; | 695 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; |
| 690 if (info.target != 0) { | 696 if (info.target != 0) { |
| 691 return info.image; | 697 return info.image; |
| 692 } | 698 } |
| 693 } | 699 } |
| 694 return 0; | 700 return 0; |
| 695 } | 701 } |
| 696 | 702 |
| 703 |
| 704 void Texture::StartUsingSharedTexture(TextureDefinition* definition) { |
| 705 shared_texture_ = definition; |
| 706 TextureDefinition::Client::StartUsingSharedTexture(definition); |
| 707 } |
| 708 |
| 709 bool Texture::StopUsingSharedTexture(bool have_context) { |
| 710 bool was_deleted = TextureDefinition::Client::StopUsingSharedTexture( |
| 711 shared_texture_, have_context); |
| 712 shared_texture_ = NULL; |
| 713 return was_deleted; |
| 714 } |
| 715 |
| 697 TextureManager::TextureManager( | 716 TextureManager::TextureManager( |
| 698 MemoryTracker* memory_tracker, | 717 MemoryTracker* memory_tracker, |
| 699 FeatureInfo* feature_info, | 718 FeatureInfo* feature_info, |
| 700 GLint max_texture_size, | 719 GLint max_texture_size, |
| 701 GLint max_cube_map_texture_size) | 720 GLint max_cube_map_texture_size) |
| 702 : memory_tracker_managed_( | 721 : memory_tracker_managed_( |
| 703 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)), | 722 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)), |
| 704 memory_tracker_unmanaged_( | 723 memory_tracker_unmanaged_( |
| 705 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), | 724 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), |
| 706 feature_info_(feature_info), | 725 feature_info_(feature_info), |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 ++num_unrenderable_textures_; | 945 ++num_unrenderable_textures_; |
| 927 } | 946 } |
| 928 if (!texture->SafeToRenderFrom()) { | 947 if (!texture->SafeToRenderFrom()) { |
| 929 ++num_unsafe_textures_; | 948 ++num_unsafe_textures_; |
| 930 } | 949 } |
| 931 } | 950 } |
| 932 | 951 |
| 933 TextureDefinition* TextureManager::Save(Texture* texture) { | 952 TextureDefinition* TextureManager::Save(Texture* texture) { |
| 934 DCHECK(texture->owned_); | 953 DCHECK(texture->owned_); |
| 935 | 954 |
| 955 // Fail if we are not the current owner of the shared texture. |
| 956 if (texture->shared_texture_ && |
| 957 texture->shared_texture_->service_id() != texture->service_id()) |
| 958 return NULL; |
| 959 |
| 936 if (texture->IsAttachedToFramebuffer()) | 960 if (texture->IsAttachedToFramebuffer()) |
| 937 return NULL; | 961 return NULL; |
| 938 | 962 |
| 939 TextureDefinition::LevelInfos level_infos(texture->level_infos_.size()); | 963 TextureDefinition::LevelInfos level_infos(texture->level_infos_.size()); |
| 940 for (size_t face = 0; face < level_infos.size(); ++face) { | 964 for (size_t face = 0; face < level_infos.size(); ++face) { |
| 941 GLenum target = | 965 GLenum target = |
| 942 texture->target() == GL_TEXTURE_CUBE_MAP ? FaceIndexToGLTarget(face) | 966 texture->target() == GL_TEXTURE_CUBE_MAP ? FaceIndexToGLTarget(face) |
| 943 : texture->target(); | 967 : texture->target(); |
| 944 for (GLint level = 0; level <= texture->max_level_set_; ++level) { | 968 for (GLint level = 0; level <= texture->max_level_set_; ++level) { |
| 945 const Texture::LevelInfo& level_info = | 969 const Texture::LevelInfo& level_info = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 969 true); | 993 true); |
| 970 } | 994 } |
| 971 } | 995 } |
| 972 | 996 |
| 973 GLuint old_service_id = texture->service_id(); | 997 GLuint old_service_id = texture->service_id(); |
| 974 bool immutable = texture->IsImmutable(); | 998 bool immutable = texture->IsImmutable(); |
| 975 | 999 |
| 976 GLuint new_service_id = 0; | 1000 GLuint new_service_id = 0; |
| 977 glGenTextures(1, &new_service_id); | 1001 glGenTextures(1, &new_service_id); |
| 978 texture->SetServiceId(new_service_id); | 1002 texture->SetServiceId(new_service_id); |
| 979 texture->SetImmutable(false); | 1003 texture->SetImmutable(true); |
| 980 | 1004 |
| 981 return new TextureDefinition(texture->target(), | 1005 if (!texture->shared_texture_) { |
| 982 old_service_id, | 1006 texture->StartUsingSharedTexture( |
| 983 texture->min_filter(), | 1007 new TextureDefinition(texture->target(), |
| 984 texture->mag_filter(), | 1008 old_service_id, |
| 985 texture->wrap_s(), | 1009 texture->min_filter(), |
| 986 texture->wrap_t(), | 1010 texture->mag_filter(), |
| 987 texture->usage(), | 1011 texture->wrap_s(), |
| 988 immutable, | 1012 texture->wrap_t(), |
| 989 level_infos); | 1013 texture->usage(), |
| 1014 immutable, |
| 1015 level_infos)); |
| 1016 } |
| 1017 return texture->shared_texture_; |
| 990 } | 1018 } |
| 991 | 1019 |
| 992 bool TextureManager::Restore( | 1020 bool TextureManager::Restore( |
| 993 const char* function_name, | 1021 const char* function_name, |
| 994 GLES2Decoder* decoder, | 1022 GLES2Decoder* decoder, |
| 995 Texture* texture, | 1023 Texture* texture, |
| 996 TextureDefinition* definition) { | 1024 TextureDefinition* definition) { |
| 997 DCHECK(texture->owned_); | 1025 DCHECK(texture->owned_); |
| 998 | 1026 |
| 999 scoped_ptr<TextureDefinition> scoped_definition(definition); | |
| 1000 | |
| 1001 if (texture->IsAttachedToFramebuffer()) | 1027 if (texture->IsAttachedToFramebuffer()) |
| 1002 return false; | 1028 return false; |
| 1003 | 1029 |
| 1004 if (texture->target() != definition->target()) | 1030 if (texture->target() != definition->target()) |
| 1005 return false; | 1031 return false; |
| 1006 | 1032 |
| 1007 if (texture->level_infos_.size() < definition->level_infos().size()) | 1033 if (texture->level_infos_.size() < definition->level_infos().size()) |
| 1008 return false; | 1034 return false; |
| 1009 | 1035 |
| 1010 if (texture->level_infos_[0].size() < definition->level_infos()[0].size()) | 1036 if (texture->level_infos_[0].size() < definition->level_infos()[0].size()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1029 level_info.height, | 1055 level_info.height, |
| 1030 level_info.depth, | 1056 level_info.depth, |
| 1031 level_info.border, | 1057 level_info.border, |
| 1032 level_info.format, | 1058 level_info.format, |
| 1033 level_info.type, | 1059 level_info.type, |
| 1034 level_info.cleared); | 1060 level_info.cleared); |
| 1035 } | 1061 } |
| 1036 } | 1062 } |
| 1037 | 1063 |
| 1038 GLuint old_service_id = texture->service_id(); | 1064 GLuint old_service_id = texture->service_id(); |
| 1039 glDeleteTextures(1, &old_service_id); | 1065 |
| 1040 texture->SetServiceId(definition->ReleaseServiceId()); | 1066 // We don't allow real sharing (yet), so we can't already be using the same |
| 1067 // texture. |
| 1068 DCHECK(definition->service_id() != old_service_id); |
| 1069 |
| 1070 if (texture->shared_texture_ && texture->shared_texture_ != definition) { |
| 1071 // We were already referencing a texture, and it's different from the one we |
| 1072 // are consuming now. |
| 1073 bool owned = texture->shared_texture_->service_id() != old_service_id; |
| 1074 if (owned) |
| 1075 glDeleteTextures(1, &old_service_id); |
| 1076 texture->StopUsingSharedTexture(true); |
| 1077 } else { |
| 1078 glDeleteTextures(1, &old_service_id); |
| 1079 } |
| 1080 |
| 1081 if (!texture->shared_texture_) |
| 1082 texture->StartUsingSharedTexture(definition); |
| 1083 |
| 1084 texture->SetServiceId(definition->service_id()); |
| 1041 glBindTexture(texture->target(), texture->service_id()); | 1085 glBindTexture(texture->target(), texture->service_id()); |
| 1042 texture->SetImmutable(definition->immutable()); | 1086 texture->SetImmutable(definition->immutable()); |
| 1043 SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER, | 1087 SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER, |
| 1044 definition->min_filter()); | 1088 definition->min_filter()); |
| 1045 SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER, | 1089 SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER, |
| 1046 definition->mag_filter()); | 1090 definition->mag_filter()); |
| 1047 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S, | 1091 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S, |
| 1048 definition->wrap_s()); | 1092 definition->wrap_s()); |
| 1049 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T, | 1093 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T, |
| 1050 definition->wrap_t()); | 1094 definition->wrap_t()); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 void TextureManager::AddToSignature( | 1274 void TextureManager::AddToSignature( |
| 1231 Texture* texture, | 1275 Texture* texture, |
| 1232 GLenum target, | 1276 GLenum target, |
| 1233 GLint level, | 1277 GLint level, |
| 1234 std::string* signature) const { | 1278 std::string* signature) const { |
| 1235 texture->AddToSignature(feature_info_.get(), target, level, signature); | 1279 texture->AddToSignature(feature_info_.get(), target, level, signature); |
| 1236 } | 1280 } |
| 1237 | 1281 |
| 1238 } // namespace gles2 | 1282 } // namespace gles2 |
| 1239 } // namespace gpu | 1283 } // namespace gpu |
| OLD | NEW |