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

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

Issue 12717013: Add reference-counting for mailbox textures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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/feature_info.h" 9 #include "gpu/command_buffer/service/feature_info.h"
10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 owned_(true), 108 owned_(true),
109 stream_texture_(false), 109 stream_texture_(false),
110 immutable_(false), 110 immutable_(false),
111 estimated_size_(0) { 111 estimated_size_(0) {
112 if (manager_) { 112 if (manager_) {
113 manager_->StartTracking(this); 113 manager_->StartTracking(this);
114 } 114 }
115 } 115 }
116 116
117 Texture::~Texture() { 117 Texture::~Texture() {
118 DCHECK(!owned_ || !mailbox_);
119 if (mailbox_ && mailbox_->HasOneRef()) {
apatrick_chromium 2013/03/19 18:50:18 HasOneRef is a bit dangerous if there are potentia
120 bool have_context = manager_ && manager_->have_context_;
121 if (have_context) {
122 GLuint id = mailbox_->ReleaseServiceId();
123 glDeleteTextures(1, &id);
124 }
125 }
126
118 if (manager_) { 127 if (manager_) {
119 if (owned_ && manager_->have_context_) { 128 if (owned_ && manager_->have_context_) {
120 GLuint id = service_id(); 129 GLuint id = service_id();
121 glDeleteTextures(1, &id); 130 glDeleteTextures(1, &id);
122 } 131 }
123 MarkAsDeleted(); 132 MarkAsDeleted();
124 manager_->StopTracking(this); 133 manager_->StopTracking(this);
125 manager_ = NULL; 134 manager_ = NULL;
126 } 135 }
127 } 136 }
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 num_uncleared_mips_ += texture->num_uncleared_mips(); 933 num_uncleared_mips_ += texture->num_uncleared_mips();
925 if (!texture->CanRender(feature_info_)) { 934 if (!texture->CanRender(feature_info_)) {
926 ++num_unrenderable_textures_; 935 ++num_unrenderable_textures_;
927 } 936 }
928 if (!texture->SafeToRenderFrom()) { 937 if (!texture->SafeToRenderFrom()) {
929 ++num_unsafe_textures_; 938 ++num_unsafe_textures_;
930 } 939 }
931 } 940 }
932 941
933 TextureDefinition* TextureManager::Save(Texture* texture) { 942 TextureDefinition* TextureManager::Save(Texture* texture) {
934 DCHECK(texture->owned_); 943 DCHECK(texture->owned_ || texture->mailbox_);
935 944
936 if (texture->IsAttachedToFramebuffer()) 945 if (texture->IsAttachedToFramebuffer())
937 return NULL; 946 return NULL;
938 947
939 TextureDefinition::LevelInfos level_infos(texture->level_infos_.size()); 948 TextureDefinition::LevelInfos level_infos(texture->level_infos_.size());
940 for (size_t face = 0; face < level_infos.size(); ++face) { 949 for (size_t face = 0; face < level_infos.size(); ++face) {
941 GLenum target = texture->target() == GL_TEXTURE_2D ? 950 GLenum target = texture->target() == GL_TEXTURE_2D ?
942 GL_TEXTURE_2D : FaceIndexToGLTarget(face); 951 GL_TEXTURE_2D : FaceIndexToGLTarget(face);
943 for (size_t level = 0; level < texture->level_infos_[face].size(); 952 for (size_t level = 0; level < texture->level_infos_[face].size();
944 ++level) { 953 ++level) {
945 const Texture::LevelInfo& level_info = 954 const Texture::LevelInfo& level_info =
946 texture->level_infos_[face][level]; 955 texture->level_infos_[face][level];
947 level_infos[face].push_back( 956 level_infos[face].push_back(
948 TextureDefinition::LevelInfo(target, 957 TextureDefinition::LevelInfo(target,
949 level_info.internal_format, 958 level_info.internal_format,
950 level_info.width, 959 level_info.width,
951 level_info.height, 960 level_info.height,
952 level_info.depth, 961 level_info.depth,
953 level_info.border, 962 level_info.border,
954 level_info.format, 963 level_info.format,
955 level_info.type, 964 level_info.type,
956 level_info.cleared)); 965 level_info.cleared));
957 966 }
958 SetLevelInfo(texture,
959 target,
960 level,
961 GL_RGBA,
962 0,
963 0,
964 0,
965 0,
966 GL_RGBA,
967 GL_UNSIGNED_BYTE,
968 true);
969 }
970 } 967 }
971 968
972 GLuint old_service_id = texture->service_id();
973 bool immutable = texture->IsImmutable(); 969 bool immutable = texture->IsImmutable();
974 970
975 GLuint new_service_id = 0; 971 texture->mailbox_ = new TextureDefinition(texture->target(),
976 glGenTextures(1, &new_service_id); 972 texture->service_id(),
977 texture->SetServiceId(new_service_id); 973 texture->min_filter(),
apatrick_chromium 2013/03/19 18:50:18 indentation
no sievers 2013/04/02 03:07:20 Done.
978 texture->SetImmutable(false); 974 texture->mag_filter(),
979 975 texture->wrap_s(),
980 return new TextureDefinition(texture->target(), 976 texture->wrap_t(),
981 old_service_id, 977 texture->usage(),
982 texture->min_filter(), 978 immutable,
983 texture->mag_filter(), 979 level_infos);
984 texture->wrap_s(), 980 texture->SetImmutable(true);
985 texture->wrap_t(), 981 texture->SetNotOwned();
986 texture->usage(), 982 return texture->mailbox_;
987 immutable,
988 level_infos);
989 } 983 }
990 984
991 bool TextureManager::Restore( 985 bool TextureManager::Restore(
992 const char* function_name, 986 const char* function_name,
993 GLES2Decoder* decoder, 987 GLES2Decoder* decoder,
994 Texture* texture, 988 Texture* texture,
995 TextureDefinition* definition) { 989 TextureDefinition* definition) {
996 DCHECK(texture->owned_);
997
998 scoped_ptr<TextureDefinition> scoped_definition(definition);
999
1000 if (texture->IsAttachedToFramebuffer()) 990 if (texture->IsAttachedToFramebuffer())
1001 return false; 991 return false;
1002 992
1003 if (texture->target() != definition->target()) 993 if (texture->target() != definition->target())
1004 return false; 994 return false;
1005 995
1006 if (texture->level_infos_.size() != definition->level_infos().size()) 996 if (texture->level_infos_.size() != definition->level_infos().size())
1007 return false; 997 return false;
1008 998
1009 if (texture->level_infos_[0].size() != definition->level_infos()[0].size()) 999 if (texture->level_infos_[0].size() != definition->level_infos()[0].size())
(...skipping 14 matching lines...) Expand all
1024 level_info.height, 1014 level_info.height,
1025 level_info.depth, 1015 level_info.depth,
1026 level_info.border, 1016 level_info.border,
1027 level_info.format, 1017 level_info.format,
1028 level_info.type, 1018 level_info.type,
1029 level_info.cleared); 1019 level_info.cleared);
1030 } 1020 }
1031 } 1021 }
1032 1022
1033 GLuint old_service_id = texture->service_id(); 1023 GLuint old_service_id = texture->service_id();
1034 glDeleteTextures(1, &old_service_id); 1024 if (texture->mailbox_ && texture->mailbox_->HasOneRef()) {
1035 texture->SetServiceId(definition->ReleaseServiceId()); 1025 GLuint id = texture->mailbox_->ReleaseServiceId();
1036 glBindTexture(texture->target(), texture->service_id()); 1026 DCHECK(id == old_service_id);
1027 }
1028 texture->mailbox_ = definition;
1029
1030 if (old_service_id != definition->service_id()) {
1031 glDeleteTextures(1, &old_service_id);
1032 texture->SetServiceId(definition->service_id());
1033 glBindTexture(texture->target(), texture->service_id());
1034 SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER,
1035 definition->min_filter());
1036 SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER,
1037 definition->mag_filter());
1038 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S,
1039 definition->wrap_s());
1040 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T,
1041 definition->wrap_t());
1042 if (feature_info_->validators()->texture_parameter.IsValid(
1043 GL_TEXTURE_USAGE_ANGLE)) {
1044 SetParameter(function_name, decoder, texture, GL_TEXTURE_USAGE_ANGLE,
1045 definition->usage());
1046 }
1047 }
1048
1049 texture->SetNotOwned();
1037 texture->SetImmutable(definition->immutable()); 1050 texture->SetImmutable(definition->immutable());
1038 SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER,
1039 definition->min_filter());
1040 SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER,
1041 definition->mag_filter());
1042 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S,
1043 definition->wrap_s());
1044 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T,
1045 definition->wrap_t());
1046 if (feature_info_->validators()->texture_parameter.IsValid(
1047 GL_TEXTURE_USAGE_ANGLE)) {
1048 SetParameter(function_name, decoder, texture, GL_TEXTURE_USAGE_ANGLE,
1049 definition->usage());
1050 }
1051 1051
1052 return true; 1052 return true;
1053 } 1053 }
1054 1054
1055 void TextureManager::SetParameter( 1055 void TextureManager::SetParameter(
1056 const char* function_name, GLES2Decoder* decoder, 1056 const char* function_name, GLES2Decoder* decoder,
1057 Texture* texture, GLenum pname, GLint param) { 1057 Texture* texture, GLenum pname, GLint param) {
1058 DCHECK(decoder); 1058 DCHECK(decoder);
1059 DCHECK(texture); 1059 DCHECK(texture);
1060 if (!texture->CanRender(feature_info_)) { 1060 if (!texture->CanRender(feature_info_)) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 void TextureManager::AddToSignature( 1225 void TextureManager::AddToSignature(
1226 Texture* texture, 1226 Texture* texture,
1227 GLenum target, 1227 GLenum target,
1228 GLint level, 1228 GLint level,
1229 std::string* signature) const { 1229 std::string* signature) const {
1230 texture->AddToSignature(feature_info_.get(), target, level, signature); 1230 texture->AddToSignature(feature_info_.get(), target, level, signature);
1231 } 1231 }
1232 1232
1233 } // namespace gles2 1233 } // namespace gles2
1234 } // namespace gpu 1234 } // namespace gpu
OLDNEW
« gpu/command_buffer/service/texture_manager.h ('K') | « gpu/command_buffer/service/texture_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698