Commit 2bd4e9c4 authored by Vikas Soni's avatar Vikas Soni Committed by Commit Bot

Add SharedImageRepresentationGLTextureAHardwareBuffer.

Implement SharedImageRepresentationGLTexture interface
for SharedImageBackingAHardwareBuffer.

Bug: 891060
Change-Id: I36429244c3643655124052392f983ee4713f60bb
Reviewed-on: https://chromium-review.googlesource.com/c/1294513
Commit-Queue: vikas soni <vikassoni@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602978}
parent 43d62bc1
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "components/viz/common/resources/resource_format.h" #include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/service/shared_image_backing_factory.h" #include "gpu/command_buffer/service/shared_image_backing_factory.h"
#include "gpu/gpu_gles2_export.h" #include "gpu/gpu_gles2_export.h"
#include "ui/gl/gl_bindings.h"
namespace gfx { namespace gfx {
class Size; class Size;
...@@ -18,7 +19,10 @@ class ColorSpace; ...@@ -18,7 +19,10 @@ class ColorSpace;
namespace gpu { namespace gpu {
class SharedImageBacking; class SharedImageBacking;
class GpuDriverBugWorkarounds; class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct Mailbox; struct Mailbox;
class MemoryTracker;
class MemoryTypeTracker;
// Implementation of SharedImageBackingFactory that produces AHardwareBuffer // Implementation of SharedImageBackingFactory that produces AHardwareBuffer
// backed SharedImages. This is meant to be used on Android only. // backed SharedImages. This is meant to be used on Android only.
...@@ -26,7 +30,9 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryAHardwareBuffer ...@@ -26,7 +30,9 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryAHardwareBuffer
: public SharedImageBackingFactory { : public SharedImageBackingFactory {
public: public:
SharedImageBackingFactoryAHardwareBuffer( SharedImageBackingFactoryAHardwareBuffer(
const GpuDriverBugWorkarounds& workarounds); const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
MemoryTracker* tracker);
~SharedImageBackingFactoryAHardwareBuffer() override; ~SharedImageBackingFactoryAHardwareBuffer() override;
// SharedImageBackingFactory implementation. // SharedImageBackingFactory implementation.
...@@ -38,8 +44,28 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryAHardwareBuffer ...@@ -38,8 +44,28 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryAHardwareBuffer
uint32_t usage) override; uint32_t usage) override;
private: private:
struct FormatInfo {
FormatInfo();
~FormatInfo();
// Whether this format is supported by AHardwareBuffer.
bool ahb_supported = false;
unsigned int ahb_format = 0;
// Whether this format can be used to create a GL texture from the AHB.
bool gl_supported = false;
// GL internal_format/format/type triplet.
GLuint internal_format = 0;
GLenum gl_format = 0;
GLenum gl_type = 0;
};
FormatInfo format_info_[viz::RESOURCE_FORMAT_MAX + 1];
// Used to limit the max size of AHardwareBuffer. // Used to limit the max size of AHardwareBuffer.
int32_t max_gl_texture_size_ = 0; int32_t max_gl_texture_size_ = 0;
std::unique_ptr<MemoryTypeTracker> memory_tracker_;
DISALLOW_COPY_AND_ASSIGN(SharedImageBackingFactoryAHardwareBuffer); DISALLOW_COPY_AND_ASSIGN(SharedImageBackingFactoryAHardwareBuffer);
}; };
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "gpu/command_buffer/common/shared_image_usage.h" #include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/mailbox_manager_impl.h" #include "gpu/command_buffer/service/mailbox_manager_impl.h"
#include "gpu/command_buffer/service/shared_image_backing.h" #include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image_manager.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/config/gpu_driver_bug_workarounds.h" #include "gpu/config/gpu_driver_bug_workarounds.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
...@@ -39,7 +42,8 @@ class SharedImageBackingFactoryAHardwareBufferTest : public testing::Test { ...@@ -39,7 +42,8 @@ class SharedImageBackingFactoryAHardwareBufferTest : public testing::Test {
GpuDriverBugWorkarounds workarounds; GpuDriverBugWorkarounds workarounds;
workarounds.max_texture_size = INT_MAX - 1; workarounds.max_texture_size = INT_MAX - 1;
backing_factory_ = backing_factory_ =
std::make_unique<SharedImageBackingFactoryAHardwareBuffer>(workarounds); std::make_unique<SharedImageBackingFactoryAHardwareBuffer>(
workarounds, GpuFeatureInfo(), nullptr);
} }
protected: protected:
...@@ -47,6 +51,7 @@ class SharedImageBackingFactoryAHardwareBufferTest : public testing::Test { ...@@ -47,6 +51,7 @@ class SharedImageBackingFactoryAHardwareBufferTest : public testing::Test {
scoped_refptr<gl::GLContext> context_; scoped_refptr<gl::GLContext> context_;
std::unique_ptr<SharedImageBackingFactoryAHardwareBuffer> backing_factory_; std::unique_ptr<SharedImageBackingFactoryAHardwareBuffer> backing_factory_;
gles2::MailboxManagerImpl mailbox_manager_; gles2::MailboxManagerImpl mailbox_manager_;
SharedImageManager shared_image_manager_;
}; };
// Basic test to check creation and deletion of AHB backed shared image. // Basic test to check creation and deletion of AHB backed shared image.
...@@ -63,13 +68,44 @@ TEST_F(SharedImageBackingFactoryAHardwareBufferTest, Basic) { ...@@ -63,13 +68,44 @@ TEST_F(SharedImageBackingFactoryAHardwareBufferTest, Basic) {
color_space, usage); color_space, usage);
EXPECT_TRUE(backing); EXPECT_TRUE(backing);
// There is no Legacy mailbox support in AHardwareBuffer Implementation. // Check clearing.
EXPECT_FALSE(backing->ProduceLegacyMailbox(&mailbox_manager_)); if (!backing->IsCleared()) {
backing->SetCleared();
EXPECT_TRUE(backing->IsCleared());
}
// First, validate via a legacy mailbox.
GLenum expected_target = GL_TEXTURE_EXTERNAL_OES;
EXPECT_TRUE(backing->ProduceLegacyMailbox(&mailbox_manager_));
TextureBase* texture_base = mailbox_manager_.ConsumeTexture(mailbox); TextureBase* texture_base = mailbox_manager_.ConsumeTexture(mailbox);
ASSERT_FALSE(texture_base);
// Destroy the backing resource. // Currently there is no support for passthrough texture on android and hence
backing->Destroy(); // in AHB backing. So the TextureBase* should be pointing to a Texture object.
auto* texture = gles2::Texture::CheckedCast(texture_base);
ASSERT_TRUE(texture);
EXPECT_EQ(texture->target(), expected_target);
EXPECT_TRUE(texture->IsImmutable());
int width, height, depth;
bool has_level =
texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, &depth);
EXPECT_TRUE(has_level);
EXPECT_EQ(width, size.width());
EXPECT_EQ(height, size.height());
// Next validate via a SharedImageRepresentationGLTexture.
EXPECT_TRUE(shared_image_manager_.Register(std::move(backing)));
auto gl_representation = shared_image_manager_.ProduceGLTexture(mailbox);
EXPECT_TRUE(gl_representation);
EXPECT_TRUE(gl_representation->GetTexture()->service_id());
EXPECT_EQ(expected_target, gl_representation->GetTexture()->target());
EXPECT_EQ(size, gl_representation->size());
EXPECT_EQ(format, gl_representation->format());
EXPECT_EQ(color_space, gl_representation->color_space());
EXPECT_EQ(usage, gl_representation->usage());
gl_representation.reset();
shared_image_manager_.Unregister(mailbox);
EXPECT_FALSE(mailbox_manager_.ConsumeTexture(mailbox));
} }
// Test to check invalid format support. // Test to check invalid format support.
......
...@@ -37,6 +37,7 @@ class DecoderContext; ...@@ -37,6 +37,7 @@ class DecoderContext;
class ServiceDiscardableManager; class ServiceDiscardableManager;
class SharedImageBackingGLTexture; class SharedImageBackingGLTexture;
class SharedImageBackingFactoryGLTexture; class SharedImageBackingFactoryGLTexture;
class SharedImageBackingAHardwareBuffer;
class SharedImageRepresentationGLTexture; class SharedImageRepresentationGLTexture;
namespace gles2 { namespace gles2 {
...@@ -354,6 +355,7 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -354,6 +355,7 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
friend class MailboxManagerTest; friend class MailboxManagerTest;
friend class gpu::SharedImageBackingGLTexture; friend class gpu::SharedImageBackingGLTexture;
friend class gpu::SharedImageBackingFactoryGLTexture; friend class gpu::SharedImageBackingFactoryGLTexture;
friend class gpu::SharedImageBackingAHardwareBuffer;
friend class TextureDefinition; friend class TextureDefinition;
friend class TextureManager; friend class TextureManager;
friend class TextureRef; friend class TextureRef;
......
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