Reland "Refactor SharedImageVideo backing."
This is a reland of 5f7b87c0a1
with some
additional changes and refactor.
Original change's description:
> Refactor SharedImageVideo backing.
>
> 1. Refactor SharedImageVideo backing to use SharedImageBackingAndroid
> and SharedImageRepresentationSkiaVkAndroid.
>
> 2. Move GetAhardwareBuffer and VkImage creation from Representation's
> BeginRead to ProduceSkia.
>
> Bug: 1091945
> Change-Id: Ic08616f37754c864d0059c38b0a64f1f296b1ae4
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2281478
> Commit-Queue: vikas soni <vikassoni@chromium.org>
> Reviewed-by: Peng Huang <penghuang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#785336}
Bug: 1091945
Change-Id: Ic46dbcfda2bc3c7a9435c1b5001b1c1722ed09a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2282729
Reviewed-by: Peng Huang <penghuang@chromium.org>
Commit-Queue: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786491}
This commit is contained in:
@ -102,4 +102,10 @@ void SharedImageBackingAndroid::EndRead(const SharedImageRepresentation* reader,
|
||||
gl::MergeFDs(std::move(read_sync_fd_), std::move(end_read_fd));
|
||||
}
|
||||
|
||||
base::ScopedFD SharedImageBackingAndroid::TakeReadFence() {
|
||||
AutoLock auto_lock(this);
|
||||
|
||||
return std::move(read_sync_fd_);
|
||||
}
|
||||
|
||||
} // namespace gpu
|
||||
|
@ -30,6 +30,7 @@ class SharedImageBackingAndroid : public ClearTrackingSharedImageBacking {
|
||||
base::ScopedFD* fd_to_wait_on);
|
||||
virtual void EndRead(const SharedImageRepresentation* reader,
|
||||
base::ScopedFD end_read_fd);
|
||||
base::ScopedFD TakeReadFence();
|
||||
|
||||
protected:
|
||||
// All reads and writes must wait for exiting writes to complete.
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "gpu/command_buffer/service/shared_context_state.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_skia_gl.h"
|
||||
#include "gpu/command_buffer/service/skia_utils.h"
|
||||
#include "gpu/command_buffer/service/texture_manager.h"
|
||||
#include "gpu/vulkan/vulkan_device_queue.h"
|
||||
#include "gpu/vulkan/vulkan_fence_helper.h"
|
||||
|
@ -43,6 +43,12 @@ class SharedImageRepresentationSkiaVkAndroid
|
||||
void EndReadAccess() override;
|
||||
|
||||
protected:
|
||||
SharedImageBackingAndroid* android_backing() const {
|
||||
return static_cast<SharedImageBackingAndroid*>(backing());
|
||||
}
|
||||
|
||||
SharedContextState* context_state() const { return context_state_.get(); }
|
||||
|
||||
std::unique_ptr<VulkanImage> vulkan_image_;
|
||||
|
||||
// Initial read fence to wait on before reading |vulkan_image_|.
|
||||
@ -59,9 +65,6 @@ class SharedImageRepresentationSkiaVkAndroid
|
||||
VulkanImplementation* vk_implementation();
|
||||
VkPhysicalDevice vk_phy_device();
|
||||
VkQueue vk_queue();
|
||||
SharedImageBackingAndroid* android_backing() {
|
||||
return static_cast<SharedImageBackingAndroid*>(backing());
|
||||
}
|
||||
|
||||
RepresentationAccessMode mode_ = RepresentationAccessMode::kNone;
|
||||
int surface_msaa_count_ = 0;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "gpu/command_buffer/service/shared_context_state.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_skia_gl.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_skia_vk_android.h"
|
||||
#include "gpu/command_buffer/service/skia_utils.h"
|
||||
#include "gpu/command_buffer/service/texture_manager.h"
|
||||
#include "gpu/command_buffer/service/texture_owner.h"
|
||||
@ -42,7 +43,7 @@ SharedImageVideo::SharedImageVideo(
|
||||
std::unique_ptr<gles2::AbstractTexture> abstract_texture,
|
||||
scoped_refptr<SharedContextState> context_state,
|
||||
bool is_thread_safe)
|
||||
: SharedImageBacking(
|
||||
: SharedImageBackingAndroid(
|
||||
mailbox,
|
||||
viz::RGBA_8888,
|
||||
size,
|
||||
@ -50,7 +51,8 @@ SharedImageVideo::SharedImageVideo(
|
||||
(SHARED_IMAGE_USAGE_DISPLAY | SHARED_IMAGE_USAGE_GLES2),
|
||||
viz::ResourceSizes::UncheckedSizeInBytes<size_t>(size,
|
||||
viz::RGBA_8888),
|
||||
is_thread_safe),
|
||||
is_thread_safe,
|
||||
base::ScopedFD()),
|
||||
stream_texture_sii_(std::move(stream_texture_sii)),
|
||||
abstract_texture_(std::move(abstract_texture)),
|
||||
context_state_(std::move(context_state)) {
|
||||
@ -200,33 +202,18 @@ class SharedImageRepresentationGLTexturePassthroughVideo
|
||||
DISALLOW_COPY_AND_ASSIGN(SharedImageRepresentationGLTexturePassthroughVideo);
|
||||
};
|
||||
|
||||
// Vulkan backed Skia representation of SharedImageVideo.
|
||||
class SharedImageRepresentationVideoSkiaVk
|
||||
: public SharedImageRepresentationSkia {
|
||||
: public SharedImageRepresentationSkiaVkAndroid {
|
||||
public:
|
||||
SharedImageRepresentationVideoSkiaVk(
|
||||
SharedImageManager* manager,
|
||||
SharedImageBacking* backing,
|
||||
SharedImageBackingAndroid* backing,
|
||||
scoped_refptr<SharedContextState> context_state,
|
||||
MemoryTypeTracker* tracker)
|
||||
: SharedImageRepresentationSkia(manager, backing, tracker),
|
||||
context_state_(std::move(context_state)) {
|
||||
DCHECK(context_state_);
|
||||
DCHECK(context_state_->vk_context_provider());
|
||||
}
|
||||
|
||||
~SharedImageRepresentationVideoSkiaVk() override {
|
||||
DCHECK(end_access_semaphore_ == VK_NULL_HANDLE);
|
||||
|
||||
// |promise_texture_| could be null if we never being read.
|
||||
if (!vulkan_image_)
|
||||
return;
|
||||
VulkanFenceHelper* fence_helper = context_state_->vk_context_provider()
|
||||
->GetDeviceQueue()
|
||||
->GetFenceHelper();
|
||||
fence_helper->EnqueueVulkanObjectCleanupForSubmittedWork(
|
||||
std::move(vulkan_image_));
|
||||
}
|
||||
: SharedImageRepresentationSkiaVkAndroid(manager,
|
||||
backing,
|
||||
std::move(context_state),
|
||||
tracker) {}
|
||||
|
||||
sk_sp<SkSurface> BeginWriteAccess(
|
||||
int final_msaa_count,
|
||||
@ -260,17 +247,14 @@ class SharedImageRepresentationVideoSkiaVk
|
||||
// Wait on the sync fd attached to the buffer to make sure buffer is
|
||||
// ready before the read. This is done by inserting the sync fd semaphore
|
||||
// into begin_semaphore vector which client will wait on.
|
||||
base::ScopedFD sync_fd = scoped_hardware_buffer_->TakeFence();
|
||||
if (!BeginRead(begin_semaphores, end_semaphores, std::move(sync_fd))) {
|
||||
return nullptr;
|
||||
}
|
||||
init_read_fence_ = scoped_hardware_buffer_->TakeFence();
|
||||
|
||||
if (!vulkan_image_) {
|
||||
DCHECK(!promise_texture_);
|
||||
|
||||
vulkan_image_ =
|
||||
CreateVkImageFromAhbHandle(scoped_hardware_buffer_->TakeBuffer(),
|
||||
context_state_.get(), size(), format());
|
||||
context_state(), size(), format());
|
||||
if (!vulkan_image_)
|
||||
return nullptr;
|
||||
|
||||
@ -292,91 +276,27 @@ class SharedImageRepresentationVideoSkiaVk
|
||||
CreateGrVkImageInfo(vulkan_image_.get())));
|
||||
DCHECK(promise_texture_);
|
||||
}
|
||||
return promise_texture_;
|
||||
|
||||
return SharedImageRepresentationSkiaVkAndroid::BeginReadAccess(
|
||||
begin_semaphores, end_semaphores);
|
||||
}
|
||||
|
||||
void EndReadAccess() override {
|
||||
DCHECK(scoped_hardware_buffer_);
|
||||
DCHECK(end_access_semaphore_ != VK_NULL_HANDLE);
|
||||
|
||||
SemaphoreHandle semaphore_handle = vk_implementation()->GetSemaphoreHandle(
|
||||
vk_device(), end_access_semaphore_);
|
||||
auto sync_fd = semaphore_handle.TakeHandle();
|
||||
DCHECK(sync_fd.is_valid());
|
||||
SharedImageRepresentationSkiaVkAndroid::EndReadAccess();
|
||||
|
||||
// Pass the end access sync fd to the scoped hardware buffer. This will make
|
||||
// sure that the AImage associated with the hardware buffer will be deleted
|
||||
// only when the read access is ending.
|
||||
scoped_hardware_buffer_->SetReadFence(std::move(sync_fd), true);
|
||||
fence_helper()->EnqueueSemaphoreCleanupForSubmittedWork(
|
||||
end_access_semaphore_);
|
||||
end_access_semaphore_ = VK_NULL_HANDLE;
|
||||
// Pass the end read access sync fd to the scoped hardware buffer. This will
|
||||
// make sure that the AImage associated with the hardware buffer will be
|
||||
// deleted only when the read access is ending.
|
||||
scoped_hardware_buffer_->SetReadFence(android_backing()->TakeReadFence(),
|
||||
true);
|
||||
scoped_hardware_buffer_ = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
bool BeginRead(std::vector<GrBackendSemaphore>* begin_semaphores,
|
||||
std::vector<GrBackendSemaphore>* end_semaphores,
|
||||
base::ScopedFD sync_fd) {
|
||||
DCHECK(begin_semaphores);
|
||||
DCHECK(end_semaphores);
|
||||
DCHECK(end_access_semaphore_ == VK_NULL_HANDLE);
|
||||
|
||||
VkSemaphore begin_access_semaphore = VK_NULL_HANDLE;
|
||||
if (sync_fd.is_valid()) {
|
||||
begin_access_semaphore = vk_implementation()->ImportSemaphoreHandle(
|
||||
vk_device(),
|
||||
SemaphoreHandle(VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT,
|
||||
std::move(sync_fd)));
|
||||
if (begin_access_semaphore == VK_NULL_HANDLE) {
|
||||
DLOG(ERROR) << "Failed to import semaphore from sync_fd.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
end_access_semaphore_ =
|
||||
vk_implementation()->CreateExternalSemaphore(vk_device());
|
||||
|
||||
if (end_access_semaphore_ == VK_NULL_HANDLE) {
|
||||
DLOG(ERROR) << "Failed to create the external semaphore.";
|
||||
if (begin_access_semaphore != VK_NULL_HANDLE) {
|
||||
vkDestroySemaphore(vk_device(), begin_access_semaphore,
|
||||
nullptr /* pAllocator */);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
end_semaphores->emplace_back();
|
||||
end_semaphores->back().initVulkan(end_access_semaphore_);
|
||||
|
||||
if (begin_access_semaphore != VK_NULL_HANDLE) {
|
||||
begin_semaphores->emplace_back();
|
||||
begin_semaphores->back().initVulkan(begin_access_semaphore);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
VkDevice vk_device() {
|
||||
return context_state_->vk_context_provider()
|
||||
->GetDeviceQueue()
|
||||
->GetVulkanDevice();
|
||||
}
|
||||
|
||||
VulkanImplementation* vk_implementation() {
|
||||
return context_state_->vk_context_provider()->GetVulkanImplementation();
|
||||
}
|
||||
|
||||
VulkanFenceHelper* fence_helper() {
|
||||
return context_state_->vk_context_provider()
|
||||
->GetDeviceQueue()
|
||||
->GetFenceHelper();
|
||||
}
|
||||
|
||||
std::unique_ptr<VulkanImage> vulkan_image_;
|
||||
sk_sp<SkPromiseImageTexture> promise_texture_;
|
||||
scoped_refptr<SharedContextState> context_state_;
|
||||
std::unique_ptr<base::android::ScopedHardwareBufferFenceSync>
|
||||
scoped_hardware_buffer_;
|
||||
VkSemaphore end_access_semaphore_ = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
// TODO(vikassoni): Currently GLRenderer doesn't support overlays with shared
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/optional.h"
|
||||
#include "gpu/command_buffer/service/shared_context_state.h"
|
||||
#include "gpu/command_buffer/service/shared_image_backing.h"
|
||||
#include "gpu/command_buffer/service/shared_image_backing_android.h"
|
||||
#include "gpu/command_buffer/service/stream_texture_shared_image_interface.h"
|
||||
#include "gpu/gpu_gles2_export.h"
|
||||
#include "gpu/ipc/common/vulkan_ycbcr_info.h"
|
||||
@ -27,7 +27,7 @@ class AbstractTexture;
|
||||
// Implementation of SharedImageBacking that renders MediaCodec buffers to a
|
||||
// TextureOwner or overlay as needed in order to draw them.
|
||||
class GPU_GLES2_EXPORT SharedImageVideo
|
||||
: public SharedImageBacking,
|
||||
: public SharedImageBackingAndroid,
|
||||
public SharedContextState::ContextLostObserver {
|
||||
public:
|
||||
SharedImageVideo(
|
||||
|
Reference in New Issue
Block a user