1 /*
2 * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Waldo Bastian <waldo.bastian@intel.com>
26 *
27 */
28
29 #ifndef _PSB_DRV_VIDEO_H_
30 #define _PSB_DRV_VIDEO_H_
31
32 #include <pthread.h> /* POSIX threads headers */
33
34 #include <va/va_backend.h>
35 #include <va/va.h>
36 #include <va/va_tpi.h>
37
38 #include <va/va_vpp.h>
39
40 #include "object_heap.h"
41 #include "psb_def.h"
42 //#include "psb_drv_debug.h"
43 #include "xf86drm.h"
44 #ifdef ANDROID
45 #ifdef BAYTRAIL
46 #include <linux/vxd_drm.h>
47 #else
48 #include <linux/psb_drm.h>
49 #endif
50 #endif
51 #include "psb_overlay.h"
52 #include "psb_texture.h"
53 #include <stdint.h>
54 #ifndef ANDROID
55 #include <psb_drm.h>
56 #include <X11/Xlibint.h>
57 #include <X11/X.h>
58 #include <X11/extensions/Xv.h>
59 #include <X11/extensions/Xvlib.h>
60 #include <X11/Xlib.h>
61 #else
62 #define XID unsigned int
63 #define INT16 unsigned int
64 #include <cutils/log.h>
65 #include <system/window.h>
66 #undef LOG_TAG
67 #define LOG_TAG "pvr_drv_video"
68 #endif
69 #include "hwdefs/dxva_fw_flags.h"
70 #include <wsbm/wsbm_pool.h>
71
72 #ifdef __GNUC__
73 # define __maybe_unused __attribute__((__unused__))
74 #else
75 # define __maybe_unused
76 #endif
77
78 #ifndef min
79 #define min(a, b) ((a) < (b)) ? (a) : (b)
80 #endif
81
82 #ifndef max
83 #define max(a, b) ((a) > (b)) ? (a) : (b)
84 #endif
85
86 //#define _TOPAZHP_PDUMP_
87 #define TOPAZHP_PIPE_NUM 2
88
89 #define _TNG_RELOC_
90 //#define _TNG_FRAMES_
91 #define FORCED_REFERENCE 1
92 #define LTREFHEADER 1
93 //#define _TP_DEBUG_MMU_
94 //#define _TOPAZHP_REC_
95
96 /*
97 * WORKAROUND_DMA_OFF_BY_ONE: LLDMA requests may access one additional byte which can cause
98 * a MMU fault if the next byte after the buffer end is on a different page that isn't mapped.
99 */
100 #define WORKAROUND_DMA_OFF_BY_ONE
101 #define FOURCC_XVVA (('A' << 24) + ('V' << 16) + ('V' << 8) + 'X')
102
103 #define PSB_MAX_PROFILES 32
104 #define PSB_MAX_ENTRYPOINTS 32
105 #define PSB_MAX_CONFIG_ATTRIBUTES VAConfigAttribTypeMax
106
107 /* VABufferTypeMax is large(1000+) because there is big blank space between common libva buffer
108 * type and Intel specific buffer types(for GEN usage only). If use VABufferTypeMax as
109 * PSB_MAX_BUFFERTYPES to define the size of buffer type related arrays in context object,
110 * we will waste about 16K memory. Currently, the max value of buffer type used in psb_video is
111 * VAParseSliceHeaderGroupBufferType(44).
112 */
113 #define PSB_MAX_BUFFERTYPES 64
114
115 /* Max # of command submission buffers */
116 #define PSB_MAX_CMDBUFS 10
117 #define LNC_MAX_CMDBUFS_ENCODE 4
118 #define PNW_MAX_CMDBUFS_ENCODE 4
119 #define TNG_MAX_CMDBUFS_ENCODE 4
120 #define VSP_MAX_CMDBUFS 10
121
122 #define PSB_SURFACE_DISPLAYING_F (0x1U<<0)
123 #define PSB_SURFACE_IS_FLAG_SET(flags, mask) (((flags)& PSB_SURFACE_DISPLAYING_F) != 0)
124
125 #define PSB_CTX_TILING_MASK 0x00FF0000
126
127 /*xrandr dirty flag*/
128 #define PSB_NEW_ROTATION 1
129 #define PSB_NEW_EXTVIDEO 2
130
131 #define PSB_NEW_VA_ROTATION 1 << 0
132 #define PSB_NEW_WM_ROTATION 1 << 1
133
134 #define MAX_SLICES_PER_PICTURE 72
135 #define MAX_MB_ERRORS 72
136
137 /* Some funtions aren't used but we'd like to keep them as reference code in future */
138 #define PSB_MFLD_DUMMY_CODE 0
139
140 typedef struct object_config_s *object_config_p;
141 typedef struct object_context_s *object_context_p;
142 typedef struct object_surface_s *object_surface_p;
143 typedef struct object_buffer_s *object_buffer_p;
144 typedef struct object_image_s *object_image_p;
145 typedef struct object_subpic_s *object_subpic_p;
146 typedef struct format_vtable_s *format_vtable_p;
147 typedef struct psb_driver_data_s *psb_driver_data_p;
148
149 typedef struct psb_surface_share_info_s psb_surface_share_info_t, *psb_surface_share_info_p;
150 /* post-processing data structure */
151 enum psb_output_method_t {
152 PSB_PUTSURFACE_NONE = 0,
153 PSB_PUTSURFACE_X11,/* use x11 method */
154 PSB_PUTSURFACE_TEXTURE,/* texture xvideo */
155 PSB_PUTSURFACE_OVERLAY,/* overlay xvideo */
156 PSB_PUTSURFACE_COVERLAY,/* client overlay */
157 PSB_PUTSURFACE_CTEXTURE,/* client textureblit */
158 PSB_PUTSURFACE_TEXSTREAMING,/* texsteaming */
159 PSB_PUTSURFACE_FORCE_TEXTURE,/* force texture xvideo */
160 PSB_PUTSURFACE_FORCE_OVERLAY,/* force overlay xvideo */
161 PSB_PUTSURFACE_FORCE_CTEXTURE,/* force client textureblit */
162 PSB_PUTSURFACE_FORCE_COVERLAY,/* force client overlay */
163 PSB_PUTSURFACE_FORCE_TEXSTREAMING,/* force texstreaming */
164 };
165
166 typedef struct psb_decode_info {
167 uint32_t num_surface;
168 uint32_t surface_id;
169 } psb_decode_info_t;
170 typedef struct msvdx_decode_info *psb_decode_info_p;
171
172 #define CSC_MATRIX_X (3)
173 #define CSC_MATRIX_Y (3)
174
175 struct psb_driver_data_s {
176 struct object_heap_s config_heap;
177 struct object_heap_s context_heap;
178 struct object_heap_s surface_heap;
179 struct object_heap_s buffer_heap;
180 struct object_heap_s image_heap;
181 struct object_heap_s subpic_heap;
182 char * bus_id;
183 uint32_t dev_id;
184 int drm_fd;
185 int dup_drm_fd;
186
187 /* PM_QoS */
188 int pm_qos_fd;
189 int dri2;
190 int dri_dummy;
191 XID context_id;
192 drm_context_t drm_context;
193 drmLock *drm_lock;
194 int contended_lock;
195 pthread_mutex_t drm_mutex;
196 format_vtable_p profile2Format[PSB_MAX_PROFILES][PSB_MAX_ENTRYPOINTS];
197 #ifdef PSBVIDEO_MRFL_VPP
198 format_vtable_p vpp_profile;
199 #endif
200 #ifdef PSBVIDEO_MFLD
201 format_vtable_p vpp_profile;
202 #endif
203 uint32_t msvdx_context_base;
204 int video_sd_disabled;
205 int video_hd_disabled;
206 unsigned char * camera_bo;
207 uint32_t camera_phyaddr;
208 uint32_t camera_size;
209 unsigned char * rar_bo;
210 uint32_t rar_phyaddr;
211 uint32_t rar_size;
212
213 int encode_supported;
214 int decode_supported;
215 int hd_encode_supported;
216 int hd_decode_supported;
217
218 int execIoctlOffset;
219 int getParamIoctlOffset;
220
221 struct _WsbmBufferPool *main_pool;
222 struct _WsbmFenceMgr *fence_mgr;
223
224 enum psb_output_method_t output_method;
225
226 /* whether the post-processing use client overlay or not */
227 int coverlay;
228 int coverlay_init;
229 PsbPortPrivRec coverlay_priv;
230
231
232 /* whether the post-processing use client textureblit or not */
233 int ctexture;
234 struct psb_texture_s ctexture_priv;
235
236 /*
237 //whether the post-processing use texstreaing or not
238 int ctexstreaing;
239 struct psb_texstreaing ctexstreaing_priv;
240 */
241
242 unsigned char *ws_priv; /* window system related data structure */
243
244
245 VASurfaceID cur_displaying_surface;
246 VASurfaceID last_displaying_surface;
247
248 VADisplayAttribute ble_black_mode;
249 VADisplayAttribute ble_white_mode;
250
251 VADisplayAttribute blueStretch_gain;
252 VADisplayAttribute skinColorCorrection_gain;
253
254 VADisplayAttribute brightness;
255 VADisplayAttribute hue;
256 VADisplayAttribute contrast;
257 VADisplayAttribute saturation;
258 /*Save RenderMode and RenderRect attribute
259 * for medfield android extend video mode.*/
260 uint32_t render_device;
261 uint32_t render_mode;
262 VARectangle render_rect;
263
264 unsigned int clear_color;
265
266 int is_oold;
267
268 unsigned int load_csc_matrix;
269 signed int csc_matrix[CSC_MATRIX_X][CSC_MATRIX_Y];
270
271 /* subpic number current buffers support */
272 unsigned int max_subpic;
273
274 /* for multi-thread safe */
275 int use_xrandr_thread;
276 pthread_mutex_t output_mutex;
277 pthread_t xrandr_thread_id;
278 int extend_fullscreen;
279
280 int drawable_info;
281 int dummy_putsurface;
282 int fixed_fps;
283 unsigned int frame_count;
284
285 uint32_t blend_mode;
286 uint32_t blend_color;
287 uint32_t overlay_auto_paint_color_key;
288 uint32_t color_key;
289
290 /*output rotation info*/
291 int disable_msvdx_rotate;
292 int disable_msvdx_rotate_backup;
293 int msvdx_rotate_want; /* msvdx rotate info programed to msvdx */
294 int va_rotate; /* VA rotate passed from APP */
295 int mipi0_rotation; /* window manager rotation */
296 int mipi1_rotation; /* window manager rotation */
297 int hdmi_rotation; /* window manager rotation */
298 int local_rotation; /* final device rotate: VA rotate+wm rotate */
299 int extend_rotation; /* final device rotate: VA rotate+wm rotate */
300 int rotation_dirty; /*flag for recaculate final rotation*/
301
302 unsigned int outputmethod_checkinterval;
303
304 uint32_t xrandr_dirty;
305 uint32_t xrandr_update;
306 /*only VAProfileH264ConstrainedBaseline profile enable error concealment*/
307 uint32_t ec_enabled;
308 uint32_t ved_vpp;
309
310 /* vpp is on or off */
311 int vpp_on;
312
313 uint32_t pre_surfaceid;
314 psb_decode_info_t decode_info;
315 drm_psb_msvdx_decode_status_t *msvdx_decode_status;
316 VASurfaceDecodeMBErrors *surface_mb_error;
317
318 unsigned char *hPVR2DContext;
319
320 VAGenericID wrapped_surface_id[VIDEO_BUFFER_NUM];
321 VAGenericID wrapped_subpic_id[VIDEO_BUFFER_NUM];
322 PVR2DMEMINFO *videoBuf[VIDEO_BUFFER_NUM];
323 PVR2DMEMINFO *subpicBuf[VIDEO_BUFFER_NUM];
324 void *native_window;
325 int is_android;
326 /* VA_RT_FORMAT_PROTECTED is set to protected for Widevine case */
327 int protected;
328 };
329
330
331 #ifdef _FOR_FPGA_
332 #define IS_CTP(driver_data) 0
333 #define IS_MFLD(driver_data) 0
334 #define IS_MRFL(driver_data) 1
335 #define IS_MRST(driver_data) 0
336 #else
337 #define IS_CTP(driver_data) (((driver_data->dev_id & 0xffff) == 0x08c0) || \
338 ((driver_data->dev_id & 0xffff) == 0x08c7) || \
339 ((driver_data->dev_id & 0xffff) == 0x08c8))
340 #define IS_MRST(driver_data) ((driver_data->dev_id & 0xFFFC) == 0x4100)
341 #define IS_MFLD(driver_data) (((driver_data->dev_id & 0xFFFC) == 0x0130) || ((driver_data->dev_id & 0xFFFF) == 0x08C0) || ((driver_data->dev_id & 0xFFFF) == 0x08C7) || ((driver_data->dev_id & 0xFFFF) == 0x01FF) || ((driver_data->dev_id & 0xFFFF) == 0x08C8))
342 #define IS_MRFL(driver_data) (((driver_data->dev_id & 0xFFFC) == 0x1180) || ((driver_data->dev_id & 0xFFFC) == 0x1480))
343 #define IS_MOFD(driver_data) ((driver_data->dev_id & 0xFFFC) == 0x1480)
344 #define IS_LEXINGTON(driver_data) ((driver_data->dev_id & 0xFFFF) == 0x01FF)
345 #define IS_BAYTRAIL(driver_data) ((driver_data->dev_id & 0xFFFF) == 0x0F31)
346 #endif
347
348 struct object_config_s {
349 struct object_base_s base;
350 VAProfile profile;
351 VAEntrypoint entrypoint;
352 VAConfigAttrib attrib_list[PSB_MAX_CONFIG_ATTRIBUTES];
353 int attrib_count;
354 format_vtable_p format_vtable;
355 };
356
357 struct object_context_s {
358 struct object_base_s base;
359 VAContextID context_id;
360 VAConfigID config_id;
361 VAProfile profile;
362 VAEntrypoint entry_point;
363 int picture_width;
364 int picture_height;
365 int num_render_targets;
366 VASurfaceID *render_targets;
367 int va_flags;
368
369 object_surface_p current_render_target;
370 object_surface_p ec_target;
371 object_surface_p ec_candidate;
372 VASurfaceID current_render_surface_id;
373 psb_driver_data_p driver_data;
374 format_vtable_p format_vtable;
375 unsigned char *format_data;
376 struct psb_cmdbuf_s *cmdbuf_list[PSB_MAX_CMDBUFS];
377 struct lnc_cmdbuf_s *lnc_cmdbuf_list[LNC_MAX_CMDBUFS_ENCODE];
378 struct pnw_cmdbuf_s *pnw_cmdbuf_list[PNW_MAX_CMDBUFS_ENCODE];
379 struct tng_cmdbuf_s *tng_cmdbuf_list[TNG_MAX_CMDBUFS_ENCODE];
380 struct vsp_cmdbuf_s *vsp_cmdbuf_list[VSP_MAX_CMDBUFS];
381
382 struct psb_cmdbuf_s *cmdbuf; /* Current cmd buffer */
383 struct lnc_cmdbuf_s *lnc_cmdbuf;
384 struct pnw_cmdbuf_s *pnw_cmdbuf;
385 struct tng_cmdbuf_s *tng_cmdbuf;
386 struct vsp_cmdbuf_s *vsp_cmdbuf;
387
388 int cmdbuf_current;
389
390 /* Buffers */
391 object_buffer_p buffers_unused[PSB_MAX_BUFFERTYPES]; /* Linked lists (HEAD) of unused buffers for each buffer type */
392 int buffers_unused_count[PSB_MAX_BUFFERTYPES]; /* Linked lists (HEAD) of unused buffers for each buffer type */
393 object_buffer_p buffers_unused_tail[PSB_MAX_BUFFERTYPES]; /* Linked lists (TAIL) of unused buffers for each buffer type */
394 object_buffer_p buffers_active[PSB_MAX_BUFFERTYPES]; /* Linked lists of active buffers for each buffer type */
395
396 object_buffer_p *buffer_list; /* for vaRenderPicture */
397 int num_buffers;
398
399 enum {
400 psb_video_none = 0,
401 psb_video_mc,
402 psb_video_vld,
403 psb_video_deblock
404 } video_op;
405
406 uint32_t operating_mode;
407 uint32_t flags; /* See render flags below */
408 uint32_t first_mb;
409 uint32_t last_mb;
410
411 int is_oold;
412 int msvdx_rotate;
413 int msvdx_scaling;
414 int interlaced_stream;
415
416 /* value is 64bits value, consist of 8 bytes
417 * bytes[0]: entrypoint
418 * bytes[1]: profile
419 * bytes[2]: tile stride | rotated tile stride
420 * bytes[3]: driver_data->protected
421 * bytes[4]: width_in_mb; pass width kernel for VC1 workaround
422 */
423 uint64_t ctp_type;
424
425 unsigned long msvdx_tile; /* normal tile | (rotate tile << 4) */
426 #ifdef SLICE_HEADER_PARSING
427 int msvdx_frame_end;
428 int modular_drm;
429 #endif
430
431 uint32_t msvdx_context;
432
433 int scaling_width;
434 int scaling_height;
435 int scaling_buffer_width;
436 int scaling_buffer_height;
437 int scaling_offset_x;
438 int scaling_offset_y;
439 int scaling_update;
440
441 /* Debug */
442 uint32_t frame_count;
443 uint32_t slice_count;
444 };
445
446 #define ROTATE_VA2MSVDX(va_rotate) (va_rotate)
447 #define CONTEXT_ROTATE(obj_context) (obj_context->msvdx_rotate != ROTATE_VA2MSVDX(VA_ROTATION_NONE))
448 #define CONTEXT_SCALING(obj_context) (obj_context->msvdx_scaling)
449 #define CONTEXT_ALTERNATIVE_OUTPUT(obj_context) (CONTEXT_ROTATE(obj_context) || CONTEXT_SCALING(obj_context))
450
451 enum force_output_method_t {
452 OUTPUT_FORCE_NULL = 0,
453 OUTPUT_FORCE_GPU,
454 OUTPUT_FORCE_OVERLAY,
455 OUTPUT_FORCE_OVERLAY_FOR_SW_DECODE,
456 };
457
458 #define MAX_SHARE_INFO_KHANDLES 32
459 struct psb_surface_share_info_s {
460 //int rotation_sf; /*rotaion degree from surface flinger.*/
461 int surface_rotate; /*rotation degree of current rotation surface*/
462 int metadata_rotate; /*rotation degree of meta data*/
463 int width_r;
464 int height_r;
465 int surface_protected; /*whether this surface need be protected*/
466 /*Force render path.
467 0 : no fore.
468 1 : force gpu render;
469 2 : force overlay render.*/
470 int force_output_method;
471 unsigned int out_loop_khandle;
472 unsigned int renderStatus;
473 unsigned int used_by_widi;
474 int bob_deinterlace;
475 int tiling;
476 unsigned int width;
477 unsigned int height;
478 unsigned int luma_stride;
479 unsigned int chroma_u_stride;
480 unsigned int chroma_v_stride;
481 unsigned int format;
482 unsigned int khandle;
483 long long timestamp;
484
485 unsigned int out_loop_luma_stride;
486 unsigned int out_loop_chroma_u_stride;
487 unsigned int out_loop_chroma_v_stride;
488
489 long long hwc_timestamp;
490 unsigned int layer_transform;
491
492 void *native_window;
493 unsigned int scaling_khandle;
494 unsigned int width_s;
495 unsigned int height_s;
496
497 unsigned int scaling_luma_stride;
498 unsigned int scaling_chroma_u_stride;
499 unsigned int scaling_chroma_v_stride;
500
501 unsigned int crop_width;
502 unsigned int crop_height;
503
504 unsigned int coded_width;
505 unsigned int coded_height;
506 unsigned int initialized;
507 };
508
509 struct object_surface_s {
510 struct object_base_s base;
511 VASurfaceID surface_id;
512 VAContextID context_id;
513 int width;
514 int height;
515 int height_origin;
516 int width_r;
517 int height_r;
518 int width_s;
519 int height_s;
520 int buffer_width_s;
521 int buffer_height_s;
522 int offset_x_s;
523 int offset_y_s;
524
525 struct psb_surface_s *psb_surface;
526 struct psb_surface_s *out_loop_surface; /* Alternative output surface for rotation */
527 struct psb_surface_s *scaling_surface; /* Alternative output surface for scaling */
528 void *subpictures;/* if not NULL, have subpicture information */
529 unsigned int subpic_count; /* to ensure output have enough space for PDS & RAST */
530 unsigned int derived_imgcnt; /* is the surface derived by a VAImage? */
531 unsigned long display_timestamp; /* record the time point of put surface*/
532 void *rotate_vaddr;
533 struct psb_surface_share_info_s *share_info;
534 int is_ref_surface; /* If true, vaDeriveImage returns error */
535 };
536
537 #define PSB_CODEDBUF_SLICE_NUM_MASK (0xff)
538 #define PSB_CODEDBUF_SLICE_NUM_SHIFT (0)
539
540 #define PSB_CODEDBUF_NONE_VCL_NUM_MASK (0xff)
541 #define PSB_CODEDBUF_NONE_VCL_NUM_SHIFT (8)
542
543 #define SET_CODEDBUF_INFO(flag, aux_info, slice_num) \
544 do {\
545 (aux_info) &= ~(PSB_CODEDBUF_##flag##_MASK<<PSB_CODEDBUF_##flag##_SHIFT);\
546 (aux_info) |= ((slice_num) & PSB_CODEDBUF_##flag##_MASK)\
547 <<PSB_CODEDBUF_##flag##_SHIFT;\
548 } while (0)
549
550 #define CLEAR_CODEDBUF_INFO(flag, aux_info) \
551 do {\
552 (aux_info) &= ~(PSB_CODEDBUF_##flag##_MASK<<PSB_CODEDBUF_##flag##_SHIFT);\
553 } while (0)
554
555 #define GET_CODEDBUF_INFO(flag, aux_info) \
556 (((aux_info)>>PSB_CODEDBUF_##flag##_SHIFT) & PSB_CODEDBUF_##flag##_MASK)
557
558
559 #define PSB_CODEDBUF_SEGMENT_MAX (9)
560
561 struct object_buffer_s {
562 struct object_base_s base;
563 object_buffer_p ptr_next; /* Generic ptr for linked list */
564 object_buffer_p *pptr_prev_next; /* Generic ptr for linked list */
565 struct psb_buffer_s *psb_buffer;
566 unsigned char *buffer_data;
567 unsigned int size;
568 unsigned int alloc_size;
569 unsigned int max_num_elements;
570 unsigned int num_elements;
571 object_context_p context;
572 VABufferType type;
573 uint32_t last_used;
574
575 /* for VAEncCodedBufferType */
576 VACodedBufferSegment codedbuf_mapinfo[PSB_CODEDBUF_SEGMENT_MAX];
577 uint32_t codedbuf_aux_info;
578 };
579
580 struct object_image_s {
581 struct object_base_s base;
582 VAImage image;
583 unsigned int palette[16];
584 int subpic_ref;
585 VASurfaceID derived_surface;
586 };
587
588 struct object_subpic_s {
589 struct object_base_s base;
590 VASubpictureID subpic_id;
591
592 VAImageID image_id;
593
594 /* chromakey range */
595 unsigned int chromakey_min;
596 unsigned int chromakey_max;
597 unsigned int chromakey_mask;
598
599 /* global alpha */
600 unsigned int global_alpha;
601
602 /* flags */
603 unsigned int flags; /* see below */
604
605 unsigned char *surfaces; /* surfaces, associated with this subpicture */
606 };
607
608 typedef struct _PsbSurfaceAttributeTPI {
609 VASurfaceMemoryType type;
610 unsigned int width;
611 unsigned int height;
612 unsigned int size;
613 unsigned int pixel_format; /* buffer format */
614 unsigned int tiling; /* the memory is tiling or not */
615 unsigned int luma_stride; /* luma stride, could be width aligned with a special value */
616 unsigned int chroma_u_stride; /* chroma stride */
617 unsigned int chroma_v_stride;
618 unsigned int luma_offset; /* could be 0 */
619 unsigned int chroma_u_offset; /* U offset from the beginning of the memory */
620 unsigned int chroma_v_offset; /* V offset from the beginning of the memory */
621 unsigned int count; /* buffer count for surface creation */
622 unsigned long *buffers; /* buffer handles or user pointers */
623 unsigned long reserved[4]; /* used to pass additional information, like 362
624 * Android native window pointer 363
625 */
626 } PsbSurfaceAttributeTPI;
627
628 #define MEMSET_OBJECT(ptr, data_struct) \
629 memset((unsigned char *)ptr + sizeof(struct object_base_s),\
630 0, \
631 sizeof(data_struct) - sizeof(struct object_base_s))
632
633 struct format_vtable_s {
634 void (*queryConfigAttributes)(
635 VAProfile profile,
636 VAEntrypoint entrypoint,
637 VAConfigAttrib *attrib_list,
638 int num_attribs
639 );
640 VAStatus(*validateConfig)(
641 object_config_p obj_config
642 );
643 VAStatus(*createContext)(
644 object_context_p obj_context,
645 object_config_p obj_config
646 );
647 void (*destroyContext)(
648 object_context_p obj_context
649 );
650 VAStatus(*beginPicture)(
651 object_context_p obj_context
652 );
653 VAStatus(*renderPicture)(
654 object_context_p obj_context,
655 object_buffer_p *buffers,
656 int num_buffers
657 );
658 VAStatus(*endPicture)(
659 object_context_p obj_context
660 );
661 };
662
663 #define psb__bounds_check(x, max) \
664 do { ASSERT(x < max); if (x >= max) x = max - 1; } while(0);
665
GetTickCount()666 static inline unsigned long GetTickCount()
667 {
668 struct timeval tv;
669 if (gettimeofday(&tv, NULL))
670 return 0;
671 return tv.tv_usec / 1000 + tv.tv_sec * 1000;
672 }
673
buffer_type_to_string(int type)674 inline static char * buffer_type_to_string(int type)
675 {
676 switch (type) {
677 case VAPictureParameterBufferType:
678 return "VAPictureParameterBufferType";
679 case VAIQMatrixBufferType:
680 return "VAIQMatrixBufferType";
681 case VABitPlaneBufferType:
682 return "VABitPlaneBufferType";
683 case VASliceGroupMapBufferType:
684 return "VASliceGroupMapBufferType";
685 case VASliceParameterBufferType:
686 return "VASliceParameterBufferType";
687 case VASliceDataBufferType:
688 return "VASliceDataBufferType";
689 case VAProtectedSliceDataBufferType:
690 return "VAProtectedSliceDataBufferType";
691 case VAMacroblockParameterBufferType:
692 return "VAMacroblockParameterBufferType";
693 case VAResidualDataBufferType:
694 return "VAResidualDataBufferType";
695 case VADeblockingParameterBufferType:
696 return "VADeblockingParameterBufferType";
697 case VAImageBufferType:
698 return "VAImageBufferType";
699 case VAEncCodedBufferType:
700 return "VAEncCodedBufferType";
701 case VAEncSequenceParameterBufferType:
702 return "VAEncSequenceParameterBufferType";
703 case VAEncPictureParameterBufferType:
704 return "VAEncPictureParameterBufferType";
705 case VAEncSliceParameterBufferType:
706 return "VAEncSliceParameterBufferType";
707 case VAEncMiscParameterBufferType:
708 return "VAEncMiscParameterBufferType";
709 case VAProbabilityBufferType:
710 return "VAProbabilityBufferType";
711 case VAHuffmanTableBufferType:
712 return "VAHuffmanTableBufferType";
713 case VAQMatrixBufferType:
714 return "VAQMatrixBufferType";
715 default:
716 return "UnknowBuffer";
717 }
718 }
719
Angle2Rotation(int angle)720 inline static int Angle2Rotation(int angle)
721 {
722 angle %= 360;
723 switch (angle) {
724 case 0:
725 return VA_ROTATION_NONE;
726 case 90:
727 return VA_ROTATION_90;
728 case 180:
729 return VA_ROTATION_180;
730 case 270:
731 return VA_ROTATION_270;
732 default:
733 return -1;
734 }
735 }
736
Rotation2Angle(int rotation)737 inline static int Rotation2Angle(int rotation)
738 {
739 switch (rotation) {
740 case VA_ROTATION_NONE:
741 return 0;
742 case VA_ROTATION_90:
743 return 90;
744 case VA_ROTATION_180:
745 return 180;
746 case VA_ROTATION_270:
747 return 270;
748 default:
749 return -1;
750 }
751 }
752
753 int psb_parse_config(char *env, char *env_value);
754 void psb__destroy_surface(psb_driver_data_p driver_data, object_surface_p obj_surface);
755 unsigned long psb_tile_stride_mode(int w);
756 VAStatus psb__checkSurfaceDimensions(psb_driver_data_p driver_data, int width, int height);
757
758 int LOCK_HARDWARE(psb_driver_data_p driver_data);
759 int UNLOCK_HARDWARE(psb_driver_data_p driver_data);
760 unsigned long psb__tile_stride_log2_256(int w);
761 int psb_update_context(psb_driver_data_p driver_data, unsigned long ctx_type);
762
763 #define CHECK_SURFACE(obj_surface) \
764 do { \
765 if (NULL == obj_surface) { \
766 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE; \
767 DEBUG_FAILURE; \
768 return vaStatus; \
769 } \
770 } while (0)
771
772 #define CHECK_CONFIG(obj_config) \
773 do { \
774 if (NULL == obj_config) { \
775 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG; \
776 DEBUG_FAILURE; \
777 return vaStatus; \
778 } \
779 } while (0)
780
781 #define CHECK_CONTEXT(obj_context) \
782 do { \
783 if (NULL == obj_context) { \
784 vaStatus = VA_STATUS_ERROR_INVALID_CONTEXT; \
785 DEBUG_FAILURE; \
786 return vaStatus; \
787 } \
788 } while (0)
789
790 #define CHECK_BUFFER(obj_buffer) \
791 do { \
792 if (NULL == obj_buffer) { \
793 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER; \
794 DEBUG_FAILURE; \
795 return vaStatus; \
796 } \
797 } while (0)
798
799 #define CHECK_IMAGE(obj_image) \
800 do { \
801 if (NULL == obj_image) { \
802 vaStatus = VA_STATUS_ERROR_INVALID_IMAGE; \
803 DEBUG_FAILURE; \
804 return vaStatus; \
805 } \
806 } while (0)
807
808 #define CHECK_SUBPICTURE(obj_subpic) \
809 do { \
810 if (NULL == obj_subpic) { \
811 vaStatus = VA_STATUS_ERROR_INVALID_SUBPICTURE; \
812 DEBUG_FAILURE; \
813 return vaStatus; \
814 } \
815 } while (0)
816
817 #define CHECK_ALLOCATION(buf) \
818 do { \
819 if (buf == NULL) { \
820 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; \
821 DEBUG_FAILURE; \
822 return vaStatus; \
823 } \
824 } while (0)
825
826 #define CHECK_VASTATUS() \
827 do { \
828 if (VA_STATUS_SUCCESS != vaStatus) { \
829 DEBUG_FAILURE; \
830 return vaStatus; \
831 } \
832 } while (0)
833
834 #define CHECK_INVALID_PARAM(param) \
835 do { \
836 if (param) { \
837 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; \
838 DEBUG_FAILURE; \
839 return vaStatus; \
840 } \
841 } while (0)
842
843 #endif /* _PSB_DRV_VIDEO_H_ */
844