diff --git a/gpu/command_buffer/service/ahardwarebuffer_utils.cc b/gpu/command_buffer/service/ahardwarebuffer_utils.cc index a54bc4d44b99a..d88888498f249 100644 --- a/gpu/command_buffer/service/ahardwarebuffer_utils.cc +++ b/gpu/command_buffer/service/ahardwarebuffer_utils.cc @@ -18,96 +18,10 @@ #include "ui/gfx/color_space.h" #include "ui/gfx/geometry/size.h" #include "ui/gl/gl_gl_api_implementation.h" -#include "ui/gl/gl_image_ahardwarebuffer.h" #include "ui/gl/scoped_binders.h" namespace gpu { -// Helpers to allow for easy friending of the below restricted functions. -void SetColorSpaceOnGLImage(gl::GLImage* gl_image, - const gfx::ColorSpace& color_space) { - gl_image->SetColorSpace(color_space); -} -unsigned GetDataFormatOfGLImage(gl::GLImage* gl_image) { - return gl_image->GetDataFormat(); -} - -namespace { - -gles2::Texture* MakeGLTexture( - GLenum target, - GLuint service_id, - scoped_refptr egl_image, - const gfx::Size& size, - const gfx::Rect& cleared_rect) { - auto* texture = gles2::CreateGLES2TextureWithLightRef(service_id, target); - - texture->SetLevelInfo(target, 0, egl_image->GetInternalFormat(), size.width(), - size.height(), 1, 0, - GetDataFormatOfGLImage(egl_image.get()), - egl_image->GetDataType(), cleared_rect); - texture->SetLevelImage(target, 0, egl_image.get(), gles2::Texture::BOUND); - texture->SetImmutable(true, false); - return texture; -} - -scoped_refptr MakeGLTexturePassthrough( - GLenum target, - GLuint service_id, - scoped_refptr egl_image, - const size_t estimated_size) { - auto passthrough_texture = - base::MakeRefCounted(service_id, target); - passthrough_texture->SetEstimatedSize(estimated_size); - passthrough_texture->SetLevelImage(target, 0, egl_image.get()); - return passthrough_texture; -} - -void GenGLTextureInternal( - AHardwareBuffer* buffer, - GLenum target, - const gfx::ColorSpace& color_space, - const gfx::Size& size, - const size_t estimated_size, - const gfx::Rect& cleared_rect, - scoped_refptr* passthrough_texture, - gles2::Texture** texture) { - gl::GLApi* api = gl::g_current_gl_context; - GLuint service_id = 0; - api->glGenTexturesFn(1, &service_id); - gl::ScopedTextureBinder texture_binder(target, service_id); - - api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - // Create an egl image using AHardwareBuffer. - auto egl_image = base::MakeRefCounted(size); - if (!egl_image->Initialize(buffer, false)) { - LOG(ERROR) << "Failed to create EGL image"; - api->glDeleteTexturesFn(1, &service_id); - return; - } - - if (!egl_image->BindTexImage(target)) { - LOG(ERROR) << "Failed to bind egl image"; - api->glDeleteTexturesFn(1, &service_id); - return; - } - SetColorSpaceOnGLImage(egl_image.get(), color_space); - - if (passthrough_texture) { - *passthrough_texture = MakeGLTexturePassthrough( - target, service_id, std::move(egl_image), estimated_size); - } else { - *texture = MakeGLTexture(target, service_id, std::move(egl_image), size, - cleared_rect); - } -} - -} // namespace - bool AHardwareBufferSupportedFormat(viz::ResourceFormat format) { switch (format) { case viz::RGBA_8888: @@ -143,33 +57,6 @@ unsigned int AHardwareBufferFormat(viz::ResourceFormat format) { } } -gles2::Texture* GenGLTexture(AHardwareBuffer* buffer, - GLenum target, - const gfx::ColorSpace& color_space, - const gfx::Size& size, - const size_t estimated_size, - const gfx::Rect& cleared_rect) { - gles2::Texture* texture = nullptr; - GenGLTextureInternal(buffer, target, color_space, size, estimated_size, - cleared_rect, nullptr /* passthrough_texture */, - &texture); - return texture; -} - -scoped_refptr GenGLTexturePassthrough( - AHardwareBuffer* buffer, - GLenum target, - const gfx::ColorSpace& color_space, - const gfx::Size& size, - const size_t estimated_size, - const gfx::Rect& cleared_rect) { - scoped_refptr passthrough_texture; - GenGLTextureInternal(buffer, target, color_space, size, estimated_size, - cleared_rect, &passthrough_texture, - nullptr /* texture */); - return passthrough_texture; -} - std::unique_ptr CreateVkImageFromAhbHandle( base::android::ScopedHardwareBufferHandle ahb_handle, SharedContextState* context_state, diff --git a/gpu/command_buffer/service/ahardwarebuffer_utils.h b/gpu/command_buffer/service/ahardwarebuffer_utils.h index 64822150695e0..234f2307823cc 100644 --- a/gpu/command_buffer/service/ahardwarebuffer_utils.h +++ b/gpu/command_buffer/service/ahardwarebuffer_utils.h @@ -23,8 +23,6 @@ class ScopedHardwareBufferHandle; } // namespace base namespace gfx { -class ColorSpace; -class Rect; class Size; } // namespace gfx @@ -32,11 +30,6 @@ namespace gpu { class SharedContextState; class VulkanImage; -namespace gles2 { -class Texture; -class TexturePassthrough; -} // namespace gles2 - // TODO(vikassoni): In future we will need to expose the set of formats and // constraints (e.g. max size) to the clients somehow that are available for // certain combinations of SharedImageUsage flags (e.g. when Vulkan is on, @@ -52,26 +45,6 @@ AHardwareBufferSupportedFormat(viz::ResourceFormat format); // Returns the corresponding AHardwareBuffer format. unsigned int GPU_GLES2_EXPORT AHardwareBufferFormat(viz::ResourceFormat format); -// Generates a gles2 texture from AHB. This method must be called with a current -// GLContext which will be used to create the Texture. This method adds a -// lightweight ref on the Texture which the caller is responsible for releasing. -gles2::Texture* GenGLTexture(AHardwareBuffer* buffer, - GLenum target, - const gfx::ColorSpace& color_space, - const gfx::Size& size, - const size_t estimated_size, - const gfx::Rect& cleared_rect); - -// Generates a passthrough texture from AHB. This method must be called with a -// current GLContext which will be used to create the Texture. -scoped_refptr GenGLTexturePassthrough( - AHardwareBuffer* buffer, - GLenum target, - const gfx::ColorSpace& color_space, - const gfx::Size& size, - const size_t estimated_size, - const gfx::Rect& cleared_rect); - // Create a vulkan image from the AHB handle. std::unique_ptr CreateVkImageFromAhbHandle( base::android::ScopedHardwareBufferHandle ahb_handle, diff --git a/gpu/command_buffer/service/shared_image/ahardwarebuffer_image_backing_factory.cc b/gpu/command_buffer/service/shared_image/ahardwarebuffer_image_backing_factory.cc index 865b8469bf71c..74e7209eb8abd 100644 --- a/gpu/command_buffer/service/shared_image/ahardwarebuffer_image_backing_factory.cc +++ b/gpu/command_buffer/service/shared_image/ahardwarebuffer_image_backing_factory.cc @@ -52,9 +52,9 @@ #include "ui/gl/gl_context.h" #include "ui/gl/gl_fence_android_native_fence_sync.h" #include "ui/gl/gl_gl_api_implementation.h" -#include "ui/gl/gl_image_ahardwarebuffer.h" #include "ui/gl/gl_utils.h" #include "ui/gl/gl_version_info.h" +#include "ui/gl/scoped_binders.h" namespace gpu { namespace { @@ -119,6 +119,21 @@ class OverlayImage final : public base::RefCounted { base::ScopedFD previous_end_read_fence_; }; +GLuint CreateAndBindTexture(EGLImage image, GLenum target) { + gl::GLApi* api = gl::g_current_gl_context; + GLuint service_id = 0; + api->glGenTexturesFn(1, &service_id); + gl::ScopedTextureBinder texture_binder(target, service_id); + + api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glEGLImageTargetTexture2DOES(target, image); + + return service_id; +} } // namespace // Implementation of SharedImageBacking that holds an AHardwareBuffer. This @@ -322,19 +337,30 @@ AHardwareBufferImageBacking::ProduceGLTexture(SharedImageManager* manager, // backing. DCHECK(hardware_buffer_handle_.is_valid()); - // Note that we are not using GL_TEXTURE_EXTERNAL_OES target(here and all - // other places in this file) since sksurface - // doesn't supports it. As per the egl documentation - - // https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt - // if GL_OES_EGL_image is supported then may also be TEXTURE_2D. - auto* texture = - GenGLTexture(hardware_buffer_handle_.get(), GL_TEXTURE_2D, color_space(), - size(), GetEstimatedSize(), ClearedRect()); - if (!texture) + auto egl_image = + CreateEGLImageFromAHardwareBuffer(hardware_buffer_handle_.get()); + + if (!egl_image.is_valid()) { return nullptr; + } + + // Android documentation states that right GL format for RGBX AHardwareBuffer + // is GL_RGB8, so we don't use angle rgbx. + auto gl_format_desc = ToGLFormatDesc(format(), /*plane_index=*/0, + /*use_angle_rgbx_format=*/false); + GLuint service_id = + CreateAndBindTexture(egl_image.get(), gl_format_desc.target); + + auto* texture = + gles2::CreateGLES2TextureWithLightRef(service_id, gl_format_desc.target); + texture->SetLevelInfo(gl_format_desc.target, 0, + gl_format_desc.image_internal_format, size().width(), + size().height(), 1, 0, gl_format_desc.data_format, + gl_format_desc.data_type, ClearedRect()); + texture->SetImmutable(true, false); return std::make_unique( - manager, this, tracker, std::move(texture)); + manager, this, tracker, std::move(egl_image), std::move(texture)); } std::unique_ptr @@ -345,19 +371,25 @@ AHardwareBufferImageBacking::ProduceGLTexturePassthrough( // backing. DCHECK(hardware_buffer_handle_.is_valid()); - // Note that we are not using GL_TEXTURE_EXTERNAL_OES target(here and all - // other places in this file) since sksurface - // doesn't supports it. As per the egl documentation - - // https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt - // if GL_OES_EGL_image is supported then may also be TEXTURE_2D. - auto texture = GenGLTexturePassthrough(hardware_buffer_handle_.get(), - GL_TEXTURE_2D, color_space(), size(), - GetEstimatedSize(), ClearedRect()); - if (!texture) + auto egl_image = + CreateEGLImageFromAHardwareBuffer(hardware_buffer_handle_.get()); + if (!egl_image.is_valid()) { return nullptr; + } + + // Android documentation states that right GL format for RGBX AHardwareBuffer + // is GL_RGB8, so we don't use angle rgbx. + auto gl_format_desc = ToGLFormatDesc(format(), /*plane_index=*/0, + /*use_angle_rgbx_format=*/false); + GLuint service_id = + CreateAndBindTexture(egl_image.get(), gl_format_desc.target); + + auto texture = base::MakeRefCounted( + service_id, gl_format_desc.target); + texture->SetEstimatedSize(GetEstimatedSize()); return std::make_unique( - manager, this, tracker, std::move(texture)); + manager, this, tracker, std::move(egl_image), std::move(texture)); } std::unique_ptr diff --git a/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.cc b/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.cc index 2ece75d804184..50bc1a3ba4241 100644 --- a/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.cc +++ b/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.cc @@ -13,8 +13,10 @@ GLTextureAndroidImageRepresentation::GLTextureAndroidImageRepresentation( SharedImageManager* manager, AndroidImageBacking* backing, MemoryTypeTracker* tracker, + ui::ScopedEGLImage egl_image, gles2::Texture* texture) : GLTextureImageRepresentation(manager, backing, tracker), + egl_image_(std::move(egl_image)), texture_(texture) {} GLTextureAndroidImageRepresentation::~GLTextureAndroidImageRepresentation() { diff --git a/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.h b/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.h index 993e42bf2fc20..2cc530e72f677 100644 --- a/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.h +++ b/gpu/command_buffer/service/shared_image/gl_texture_android_image_representation.h @@ -8,6 +8,7 @@ #include "base/memory/raw_ptr.h" #include "gpu/command_buffer/service/shared_image/android_image_backing.h" #include "gpu/command_buffer/service/shared_image/shared_image_representation.h" +#include "ui/gl/scoped_egl_image.h" namespace gpu { class AndroidImageBacking; @@ -20,6 +21,7 @@ class GLTextureAndroidImageRepresentation GLTextureAndroidImageRepresentation(SharedImageManager* manager, AndroidImageBacking* backing, MemoryTypeTracker* tracker, + ui::ScopedEGLImage egl_image, gles2::Texture* texture); ~GLTextureAndroidImageRepresentation() override; @@ -38,6 +40,7 @@ class GLTextureAndroidImageRepresentation return static_cast(backing()); } + ui::ScopedEGLImage egl_image_; const raw_ptr texture_; RepresentationAccessMode mode_ = RepresentationAccessMode::kNone; }; diff --git a/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.cc b/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.cc index a3924005cf88e..eb2adc2327249 100644 --- a/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.cc +++ b/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.cc @@ -14,8 +14,10 @@ GLTexturePassthroughAndroidImageRepresentation:: SharedImageManager* manager, AndroidImageBacking* backing, MemoryTypeTracker* tracker, + ui::ScopedEGLImage egl_image, scoped_refptr texture) : GLTexturePassthroughImageRepresentation(manager, backing, tracker), + egl_image_(std::move(egl_image)), texture_(std::move(texture)) { // TODO(https://crbug.com/1172769): Remove this CHECK. CHECK(texture_); diff --git a/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.h b/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.h index 2f168f853ed64..6e0103beeab1f 100644 --- a/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.h +++ b/gpu/command_buffer/service/shared_image/gl_texture_passthrough_android_image_representation.h @@ -7,6 +7,7 @@ #include "gpu/command_buffer/service/shared_image/android_image_backing.h" #include "gpu/command_buffer/service/shared_image/shared_image_representation.h" +#include "ui/gl/scoped_egl_image.h" namespace gpu { class AndroidImageBacking; @@ -18,6 +19,7 @@ class GLTexturePassthroughAndroidImageRepresentation SharedImageManager* manager, AndroidImageBacking* backing, MemoryTypeTracker* tracker, + ui::ScopedEGLImage egl_image, scoped_refptr texture); ~GLTexturePassthroughAndroidImageRepresentation() override; @@ -37,6 +39,7 @@ class GLTexturePassthroughAndroidImageRepresentation return static_cast(backing()); } + ui::ScopedEGLImage egl_image_; scoped_refptr texture_; RepresentationAccessMode mode_ = RepresentationAccessMode::kNone; }; diff --git a/gpu/command_buffer/service/shared_image/video_image_reader_image_backing.cc b/gpu/command_buffer/service/shared_image/video_image_reader_image_backing.cc index 8e556df537d4c..c15a11c2df162 100644 --- a/gpu/command_buffer/service/shared_image/video_image_reader_image_backing.cc +++ b/gpu/command_buffer/service/shared_image/video_image_reader_image_backing.cc @@ -33,7 +33,6 @@ #include "third_party/skia/include/gpu/GrBackendSemaphore.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "ui/gl/android/egl_fence_utils.h" -#include "ui/gl/gl_image_ahardwarebuffer.h" #include "ui/gl/gl_utils.h" namespace gpu { @@ -43,12 +42,12 @@ void CreateAndBindEglImageFromAHB(AHardwareBuffer* buffer, GLuint service_id) { DCHECK(buffer); AHardwareBuffer_Desc desc; + base::AndroidHardwareBufferCompat::GetInstance().Describe(buffer, &desc); - auto egl_image = base::MakeRefCounted( - gfx::Size(desc.width, desc.height)); - if (egl_image->Initialize(buffer, false)) { + auto egl_image = CreateEGLImageFromAHardwareBuffer(buffer); + if (egl_image.is_valid()) { glBindTexture(GL_TEXTURE_EXTERNAL_OES, service_id); - egl_image->BindTexImage(GL_TEXTURE_EXTERNAL_OES); + glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image.get()); } else { LOG(ERROR) << "Failed to create EGL image "; } diff --git a/ui/gl/BUILD.gn b/ui/gl/BUILD.gn index 9fa04fc9722cd..c66c07ab333d9 100644 --- a/ui/gl/BUILD.gn +++ b/ui/gl/BUILD.gn @@ -233,8 +233,6 @@ component("gl") { sources += [ "android/egl_fence_utils.cc", "android/egl_fence_utils.h", - "gl_image_ahardwarebuffer.cc", - "gl_image_ahardwarebuffer.h", "gl_surface_egl_surface_control.cc", "gl_surface_egl_surface_control.h", ] @@ -576,10 +574,6 @@ test("gl_unittests") { ] } - if (is_android) { - sources += [ "gl_image_ahardwarebuffer_unittest.cc" ] - } - if (is_linux || is_chromeos_lacros) { sources += [ "gl_image_native_pixmap_unittest.cc" ] } diff --git a/ui/gl/gl_image_ahardwarebuffer.cc b/ui/gl/gl_image_ahardwarebuffer.cc deleted file mode 100644 index a9f13a2847697..0000000000000 --- a/ui/gl/gl_image_ahardwarebuffer.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2017 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/gl/gl_image_ahardwarebuffer.h" - -#include "base/android/android_hardware_buffer_compat.h" -#include "base/android/scoped_hardware_buffer_fence_sync.h" -#include "ui/gl/gl_bindings.h" -#include "ui/gl/gl_fence_android_native_fence_sync.h" -#include "ui/gl/gl_utils.h" - -namespace gl { -namespace { - -uint32_t GetBufferFormat(const AHardwareBuffer* buffer) { - AHardwareBuffer_Desc desc = {}; - base::AndroidHardwareBufferCompat::GetInstance().Describe(buffer, &desc); - return desc.format; -} - -unsigned int GLInternalFormat(uint32_t buffer_format) { - switch (buffer_format) { - case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: - case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: - case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: - return GL_RGBA; - case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: - case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM: - case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM: - return GL_RGB; - default: - // For all other buffer formats, use GL_RGBA as internal format. - return GL_RGBA; - } -} - -unsigned int GLDataType(uint32_t buffer_format) { - switch (buffer_format) { - case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: - case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: - case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM: - return GL_UNSIGNED_BYTE; - case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: - return GL_HALF_FLOAT_OES; - case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: - return GL_UNSIGNED_INT_2_10_10_10_REV; - case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM: - return GL_UNSIGNED_SHORT_5_6_5; - default: - // For all other buffer formats, use GL_UNSIGNED_BYTE as type. - return GL_UNSIGNED_BYTE; - } -} - -} // namespace - -GLImageAHardwareBuffer::GLImageAHardwareBuffer(const gfx::Size& size) - : GLImageEGL(size) {} - -GLImageAHardwareBuffer::~GLImageAHardwareBuffer() {} - -bool GLImageAHardwareBuffer::Initialize(AHardwareBuffer* buffer, - bool preserved) { - handle_ = base::android::ScopedHardwareBufferHandle::Create(buffer); - uint32_t buffer_format = GetBufferFormat(buffer); - internal_format_ = GLInternalFormat(buffer_format); - data_type_ = GLDataType(buffer_format); - EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, preserved ? EGL_TRUE : EGL_FALSE, - EGL_NONE}; - EGLClientBuffer client_buffer = eglGetNativeClientBufferANDROID(buffer); - return GLImageEGL::Initialize(EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, - client_buffer, attribs); -} - -unsigned GLImageAHardwareBuffer::GetInternalFormat() { - return internal_format_; -} - -unsigned GLImageAHardwareBuffer::GetDataType() { - return data_type_; -} - -bool GLImageAHardwareBuffer::BindTexImage(unsigned target) { - return GLImageEGL::BindTexImage(target); -} - -bool GLImageAHardwareBuffer::CopyTexImage(unsigned target) { - return false; -} - -bool GLImageAHardwareBuffer::CopyTexSubImage(unsigned target, - const gfx::Point& offset, - const gfx::Rect& rect) { - return false; -} - -void GLImageAHardwareBuffer::OnMemoryDump( - base::trace_event::ProcessMemoryDump* pmd, - uint64_t process_tracing_id, - const std::string& dump_name) {} - -} // namespace gl diff --git a/ui/gl/gl_image_ahardwarebuffer.h b/ui/gl/gl_image_ahardwarebuffer.h deleted file mode 100644 index 0c11ff854a89c..0000000000000 --- a/ui/gl/gl_image_ahardwarebuffer.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_GL_GL_IMAGE_AHARDWAREBUFFER_H_ -#define UI_GL_GL_IMAGE_AHARDWAREBUFFER_H_ - -#include - -#include "base/android/scoped_hardware_buffer_handle.h" -#include "ui/gl/gl_bindings.h" -#include "ui/gl/gl_export.h" -#include "ui/gl/gl_image_egl.h" - -namespace gl { - -class GL_EXPORT GLImageAHardwareBuffer : public GLImageEGL { - public: - explicit GLImageAHardwareBuffer(const gfx::Size& size); - - GLImageAHardwareBuffer(const GLImageAHardwareBuffer&) = delete; - GLImageAHardwareBuffer& operator=(const GLImageAHardwareBuffer&) = delete; - - // Create an EGLImage from a given Android hardware buffer. - bool Initialize(AHardwareBuffer* buffer, bool preserved); - - // Overridden from GLImage: - unsigned GetInternalFormat() override; - unsigned GetDataType() override; - bool BindTexImage(unsigned target) override; - bool CopyTexImage(unsigned target) override; - bool CopyTexSubImage(unsigned target, - const gfx::Point& offset, - const gfx::Rect& rect) override; - void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, - uint64_t process_tracing_id, - const std::string& dump_name) override; - - protected: - ~GLImageAHardwareBuffer() override; - - private: - base::android::ScopedHardwareBufferHandle handle_; - unsigned internal_format_ = GL_RGBA; - unsigned data_type_ = GL_UNSIGNED_BYTE; -}; - -} // namespace gl - -#endif // UI_GL_GL_IMAGE_AHARDWAREBUFFER_H_ diff --git a/ui/gl/gl_image_ahardwarebuffer_unittest.cc b/ui/gl/gl_image_ahardwarebuffer_unittest.cc deleted file mode 100644 index b7c30ac247886..0000000000000 --- a/ui/gl/gl_image_ahardwarebuffer_unittest.cc +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2017 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include - -#include "base/android/android_hardware_buffer_compat.h" -#include "base/memory/scoped_refptr.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/gl/gl_image_ahardwarebuffer.h" -#include "ui/gl/test/gl_image_bind_test_template.h" -#include "ui/gl/test/gl_image_test_template.h" -#include "ui/gl/test/gl_image_zero_initialize_test_template.h" - -namespace gl { -namespace { - -const uint8_t kGreen[] = {0x0, 0xFF, 0x0, 0xFF}; - -template -class GLImageAHardwareBufferTestDelegate : public GLImageTestDelegateBase { - public: - scoped_refptr CreateSolidColorImage(const gfx::Size& size, - const uint8_t color[4]) const { - CHECK(base::AndroidHardwareBufferCompat::IsSupportAvailable()); - - // AHardwareBuffer_Desc's stride parameter is in pixels, not in bytes. - // - // We can't use the 3-byte-per-pixel AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM - // format in this test since there's no matching gfx::BufferFormat, - // gfx::BufferFormat::RGBX_8888 assumes 4 bytes per pixel. - const int kBytesPerPixel = 4; - - // cf. gpu_memory_buffer_impl_android_hardware_buffer - AHardwareBuffer_Desc desc = {}; - desc.width = size.width(); - desc.height = size.height(); - desc.layers = 1; // number of images - desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | - AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | - AHARDWAREBUFFER_USAGE_CPU_READ_RARELY | - AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY; - - switch (format) { - case gfx::BufferFormat::RGBA_8888: - desc.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM; - break; - case gfx::BufferFormat::RGBX_8888: - desc.format = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM; - break; - default: - NOTREACHED(); - } - - AHardwareBuffer* buffer = nullptr; - base::AndroidHardwareBufferCompat::GetInstance().Allocate(&desc, &buffer); - EXPECT_TRUE(buffer); - - uint8_t* data = nullptr; - int lock_result = base::AndroidHardwareBufferCompat::GetInstance().Lock( - buffer, AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY, -1, nullptr, - reinterpret_cast(&data)); - EXPECT_EQ(lock_result, 0); - EXPECT_TRUE(data); - - AHardwareBuffer_Desc desc_locked = {}; - base::AndroidHardwareBufferCompat::GetInstance().Describe(buffer, - &desc_locked); - - GLImageTestSupport::SetBufferDataToColor( - size.width(), size.height(), desc_locked.stride * kBytesPerPixel, 0, - format, color, data); - - int unlock_result = base::AndroidHardwareBufferCompat::GetInstance().Unlock( - buffer, nullptr); - EXPECT_EQ(unlock_result, 0); - - auto image = base::MakeRefCounted(size); - bool rv = image->Initialize(buffer, /* preserved */ true); - EXPECT_TRUE(rv); - return image; - } - - scoped_refptr CreateImage(const gfx::Size& size) const { - const uint8_t kTransparentBlack[4] = {0, 0, 0, 0}; - return CreateSolidColorImage(size, kTransparentBlack); - } - - unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } - const uint8_t* GetImageColor() { return kGreen; } - int GetAdmissibleError() const { return 0; } -}; - -using GLImageTestTypes = testing::Types< - GLImageAHardwareBufferTestDelegate, - GLImageAHardwareBufferTestDelegate>; - -using GLImageRGBTestTypes = testing::Types< - GLImageAHardwareBufferTestDelegate>; - -// Disable the tests by default for now since they require Android O, -// the test bots don't generally have that yet. For manual testing, -// add: --gtest_also_run_disabled_tests -f 'GLImageAHardwareBuffer/*' - -INSTANTIATE_TYPED_TEST_SUITE_P(DISABLED_GLImageAHardwareBuffer, - GLImageTest, - GLImageTestTypes); - -INSTANTIATE_TYPED_TEST_SUITE_P(DISABLED_GLImageAHardwareBuffer, - GLImageOddSizeTest, - GLImageTestTypes); - -INSTANTIATE_TYPED_TEST_SUITE_P(DISABLED_GLImageAHardwareBuffer, - GLImageBindTest, - GLImageTestTypes); - -INSTANTIATE_TYPED_TEST_SUITE_P(DISABLED_GLImageAHardwareBuffer, - GLImageZeroInitializeTest, - GLImageRGBTestTypes); - -} // namespace -} // namespace gl