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/context_state.h" | 9 #include "gpu/command_buffer/service/context_state.h" |
10 #include "gpu/command_buffer/service/error_state.h" | 10 #include "gpu/command_buffer/service/error_state.h" |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 TextureRef::~TextureRef() { | 889 TextureRef::~TextureRef() { |
890 manager_->StopTracking(this); | 890 manager_->StopTracking(this); |
891 texture_->RemoveTextureRef(this, manager_->have_context_); | 891 texture_->RemoveTextureRef(this, manager_->have_context_); |
892 manager_ = NULL; | 892 manager_ = NULL; |
893 } | 893 } |
894 | 894 |
895 TextureManager::TextureManager(MemoryTracker* memory_tracker, | 895 TextureManager::TextureManager(MemoryTracker* memory_tracker, |
896 FeatureInfo* feature_info, | 896 FeatureInfo* feature_info, |
897 GLint max_texture_size, | 897 GLint max_texture_size, |
898 GLint max_cube_map_texture_size) | 898 GLint max_cube_map_texture_size) |
899 : memory_tracker_managed_(new MemoryTypeTracker(memory_tracker, | 899 : memory_tracker_managed_( |
900 MemoryTracker::kManaged)), | 900 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)), |
901 memory_tracker_unmanaged_( | 901 memory_tracker_unmanaged_( |
902 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), | 902 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), |
903 feature_info_(feature_info), | 903 feature_info_(feature_info), |
904 framebuffer_manager_(NULL), | 904 framebuffer_manager_(NULL), |
905 max_texture_size_(max_texture_size), | 905 max_texture_size_(max_texture_size), |
906 max_cube_map_texture_size_(max_cube_map_texture_size), | 906 max_cube_map_texture_size_(max_cube_map_texture_size), |
907 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, | 907 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, |
908 max_texture_size, | 908 max_texture_size, |
909 max_texture_size, | 909 max_texture_size, |
910 max_texture_size)), | 910 max_texture_size)), |
911 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, | 911 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, |
912 max_cube_map_texture_size, | 912 max_cube_map_texture_size, |
913 max_cube_map_texture_size, | 913 max_cube_map_texture_size, |
914 max_cube_map_texture_size)), | 914 max_cube_map_texture_size)), |
| 915 use_default_textures_(false), |
915 num_unrenderable_textures_(0), | 916 num_unrenderable_textures_(0), |
916 num_unsafe_textures_(0), | 917 num_unsafe_textures_(0), |
917 num_uncleared_mips_(0), | 918 num_uncleared_mips_(0), |
918 num_images_(0), | 919 num_images_(0), |
919 texture_count_(0), | 920 texture_count_(0), |
920 have_context_(true) { | 921 have_context_(true) { |
921 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 922 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
922 black_texture_ids_[ii] = 0; | 923 black_texture_ids_[ii] = 0; |
923 } | 924 } |
924 } | 925 } |
(...skipping 27 matching lines...) Expand all Loading... |
952 GLuint* black_texture) { | 953 GLuint* black_texture) { |
953 static uint8 black[] = {0, 0, 0, 255}; | 954 static uint8 black[] = {0, 0, 0, 255}; |
954 | 955 |
955 // Sampling a texture not associated with any EGLImage sibling will return | 956 // Sampling a texture not associated with any EGLImage sibling will return |
956 // black values according to the spec. | 957 // black values according to the spec. |
957 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); | 958 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); |
958 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); | 959 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); |
959 | 960 |
960 // Make default textures and texture for replacing non-renderable textures. | 961 // Make default textures and texture for replacing non-renderable textures. |
961 GLuint ids[2]; | 962 GLuint ids[2]; |
962 glGenTextures(arraysize(ids), ids); | 963 const unsigned long num_ids = use_default_textures_ ? 2 : 1; |
963 for (unsigned long ii = 0; ii < arraysize(ids); ++ii) { | 964 glGenTextures(num_ids, ids); |
| 965 for (unsigned long ii = 0; ii < num_ids; ++ii) { |
964 glBindTexture(target, ids[ii]); | 966 glBindTexture(target, ids[ii]); |
965 if (needs_initialization) { | 967 if (needs_initialization) { |
966 if (needs_faces) { | 968 if (needs_faces) { |
967 for (int jj = 0; jj < GLES2Util::kNumFaces; ++jj) { | 969 for (int jj = 0; jj < GLES2Util::kNumFaces; ++jj) { |
968 glTexImage2D(GLES2Util::IndexToGLFaceTarget(jj), 0, GL_RGBA, 1, 1, 0, | 970 glTexImage2D(GLES2Util::IndexToGLFaceTarget(jj), 0, GL_RGBA, 1, 1, 0, |
969 GL_RGBA, GL_UNSIGNED_BYTE, black); | 971 GL_RGBA, GL_UNSIGNED_BYTE, black); |
970 } | 972 } |
971 } else { | 973 } else { |
972 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, | 974 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, |
973 GL_UNSIGNED_BYTE, black); | 975 GL_UNSIGNED_BYTE, black); |
974 } | 976 } |
975 } | 977 } |
976 } | 978 } |
977 glBindTexture(target, 0); | 979 glBindTexture(target, 0); |
978 | 980 |
979 scoped_refptr<TextureRef> default_texture( | 981 scoped_refptr<TextureRef> default_texture; |
980 TextureRef::Create(this, 0, ids[1])); | 982 if (use_default_textures_) { |
981 SetTarget(default_texture.get(), target); | 983 default_texture = TextureRef::Create(this, 0, ids[1]); |
982 if (needs_faces) { | 984 SetTarget(default_texture.get(), target); |
983 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | 985 if (needs_faces) { |
984 SetLevelInfo(default_texture.get(), | 986 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
985 GLES2Util::IndexToGLFaceTarget(ii), | 987 SetLevelInfo(default_texture.get(), |
986 0, | 988 GLES2Util::IndexToGLFaceTarget(ii), |
987 GL_RGBA, | 989 0, |
988 1, | 990 GL_RGBA, |
989 1, | 991 1, |
990 1, | 992 1, |
991 0, | 993 1, |
992 GL_RGBA, | 994 0, |
993 GL_UNSIGNED_BYTE, | 995 GL_RGBA, |
994 true); | 996 GL_UNSIGNED_BYTE, |
995 } | 997 true); |
996 } else { | 998 } |
997 if (needs_initialization) { | |
998 SetLevelInfo(default_texture.get(), | |
999 GL_TEXTURE_2D, | |
1000 0, | |
1001 GL_RGBA, | |
1002 1, | |
1003 1, | |
1004 1, | |
1005 0, | |
1006 GL_RGBA, | |
1007 GL_UNSIGNED_BYTE, | |
1008 true); | |
1009 } else { | 999 } else { |
1010 SetLevelInfo(default_texture.get(), | 1000 if (needs_initialization) { |
1011 GL_TEXTURE_EXTERNAL_OES, | 1001 SetLevelInfo(default_texture.get(), |
1012 0, | 1002 GL_TEXTURE_2D, |
1013 GL_RGBA, | 1003 0, |
1014 1, | 1004 GL_RGBA, |
1015 1, | 1005 1, |
1016 1, | 1006 1, |
1017 0, | 1007 1, |
1018 GL_RGBA, | 1008 0, |
1019 GL_UNSIGNED_BYTE, | 1009 GL_RGBA, |
1020 true); | 1010 GL_UNSIGNED_BYTE, |
| 1011 true); |
| 1012 } else { |
| 1013 SetLevelInfo(default_texture.get(), |
| 1014 GL_TEXTURE_EXTERNAL_OES, |
| 1015 0, |
| 1016 GL_RGBA, |
| 1017 1, |
| 1018 1, |
| 1019 1, |
| 1020 0, |
| 1021 GL_RGBA, |
| 1022 GL_UNSIGNED_BYTE, |
| 1023 true); |
| 1024 } |
1021 } | 1025 } |
1022 } | 1026 } |
1023 | 1027 |
1024 *black_texture = ids[0]; | 1028 *black_texture = ids[0]; |
1025 return default_texture; | 1029 return default_texture; |
1026 } | 1030 } |
1027 | 1031 |
1028 bool TextureManager::ValidForTarget( | 1032 bool TextureManager::ValidForTarget( |
1029 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) { | 1033 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) { |
1030 GLsizei max_size = MaxSizeForTarget(target) >> level; | 1034 GLsizei max_size = MaxSizeForTarget(target) >> level; |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 } | 1571 } |
1568 | 1572 |
1569 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 1573 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
1570 texture_state_->texture_upload_count++; | 1574 texture_state_->texture_upload_count++; |
1571 texture_state_->total_texture_upload_time += | 1575 texture_state_->total_texture_upload_time += |
1572 base::TimeTicks::HighResNow() - begin_time_; | 1576 base::TimeTicks::HighResNow() - begin_time_; |
1573 } | 1577 } |
1574 | 1578 |
1575 } // namespace gles2 | 1579 } // namespace gles2 |
1576 } // namespace gpu | 1580 } // namespace gpu |
OLD | NEW |