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