Commit ab9c4551 authored by Khushal's avatar Khushal Committed by Commit Bot

gpu: Support texture_storage_image on android using AHBs.

The above capability allows creating shared images for scanout using the
GL backing factory. This was needed to support images with concurrent
read/write usage which is currently not supported by the AHB backing
factory.

R=vikassoni@chromium.org

Bug: 1019751
Change-Id: Iaf0300e049ac65fbe839b5fdf6d22db7a81d44f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147353
Commit-Queue: Khushal <khushalsagar@chromium.org>
Auto-Submit: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarvikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759837}
parent ba7954e5
......@@ -6,6 +6,7 @@
#define GPU_COMMAND_BUFFER_SERVICE_AHARDWAREBUFFER_UTILS_H_
#include "components/viz/common/resources/resource_format.h"
#include "gpu/gpu_gles2_export.h"
namespace gpu {
......@@ -18,10 +19,11 @@ namespace gpu {
// probably need something like gpu::Capabilities.texture_target_exception_list.
// Returns whether the format is supported by AHardwareBuffer.
bool AHardwareBufferSupportedFormat(viz::ResourceFormat format);
bool GPU_GLES2_EXPORT
AHardwareBufferSupportedFormat(viz::ResourceFormat format);
// Returns the corresponding AHardwareBuffer format.
unsigned int AHardwareBufferFormat(viz::ResourceFormat format);
unsigned int GPU_GLES2_EXPORT AHardwareBufferFormat(viz::ResourceFormat format);
} // namespace gpu
......
......@@ -392,12 +392,6 @@ SharedImageBackingFactory* SharedImageFactory::GetFactoryByUsage(
(usage & SHARED_IMAGE_USAGE_VIDEO_DECODE) ||
(share_between_threads && vulkan_usage);
// TODO(vasilyt): Android required AHB for overlays
// What about other platforms?
#if defined(OS_ANDROID)
using_interop_factory |= usage & SHARED_IMAGE_USAGE_SCANOUT;
#endif
// wrapped_sk_image_factory_ is only used for OOPR and supports
// a limited number of flags (e.g. no SHARED_IMAGE_USAGE_SCANOUT).
constexpr auto kWrappedSkImageUsage = SHARED_IMAGE_USAGE_RASTER |
......
......@@ -5,6 +5,7 @@ include_rules = [
"+components/viz/common/gpu/gpu_vsync_callback.h",
"+components/viz/common/gpu/vulkan_context_provider.h",
"+components/viz/common/resources/resource_format.h",
"+components/viz/common/resources/resource_format_utils.h",
"+components/viz/common/resources/resource_sizes.h",
"+third_party/skia",
"+ui/accelerated_widget_mac",
......
......@@ -5,13 +5,44 @@
#include "gpu/ipc/service/gpu_memory_buffer_factory_android_hardware_buffer.h"
#include "base/android/android_hardware_buffer_compat.h"
#include "base/android/scoped_hardware_buffer_handle.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "build/build_config.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/service/ahardwarebuffer_utils.h"
#include "gpu/ipc/common/gpu_memory_buffer_impl_android_hardware_buffer.h"
#include "ui/gl/android/android_surface_control_compat.h"
#include "ui/gl/gl_image_ahardwarebuffer.h"
namespace gpu {
namespace {
AHardwareBuffer_Desc GetBufferDescription(const gfx::Size& size,
viz::ResourceFormat format,
gfx::BufferUsage usage) {
AHardwareBuffer_Desc hwb_desc;
hwb_desc.width = size.width();
hwb_desc.height = size.height();
hwb_desc.format = AHardwareBufferFormat(format);
hwb_desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
if (usage == gfx::BufferUsage::SCANOUT)
hwb_desc.usage |= gl::SurfaceControl::RequiredUsage();
// Number of images in an image array.
hwb_desc.layers = 1;
// The following three are not used here.
hwb_desc.stride = 0;
hwb_desc.rfu0 = 0;
hwb_desc.rfu1 = 0;
return hwb_desc;
}
} // namespace
GpuMemoryBufferFactoryAndroidHardwareBuffer::
GpuMemoryBufferFactoryAndroidHardwareBuffer() = default;
......@@ -57,6 +88,44 @@ ImageFactory* GpuMemoryBufferFactoryAndroidHardwareBuffer::AsImageFactory() {
return this;
}
bool GpuMemoryBufferFactoryAndroidHardwareBuffer::SupportsCreateAnonymousImage()
const {
return true;
}
scoped_refptr<gl::GLImage>
GpuMemoryBufferFactoryAndroidHardwareBuffer::CreateAnonymousImage(
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
SurfaceHandle surface_handle,
bool* is_cleared) {
auto resource_format = viz::GetResourceFormat(format);
if (!AHardwareBufferSupportedFormat(resource_format)) {
LOG(ERROR) << "Requested format not supported by AHB : " << resource_format;
return nullptr;
}
AHardwareBuffer* buffer = nullptr;
AHardwareBuffer_Desc hwb_desc =
GetBufferDescription(size, resource_format, usage);
base::AndroidHardwareBufferCompat::GetInstance().Allocate(&hwb_desc, &buffer);
if (!buffer) {
LOG(ERROR) << "Failed to allocate AHB";
}
auto handle = base::android::ScopedHardwareBufferHandle::Adopt(buffer);
scoped_refptr<gl::GLImageAHardwareBuffer> gl_image =
new gl::GLImageAHardwareBuffer(size);
if (!gl_image->Initialize(handle.get(), false)) {
LOG(ERROR) << "Failed to initialize GLImageAHardwareBuffer";
return nullptr;
}
*is_cleared = false;
return gl_image;
}
scoped_refptr<gl::GLImage>
GpuMemoryBufferFactoryAndroidHardwareBuffer::CreateImageForGpuMemoryBuffer(
gfx::GpuMemoryBufferHandle handle,
......
......@@ -41,7 +41,12 @@ class GPU_IPC_SERVICE_EXPORT GpuMemoryBufferFactoryAndroidHardwareBuffer
ImageFactory* AsImageFactory() override;
// Overridden from ImageFactory:
// TODO(khushalsagar): Add support for anonymous images.
bool SupportsCreateAnonymousImage() const override;
scoped_refptr<gl::GLImage> CreateAnonymousImage(const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
SurfaceHandle surface_handle,
bool* is_cleared) override;
scoped_refptr<gl::GLImage> CreateImageForGpuMemoryBuffer(
gfx::GpuMemoryBufferHandle handle,
const gfx::Size& size,
......
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