diff options
-rw-r--r-- | opengl/libs/EGL/egl_platform_entries.cpp | 29 | ||||
-rw-r--r-- | vulkan/libvulkan/swapchain.cpp | 30 |
2 files changed, 38 insertions, 21 deletions
diff --git a/opengl/libs/EGL/egl_platform_entries.cpp b/opengl/libs/EGL/egl_platform_entries.cpp index de36a7aea6..f4dbe499eb 100644 --- a/opengl/libs/EGL/egl_platform_entries.cpp +++ b/opengl/libs/EGL/egl_platform_entries.cpp @@ -29,6 +29,7 @@ #include <private/android/AHardwareBufferHelpers.h> #include <stdlib.h> #include <string.h> +#include <aidl/android/hardware/graphics/common/PixelFormat.h> #include <condition_variable> #include <deque> @@ -564,9 +565,11 @@ void convertAttribs(const EGLAttrib* attribList, std::vector<EGLint>& newList) { newList.push_back(EGL_NONE); } +using PixelFormat = aidl::android::hardware::graphics::common::PixelFormat; + // Gets the native pixel format corrsponding to the passed EGLConfig. void getNativePixelFormat(EGLDisplay dpy, egl_connection_t* cnx, EGLConfig config, - android_pixel_format* format) { + PixelFormat* format) { // Set the native window's buffers format to match what this config requests. // Whether to use sRGB gamma is not part of the EGLconfig, but is part // of our native format. So if sRGB gamma is requested, we have to @@ -599,28 +602,30 @@ void getNativePixelFormat(EGLDisplay dpy, egl_connection_t* cnx, EGLConfig confi // strip colorspace from attribs. // endif if (a == 0) { - if (colorDepth <= 16) { - *format = HAL_PIXEL_FORMAT_RGB_565; + if (8 == r && 0 == g && 0 == b) { + *format = PixelFormat::R_8; + } else if (colorDepth <= 16) { + *format = PixelFormat::RGB_565; } else { if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) { if (colorDepth > 24) { - *format = HAL_PIXEL_FORMAT_RGBA_1010102; + *format = PixelFormat::RGBA_1010102; } else { - *format = HAL_PIXEL_FORMAT_RGBX_8888; + *format = PixelFormat::RGBX_8888; } } else { - *format = HAL_PIXEL_FORMAT_RGBA_FP16; + *format = PixelFormat::RGBA_FP16; } } } else { if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) { if (colorDepth > 24) { - *format = HAL_PIXEL_FORMAT_RGBA_1010102; + *format = PixelFormat::RGBA_1010102; } else { - *format = HAL_PIXEL_FORMAT_RGBA_8888; + *format = PixelFormat::RGBA_8888; } } else { - *format = HAL_PIXEL_FORMAT_RGBA_FP16; + *format = PixelFormat::RGBA_FP16; } } } @@ -678,7 +683,7 @@ EGLSurface eglCreateWindowSurfaceTmpl(egl_display_t* dp, egl_connection_t* cnx, } EGLDisplay iDpy = dp->disp.dpy; - android_pixel_format format; + PixelFormat format; getNativePixelFormat(iDpy, cnx, config, &format); // now select correct colorspace and dataspace based on user's attribute list @@ -694,7 +699,7 @@ EGLSurface eglCreateWindowSurfaceTmpl(egl_display_t* dp, egl_connection_t* cnx, attrib_list = strippedAttribList.data(); if (!cnx->useAngle) { - int err = native_window_set_buffers_format(window, format); + int err = native_window_set_buffers_format(window, static_cast<int>(format)); if (err != 0) { ALOGE("error setting native window pixel format: %s (%d)", strerror(-err), err); native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); @@ -818,7 +823,7 @@ EGLSurface eglCreatePbufferSurfaceImpl(EGLDisplay dpy, EGLConfig config, if (!dp) return EGL_NO_SURFACE; EGLDisplay iDpy = dp->disp.dpy; - android_pixel_format format; + PixelFormat format; getNativePixelFormat(iDpy, cnx, config, &format); // Select correct colorspace based on user's attribute list diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index b5a0bdfe6f..eb4befd5ec 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -23,6 +23,8 @@ #include <sync/sync.h> #include <system/window.h> #include <ui/BufferQueueDefs.h> +#include <ui/DebugUtils.h> +#include <ui/PixelFormat.h> #include <utils/StrongPointer.h> #include <utils/Timers.h> #include <utils/Trace.h> @@ -462,21 +464,24 @@ void copy_ready_timings(Swapchain& swapchain, *count = num_copied; } -android_pixel_format GetNativePixelFormat(VkFormat format) { - android_pixel_format native_format = HAL_PIXEL_FORMAT_RGBA_8888; +android::PixelFormat GetNativePixelFormat(VkFormat format) { + android::PixelFormat native_format = android::PIXEL_FORMAT_RGBA_8888; switch (format) { case VK_FORMAT_R8G8B8A8_UNORM: case VK_FORMAT_R8G8B8A8_SRGB: - native_format = HAL_PIXEL_FORMAT_RGBA_8888; + native_format = android::PIXEL_FORMAT_RGBA_8888; break; case VK_FORMAT_R5G6B5_UNORM_PACK16: - native_format = HAL_PIXEL_FORMAT_RGB_565; + native_format = android::PIXEL_FORMAT_RGB_565; break; case VK_FORMAT_R16G16B16A16_SFLOAT: - native_format = HAL_PIXEL_FORMAT_RGBA_FP16; + native_format = android::PIXEL_FORMAT_RGBA_FP16; break; case VK_FORMAT_A2B10G10R10_UNORM_PACK32: - native_format = HAL_PIXEL_FORMAT_RGBA_1010102; + native_format = android::PIXEL_FORMAT_RGBA_1010102; + break; + case VK_FORMAT_R8_UNORM: + native_format = android::PIXEL_FORMAT_R_8; break; default: ALOGV("unsupported swapchain format %d", format); @@ -758,6 +763,13 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, } } + desc.format = AHARDWAREBUFFER_FORMAT_R8_UNORM; + if (AHardwareBuffer_isSupported(&desc)) { + all_formats.emplace_back( + VkSurfaceFormatKHR{VK_FORMAT_R8_UNORM, + VK_COLOR_SPACE_PASS_THROUGH_EXT}); + } + VkResult result = VK_SUCCESS; if (formats) { uint32_t transfer_count = all_formats.size(); @@ -1034,7 +1046,7 @@ VkResult CreateSwapchainKHR(VkDevice device, if (!allocator) allocator = &GetData(device).allocator; - android_pixel_format native_pixel_format = + android::PixelFormat native_pixel_format = GetNativePixelFormat(create_info->imageFormat); android_dataspace native_dataspace = GetNativeDataspace(create_info->imageColorSpace); @@ -1131,8 +1143,8 @@ VkResult CreateSwapchainKHR(VkDevice device, err = native_window_set_buffers_format(window, native_pixel_format); if (err != android::OK) { - ALOGE("native_window_set_buffers_format(%d) failed: %s (%d)", - native_pixel_format, strerror(-err), err); + ALOGE("native_window_set_buffers_format(%s) failed: %s (%d)", + decodePixelFormat(native_pixel_format).c_str(), strerror(-err), err); return VK_ERROR_SURFACE_LOST_KHR; } err = native_window_set_buffers_data_space(window, native_dataspace); |