Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: gpu/command_buffer/service/texture_manager.cc

Issue 224763002: Remove default textures in (!bind_generates_resource) context groups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use kBindGeneratesResource in context_group_unittest.cc. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 888
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 bool use_default_textures)
900 MemoryTracker::kManaged)), 900 : memory_tracker_managed_(
901 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)),
901 memory_tracker_unmanaged_( 902 memory_tracker_unmanaged_(
902 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), 903 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)),
903 feature_info_(feature_info), 904 feature_info_(feature_info),
904 framebuffer_manager_(NULL), 905 framebuffer_manager_(NULL),
905 max_texture_size_(max_texture_size), 906 max_texture_size_(max_texture_size),
906 max_cube_map_texture_size_(max_cube_map_texture_size), 907 max_cube_map_texture_size_(max_cube_map_texture_size),
907 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, 908 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D,
908 max_texture_size, 909 max_texture_size,
909 max_texture_size, 910 max_texture_size,
910 max_texture_size)), 911 max_texture_size)),
911 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, 912 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP,
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 max_cube_map_texture_size)),
916 use_default_textures_(use_default_textures),
915 num_unrenderable_textures_(0), 917 num_unrenderable_textures_(0),
916 num_unsafe_textures_(0), 918 num_unsafe_textures_(0),
917 num_uncleared_mips_(0), 919 num_uncleared_mips_(0),
918 num_images_(0), 920 num_images_(0),
919 texture_count_(0), 921 texture_count_(0),
920 have_context_(true) { 922 have_context_(true) {
921 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { 923 for (int ii = 0; ii < kNumDefaultTextures; ++ii) {
922 black_texture_ids_[ii] = 0; 924 black_texture_ids_[ii] = 0;
923 } 925 }
924 } 926 }
(...skipping 27 matching lines...) Expand all
952 GLuint* black_texture) { 954 GLuint* black_texture) {
953 static uint8 black[] = {0, 0, 0, 255}; 955 static uint8 black[] = {0, 0, 0, 255};
954 956
955 // Sampling a texture not associated with any EGLImage sibling will return 957 // Sampling a texture not associated with any EGLImage sibling will return
956 // black values according to the spec. 958 // black values according to the spec.
957 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); 959 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES);
958 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); 960 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP);
959 961
960 // Make default textures and texture for replacing non-renderable textures. 962 // Make default textures and texture for replacing non-renderable textures.
961 GLuint ids[2]; 963 GLuint ids[2];
962 glGenTextures(arraysize(ids), ids); 964 const unsigned long num_ids = use_default_textures_ ? 2 : 1;
963 for (unsigned long ii = 0; ii < arraysize(ids); ++ii) { 965 glGenTextures(num_ids, ids);
966 for (unsigned long ii = 0; ii < num_ids; ++ii) {
964 glBindTexture(target, ids[ii]); 967 glBindTexture(target, ids[ii]);
965 if (needs_initialization) { 968 if (needs_initialization) {
966 if (needs_faces) { 969 if (needs_faces) {
967 for (int jj = 0; jj < GLES2Util::kNumFaces; ++jj) { 970 for (int jj = 0; jj < GLES2Util::kNumFaces; ++jj) {
968 glTexImage2D(GLES2Util::IndexToGLFaceTarget(jj), 0, GL_RGBA, 1, 1, 0, 971 glTexImage2D(GLES2Util::IndexToGLFaceTarget(jj), 0, GL_RGBA, 1, 1, 0,
969 GL_RGBA, GL_UNSIGNED_BYTE, black); 972 GL_RGBA, GL_UNSIGNED_BYTE, black);
970 } 973 }
971 } else { 974 } else {
972 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, 975 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
973 GL_UNSIGNED_BYTE, black); 976 GL_UNSIGNED_BYTE, black);
974 } 977 }
975 } 978 }
976 } 979 }
977 glBindTexture(target, 0); 980 glBindTexture(target, 0);
978 981
979 scoped_refptr<TextureRef> default_texture( 982 scoped_refptr<TextureRef> default_texture;
980 TextureRef::Create(this, 0, ids[1])); 983 if (use_default_textures_) {
981 SetTarget(default_texture.get(), target); 984 default_texture = TextureRef::Create(this, 0, ids[1]);
982 if (needs_faces) { 985 SetTarget(default_texture.get(), target);
983 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { 986 if (needs_faces) {
984 SetLevelInfo(default_texture.get(), 987 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) {
985 GLES2Util::IndexToGLFaceTarget(ii), 988 SetLevelInfo(default_texture.get(),
986 0, 989 GLES2Util::IndexToGLFaceTarget(ii),
987 GL_RGBA, 990 0,
988 1, 991 GL_RGBA,
989 1, 992 1,
990 1, 993 1,
991 0, 994 1,
992 GL_RGBA, 995 0,
993 GL_UNSIGNED_BYTE, 996 GL_RGBA,
994 true); 997 GL_UNSIGNED_BYTE,
995 } 998 true);
996 } else { 999 }
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 { 1000 } else {
1010 SetLevelInfo(default_texture.get(), 1001 if (needs_initialization) {
1011 GL_TEXTURE_EXTERNAL_OES, 1002 SetLevelInfo(default_texture.get(),
1012 0, 1003 GL_TEXTURE_2D,
1013 GL_RGBA, 1004 0,
1014 1, 1005 GL_RGBA,
1015 1, 1006 1,
1016 1, 1007 1,
1017 0, 1008 1,
1018 GL_RGBA, 1009 0,
1019 GL_UNSIGNED_BYTE, 1010 GL_RGBA,
1020 true); 1011 GL_UNSIGNED_BYTE,
1012 true);
1013 } else {
1014 SetLevelInfo(default_texture.get(),
1015 GL_TEXTURE_EXTERNAL_OES,
1016 0,
1017 GL_RGBA,
1018 1,
1019 1,
1020 1,
1021 0,
1022 GL_RGBA,
1023 GL_UNSIGNED_BYTE,
1024 true);
1025 }
1021 } 1026 }
1022 } 1027 }
1023 1028
1024 *black_texture = ids[0]; 1029 *black_texture = ids[0];
1025 return default_texture; 1030 return default_texture;
1026 } 1031 }
1027 1032
1028 bool TextureManager::ValidForTarget( 1033 bool TextureManager::ValidForTarget(
1029 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) { 1034 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) {
1030 GLsizei max_size = MaxSizeForTarget(target) >> level; 1035 GLsizei max_size = MaxSizeForTarget(target) >> level;
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 } 1572 }
1568 1573
1569 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { 1574 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() {
1570 texture_state_->texture_upload_count++; 1575 texture_state_->texture_upload_count++;
1571 texture_state_->total_texture_upload_time += 1576 texture_state_->total_texture_upload_time +=
1572 base::TimeTicks::HighResNow() - begin_time_; 1577 base::TimeTicks::HighResNow() - begin_time_;
1573 } 1578 }
1574 1579
1575 } // namespace gles2 1580 } // namespace gles2
1576 } // namespace gpu 1581 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | gpu/command_buffer/service/texture_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698