sna_video.h revision 42542f5f
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 uint32_t gamma0; 81 uint32_t gamma1; 82 uint32_t gamma2; 83 uint32_t gamma3; 84 uint32_t gamma4; 85 uint32_t gamma5; 86 87 unsigned color_key; 88 unsigned color_key_changed; 89 bool has_color_key; 90 91 /** YUV data buffers */ 92 struct kgem_bo *old_buf[2]; 93 struct kgem_bo *buf; 94 int width, height, format; 95 96 int alignment; 97 bool tiled; 98 bool textured; 99 int plane; 100 101 struct kgem_bo *bo[4]; 102 RegionRec clip; 103 104 int SyncToVblank; /* -1: auto, 0: off, 1: on */ 105 int AlwaysOnTop; 106}; 107 108struct sna_video_frame { 109 struct kgem_bo *bo; 110 uint32_t id; 111 uint32_t size; 112 uint32_t UBufOffset; 113 uint32_t VBufOffset; 114 Rotation rotation; 115 116 uint16_t width, height; 117 uint16_t pitch[2]; 118 119 /* extents */ 120 BoxRec image; 121 BoxRec src; 122}; 123 124static inline XvScreenPtr to_xv(ScreenPtr screen) 125{ 126 return dixLookupPrivate(&screen->devPrivates, XvGetScreenKey()); 127} 128 129void sna_video_init(struct sna *sna, ScreenPtr screen); 130void sna_video_overlay_setup(struct sna *sna, ScreenPtr screen); 131void sna_video_sprite_setup(struct sna *sna, ScreenPtr screen); 132void sna_video_textured_setup(struct sna *sna, ScreenPtr screen); 133void sna_video_destroy_window(WindowPtr win); 134void sna_video_close(struct sna *sna); 135 136XvAdaptorPtr sna_xv_adaptor_alloc(struct sna *sna); 137int sna_xv_fixup_formats(ScreenPtr screen, 138 XvFormatPtr formats, 139 int num_formats); 140int sna_xv_alloc_port(unsigned long port, XvPortPtr in, XvPortPtr *out); 141int sna_xv_free_port(XvPortPtr port); 142 143static inline int xvmc_passthrough(int id) 144{ 145 switch (id) { 146 case FOURCC_XVMC: 147 case FOURCC_RGB565: 148 case FOURCC_RGB888: 149 return true; 150 default: 151 return false; 152 } 153} 154 155static inline int is_planar_fourcc(int id) 156{ 157 switch (id) { 158 case FOURCC_YV12: 159 case FOURCC_I420: 160 case FOURCC_XVMC: 161 return 1; 162 default: 163 return 0; 164 } 165} 166 167bool 168sna_video_clip_helper(struct sna_video *video, 169 struct sna_video_frame *frame, 170 xf86CrtcPtr *crtc_ret, 171 BoxPtr dst, 172 short src_x, short src_y, 173 short drw_x, short drw_y, 174 short src_w, short src_h, 175 short drw_w, short drw_h, 176 RegionPtr reg); 177 178void 179sna_video_frame_init(struct sna_video *video, 180 int id, short width, short height, 181 struct sna_video_frame *frame); 182 183void 184sna_video_frame_set_rotation(struct sna_video *video, 185 struct sna_video_frame *frame, 186 Rotation rotation); 187 188struct kgem_bo * 189sna_video_buffer(struct sna_video *video, 190 struct sna_video_frame *frame); 191 192bool 193sna_video_copy_data(struct sna_video *video, 194 struct sna_video_frame *frame, 195 const uint8_t *buf); 196 197void sna_video_buffer_fini(struct sna_video *video); 198 199void sna_video_free_buffers(struct sna_video *video); 200 201static inline XvPortPtr 202sna_window_get_port(WindowPtr window) 203{ 204 return ((void **)__get_private(window, sna_window_key))[2]; 205} 206 207static inline void 208sna_window_set_port(WindowPtr window, XvPortPtr port) 209{ 210 ((void **)__get_private(window, sna_window_key))[2] = port; 211} 212 213#endif /* SNA_VIDEO_H */ 214