d3d11: Use configuration file for dxgi header version check
authorSeungha Yang <seungha.yang@navercorp.com>
Wed, 18 Dec 2019 04:21:31 +0000 (13:21 +0900)
committerSeungha Yang <seungha.yang@navercorp.com>
Fri, 20 Dec 2019 02:15:12 +0000 (11:15 +0900)
sys/d3d11/gstd3d11_fwd.h
sys/d3d11/gstd3d11device.c
sys/d3d11/gstd3d11window.c
sys/d3d11/meson.build

index 2e7219d..9485c20 100644 (file)
 #define __GST_D3D11_FWD_H__
 
 #include <gst/gst.h>
-
-/* define COBJMACROS to use d3d11 C APIs */
-#ifndef COBJMACROS
-#define COBJMACROS
-#endif
+#include "d3d11config.h"
 
 #ifndef INITGUID
 #include <initguid.h>
 #endif
 
 #include <d3d11.h>
-#ifdef HAVE_DXGI_1_5_H
+
+#if (DXGI_HEADER_VERSION >= 6)
+#include <dxgi1_6.h>
+#elif (DXGI_HEADER_VERSION >= 5)
 #include <dxgi1_5.h>
+#elif (DXGI_HEADER_VERSION >= 4)
+#include <dxgi1_4.h>
+#elif (DXGI_HEADER_VERSION >= 3)
+#include <dxgi1_3.h>
+#elif (DXGI_HEADER_VERSION >= 2)
+#include <dxgi1_2.h>
 #else
 #include <dxgi.h>
 #endif
index 9f11e43..05d3d60 100644 (file)
@@ -21,6 +21,8 @@
 #include "config.h"
 #endif
 
+#include "d3d11config.h"
+
 #include "gstd3d11device.h"
 #include "gstd3d11utils.h"
 #include "gmodule.h"
@@ -234,7 +236,10 @@ gst_d3d11_device_constructed (GObject * object)
   };
   D3D_FEATURE_LEVEL selected_level;
 
-#ifdef HAVE_DXGI_1_5_H
+  GST_DEBUG_OBJECT (self,
+      "Built with DXGI header version %d", DXGI_HEADER_VERSION);
+
+#if (DXGI_HEADER_VERSION >= 5)
   hr = CreateDXGIFactory1 (&IID_IDXGIFactory5, (void **) &factory);
   if (!gst_d3d11_result (hr)) {
     GST_INFO_OBJECT (self, "IDXGIFactory5 was unavailable");
index ddab50f..33b14b8 100644 (file)
@@ -24,6 +24,8 @@
 #include "config.h"
 #endif
 
+#include "d3d11config.h"
+
 #include "gstd3d11window.h"
 #include "gstd3d11device.h"
 #include "gstd3d11memory.h"
@@ -806,7 +808,7 @@ gst_d3d11_window_new (GstD3D11Device * device)
   return window;
 }
 
-#ifdef HAVE_DXGI_1_5_H
+#if (DXGI_HEADER_VERSION >= 5)
 static inline UINT16
 fraction_to_uint (guint num, guint den, guint scale)
 {
@@ -1008,7 +1010,7 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint width, guint height,
   GstCaps *render_caps;
   MakeWindowAssociationData mwa_data = { 0, };
   UINT swapchain_flags = 0;
-#if defined(HAVE_DXGI_1_5_H)
+#if (DXGI_HEADER_VERSION >= 5)
   gboolean have_cll = FALSE;
   gboolean have_mastering = FALSE;
   gboolean swapchain4_available = FALSE;
@@ -1075,7 +1077,7 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint width, guint height,
   }
 
   window->allow_tearing = FALSE;
-#if defined(HAVE_DXGI_1_5_H)
+#if (DXGI_HEADER_VERSION >= 5)
   if (!gst_video_content_light_level_from_caps (&window->content_light_level,
           caps)) {
     gst_video_content_light_level_init (&window->content_light_level);
@@ -1147,7 +1149,7 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint width, guint height,
   desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
   desc.BufferCount = 2;
   desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
-#if defined(HAVE_DXGI_1_5_H)
+#if (DXGI_HEADER_VERSION >= 5)
   /* For non-DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 color space support,
    * DXGI_SWAP_EFFECT_FLIP_DISCARD instead of DXGI_SWAP_EFFECT_DISCARD */
   if (swapchain4_available)
@@ -1175,7 +1177,7 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint width, guint height,
   gst_d3d11_device_thread_add (window->device,
       (GstD3D11DeviceThreadFunc) gst_d3d11_window_disable_alt_enter, &mwa_data);
 
-#if defined(HAVE_DXGI_1_5_H)
+#if (DXGI_HEADER_VERSION >= 5)
   if (swapchain4_available) {
     HRESULT hr;
     GST_DXGI_COLOR_SPACE_TYPE ctype;
@@ -1346,7 +1348,7 @@ _present_on_device_thread (GstD3D11Device * device, FramePresentData * data)
     gst_d3d11_color_converter_update_rect (self->converter, &rect);
     gst_d3d11_color_converter_convert (self->converter, srv, &self->rtv);
   }
-#ifdef HAVE_DXGI_1_5_H
+#if (DXGI_HEADER_VERSION >= 5)
   if (self->allow_tearing) {
     present_flags |= DXGI_PRESENT_ALLOW_TEARING;
   }
index 7e6783b..5b84d7b 100644 (file)
@@ -16,9 +16,20 @@ d3d11_sources = [
   'gstd3d11colorconverter.c',
 ]
 
+dxgi_headers = [
+  ['dxgi1_6.h', 6],
+  ['dxgi1_5.h', 5],
+  ['dxgi1_4.h', 4],
+  ['dxgi1_3.h', 3],
+  ['dxgi1_2.h', 2],
+  ['dxgi.h', 1]
+]
+
 have_d3d11 = false
-extra_c_args = []
+extra_c_args = ['-DCOBJMACROS']
+have_dxgi_header = false
 extra_dep = []
+d3d11_conf = configuration_data()
 
 d3d11_option = get_option('d3d11')
 if host_system != 'windows' or d3d11_option.disabled()
@@ -29,7 +40,14 @@ d3d11_lib = cc.find_library('d3d11', required : d3d11_option)
 dxgi_lib = cc.find_library('dxgi', required : d3d11_option)
 d3dcompiler_lib = cc.find_library('d3dcompiler', required: d3d11_option)
 
-have_d3d11 = d3d11_lib.found() and dxgi_lib.found() and cc.has_header('d3d11.h') and cc.has_header('dxgi.h') and cc.has_header('d3dcompiler.h')
+foreach dxgi_h: dxgi_headers
+  if not have_dxgi_header and cc.has_header(dxgi_h[0])
+    d3d11_conf.set('DXGI_HEADER_VERSION', dxgi_h[1])
+    have_dxgi_header = true
+  endif
+endforeach
+
+have_d3d11 = d3d11_lib.found() and dxgi_lib.found() and cc.has_header('d3d11.h') and have_dxgi_header and cc.has_header('d3dcompiler.h')
 if not have_d3d11
   if d3d11_option.enabled()
     error('The d3d11 plugin was enabled explicitly, but required dependencies were not found.')
@@ -37,17 +55,17 @@ if not have_d3d11
   subdir_done()
 endif
 
-# required for HDR metadata
-if cc.has_header('dxgi1_5.h')
-  extra_c_args += ['-DHAVE_DXGI_1_5_H']
-endif
-
 # for enabling debug layer
 if cc.has_header('d3d11sdklayers.h')
-  extra_c_args += ['-DHAVE_D3D11SDKLAYER_H']
+  d3d11_conf.set('HAVE_D3D11SDKLAYER_H', 1)
   extra_dep += [gmodule_dep]
 endif
 
+configure_file(
+  output: 'd3d11config.h',
+  configuration: d3d11_conf,
+)
+
 gstd3d11 = library('gstd3d11',
   d3d11_sources,
   c_args : gst_plugins_bad_args + extra_c_args,