ref: 7f5cf34d06e4b8e7ff83e653c67532e92f4b462b
parent: e8fc62fc2ae012fafbd3d4f0e48d0f1a145fe8c5
author: Marvin Scholz <epirat07@gmail.com>
date: Thu May 14 22:23:19 EDT 2020
Dav1dPlay: Fix renderer selection
--- a/examples/dav1dplay.c
+++ b/examples/dav1dplay.c
@@ -42,6 +42,37 @@
#include "tools/input/input.h"
#include "dp_fifo.h"
+// Determine which renderer we are going to compile:
+// Selection order by preference:
+// - libplacebo Vulkan renderer
+// - libplacebo OpenGL renderer
+// - SDL2 renderer
+#ifdef HAVE_PLACEBO
+# include <libplacebo/config.h>
+#endif
+
+// Check libplacebo Vulkan rendering
+#if defined(HAVE_VULKAN) && defined(SDL_VIDEO_VULKAN)
+# if defined(PL_HAVE_VULKAN) && PL_HAVE_VULKAN
+# define HAVE_RENDERER_PLACEBO
+# define HAVE_PLACEBO_VULKAN
+# endif
+#endif
+
+// Check libplacebo OpenGL rendering
+#ifndef HAVE_RENDERER_PLACEBO
+# if defined(PL_HAVE_OPENGL) && PL_HAVE_OPENGL
+# define HAVE_RENDERER_PLACEBO
+# define HAVE_PLACEBO_OPENGL
+# endif
+#endif
+
+// Fallback to SDL if we can't use placebo
+#ifndef HAVE_RENDERER_PLACEBO
+# define HAVE_RENDERER_SDL
+#endif
+
+
/**
* Settings structure
* Hold all settings available for the player,
@@ -176,13 +207,13 @@
break;
case ARG_HIGH_QUALITY:
settings->highquality = true;
-#if !defined(HAVE_PLACEBO_VULKAN) && !defined(HAVE_PLACEBO_OPENGL)
+#ifndef HAVE_RENDERER_PLACEBO
fprintf(stderr, "warning: --highquality requires libplacebo\n");
#endif
break;
case 'z':
settings->zerocopy = true;
-#if !defined(HAVE_PLACEBO_VULKAN) && !defined(HAVE_PLACEBO_OPENGL)
+#ifndef HAVE_RENDERER_PLACEBO
fprintf(stderr, "warning: --zerocopy requires libplacebo\n");
#endif
break;
--- a/examples/dp_renderer.h
+++ b/examples/dp_renderer.h
@@ -45,7 +45,7 @@
void (*release_pic)(Dav1dPicture *pic, void *cookie);
} Dav1dPlayRenderInfo;
-#if defined(HAVE_PLACEBO_VULKAN) || defined(HAVE_PLACEBO_OPENGL)
+#ifdef HAVE_RENDERER_PLACEBO
# include "dp_renderer_placebo.h"
#else
# include "dp_renderer_sdl.h"
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -41,22 +41,24 @@
sdl2_dependency = dependency('sdl2', version: '>= 2.0.1', required: true)
if sdl2_dependency.found()
+ dav1dplay_deps = [sdl2_dependency]
+ dav1dplay_cflags = []
+
placebo_dependency = dependency('libplacebo', version: '>= 1.18.0', required: false)
- vulkan_dependency = dependency('vulkan', required: false)
- sdl_has_vulkan = cc.has_header('SDL_vulkan.h', dependencies: [sdl2_dependency])
- sdl_has_opengl = cc.has_header('SDL_opengl.h', dependencies: [sdl2_dependency])
- cflag_placebo = []
- deps_placebo = []
+
if placebo_dependency.found()
- deps_placebo += placebo_dependency
- if vulkan_dependency.found() and sdl_has_vulkan
- cflag_placebo += '-DHAVE_PLACEBO_VULKAN=1'
- deps_placebo += vulkan_dependency
+ dav1dplay_deps += placebo_dependency
+ dav1dplay_cflags += '-DHAVE_PLACEBO'
+
+ # If libplacebo is found, we might be able to use Vulkan
+ # with it, in which case we need the Vulkan library too.
+ vulkan_dependency = dependency('vulkan', required: false)
+ if vulkan_dependency.found()
+ dav1dplay_deps += vulkan_dependency
+ dav1dplay_cflags += '-DHAVE_VULKAN'
endif
- if sdl_has_opengl
- cflag_placebo += '-DHAVE_PLACEBO_OPENGL=1'
- endif
endif
+
dav1dplay = executable('dav1dplay',
dav1dplay_sources,
rev_target,
@@ -63,8 +65,8 @@
link_with : [libdav1d, dav1d_input_objs],
include_directories : [dav1d_inc_dirs],
- dependencies : [getopt_dependency, sdl2_dependency, deps_placebo],
+ dependencies : [getopt_dependency, dav1dplay_deps],
install : true,
- c_args : cflag_placebo,
+ c_args : dav1dplay_cflags,
)
endif