sna_video.h revision 03b705cf
103b705cfSriastradh/***************************************************************************
203b705cfSriastradh
303b705cfSriastradhCopyright 2000 Intel Corporation.  All Rights Reserved.
403b705cfSriastradh
503b705cfSriastradhPermission is hereby granted, free of charge, to any person obtaining a
603b705cfSriastradhcopy of this software and associated documentation files (the
703b705cfSriastradh"Software"), to deal in the Software without restriction, including
803b705cfSriastradhwithout limitation the rights to use, copy, modify, merge, publish,
903b705cfSriastradhdistribute, sub license, and/or sell copies of the Software, and to
1003b705cfSriastradhpermit persons to whom the Software is furnished to do so, subject to
1103b705cfSriastradhthe following conditions:
1203b705cfSriastradh
1303b705cfSriastradhThe above copyright notice and this permission notice (including the
1403b705cfSriastradhnext paragraph) shall be included in all copies or substantial portions
1503b705cfSriastradhof the Software.
1603b705cfSriastradh
1703b705cfSriastradhTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1803b705cfSriastradhOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1903b705cfSriastradhMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2003b705cfSriastradhIN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
2103b705cfSriastradhDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2203b705cfSriastradhOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
2303b705cfSriastradhTHE USE OR OTHER DEALINGS IN THE SOFTWARE.
2403b705cfSriastradh
2503b705cfSriastradh**************************************************************************/
2603b705cfSriastradh
2703b705cfSriastradh#ifndef SNA_VIDEO_H
2803b705cfSriastradh#define SNA_VIDEO_H
2903b705cfSriastradh
3003b705cfSriastradh#include <xf86_OSproc.h>
3103b705cfSriastradh#include <xf86xv.h>
3203b705cfSriastradh#include <fourcc.h>
3303b705cfSriastradh
3403b705cfSriastradh#if defined(XvMCExtension) && defined(ENABLE_XVMC)
3503b705cfSriastradh#define SNA_XVMC 1
3603b705cfSriastradh#endif
3703b705cfSriastradh
3803b705cfSriastradh#define FOURCC_XVMC (('C' << 24) + ('M' << 16) + ('V' << 8) + 'X')
3903b705cfSriastradh#define FOURCC_RGB565 ((16 << 24) + ('B' << 16) + ('G' << 8) + 'R')
4003b705cfSriastradh#define FOURCC_RGB888 ((24 << 24) + ('B' << 16) + ('G' << 8) + 'R')
4103b705cfSriastradh
4203b705cfSriastradh/*
4303b705cfSriastradh * Below, a dummy picture type that is used in XvPutImage
4403b705cfSriastradh * only to do an overlay update.
4503b705cfSriastradh * Introduced for the XvMC client lib.
4603b705cfSriastradh * Defined to have a zero data size.
4703b705cfSriastradh */
4803b705cfSriastradh#define XVMC_YUV { \
4903b705cfSriastradh	FOURCC_XVMC, XvYUV, LSBFirst, \
5003b705cfSriastradh	{'X', 'V', 'M', 'C', 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}, \
5103b705cfSriastradh	12, XvPlanar, 3, 0, 0, 0, 0, 8, 8, 8, 1, 2, 2, 1, 2, 2, \
5203b705cfSriastradh	{'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}, \
5303b705cfSriastradh	XvTopToBottom \
5403b705cfSriastradh}
5503b705cfSriastradh
5603b705cfSriastradh#define XVMC_RGB565 { \
5703b705cfSriastradh	FOURCC_RGB565, XvRGB, LSBFirst, \
5803b705cfSriastradh	{'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '1', '6'}, \
5903b705cfSriastradh	16, XvPacked, 1, 16, 0x1f<<11, 0x3f<<5, 0x1f<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
6003b705cfSriastradh	{'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}, \
6103b705cfSriastradh	XvTopToBottom \
6203b705cfSriastradh}
6303b705cfSriastradh
6403b705cfSriastradh#define XVMC_RGB888 { \
6503b705cfSriastradh	FOURCC_RGB888, XvRGB, LSBFirst, \
6603b705cfSriastradh	{'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '2', '4'}, \
6703b705cfSriastradh	32, XvPacked, 1, 24, 0xff<<16, 0xff<<8, 0xff<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
6803b705cfSriastradh	{'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}, \
6903b705cfSriastradh	XvTopToBottom \
7003b705cfSriastradh}
7103b705cfSriastradh
7203b705cfSriastradhstruct sna_video {
7303b705cfSriastradh	struct sna *sna;
7403b705cfSriastradh
7503b705cfSriastradh	int brightness;
7603b705cfSriastradh	int contrast;
7703b705cfSriastradh	int saturation;
7803b705cfSriastradh	xf86CrtcPtr desired_crtc;
7903b705cfSriastradh
8003b705cfSriastradh	RegionRec clip;
8103b705cfSriastradh
8203b705cfSriastradh	uint32_t gamma0;
8303b705cfSriastradh	uint32_t gamma1;
8403b705cfSriastradh	uint32_t gamma2;
8503b705cfSriastradh	uint32_t gamma3;
8603b705cfSriastradh	uint32_t gamma4;
8703b705cfSriastradh	uint32_t gamma5;
8803b705cfSriastradh
8903b705cfSriastradh	int color_key;
9003b705cfSriastradh	int color_key_changed;
9103b705cfSriastradh
9203b705cfSriastradh	/** YUV data buffers */
9303b705cfSriastradh	struct kgem_bo *old_buf[2];
9403b705cfSriastradh	struct kgem_bo *buf;
9503b705cfSriastradh
9603b705cfSriastradh	int alignment;
9703b705cfSriastradh	bool tiled;
9803b705cfSriastradh	bool textured;
9903b705cfSriastradh	Rotation rotation;
10003b705cfSriastradh	int plane;
10103b705cfSriastradh	struct kgem_bo *bo;
10203b705cfSriastradh
10303b705cfSriastradh	int SyncToVblank;	/* -1: auto, 0: off, 1: on */
10403b705cfSriastradh	int AlwaysOnTop;
10503b705cfSriastradh};
10603b705cfSriastradh
10703b705cfSriastradhstruct sna_video_frame {
10803b705cfSriastradh	struct kgem_bo *bo;
10903b705cfSriastradh	uint32_t id;
11003b705cfSriastradh	uint32_t size;
11103b705cfSriastradh	uint32_t UBufOffset;
11203b705cfSriastradh	uint32_t VBufOffset;
11303b705cfSriastradh
11403b705cfSriastradh	uint16_t width, height;
11503b705cfSriastradh	uint16_t pitch[2];
11603b705cfSriastradh
11703b705cfSriastradh	/* extents */
11803b705cfSriastradh	BoxRec image;
11903b705cfSriastradh	BoxRec src;
12003b705cfSriastradh};
12103b705cfSriastradh
12203b705cfSriastradhstatic inline XvScreenPtr to_xv(ScreenPtr screen)
12303b705cfSriastradh{
12403b705cfSriastradh	return dixLookupPrivate(&screen->devPrivates, XvGetScreenKey());
12503b705cfSriastradh}
12603b705cfSriastradh
12703b705cfSriastradhvoid sna_video_init(struct sna *sna, ScreenPtr screen);
12803b705cfSriastradhvoid sna_video_overlay_setup(struct sna *sna, ScreenPtr screen);
12903b705cfSriastradhvoid sna_video_sprite_setup(struct sna *sna, ScreenPtr screen);
13003b705cfSriastradhvoid sna_video_textured_setup(struct sna *sna, ScreenPtr screen);
13103b705cfSriastradhvoid sna_video_destroy_window(WindowPtr win);
13203b705cfSriastradh
13303b705cfSriastradhXvAdaptorPtr sna_xv_adaptor_alloc(struct sna *sna);
13403b705cfSriastradhint sna_xv_fixup_formats(ScreenPtr screen,
13503b705cfSriastradh			 XvFormatPtr formats,
13603b705cfSriastradh			 int num_formats);
13703b705cfSriastradhint sna_xv_alloc_port(unsigned long port, XvPortPtr in, XvPortPtr *out);
13803b705cfSriastradhint sna_xv_free_port(XvPortPtr port);
13903b705cfSriastradh
14003b705cfSriastradhstatic inline int xvmc_passthrough(int id)
14103b705cfSriastradh{
14203b705cfSriastradh	switch (id) {
14303b705cfSriastradh	case FOURCC_XVMC:
14403b705cfSriastradh	case FOURCC_RGB565:
14503b705cfSriastradh	case FOURCC_RGB888:
14603b705cfSriastradh		return true;
14703b705cfSriastradh	default:
14803b705cfSriastradh		return false;
14903b705cfSriastradh	}
15003b705cfSriastradh}
15103b705cfSriastradh
15203b705cfSriastradhstatic inline int is_planar_fourcc(int id)
15303b705cfSriastradh{
15403b705cfSriastradh	switch (id) {
15503b705cfSriastradh	case FOURCC_YV12:
15603b705cfSriastradh	case FOURCC_I420:
15703b705cfSriastradh	case FOURCC_XVMC:
15803b705cfSriastradh		return 1;
15903b705cfSriastradh	default:
16003b705cfSriastradh		return 0;
16103b705cfSriastradh	}
16203b705cfSriastradh}
16303b705cfSriastradh
16403b705cfSriastradhbool
16503b705cfSriastradhsna_video_clip_helper(ScrnInfoPtr scrn,
16603b705cfSriastradh		      struct sna_video *adaptor_priv,
16703b705cfSriastradh		      struct sna_video_frame *frame,
16803b705cfSriastradh		      xf86CrtcPtr * crtc_ret,
16903b705cfSriastradh		      BoxPtr dst,
17003b705cfSriastradh		      short src_x, short src_y,
17103b705cfSriastradh		      short drw_x, short drw_y,
17203b705cfSriastradh		      short src_w, short src_h,
17303b705cfSriastradh		      short drw_w, short drw_h,
17403b705cfSriastradh		      RegionPtr reg);
17503b705cfSriastradh
17603b705cfSriastradhvoid
17703b705cfSriastradhsna_video_frame_init(struct sna_video *video,
17803b705cfSriastradh		     int id, short width, short height,
17903b705cfSriastradh		     struct sna_video_frame *frame);
18003b705cfSriastradh
18103b705cfSriastradhstruct kgem_bo *
18203b705cfSriastradhsna_video_buffer(struct sna_video *video,
18303b705cfSriastradh		 struct sna_video_frame *frame);
18403b705cfSriastradh
18503b705cfSriastradhbool
18603b705cfSriastradhsna_video_copy_data(struct sna_video *video,
18703b705cfSriastradh		    struct sna_video_frame *frame,
18803b705cfSriastradh		    const uint8_t *buf);
18903b705cfSriastradh
19003b705cfSriastradhvoid sna_video_buffer_fini(struct sna_video *video);
19103b705cfSriastradh
19203b705cfSriastradhvoid sna_video_free_buffers(struct sna_video *video);
19303b705cfSriastradh
19403b705cfSriastradhstatic inline XvPortPtr
19503b705cfSriastradhsna_window_get_port(WindowPtr window)
19603b705cfSriastradh{
19703b705cfSriastradh	return ((void **)__get_private(window, sna_window_key))[2];
19803b705cfSriastradh}
19903b705cfSriastradh
20003b705cfSriastradhstatic inline void
20103b705cfSriastradhsna_window_set_port(WindowPtr window, XvPortPtr port)
20203b705cfSriastradh{
20303b705cfSriastradh	((void **)__get_private(window, sna_window_key))[2] = port;
20403b705cfSriastradh}
20503b705cfSriastradh
20603b705cfSriastradh#endif /* SNA_VIDEO_H */
207