sna_video.h revision 03b705cf
1/***************************************************************************
2
3Copyright 2000 Intel Corporation.  All Rights Reserved.
4
5Permission is hereby granted, free of charge, to any person obtaining a
6copy of this software and associated documentation files (the
7"Software"), to deal in the Software without restriction, including
8without limitation the rights to use, copy, modify, merge, publish,
9distribute, sub license, and/or sell copies of the Software, and to
10permit persons to whom the Software is furnished to do so, subject to
11the following conditions:
12
13The above copyright notice and this permission notice (including the
14next paragraph) shall be included in all copies or substantial portions
15of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20IN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
21DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
23THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25**************************************************************************/
26
27#ifndef SNA_VIDEO_H
28#define SNA_VIDEO_H
29
30#include <xf86_OSproc.h>
31#include <xf86xv.h>
32#include <fourcc.h>
33
34#if defined(XvMCExtension) && defined(ENABLE_XVMC)
35#define SNA_XVMC 1
36#endif
37
38#define FOURCC_XVMC (('C' << 24) + ('M' << 16) + ('V' << 8) + 'X')
39#define FOURCC_RGB565 ((16 << 24) + ('B' << 16) + ('G' << 8) + 'R')
40#define FOURCC_RGB888 ((24 << 24) + ('B' << 16) + ('G' << 8) + 'R')
41
42/*
43 * Below, a dummy picture type that is used in XvPutImage
44 * only to do an overlay update.
45 * Introduced for the XvMC client lib.
46 * Defined to have a zero data size.
47 */
48#define XVMC_YUV { \
49	FOURCC_XVMC, XvYUV, LSBFirst, \
50	{'X', 'V', 'M', 'C', 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}, \
51	12, XvPlanar, 3, 0, 0, 0, 0, 8, 8, 8, 1, 2, 2, 1, 2, 2, \
52	{'Y', 'V', 'U', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \
53	XvTopToBottom \
54}
55
56#define XVMC_RGB565 { \
57	FOURCC_RGB565, XvRGB, LSBFirst, \
58	{'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '1', '6'}, \
59	16, XvPacked, 1, 16, 0x1f<<11, 0x3f<<5, 0x1f<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
60	{'B', 'G', 'R', 'X', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \
61	XvTopToBottom \
62}
63
64#define XVMC_RGB888 { \
65	FOURCC_RGB888, XvRGB, LSBFirst, \
66	{'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '2', '4'}, \
67	32, XvPacked, 1, 24, 0xff<<16, 0xff<<8, 0xff<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
68	{'B', 'G', 'R', 'X', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \
69	XvTopToBottom \
70}
71
72struct sna_video {
73	struct sna *sna;
74
75	int brightness;
76	int contrast;
77	int saturation;
78	xf86CrtcPtr desired_crtc;
79
80	RegionRec clip;
81
82	uint32_t gamma0;
83	uint32_t gamma1;
84	uint32_t gamma2;
85	uint32_t gamma3;
86	uint32_t gamma4;
87	uint32_t gamma5;
88
89	int color_key;
90	int color_key_changed;
91
92	/** YUV data buffers */
93	struct kgem_bo *old_buf[2];
94	struct kgem_bo *buf;
95
96	int alignment;
97	bool tiled;
98	bool textured;
99	Rotation rotation;
100	int plane;
101	struct kgem_bo *bo;
102
103	int SyncToVblank;	/* -1: auto, 0: off, 1: on */
104	int AlwaysOnTop;
105};
106
107struct sna_video_frame {
108	struct kgem_bo *bo;
109	uint32_t id;
110	uint32_t size;
111	uint32_t UBufOffset;
112	uint32_t VBufOffset;
113
114	uint16_t width, height;
115	uint16_t pitch[2];
116
117	/* extents */
118	BoxRec image;
119	BoxRec src;
120};
121
122static inline XvScreenPtr to_xv(ScreenPtr screen)
123{
124	return dixLookupPrivate(&screen->devPrivates, XvGetScreenKey());
125}
126
127void sna_video_init(struct sna *sna, ScreenPtr screen);
128void sna_video_overlay_setup(struct sna *sna, ScreenPtr screen);
129void sna_video_sprite_setup(struct sna *sna, ScreenPtr screen);
130void sna_video_textured_setup(struct sna *sna, ScreenPtr screen);
131void sna_video_destroy_window(WindowPtr win);
132
133XvAdaptorPtr sna_xv_adaptor_alloc(struct sna *sna);
134int sna_xv_fixup_formats(ScreenPtr screen,
135			 XvFormatPtr formats,
136			 int num_formats);
137int sna_xv_alloc_port(unsigned long port, XvPortPtr in, XvPortPtr *out);
138int sna_xv_free_port(XvPortPtr port);
139
140static inline int xvmc_passthrough(int id)
141{
142	switch (id) {
143	case FOURCC_XVMC:
144	case FOURCC_RGB565:
145	case FOURCC_RGB888:
146		return true;
147	default:
148		return false;
149	}
150}
151
152static inline int is_planar_fourcc(int id)
153{
154	switch (id) {
155	case FOURCC_YV12:
156	case FOURCC_I420:
157	case FOURCC_XVMC:
158		return 1;
159	default:
160		return 0;
161	}
162}
163
164bool
165sna_video_clip_helper(ScrnInfoPtr scrn,
166		      struct sna_video *adaptor_priv,
167		      struct sna_video_frame *frame,
168		      xf86CrtcPtr * crtc_ret,
169		      BoxPtr dst,
170		      short src_x, short src_y,
171		      short drw_x, short drw_y,
172		      short src_w, short src_h,
173		      short drw_w, short drw_h,
174		      RegionPtr reg);
175
176void
177sna_video_frame_init(struct sna_video *video,
178		     int id, short width, short height,
179		     struct sna_video_frame *frame);
180
181struct kgem_bo *
182sna_video_buffer(struct sna_video *video,
183		 struct sna_video_frame *frame);
184
185bool
186sna_video_copy_data(struct sna_video *video,
187		    struct sna_video_frame *frame,
188		    const uint8_t *buf);
189
190void sna_video_buffer_fini(struct sna_video *video);
191
192void sna_video_free_buffers(struct sna_video *video);
193
194static inline XvPortPtr
195sna_window_get_port(WindowPtr window)
196{
197	return ((void **)__get_private(window, sna_window_key))[2];
198}
199
200static inline void
201sna_window_set_port(WindowPtr window, XvPortPtr port)
202{
203	((void **)__get_private(window, sna_window_key))[2] = port;
204}
205
206#endif /* SNA_VIDEO_H */
207