Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright © 2009 Intel Corporation
  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.  *    Xiang Haihao <haihao.xiang@intel.com>
  26.  *    Zou Nan hai <nanhai.zou@intel.com>
  27.  *
  28.  */
  29.  
  30. #ifndef _I965_DRV_VIDEO_H_
  31. #define _I965_DRV_VIDEO_H_
  32.  
  33. #include <va/va.h>
  34. #include <va/va_backend.h>
  35.  
  36. #include "i965_mutext.h"
  37. #include "object_heap.h"
  38. #include "intel_driver.h"
  39.  
  40. #define I965_MAX_PROFILES                       11
  41. #define I965_MAX_ENTRYPOINTS                    5
  42. #define I965_MAX_CONFIG_ATTRIBUTES              10
  43. #define I965_MAX_IMAGE_FORMATS                  3
  44. #define I965_MAX_SUBPIC_FORMATS                 6
  45. #define I965_MAX_SUBPIC_SUM                     4
  46.  
  47. #define INTEL_STR_DRIVER_VENDOR                 "Intel"
  48. #define INTEL_STR_DRIVER_NAME                   "i965"
  49.  
  50. #define I965_SURFACE_TYPE_IMAGE                   0
  51. #define I965_SURFACE_TYPE_SURFACE                 1
  52.  
  53. #define I965_SURFACE_FLAG_FRAME                  0x00000000
  54. #define I965_SURFACE_FLAG_TOP_FIELD_FIRST        0x00000001
  55. #define I965_SURFACE_FLAG_BOTTOM_FIELD_FIRST     0x00000002
  56.  
  57. struct i965_surface
  58. {
  59.     VAGenericID id;
  60.     int type;
  61.     int flags;
  62. };
  63.  
  64. struct i965_kernel
  65. {
  66.     char *name;
  67.     int interface;
  68.     const uint32_t (*bin)[4];
  69.     int size;
  70.     dri_bo *bo;
  71. };
  72.  
  73. struct buffer_store
  74. {
  75.     unsigned char *buffer;
  76.     dri_bo *bo;
  77.     int ref_count;
  78.     int num_elements;
  79. };
  80.    
  81. struct object_config
  82. {
  83.     struct object_base base;
  84.     VAProfile profile;
  85.     VAEntrypoint entrypoint;
  86.     VAConfigAttrib attrib_list[I965_MAX_CONFIG_ATTRIBUTES];
  87.     int num_attribs;
  88. };
  89.  
  90. #define NUM_SLICES     10
  91.  
  92. struct decode_state
  93. {
  94.     struct buffer_store *pic_param;
  95.     struct buffer_store **slice_params;
  96.     struct buffer_store *iq_matrix;
  97.     struct buffer_store *bit_plane;
  98.     struct buffer_store *huffman_table;
  99.     struct buffer_store **slice_datas;
  100.     VASurfaceID current_render_target;
  101.     int max_slice_params;
  102.     int max_slice_datas;
  103.     int num_slice_params;
  104.     int num_slice_datas;
  105. };
  106.  
  107. struct encode_state
  108. {
  109.     struct buffer_store *seq_param;
  110.     struct buffer_store *pic_param;
  111.     struct buffer_store *pic_control;
  112.     struct buffer_store *iq_matrix;
  113.     struct buffer_store *q_matrix;
  114.     struct buffer_store **slice_params;
  115.     VASurfaceID current_render_target;
  116.     int max_slice_params;
  117.     int num_slice_params;
  118. };
  119.  
  120. #define CODEC_DEC       0
  121. #define CODEC_ENC       1
  122.  
  123. union codec_state
  124. {
  125.     struct decode_state decode;
  126.     struct encode_state encode;
  127. };
  128.  
  129. struct hw_context
  130. {
  131.     void (*run)(VADriverContextP ctx,
  132.                 VAProfile profile,
  133.                 union codec_state *codec_state,
  134.                 struct hw_context *hw_context);
  135.     void (*destroy)(void *);
  136.     struct intel_batchbuffer *batch;
  137. };
  138.  
  139. struct object_context
  140. {
  141.     struct object_base base;
  142.     VAContextID context_id;
  143.     VAConfigID config_id;
  144.     VASurfaceID *render_targets;                //input->encode, output->decode
  145.     int num_render_targets;
  146.     int picture_width;
  147.     int picture_height;
  148.     int flags;
  149.     int codec_type;
  150.     union codec_state codec_state;
  151.     struct hw_context *hw_context;
  152. };
  153.  
  154. #define SURFACE_REFERENCED      (1 << 0)
  155. #define SURFACE_DISPLAYED       (1 << 1)
  156. #define SURFACE_DERIVED         (1 << 2)
  157. #define SURFACE_REF_DIS_MASK    ((SURFACE_REFERENCED) | \
  158.                                  (SURFACE_DISPLAYED))
  159. #define SURFACE_ALL_MASK        ((SURFACE_REFERENCED) | \
  160.                                  (SURFACE_DISPLAYED) |  \
  161.                                  (SURFACE_DERIVED))
  162.  
  163. struct object_surface
  164. {
  165.     struct object_base base;
  166.     VASurfaceStatus status;
  167.     VASubpictureID subpic[I965_MAX_SUBPIC_SUM];
  168.     unsigned int subpic_render_idx;
  169.  
  170.     int width;
  171.     int height;
  172.     int size;
  173.     int orig_width;
  174.     int orig_height;
  175.     int flags;
  176.     unsigned int fourcc;    
  177.     dri_bo *bo;
  178.     VAImageID locked_image_id;
  179.     void (*free_private_data)(void **data);
  180.     void *private_data;
  181.     unsigned int subsampling;
  182.     int x_cb_offset;
  183.     int y_cb_offset;
  184.     int x_cr_offset;
  185.     int y_cr_offset;
  186.     int cb_cr_width;
  187.     int cb_cr_height;
  188.     int cb_cr_pitch;
  189. };
  190.  
  191. struct object_buffer
  192. {
  193.     struct object_base base;
  194.     struct buffer_store *buffer_store;
  195.     int max_num_elements;
  196.     int num_elements;
  197.     int size_element;
  198.     VABufferType type;
  199. };
  200.  
  201. struct object_image
  202. {
  203.     struct object_base base;
  204.     VAImage image;
  205.     dri_bo *bo;
  206.     unsigned int *palette;
  207.     VASurfaceID derived_surface;
  208. };
  209.  
  210. struct object_subpic
  211. {
  212.     struct object_base base;
  213.     VAImageID image;
  214.     VARectangle src_rect;
  215.     VARectangle dst_rect;
  216.     unsigned int format;
  217.     int width;
  218.     int height;
  219.     int pitch;
  220.     float global_alpha;
  221.     dri_bo *bo;
  222.     unsigned int flags;
  223. };
  224.  
  225. struct hw_codec_info
  226. {
  227.     struct hw_context *(*dec_hw_context_init)(VADriverContextP, VAProfile);
  228.     struct hw_context *(*enc_hw_context_init)(VADriverContextP, VAProfile);
  229.     int max_width;
  230.     int max_height;
  231. };
  232.  
  233.  
  234. #include "i965_render.h"
  235.  
  236. struct i965_driver_data
  237. {
  238.     struct intel_driver_data intel;
  239.     struct object_heap config_heap;
  240.     struct object_heap context_heap;
  241.     struct object_heap surface_heap;
  242.     struct object_heap buffer_heap;
  243.     struct object_heap image_heap;
  244.     struct object_heap subpic_heap;
  245.     struct hw_codec_info *codec_info;
  246.  
  247.     _I965Mutex render_mutex;
  248.     struct intel_batchbuffer *batch;
  249.     struct i965_render_state render_state;
  250.     void *pp_context;
  251.     char va_vendor[256];
  252.  
  253.     VADisplayAttribute *display_attributes;
  254.     unsigned int num_display_attributes;
  255.     VADisplayAttribute *rotation_attrib;
  256.  
  257.     /* VA/DRI (X11) specific data */
  258.     struct va_dri_output *dri_output;
  259.  
  260.     /* VA/Wayland specific data */
  261.     struct va_wl_output *wl_output;
  262. };
  263.  
  264. #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
  265. #define NEW_CONTEXT_ID() object_heap_allocate(&i965->context_heap);
  266. #define NEW_SURFACE_ID() object_heap_allocate(&i965->surface_heap);
  267. #define NEW_BUFFER_ID() object_heap_allocate(&i965->buffer_heap);
  268. #define NEW_IMAGE_ID() object_heap_allocate(&i965->image_heap);
  269. #define NEW_SUBPIC_ID() object_heap_allocate(&i965->subpic_heap);
  270.  
  271. #define CONFIG(id) ((struct object_config *)object_heap_lookup(&i965->config_heap, id))
  272. #define CONTEXT(id) ((struct object_context *)object_heap_lookup(&i965->context_heap, id))
  273. #define SURFACE(id) ((struct object_surface *)object_heap_lookup(&i965->surface_heap, id))
  274. #define BUFFER(id) ((struct object_buffer *)object_heap_lookup(&i965->buffer_heap, id))
  275. #define IMAGE(id) ((struct object_image *)object_heap_lookup(&i965->image_heap, id))
  276. #define SUBPIC(id) ((struct object_subpic *)object_heap_lookup(&i965->subpic_heap, id))
  277.  
  278. #define FOURCC_IA44 0x34344149
  279. #define FOURCC_AI44 0x34344941
  280.  
  281. #define STRIDE(w)               (((w) + 0xf) & ~0xf)
  282. #define SIZE_YUV420(w, h)       (h * (STRIDE(w) + STRIDE(w >> 1)))
  283.  
  284. static INLINE struct i965_driver_data *
  285. i965_driver_data(VADriverContextP ctx)
  286. {
  287.     return (struct i965_driver_data *)(ctx->pDriverData);
  288. }
  289.  
  290. void
  291. i965_check_alloc_surface_bo(VADriverContextP ctx,
  292.                             struct object_surface *obj_surface,
  293.                             int tiled,
  294.                             unsigned int fourcc,
  295.                             unsigned int subsampling);
  296.  
  297.  
  298. extern VAStatus i965_MapBuffer(VADriverContextP ctx,
  299.                 VABufferID buf_id,       /* in */
  300.                 void **pbuf);            /* out */
  301.  
  302. extern VAStatus i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id);
  303.  
  304. #endif /* _I965_DRV_VIDEO_H_ */
  305.