| 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/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" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 estimated_size(rhs.estimated_size) { | 156 estimated_size(rhs.estimated_size) { |
| 157 } | 157 } |
| 158 | 158 |
| 159 Texture::LevelInfo::~LevelInfo() { | 159 Texture::LevelInfo::~LevelInfo() { |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool Texture::CanRender(const FeatureInfo* feature_info) const { | 162 bool Texture::CanRender(const FeatureInfo* feature_info) const { |
| 163 if (target_ == 0) { | 163 if (target_ == 0) { |
| 164 return false; | 164 return false; |
| 165 } | 165 } |
| 166 |
| 167 if (target_ == GL_TEXTURE_EXTERNAL_OES) { |
| 168 if (!IsStreamTexture()) { |
| 169 return false; |
| 170 } |
| 171 } else { |
| 172 if (level_infos_.empty()) { |
| 173 return false; |
| 174 } |
| 175 |
| 176 const Texture::LevelInfo& first_face = level_infos_[0][0]; |
| 177 if (first_face.width == 0 || |
| 178 first_face.height == 0 || |
| 179 first_face.depth == 0) { |
| 180 return false; |
| 181 } |
| 182 } |
| 183 |
| 166 bool needs_mips = NeedsMips(); | 184 bool needs_mips = NeedsMips(); |
| 167 if ((npot() && !feature_info->feature_flags().npot_ok) || | 185 if ((npot() && !feature_info->feature_flags().npot_ok) || |
| 168 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { | 186 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { |
| 169 return !needs_mips && | 187 return !needs_mips && |
| 170 wrap_s_ == GL_CLAMP_TO_EDGE && | 188 wrap_s_ == GL_CLAMP_TO_EDGE && |
| 171 wrap_t_ == GL_CLAMP_TO_EDGE; | 189 wrap_t_ == GL_CLAMP_TO_EDGE; |
| 172 } | 190 } |
| 173 if (needs_mips) { | 191 if (needs_mips) { |
| 174 if (target_ == GL_TEXTURE_2D) { | 192 if (target_ == GL_TEXTURE_2D) { |
| 175 return texture_complete(); | 193 return texture_complete(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 info1.border, | 254 info1.border, |
| 237 info1.format, | 255 info1.format, |
| 238 info1.type, | 256 info1.type, |
| 239 true); | 257 true); |
| 240 } | 258 } |
| 241 } | 259 } |
| 242 | 260 |
| 243 return true; | 261 return true; |
| 244 } | 262 } |
| 245 | 263 |
| 246 void Texture::SetTarget(GLenum target, GLint max_levels) { | 264 void Texture::SetTarget( |
| 265 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { |
| 247 DCHECK_EQ(0u, target_); // you can only set this once. | 266 DCHECK_EQ(0u, target_); // you can only set this once. |
| 248 target_ = target; | 267 target_ = target; |
| 249 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; | 268 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; |
| 250 level_infos_.resize(num_faces); | 269 level_infos_.resize(num_faces); |
| 251 for (size_t ii = 0; ii < num_faces; ++ii) { | 270 for (size_t ii = 0; ii < num_faces; ++ii) { |
| 252 level_infos_[ii].resize(max_levels); | 271 level_infos_[ii].resize(max_levels); |
| 253 } | 272 } |
| 254 | 273 |
| 255 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { | 274 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { |
| 256 min_filter_ = GL_LINEAR; | 275 min_filter_ = GL_LINEAR; |
| 257 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; | 276 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; |
| 258 } | 277 } |
| 259 | 278 |
| 260 if (target == GL_TEXTURE_EXTERNAL_OES) { | 279 if (target == GL_TEXTURE_EXTERNAL_OES) { |
| 261 immutable_ = true; | 280 immutable_ = true; |
| 262 } | 281 } |
| 282 Update(feature_info); |
| 263 } | 283 } |
| 264 | 284 |
| 265 bool Texture::CanGenerateMipmaps( | 285 bool Texture::CanGenerateMipmaps( |
| 266 const FeatureInfo* feature_info) const { | 286 const FeatureInfo* feature_info) const { |
| 267 if ((npot() && !feature_info->feature_flags().npot_ok) || | 287 if ((npot() && !feature_info->feature_flags().npot_ok) || |
| 268 level_infos_.empty() || | 288 level_infos_.empty() || |
| 269 target_ == GL_TEXTURE_EXTERNAL_OES || | 289 target_ == GL_TEXTURE_EXTERNAL_OES || |
| 270 target_ == GL_TEXTURE_RECTANGLE_ARB) { | 290 target_ == GL_TEXTURE_RECTANGLE_ARB) { |
| 271 return false; | 291 return false; |
| 272 } | 292 } |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 NOTREACHED(); | 530 NOTREACHED(); |
| 511 return GL_INVALID_ENUM; | 531 return GL_INVALID_ENUM; |
| 512 } | 532 } |
| 513 Update(feature_info); | 533 Update(feature_info); |
| 514 UpdateCleared(); | 534 UpdateCleared(); |
| 515 return GL_NO_ERROR; | 535 return GL_NO_ERROR; |
| 516 } | 536 } |
| 517 | 537 |
| 518 void Texture::Update(const FeatureInfo* feature_info) { | 538 void Texture::Update(const FeatureInfo* feature_info) { |
| 519 // Update npot status. | 539 // Update npot status. |
| 520 npot_ = false; | 540 // Assume GL_TEXTURE_EXTERNAL_OES textures are npot, all others |
| 541 npot_ = target_ == GL_TEXTURE_EXTERNAL_OES; |
| 521 | 542 |
| 522 if (level_infos_.empty()) { | 543 if (level_infos_.empty()) { |
| 523 texture_complete_ = false; | 544 texture_complete_ = false; |
| 524 cube_complete_ = false; | 545 cube_complete_ = false; |
| 525 return; | 546 return; |
| 526 } | 547 } |
| 527 | 548 |
| 528 // checks that the first mip of any face is npot. | 549 // checks that the first mip of any face is npot. |
| 529 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 550 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
| 530 const Texture::LevelInfo& info = level_infos_[ii][0]; | 551 const Texture::LevelInfo& info = level_infos_[ii][0]; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && | 845 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && |
| 825 (target != GL_TEXTURE_2D || (depth == 1)); | 846 (target != GL_TEXTURE_2D || (depth == 1)); |
| 826 } | 847 } |
| 827 | 848 |
| 828 void TextureManager::SetTarget(Texture* texture, GLenum target) { | 849 void TextureManager::SetTarget(Texture* texture, GLenum target) { |
| 829 DCHECK(texture); | 850 DCHECK(texture); |
| 830 if (!texture->CanRender(feature_info_)) { | 851 if (!texture->CanRender(feature_info_)) { |
| 831 DCHECK_NE(0, num_unrenderable_textures_); | 852 DCHECK_NE(0, num_unrenderable_textures_); |
| 832 --num_unrenderable_textures_; | 853 --num_unrenderable_textures_; |
| 833 } | 854 } |
| 834 texture->SetTarget(target, MaxLevelsForTarget(target)); | 855 texture->SetTarget(feature_info_, target, MaxLevelsForTarget(target)); |
| 835 if (!texture->CanRender(feature_info_)) { | 856 if (!texture->CanRender(feature_info_)) { |
| 836 ++num_unrenderable_textures_; | 857 ++num_unrenderable_textures_; |
| 837 } | 858 } |
| 859 } |
| 860 |
| 861 void TextureManager::SetStreamTexture(Texture* texture, bool stream_texture) { |
| 862 DCHECK(texture); |
| 863 if (!texture->CanRender(feature_info_)) { |
| 864 DCHECK_NE(0, num_unrenderable_textures_); |
| 865 --num_unrenderable_textures_; |
| 866 } |
| 867 texture->SetStreamTexture(stream_texture); |
| 868 if (!texture->CanRender(feature_info_)) { |
| 869 ++num_unrenderable_textures_; |
| 870 } |
| 838 } | 871 } |
| 839 | 872 |
| 840 void TextureManager::SetLevelCleared(Texture* texture, | 873 void TextureManager::SetLevelCleared(Texture* texture, |
| 841 GLenum target, | 874 GLenum target, |
| 842 GLint level, | 875 GLint level, |
| 843 bool cleared) { | 876 bool cleared) { |
| 844 DCHECK(texture); | 877 DCHECK(texture); |
| 845 if (!texture->SafeToRenderFrom()) { | 878 if (!texture->SafeToRenderFrom()) { |
| 846 DCHECK_NE(0, num_unsafe_textures_); | 879 DCHECK_NE(0, num_unsafe_textures_); |
| 847 --num_unsafe_textures_; | 880 --num_unsafe_textures_; |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 void TextureManager::AddToSignature( | 1273 void TextureManager::AddToSignature( |
| 1241 Texture* texture, | 1274 Texture* texture, |
| 1242 GLenum target, | 1275 GLenum target, |
| 1243 GLint level, | 1276 GLint level, |
| 1244 std::string* signature) const { | 1277 std::string* signature) const { |
| 1245 texture->AddToSignature(feature_info_.get(), target, level, signature); | 1278 texture->AddToSignature(feature_info_.get(), target, level, signature); |
| 1246 } | 1279 } |
| 1247 | 1280 |
| 1248 } // namespace gles2 | 1281 } // namespace gles2 |
| 1249 } // namespace gpu | 1282 } // namespace gpu |
| OLD | NEW |