Update emulated gralloc to use AHB format
... to match the existing real guest usage. This was okay since all of
the tests were using the drm format too but we should match.
Bug: b/283005889
Test: GfxstreamEnd2EndTests
Change-Id: I28600d8869a2977cb726ac483c3ab930148c3686
diff --git a/common/end2end/GfxstreamEnd2EndCompositionTests.cpp b/common/end2end/GfxstreamEnd2EndCompositionTests.cpp
index 4f5948b..56d5da2 100644
--- a/common/end2end/GfxstreamEnd2EndCompositionTests.cpp
+++ b/common/end2end/GfxstreamEnd2EndCompositionTests.cpp
@@ -30,7 +30,7 @@
auto layer1Ahb = GL_ASSERT(CreateAHBFromImage("256x256_android.png"));
auto layer2Ahb = GL_ASSERT(CreateAHBFromImage("256x256_android_with_transparency.png"));
auto resultAhb =
- GL_ASSERT(ScopedAHardwareBuffer::Allocate(*mGralloc, 256, 256, DRM_FORMAT_ABGR8888));
+ GL_ASSERT(ScopedAHardwareBuffer::Allocate(*mGralloc, 256, 256, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM));
const RenderControlComposition composition = {
.displayId = 0,
diff --git a/common/end2end/GfxstreamEnd2EndGlTests.cpp b/common/end2end/GfxstreamEnd2EndGlTests.cpp
index ac3934d..ff081b7 100644
--- a/common/end2end/GfxstreamEnd2EndGlTests.cpp
+++ b/common/end2end/GfxstreamEnd2EndGlTests.cpp
@@ -15,7 +15,6 @@
#include <log/log.h>
#include "GfxstreamEnd2EndTests.h"
-#include "drm_fourcc.h"
namespace gfxstream {
namespace tests {
@@ -455,7 +454,7 @@
const uint32_t width = 2;
const uint32_t height = 2;
auto ahb =
- GL_ASSERT(ScopedAHardwareBuffer::Allocate(*mGralloc, width, height, DRM_FORMAT_ABGR8888));
+ GL_ASSERT(ScopedAHardwareBuffer::Allocate(*mGralloc, width, height, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM));
{
uint8_t* mapped = GL_ASSERT(ahb.Lock());
diff --git a/common/end2end/GfxstreamEnd2EndTests.cpp b/common/end2end/GfxstreamEnd2EndTests.cpp
index 6198d4e..5d15b9d 100644
--- a/common/end2end/GfxstreamEnd2EndTests.cpp
+++ b/common/end2end/GfxstreamEnd2EndTests.cpp
@@ -649,7 +649,7 @@
auto image = GL_EXPECT(LoadImage(basename));
auto ahb = GL_EXPECT(
- ScopedAHardwareBuffer::Allocate(*mGralloc, image.width, image.height, DRM_FORMAT_ABGR8888));
+ ScopedAHardwareBuffer::Allocate(*mGralloc, image.width, image.height, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM));
{
uint8_t* ahbPixels = GL_EXPECT(ahb.Lock());
diff --git a/common/end2end/GfxstreamEnd2EndVkTests.cpp b/common/end2end/GfxstreamEnd2EndVkTests.cpp
index b36323b..d6463b6 100644
--- a/common/end2end/GfxstreamEnd2EndVkTests.cpp
+++ b/common/end2end/GfxstreamEnd2EndVkTests.cpp
@@ -18,7 +18,6 @@
#include <thread>
#include "GfxstreamEnd2EndTests.h"
-#include "drm_fourcc.h"
namespace gfxstream {
namespace tests {
@@ -51,7 +50,7 @@
const uint32_t width = 32;
const uint32_t height = 32;
AHardwareBuffer* ahb = nullptr;
- ASSERT_THAT(mGralloc->allocate(width, height, DRM_FORMAT_ABGR8888, -1, &ahb), Eq(0));
+ ASSERT_THAT(mGralloc->allocate(width, height, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM, -1, &ahb), Eq(0));
const VkNativeBufferANDROID imageNativeBufferInfo = {
.sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID,
@@ -179,7 +178,7 @@
const uint32_t width = 32;
const uint32_t height = 32;
AHardwareBuffer* ahb = nullptr;
- ASSERT_THAT(mGralloc->allocate(width, height, DRM_FORMAT_ABGR8888, -1, &ahb), Eq(0));
+ ASSERT_THAT(mGralloc->allocate(width, height, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM, -1, &ahb), Eq(0));
auto vkQueueSignalReleaseImageANDROID = PFN_vkQueueSignalReleaseImageANDROID(
device->getProcAddr("vkQueueSignalReleaseImageANDROID"));
diff --git a/guest/android/ANativeWindowEmulated.cpp b/guest/android/ANativeWindowEmulated.cpp
index d3e83c3..ce47551 100644
--- a/guest/android/ANativeWindowEmulated.cpp
+++ b/guest/android/ANativeWindowEmulated.cpp
@@ -16,8 +16,6 @@
#include <log/log.h>
-#include "drm_fourcc.h"
-
namespace gfxstream {
EmulatedANativeWindow::EmulatedANativeWindow(
@@ -182,14 +180,14 @@
std::vector<std::unique_ptr<EmulatedAHardwareBuffer>> buffers;
for (int i = 0; i < 3; i++) {
AHardwareBuffer* ahb = nullptr;
- if (gralloc->allocate(width, height, DRM_FORMAT_ABGR8888, -1, &ahb) != 0) {
+ if (gralloc->allocate(width, height, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM, -1, &ahb) != 0) {
ALOGE("Failed to allocate gralloc buffer.");
return nullptr;
}
buffers.emplace_back(reinterpret_cast<EmulatedAHardwareBuffer*>(ahb));
}
return reinterpret_cast<EGLNativeWindowType>(
- new EmulatedANativeWindow(width, height, DRM_FORMAT_ABGR8888, std::move(buffers)));
+ new EmulatedANativeWindow(width, height, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM, std::move(buffers)));
}
ANativeWindowHelper* createPlatformANativeWindowHelper() {
diff --git a/guest/android/GrallocEmulated.cpp b/guest/android/GrallocEmulated.cpp
index e2b1cb9..d120700 100644
--- a/guest/android/GrallocEmulated.cpp
+++ b/guest/android/GrallocEmulated.cpp
@@ -38,6 +38,38 @@
return std::nullopt;
}
+std::optional<uint32_t> AhbToDrmFormat(uint32_t ahbFormat) {
+ switch (ahbFormat) {
+ case GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM:
+ return DRM_FORMAT_ABGR8888;
+ case GFXSTREAM_AHB_FORMAT_R8G8B8X8_UNORM:
+ return DRM_FORMAT_XBGR8888;
+ case GFXSTREAM_AHB_FORMAT_R8G8B8_UNORM:
+ return DRM_FORMAT_BGR888;
+ /*
+ * Confusingly, AHARDWAREBUFFER_FORMAT_RGB_565 is defined as:
+ *
+ * "16-bit packed format that has 5-bit R, 6-bit G, and 5-bit B components, in that
+ * order, from the most-sigfinicant bits to the least-significant bits."
+ *
+ * so the order of the components is intentionally not flipped between the pixel
+ * format and the DRM format.
+ */
+ case GFXSTREAM_AHB_FORMAT_R5G6B5_UNORM:
+ return DRM_FORMAT_RGB565;
+ case GFXSTREAM_AHB_FORMAT_BLOB:
+ case GFXSTREAM_AHB_FORMAT_R8_UNORM:
+ return DRM_FORMAT_R8;
+ case GFXSTREAM_AHB_FORMAT_YV12:
+ return DRM_FORMAT_YVU420;
+ case GFXSTREAM_AHB_FORMAT_R16G16B16A16_FLOAT:
+ return DRM_FORMAT_ABGR16161616F;
+ case GFXSTREAM_AHB_FORMAT_R10G10B10A2_UNORM:
+ return DRM_FORMAT_ABGR2101010;
+ }
+ return std::nullopt;
+}
+
std::optional<uint32_t> DrmToVirglFormat(uint32_t drmFormat) {
switch (drmFormat) {
case DRM_FORMAT_ABGR8888:
@@ -135,10 +167,17 @@
return rahb->getResourceId();
}
-int EmulatedGralloc::allocate(uint32_t width, uint32_t height, uint32_t format, uint64_t usage,
+int EmulatedGralloc::allocate(uint32_t width, uint32_t height, uint32_t ahbFormat, uint64_t usage,
AHardwareBuffer** outputAhb) {
(void)usage;
- *outputAhb = allocate(width, height, format);
+
+ auto drmFormat = AhbToDrmFormat(ahbFormat);
+ if (!drmFormat) {
+ ALOGE("Unhandled AHB format:%u", ahbFormat);
+ return -1;
+ }
+
+ *outputAhb = allocate(width, height, *drmFormat);
return 0;
}
diff --git a/guest/android/include/gfxstream/guest/Gralloc.h b/guest/android/include/gfxstream/guest/Gralloc.h
index e385686..7d037cb 100644
--- a/guest/android/include/gfxstream/guest/Gralloc.h
+++ b/guest/android/include/gfxstream/guest/Gralloc.h
@@ -28,6 +28,31 @@
constexpr uint32_t kGlRGBA = 0x1908;
constexpr uint32_t kGlRGB565 = 0x8D62;
+// Buffer pixel formats mirrored from Android to avoid extra
+// build dependencies on Android libraries.
+enum {
+ GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM = 1,
+ GFXSTREAM_AHB_FORMAT_R8G8B8X8_UNORM = 2,
+ GFXSTREAM_AHB_FORMAT_R8G8B8_UNORM = 3,
+ GFXSTREAM_AHB_FORMAT_R5G6B5_UNORM = 4,
+ GFXSTREAM_AHB_FORMAT_B8G8R8A8_UNORM = 5,
+ GFXSTREAM_AHB_FORMAT_B5G5R5A1_UNORM = 6,
+ GFXSTREAM_AHB_FORMAT_B4G4R4A4_UNORM = 7,
+ GFXSTREAM_AHB_FORMAT_R16G16B16A16_FLOAT = 0x16,
+ GFXSTREAM_AHB_FORMAT_R10G10B10A2_UNORM = 0x2b,
+ GFXSTREAM_AHB_FORMAT_BLOB = 0x21,
+ GFXSTREAM_AHB_FORMAT_D16_UNORM = 0x30,
+ GFXSTREAM_AHB_FORMAT_D24_UNORM = 0x31,
+ GFXSTREAM_AHB_FORMAT_D24_UNORM_S8_UINT = 0x32,
+ GFXSTREAM_AHB_FORMAT_D32_FLOAT = 0x33,
+ GFXSTREAM_AHB_FORMAT_D32_FLOAT_S8_UINT = 0x34,
+ GFXSTREAM_AHB_FORMAT_S8_UINT = 0x35,
+ GFXSTREAM_AHB_FORMAT_Y8Cb8Cr8_420 = 0x23,
+ GFXSTREAM_AHB_FORMAT_YV12 = 0x32315659,
+ GFXSTREAM_AHB_FORMAT_IMPLEMENTATION_DEFINED = 0x22,
+ GFXSTREAM_AHB_FORMAT_R8_UNORM = 0x38,
+};
+
// Abstraction for gralloc handle conversion
class Gralloc {
public:
@@ -38,7 +63,7 @@
virtual void acquire(AHardwareBuffer* ahb) = 0;
virtual void release(AHardwareBuffer* ahb) = 0;
- virtual int allocate(uint32_t width, uint32_t height, uint32_t format, uint64_t usage,
+ virtual int allocate(uint32_t width, uint32_t height, uint32_t ahbFormat, uint64_t usage,
AHardwareBuffer** outputAhb) = 0;
virtual int lock(AHardwareBuffer* ahb, uint8_t** ptr) = 0;