3 * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
4 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef __GST_D3D11_WINDOW_H__
23 #define __GST_D3D11_WINDOW_H__
26 #include <gst/video/video.h>
27 #include <gst/d3d11/gstd3d11.h>
28 #include "gstd3d11overlaycompositor.h"
29 #include "gstd3d11pluginutils.h"
33 #define GST_TYPE_D3D11_WINDOW (gst_d3d11_window_get_type())
34 #define GST_D3D11_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_D3D11_WINDOW, GstD3D11Window))
35 #define GST_D3D11_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_D3D11_WINDOW, GstD3D11WindowClass))
36 #define GST_IS_D3D11_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_D3D11_WINDOW))
37 #define GST_IS_D3D11_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_D3D11_WINDOW))
38 #define GST_D3D11_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_D3D11_WINDOW, GstD3D11WindowClass))
39 #define GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE (gst_d3d11_window_fullscreen_toggle_mode_type())
41 typedef struct _GstD3D11Window GstD3D11Window;
42 typedef struct _GstD3D11WindowClass GstD3D11WindowClass;
44 #define GST_D3D11_WINDOW_FLOW_CLOSED GST_FLOW_CUSTOM_ERROR
48 GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_NONE = 0,
49 GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_ALT_ENTER = (1 << 1),
50 GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_PROPERTY = (1 << 2),
51 } GstD3D11WindowFullscreenToggleMode;
53 GType gst_d3d11_window_fullscreen_toggle_mode_type (void);
57 GST_D3D11_WINDOW_NATIVE_TYPE_NONE = 0,
58 GST_D3D11_WINDOW_NATIVE_TYPE_HWND,
59 GST_D3D11_WINDOW_NATIVE_TYPE_CORE_WINDOW,
60 GST_D3D11_WINDOW_NATIVE_TYPE_SWAP_CHAIN_PANEL,
61 } GstD3D11WindowNativeType;
66 guint texture_misc_flags;
70 GstBuffer *render_target;
71 IDXGIKeyedMutex *keyed_mutex;
72 } GstD3D11WindowSharedHandleData;
74 struct _GstD3D11Window
80 GstD3D11Device *device;
81 guintptr external_handle;
84 gboolean force_aspect_ratio;
85 gboolean enable_navigation_events;
86 GstD3D11WindowFullscreenToggleMode fullscreen_toggle_mode;
87 gboolean requested_fullscreen;
89 gboolean emit_present;
92 GstVideoInfo render_info;
93 GstD3D11Converter *converter;
94 GstD3D11OverlayCompositor *compositor;
96 /* calculated rect with aspect ratio and window area */
99 /* input resolution */
101 RECT prev_input_rect;
103 /* requested rect via gst_d3d11_window_render */
104 GstVideoRectangle rect;
107 guint surface_height;
109 IDXGISwapChain *swap_chain;
110 GstBuffer *backbuffer;
111 DXGI_FORMAT dxgi_format;
113 GstBuffer *cached_buffer;
114 gboolean first_present;
116 GstVideoOrientationMethod method;
119 struct _GstD3D11WindowClass
121 GstObjectClass object_class;
123 void (*show) (GstD3D11Window * window);
125 void (*update_swap_chain) (GstD3D11Window * window);
127 void (*change_fullscreen_mode) (GstD3D11Window * window);
129 gboolean (*create_swap_chain) (GstD3D11Window * window,
133 guint swapchain_flags,
134 IDXGISwapChain ** swap_chain);
136 GstFlowReturn (*present) (GstD3D11Window * window,
137 guint present_flags);
139 gboolean (*unlock) (GstD3D11Window * window);
141 gboolean (*unlock_stop) (GstD3D11Window * window);
143 void (*on_resize) (GstD3D11Window * window,
147 GstFlowReturn (*prepare) (GstD3D11Window * window,
149 guint display_height,
151 GstStructure * config,
152 DXGI_FORMAT display_format,
155 void (*unprepare) (GstD3D11Window * window);
157 gboolean (*open_shared_handle) (GstD3D11Window * window,
158 GstD3D11WindowSharedHandleData * data);
160 gboolean (*release_shared_handle) (GstD3D11Window * window,
161 GstD3D11WindowSharedHandleData * data);
163 void (*set_render_rectangle) (GstD3D11Window * window,
164 const GstVideoRectangle * rect);
166 void (*set_title) (GstD3D11Window * window,
170 GType gst_d3d11_window_get_type (void);
172 void gst_d3d11_window_show (GstD3D11Window * window);
174 void gst_d3d11_window_set_render_rectangle (GstD3D11Window * window,
175 const GstVideoRectangle * rect);
177 void gst_d3d11_window_set_title (GstD3D11Window * window,
180 void gst_d3d11_window_set_orientation (GstD3D11Window * window,
181 GstVideoOrientationMethod method);
183 GstFlowReturn gst_d3d11_window_prepare (GstD3D11Window * window,
185 guint display_height,
187 GstStructure * config,
188 DXGI_FORMAT display_format,
191 GstFlowReturn gst_d3d11_window_render (GstD3D11Window * window,
194 GstFlowReturn gst_d3d11_window_render_on_shared_handle (GstD3D11Window * window,
196 HANDLE shared_handle,
197 guint texture_misc_flags,
199 guint64 release_key);
201 gboolean gst_d3d11_window_unlock (GstD3D11Window * window);
203 gboolean gst_d3d11_window_unlock_stop (GstD3D11Window * window);
205 void gst_d3d11_window_unprepare (GstD3D11Window * window);
207 void gst_d3d11_window_on_key_event (GstD3D11Window * window,
211 void gst_d3d11_window_on_mouse_event (GstD3D11Window * window,
218 GstD3D11WindowNativeType gst_d3d11_window_get_native_type_from_handle (guintptr handle);
220 const gchar * gst_d3d11_window_get_native_type_to_string (GstD3D11WindowNativeType type);
222 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstD3D11Window, gst_object_unref)
226 #endif /* __GST_D3D11_WINDOW_H__ */