1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2010 Younes Manton & Thomas Balling Sørensen.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifndef VDPAU_PRIVATE_H
29bf215546Sopenharmony_ci#define VDPAU_PRIVATE_H
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include <assert.h>
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include <vdpau/vdpau.h>
34bf215546Sopenharmony_ci#include <vdpau/vdpau_x11.h>
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include "pipe/p_compiler.h"
37bf215546Sopenharmony_ci#include "pipe/p_video_codec.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "frontend/vdpau_interop.h"
40bf215546Sopenharmony_ci#include "frontend/vdpau_dmabuf.h"
41bf215546Sopenharmony_ci#include "frontend/vdpau_funcs.h"
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci#include "util/u_debug.h"
44bf215546Sopenharmony_ci#include "util/u_rect.h"
45bf215546Sopenharmony_ci#include "os/os_thread.h"
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci#include "vl/vl_video_buffer.h"
48bf215546Sopenharmony_ci#include "vl/vl_bicubic_filter.h"
49bf215546Sopenharmony_ci#include "vl/vl_compositor.h"
50bf215546Sopenharmony_ci#include "vl/vl_csc.h"
51bf215546Sopenharmony_ci#include "vl/vl_deint_filter.h"
52bf215546Sopenharmony_ci#include "vl/vl_matrix_filter.h"
53bf215546Sopenharmony_ci#include "vl/vl_median_filter.h"
54bf215546Sopenharmony_ci#include "vl/vl_winsys.h"
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci/* Full VDPAU API documentation available at :
57bf215546Sopenharmony_ci * ftp://download.nvidia.com/XFree86/vdpau/doxygen/html/index.html */
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci#define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
60bf215546Sopenharmony_ci#define QUOTEME(x) #x
61bf215546Sopenharmony_ci#define TOSTRING(x) QUOTEME(x)
62bf215546Sopenharmony_ci#define INFORMATION_STRING TOSTRING(INFORMATION)
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_cistatic inline enum pipe_video_chroma_format
65bf215546Sopenharmony_ciChromaToPipe(VdpChromaType vdpau_type)
66bf215546Sopenharmony_ci{
67bf215546Sopenharmony_ci   switch (vdpau_type) {
68bf215546Sopenharmony_ci      case VDP_CHROMA_TYPE_420:
69bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_420;
70bf215546Sopenharmony_ci      case VDP_CHROMA_TYPE_422:
71bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_422;
72bf215546Sopenharmony_ci      case VDP_CHROMA_TYPE_444:
73bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_444;
74bf215546Sopenharmony_ci      default:
75bf215546Sopenharmony_ci         assert(0);
76bf215546Sopenharmony_ci   }
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   return -1;
79bf215546Sopenharmony_ci}
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_cistatic inline VdpChromaType
82bf215546Sopenharmony_ciPipeToChroma(enum pipe_video_chroma_format pipe_type)
83bf215546Sopenharmony_ci{
84bf215546Sopenharmony_ci   switch (pipe_type) {
85bf215546Sopenharmony_ci      case PIPE_VIDEO_CHROMA_FORMAT_420:
86bf215546Sopenharmony_ci         return VDP_CHROMA_TYPE_420;
87bf215546Sopenharmony_ci      case PIPE_VIDEO_CHROMA_FORMAT_422:
88bf215546Sopenharmony_ci         return VDP_CHROMA_TYPE_422;
89bf215546Sopenharmony_ci      case PIPE_VIDEO_CHROMA_FORMAT_444:
90bf215546Sopenharmony_ci         return VDP_CHROMA_TYPE_444;
91bf215546Sopenharmony_ci      default:
92bf215546Sopenharmony_ci         assert(0);
93bf215546Sopenharmony_ci   }
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   return -1;
96bf215546Sopenharmony_ci}
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_cistatic inline enum pipe_video_chroma_format
99bf215546Sopenharmony_ciFormatYCBCRToPipeChroma(VdpYCbCrFormat vdpau_format)
100bf215546Sopenharmony_ci{
101bf215546Sopenharmony_ci   switch (vdpau_format) {
102bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_NV12:
103bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_420;
104bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_YV12:
105bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_420;
106bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_UYVY:
107bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_422;
108bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_YUYV:
109bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_422;
110bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_Y8U8V8A8:
111bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_444;
112bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_V8U8Y8A8:
113bf215546Sopenharmony_ci         return PIPE_VIDEO_CHROMA_FORMAT_444;
114bf215546Sopenharmony_ci      default:
115bf215546Sopenharmony_ci         assert(0);
116bf215546Sopenharmony_ci   }
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci   return PIPE_VIDEO_CHROMA_FORMAT_NONE;
119bf215546Sopenharmony_ci}
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_cistatic inline enum pipe_format
122bf215546Sopenharmony_ciFormatYCBCRToPipe(VdpYCbCrFormat vdpau_format)
123bf215546Sopenharmony_ci{
124bf215546Sopenharmony_ci   switch (vdpau_format) {
125bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_NV12:
126bf215546Sopenharmony_ci         return PIPE_FORMAT_NV12;
127bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_YV12:
128bf215546Sopenharmony_ci         return PIPE_FORMAT_YV12;
129bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_UYVY:
130bf215546Sopenharmony_ci         return PIPE_FORMAT_UYVY;
131bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_YUYV:
132bf215546Sopenharmony_ci         return PIPE_FORMAT_YUYV;
133bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_Y8U8V8A8:
134bf215546Sopenharmony_ci         return PIPE_FORMAT_R8G8B8A8_UNORM;
135bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_V8U8Y8A8:
136bf215546Sopenharmony_ci         return PIPE_FORMAT_B8G8R8A8_UNORM;
137bf215546Sopenharmony_ci#ifdef VDP_YCBCR_FORMAT_P010
138bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_P010:
139bf215546Sopenharmony_ci         return PIPE_FORMAT_P010;
140bf215546Sopenharmony_ci#endif
141bf215546Sopenharmony_ci#ifdef VDP_YCBCR_FORMAT_P016
142bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_P016:
143bf215546Sopenharmony_ci         return PIPE_FORMAT_P016;
144bf215546Sopenharmony_ci#endif
145bf215546Sopenharmony_ci      default:
146bf215546Sopenharmony_ci         /* NOTE: Can't be "unreachable", as it's quite reachable. */
147bf215546Sopenharmony_ci         assert(!"unexpected VdpYCbCrFormat");
148bf215546Sopenharmony_ci#ifdef VDP_YCBCR_FORMAT_Y_UV_444
149bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_Y_UV_444:
150bf215546Sopenharmony_ci#endif
151bf215546Sopenharmony_ci#ifdef VDP_YCBCR_FORMAT_Y_U_V_444
152bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_Y_U_V_444:
153bf215546Sopenharmony_ci#endif
154bf215546Sopenharmony_ci#ifdef VDP_YCBCR_FORMAT_Y_U_V_444_16
155bf215546Sopenharmony_ci      case VDP_YCBCR_FORMAT_Y_U_V_444_16:
156bf215546Sopenharmony_ci#endif
157bf215546Sopenharmony_ci         return PIPE_FORMAT_NONE;
158bf215546Sopenharmony_ci   }
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci}
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_cistatic inline VdpYCbCrFormat
163bf215546Sopenharmony_ciPipeToFormatYCBCR(enum pipe_format p_format)
164bf215546Sopenharmony_ci{
165bf215546Sopenharmony_ci   switch (p_format) {
166bf215546Sopenharmony_ci      case PIPE_FORMAT_NV12:
167bf215546Sopenharmony_ci         return VDP_YCBCR_FORMAT_NV12;
168bf215546Sopenharmony_ci      case PIPE_FORMAT_YV12:
169bf215546Sopenharmony_ci         return VDP_YCBCR_FORMAT_YV12;
170bf215546Sopenharmony_ci      case PIPE_FORMAT_UYVY:
171bf215546Sopenharmony_ci         return VDP_YCBCR_FORMAT_UYVY;
172bf215546Sopenharmony_ci      case PIPE_FORMAT_YUYV:
173bf215546Sopenharmony_ci         return VDP_YCBCR_FORMAT_YUYV;
174bf215546Sopenharmony_ci      case PIPE_FORMAT_R8G8B8A8_UNORM:
175bf215546Sopenharmony_ci        return VDP_YCBCR_FORMAT_Y8U8V8A8;
176bf215546Sopenharmony_ci      case PIPE_FORMAT_B8G8R8A8_UNORM:
177bf215546Sopenharmony_ci         return VDP_YCBCR_FORMAT_V8U8Y8A8;
178bf215546Sopenharmony_ci      default:
179bf215546Sopenharmony_ci         assert(0);
180bf215546Sopenharmony_ci   }
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_ci   return -1;
183bf215546Sopenharmony_ci}
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_cistatic inline VdpRGBAFormat
186bf215546Sopenharmony_ciPipeToFormatRGBA(enum pipe_format p_format)
187bf215546Sopenharmony_ci{
188bf215546Sopenharmony_ci   switch (p_format) {
189bf215546Sopenharmony_ci      case PIPE_FORMAT_A8_UNORM:
190bf215546Sopenharmony_ci         return VDP_RGBA_FORMAT_A8;
191bf215546Sopenharmony_ci      case PIPE_FORMAT_B10G10R10A2_UNORM:
192bf215546Sopenharmony_ci         return VDP_RGBA_FORMAT_B10G10R10A2;
193bf215546Sopenharmony_ci      case PIPE_FORMAT_B8G8R8A8_UNORM:
194bf215546Sopenharmony_ci         return VDP_RGBA_FORMAT_B8G8R8A8;
195bf215546Sopenharmony_ci      case PIPE_FORMAT_R10G10B10A2_UNORM:
196bf215546Sopenharmony_ci         return VDP_RGBA_FORMAT_R10G10B10A2;
197bf215546Sopenharmony_ci      case PIPE_FORMAT_R8G8B8A8_UNORM:
198bf215546Sopenharmony_ci         return VDP_RGBA_FORMAT_R8G8B8A8;
199bf215546Sopenharmony_ci      default:
200bf215546Sopenharmony_ci         assert(0);
201bf215546Sopenharmony_ci   }
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci   return -1;
204bf215546Sopenharmony_ci}
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_cistatic inline enum pipe_format
207bf215546Sopenharmony_ciFormatIndexedToPipe(VdpRGBAFormat vdpau_format)
208bf215546Sopenharmony_ci{
209bf215546Sopenharmony_ci   switch (vdpau_format) {
210bf215546Sopenharmony_ci      case VDP_INDEXED_FORMAT_A4I4:
211bf215546Sopenharmony_ci         return PIPE_FORMAT_R4A4_UNORM;
212bf215546Sopenharmony_ci      case VDP_INDEXED_FORMAT_I4A4:
213bf215546Sopenharmony_ci         return PIPE_FORMAT_A4R4_UNORM;
214bf215546Sopenharmony_ci      case VDP_INDEXED_FORMAT_A8I8:
215bf215546Sopenharmony_ci         return PIPE_FORMAT_A8R8_UNORM;
216bf215546Sopenharmony_ci      case VDP_INDEXED_FORMAT_I8A8:
217bf215546Sopenharmony_ci         return PIPE_FORMAT_R8A8_UNORM;
218bf215546Sopenharmony_ci      default:
219bf215546Sopenharmony_ci         assert(0);
220bf215546Sopenharmony_ci   }
221bf215546Sopenharmony_ci
222bf215546Sopenharmony_ci   return PIPE_FORMAT_NONE;
223bf215546Sopenharmony_ci}
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_cistatic inline enum pipe_format
226bf215546Sopenharmony_ciFormatColorTableToPipe(VdpColorTableFormat vdpau_format)
227bf215546Sopenharmony_ci{
228bf215546Sopenharmony_ci   switch(vdpau_format) {
229bf215546Sopenharmony_ci      case VDP_COLOR_TABLE_FORMAT_B8G8R8X8:
230bf215546Sopenharmony_ci         return PIPE_FORMAT_B8G8R8X8_UNORM;
231bf215546Sopenharmony_ci      default:
232bf215546Sopenharmony_ci         assert(0);
233bf215546Sopenharmony_ci   }
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ci   return PIPE_FORMAT_NONE;
236bf215546Sopenharmony_ci}
237bf215546Sopenharmony_ci
238bf215546Sopenharmony_cistatic inline enum pipe_video_profile
239bf215546Sopenharmony_ciProfileToPipe(VdpDecoderProfile vdpau_profile)
240bf215546Sopenharmony_ci{
241bf215546Sopenharmony_ci   switch (vdpau_profile) {
242bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_MPEG1:
243bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG1;
244bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_MPEG2_SIMPLE:
245bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
246bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_MPEG2_MAIN:
247bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
248bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_H264_BASELINE:
249bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
250bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE:
251bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE;
252bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_H264_MAIN:
253bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
254bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_H264_HIGH:
255bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
256bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_MPEG4_PART2_SP:
257bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE;
258bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_MPEG4_PART2_ASP:
259bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE;
260bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_VC1_SIMPLE:
261bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_VC1_SIMPLE;
262bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_VC1_MAIN:
263bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_VC1_MAIN;
264bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_VC1_ADVANCED:
265bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_VC1_ADVANCED;
266bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_HEVC_MAIN:
267bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_HEVC_MAIN;
268bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_HEVC_MAIN_10:
269bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_HEVC_MAIN_10;
270bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_HEVC_MAIN_STILL:
271bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL;
272bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_HEVC_MAIN_12:
273bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_HEVC_MAIN_12;
274bf215546Sopenharmony_ci      case VDP_DECODER_PROFILE_HEVC_MAIN_444:
275bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_HEVC_MAIN_444;
276bf215546Sopenharmony_ci      default:
277bf215546Sopenharmony_ci         return PIPE_VIDEO_PROFILE_UNKNOWN;
278bf215546Sopenharmony_ci   }
279bf215546Sopenharmony_ci}
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_cistatic inline VdpDecoderProfile
282bf215546Sopenharmony_ciPipeToProfile(enum pipe_video_profile p_profile)
283bf215546Sopenharmony_ci{
284bf215546Sopenharmony_ci   switch (p_profile) {
285bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG1:
286bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_MPEG1;
287bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
288bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_MPEG2_SIMPLE;
289bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
290bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_MPEG2_MAIN;
291bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
292bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_H264_BASELINE;
293bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
294bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE;
295bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
296bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_H264_MAIN;
297bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
298bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_H264_HIGH;
299bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
300bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_MPEG4_PART2_SP;
301bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
302bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
303bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
304bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_VC1_SIMPLE;
305bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_VC1_MAIN:
306bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_VC1_MAIN;
307bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
308bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_VC1_ADVANCED;
309bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_HEVC_MAIN:
310bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_HEVC_MAIN;
311bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_HEVC_MAIN_10:
312bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_HEVC_MAIN_10;
313bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL:
314bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_HEVC_MAIN_STILL;
315bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_HEVC_MAIN_12:
316bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_HEVC_MAIN_12;
317bf215546Sopenharmony_ci      case PIPE_VIDEO_PROFILE_HEVC_MAIN_444:
318bf215546Sopenharmony_ci         return VDP_DECODER_PROFILE_HEVC_MAIN_444;
319bf215546Sopenharmony_ci      default:
320bf215546Sopenharmony_ci         assert(0);
321bf215546Sopenharmony_ci         return -1;
322bf215546Sopenharmony_ci   }
323bf215546Sopenharmony_ci}
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_cistatic inline struct u_rect *
326bf215546Sopenharmony_ciRectToPipe(const VdpRect *src, struct u_rect *dst)
327bf215546Sopenharmony_ci{
328bf215546Sopenharmony_ci   if (src) {
329bf215546Sopenharmony_ci      dst->x0 = src->x0;
330bf215546Sopenharmony_ci      dst->y0 = src->y0;
331bf215546Sopenharmony_ci      dst->x1 = src->x1;
332bf215546Sopenharmony_ci      dst->y1 = src->y1;
333bf215546Sopenharmony_ci      return dst;
334bf215546Sopenharmony_ci   }
335bf215546Sopenharmony_ci   return NULL;
336bf215546Sopenharmony_ci}
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_cistatic inline struct pipe_box
339bf215546Sopenharmony_ciRectToPipeBox(const VdpRect *rect, struct pipe_resource *res)
340bf215546Sopenharmony_ci{
341bf215546Sopenharmony_ci   struct pipe_box box;
342bf215546Sopenharmony_ci
343bf215546Sopenharmony_ci   box.x = 0;
344bf215546Sopenharmony_ci   box.y = 0;
345bf215546Sopenharmony_ci   box.z = 0;
346bf215546Sopenharmony_ci   box.width = res->width0;
347bf215546Sopenharmony_ci   box.height = res->height0;
348bf215546Sopenharmony_ci   box.depth = 1;
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci   if (rect) {
351bf215546Sopenharmony_ci      if (rect->x1 > rect->x0 &&
352bf215546Sopenharmony_ci          rect->y1 > rect->y0) {
353bf215546Sopenharmony_ci         box.x = rect->x0;
354bf215546Sopenharmony_ci         box.y = rect->y0;
355bf215546Sopenharmony_ci         box.width = rect->x1 - box.x;
356bf215546Sopenharmony_ci         box.height = rect->y1 - box.y;
357bf215546Sopenharmony_ci      } else {
358bf215546Sopenharmony_ci         box.width = 0;
359bf215546Sopenharmony_ci         box.height = 0;
360bf215546Sopenharmony_ci      }
361bf215546Sopenharmony_ci   }
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci   return box;
364bf215546Sopenharmony_ci}
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_cistatic inline bool
367bf215546Sopenharmony_ciCheckSurfaceParams(struct pipe_screen *screen,
368bf215546Sopenharmony_ci                   const struct pipe_resource *templ)
369bf215546Sopenharmony_ci{
370bf215546Sopenharmony_ci   return screen->is_format_supported(screen, templ->format, templ->target,
371bf215546Sopenharmony_ci                                      templ->nr_samples,
372bf215546Sopenharmony_ci                                      templ->nr_storage_samples, templ->bind);
373bf215546Sopenharmony_ci}
374bf215546Sopenharmony_ci
375bf215546Sopenharmony_citypedef struct
376bf215546Sopenharmony_ci{
377bf215546Sopenharmony_ci   struct pipe_reference reference;
378bf215546Sopenharmony_ci   struct vl_screen *vscreen;
379bf215546Sopenharmony_ci   struct pipe_context *context;
380bf215546Sopenharmony_ci   struct vl_compositor compositor;
381bf215546Sopenharmony_ci   struct pipe_sampler_view *dummy_sv;
382bf215546Sopenharmony_ci   mtx_t mutex;
383bf215546Sopenharmony_ci} vlVdpDevice;
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_citypedef struct
386bf215546Sopenharmony_ci{
387bf215546Sopenharmony_ci   vlVdpDevice *device;
388bf215546Sopenharmony_ci   struct vl_compositor_state cstate;
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci   struct {
391bf215546Sopenharmony_ci       bool supported, enabled;
392bf215546Sopenharmony_ci       float luma_min, luma_max;
393bf215546Sopenharmony_ci   } luma_key;
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_ci   struct {
396bf215546Sopenharmony_ci	  bool supported, enabled, spatial;
397bf215546Sopenharmony_ci	  struct vl_deint_filter *filter;
398bf215546Sopenharmony_ci   } deint;
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ci   struct {
401bf215546Sopenharmony_ci	  bool supported, enabled;
402bf215546Sopenharmony_ci	  struct vl_bicubic_filter *filter;
403bf215546Sopenharmony_ci   } bicubic;
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci   struct {
406bf215546Sopenharmony_ci      bool supported, enabled;
407bf215546Sopenharmony_ci      unsigned level;
408bf215546Sopenharmony_ci      struct vl_median_filter *filter;
409bf215546Sopenharmony_ci   } noise_reduction;
410bf215546Sopenharmony_ci
411bf215546Sopenharmony_ci   struct {
412bf215546Sopenharmony_ci      bool supported, enabled;
413bf215546Sopenharmony_ci      float value;
414bf215546Sopenharmony_ci      struct vl_matrix_filter *filter;
415bf215546Sopenharmony_ci   } sharpness;
416bf215546Sopenharmony_ci
417bf215546Sopenharmony_ci   unsigned video_width, video_height;
418bf215546Sopenharmony_ci   enum pipe_video_chroma_format chroma_format;
419bf215546Sopenharmony_ci   unsigned max_layers, skip_chroma_deint;
420bf215546Sopenharmony_ci
421bf215546Sopenharmony_ci   bool custom_csc;
422bf215546Sopenharmony_ci   vl_csc_matrix csc;
423bf215546Sopenharmony_ci} vlVdpVideoMixer;
424bf215546Sopenharmony_ci
425bf215546Sopenharmony_citypedef struct
426bf215546Sopenharmony_ci{
427bf215546Sopenharmony_ci   vlVdpDevice *device;
428bf215546Sopenharmony_ci   struct pipe_video_buffer templat, *video_buffer;
429bf215546Sopenharmony_ci} vlVdpSurface;
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_citypedef struct
432bf215546Sopenharmony_ci{
433bf215546Sopenharmony_ci   vlVdpDevice *device;
434bf215546Sopenharmony_ci   struct pipe_sampler_view *sampler_view;
435bf215546Sopenharmony_ci} vlVdpBitmapSurface;
436bf215546Sopenharmony_ci
437bf215546Sopenharmony_citypedef uint64_t vlVdpTime;
438bf215546Sopenharmony_ci
439bf215546Sopenharmony_citypedef struct
440bf215546Sopenharmony_ci{
441bf215546Sopenharmony_ci   vlVdpDevice *device;
442bf215546Sopenharmony_ci   struct pipe_surface *surface;
443bf215546Sopenharmony_ci   struct pipe_sampler_view *sampler_view;
444bf215546Sopenharmony_ci   struct pipe_fence_handle *fence;
445bf215546Sopenharmony_ci   struct vl_compositor_state cstate;
446bf215546Sopenharmony_ci   struct u_rect dirty_area;
447bf215546Sopenharmony_ci   bool send_to_X;
448bf215546Sopenharmony_ci} vlVdpOutputSurface;
449bf215546Sopenharmony_ci
450bf215546Sopenharmony_citypedef struct
451bf215546Sopenharmony_ci{
452bf215546Sopenharmony_ci   vlVdpDevice *device;
453bf215546Sopenharmony_ci   Drawable drawable;
454bf215546Sopenharmony_ci} vlVdpPresentationQueueTarget;
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_citypedef struct
457bf215546Sopenharmony_ci{
458bf215546Sopenharmony_ci   vlVdpDevice *device;
459bf215546Sopenharmony_ci   Drawable drawable;
460bf215546Sopenharmony_ci   struct vl_compositor_state cstate;
461bf215546Sopenharmony_ci   vlVdpOutputSurface *last_surf;
462bf215546Sopenharmony_ci} vlVdpPresentationQueue;
463bf215546Sopenharmony_ci
464bf215546Sopenharmony_citypedef struct
465bf215546Sopenharmony_ci{
466bf215546Sopenharmony_ci   vlVdpDevice *device;
467bf215546Sopenharmony_ci   mtx_t mutex;
468bf215546Sopenharmony_ci   struct pipe_video_codec *decoder;
469bf215546Sopenharmony_ci} vlVdpDecoder;
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_citypedef uint32_t vlHandle;
472bf215546Sopenharmony_ci
473bf215546Sopenharmony_ciboolean vlCreateHTAB(void);
474bf215546Sopenharmony_civoid vlDestroyHTAB(void);
475bf215546Sopenharmony_civlHandle vlAddDataHTAB(void *data);
476bf215546Sopenharmony_civoid* vlGetDataHTAB(vlHandle handle);
477bf215546Sopenharmony_civoid vlRemoveDataHTAB(vlHandle handle);
478bf215546Sopenharmony_ci
479bf215546Sopenharmony_ciboolean vlGetFuncFTAB(VdpFuncId function_id, void **func);
480bf215546Sopenharmony_ci
481bf215546Sopenharmony_ci/* Public functions */
482bf215546Sopenharmony_ciVdpDeviceCreateX11 vdp_imp_device_create_x11;
483bf215546Sopenharmony_ci
484bf215546Sopenharmony_civoid vlVdpDefaultSamplerViewTemplate(struct pipe_sampler_view *templ, struct pipe_resource *res);
485bf215546Sopenharmony_ci
486bf215546Sopenharmony_ci/* Internal function pointers */
487bf215546Sopenharmony_ciVdpGetErrorString vlVdpGetErrorString;
488bf215546Sopenharmony_ciVdpDeviceDestroy vlVdpDeviceDestroy;
489bf215546Sopenharmony_civoid vlVdpDeviceFree(vlVdpDevice *dev);
490bf215546Sopenharmony_ciVdpGetProcAddress vlVdpGetProcAddress;
491bf215546Sopenharmony_ciVdpGetApiVersion vlVdpGetApiVersion;
492bf215546Sopenharmony_ciVdpGetInformationString vlVdpGetInformationString;
493bf215546Sopenharmony_ciVdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities;
494bf215546Sopenharmony_ciVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities;
495bf215546Sopenharmony_ciVdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities;
496bf215546Sopenharmony_ciVdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities;
497bf215546Sopenharmony_ciVdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities;
498bf215546Sopenharmony_ciVdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities;
499bf215546Sopenharmony_ciVdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities;
500bf215546Sopenharmony_ciVdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities;
501bf215546Sopenharmony_ciVdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport;
502bf215546Sopenharmony_ciVdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport;
503bf215546Sopenharmony_ciVdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
504bf215546Sopenharmony_ciVdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
505bf215546Sopenharmony_ciVdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
506bf215546Sopenharmony_ciVdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
507bf215546Sopenharmony_ciVdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
508bf215546Sopenharmony_ciVdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
509bf215546Sopenharmony_ciVdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
510bf215546Sopenharmony_ciVdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
511bf215546Sopenharmony_civoid vlVdpVideoSurfaceClear(vlVdpSurface *vlsurf);
512bf215546Sopenharmony_ciVdpDecoderCreate vlVdpDecoderCreate;
513bf215546Sopenharmony_ciVdpDecoderDestroy vlVdpDecoderDestroy;
514bf215546Sopenharmony_ciVdpDecoderGetParameters vlVdpDecoderGetParameters;
515bf215546Sopenharmony_ciVdpDecoderRender vlVdpDecoderRender;
516bf215546Sopenharmony_ciVdpOutputSurfaceCreate vlVdpOutputSurfaceCreate;
517bf215546Sopenharmony_ciVdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy;
518bf215546Sopenharmony_ciVdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters;
519bf215546Sopenharmony_ciVdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative;
520bf215546Sopenharmony_ciVdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative;
521bf215546Sopenharmony_ciVdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed;
522bf215546Sopenharmony_ciVdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr;
523bf215546Sopenharmony_ciVdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface;
524bf215546Sopenharmony_ciVdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface;
525bf215546Sopenharmony_ciVdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate;
526bf215546Sopenharmony_ciVdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy;
527bf215546Sopenharmony_ciVdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters;
528bf215546Sopenharmony_ciVdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative;
529bf215546Sopenharmony_ciVdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy;
530bf215546Sopenharmony_ciVdpPresentationQueueCreate vlVdpPresentationQueueCreate;
531bf215546Sopenharmony_ciVdpPresentationQueueDestroy vlVdpPresentationQueueDestroy;
532bf215546Sopenharmony_ciVdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor;
533bf215546Sopenharmony_ciVdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor;
534bf215546Sopenharmony_ciVdpPresentationQueueGetTime vlVdpPresentationQueueGetTime;
535bf215546Sopenharmony_ciVdpPresentationQueueDisplay vlVdpPresentationQueueDisplay;
536bf215546Sopenharmony_ciVdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle;
537bf215546Sopenharmony_ciVdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus;
538bf215546Sopenharmony_ciVdpPreemptionCallback vlVdpPreemptionCallback;
539bf215546Sopenharmony_ciVdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister;
540bf215546Sopenharmony_ciVdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables;
541bf215546Sopenharmony_ciVdpVideoMixerCreate vlVdpVideoMixerCreate;
542bf215546Sopenharmony_ciVdpVideoMixerRender vlVdpVideoMixerRender;
543bf215546Sopenharmony_ciVdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues;
544bf215546Sopenharmony_ciVdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport;
545bf215546Sopenharmony_ciVdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables;
546bf215546Sopenharmony_ciVdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues;
547bf215546Sopenharmony_ciVdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
548bf215546Sopenharmony_ciVdpVideoMixerDestroy vlVdpVideoMixerDestroy;
549bf215546Sopenharmony_ciVdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
550bf215546Sopenharmony_ci/* Winsys specific internal function pointers */
551bf215546Sopenharmony_ciVdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11;
552bf215546Sopenharmony_ci
553bf215546Sopenharmony_ci
554bf215546Sopenharmony_ci/* interop for GL gallium frontend */
555bf215546Sopenharmony_ciVdpVideoSurfaceGallium vlVdpVideoSurfaceGallium;
556bf215546Sopenharmony_ciVdpOutputSurfaceGallium vlVdpOutputSurfaceGallium;
557bf215546Sopenharmony_ciVdpVideoSurfaceDMABuf vlVdpVideoSurfaceDMABuf;
558bf215546Sopenharmony_ciVdpOutputSurfaceDMABuf vlVdpOutputSurfaceDMABuf;
559bf215546Sopenharmony_ci
560bf215546Sopenharmony_ci#define VDPAU_OUT   0
561bf215546Sopenharmony_ci#define VDPAU_ERR   1
562bf215546Sopenharmony_ci#define VDPAU_WARN  2
563bf215546Sopenharmony_ci#define VDPAU_TRACE 3
564bf215546Sopenharmony_ci
565bf215546Sopenharmony_cistatic inline void VDPAU_MSG(unsigned int level, const char *fmt, ...)
566bf215546Sopenharmony_ci{
567bf215546Sopenharmony_ci   static int debug_level = -1;
568bf215546Sopenharmony_ci
569bf215546Sopenharmony_ci   if (debug_level == -1) {
570bf215546Sopenharmony_ci      debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
571bf215546Sopenharmony_ci   }
572bf215546Sopenharmony_ci
573bf215546Sopenharmony_ci   if (level <= debug_level) {
574bf215546Sopenharmony_ci      va_list ap;
575bf215546Sopenharmony_ci      va_start(ap, fmt);
576bf215546Sopenharmony_ci      _debug_vprintf(fmt, ap);
577bf215546Sopenharmony_ci      va_end(ap);
578bf215546Sopenharmony_ci   }
579bf215546Sopenharmony_ci}
580bf215546Sopenharmony_ci
581bf215546Sopenharmony_cistatic inline void
582bf215546Sopenharmony_ciDeviceReference(vlVdpDevice **ptr, vlVdpDevice *dev)
583bf215546Sopenharmony_ci{
584bf215546Sopenharmony_ci   vlVdpDevice *old_dev = *ptr;
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci   if (pipe_reference(&(*ptr)->reference, &dev->reference))
587bf215546Sopenharmony_ci      vlVdpDeviceFree(old_dev);
588bf215546Sopenharmony_ci   *ptr = dev;
589bf215546Sopenharmony_ci}
590bf215546Sopenharmony_ci
591bf215546Sopenharmony_ci#endif /* VDPAU_PRIVATE_H */
592