| Index: components/exo/buffer.cc
|
| diff --git a/components/exo/buffer.cc b/components/exo/buffer.cc
|
| index 0c771df3d66a9af9af0a44c9fa7e7f412b238e52..507cbeb04cc962e7d66454dc52156c6eb3ea0551 100644
|
| --- a/components/exo/buffer.cc
|
| +++ b/components/exo/buffer.cc
|
| @@ -28,6 +28,7 @@
|
| #include "gpu/command_buffer/client/gles2_interface.h"
|
| #include "ui/aura/env.h"
|
| #include "ui/compositor/compositor.h"
|
| +#include "ui/gfx/gpu_fence.h"
|
| #include "ui/gfx/gpu_memory_buffer.h"
|
|
|
| namespace exo {
|
| @@ -116,9 +117,10 @@ class Buffer::Texture : public ui::ContextFactoryObserver {
|
| bool is_lost);
|
|
|
| // Binds the contents referenced by |image_id_| to the texture returned by
|
| - // mailbox(). Returns a sync token that can be used when accessing texture
|
| - // from a different context.
|
| - gpu::SyncToken BindTexImage();
|
| + // mailbox(), using the fence from |fence| for synchronization. Returns a
|
| + // sync token that can be used when accessing texture from a different
|
| + // context.
|
| + gpu::SyncToken BindTexImage(gfx::GpuFence* fence);
|
|
|
| // Releases the contents referenced by |image_id_| after |sync_token| has
|
| // passed and runs |callback| when completed.
|
| @@ -129,7 +131,8 @@ class Buffer::Texture : public ui::ContextFactoryObserver {
|
| // Copy the contents of texture to |destination| and runs |callback| when
|
| // completed. Returns a sync token that can be used when accessing texture
|
| // from a different context.
|
| - gpu::SyncToken CopyTexImage(Texture* destination,
|
| + gpu::SyncToken CopyTexImage(gfx::GpuFence* fence,
|
| + Texture* destination,
|
| const base::Closure& callback);
|
|
|
| // Returns the mailbox for this texture.
|
| @@ -150,6 +153,7 @@ class Buffer::Texture : public ui::ContextFactoryObserver {
|
| unsigned image_id_ = 0;
|
| unsigned query_id_ = 0;
|
| unsigned texture_id_ = 0;
|
| + unsigned fence_id_ = 0;
|
| gpu::Mailbox mailbox_;
|
| base::Closure release_callback_;
|
| base::TimeTicks wait_for_release_time_;
|
| @@ -231,14 +235,18 @@ void Buffer::Texture::Release(const base::Closure& callback,
|
| callback.Run();
|
| }
|
|
|
| -gpu::SyncToken Buffer::Texture::BindTexImage() {
|
| +gpu::SyncToken Buffer::Texture::BindTexImage(gfx::GpuFence* fence) {
|
| gpu::SyncToken sync_token;
|
| if (context_provider_) {
|
| gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL();
|
| gles2->ActiveTexture(GL_TEXTURE0);
|
| gles2->BindTexture(texture_target_, texture_id_);
|
| DCHECK_NE(image_id_, 0u);
|
| - gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, 0);
|
| + if (fence) {
|
| + fence_id_ = gles2->CreateFenceCHROMIUM(fence->AsClientFence());
|
| + DCHECK_NE(fence_id_, 0u);
|
| + }
|
| + gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, fence_id_);
|
| // Generate a crypto-secure random mailbox name if not already done.
|
| if (mailbox_.IsZero())
|
| CreateGLTextureMailbox(gles2, texture_id_, texture_target_, &mailbox_);
|
| @@ -264,6 +272,10 @@ void Buffer::Texture::ReleaseTexImage(const base::Closure& callback,
|
| DCHECK_NE(query_id_, 0u);
|
| gles2->BeginQueryEXT(query_type_, query_id_);
|
| gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_);
|
| + if (fence_id_) {
|
| + gles2->DestroyFenceCHROMIUM(fence_id_);
|
| + fence_id_ = 0;
|
| + }
|
| gles2->EndQueryEXT(query_type_);
|
| // Run callback when query result is available and ReleaseTexImage has been
|
| // handled if sync token has data and buffer has been used. If buffer was
|
| @@ -276,7 +288,8 @@ void Buffer::Texture::ReleaseTexImage(const base::Closure& callback,
|
| callback.Run();
|
| }
|
|
|
| -gpu::SyncToken Buffer::Texture::CopyTexImage(Texture* destination,
|
| +gpu::SyncToken Buffer::Texture::CopyTexImage(gfx::GpuFence* fence,
|
| + Texture* destination,
|
| const base::Closure& callback) {
|
| gpu::SyncToken sync_token;
|
| if (context_provider_) {
|
| @@ -284,13 +297,21 @@ gpu::SyncToken Buffer::Texture::CopyTexImage(Texture* destination,
|
| gles2->ActiveTexture(GL_TEXTURE0);
|
| gles2->BindTexture(texture_target_, texture_id_);
|
| DCHECK_NE(image_id_, 0u);
|
| - gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, 0);
|
| + if (fence) {
|
| + fence_id_ = gles2->CreateFenceCHROMIUM(fence->AsClientFence());
|
| + DCHECK_NE(fence_id_, 0u);
|
| + }
|
| + gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, fence_id_);
|
| gles2->CopyTextureCHROMIUM(texture_id_, destination->texture_id_,
|
| internalformat_, GL_UNSIGNED_BYTE, false, false,
|
| false);
|
| DCHECK_NE(query_id_, 0u);
|
| gles2->BeginQueryEXT(query_type_, query_id_);
|
| gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_);
|
| + if (fence_id_) {
|
| + gles2->DestroyFenceCHROMIUM(fence_id_);
|
| + fence_id_ = 0;
|
| + }
|
| gles2->EndQueryEXT(query_type_);
|
| // Run callback when query result is available and ReleaseTexImage has been
|
| // handled.
|
| @@ -313,6 +334,8 @@ void Buffer::Texture::DestroyResources() {
|
| gles2->DeleteQueriesEXT(1, &query_id_);
|
| if (image_id_)
|
| gles2->DestroyImageCHROMIUM(image_id_);
|
| + if (fence_id_)
|
| + gles2->DestroyFenceCHROMIUM(fence_id_);
|
| }
|
| }
|
|
|
| @@ -400,6 +423,7 @@ Buffer::~Buffer() {}
|
|
|
| std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox(
|
| cc::TextureMailbox* texture_mailbox,
|
| + gfx::GpuFence* fence,
|
| bool secure_output_only,
|
| bool client_usage) {
|
| DCHECK(attach_count_);
|
| @@ -450,7 +474,7 @@ 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();
|
| + gpu::SyncToken sync_token = texture->BindTexImage(fence);
|
|
|
| *texture_mailbox =
|
| cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_,
|
| @@ -477,8 +501,8 @@ std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox(
|
|
|
| // 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_)));
|
| + fence, 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(),
|
|
|