Chromium Code Reviews| Index: components/exo/buffer.cc |
| diff --git a/components/exo/buffer.cc b/components/exo/buffer.cc |
| index 9b1778d989d6c0250efff832d6372f401e15e129..060c7e542d6092d9ab6e7134dc4ff071f996846a 100644 |
| --- a/components/exo/buffer.cc |
| +++ b/components/exo/buffer.cc |
| @@ -24,6 +24,7 @@ |
| #include "cc/output/context_provider.h" |
| #include "cc/resources/single_release_callback.h" |
| #include "cc/resources/texture_mailbox.h" |
| +#include "components/exo/compositor_frame_sink_holder.h" |
| #include "gpu/command_buffer/client/context_support.h" |
| #include "gpu/command_buffer/client/gles2_interface.h" |
| #include "ui/aura/env.h" |
| @@ -398,10 +399,12 @@ Buffer::Buffer(std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer, |
| Buffer::~Buffer() {} |
| -std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( |
| - cc::TextureMailbox* texture_mailbox, |
| +bool Buffer::ProduceTransferableResource( |
| + CompositorFrameSinkHolder* compositor_frame_sink_holder, |
| + cc::ResourceId resource_id, |
| bool secure_output_only, |
| - bool client_usage) { |
| + bool client_usage, |
| + cc::TransferableResource* resource) { |
| DCHECK(attach_count_); |
| DLOG_IF(WARNING, use_count_ && client_usage) |
| << "Producing a texture mailbox for a buffer that has not been released"; |
| @@ -433,9 +436,20 @@ std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( |
| if (!context_provider) { |
| DLOG(WARNING) << "Failed to acquire a context provider"; |
| Release(); // Decrements the use count |
| - return nullptr; |
| + resource->id = 0; |
| + resource->size = gfx::Size(); |
| + return false; |
| } |
| + // The reference to the CompositorFrameSinkHolder keeps it alive until a |
| + // release callback is received. |
| + compositor_frame_sink_holder_ = compositor_frame_sink_holder; |
| + |
| + resource->id = resource_id; |
| + resource->format = cc::RGBA_8888; |
| + resource->filter = GL_LINEAR; |
| + resource->size = gpu_memory_buffer_->GetSize(); |
| + |
| // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| |
| // if one doesn't already exist. The contents of this buffer are copied to |
| // |texture| using a call to CopyTexImage. |
| @@ -450,18 +464,19 @@ std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( |
| Texture* texture = contents_texture_.get(); |
| // This binds the latest contents of this buffer to |texture|. |
| - gpu::SyncToken sync_token = texture->BindTexImage(); |
| + resource->mailbox_holder = gpu::MailboxHolder( |
| + texture->mailbox(), texture->BindTexImage(), texture_target_); |
| + |
| + resource->is_overlay_candidate = is_overlay_candidate_; |
| - *texture_mailbox = |
| - cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, |
| - gpu_memory_buffer_->GetSize(), is_overlay_candidate_, |
| - secure_output_only); |
| // The contents texture will be released when no longer used by the |
| // compositor. |
| - return cc::SingleReleaseCallback::Create( |
| + compositor_frame_sink_holder_->SetResourceReleaseCallback( |
| + resource_id, |
| base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), |
| base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| base::Passed(&contents_texture_)))); |
| + return true; |
| } |
| // Create a mailbox texture that we copy the buffer contents to. |
| @@ -476,19 +491,22 @@ std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( |
| Texture* texture = texture_.get(); |
| // The contents texture will be released when copy has completed. |
| - gpu::SyncToken sync_token = contents_texture->CopyTexImage( |
| - texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| - base::Passed(&contents_texture_))); |
| - *texture_mailbox = |
| - cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, |
| - gpu_memory_buffer_->GetSize(), |
| - false /* is_overlay_candidate */, secure_output_only); |
| + resource->mailbox_holder = gpu::MailboxHolder( |
| + texture->mailbox(), |
| + contents_texture->CopyTexImage( |
| + texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| + base::Passed(&contents_texture_))), |
| + GL_TEXTURE_2D); |
| + resource->is_overlay_candidate = false; |
| + |
| // The mailbox texture will be released when no longer used by the |
| // compositor. |
| - return cc::SingleReleaseCallback::Create( |
| + compositor_frame_sink_holder_->SetResourceReleaseCallback( |
| + resource_id, |
| base::Bind(&Buffer::Texture::Release, base::Unretained(texture), |
| base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), |
| base::Passed(&texture_)))); |
| + return true; |
| } |
| void Buffer::OnAttach() { |
| @@ -534,6 +552,8 @@ void Buffer::CheckReleaseCallback() { |
| // Run release callback to notify the client that buffer has been released. |
| if (!release_callback_.is_null()) |
| release_callback_.Run(); |
| + |
| + compositor_frame_sink_holder_ = nullptr; |
| } |
| void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { |
| @@ -542,7 +562,6 @@ void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { |
| void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { |
| TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); |
| - |
|
reveman
2017/01/03 23:48:34
nit: keep this line
|
| contents_texture_ = std::move(texture); |
| Release(); |
| } |