| 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/strings/stringprintf.h" | 7 #include "base/strings/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/error_state.h" | 9 #include "gpu/command_buffer/service/error_state.h" |
| 10 #include "gpu/command_buffer/service/feature_info.h" | 10 #include "gpu/command_buffer/service/feature_info.h" |
| 11 #include "gpu/command_buffer/service/framebuffer_manager.h" | 11 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 13 #include "gpu/command_buffer/service/mailbox_manager.h" | 13 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 14 #include "gpu/command_buffer/service/memory_tracking.h" | 14 #include "gpu/command_buffer/service/memory_tracking.h" |
| 15 #include "gpu/command_buffer/service/stream_texture_manager.h" | |
| 16 | 15 |
| 17 namespace gpu { | 16 namespace gpu { |
| 18 namespace gles2 { | 17 namespace gles2 { |
| 19 | 18 |
| 20 static size_t GLTargetToFaceIndex(GLenum target) { | 19 static size_t GLTargetToFaceIndex(GLenum target) { |
| 21 switch (target) { | 20 switch (target) { |
| 22 case GL_TEXTURE_2D: | 21 case GL_TEXTURE_2D: |
| 23 case GL_TEXTURE_EXTERNAL_OES: | 22 case GL_TEXTURE_EXTERNAL_OES: |
| 24 case GL_TEXTURE_RECTANGLE_ARB: | 23 case GL_TEXTURE_RECTANGLE_ARB: |
| 25 return 0; | 24 return 0; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 wrap_s_(GL_REPEAT), | 107 wrap_s_(GL_REPEAT), |
| 109 wrap_t_(GL_REPEAT), | 108 wrap_t_(GL_REPEAT), |
| 110 usage_(GL_NONE), | 109 usage_(GL_NONE), |
| 111 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), | 110 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), |
| 112 max_level_set_(-1), | 111 max_level_set_(-1), |
| 113 texture_complete_(false), | 112 texture_complete_(false), |
| 114 cube_complete_(false), | 113 cube_complete_(false), |
| 115 npot_(false), | 114 npot_(false), |
| 116 has_been_bound_(false), | 115 has_been_bound_(false), |
| 117 framebuffer_attachment_count_(0), | 116 framebuffer_attachment_count_(0), |
| 118 stream_texture_(false), | |
| 119 immutable_(false), | 117 immutable_(false), |
| 120 estimated_size_(0), | 118 estimated_size_(0), |
| 121 can_render_condition_(CAN_RENDER_ALWAYS) { | 119 can_render_condition_(CAN_RENDER_ALWAYS) { |
| 122 } | 120 } |
| 123 | 121 |
| 124 Texture::~Texture() { | 122 Texture::~Texture() { |
| 125 if (mailbox_manager_) | 123 if (mailbox_manager_) |
| 126 mailbox_manager_->TextureDeleted(this); | 124 mailbox_manager_->TextureDeleted(this); |
| 127 } | 125 } |
| 128 | 126 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 189 } |
| 192 | 190 |
| 193 Texture::LevelInfo::~LevelInfo() { | 191 Texture::LevelInfo::~LevelInfo() { |
| 194 } | 192 } |
| 195 | 193 |
| 196 Texture::CanRenderCondition Texture::GetCanRenderCondition() const { | 194 Texture::CanRenderCondition Texture::GetCanRenderCondition() const { |
| 197 if (target_ == 0) | 195 if (target_ == 0) |
| 198 return CAN_RENDER_ALWAYS; | 196 return CAN_RENDER_ALWAYS; |
| 199 | 197 |
| 200 if (target_ == GL_TEXTURE_EXTERNAL_OES) { | 198 if (target_ == GL_TEXTURE_EXTERNAL_OES) { |
| 201 if (!IsStreamTexture()) { | 199 if (!GetLevelImage(target_, 0)) { |
| 202 return CAN_RENDER_NEVER; | 200 return CAN_RENDER_NEVER; |
| 203 } | 201 } |
| 204 } else { | 202 } else { |
| 205 if (level_infos_.empty()) { | 203 if (level_infos_.empty()) { |
| 206 return CAN_RENDER_NEVER; | 204 return CAN_RENDER_NEVER; |
| 207 } | 205 } |
| 208 | 206 |
| 209 const Texture::LevelInfo& first_face = level_infos_[0][0]; | 207 const Texture::LevelInfo& first_face = level_infos_[0][0]; |
| 210 if (first_face.width == 0 || | 208 if (first_face.width == 0 || |
| 211 first_face.height == 0 || | 209 first_face.height == 0 || |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 } | 794 } |
| 797 return 0; | 795 return 0; |
| 798 } | 796 } |
| 799 | 797 |
| 800 | 798 |
| 801 TextureRef::TextureRef(TextureManager* manager, | 799 TextureRef::TextureRef(TextureManager* manager, |
| 802 GLuint client_id, | 800 GLuint client_id, |
| 803 Texture* texture) | 801 Texture* texture) |
| 804 : manager_(manager), | 802 : manager_(manager), |
| 805 texture_(texture), | 803 texture_(texture), |
| 806 client_id_(client_id), | 804 client_id_(client_id) { |
| 807 is_stream_texture_owner_(false) { | |
| 808 DCHECK(manager_); | 805 DCHECK(manager_); |
| 809 DCHECK(texture_); | 806 DCHECK(texture_); |
| 810 texture_->AddTextureRef(this); | 807 texture_->AddTextureRef(this); |
| 811 manager_->StartTracking(this); | 808 manager_->StartTracking(this); |
| 812 } | 809 } |
| 813 | 810 |
| 814 scoped_refptr<TextureRef> TextureRef::Create(TextureManager* manager, | 811 scoped_refptr<TextureRef> TextureRef::Create(TextureManager* manager, |
| 815 GLuint client_id, | 812 GLuint client_id, |
| 816 GLuint service_id) { | 813 GLuint service_id) { |
| 817 return new TextureRef(manager, client_id, new Texture(service_id)); | 814 return new TextureRef(manager, client_id, new Texture(service_id)); |
| 818 } | 815 } |
| 819 | 816 |
| 820 TextureRef::~TextureRef() { | 817 TextureRef::~TextureRef() { |
| 821 manager_->StopTracking(this); | 818 manager_->StopTracking(this); |
| 822 texture_->RemoveTextureRef(this, manager_->have_context_); | 819 texture_->RemoveTextureRef(this, manager_->have_context_); |
| 823 manager_ = NULL; | 820 manager_ = NULL; |
| 824 } | 821 } |
| 825 | 822 |
| 826 TextureManager::TextureManager( | 823 TextureManager::TextureManager( |
| 827 MemoryTracker* memory_tracker, | 824 MemoryTracker* memory_tracker, |
| 828 FeatureInfo* feature_info, | 825 FeatureInfo* feature_info, |
| 829 GLint max_texture_size, | 826 GLint max_texture_size, |
| 830 GLint max_cube_map_texture_size) | 827 GLint max_cube_map_texture_size) |
| 831 : memory_tracker_managed_( | 828 : memory_tracker_managed_( |
| 832 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)), | 829 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)), |
| 833 memory_tracker_unmanaged_( | 830 memory_tracker_unmanaged_( |
| 834 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), | 831 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), |
| 835 feature_info_(feature_info), | 832 feature_info_(feature_info), |
| 836 framebuffer_manager_(NULL), | 833 framebuffer_manager_(NULL), |
| 837 stream_texture_manager_(NULL), | |
| 838 max_texture_size_(max_texture_size), | 834 max_texture_size_(max_texture_size), |
| 839 max_cube_map_texture_size_(max_cube_map_texture_size), | 835 max_cube_map_texture_size_(max_cube_map_texture_size), |
| 840 max_levels_(ComputeMipMapCount(max_texture_size, | 836 max_levels_(ComputeMipMapCount(max_texture_size, |
| 841 max_texture_size, | 837 max_texture_size, |
| 842 max_texture_size)), | 838 max_texture_size)), |
| 843 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, | 839 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, |
| 844 max_cube_map_texture_size, | 840 max_cube_map_texture_size, |
| 845 max_cube_map_texture_size)), | 841 max_cube_map_texture_size)), |
| 846 num_unrenderable_textures_(0), | 842 num_unrenderable_textures_(0), |
| 847 num_unsafe_textures_(0), | 843 num_unsafe_textures_(0), |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && | 969 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && |
| 974 (target != GL_TEXTURE_2D || (depth == 1)); | 970 (target != GL_TEXTURE_2D || (depth == 1)); |
| 975 } | 971 } |
| 976 | 972 |
| 977 void TextureManager::SetTarget(TextureRef* ref, GLenum target) { | 973 void TextureManager::SetTarget(TextureRef* ref, GLenum target) { |
| 978 DCHECK(ref); | 974 DCHECK(ref); |
| 979 ref->texture() | 975 ref->texture() |
| 980 ->SetTarget(feature_info_.get(), target, MaxLevelsForTarget(target)); | 976 ->SetTarget(feature_info_.get(), target, MaxLevelsForTarget(target)); |
| 981 } | 977 } |
| 982 | 978 |
| 983 void TextureManager::SetStreamTexture(TextureRef* ref, bool stream_texture) { | |
| 984 DCHECK(ref); | |
| 985 // Only the owner can mark as non-stream texture. | |
| 986 DCHECK_EQ(stream_texture, !ref->is_stream_texture_owner_); | |
| 987 ref->texture()->SetStreamTexture(stream_texture); | |
| 988 ref->set_is_stream_texture_owner(stream_texture); | |
| 989 } | |
| 990 | |
| 991 bool TextureManager::IsStreamTextureOwner(TextureRef* ref) { | |
| 992 DCHECK(ref); | |
| 993 return ref->is_stream_texture_owner(); | |
| 994 } | |
| 995 | |
| 996 void TextureManager::SetLevelCleared(TextureRef* ref, | 979 void TextureManager::SetLevelCleared(TextureRef* ref, |
| 997 GLenum target, | 980 GLenum target, |
| 998 GLint level, | 981 GLint level, |
| 999 bool cleared) { | 982 bool cleared) { |
| 1000 DCHECK(ref); | 983 DCHECK(ref); |
| 1001 ref->texture()->SetLevelCleared(target, level, cleared); | 984 ref->texture()->SetLevelCleared(target, level, cleared); |
| 1002 } | 985 } |
| 1003 | 986 |
| 1004 bool TextureManager::ClearRenderableLevels( | 987 bool TextureManager::ClearRenderableLevels( |
| 1005 GLES2Decoder* decoder, TextureRef* ref) { | 988 GLES2Decoder* decoder, TextureRef* ref) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 if (!texture->CanRender(feature_info_.get())) | 1115 if (!texture->CanRender(feature_info_.get())) |
| 1133 ++num_unrenderable_textures_; | 1116 ++num_unrenderable_textures_; |
| 1134 } | 1117 } |
| 1135 | 1118 |
| 1136 void TextureManager::StopTracking(TextureRef* ref) { | 1119 void TextureManager::StopTracking(TextureRef* ref) { |
| 1137 FOR_EACH_OBSERVER(DestructionObserver, | 1120 FOR_EACH_OBSERVER(DestructionObserver, |
| 1138 destruction_observers_, | 1121 destruction_observers_, |
| 1139 OnTextureRefDestroying(ref)); | 1122 OnTextureRefDestroying(ref)); |
| 1140 | 1123 |
| 1141 Texture* texture = ref->texture(); | 1124 Texture* texture = ref->texture(); |
| 1142 if (ref->is_stream_texture_owner_ && stream_texture_manager_) { | |
| 1143 DCHECK(texture->IsStreamTexture()); | |
| 1144 stream_texture_manager_->DestroyStreamTexture(texture->service_id()); | |
| 1145 } | |
| 1146 | 1125 |
| 1147 --texture_count_; | 1126 --texture_count_; |
| 1148 if (!texture->CanRender(feature_info_.get())) { | 1127 if (!texture->CanRender(feature_info_.get())) { |
| 1149 DCHECK_NE(0, num_unrenderable_textures_); | 1128 DCHECK_NE(0, num_unrenderable_textures_); |
| 1150 --num_unrenderable_textures_; | 1129 --num_unrenderable_textures_; |
| 1151 } | 1130 } |
| 1152 if (!texture->SafeToRenderFrom()) { | 1131 if (!texture->SafeToRenderFrom()) { |
| 1153 DCHECK_NE(0, num_unsafe_textures_); | 1132 DCHECK_NE(0, num_unsafe_textures_); |
| 1154 --num_unsafe_textures_; | 1133 --num_unsafe_textures_; |
| 1155 } | 1134 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 } | 1210 } |
| 1232 | 1211 |
| 1233 void TextureManager::IncFramebufferStateChangeCount() { | 1212 void TextureManager::IncFramebufferStateChangeCount() { |
| 1234 if (framebuffer_manager_) | 1213 if (framebuffer_manager_) |
| 1235 framebuffer_manager_->IncFramebufferStateChangeCount(); | 1214 framebuffer_manager_->IncFramebufferStateChangeCount(); |
| 1236 | 1215 |
| 1237 } | 1216 } |
| 1238 | 1217 |
| 1239 } // namespace gles2 | 1218 } // namespace gles2 |
| 1240 } // namespace gpu | 1219 } // namespace gpu |
| OLD | NEW |