diff options
Diffstat (limited to 'libs/hwui/renderthread/VulkanSurface.cpp')
-rw-r--r-- | libs/hwui/renderthread/VulkanSurface.cpp | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/libs/hwui/renderthread/VulkanSurface.cpp b/libs/hwui/renderthread/VulkanSurface.cpp index a7ea21d8c4de..c55942596e60 100644 --- a/libs/hwui/renderthread/VulkanSurface.cpp +++ b/libs/hwui/renderthread/VulkanSurface.cpp @@ -16,6 +16,7 @@ #include "VulkanSurface.h" +#include <GrDirectContext.h> #include <SkSurface.h> #include <algorithm> @@ -117,7 +118,7 @@ static bool ConnectAndSetWindowDefaults(ANativeWindow* window) { VulkanSurface* VulkanSurface::Create(ANativeWindow* window, ColorMode colorMode, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, - GrContext* grContext, const VulkanManager& vkManager, + GrDirectContext* grContext, const VulkanManager& vkManager, uint32_t extraBuffers) { // Connect and set native window to default configurations. if (!ConnectAndSetWindowDefaults(window)) { @@ -193,24 +194,25 @@ bool VulkanSurface::InitializeWindowInfoStruct(ANativeWindow* window, ColorMode outWindowInfo->bufferCount = static_cast<uint32_t>(query_value); } - outWindowInfo->dataspace = HAL_DATASPACE_V0_SRGB; - if (colorMode == ColorMode::WideColorGamut) { - skcms_Matrix3x3 surfaceGamut; - LOG_ALWAYS_FATAL_IF(!colorSpace->toXYZD50(&surfaceGamut), - "Could not get gamut matrix from color space"); - if (memcmp(&surfaceGamut, &SkNamedGamut::kSRGB, sizeof(surfaceGamut)) == 0) { - outWindowInfo->dataspace = HAL_DATASPACE_V0_SCRGB; - } else if (memcmp(&surfaceGamut, &SkNamedGamut::kDCIP3, sizeof(surfaceGamut)) == 0) { - outWindowInfo->dataspace = HAL_DATASPACE_DISPLAY_P3; - } else { - LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space."); - } - } + outWindowInfo->bufferFormat = ColorTypeToBufferFormat(colorType); + outWindowInfo->colorspace = colorSpace; + outWindowInfo->dataspace = ColorSpaceToADataSpace(colorSpace.get(), colorType); + LOG_ALWAYS_FATAL_IF(outWindowInfo->dataspace == HAL_DATASPACE_UNKNOWN, + "Unsupported colorspace"); - outWindowInfo->pixelFormat = ColorTypeToPixelFormat(colorType); - VkFormat vkPixelFormat = VK_FORMAT_R8G8B8A8_UNORM; - if (outWindowInfo->pixelFormat == PIXEL_FORMAT_RGBA_FP16) { - vkPixelFormat = VK_FORMAT_R16G16B16A16_SFLOAT; + VkFormat vkPixelFormat; + switch (colorType) { + case kRGBA_8888_SkColorType: + vkPixelFormat = VK_FORMAT_R8G8B8A8_UNORM; + break; + case kRGBA_F16_SkColorType: + vkPixelFormat = VK_FORMAT_R16G16B16A16_SFLOAT; + break; + case kRGBA_1010102_SkColorType: + vkPixelFormat = VK_FORMAT_A2B10G10R10_UNORM_PACK32; + break; + default: + LOG_ALWAYS_FATAL("Unsupported colorType: %d", (int)colorType); } LOG_ALWAYS_FATAL_IF(nullptr == vkManager.mGetPhysicalDeviceImageFormatProperties2, @@ -263,10 +265,10 @@ bool VulkanSurface::InitializeWindowInfoStruct(ANativeWindow* window, ColorMode bool VulkanSurface::UpdateWindow(ANativeWindow* window, const WindowInfo& windowInfo) { ATRACE_CALL(); - int err = native_window_set_buffers_format(window, windowInfo.pixelFormat); + int err = native_window_set_buffers_format(window, windowInfo.bufferFormat); if (err != 0) { ALOGE("VulkanSurface::UpdateWindow() native_window_set_buffers_format(%d) failed: %s (%d)", - windowInfo.pixelFormat, strerror(-err), err); + windowInfo.bufferFormat, strerror(-err), err); return false; } @@ -310,7 +312,7 @@ bool VulkanSurface::UpdateWindow(ANativeWindow* window, const WindowInfo& window } VulkanSurface::VulkanSurface(ANativeWindow* window, const WindowInfo& windowInfo, - GrContext* grContext) + GrDirectContext* grContext) : mNativeWindow(window), mWindowInfo(windowInfo), mGrContext(grContext) {} VulkanSurface::~VulkanSurface() { @@ -327,20 +329,16 @@ void VulkanSurface::releaseBuffers() { if (bufferInfo.buffer.get() != nullptr && bufferInfo.dequeued) { int err = mNativeWindow->cancelBuffer(mNativeWindow.get(), bufferInfo.buffer.get(), - bufferInfo.dequeue_fence); + bufferInfo.dequeue_fence.release()); if (err != 0) { ALOGE("cancelBuffer[%u] failed during destroy: %s (%d)", i, strerror(-err), err); } bufferInfo.dequeued = false; - - if (bufferInfo.dequeue_fence >= 0) { - close(bufferInfo.dequeue_fence); - bufferInfo.dequeue_fence = -1; - } + bufferInfo.dequeue_fence.reset(); } LOG_ALWAYS_FATAL_IF(bufferInfo.dequeued); - LOG_ALWAYS_FATAL_IF(bufferInfo.dequeue_fence != -1); + LOG_ALWAYS_FATAL_IF(bufferInfo.dequeue_fence.ok()); bufferInfo.skSurface.reset(); bufferInfo.buffer.clear(); @@ -363,8 +361,12 @@ VulkanSurface::NativeBufferInfo* VulkanSurface::dequeueNativeBuffer() { // Since auto pre-rotation is enabled, dequeueBuffer to get the consumer driven buffer size // from ANativeWindowBuffer. ANativeWindowBuffer* buffer; - int fence_fd; - err = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buffer, &fence_fd); + base::unique_fd fence_fd; + { + int rawFd = -1; + err = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buffer, &rawFd); + fence_fd.reset(rawFd); + } if (err != 0) { ALOGE("dequeueBuffer failed: %s (%d)", strerror(-err), err); return nullptr; @@ -385,7 +387,7 @@ VulkanSurface::NativeBufferInfo* VulkanSurface::dequeueNativeBuffer() { if (err != 0) { ALOGE("native_window_set_buffers_transform(%d) failed: %s (%d)", transformHint, strerror(-err), err); - mNativeWindow->cancelBuffer(mNativeWindow.get(), buffer, fence_fd); + mNativeWindow->cancelBuffer(mNativeWindow.get(), buffer, fence_fd.release()); return nullptr; } mWindowInfo.transform = transformHint; @@ -403,19 +405,19 @@ VulkanSurface::NativeBufferInfo* VulkanSurface::dequeueNativeBuffer() { for (idx = 0; idx < mWindowInfo.bufferCount; idx++) { if (mNativeBuffers[idx].buffer.get() == buffer) { mNativeBuffers[idx].dequeued = true; - mNativeBuffers[idx].dequeue_fence = fence_fd; + mNativeBuffers[idx].dequeue_fence = std::move(fence_fd); break; } else if (mNativeBuffers[idx].buffer.get() == nullptr) { // increasing the number of buffers we have allocated mNativeBuffers[idx].buffer = buffer; mNativeBuffers[idx].dequeued = true; - mNativeBuffers[idx].dequeue_fence = fence_fd; + mNativeBuffers[idx].dequeue_fence = std::move(fence_fd); break; } } if (idx == mWindowInfo.bufferCount) { ALOGE("dequeueBuffer returned unrecognized buffer"); - mNativeWindow->cancelBuffer(mNativeWindow.get(), buffer, fence_fd); + mNativeWindow->cancelBuffer(mNativeWindow.get(), buffer, fence_fd.release()); return nullptr; } @@ -424,10 +426,10 @@ VulkanSurface::NativeBufferInfo* VulkanSurface::dequeueNativeBuffer() { if (bufferInfo->skSurface.get() == nullptr) { bufferInfo->skSurface = SkSurface::MakeFromAHardwareBuffer( mGrContext, ANativeWindowBuffer_getHardwareBuffer(bufferInfo->buffer.get()), - kTopLeft_GrSurfaceOrigin, DataSpaceToColorSpace(mWindowInfo.dataspace), nullptr); + kTopLeft_GrSurfaceOrigin, mWindowInfo.colorspace, nullptr); if (bufferInfo->skSurface.get() == nullptr) { ALOGE("SkSurface::MakeFromAHardwareBuffer failed"); - mNativeWindow->cancelBuffer(mNativeWindow.get(), buffer, fence_fd); + mNativeWindow->cancelBuffer(mNativeWindow.get(), buffer, fence_fd.release()); return nullptr; } } @@ -458,25 +460,23 @@ bool VulkanSurface::presentCurrentBuffer(const SkRect& dirtyRect, int semaphoreF LOG_ALWAYS_FATAL_IF(!mCurrentBufferInfo); VulkanSurface::NativeBufferInfo& currentBuffer = *mCurrentBufferInfo; - int queuedFd = (semaphoreFd != -1) ? semaphoreFd : currentBuffer.dequeue_fence; + // queueBuffer always closes fence, even on error + int queuedFd = (semaphoreFd != -1) ? semaphoreFd : currentBuffer.dequeue_fence.release(); int err = mNativeWindow->queueBuffer(mNativeWindow.get(), currentBuffer.buffer.get(), queuedFd); currentBuffer.dequeued = false; - // queueBuffer always closes fence, even on error if (err != 0) { ALOGE("queueBuffer failed: %s (%d)", strerror(-err), err); + // cancelBuffer takes ownership of the fence mNativeWindow->cancelBuffer(mNativeWindow.get(), currentBuffer.buffer.get(), - currentBuffer.dequeue_fence); + currentBuffer.dequeue_fence.release()); } else { currentBuffer.hasValidContents = true; currentBuffer.lastPresentedCount = mPresentCount; mPresentCount++; } - if (currentBuffer.dequeue_fence >= 0) { - close(currentBuffer.dequeue_fence); - currentBuffer.dequeue_fence = -1; - } + currentBuffer.dequeue_fence.reset(); return err == 0; } |