SDL: Allow building testffmpeg without Vulkan support

From fcb132b8e83bcc1fb1e356ea1b126d00f39707f5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 8 Mar 2024 16:26:19 -0800
Subject: [PATCH] Allow building testffmpeg without Vulkan support

---
 test/CMakeLists.txt      |  5 ++++-
 test/testffmpeg_vulkan.c | 43 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 4f0fc5331b25e..7bc3049da4bf4 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -229,8 +229,11 @@ if(FFmpeg_FOUND)
     check_struct_has_member("AVVulkanFramesContext" "format" "libavutil/hwcontext_vulkan.h" LIBAVUTIL_AVFULKANFRAMESCONTEXT_HAS_FORMAT)
     cmake_pop_check_state()
 endif()
-if(FFmpeg_FOUND AND LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT AND LIBAVUTIL_AVFULKANFRAMESCONTEXT_HAS_FORMAT)
+if(FFmpeg_FOUND AND LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT)
     add_sdl_test_executable(testffmpeg NO_C90 SOURCES testffmpeg.c testffmpeg_vulkan.c ${icon_bmp_header})
+    if(LIBAVUTIL_AVFULKANFRAMESCONTEXT_HAS_FORMAT)
+      target_compile_definitions(testffmpeg PRIVATE FFMPEG_VULKAN_SUPPORT)
+    endif()
     if(APPLE)
         target_link_options(testffmpeg PRIVATE "-Wl,-framework,CoreVideo")
     endif()
diff --git a/test/testffmpeg_vulkan.c b/test/testffmpeg_vulkan.c
index 397b77919cfbb..6a80505e73b63 100644
--- a/test/testffmpeg_vulkan.c
+++ b/test/testffmpeg_vulkan.c
@@ -12,11 +12,13 @@
 #include <SDL3/SDL.h>
 #include <SDL3/SDL_vulkan.h>
 
+#include "testffmpeg_vulkan.h"
+
+#ifdef FFMPEG_VULKAN_SUPPORT
+
 #include <libavutil/hwcontext.h>
 #include <libavutil/hwcontext_vulkan.h>
 
-#include "testffmpeg_vulkan.h"
-
 #define VULKAN_FUNCTIONS()                                             \
     VULKAN_GLOBAL_FUNCTION(vkCreateInstance)                           \
     VULKAN_GLOBAL_FUNCTION(vkEnumerateInstanceExtensionProperties)     \
@@ -966,3 +968,40 @@ void DestroyVulkanVideoContext(VulkanVideoContext *context)
         SDL_free(context);
     }
 }
+
+#else
+
+VulkanVideoContext *CreateVulkanVideoContext(SDL_Window *window)
+{
+    SDL_SetError("testffmpeg not built with Vulkan support");
+    return NULL;
+}
+
+void SetupVulkanRenderProperties(VulkanVideoContext *context, SDL_PropertiesID props)
+{
+}
+
+void SetupVulkanDeviceContextData(VulkanVideoContext *context, AVVulkanDeviceContext *ctx)
+{
+}
+
+SDL_Texture *CreateVulkanVideoTexture(VulkanVideoContext *context, AVFrame *frame, SDL_Renderer *renderer, SDL_PropertiesID props)
+{
+    return NULL;
+}
+
+int BeginVulkanFrameRendering(VulkanVideoContext *context, AVFrame *frame, SDL_Renderer *renderer)
+{
+    return -1;
+}
+
+int FinishVulkanFrameRendering(VulkanVideoContext *context, AVFrame *frame, SDL_Renderer *renderer)
+{
+    return -1;
+}
+
+void DestroyVulkanVideoContext(VulkanVideoContext *context)
+{
+}
+
+#endif // FFMPEG_VULKAN_SUPPORT