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