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

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

Issue 16293004: Update gpu/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
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/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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // Can't generate mips for depth or stencil textures. 349 // Can't generate mips for depth or stencil textures.
350 const Texture::LevelInfo& first = level_infos_[0][0]; 350 const Texture::LevelInfo& first = level_infos_[0][0];
351 uint32 channels = GLES2Util::GetChannelsForFormat(first.format); 351 uint32 channels = GLES2Util::GetChannelsForFormat(first.format);
352 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { 352 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) {
353 return false; 353 return false;
354 } 354 }
355 355
356 // TODO(gman): Check internal_format, format and type. 356 // TODO(gman): Check internal_format, format and type.
357 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { 357 for (size_t ii = 0; ii < level_infos_.size(); ++ii) {
358 const LevelInfo& info = level_infos_[ii][0]; 358 const LevelInfo& info = level_infos_[ii][0];
359 if ((info.target == 0) || 359 if ((info.target == 0) || (info.width != first.width) ||
360 (info.width != first.width) || 360 (info.height != first.height) || (info.depth != 1) ||
361 (info.height != first.height) ||
362 (info.depth != 1) ||
363 (info.format != first.format) || 361 (info.format != first.format) ||
364 (info.internal_format != first.internal_format) || 362 (info.internal_format != first.internal_format) ||
365 (info.type != first.type) || 363 (info.type != first.type) ||
366 feature_info->validators()->compressed_texture_format.IsValid( 364 feature_info->validators()->compressed_texture_format.IsValid(
367 info.internal_format) || 365 info.internal_format) ||
368 info.image) { 366 info.image.get()) {
369 return false; 367 return false;
370 } 368 }
371 } 369 }
372 return true; 370 return true;
373 } 371 }
374 372
375 void Texture::SetLevelCleared(GLenum target, GLint level, bool cleared) { 373 void Texture::SetLevelCleared(GLenum target, GLint level, bool cleared) {
376 DCHECK_GE(level, 0); 374 DCHECK_GE(level, 0);
377 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), 375 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)),
378 level_infos_.size()); 376 level_infos_.size());
379 DCHECK_LT(static_cast<size_t>(level), 377 DCHECK_LT(static_cast<size_t>(level),
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 UpdateCanRenderCondition(); 784 UpdateCanRenderCondition();
787 } 785 }
788 786
789 gfx::GLImage* Texture::GetLevelImage( 787 gfx::GLImage* Texture::GetLevelImage(
790 GLint target, GLint level) const { 788 GLint target, GLint level) const {
791 size_t face_index = GLTargetToFaceIndex(target); 789 size_t face_index = GLTargetToFaceIndex(target);
792 if (level >= 0 && face_index < level_infos_.size() && 790 if (level >= 0 && face_index < level_infos_.size() &&
793 static_cast<size_t>(level) < level_infos_[face_index].size()) { 791 static_cast<size_t>(level) < level_infos_[face_index].size()) {
794 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; 792 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level];
795 if (info.target != 0) { 793 if (info.target != 0) {
796 return info.image; 794 return info.image.get();
797 } 795 }
798 } 796 }
799 return 0; 797 return 0;
800 } 798 }
801 799
802 800
803 TextureRef::TextureRef(TextureManager* manager, 801 TextureRef::TextureRef(TextureManager* manager,
804 GLuint client_id, 802 GLuint client_id,
805 Texture* texture) 803 Texture* texture)
806 : manager_(manager), 804 : manager_(manager),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 } else { 899 } else {
902 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, 900 glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
903 GL_UNSIGNED_BYTE, black); 901 GL_UNSIGNED_BYTE, black);
904 } 902 }
905 } 903 }
906 } 904 }
907 glBindTexture(target, 0); 905 glBindTexture(target, 0);
908 906
909 scoped_refptr<TextureRef> default_texture( 907 scoped_refptr<TextureRef> default_texture(
910 TextureRef::Create(this, 0, ids[1])); 908 TextureRef::Create(this, 0, ids[1]));
911 SetTarget(default_texture, target); 909 SetTarget(default_texture.get(), target);
912 if (needs_faces) { 910 if (needs_faces) {
913 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { 911 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) {
914 SetLevelInfo( 912 SetLevelInfo(default_texture.get(),
915 default_texture, GLES2Util::IndexToGLFaceTarget(ii), 913 GLES2Util::IndexToGLFaceTarget(ii),
916 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); 914 0,
915 GL_RGBA,
916 1,
917 1,
918 1,
919 0,
920 GL_RGBA,
921 GL_UNSIGNED_BYTE,
922 true);
917 } 923 }
918 } else { 924 } else {
919 if (needs_initialization) { 925 if (needs_initialization) {
920 SetLevelInfo(default_texture, 926 SetLevelInfo(default_texture.get(),
921 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, 927 GL_TEXTURE_2D,
922 GL_RGBA, GL_UNSIGNED_BYTE, true); 928 0,
929 GL_RGBA,
930 1,
931 1,
932 1,
933 0,
934 GL_RGBA,
935 GL_UNSIGNED_BYTE,
936 true);
923 } else { 937 } else {
924 SetLevelInfo( 938 SetLevelInfo(default_texture.get(),
925 default_texture, GL_TEXTURE_EXTERNAL_OES, 0, 939 GL_TEXTURE_EXTERNAL_OES,
926 GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); 940 0,
941 GL_RGBA,
942 1,
943 1,
944 1,
945 0,
946 GL_RGBA,
947 GL_UNSIGNED_BYTE,
948 true);
927 } 949 }
928 } 950 }
929 951
930 *black_texture = ids[0]; 952 *black_texture = ids[0];
931 return default_texture; 953 return default_texture;
932 } 954 }
933 955
934 bool TextureManager::ValidForTarget( 956 bool TextureManager::ValidForTarget(
935 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) { 957 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) {
936 GLsizei max_size = MaxSizeForTarget(target) >> level; 958 GLsizei max_size = MaxSizeForTarget(target) >> level;
937 return level >= 0 && 959 return level >= 0 &&
938 width >= 0 && 960 width >= 0 &&
939 height >= 0 && 961 height >= 0 &&
940 depth >= 0 && 962 depth >= 0 &&
941 level < MaxLevelsForTarget(target) && 963 level < MaxLevelsForTarget(target) &&
942 width <= max_size && 964 width <= max_size &&
943 height <= max_size && 965 height <= max_size &&
944 depth <= max_size && 966 depth <= max_size &&
945 (level == 0 || feature_info_->feature_flags().npot_ok || 967 (level == 0 || feature_info_->feature_flags().npot_ok ||
946 (!GLES2Util::IsNPOT(width) && 968 (!GLES2Util::IsNPOT(width) &&
947 !GLES2Util::IsNPOT(height) && 969 !GLES2Util::IsNPOT(height) &&
948 !GLES2Util::IsNPOT(depth))) && 970 !GLES2Util::IsNPOT(depth))) &&
949 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && 971 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) &&
950 (target != GL_TEXTURE_2D || (depth == 1)); 972 (target != GL_TEXTURE_2D || (depth == 1));
951 } 973 }
952 974
953 void TextureManager::SetTarget(TextureRef* ref, GLenum target) { 975 void TextureManager::SetTarget(TextureRef* ref, GLenum target) {
954 DCHECK(ref); 976 DCHECK(ref);
955 ref->texture()->SetTarget(feature_info_, target, MaxLevelsForTarget(target)); 977 ref->texture()
978 ->SetTarget(feature_info_.get(), target, MaxLevelsForTarget(target));
956 } 979 }
957 980
958 void TextureManager::SetStreamTexture(TextureRef* ref, bool stream_texture) { 981 void TextureManager::SetStreamTexture(TextureRef* ref, bool stream_texture) {
959 DCHECK(ref); 982 DCHECK(ref);
960 ref->texture()->SetStreamTexture(stream_texture); 983 ref->texture()->SetStreamTexture(stream_texture);
961 } 984 }
962 985
963 void TextureManager::SetLevelCleared(TextureRef* ref, 986 void TextureManager::SetLevelCleared(TextureRef* ref,
964 GLenum target, 987 GLenum target,
965 GLint level, 988 GLint level,
(...skipping 30 matching lines...) Expand all
996 GLsizei height, 1019 GLsizei height,
997 GLsizei depth, 1020 GLsizei depth,
998 GLint border, 1021 GLint border,
999 GLenum format, 1022 GLenum format,
1000 GLenum type, 1023 GLenum type,
1001 bool cleared) { 1024 bool cleared) {
1002 DCHECK(ref); 1025 DCHECK(ref);
1003 Texture* texture = ref->texture(); 1026 Texture* texture = ref->texture();
1004 1027
1005 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); 1028 texture->GetMemTracker()->TrackMemFree(texture->estimated_size());
1006 texture->SetLevelInfo( 1029 texture->SetLevelInfo(feature_info_.get(),
1007 feature_info_, target, level, internal_format, width, height, depth, 1030 target,
1008 border, format, type, cleared); 1031 level,
1032 internal_format,
1033 width,
1034 height,
1035 depth,
1036 border,
1037 format,
1038 type,
1039 cleared);
1009 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); 1040 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size());
1010 } 1041 }
1011 1042
1012 Texture* TextureManager::Produce(TextureRef* ref) { 1043 Texture* TextureManager::Produce(TextureRef* ref) {
1013 DCHECK(ref); 1044 DCHECK(ref);
1014 Texture* texture = ref->texture(); 1045 Texture* texture = ref->texture();
1015 if (!texture->owned_) 1046 if (!texture->owned_)
1016 return NULL; 1047 return NULL;
1017 return texture; 1048 return texture;
1018 } 1049 }
1019 1050
1020 TextureRef* TextureManager::Consume( 1051 TextureRef* TextureManager::Consume(
1021 GLuint client_id, 1052 GLuint client_id,
1022 Texture* texture) { 1053 Texture* texture) {
1023 DCHECK(client_id); 1054 DCHECK(client_id);
1024 scoped_refptr<TextureRef> ref(new TextureRef(this, client_id, texture)); 1055 scoped_refptr<TextureRef> ref(new TextureRef(this, client_id, texture));
1025 bool result = textures_.insert(std::make_pair(client_id, ref)).second; 1056 bool result = textures_.insert(std::make_pair(client_id, ref)).second;
1026 DCHECK(result); 1057 DCHECK(result);
1027 return ref.get(); 1058 return ref.get();
1028 } 1059 }
1029 1060
1030 void TextureManager::SetParameter( 1061 void TextureManager::SetParameter(
1031 const char* function_name, ErrorState* error_state, 1062 const char* function_name, ErrorState* error_state,
1032 TextureRef* ref, GLenum pname, GLint param) { 1063 TextureRef* ref, GLenum pname, GLint param) {
1033 DCHECK(error_state); 1064 DCHECK(error_state);
1034 DCHECK(ref); 1065 DCHECK(ref);
1035 Texture* texture = ref->texture(); 1066 Texture* texture = ref->texture();
1036 GLenum result = texture->SetParameter(feature_info_, pname, param); 1067 GLenum result = texture->SetParameter(feature_info_.get(), pname, param);
1037 if (result != GL_NO_ERROR) { 1068 if (result != GL_NO_ERROR) {
1038 if (result == GL_INVALID_ENUM) { 1069 if (result == GL_INVALID_ENUM) {
1039 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( 1070 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(
1040 error_state, function_name, param, "param"); 1071 error_state, function_name, param, "param");
1041 } else { 1072 } else {
1042 ERRORSTATE_SET_GL_ERROR_INVALID_PARAM( 1073 ERRORSTATE_SET_GL_ERROR_INVALID_PARAM(
1043 error_state, result, function_name, pname, static_cast<GLint>(param)); 1074 error_state, result, function_name, pname, static_cast<GLint>(param));
1044 } 1075 }
1045 } else { 1076 } else {
1046 // Texture tracking pools exist only for the command decoder, so 1077 // Texture tracking pools exist only for the command decoder, so
1047 // do not pass them on to the native GL implementation. 1078 // do not pass them on to the native GL implementation.
1048 if (pname != GL_TEXTURE_POOL_CHROMIUM) { 1079 if (pname != GL_TEXTURE_POOL_CHROMIUM) {
1049 glTexParameteri(texture->target(), pname, param); 1080 glTexParameteri(texture->target(), pname, param);
1050 } 1081 }
1051 } 1082 }
1052 } 1083 }
1053 1084
1054 bool TextureManager::MarkMipmapsGenerated(TextureRef* ref) { 1085 bool TextureManager::MarkMipmapsGenerated(TextureRef* ref) {
1055 DCHECK(ref); 1086 DCHECK(ref);
1056 Texture* texture = ref->texture(); 1087 Texture* texture = ref->texture();
1057 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); 1088 texture->GetMemTracker()->TrackMemFree(texture->estimated_size());
1058 bool result = texture->MarkMipmapsGenerated(feature_info_); 1089 bool result = texture->MarkMipmapsGenerated(feature_info_.get());
1059 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); 1090 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size());
1060 return result; 1091 return result;
1061 } 1092 }
1062 1093
1063 TextureRef* TextureManager::CreateTexture( 1094 TextureRef* TextureManager::CreateTexture(
1064 GLuint client_id, GLuint service_id) { 1095 GLuint client_id, GLuint service_id) {
1065 DCHECK_NE(0u, service_id); 1096 DCHECK_NE(0u, service_id);
1066 scoped_refptr<TextureRef> ref(TextureRef::Create( 1097 scoped_refptr<TextureRef> ref(TextureRef::Create(
1067 this, client_id, service_id)); 1098 this, client_id, service_id));
1068 std::pair<TextureMap::iterator, bool> result = 1099 std::pair<TextureMap::iterator, bool> result =
(...skipping 15 matching lines...) Expand all
1084 textures_.erase(it); 1115 textures_.erase(it);
1085 } 1116 }
1086 } 1117 }
1087 1118
1088 void TextureManager::StartTracking(TextureRef* ref) { 1119 void TextureManager::StartTracking(TextureRef* ref) {
1089 Texture* texture = ref->texture(); 1120 Texture* texture = ref->texture();
1090 ++texture_count_; 1121 ++texture_count_;
1091 num_uncleared_mips_ += texture->num_uncleared_mips(); 1122 num_uncleared_mips_ += texture->num_uncleared_mips();
1092 if (!texture->SafeToRenderFrom()) 1123 if (!texture->SafeToRenderFrom())
1093 ++num_unsafe_textures_; 1124 ++num_unsafe_textures_;
1094 if (!texture->CanRender(feature_info_)) 1125 if (!texture->CanRender(feature_info_.get()))
1095 ++num_unrenderable_textures_; 1126 ++num_unrenderable_textures_;
1096 } 1127 }
1097 1128
1098 void TextureManager::StopTracking(TextureRef* ref) { 1129 void TextureManager::StopTracking(TextureRef* ref) {
1099 FOR_EACH_OBSERVER(DestructionObserver, 1130 FOR_EACH_OBSERVER(DestructionObserver,
1100 destruction_observers_, 1131 destruction_observers_,
1101 OnTextureRefDestroying(ref)); 1132 OnTextureRefDestroying(ref));
1102 1133
1103 Texture* texture = ref->texture(); 1134 Texture* texture = ref->texture();
1104 --texture_count_; 1135 --texture_count_;
1105 if (!texture->CanRender(feature_info_)) { 1136 if (!texture->CanRender(feature_info_.get())) {
1106 DCHECK_NE(0, num_unrenderable_textures_); 1137 DCHECK_NE(0, num_unrenderable_textures_);
1107 --num_unrenderable_textures_; 1138 --num_unrenderable_textures_;
1108 } 1139 }
1109 if (!texture->SafeToRenderFrom()) { 1140 if (!texture->SafeToRenderFrom()) {
1110 DCHECK_NE(0, num_unsafe_textures_); 1141 DCHECK_NE(0, num_unsafe_textures_);
1111 --num_unsafe_textures_; 1142 --num_unsafe_textures_;
1112 } 1143 }
1113 num_uncleared_mips_ -= texture->num_uncleared_mips(); 1144 num_uncleared_mips_ -= texture->num_uncleared_mips();
1114 DCHECK_GE(num_uncleared_mips_, 0); 1145 DCHECK_GE(num_uncleared_mips_, 0);
1115 } 1146 }
(...skipping 28 matching lines...) Expand all
1144 GLsizei width, GLsizei height, GLsizei depth) { 1175 GLsizei width, GLsizei height, GLsizei depth) {
1145 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); 1176 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth));
1146 } 1177 }
1147 1178
1148 void TextureManager::SetLevelImage( 1179 void TextureManager::SetLevelImage(
1149 TextureRef* ref, 1180 TextureRef* ref,
1150 GLenum target, 1181 GLenum target,
1151 GLint level, 1182 GLint level,
1152 gfx::GLImage* image) { 1183 gfx::GLImage* image) {
1153 DCHECK(ref); 1184 DCHECK(ref);
1154 ref->texture()->SetLevelImage(feature_info_, target, level, image); 1185 ref->texture()->SetLevelImage(feature_info_.get(), target, level, image);
1155 } 1186 }
1156 1187
1157 void TextureManager::AddToSignature( 1188 void TextureManager::AddToSignature(
1158 TextureRef* ref, 1189 TextureRef* ref,
1159 GLenum target, 1190 GLenum target,
1160 GLint level, 1191 GLint level,
1161 std::string* signature) const { 1192 std::string* signature) const {
1162 ref->texture()->AddToSignature(feature_info_.get(), target, level, signature); 1193 ref->texture()->AddToSignature(feature_info_.get(), target, level, signature);
1163 } 1194 }
1164 1195
(...skipping 23 matching lines...) Expand all
1188 } 1219 }
1189 1220
1190 void TextureManager::IncFramebufferStateChangeCount() { 1221 void TextureManager::IncFramebufferStateChangeCount() {
1191 if (framebuffer_manager_) 1222 if (framebuffer_manager_)
1192 framebuffer_manager_->IncFramebufferStateChangeCount(); 1223 framebuffer_manager_->IncFramebufferStateChangeCount();
1193 1224
1194 } 1225 }
1195 1226
1196 } // namespace gles2 1227 } // namespace gles2
1197 } // namespace gpu 1228 } // 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