EGL: Refcount external AHB when backing an image

When an image is backed by an external source like an AHB
we need to refcount the buffer appropriately to prevent
deletion of the buffer while in use.

Bug: angleproject:5018
Tests: angle_end2end_tests --gtest_filter=ImageTest.SourceAHBTarget2DEarlyDelete*
Change-Id: Ib6318fc3dc442460d1a2bdd6d75a4458895667bb
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2406615
Commit-Queue: Mohan Maiya <m.maiya@samsung.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Mohan Maiya
2020-09-11 12:47:52 -07:00
committed by Commit Bot
parent 2879eb5512
commit ed518d1585
2 changed files with 37 additions and 0 deletions

View File

@@ -149,6 +149,7 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
struct AHardwareBuffer *hardwareBuffer =
angle::android::ANativeWindowBufferToAHardwareBuffer(windowBuffer);
AHardwareBuffer_acquire(hardwareBuffer);
VkAndroidHardwareBufferFormatPropertiesANDROID bufferFormatProperties;
bufferFormatProperties.sType =
VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID;
@@ -271,6 +272,9 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
void HardwareBufferImageSiblingVkAndroid::onDestroy(const egl::Display *display)
{
AHardwareBuffer_release(angle::android::ANativeWindowBufferToAHardwareBuffer(
angle::android::ClientBufferToANativeWindowBuffer(mBuffer)));
ASSERT(mImage == nullptr);
}

View File

@@ -1434,6 +1434,39 @@ void ImageTest::Source2DTarget2DArray_helper(const EGLint *attribs)
glDeleteTextures(1, &target);
}
// Testing source AHB EGL image, target 2D texture and delete when in use
// If refcounted correctly, the test should pass without issues
TEST_P(ImageTest, SourceAHBTarget2DEarlyDelete)
{
EGLWindow *window = getEGLWindow();
ANGLE_SKIP_TEST_IF(!hasOESExt() || !hasBaseExt() || !has2DTextureExt());
ANGLE_SKIP_TEST_IF(!hasAndroidImageNativeBufferExt() || !hasAndroidHardwareBufferSupport());
GLubyte data[4] = {7, 51, 197, 231};
// Create the Image
AHardwareBuffer *source;
EGLImageKHR image;
createEGLImageAndroidHardwareBufferSource(1, 1, 1, GL_RGBA8, kDefaultAttribs, data, 4, &source,
&image);
// Create a texture target to bind the egl image
GLuint target;
createEGLImageTargetTexture2D(image, &target);
// Delete the source AHB when in use
destroyAndroidHardwareBuffer(source);
// Use texture target bound to egl image as source and render to framebuffer
// Verify that data in framebuffer matches that in the egl image
verifyResults2D(target, data);
// Clean up
glDeleteTextures(1, &target);
eglDestroyImageKHR(window->getDisplay(), image);
}
// Testing source AHB EGL image, target 2D texture
TEST_P(ImageTest, SourceAHBTarget2D)
{