xa_tracker.h revision 9a0c5b46344740dbc9ffa5cbf574a7812425237c
1ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/********************************************************** 2ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown * Copyright 2009-2011 VMware, Inc. All rights reserved. 3ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown * 4ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown * Permission is hereby granted, free of charge, to any person 5ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown * obtaining a copy of this software and associated documentation 6ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown * files (the "Software"), to deal in the Software without 7ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown * restriction, including without limitation the rights to use, copy, 8ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 * The format encoding idea is partially borrowed from libpixman, but it is not 25 * considered a "substantial part of the software", so the pixman copyright 26 * is left out for simplicity, and acknowledgment is instead given in this way. 27 * 28 ********************************************************* 29 * Authors: 30 * Zack Rusin <zackr-at-vmware-dot-com> 31 * Thomas Hellstrom <thellstrom-at-vmware-dot-com> 32 */ 33 34#ifndef _XA_TRACKER_H_ 35#define _XA_TRACKER_H_ 36 37#include <stdint.h> 38 39#define XA_TRACKER_VERSION_MAJOR 0 40#define XA_TRACKER_VERSION_MINOR 4 41#define XA_TRACKER_VERSION_PATCH 0 42 43#define XA_FLAG_SHARED (1 << 0) 44#define XA_FLAG_RENDER_TARGET (1 << 1) 45 46#define XA_MAP_READ (1 << 0) 47#define XA_MAP_WRITE (1 << 1) 48 49#define XA_ERR_NONE 0 50#define XA_ERR_NORES 1 51#define XA_ERR_INVAL 2 52#define XA_ERR_BUSY 3 53 54enum xa_surface_type { 55 xa_type_other, 56 xa_type_a, 57 xa_type_argb, 58 xa_type_abgr, 59 xa_type_bgra, 60 xa_type_z, 61 xa_type_zs, 62 xa_type_sz, 63 xa_type_yuv_component 64}; 65 66/* 67 * Note that these formats should not be assumed to be binary compatible with 68 * pixman formats, but with the below macros and a format type map, 69 * conversion should be simple. Macros for now. We might replace with 70 * inline functions. 71 */ 72 73#define xa_format(bpp,type,a,r,g,b) (((bpp) << 24) | \ 74 ((type) << 16) | \ 75 ((a) << 12) | \ 76 ((r) << 8) | \ 77 ((g) << 4) | \ 78 ((b))) 79/* 80 * Non-RGBA one- and two component formats. 81 */ 82 83#define xa_format_c(bpp,type,c1,c2) (((bpp) << 24) | \ 84 ((type) << 16) | \ 85 ((c1) << 8) | \ 86 ((c2))) 87#define xa_format_bpp(f) (((f) >> 24) ) 88#define xa_format_type(f) (((f) >> 16) & 0xff) 89#define xa_format_a(f) (((f) >> 12) & 0x0f) 90#define xa_format_r(f) (((f) >> 8) & 0x0f) 91#define xa_format_g(f) (((f) >> 4) & 0x0f) 92#define xa_format_b(f) (((f) ) & 0x0f) 93#define xa_format_rgb(f) (((f) ) & 0xfff) 94#define xa_format_c1(f) (((f) >> 8 ) & 0xff) 95#define xa_format_c2(f) (((f) ) & 0xff) 96#define xa_format_argb_depth(f) (xa_format_a(f) + \ 97 xa_format_r(f) + \ 98 xa_format_g(f) + \ 99 xa_format_b(f)) 100#define xa_format_c_depth(f) (xa_format_c1(f) + \ 101 xa_format_c2(f)) 102 103static inline int 104xa_format_type_is_color(uint32_t xa_format) 105{ 106 return (xa_format_type(xa_format) < xa_type_z); 107} 108 109static inline unsigned int 110xa_format_depth(uint32_t xa_format) 111{ 112 return ((xa_format_type_is_color(xa_format)) ? 113 xa_format_argb_depth(xa_format) : xa_format_c_depth(xa_format)); 114} 115 116enum xa_formats { 117 xa_format_unknown = 0, 118 xa_format_a8 = xa_format(8, xa_type_a, 8, 0, 0, 0), 119 120 xa_format_a8r8g8b8 = xa_format(32, xa_type_argb, 8, 8, 8, 8), 121 xa_format_x8r8g8b8 = xa_format(32, xa_type_argb, 0, 8, 8, 8), 122 xa_format_r5g6b5 = xa_format(16, xa_type_argb, 0, 5, 6, 5), 123 xa_format_x1r5g5b5 = xa_format(16, xa_type_argb, 0, 5, 5, 5), 124 125 xa_format_z16 = xa_format_c(16, xa_type_z, 16, 0), 126 xa_format_z32 = xa_format_c(32, xa_type_z, 32, 0), 127 xa_format_z24 = xa_format_c(32, xa_type_z, 24, 0), 128 129 xa_format_x8z24 = xa_format_c(32, xa_type_sz, 24, 0), 130 xa_format_s8z24 = xa_format_c(32, xa_type_sz, 24, 8), 131 xa_format_z24x8 = xa_format_c(32, xa_type_zs, 24, 0), 132 xa_format_z24s8 = xa_format_c(32, xa_type_zs, 24, 8), 133 134 xa_format_yuv8 = xa_format_c(8, xa_type_yuv_component, 8, 0) 135}; 136 137struct xa_tracker; 138struct xa_surface; 139 140struct xa_box { 141 uint16_t x1, y1, x2, y2; 142}; 143 144extern void xa_tracker_version(int *major, int *minor, int *patch); 145 146extern struct xa_tracker *xa_tracker_create(int drm_fd); 147 148extern void xa_tracker_destroy(struct xa_tracker *xa); 149 150extern int xa_format_check_supported(struct xa_tracker *xa, 151 enum xa_formats xa_format, 152 unsigned int flags); 153 154extern struct xa_surface *xa_surface_create(struct xa_tracker *xa, 155 int width, 156 int height, 157 int depth, 158 enum xa_surface_type stype, 159 enum xa_formats pform, 160 unsigned int flags); 161 162enum xa_formats xa_surface_format(const struct xa_surface *srf); 163 164extern void xa_surface_destroy(struct xa_surface *srf); 165 166extern int xa_surface_redefine(struct xa_surface *srf, 167 int width, 168 int height, 169 int depth, 170 enum xa_surface_type stype, 171 enum xa_formats rgb_format, 172 unsigned int new_flags, 173 int copy_contents); 174 175extern int xa_surface_handle(struct xa_surface *srf, 176 uint32_t * handle, unsigned int *byte_stride); 177 178#endif 179