1428d7b3dSmrg/*************************************************************************** 2428d7b3dSmrg 3428d7b3dSmrgCopyright 2000 Intel Corporation. All Rights Reserved. 4428d7b3dSmrg 5428d7b3dSmrgPermission is hereby granted, free of charge, to any person obtaining a 6428d7b3dSmrgcopy of this software and associated documentation files (the 7428d7b3dSmrg"Software"), to deal in the Software without restriction, including 8428d7b3dSmrgwithout limitation the rights to use, copy, modify, merge, publish, 9428d7b3dSmrgdistribute, sub license, and/or sell copies of the Software, and to 10428d7b3dSmrgpermit persons to whom the Software is furnished to do so, subject to 11428d7b3dSmrgthe following conditions: 12428d7b3dSmrg 13428d7b3dSmrgThe above copyright notice and this permission notice (including the 14428d7b3dSmrgnext paragraph) shall be included in all copies or substantial portions 15428d7b3dSmrgof the Software. 16428d7b3dSmrg 17428d7b3dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18428d7b3dSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19428d7b3dSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20428d7b3dSmrgIN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 21428d7b3dSmrgDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22428d7b3dSmrgOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 23428d7b3dSmrgTHE USE OR OTHER DEALINGS IN THE SOFTWARE. 24428d7b3dSmrg 25428d7b3dSmrg**************************************************************************/ 26428d7b3dSmrg 27428d7b3dSmrg#ifndef SNA_VIDEO_H 28428d7b3dSmrg#define SNA_VIDEO_H 29428d7b3dSmrg 30428d7b3dSmrg#include <xf86_OSproc.h> 31428d7b3dSmrg#include <xf86xv.h> 32428d7b3dSmrg#include <fourcc.h> 33428d7b3dSmrg 34428d7b3dSmrg#if defined(XvMCExtension) && defined(ENABLE_XVMC) 35428d7b3dSmrg#define SNA_XVMC 1 36428d7b3dSmrg#endif 37428d7b3dSmrg 38428d7b3dSmrg#define FOURCC_XVMC (('C' << 24) + ('M' << 16) + ('V' << 8) + 'X') 39428d7b3dSmrg#define FOURCC_RGB565 ((16 << 24) + ('B' << 16) + ('G' << 8) + 'R') 40428d7b3dSmrg#define FOURCC_RGB888 ((24 << 24) + ('B' << 16) + ('G' << 8) + 'R') 41428d7b3dSmrg 42428d7b3dSmrg/* 43428d7b3dSmrg * Below, a dummy picture type that is used in XvPutImage 44428d7b3dSmrg * only to do an overlay update. 45428d7b3dSmrg * Introduced for the XvMC client lib. 46428d7b3dSmrg * Defined to have a zero data size. 47428d7b3dSmrg */ 48428d7b3dSmrg#define XVMC_YUV { \ 49428d7b3dSmrg FOURCC_XVMC, XvYUV, LSBFirst, \ 50428d7b3dSmrg {'X', 'V', 'M', 'C', 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}, \ 51428d7b3dSmrg 12, XvPlanar, 3, 0, 0, 0, 0, 8, 8, 8, 1, 2, 2, 1, 2, 2, \ 52428d7b3dSmrg {'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}, \ 53428d7b3dSmrg XvTopToBottom \ 54428d7b3dSmrg} 55428d7b3dSmrg 56428d7b3dSmrg#define XVMC_RGB565 { \ 57428d7b3dSmrg FOURCC_RGB565, XvRGB, LSBFirst, \ 58428d7b3dSmrg {'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '1', '6'}, \ 59428d7b3dSmrg 16, XvPacked, 1, 16, 0x1f<<11, 0x3f<<5, 0x1f<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 60428d7b3dSmrg {'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}, \ 61428d7b3dSmrg XvTopToBottom \ 62428d7b3dSmrg} 63428d7b3dSmrg 64428d7b3dSmrg#define XVMC_RGB888 { \ 65428d7b3dSmrg FOURCC_RGB888, XvRGB, LSBFirst, \ 66428d7b3dSmrg {'P', 'A', 'S', 'S', 'T', 'H', 'R', 'O', 'U', 'G', 'H', 'R', 'G', 'B', '2', '4'}, \ 67428d7b3dSmrg 32, XvPacked, 1, 24, 0xff<<16, 0xff<<8, 0xff<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 68428d7b3dSmrg {'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}, \ 69428d7b3dSmrg XvTopToBottom \ 70428d7b3dSmrg} 71428d7b3dSmrg 72428d7b3dSmrgstruct sna_video { 73428d7b3dSmrg struct sna *sna; 74428d7b3dSmrg 75428d7b3dSmrg int brightness; 76428d7b3dSmrg int contrast; 77428d7b3dSmrg int saturation; 78428d7b3dSmrg xf86CrtcPtr desired_crtc; 79428d7b3dSmrg 80428d7b3dSmrg uint32_t gamma0; 81428d7b3dSmrg uint32_t gamma1; 82428d7b3dSmrg uint32_t gamma2; 83428d7b3dSmrg uint32_t gamma3; 84428d7b3dSmrg uint32_t gamma4; 85428d7b3dSmrg uint32_t gamma5; 86428d7b3dSmrg 87428d7b3dSmrg unsigned color_key; 88428d7b3dSmrg unsigned color_key_changed; 89428d7b3dSmrg bool has_color_key; 90428d7b3dSmrg 91428d7b3dSmrg /** YUV data buffers */ 92428d7b3dSmrg struct kgem_bo *old_buf[2]; 93428d7b3dSmrg struct kgem_bo *buf; 94428d7b3dSmrg int width, height, format; 95428d7b3dSmrg 96428d7b3dSmrg int alignment; 97428d7b3dSmrg bool tiled; 98428d7b3dSmrg bool textured; 99428d7b3dSmrg int plane; 100428d7b3dSmrg 101428d7b3dSmrg struct kgem_bo *bo[4]; 102428d7b3dSmrg RegionRec clip; 103428d7b3dSmrg 104428d7b3dSmrg int SyncToVblank; /* -1: auto, 0: off, 1: on */ 105428d7b3dSmrg int AlwaysOnTop; 106428d7b3dSmrg}; 107428d7b3dSmrg 108428d7b3dSmrgstruct sna_video_frame { 109428d7b3dSmrg struct kgem_bo *bo; 110428d7b3dSmrg uint32_t id; 111428d7b3dSmrg uint32_t size; 112428d7b3dSmrg uint32_t UBufOffset; 113428d7b3dSmrg uint32_t VBufOffset; 114428d7b3dSmrg Rotation rotation; 115428d7b3dSmrg 116428d7b3dSmrg uint16_t width, height; 117428d7b3dSmrg uint16_t pitch[2]; 118428d7b3dSmrg 119428d7b3dSmrg /* extents */ 120428d7b3dSmrg BoxRec image; 121428d7b3dSmrg BoxRec src; 122428d7b3dSmrg}; 123428d7b3dSmrg 124428d7b3dSmrgstatic inline XvScreenPtr to_xv(ScreenPtr screen) 125428d7b3dSmrg{ 126428d7b3dSmrg return dixLookupPrivate(&screen->devPrivates, XvGetScreenKey()); 127428d7b3dSmrg} 128428d7b3dSmrg 129428d7b3dSmrgvoid sna_video_init(struct sna *sna, ScreenPtr screen); 130428d7b3dSmrgvoid sna_video_overlay_setup(struct sna *sna, ScreenPtr screen); 131428d7b3dSmrgvoid sna_video_sprite_setup(struct sna *sna, ScreenPtr screen); 132428d7b3dSmrgvoid sna_video_textured_setup(struct sna *sna, ScreenPtr screen); 133428d7b3dSmrgvoid sna_video_destroy_window(WindowPtr win); 134428d7b3dSmrgvoid sna_video_close(struct sna *sna); 135428d7b3dSmrg 136428d7b3dSmrgXvAdaptorPtr sna_xv_adaptor_alloc(struct sna *sna); 137428d7b3dSmrgint sna_xv_fixup_formats(ScreenPtr screen, 138428d7b3dSmrg XvFormatPtr formats, 139428d7b3dSmrg int num_formats); 140428d7b3dSmrgint sna_xv_alloc_port(unsigned long port, XvPortPtr in, XvPortPtr *out); 141428d7b3dSmrgint sna_xv_free_port(XvPortPtr port); 142428d7b3dSmrg 143428d7b3dSmrgstatic inline int xvmc_passthrough(int id) 144428d7b3dSmrg{ 145428d7b3dSmrg switch (id) { 146428d7b3dSmrg case FOURCC_XVMC: 147428d7b3dSmrg case FOURCC_RGB565: 148428d7b3dSmrg case FOURCC_RGB888: 149428d7b3dSmrg return true; 150428d7b3dSmrg default: 151428d7b3dSmrg return false; 152428d7b3dSmrg } 153428d7b3dSmrg} 154428d7b3dSmrg 155428d7b3dSmrgstatic inline int is_planar_fourcc(int id) 156428d7b3dSmrg{ 157428d7b3dSmrg switch (id) { 158428d7b3dSmrg case FOURCC_YV12: 159428d7b3dSmrg case FOURCC_I420: 160428d7b3dSmrg case FOURCC_XVMC: 161428d7b3dSmrg return 1; 162428d7b3dSmrg default: 163428d7b3dSmrg return 0; 164428d7b3dSmrg } 165428d7b3dSmrg} 166428d7b3dSmrg 167428d7b3dSmrgbool 168428d7b3dSmrgsna_video_clip_helper(struct sna_video *video, 169428d7b3dSmrg struct sna_video_frame *frame, 170428d7b3dSmrg xf86CrtcPtr *crtc_ret, 171428d7b3dSmrg BoxPtr dst, 172428d7b3dSmrg short src_x, short src_y, 173428d7b3dSmrg short drw_x, short drw_y, 174428d7b3dSmrg short src_w, short src_h, 175428d7b3dSmrg short drw_w, short drw_h, 176428d7b3dSmrg RegionPtr reg); 177428d7b3dSmrg 178428d7b3dSmrgvoid 179428d7b3dSmrgsna_video_frame_init(struct sna_video *video, 180428d7b3dSmrg int id, short width, short height, 181428d7b3dSmrg struct sna_video_frame *frame); 182428d7b3dSmrg 183428d7b3dSmrgvoid 184428d7b3dSmrgsna_video_frame_set_rotation(struct sna_video *video, 185428d7b3dSmrg struct sna_video_frame *frame, 186428d7b3dSmrg Rotation rotation); 187428d7b3dSmrg 188428d7b3dSmrgstruct kgem_bo * 189428d7b3dSmrgsna_video_buffer(struct sna_video *video, 190428d7b3dSmrg struct sna_video_frame *frame); 191428d7b3dSmrg 192428d7b3dSmrgbool 193428d7b3dSmrgsna_video_copy_data(struct sna_video *video, 194428d7b3dSmrg struct sna_video_frame *frame, 195428d7b3dSmrg const uint8_t *buf); 196428d7b3dSmrg 197428d7b3dSmrgvoid sna_video_buffer_fini(struct sna_video *video); 198428d7b3dSmrg 199428d7b3dSmrgvoid sna_video_free_buffers(struct sna_video *video); 200428d7b3dSmrg 201428d7b3dSmrgstatic inline XvPortPtr 202428d7b3dSmrgsna_window_get_port(WindowPtr window) 203428d7b3dSmrg{ 204428d7b3dSmrg return ((void **)__get_private(window, sna_window_key))[2]; 205428d7b3dSmrg} 206428d7b3dSmrg 207428d7b3dSmrgstatic inline void 208428d7b3dSmrgsna_window_set_port(WindowPtr window, XvPortPtr port) 209428d7b3dSmrg{ 210428d7b3dSmrg ((void **)__get_private(window, sna_window_key))[2] = port; 211428d7b3dSmrg} 212428d7b3dSmrg 213428d7b3dSmrg#endif /* SNA_VIDEO_H */ 214