Commit e5a2101a authored by Antoine Labour's avatar Antoine Labour Committed by Commit Bot

Use SharedImageInterface in ZeroCopyRasterBufferProvider

Bug: 882513, 897214
Change-Id: I3d7dc804db292b7a9844eda856195b7b7b1450d3
Reviewed-on: https://chromium-review.googlesource.com/c/1316347
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606210}
parent f08b6cda
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <algorithm> #include <algorithm>
#include "base/macros.h" #include "base/macros.h"
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h" #include "base/trace_event/traced_value.h"
#include "cc/resources/resource_pool.h" #include "cc/resources/resource_pool.h"
...@@ -16,9 +17,11 @@ ...@@ -16,9 +17,11 @@
#include "components/viz/common/gpu/context_provider.h" #include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/resources/platform_color.h" #include "components/viz/common/resources/platform_color.h"
#include "components/viz/common/resources/resource_format_utils.h" #include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h" #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/gpu_memory_buffer.h"
...@@ -32,13 +35,12 @@ constexpr static auto kBufferUsage = gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; ...@@ -32,13 +35,12 @@ constexpr static auto kBufferUsage = gfx::BufferUsage::GPU_READ_CPU_READ_WRITE;
class ZeroCopyGpuBacking : public ResourcePool::GpuBacking { class ZeroCopyGpuBacking : public ResourcePool::GpuBacking {
public: public:
~ZeroCopyGpuBacking() override { ~ZeroCopyGpuBacking() override {
gpu::gles2::GLES2Interface* gl = compositor_context_provider->ContextGL(); if (mailbox.IsZero())
return;
if (returned_sync_token.HasData()) if (returned_sync_token.HasData())
gl->WaitSyncTokenCHROMIUM(returned_sync_token.GetConstData()); shared_image_interface->DestroySharedImage(returned_sync_token, mailbox);
if (texture_id) else if (mailbox_sync_token.HasData())
gl->DeleteTextures(1, &texture_id); shared_image_interface->DestroySharedImage(mailbox_sync_token, mailbox);
if (image_id)
gl->DestroyImageCHROMIUM(image_id);
} }
void OnMemoryDump( void OnMemoryDump(
...@@ -52,16 +54,11 @@ class ZeroCopyGpuBacking : public ResourcePool::GpuBacking { ...@@ -52,16 +54,11 @@ class ZeroCopyGpuBacking : public ResourcePool::GpuBacking {
importance); importance);
} }
// The ContextProvider used to clean up the texture and image ids. // The SharedImageInterface used to clean up the shared image.
viz::ContextProvider* compositor_context_provider = nullptr; gpu::SharedImageInterface* shared_image_interface = nullptr;
// The backing for zero-copy gpu resources. The |texture_id| is bound to // The backing for zero-copy gpu resources. The |texture_id| is bound to
// this. // this.
std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer;
// The texture id bound to the GpuMemoryBuffer.
uint32_t texture_id = 0;
// The image id that associates the |gpu_memory_buffer| and the
// |texture_id|.
uint32_t image_id = 0;
}; };
// RasterBuffer for the zero copy upload, which is given to the raster worker // RasterBuffer for the zero copy upload, which is given to the raster worker
...@@ -69,7 +66,6 @@ class ZeroCopyGpuBacking : public ResourcePool::GpuBacking { ...@@ -69,7 +66,6 @@ class ZeroCopyGpuBacking : public ResourcePool::GpuBacking {
class ZeroCopyRasterBufferImpl : public RasterBuffer { class ZeroCopyRasterBufferImpl : public RasterBuffer {
public: public:
ZeroCopyRasterBufferImpl( ZeroCopyRasterBufferImpl(
viz::ContextProvider* context_provider,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
const ResourcePool::InUsePoolResource& in_use_resource, const ResourcePool::InUsePoolResource& in_use_resource,
ZeroCopyGpuBacking* backing) ZeroCopyGpuBacking* backing)
...@@ -94,63 +90,20 @@ class ZeroCopyRasterBufferImpl : public RasterBuffer { ...@@ -94,63 +90,20 @@ class ZeroCopyRasterBufferImpl : public RasterBuffer {
// we can set up the texture and SyncToken here. // we can set up the texture and SyncToken here.
// TODO(danakj): This could be done with the worker context in Playback. Do // TODO(danakj): This could be done with the worker context in Playback. Do
// we need to do things in IsResourceReadyToDraw() and OrderingBarrier then? // we need to do things in IsResourceReadyToDraw() and OrderingBarrier then?
gpu::gles2::GLES2Interface* gl = gpu::SharedImageInterface* sii = backing_->shared_image_interface;
backing_->compositor_context_provider->ContextGL(); if (backing_->mailbox.IsZero()) {
const gpu::Capabilities& caps = uint32_t usage =
backing_->compositor_context_provider->ContextCapabilities(); gpu::SHARED_IMAGE_USAGE_DISPLAY | gpu::SHARED_IMAGE_USAGE_SCANOUT;
// Make a mailbox for export of the GpuMemoryBuffer to the display
if (backing_->returned_sync_token.HasData()) { // compositor.
gl->WaitSyncTokenCHROMIUM(backing_->returned_sync_token.GetConstData()); backing_->mailbox = sii->CreateSharedImage(gpu_memory_buffer_.get(),
backing_->returned_sync_token = gpu::SyncToken(); gpu_memory_buffer_manager_,
} resource_color_space_, usage);
if (!backing_->texture_id) {
// Make a texture and a mailbox for export of the GpuMemoryBuffer to the
// display compositor.
gl->GenTextures(1, &backing_->texture_id);
backing_->texture_target = gpu::GetBufferTextureTarget(
kBufferUsage, viz::BufferFormat(resource_format_), caps);
gl->ProduceTextureDirectCHROMIUM(backing_->texture_id,
backing_->mailbox.name);
backing_->overlay_candidate = true;
// This RasterBufferProvider will modify the resource outside of the
// GL command stream. So resources should not become available for reuse
// until they are not in use by the gpu anymore, which a fence is used to
// determine.
backing_->wait_on_fence_required = true;
gl->BindTexture(backing_->texture_target, backing_->texture_id);
gl->TexParameteri(backing_->texture_target, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
gl->TexParameteri(backing_->texture_target, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
gl->TexParameteri(backing_->texture_target, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
gl->TexParameteri(backing_->texture_target, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
} else { } else {
gl->BindTexture(backing_->texture_target, backing_->texture_id); sii->UpdateSharedImage(backing_->returned_sync_token, backing_->mailbox);
} }
if (!backing_->image_id) { backing_->mailbox_sync_token = sii->GenUnverifiedSyncToken();
backing_->image_id = gl->CreateImageCHROMIUM(
gpu_memory_buffer_->AsClientBuffer(), resource_size_.width(),
resource_size_.height(), viz::GLInternalFormat(resource_format_));
gl->BindTexImage2DCHROMIUM(backing_->texture_target, backing_->image_id);
} else {
gl->ReleaseTexImage2DCHROMIUM(backing_->texture_target,
backing_->image_id);
gl->BindTexImage2DCHROMIUM(backing_->texture_target, backing_->image_id);
}
if (backing_->image_id && resource_color_space_.IsValid()) {
gl->SetColorSpaceMetadataCHROMIUM(
backing_->texture_id,
reinterpret_cast<GLColorSpace>(&resource_color_space_));
}
gl->BindTexture(backing_->texture_target, 0);
backing_->mailbox_sync_token =
viz::ClientResourceProvider::GenerateSyncTokenHelper(gl);
backing_->gpu_memory_buffer = std::move(gpu_memory_buffer_); backing_->gpu_memory_buffer = std::move(gpu_memory_buffer_);
} }
...@@ -224,15 +177,25 @@ ZeroCopyRasterBufferProvider::AcquireBufferForRaster( ...@@ -224,15 +177,25 @@ ZeroCopyRasterBufferProvider::AcquireBufferForRaster(
uint64_t previous_content_id) { uint64_t previous_content_id) {
if (!resource.gpu_backing()) { if (!resource.gpu_backing()) {
auto backing = std::make_unique<ZeroCopyGpuBacking>(); auto backing = std::make_unique<ZeroCopyGpuBacking>();
backing->compositor_context_provider = compositor_context_provider_; const gpu::Capabilities& caps =
compositor_context_provider_->ContextCapabilities();
backing->texture_target = gpu::GetBufferTextureTarget(
gfx::BufferUsage::SCANOUT, BufferFormat(resource.format()), caps);
backing->overlay_candidate = true;
// This RasterBufferProvider will modify the resource outside of the
// GL command stream. So resources should not become available for reuse
// until they are not in use by the gpu anymore, which a fence is used
// to determine.
backing->wait_on_fence_required = true;
backing->shared_image_interface =
compositor_context_provider_->SharedImageInterface();
resource.set_gpu_backing(std::move(backing)); resource.set_gpu_backing(std::move(backing));
} }
ZeroCopyGpuBacking* backing = ZeroCopyGpuBacking* backing =
static_cast<ZeroCopyGpuBacking*>(resource.gpu_backing()); static_cast<ZeroCopyGpuBacking*>(resource.gpu_backing());
return std::make_unique<ZeroCopyRasterBufferImpl>( return std::make_unique<ZeroCopyRasterBufferImpl>(gpu_memory_buffer_manager_,
compositor_context_provider_, gpu_memory_buffer_manager_, resource, resource, backing);
backing);
} }
void ZeroCopyRasterBufferProvider::Flush() {} void ZeroCopyRasterBufferProvider::Flush() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment