rendervulkan: Add vulkan_acquire_screenshot_texture DRMFormat param
This commit is contained in:
parent
b3205caec4
commit
0b8c53dcbd
4 changed files with 22 additions and 6 deletions
|
@ -414,6 +414,16 @@ static int anonymous_shm_open(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
uint32_t spa_format_to_drm(uint32_t spa_format)
|
||||
{
|
||||
switch (spa_format)
|
||||
{
|
||||
case SPA_VIDEO_FORMAT_NV12: return DRM_FORMAT_NV12;
|
||||
default:
|
||||
case SPA_VIDEO_FORMAT_BGR: return DRM_FORMAT_XRGB8888;
|
||||
}
|
||||
}
|
||||
|
||||
static void stream_handle_add_buffer(void *user_data, struct pw_buffer *pw_buffer)
|
||||
{
|
||||
struct pipewire_state *state = (struct pipewire_state *) user_data;
|
||||
|
@ -428,7 +438,9 @@ static void stream_handle_add_buffer(void *user_data, struct pw_buffer *pw_buffe
|
|||
bool is_dmabuf = (spa_data->type & (1 << SPA_DATA_DmaBuf)) != 0;
|
||||
bool is_memfd = (spa_data->type & (1 << SPA_DATA_MemFd)) != 0;
|
||||
|
||||
buffer->texture = vulkan_acquire_screenshot_texture(s_nCaptureWidth, s_nCaptureHeight, is_dmabuf, state->video_info.format == SPA_VIDEO_FORMAT_NV12);
|
||||
uint32_t drmFormat = spa_format_to_drm(state->video_info.format);
|
||||
|
||||
buffer->texture = vulkan_acquire_screenshot_texture(s_nCaptureWidth, s_nCaptureHeight, is_dmabuf, drmFormat);
|
||||
assert(buffer->texture != nullptr);
|
||||
|
||||
if (is_dmabuf) {
|
||||
|
|
|
@ -3010,7 +3010,7 @@ void vulkan_garbage_collect( void )
|
|||
g_device.garbageCollect();
|
||||
}
|
||||
|
||||
std::shared_ptr<CVulkanTexture> vulkan_acquire_screenshot_texture(uint32_t width, uint32_t height, bool exportable, bool nv12)
|
||||
std::shared_ptr<CVulkanTexture> vulkan_acquire_screenshot_texture(uint32_t width, uint32_t height, bool exportable, uint32_t drmFormat)
|
||||
{
|
||||
for (auto& pScreenshotImage : g_output.pScreenshotImages)
|
||||
{
|
||||
|
@ -3021,13 +3021,13 @@ std::shared_ptr<CVulkanTexture> vulkan_acquire_screenshot_texture(uint32_t width
|
|||
CVulkanTexture::createFlags screenshotImageFlags;
|
||||
screenshotImageFlags.bMappable = true;
|
||||
screenshotImageFlags.bTransferDst = true;
|
||||
if (exportable || nv12) {
|
||||
if (exportable || drmFormat == DRM_FORMAT_NV12) {
|
||||
screenshotImageFlags.bExportable = true;
|
||||
screenshotImageFlags.bLinear = true; // TODO: support multi-planar DMA-BUF export via PipeWire
|
||||
screenshotImageFlags.bStorage = true;
|
||||
}
|
||||
|
||||
bool bSuccess = pScreenshotImage->BInit( width, height, nv12 ? DRM_FORMAT_NV12 : VulkanFormatToDRM(g_output.outputFormat), screenshotImageFlags );
|
||||
bool bSuccess = pScreenshotImage->BInit( width, height, drmFormat, screenshotImageFlags );
|
||||
|
||||
assert( bSuccess );
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ std::shared_ptr<CVulkanTexture> vulkan_create_texture_from_wlr_buffer( struct wl
|
|||
|
||||
bool vulkan_composite( const struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTexture> pScreenshotTexture );
|
||||
std::shared_ptr<CVulkanTexture> vulkan_get_last_output_image( void );
|
||||
std::shared_ptr<CVulkanTexture> vulkan_acquire_screenshot_texture(uint32_t width, uint32_t height, bool exportable, bool nv12);
|
||||
std::shared_ptr<CVulkanTexture> vulkan_acquire_screenshot_texture(uint32_t width, uint32_t height, bool exportable, uint32_t drmFormat);
|
||||
|
||||
void vulkan_present_to_window( void );
|
||||
|
||||
|
|
|
@ -1920,9 +1920,13 @@ paint_all(bool async)
|
|||
// hack: forced to nv12 rn
|
||||
bool bHackForceNV12DumpScreenshot = true;
|
||||
|
||||
uint32_t drmCaptureFormat = bHackForceNV12DumpScreenshot
|
||||
? DRM_FORMAT_NV12
|
||||
: DRM_FORMAT_XRGB8888;
|
||||
|
||||
if ( bCapture && pCaptureTexture == nullptr )
|
||||
{
|
||||
pCaptureTexture = vulkan_acquire_screenshot_texture(g_nOutputWidth, g_nOutputHeight, false, bHackForceNV12DumpScreenshot);
|
||||
pCaptureTexture = vulkan_acquire_screenshot_texture(g_nOutputWidth, g_nOutputHeight, false, drmCaptureFormat);
|
||||
}
|
||||
|
||||
bool bResult = vulkan_composite( &frameInfo, pCaptureTexture );
|
||||
|
|
Loading…
Reference in a new issue