196c5ddc4Srjs/********************************************************** 296c5ddc4Srjs * Copyright 2009-2011 VMware, Inc. All rights reserved. 396c5ddc4Srjs * 496c5ddc4Srjs * Permission is hereby granted, free of charge, to any person 596c5ddc4Srjs * obtaining a copy of this software and associated documentation 696c5ddc4Srjs * files (the "Software"), to deal in the Software without 796c5ddc4Srjs * restriction, including without limitation the rights to use, copy, 896c5ddc4Srjs * modify, merge, publish, distribute, sublicense, and/or sell copies 996c5ddc4Srjs * of the Software, and to permit persons to whom the Software is 1096c5ddc4Srjs * furnished to do so, subject to the following conditions: 1196c5ddc4Srjs * 1296c5ddc4Srjs * The above copyright notice and this permission notice shall be 1396c5ddc4Srjs * included in all copies or substantial portions of the Software. 1496c5ddc4Srjs * 1596c5ddc4Srjs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1696c5ddc4Srjs * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1796c5ddc4Srjs * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 1896c5ddc4Srjs * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 1996c5ddc4Srjs * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 2096c5ddc4Srjs * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2196c5ddc4Srjs * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2296c5ddc4Srjs * SOFTWARE. 2396c5ddc4Srjs * 2496c5ddc4Srjs * The format encoding idea is partially borrowed from libpixman, but it is not 2596c5ddc4Srjs * considered a "substantial part of the software", so the pixman copyright 2696c5ddc4Srjs * is left out for simplicity, and acknowledgment is instead given in this way. 2796c5ddc4Srjs * 2896c5ddc4Srjs ********************************************************* 2996c5ddc4Srjs * Authors: 3096c5ddc4Srjs * Zack Rusin <zackr-at-vmware-dot-com> 3196c5ddc4Srjs * Thomas Hellstrom <thellstrom-at-vmware-dot-com> 3296c5ddc4Srjs */ 3396c5ddc4Srjs 3496c5ddc4Srjs#ifndef _XA_TRACKER_H_ 3596c5ddc4Srjs#define _XA_TRACKER_H_ 3696c5ddc4Srjs 3796c5ddc4Srjs#include <stdint.h> 3896c5ddc4Srjs 3996c5ddc4Srjs#define XA_TRACKER_VERSION_MAJOR 2 4096c5ddc4Srjs#define XA_TRACKER_VERSION_MINOR 5 4196c5ddc4Srjs#define XA_TRACKER_VERSION_PATCH 0 4296c5ddc4Srjs 4396c5ddc4Srjs#define XA_FLAG_SHARED (1 << 0) 4496c5ddc4Srjs#define XA_FLAG_RENDER_TARGET (1 << 1) 4596c5ddc4Srjs#define XA_FLAG_SCANOUT (1 << 2) 4696c5ddc4Srjs 4796c5ddc4Srjs#define XA_MAP_READ (1 << 0) 4896c5ddc4Srjs#define XA_MAP_WRITE (1 << 1) 4996c5ddc4Srjs#define XA_MAP_MAP_DIRECTLY (1 << 2) 5096c5ddc4Srjs#define XA_MAP_UNSYNCHRONIZED (1 << 3) 5196c5ddc4Srjs#define XA_MAP_DONTBLOCK (1 << 4) 5296c5ddc4Srjs#define XA_MAP_DISCARD_WHOLE_RESOURCE (1 << 5) 5396c5ddc4Srjs 5496c5ddc4Srjs#define XA_ERR_NONE 0 5596c5ddc4Srjs#define XA_ERR_NORES 1 5696c5ddc4Srjs#define XA_ERR_INVAL 2 5796c5ddc4Srjs#define XA_ERR_BUSY 3 5896c5ddc4Srjs 5996c5ddc4Srjsenum xa_surface_type { 6096c5ddc4Srjs xa_type_other, 6196c5ddc4Srjs xa_type_a, 6296c5ddc4Srjs xa_type_argb, 6396c5ddc4Srjs xa_type_abgr, 6496c5ddc4Srjs xa_type_bgra, 6596c5ddc4Srjs xa_type_z, 6696c5ddc4Srjs xa_type_zs, 6796c5ddc4Srjs xa_type_sz, 6896c5ddc4Srjs xa_type_yuv_component 6996c5ddc4Srjs}; 7096c5ddc4Srjs 7196c5ddc4Srjs/* 7296c5ddc4Srjs * Note that these formats should not be assumed to be binary compatible with 7396c5ddc4Srjs * pixman formats, but with the below macros and a format type map, 7496c5ddc4Srjs * conversion should be simple. Macros for now. We might replace with 7596c5ddc4Srjs * inline functions. 7696c5ddc4Srjs */ 7796c5ddc4Srjs 7896c5ddc4Srjs#define xa_format(bpp,type,a,r,g,b) (((bpp) << 24) | \ 7996c5ddc4Srjs ((type) << 16) | \ 8096c5ddc4Srjs ((a) << 12) | \ 8196c5ddc4Srjs ((r) << 8) | \ 8296c5ddc4Srjs ((g) << 4) | \ 8396c5ddc4Srjs ((b))) 8496c5ddc4Srjs/* 8596c5ddc4Srjs * Non-RGBA one- and two component formats. 8696c5ddc4Srjs */ 8796c5ddc4Srjs 8896c5ddc4Srjs#define xa_format_c(bpp,type,c1,c2) (((bpp) << 24) | \ 8996c5ddc4Srjs ((type) << 16) | \ 9096c5ddc4Srjs ((c1) << 8) | \ 9196c5ddc4Srjs ((c2))) 9296c5ddc4Srjs#define xa_format_bpp(f) (((f) >> 24) ) 9396c5ddc4Srjs#define xa_format_type(f) (((f) >> 16) & 0xff) 9496c5ddc4Srjs#define xa_format_a(f) (((f) >> 12) & 0x0f) 9596c5ddc4Srjs#define xa_format_r(f) (((f) >> 8) & 0x0f) 9696c5ddc4Srjs#define xa_format_g(f) (((f) >> 4) & 0x0f) 9796c5ddc4Srjs#define xa_format_b(f) (((f) ) & 0x0f) 9896c5ddc4Srjs#define xa_format_rgb(f) (((f) ) & 0xfff) 9996c5ddc4Srjs#define xa_format_c1(f) (((f) >> 8 ) & 0xff) 10096c5ddc4Srjs#define xa_format_c2(f) (((f) ) & 0xff) 10196c5ddc4Srjs#define xa_format_argb_depth(f) (xa_format_a(f) + \ 10296c5ddc4Srjs xa_format_r(f) + \ 10396c5ddc4Srjs xa_format_g(f) + \ 10496c5ddc4Srjs xa_format_b(f)) 10596c5ddc4Srjs#define xa_format_c_depth(f) (xa_format_c1(f) + \ 10696c5ddc4Srjs xa_format_c2(f)) 10796c5ddc4Srjs 10896c5ddc4Srjsstatic inline int 10996c5ddc4Srjsxa_format_type_is_color(uint32_t xa_format) 11096c5ddc4Srjs{ 11196c5ddc4Srjs return (xa_format_type(xa_format) < xa_type_z); 11296c5ddc4Srjs} 11396c5ddc4Srjs 11496c5ddc4Srjsstatic inline unsigned int 11596c5ddc4Srjsxa_format_depth(uint32_t xa_format) 11696c5ddc4Srjs{ 11796c5ddc4Srjs return ((xa_format_type_is_color(xa_format)) ? 11896c5ddc4Srjs xa_format_argb_depth(xa_format) : xa_format_c_depth(xa_format)); 11996c5ddc4Srjs} 12096c5ddc4Srjs 12196c5ddc4Srjsenum xa_formats { 12296c5ddc4Srjs xa_format_unknown = 0, 12396c5ddc4Srjs xa_format_a8 = xa_format(8, xa_type_a, 8, 0, 0, 0), 12496c5ddc4Srjs 12596c5ddc4Srjs xa_format_a8r8g8b8 = xa_format(32, xa_type_argb, 8, 8, 8, 8), 12696c5ddc4Srjs xa_format_x8r8g8b8 = xa_format(32, xa_type_argb, 0, 8, 8, 8), 12796c5ddc4Srjs xa_format_r5g6b5 = xa_format(16, xa_type_argb, 0, 5, 6, 5), 12896c5ddc4Srjs xa_format_x1r5g5b5 = xa_format(16, xa_type_argb, 0, 5, 5, 5), 12996c5ddc4Srjs xa_format_a4r4g4b4 = xa_format(16, xa_type_argb, 4, 4, 4, 4), 13096c5ddc4Srjs xa_format_a2b10g10r10 = xa_format(32, xa_type_abgr, 2, 10, 10, 10), 13196c5ddc4Srjs xa_format_x2b10g10r10 = xa_format(32, xa_type_abgr, 0, 10, 10, 10), 13296c5ddc4Srjs xa_format_b8g8r8a8 = xa_format(32, xa_type_bgra, 8, 8, 8, 8), 13396c5ddc4Srjs xa_format_b8g8r8x8 = xa_format(32, xa_type_bgra, 0, 8, 8, 8), 13496c5ddc4Srjs 13596c5ddc4Srjs xa_format_z16 = xa_format_c(16, xa_type_z, 16, 0), 13696c5ddc4Srjs xa_format_z32 = xa_format_c(32, xa_type_z, 32, 0), 13796c5ddc4Srjs xa_format_z24 = xa_format_c(32, xa_type_z, 24, 0), 13896c5ddc4Srjs 13996c5ddc4Srjs xa_format_x8z24 = xa_format_c(32, xa_type_sz, 24, 0), 14096c5ddc4Srjs xa_format_s8z24 = xa_format_c(32, xa_type_sz, 24, 8), 14196c5ddc4Srjs xa_format_z24x8 = xa_format_c(32, xa_type_zs, 24, 0), 14296c5ddc4Srjs xa_format_z24s8 = xa_format_c(32, xa_type_zs, 24, 8), 14396c5ddc4Srjs 14496c5ddc4Srjs xa_format_yuv8 = xa_format_c(8, xa_type_yuv_component, 8, 0) 14596c5ddc4Srjs}; 14696c5ddc4Srjs 14796c5ddc4Srjsstruct xa_tracker; 14896c5ddc4Srjsstruct xa_surface; 14996c5ddc4Srjs 15096c5ddc4Srjsstruct xa_box { 15196c5ddc4Srjs uint16_t x1, y1, x2, y2; 15296c5ddc4Srjs}; 15396c5ddc4Srjs 15496c5ddc4Srjsenum xa_handle_type { 15596c5ddc4Srjs xa_handle_type_shared, 15696c5ddc4Srjs xa_handle_type_kms, 15796c5ddc4Srjs xa_handle_type_fd, 15896c5ddc4Srjs}; 15996c5ddc4Srjs 16096c5ddc4Srjsextern void xa_tracker_version(int *major, int *minor, int *patch); 16196c5ddc4Srjs 16296c5ddc4Srjsextern struct xa_tracker *xa_tracker_create(int drm_fd); 16396c5ddc4Srjs 16496c5ddc4Srjsextern void xa_tracker_destroy(struct xa_tracker *xa); 16596c5ddc4Srjs 16696c5ddc4Srjsextern int xa_format_check_supported(struct xa_tracker *xa, 16796c5ddc4Srjs enum xa_formats xa_format, 16896c5ddc4Srjs unsigned int flags); 16996c5ddc4Srjs 17096c5ddc4Srjsextern struct xa_surface *xa_surface_create(struct xa_tracker *xa, 17196c5ddc4Srjs int width, 17296c5ddc4Srjs int height, 17396c5ddc4Srjs int depth, 17496c5ddc4Srjs enum xa_surface_type stype, 17596c5ddc4Srjs enum xa_formats pform, 17696c5ddc4Srjs unsigned int flags); 17796c5ddc4Srjs 17896c5ddc4Srjsextern struct xa_surface * xa_surface_from_handle(struct xa_tracker *xa, 17996c5ddc4Srjs int width, 18096c5ddc4Srjs int height, 18196c5ddc4Srjs int depth, 18296c5ddc4Srjs enum xa_surface_type stype, 18396c5ddc4Srjs enum xa_formats pform, 18496c5ddc4Srjs unsigned int flags, 18596c5ddc4Srjs uint32_t handle, uint32_t stride); 18696c5ddc4Srjsextern struct xa_surface * 18796c5ddc4Srjsxa_surface_from_handle2(struct xa_tracker *xa, 18896c5ddc4Srjs int width, 18996c5ddc4Srjs int height, 19096c5ddc4Srjs int depth, 19196c5ddc4Srjs enum xa_surface_type stype, 19296c5ddc4Srjs enum xa_formats xa_format, 19396c5ddc4Srjs unsigned int flags, 19496c5ddc4Srjs enum xa_handle_type type, 19596c5ddc4Srjs uint32_t handle, 19696c5ddc4Srjs uint32_t stride); 19796c5ddc4Srjs 19896c5ddc4Srjsenum xa_formats xa_surface_format(const struct xa_surface *srf); 19996c5ddc4Srjs 20096c5ddc4Srjsextern struct xa_surface *xa_surface_ref(struct xa_surface *srf); 20196c5ddc4Srjsextern void xa_surface_unref(struct xa_surface *srf); 20296c5ddc4Srjs 20396c5ddc4Srjsextern int xa_surface_redefine(struct xa_surface *srf, 20496c5ddc4Srjs int width, 20596c5ddc4Srjs int height, 20696c5ddc4Srjs int depth, 20796c5ddc4Srjs enum xa_surface_type stype, 20896c5ddc4Srjs enum xa_formats rgb_format, 20996c5ddc4Srjs unsigned int new_flags, 21096c5ddc4Srjs int copy_contents); 21196c5ddc4Srjs 21296c5ddc4Srjsextern int xa_surface_handle(struct xa_surface *srf, 21396c5ddc4Srjs enum xa_handle_type type, 21496c5ddc4Srjs uint32_t * handle, 21596c5ddc4Srjs unsigned int *byte_stride); 21696c5ddc4Srjs 21796c5ddc4Srjs#endif 218