Chromium Code Reviews| Index: gpu/command_buffer/service/texture_manager.cc |
| diff --git a/gpu/command_buffer/service/texture_manager.cc b/gpu/command_buffer/service/texture_manager.cc |
| index 8f72cf4a3f1eb300108080fa6a6c155df296de97..35c561d57d2f61c127356cd4700209f1c156b7f8 100644 |
| --- a/gpu/command_buffer/service/texture_manager.cc |
| +++ b/gpu/command_buffer/service/texture_manager.cc |
| @@ -115,6 +115,15 @@ Texture::Texture(TextureManager* manager, GLuint service_id) |
| } |
| Texture::~Texture() { |
| + DCHECK(!owned_ || !mailbox_); |
| + if (mailbox_ && mailbox_->HasOneRef()) { |
|
apatrick_chromium
2013/03/19 18:50:18
HasOneRef is a bit dangerous if there are potentia
|
| + bool have_context = manager_ && manager_->have_context_; |
| + if (have_context) { |
| + GLuint id = mailbox_->ReleaseServiceId(); |
| + glDeleteTextures(1, &id); |
| + } |
| + } |
| + |
| if (manager_) { |
| if (owned_ && manager_->have_context_) { |
| GLuint id = service_id(); |
| @@ -931,7 +940,7 @@ void TextureManager::SetLevelInfo( |
| } |
| TextureDefinition* TextureManager::Save(Texture* texture) { |
| - DCHECK(texture->owned_); |
| + DCHECK(texture->owned_ || texture->mailbox_); |
| if (texture->IsAttachedToFramebuffer()) |
| return NULL; |
| @@ -954,38 +963,23 @@ TextureDefinition* TextureManager::Save(Texture* texture) { |
| level_info.format, |
| level_info.type, |
| level_info.cleared)); |
| - |
| - SetLevelInfo(texture, |
| - target, |
| - level, |
| - GL_RGBA, |
| - 0, |
| - 0, |
| - 0, |
| - 0, |
| - GL_RGBA, |
| - GL_UNSIGNED_BYTE, |
| - true); |
| - } |
| + } |
| } |
| - GLuint old_service_id = texture->service_id(); |
| bool immutable = texture->IsImmutable(); |
| - GLuint new_service_id = 0; |
| - glGenTextures(1, &new_service_id); |
| - texture->SetServiceId(new_service_id); |
| - texture->SetImmutable(false); |
| - |
| - return new TextureDefinition(texture->target(), |
| - old_service_id, |
| - texture->min_filter(), |
| - texture->mag_filter(), |
| - texture->wrap_s(), |
| - texture->wrap_t(), |
| - texture->usage(), |
| - immutable, |
| - level_infos); |
| + texture->mailbox_ = new TextureDefinition(texture->target(), |
| + texture->service_id(), |
| + texture->min_filter(), |
|
apatrick_chromium
2013/03/19 18:50:18
indentation
no sievers
2013/04/02 03:07:20
Done.
|
| + texture->mag_filter(), |
| + texture->wrap_s(), |
| + texture->wrap_t(), |
| + texture->usage(), |
| + immutable, |
| + level_infos); |
| + texture->SetImmutable(true); |
| + texture->SetNotOwned(); |
| + return texture->mailbox_; |
| } |
| bool TextureManager::Restore( |
| @@ -993,10 +987,6 @@ bool TextureManager::Restore( |
| GLES2Decoder* decoder, |
| Texture* texture, |
| TextureDefinition* definition) { |
| - DCHECK(texture->owned_); |
| - |
| - scoped_ptr<TextureDefinition> scoped_definition(definition); |
| - |
| if (texture->IsAttachedToFramebuffer()) |
| return false; |
| @@ -1031,24 +1021,34 @@ bool TextureManager::Restore( |
| } |
| GLuint old_service_id = texture->service_id(); |
| - glDeleteTextures(1, &old_service_id); |
| - texture->SetServiceId(definition->ReleaseServiceId()); |
| - glBindTexture(texture->target(), texture->service_id()); |
| - texture->SetImmutable(definition->immutable()); |
| - SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER, |
| - definition->min_filter()); |
| - SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER, |
| - definition->mag_filter()); |
| - SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S, |
| - definition->wrap_s()); |
| - SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T, |
| - definition->wrap_t()); |
| - if (feature_info_->validators()->texture_parameter.IsValid( |
| - GL_TEXTURE_USAGE_ANGLE)) { |
| - SetParameter(function_name, decoder, texture, GL_TEXTURE_USAGE_ANGLE, |
| - definition->usage()); |
| + if (texture->mailbox_ && texture->mailbox_->HasOneRef()) { |
| + GLuint id = texture->mailbox_->ReleaseServiceId(); |
| + DCHECK(id == old_service_id); |
| + } |
| + texture->mailbox_ = definition; |
| + |
| + if (old_service_id != definition->service_id()) { |
| + glDeleteTextures(1, &old_service_id); |
| + texture->SetServiceId(definition->service_id()); |
| + glBindTexture(texture->target(), texture->service_id()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER, |
| + definition->min_filter()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER, |
| + definition->mag_filter()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S, |
| + definition->wrap_s()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T, |
| + definition->wrap_t()); |
| + if (feature_info_->validators()->texture_parameter.IsValid( |
| + GL_TEXTURE_USAGE_ANGLE)) { |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_USAGE_ANGLE, |
| + definition->usage()); |
| + } |
| } |
| + texture->SetNotOwned(); |
| + texture->SetImmutable(definition->immutable()); |
| + |
| return true; |
| } |