sna_video.h revision fe8aea9e
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') 41fe8aea9eSmrg#define FOURCC_NV12 (('2' << 24) + ('1' << 16) + ('V' << 8) + 'N') 42fe8aea9eSmrg#define FOURCC_AYUV (('V' << 24) + ('U' << 16) + ('Y' << 8) + 'A') 4303b705cfSriastradh 4403b705cfSriastradh/* 4503b705cfSriastradh * Below, a dummy picture type that is used in XvPutImage 4603b705cfSriastradh * only to do an overlay update. 4703b705cfSriastradh * Introduced for the XvMC client lib. 4803b705cfSriastradh * Defined to have a zero data size. 4903b705cfSriastradh */ 5003b705cfSriastradh#define XVMC_YUV { \ 5103b705cfSriastradh FOURCC_XVMC, XvYUV, LSBFirst, \ 5203b705cfSriastradh {'X', 'V', 'M', 'C', 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}, \ 5303b705cfSriastradh 12, XvPlanar, 3, 0, 0, 0, 0, 8, 8, 8, 1, 2, 2, 1, 2, 2, \ 5403b705cfSriastradh {'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}, \ 5503b705cfSriastradh XvTopToBottom \ 5603b705cfSriastradh} 5703b705cfSriastradh 5803b705cfSriastradh#define XVMC_RGB565 { \ 5903b705cfSriastradh FOURCC_RGB565, XvRGB, LSBFirst, \ 6003b705cfSriastradh {'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '1', '6'}, \ 6103b705cfSriastradh 16, XvPacked, 1, 16, 0x1f<<11, 0x3f<<5, 0x1f<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 6203b705cfSriastradh {'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}, \ 6303b705cfSriastradh XvTopToBottom \ 6403b705cfSriastradh} 6503b705cfSriastradh 6603b705cfSriastradh#define XVMC_RGB888 { \ 6703b705cfSriastradh FOURCC_RGB888, XvRGB, LSBFirst, \ 6803b705cfSriastradh {'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '2', '4'}, \ 6903b705cfSriastradh 32, XvPacked, 1, 24, 0xff<<16, 0xff<<8, 0xff<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 7003b705cfSriastradh {'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}, \ 7103b705cfSriastradh XvTopToBottom \ 7203b705cfSriastradh} 7303b705cfSriastradh 74fe8aea9eSmrg/* no standard define for this */ 75fe8aea9eSmrg#define XVIMAGE_NV12 { \ 76fe8aea9eSmrg FOURCC_NV12, XvYUV, LSBFirst, \ 77fe8aea9eSmrg {'N','V','1','2', 0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71}, \ 78fe8aea9eSmrg 12, XvPlanar, 2, 0, 0, 0, 0, 8, 8, 8, 1, 2, 2, 1, 2, 2, \ 79fe8aea9eSmrg {'Y','U','V', 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}, \ 80fe8aea9eSmrg XvTopToBottom \ 81fe8aea9eSmrg} 82fe8aea9eSmrg 83fe8aea9eSmrg#define XVIMAGE_AYUV { \ 84fe8aea9eSmrg FOURCC_AYUV, XvYUV, LSBFirst, \ 85fe8aea9eSmrg {'A', 'Y', 'U', 'V', 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}, \ 86fe8aea9eSmrg 32, XvPacked, 1, 0, 0, 0, 0, 8, 8, 8, 1, 1, 1, 1, 1, 1, \ 87fe8aea9eSmrg {'A', 'Y', 'U', 'V', 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}, \ 88fe8aea9eSmrg XvTopToBottom \ 89fe8aea9eSmrg} 90fe8aea9eSmrg 9103b705cfSriastradhstruct sna_video { 9203b705cfSriastradh struct sna *sna; 9303b705cfSriastradh 94fe8aea9eSmrg int idx; /* XXX expose struct plane instead? */ 95fe8aea9eSmrg 9603b705cfSriastradh int brightness; 9703b705cfSriastradh int contrast; 9803b705cfSriastradh int saturation; 9903b705cfSriastradh xf86CrtcPtr desired_crtc; 10003b705cfSriastradh 10103b705cfSriastradh uint32_t gamma0; 10203b705cfSriastradh uint32_t gamma1; 10303b705cfSriastradh uint32_t gamma2; 10403b705cfSriastradh uint32_t gamma3; 10503b705cfSriastradh uint32_t gamma4; 10603b705cfSriastradh uint32_t gamma5; 10703b705cfSriastradh 10842542f5fSchristos unsigned color_key; 10942542f5fSchristos unsigned color_key_changed; 11042542f5fSchristos bool has_color_key; 11103b705cfSriastradh 112fe8aea9eSmrg unsigned colorspace; 113fe8aea9eSmrg unsigned colorspace_changed; 114fe8aea9eSmrg 11503b705cfSriastradh /** YUV data buffers */ 11603b705cfSriastradh struct kgem_bo *old_buf[2]; 11703b705cfSriastradh struct kgem_bo *buf; 11842542f5fSchristos int width, height, format; 11903b705cfSriastradh 12003b705cfSriastradh int alignment; 12103b705cfSriastradh bool tiled; 12203b705cfSriastradh bool textured; 12342542f5fSchristos 12442542f5fSchristos struct kgem_bo *bo[4]; 12542542f5fSchristos RegionRec clip; 12603b705cfSriastradh 12703b705cfSriastradh int SyncToVblank; /* -1: auto, 0: off, 1: on */ 12803b705cfSriastradh int AlwaysOnTop; 12903b705cfSriastradh}; 13003b705cfSriastradh 13103b705cfSriastradhstruct sna_video_frame { 13203b705cfSriastradh struct kgem_bo *bo; 13303b705cfSriastradh uint32_t id; 13403b705cfSriastradh uint32_t size; 13503b705cfSriastradh uint32_t UBufOffset; 13603b705cfSriastradh uint32_t VBufOffset; 13742542f5fSchristos Rotation rotation; 13803b705cfSriastradh 13903b705cfSriastradh uint16_t width, height; 14003b705cfSriastradh uint16_t pitch[2]; 14103b705cfSriastradh 14203b705cfSriastradh /* extents */ 14303b705cfSriastradh BoxRec image; 14403b705cfSriastradh BoxRec src; 14503b705cfSriastradh}; 14603b705cfSriastradh 14703b705cfSriastradhstatic inline XvScreenPtr to_xv(ScreenPtr screen) 14803b705cfSriastradh{ 14903b705cfSriastradh return dixLookupPrivate(&screen->devPrivates, XvGetScreenKey()); 15003b705cfSriastradh} 15103b705cfSriastradh 15203b705cfSriastradhvoid sna_video_init(struct sna *sna, ScreenPtr screen); 15303b705cfSriastradhvoid sna_video_overlay_setup(struct sna *sna, ScreenPtr screen); 15403b705cfSriastradhvoid sna_video_sprite_setup(struct sna *sna, ScreenPtr screen); 15503b705cfSriastradhvoid sna_video_textured_setup(struct sna *sna, ScreenPtr screen); 15603b705cfSriastradhvoid sna_video_destroy_window(WindowPtr win); 15742542f5fSchristosvoid sna_video_close(struct sna *sna); 15803b705cfSriastradh 15903b705cfSriastradhXvAdaptorPtr sna_xv_adaptor_alloc(struct sna *sna); 16003b705cfSriastradhint sna_xv_fixup_formats(ScreenPtr screen, 16103b705cfSriastradh XvFormatPtr formats, 16203b705cfSriastradh int num_formats); 16303b705cfSriastradhint sna_xv_alloc_port(unsigned long port, XvPortPtr in, XvPortPtr *out); 16403b705cfSriastradhint sna_xv_free_port(XvPortPtr port); 16503b705cfSriastradh 16603b705cfSriastradhstatic inline int xvmc_passthrough(int id) 16703b705cfSriastradh{ 16803b705cfSriastradh switch (id) { 16903b705cfSriastradh case FOURCC_XVMC: 17003b705cfSriastradh case FOURCC_RGB565: 17103b705cfSriastradh case FOURCC_RGB888: 17203b705cfSriastradh return true; 17303b705cfSriastradh default: 17403b705cfSriastradh return false; 17503b705cfSriastradh } 17603b705cfSriastradh} 17703b705cfSriastradh 17803b705cfSriastradhstatic inline int is_planar_fourcc(int id) 17903b705cfSriastradh{ 18003b705cfSriastradh switch (id) { 18103b705cfSriastradh case FOURCC_YV12: 18203b705cfSriastradh case FOURCC_I420: 18303b705cfSriastradh case FOURCC_XVMC: 184fe8aea9eSmrg case FOURCC_NV12: 185fe8aea9eSmrg return 1; 186fe8aea9eSmrg default: 187fe8aea9eSmrg return 0; 188fe8aea9eSmrg } 189fe8aea9eSmrg} 190fe8aea9eSmrg 191fe8aea9eSmrgstatic inline int is_nv12_fourcc(int id) 192fe8aea9eSmrg{ 193fe8aea9eSmrg switch (id) { 194fe8aea9eSmrg case FOURCC_NV12: 195fe8aea9eSmrg return 1; 196fe8aea9eSmrg default: 197fe8aea9eSmrg return 0; 198fe8aea9eSmrg } 199fe8aea9eSmrg} 200fe8aea9eSmrg 201fe8aea9eSmrgstatic inline int is_ayuv_fourcc(int id) 202fe8aea9eSmrg{ 203fe8aea9eSmrg switch (id) { 204fe8aea9eSmrg case FOURCC_AYUV: 20503b705cfSriastradh return 1; 20603b705cfSriastradh default: 20703b705cfSriastradh return 0; 20803b705cfSriastradh } 20903b705cfSriastradh} 21003b705cfSriastradh 21103b705cfSriastradhbool 21242542f5fSchristossna_video_clip_helper(struct sna_video *video, 21303b705cfSriastradh struct sna_video_frame *frame, 21442542f5fSchristos xf86CrtcPtr *crtc_ret, 21503b705cfSriastradh BoxPtr dst, 21603b705cfSriastradh short src_x, short src_y, 21703b705cfSriastradh short drw_x, short drw_y, 21803b705cfSriastradh short src_w, short src_h, 21903b705cfSriastradh short drw_w, short drw_h, 22003b705cfSriastradh RegionPtr reg); 22103b705cfSriastradh 22203b705cfSriastradhvoid 22303b705cfSriastradhsna_video_frame_init(struct sna_video *video, 22403b705cfSriastradh int id, short width, short height, 22503b705cfSriastradh struct sna_video_frame *frame); 22603b705cfSriastradh 22742542f5fSchristosvoid 22842542f5fSchristossna_video_frame_set_rotation(struct sna_video *video, 22942542f5fSchristos struct sna_video_frame *frame, 23042542f5fSchristos Rotation rotation); 23142542f5fSchristos 23203b705cfSriastradhstruct kgem_bo * 23303b705cfSriastradhsna_video_buffer(struct sna_video *video, 23403b705cfSriastradh struct sna_video_frame *frame); 23503b705cfSriastradh 23603b705cfSriastradhbool 23703b705cfSriastradhsna_video_copy_data(struct sna_video *video, 23803b705cfSriastradh struct sna_video_frame *frame, 23903b705cfSriastradh const uint8_t *buf); 240fe8aea9eSmrgvoid 241fe8aea9eSmrgsna_video_fill_colorkey(struct sna_video *video, 242fe8aea9eSmrg const RegionRec *clip); 24303b705cfSriastradh 24403b705cfSriastradhvoid sna_video_buffer_fini(struct sna_video *video); 24503b705cfSriastradh 24603b705cfSriastradhvoid sna_video_free_buffers(struct sna_video *video); 24703b705cfSriastradh 24803b705cfSriastradhstatic inline XvPortPtr 24903b705cfSriastradhsna_window_get_port(WindowPtr window) 25003b705cfSriastradh{ 25103b705cfSriastradh return ((void **)__get_private(window, sna_window_key))[2]; 25203b705cfSriastradh} 25303b705cfSriastradh 25403b705cfSriastradhstatic inline void 25503b705cfSriastradhsna_window_set_port(WindowPtr window, XvPortPtr port) 25603b705cfSriastradh{ 25703b705cfSriastradh ((void **)__get_private(window, sna_window_key))[2] = port; 25803b705cfSriastradh} 25903b705cfSriastradh 260fe8aea9eSmrgstatic inline int offset_and_clip(int x, int dx) 261fe8aea9eSmrg{ 262fe8aea9eSmrg x += dx; 263fe8aea9eSmrg if (x <= 0) 264fe8aea9eSmrg return 0; 265fe8aea9eSmrg if (x >= MAXSHORT) 266fe8aea9eSmrg return MAXSHORT; 267fe8aea9eSmrg return x; 268fe8aea9eSmrg} 269fe8aea9eSmrg 270fe8aea9eSmrgstatic inline void init_video_region(RegionRec *region, 271fe8aea9eSmrg DrawablePtr draw, 272fe8aea9eSmrg int drw_x, int drw_y, 273fe8aea9eSmrg int drw_w, int drw_h) 274fe8aea9eSmrg{ 275fe8aea9eSmrg region->extents.x1 = offset_and_clip(draw->x, drw_x); 276fe8aea9eSmrg region->extents.y1 = offset_and_clip(draw->y, drw_y); 277fe8aea9eSmrg region->extents.x2 = offset_and_clip(draw->x, drw_x + drw_w); 278fe8aea9eSmrg region->extents.y2 = offset_and_clip(draw->y, drw_y + drw_h); 279fe8aea9eSmrg region->data = NULL; 280fe8aea9eSmrg} 281fe8aea9eSmrg 28203b705cfSriastradh#endif /* SNA_VIDEO_H */ 283