From 9ba37d923c8ac83b2d57560f9d6fda9584f60ea1 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Thu, 5 May 2022 19:24:38 +0200 Subject: [PATCH] Make actual cursor extent a CVulkanTexture property --- src/drm.cpp | 4 ++-- src/rendervulkan.cpp | 18 +++++++++++++++--- src/rendervulkan.hpp | 19 ++++++++++--------- src/steamcompmgr.cpp | 29 ++++++++++------------------- src/steamcompmgr.hpp | 2 -- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/drm.cpp b/src/drm.cpp index b5c53f7..eeba66b 100644 --- a/src/drm.cpp +++ b/src/drm.cpp @@ -1125,7 +1125,7 @@ drm_prepare_basic( struct drm_t *drm, const struct FrameInfo_t *frameInfo ) if ( g_bRotated ) { - int64_t imageH = frameInfo->layers[ 0 ].imageHeight / frameInfo->layers[ 0 ].scale.y; + int64_t imageH = frameInfo->layers[ 0 ].tex->contentHeight() / frameInfo->layers[ 0 ].scale.y; int64_t tmp = crtcX; crtcX = g_nOutputHeight - imageH - crtcY; @@ -1188,7 +1188,7 @@ drm_prepare_liftoff( struct drm_t *drm, const struct FrameInfo_t *frameInfo ) uint64_t crtcH = srcHeight / frameInfo->layers[ i ].scale.y; if (g_bRotated) { - int64_t imageH = frameInfo->layers[ i ].imageHeight / frameInfo->layers[ i ].scale.y; + int64_t imageH = frameInfo->layers[ i ].tex->contentHeight() / frameInfo->layers[ i ].scale.y; const int32_t x = crtcX; const uint64_t w = crtcW; diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index ca76000..c17182b 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -347,7 +347,7 @@ static VkResult getModifierProps( const VkImageCreateInfo *imageInfo, uint64_t m return vkGetPhysicalDeviceImageFormatProperties2(physicalDevice, &imageFormatInfo, &imageProps); } -bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t drmFormat, createFlags flags, wlr_dmabuf_attributes *pDMA /* = nullptr */ ) +bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t drmFormat, createFlags flags, wlr_dmabuf_attributes *pDMA /* = nullptr */, uint32_t contentWidth /* = 0 */, uint32_t contentHeight /* = 0 */) { VkResult res = VK_ERROR_INITIALIZATION_FAILED; @@ -530,6 +530,18 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t drmFormat, m_width = width; m_height = height; + + if (contentWidth && contentHeight) + { + m_contentWidth = contentWidth; + m_contentHeight = contentHeight; + } + else + { + m_contentWidth = width; + m_contentHeight = height; + } + m_format = imageInfo.format; res = vkCreateImage(device, &imageInfo, nullptr, &m_vkImage); @@ -2204,14 +2216,14 @@ std::shared_ptr vulkan_create_texture_from_dmabuf( struct wlr_dm return pTex; } -std::shared_ptr vulkan_create_texture_from_bits( uint32_t width, uint32_t height, uint32_t drmFormat, CVulkanTexture::createFlags texCreateFlags, void *bits ) +std::shared_ptr vulkan_create_texture_from_bits( uint32_t width, uint32_t height, uint32_t contentWidth, uint32_t contentHeight, uint32_t drmFormat, CVulkanTexture::createFlags texCreateFlags, void *bits ) { std::shared_ptr pTex = std::make_shared(); texCreateFlags.bSampled = true; texCreateFlags.bTransferDst = true; - if ( pTex->BInit( width, height, drmFormat, texCreateFlags ) == false ) + if ( pTex->BInit( width, height, drmFormat, texCreateFlags, nullptr, contentWidth, contentHeight) == false ) return nullptr; memcpy( pUploadBuffer, bits, width * height * 4 ); diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp index 52aa4bb..ecf10ba 100644 --- a/src/rendervulkan.hpp +++ b/src/rendervulkan.hpp @@ -93,13 +93,15 @@ public: bool bExportable : 1; }; - bool BInit( uint32_t width, uint32_t height, uint32_t drmFormat, createFlags flags, wlr_dmabuf_attributes *pDMA = nullptr ); + bool BInit( uint32_t width, uint32_t height, uint32_t drmFormat, createFlags flags, wlr_dmabuf_attributes *pDMA = nullptr, uint32_t contentWidth = 0, uint32_t contentHeight = 0 ); inline VkImageView view( bool linear ) { return linear ? m_linearView : m_srgbView; } inline VkImageView linearView() { return m_linearView; } inline VkImageView srgbView() { return m_srgbView; } inline uint32_t width() { return m_width; } inline uint32_t height() { return m_height; } + inline uint32_t contentWidth() {return m_contentWidth; } + inline uint32_t contentHeight() {return m_contentHeight; } inline uint32_t rowPitch() { return m_unRowPitch; } inline uint32_t fbid() { return m_FBID; } inline void *mappedData() { return m_pMappedData; } @@ -121,7 +123,12 @@ private: VkImageView m_srgbView = VK_NULL_HANDLE; VkImageView m_linearView = VK_NULL_HANDLE; - uint32_t m_width = 0, m_height = 0; + uint32_t m_width = 0; + uint32_t m_height = 0; + + uint32_t m_contentWidth = 0; + uint32_t m_contentHeight = 0; + uint32_t m_unRowPitch = 0; uint32_t m_FBID = 0; @@ -150,12 +157,6 @@ struct FrameInfo_t { std::shared_ptr tex; uint32_t fbid; // TODO pretty sure we can just move this into tex - - // Cursor has a bigger surface than the actual image - // TODO maybe move into tex? - int imageWidth; - int imageHeight; - int zpos; vec2_t offset; @@ -205,7 +206,7 @@ bool vulkan_init_formats(void); bool vulkan_make_output(void); std::shared_ptr vulkan_create_texture_from_dmabuf( struct wlr_dmabuf_attributes *pDMA ); -std::shared_ptr vulkan_create_texture_from_bits( uint32_t width, uint32_t height, uint32_t drmFormat, CVulkanTexture::createFlags texCreateFlags, void *bits ); +std::shared_ptr vulkan_create_texture_from_bits( uint32_t width, uint32_t height, uint32_t contentWidth, uint32_t contentHeight, uint32_t drmFormat, CVulkanTexture::createFlags texCreateFlags, void *bits ); std::shared_ptr vulkan_create_texture_from_wlr_buffer( struct wlr_buffer *buf ); bool vulkan_composite( struct FrameInfo_t *frameInfo, std::shared_ptr pScreenshotTexture ); diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 4dab756..1c114e6 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -1131,17 +1131,17 @@ bool MouseCursor::getTexture() m_hotspotX = image->xhot; m_hotspotY = image->yhot; - m_imageWidth = image->width; - m_imageHeight = image->height; + uint32_t surfaceWidth; + uint32_t surfaceHeight; if ( BIsNested() == false && alwaysComposite == false ) { - m_surfaceWidth = g_DRM.cursor_width; - m_surfaceHeight = g_DRM.cursor_height; + surfaceWidth = g_DRM.cursor_width; + surfaceHeight = g_DRM.cursor_height; } else { - m_surfaceWidth = m_imageWidth; - m_surfaceHeight = m_imageHeight; + surfaceWidth = image->width; + surfaceHeight = image->height; } m_texture = nullptr; @@ -1149,12 +1149,12 @@ bool MouseCursor::getTexture() // Assume the cursor is fully translucent unless proven otherwise. bool bNoCursor = true; - auto cursorBuffer = std::vector(m_surfaceWidth * m_surfaceHeight); + auto cursorBuffer = std::vector(surfaceWidth * surfaceHeight); for (int i = 0; i < image->height; i++) { for (int j = 0; j < image->width; j++) { - cursorBuffer[i * m_surfaceWidth + j] = image->pixels[i * image->width + j]; + cursorBuffer[i * surfaceWidth + j] = image->pixels[i * image->width + j]; - if ( cursorBuffer[i * m_surfaceWidth + j] & 0xff000000 ) { + if ( cursorBuffer[i * surfaceWidth + j] & 0xff000000 ) { bNoCursor = false; } } @@ -1180,7 +1180,7 @@ bool MouseCursor::getTexture() // TODO: choose format & modifiers from cursor plane } - m_texture = vulkan_create_texture_from_bits(m_surfaceWidth, m_surfaceHeight, DRM_FORMAT_ARGB8888, texCreateFlags, cursorBuffer.data()); + m_texture = vulkan_create_texture_from_bits(surfaceWidth, surfaceHeight, image->width, image->height, DRM_FORMAT_ARGB8888, texCreateFlags, cursorBuffer.data()); assert(m_texture); XFree(image); m_dirty = false; @@ -1258,9 +1258,6 @@ void MouseCursor::paint(win *window, win *fit, struct FrameInfo_t *frameInfo) layer->offset.x = -scaledX; layer->offset.y = -scaledY; - layer->imageWidth = m_imageWidth; - layer->imageHeight = m_imageHeight; - layer->zpos = g_zposCursor; // cursor, on top of both bottom layers layer->tex = m_texture; @@ -1456,9 +1453,6 @@ paint_window(win *w, win *scaleW, struct FrameInfo_t *frameInfo, layer->blackBorder = flags & PaintWindowFlag::DrawBorders; - layer->imageWidth = w->a.width; - layer->imageHeight = w->a.height; - layer->zpos = g_zposBase; if ( w != scaleW ) @@ -1808,9 +1802,6 @@ paint_all() layer->scale.y = 1.0; layer->opacity = 1.0; - layer->imageWidth = g_nOutputWidth; - layer->imageHeight = g_nOutputHeight; - layer->tex = vulkan_get_last_output_image(); layer->fbid = layer->tex->fbid(); diff --git a/src/steamcompmgr.hpp b/src/steamcompmgr.hpp index f931433..2e7e031 100644 --- a/src/steamcompmgr.hpp +++ b/src/steamcompmgr.hpp @@ -77,8 +77,6 @@ private: int m_x = 0, m_y = 0; int m_hotspotX = 0, m_hotspotY = 0; - int m_surfaceWidth = 0, m_surfaceHeight = 0; - int m_imageWidth = 0, m_imageHeight = 0; std::shared_ptr m_texture; bool m_dirty;