summaryrefslogtreecommitdiff
path: root/src/psb_overlay.h
blob: d105144bb9c31a17a21fa910c6086e364fbf5695 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/*
 * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *    Shengquan Yuan  <shengquan.yuan@intel.com>
 *    Binglin Chen <binglin.chen@intel.com>
 *    Jason Hu <jason.hu@intel.com>
 *    Zeng Li <zeng.li@intel.com>
 */

#ifndef _PSB_OVERLAY_H_
#define _PSB_OVERLAY_H_

#include <va/va.h>
#define USE_OVERLAY 1
#define USE_DISPLAY_C_SPRITE 0

/*
 * NOTE: Destination keying when enabled forces the overlay surface
 * Z order to be below the primary display. Pixels that match the key
 * value become transparent and the overlay becomes visible at that
 * pixel.
 */
#define USE_DCLRK 1
/*
 * NOTE: This is only for media player output
 */
#define USE_CLIP_FUNC 0
#define USE_SCALE_FUNC 1
#define USE_ROTATION_FUNC 1

#define Success 0

/* FIXME this will be removed later after using pvr2d */
#if 1
#define RR_Rotate_0         1
#define RR_Rotate_90        2
#define RR_Rotate_180       4
#define RR_Rotate_270       8
#endif

#define OV_HUE_DEFAULT_VALUE   0
#define OV_HUE_MIN            -30
#define OV_HUE_MAX             30

#define OV_BRIGHTNESS_DEFAULT_VALUE   0
#define OV_BRIGHTNESS_MIN            -50
#define OV_BRIGHTNESS_MAX             50

#define OV_CONTRAST_DEFAULT_VALUE     0
#define OV_CONTRAST_MIN              -100
#define OV_CONTRAST_MAX               100

#define OV_SATURATION_DEFAULT_VALUE   100
#define OV_SATURATION_MIN             0
#define OV_SATURATION_MAX             200

#define CLAMP_ATTR(a,max,min) (a>max?max:(a<min?min:a))

/*DSPCNTR - Display Control Register*/
#define DISPLAY_PLANE_ENABLE            (1<<31)
#define DISPLAY_PLANE_DISABLE           0
#define DISPPLANE_GAMMA_ENABLE          (1<<30)
#define DISPPLANE_GAMMA_DISABLE         0
#define DISPPLANE_PIXFORMAT_MASK        (0xf<<26)
#define DISPPLANE_8BPP              (0x2<<26)
#define DISPPLANE_15_16BPP          (0x4<<26)
#define DISPPLANE_16BPP             (0x5<<26)
#define DISPPLANE_32BPP_NO_ALPHA        (0x6<<26)
#define DISPPLANE_32BPP             (0x7<<26)
#define DISPPLANE_BOTTOM            (4)

/*
 * OCMD - Overlay Command Register
 */
#define OCMD_REGISTER           0x30168
#define MIRROR_MODE             (0x3<<17)
#define MIRROR_HORIZONTAL       (0x1<<17)
#define MIRROR_VERTICAL         (0x2<<17)
#define MIRROR_BOTH             (0x3<<17)
#define OV_BYTE_ORDER           (0x3<<14)
#define UV_SWAP                 (0x1<<14)
#define Y_SWAP                  (0x2<<14)
#define Y_AND_UV_SWAP           (0x3<<14)
#define SOURCE_FORMAT           (0xf<<10)
#define RGB_888                 (0x1<<10)
#define RGB_555                 (0x2<<10)
#define RGB_565                 (0x3<<10)
#define NV12                    (0xb<<10)
#define YUV_422                 (0x8<<10)
#define YUV_411                 (0x9<<10)
#define YUV_420                 (0xc<<10)
#define YUV_422_PLANAR          (0xd<<10)
#define YUV_410                 (0xe<<10)
#define TVSYNC_FLIP_PARITY      (0x1<<9)
#define TVSYNC_FLIP_ENABLE      (0x1<<7)
#define BUF_TYPE                (0x1<<5)
#define BUF_TYPE_FRAME          (0x0<<5)
#define BUF_TYPE_FIELD          (0x1<<5)
#define TEST_MODE               (0x1<<4)
#define BUFFER_SELECT           (0x3<<2)
#define BUFFER0                 (0x0<<2)
#define BUFFER1                 (0x1<<2)
#define FIELD_SELECT            (0x1<<1)
#define FIELD0                  (0x0<<1)
#define FIELD1                  (0x1<<1)
#define OVERLAY_ENABLE          0x1

#define OFC_UPDATE              0x1

/*
* OVADD - Overlay Register Update Address Register
*/
#define OVADD_PIPE_A           (0x0<<6)
#define OVADD_PIPE_B           (0x2<<6)
#define OVADD_PIPE_C           (0x1<<6)
#define LOAD_IEP_BW_EXPANSION  (0x1<<4)
#define LOAD_IEP_BS_SCC                (0x1<<3)
#define LOAD_IEP_CSC           (0x1<<2)
#define LOAD_IEP_DEBUG         (0x1<<1)
#define LOAD_COEFFICEINT       (0x1<<0)

/* OCONFIG register */
#define CC_OUT_8BIT             (0x1<<3)
#define OVERLAY_PIPE_MASK       (0x1<<18)
#define OVERLAY_PIPE_A          (0x0<<18)
#define OVERLAY_PIPE_B          (0x1<<18)
#define IEP_LITE_BYPASS                (0x1<<27)
#define OVERLAY_C_PIPE_MASK      (0x3<<17)
#define OVERLAY_C_PIPE_A         (0x0<<17)
#define OVERLAY_C_PIPE_B         (0x2<<17)
#define OVERLAY_C_PIPE_C         (0x1<<17)
#define GAMMA2_ENBL             (0x1<<16)
#define ZORDER_TOP             (0x0<<15)
#define ZORDER_BOTTOM          (0x1<<15)
#define CSC_MODE_BT709          (0x1<<5)
#define CSC_MODE_BT601          (0x0<<5)
#define CSC_BYPASS             (0x1<<4)
#define THREE_LINE_BUFFERS      (0x1<<0)
#define TWO_LINE_BUFFERS        (0x0<<0)

/* DCLRKM register */
#define DEST_KEY_ENABLE         (0x1<<31)
#define CONST_ALPHA_ENABLE      (0x1<<30)

/* Polyphase filter coefficients */
#define N_HORIZ_Y_TAPS          5
#define N_VERT_Y_TAPS           3
#define N_HORIZ_UV_TAPS         3
#define N_VERT_UV_TAPS          3
#define N_PHASES                17
#define MAX_TAPS                5

/* Filter cutoff frequency limits. */
#define MIN_CUTOFF_FREQ         1.0
#define MAX_CUTOFF_FREQ         3.0

#define RGB16ToColorKey(c) \
(((c & 0xF800) << 8) | ((c & 0x07E0) << 5) | ((c & 0x001F) << 3))

#define RGB15ToColorKey(c) \
(((c & 0x7c00) << 9) | ((c & 0x03E0) << 6) | ((c & 0x001F) << 3))

typedef struct {
    uint32_t x1;
    uint32_t x2;
    uint32_t y1;
    uint32_t y2;
} BoxRec, *BoxPtr;

typedef struct {
    uint32_t OBUF_0Y;
    uint32_t OBUF_1Y;
    uint32_t OBUF_0U;
    uint32_t OBUF_0V;
    uint32_t OBUF_1U;
    uint32_t OBUF_1V;
    uint32_t OSTRIDE;
    uint32_t YRGB_VPH;
    uint32_t UV_VPH;
    uint32_t HORZ_PH;
    uint32_t INIT_PHS;
    uint32_t DWINPOS;
    uint32_t DWINSZ;
    uint32_t SWIDTH;
    uint32_t SWIDTHSW;
    uint32_t SHEIGHT;
    uint32_t YRGBSCALE;
    uint32_t UVSCALE;
    uint32_t OCLRC0;
    uint32_t OCLRC1;
    uint32_t DCLRKV;
    uint32_t DCLRKM;
    uint32_t SCHRKVH;
    uint32_t SCHRKVL;
    uint32_t SCHRKEN;
    uint32_t OCONFIG;
    uint32_t OCMD;
    uint32_t RESERVED1;                 /* 0x6C */
    uint32_t OSTART_0Y;                 /* for i965 */
    uint32_t OSTART_1Y;         /* for i965 */
    uint32_t OSTART_0U;
    uint32_t OSTART_0V;
    uint32_t OSTART_1U;
    uint32_t OSTART_1V;
    uint32_t OTILEOFF_0Y;
    uint32_t OTILEOFF_1Y;
    uint32_t OTILEOFF_0U;
    uint32_t OTILEOFF_0V;
    uint32_t OTILEOFF_1U;
    uint32_t OTILEOFF_1V;
    uint32_t FASTHSCALE;                        /* 0xA0 */
    uint32_t UVSCALEV;                  /* 0xA4 */

    uint32_t RESERVEDC[(0x200 - 0xA8) / 4];                /* 0xA8 - 0x1FC */
    uint16_t Y_VCOEFS[N_VERT_Y_TAPS * N_PHASES];                   /* 0x200 */
    uint16_t RESERVEDD[0x100 / 2 - N_VERT_Y_TAPS * N_PHASES];
    uint16_t Y_HCOEFS[N_HORIZ_Y_TAPS * N_PHASES];                  /* 0x300 */
    uint16_t RESERVEDE[0x200 / 2 - N_HORIZ_Y_TAPS * N_PHASES];
    uint16_t UV_VCOEFS[N_VERT_UV_TAPS * N_PHASES];                 /* 0x500 */
    uint16_t RESERVEDF[0x100 / 2 - N_VERT_UV_TAPS * N_PHASES];
    uint16_t UV_HCOEFS[N_HORIZ_UV_TAPS * N_PHASES];        /* 0x600 */
    uint16_t RESERVEDG[0xa00 / 2 - N_HORIZ_UV_TAPS * N_PHASES];
    uint32_t IEP_SPACE[(0x3401c - 0x31000)/4];
} I830OverlayRegRec, *I830OverlayRegPtr;


#define Degree (2*PI / 360.0)
#define PI 3.1415927


typedef struct {
    uint8_t sign;
    uint16_t mantissa;
    uint8_t exponent;
} coeffRec, *coeffPtr;

typedef struct _ov_psb_fixed32 {
    union {
        struct {
            unsigned short Fraction;
            short Value;
        };
        long ll;
    };
} ov_psb_fixed32;

typedef struct _psb_subpictureKeyRec {
    struct _psb_subpictureKeyRec *next;
    unsigned int subpic_id;

    int subpic_dstx;
    int subpic_dsty;
    int subpic_dstw;
    int subpic_dsth;
} psb_subpictureKeyRec, *psb_subpictureKeyPtr;

typedef struct _PsbPortPrivRec {
    int curBuf;
    int is_mfld;
    /*subpicture*/
    int subpicture_enabled;
    int subpic_clear_flag;
    unsigned int subpicture_enable_mask;
    psb_subpictureKeyRec clear_key[6];

    /*overlay status*/
    int overlayA_pipeId;
    int overlayC_pipeId;
    int overlayA_enabled;
    int overlayC_enabled;

    /*window attribute*/
    int last_num_clipbox;
    VARectangle last_clipbox[16];
    int x11_window_width;
    int x11_window_height;
    int display_width;
    int display_height;
    int extend_display_width;
    int extend_display_height;

    /* used to check downscale*/
    short width_save;
    short height_save;

    /* information of display attribute */
    ov_psb_fixed32 brightness;
    ov_psb_fixed32 contrast;
    ov_psb_fixed32 saturation;
    ov_psb_fixed32 hue;

    unsigned char * p_iep_lite_context;

    /* hwoverlay */
    uint32_t gamma0;
    uint32_t gamma1;
    uint32_t gamma2;
    uint32_t gamma3;
    uint32_t gamma4;
    uint32_t gamma5;
    uint32_t colorKey;

    int oneLineMode;
    int scaleRatio;
    int rotation;

    struct _WsbmBufferObject *wsbo[2];
    uint32_t YBuf0offset;
    uint32_t UBuf0offset;
    uint32_t VBuf0offset;
    uint32_t YBuf1offset;
    uint32_t UBuf1offset;
    uint32_t VBuf1offset;
    unsigned char *regmap[2];
} PsbPortPrivRec, *PsbPortPrivPtr;


int psb_coverlay_init(VADriverContextP ctx);
int psb_coverlay_stop(VADriverContextP ctx);
int psb_coverlay_exit(VADriverContextP ctx);

VAStatus psb_putsurface_overlay(
    VADriverContextP ctx,
    VASurfaceID surface,
    short srcx,
    short srcy,
    unsigned short srcw,
    unsigned short srch,
    short destx,
    short desty,
    unsigned short destw,
    unsigned short desth,
    unsigned int flags, /* de-interlacing flags */
    int overlayId,
    int pipeId
);

enum pipe_id_t {
    PIPEA = 0,
    PIPEB,
    PIPEC,
};

enum overlay_id_t {
    OVERLAY_A = 0,
    OVERLAY_C,
};

#endif /* _PSB_OVERLAY_H_ */