Make actual cursor extent a CVulkanTexture property

This commit is contained in:
Georg Lehmann 2022-05-05 19:24:38 +02:00 committed by Joshie
parent 2c47fc57f0
commit 9ba37d923c
5 changed files with 37 additions and 35 deletions

View file

@ -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;

View file

@ -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<CVulkanTexture> vulkan_create_texture_from_dmabuf( struct wlr_dm
return pTex;
}
std::shared_ptr<CVulkanTexture> vulkan_create_texture_from_bits( uint32_t width, uint32_t height, uint32_t drmFormat, CVulkanTexture::createFlags texCreateFlags, void *bits )
std::shared_ptr<CVulkanTexture> 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<CVulkanTexture> pTex = std::make_shared<CVulkanTexture>();
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 );

View file

@ -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<CVulkanTexture> 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<CVulkanTexture> vulkan_create_texture_from_dmabuf( struct wlr_dmabuf_attributes *pDMA );
std::shared_ptr<CVulkanTexture> vulkan_create_texture_from_bits( uint32_t width, uint32_t height, uint32_t drmFormat, CVulkanTexture::createFlags texCreateFlags, void *bits );
std::shared_ptr<CVulkanTexture> 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<CVulkanTexture> vulkan_create_texture_from_wlr_buffer( struct wlr_buffer *buf );
bool vulkan_composite( struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTexture> pScreenshotTexture );

View file

@ -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<uint32_t>(m_surfaceWidth * m_surfaceHeight);
auto cursorBuffer = std::vector<uint32_t>(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();

View file

@ -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<CVulkanTexture> m_texture;
bool m_dirty;