Chromium Code Reviews| Index: content/common/gpu/texture_image_transport_surface.cc |
| diff --git a/content/common/gpu/texture_image_transport_surface.cc b/content/common/gpu/texture_image_transport_surface.cc |
| index e9649f539a8c9c7ec355f597cb2655be0498d84f..69a853690e2f7cc9a1d43819e8634d95908bf4cc 100644 |
| --- a/content/common/gpu/texture_image_transport_surface.cc |
| +++ b/content/common/gpu/texture_image_transport_surface.cc |
| @@ -50,19 +50,27 @@ class ScopedTextureBinder { |
| } // anonymous namespace |
| +TextureImageTransportSurface::Texture::Texture() |
| + : client_id(0), |
| + sent_to_client(false) { |
| +} |
| + |
| +TextureImageTransportSurface::Texture::~Texture() { |
| +} |
| + |
| TextureImageTransportSurface::TextureImageTransportSurface( |
| GpuChannelManager* manager, |
| GpuCommandBufferStub* stub, |
| const gfx::GLSurfaceHandle& handle) |
| : fbo_id_(0), |
| front_(0), |
| - stub_destroyed_(false) { |
| + stub_destroyed_(false), |
| + parent_stub_(NULL) { |
| GpuChannel* parent_channel = manager->LookupChannel(handle.parent_client_id); |
| DCHECK(parent_channel); |
| - GpuCommandBufferStub* parent_stub = parent_channel->LookupCommandBuffer( |
| - handle.parent_context_id); |
| - DCHECK(parent_stub); |
| - parent_stub_ = parent_stub->AsWeakPtr(); |
| + parent_stub_ = parent_channel->LookupCommandBuffer(handle.parent_context_id); |
| + DCHECK(parent_stub_); |
| + parent_stub_->AddDestructionObserver(this); |
| TextureManager* texture_manager = |
| parent_stub_->decoder()->GetContextGroup()->texture_manager(); |
| DCHECK(texture_manager); |
| @@ -70,14 +78,18 @@ TextureImageTransportSurface::TextureImageTransportSurface( |
| for (int i = 0; i < 2; ++i) { |
| Texture& texture = textures_[i]; |
| texture.client_id = handle.parent_texture_id[i]; |
| - TextureInfo* info = texture_manager->GetTextureInfo(texture.client_id); |
| - DCHECK(info); |
| - if (!info->target()) |
| - texture_manager->SetInfoTarget(info, GL_TEXTURE_2D); |
| - texture_manager->SetParameter(info, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| - texture_manager->SetParameter(info, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| - texture_manager->SetParameter(info, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| - texture_manager->SetParameter(info, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| + texture.info = texture_manager->GetTextureInfo(texture.client_id); |
| + DCHECK(texture.info); |
| + if (!texture.info->target()) |
| + texture_manager->SetInfoTarget(texture.info, GL_TEXTURE_2D); |
| + texture_manager->SetParameter( |
| + texture.info, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| + texture_manager->SetParameter( |
| + texture.info, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| + texture_manager->SetParameter( |
| + texture.info, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| + texture_manager->SetParameter( |
| + texture.info, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| } |
| helper_.reset(new ImageTransportHelper(this, |
| @@ -98,6 +110,10 @@ bool TextureImageTransportSurface::Initialize() { |
| } |
| void TextureImageTransportSurface::Destroy() { |
| + if (parent_stub_) { |
| + parent_stub_->RemoveDestructionObserver(this); |
| + parent_stub_ = NULL; |
| + } |
| for (int i = 0; i < 2; ++i) { |
| Texture& texture = textures_[i]; |
| if (!texture.sent_to_client) |
| @@ -105,6 +121,7 @@ void TextureImageTransportSurface::Destroy() { |
| GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| params.identifier = texture.client_id; |
| helper_->SendAcceleratedSurfaceRelease(params); |
| + texture.info = NULL; |
| } |
| helper_->Destroy(); |
| @@ -167,11 +184,11 @@ void* TextureImageTransportSurface::GetShareHandle() { |
| } |
| void* TextureImageTransportSurface::GetDisplay() { |
| - return parent_stub_.get() ? parent_stub_->surface()->GetDisplay() : NULL; |
| + return parent_stub_ ? parent_stub_->surface()->GetDisplay() : NULL; |
| } |
| void* TextureImageTransportSurface::GetConfig() { |
| - return parent_stub_.get() ? parent_stub_->surface()->GetConfig() : NULL; |
| + return parent_stub_ ? parent_stub_->surface()->GetConfig() : NULL; |
| } |
| void TextureImageTransportSurface::OnResize(gfx::Size size) { |
| @@ -180,15 +197,29 @@ void TextureImageTransportSurface::OnResize(gfx::Size size) { |
| void TextureImageTransportSurface::OnWillDestroyStub( |
| GpuCommandBufferStub* stub) { |
| - glDeleteFramebuffersEXT(1, &fbo_id_); |
| - CHECK_GL_ERROR(); |
| - fbo_id_ = 0; |
| - |
| stub->RemoveDestructionObserver(this); |
| - stub_destroyed_ = true; |
| + if (stub == parent_stub_) { |
| + // We are losing the parent stub, we need to clear the reference on the |
| + // infos (they are not allowed to outlive the stub). |
| + textures_[0].info = NULL; |
| + textures_[1].info = NULL; |
|
jonathan.backer
2012/04/17 17:21:50
parent_stub_ = NULL so that we don't access a stal
piman
2012/04/17 17:37:24
Done.
|
| + } else { |
| + // We are losing the stub owning us, this is our last chance to clean up the |
| + // resources we allocated in the stub's context. |
| + glDeleteFramebuffersEXT(1, &fbo_id_); |
| + CHECK_GL_ERROR(); |
| + fbo_id_ = 0; |
| + |
| + stub_destroyed_ = true; |
| + } |
| } |
| bool TextureImageTransportSurface::SwapBuffers() { |
| + if (!parent_stub_) { |
| + LOG(ERROR) << "SwapBuffers failed because no parent stub."; |
| + return false; |
| + } |
| + |
| glFlush(); |
| front_ = back(); |
| previous_damage_rect_ = gfx::Rect(textures_[front_].size); |
| @@ -204,18 +235,16 @@ bool TextureImageTransportSurface::SwapBuffers() { |
| bool TextureImageTransportSurface::PostSubBuffer( |
| int x, int y, int width, int height) { |
| - if (!parent_stub_.get()) |
| + if (!parent_stub_) { |
| + LOG(ERROR) << "PostSubBuffer failed because no parent stub."; |
| return false; |
| + } |
| - TextureInfo* info = GetParentInfo(textures_[back()].client_id); |
| - if (!info) |
| - return false; |
| - int back_texture_service_id = info->service_id(); |
| + DCHECK(textures_[back()].info); |
| + int back_texture_service_id = textures_[back()].info->service_id(); |
| - info = GetParentInfo(textures_[front_].client_id); |
| - if (!info) |
| - return false; |
| - int front_texture_service_id = info->service_id(); |
| + DCHECK(textures_[front_].info); |
| + int front_texture_service_id = textures_[front_].info->service_id(); |
| gfx::Size expected_size = textures_[back()].size; |
| bool surfaces_same_size = textures_[front_].size == expected_size; |
| @@ -279,7 +308,7 @@ gfx::Size TextureImageTransportSurface::GetSize() { |
| } |
| void* TextureImageTransportSurface::GetHandle() { |
| - return parent_stub_.get() ? parent_stub_->surface()->GetHandle() : NULL; |
| + return parent_stub_ ? parent_stub_->surface()->GetHandle() : NULL; |
| } |
| @@ -310,11 +339,10 @@ void TextureImageTransportSurface::OnResizeViewACK() { |
| } |
| void TextureImageTransportSurface::ReleaseBackTexture() { |
| - if (!parent_stub_.get()) |
| - return; |
| - TextureInfo* info = GetParentInfo(textures_[back()].client_id); |
| - if (!info) |
| + if (!parent_stub_) |
| return; |
| + TextureInfo* info = textures_[back()].info; |
| + DCHECK(info); |
| GLuint service_id = info->service_id(); |
| if (!service_id) |
| @@ -330,12 +358,11 @@ void TextureImageTransportSurface::ReleaseBackTexture() { |
| } |
| void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { |
| - if (!parent_stub_.get()) |
| + if (!parent_stub_) |
| return; |
| Texture& texture = textures_[back()]; |
| - TextureInfo* info = GetParentInfo(texture.client_id); |
| - if (!info) |
| - return; |
| + TextureInfo* info = texture.info; |
| + DCHECK(info); |
| GLuint service_id = info->service_id(); |
| @@ -388,17 +415,15 @@ void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { |
| } |
| void TextureImageTransportSurface::AttachBackTextureToFBO() { |
| - if (!parent_stub_.get()) |
| - return; |
| - TextureInfo* info = GetParentInfo(textures_[back()].client_id); |
| - if (!info) |
| + if (!parent_stub_) |
| return; |
| + DCHECK(textures_[back()].info); |
| ScopedFrameBufferBinder fbo_binder(fbo_id_); |
| glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| GL_COLOR_ATTACHMENT0, |
| GL_TEXTURE_2D, |
| - info->service_id(), |
| + textures_[back()].info->service_id(), |
| 0); |
| glFlush(); |
| CHECK_GL_ERROR(); |
| @@ -410,11 +435,3 @@ void TextureImageTransportSurface::AttachBackTextureToFBO() { |
| } |
| #endif |
| } |
| - |
| -TextureInfo* TextureImageTransportSurface::GetParentInfo(uint32 client_id) { |
| - DCHECK(parent_stub_.get()); |
| - TextureManager* texture_manager = |
| - parent_stub_->decoder()->GetContextGroup()->texture_manager(); |
| - TextureInfo* info = texture_manager->GetTextureInfo(client_id); |
| - return info; |
| -} |