19f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom/********************************************************** 29f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * Copyright 2009-2011 VMware, Inc. All rights reserved. 39f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * 49f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * Permission is hereby granted, free of charge, to any person 59f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * obtaining a copy of this software and associated documentation 69f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * files (the "Software"), to deal in the Software without 79f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * restriction, including without limitation the rights to use, copy, 89f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * modify, merge, publish, distribute, sublicense, and/or sell copies 99f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * of the Software, and to permit persons to whom the Software is 109f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * furnished to do so, subject to the following conditions: 119f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * 129f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * The above copyright notice and this permission notice shall be 139f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * included in all copies or substantial portions of the Software. 149f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * 159f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 169f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 179f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 189f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 199f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 209f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 219f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 229f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * SOFTWARE. 239f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * 249f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * The format encoding idea is partially borrowed from libpixman, but it is not 259f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * considered a "substantial part of the software", so the pixman copyright 269f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * is left out for simplicity, and acknowledgment is instead given in this way. 279f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * 289f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ********************************************************* 299f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * Authors: 309f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * Zack Rusin <zackr-at-vmware-dot-com> 319f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * Thomas Hellstrom <thellstrom-at-vmware-dot-com> 329f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom */ 339f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 349f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#ifndef _XA_TRACKER_H_ 359f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define _XA_TRACKER_H_ 369f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 379f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#include <stdint.h> 389f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 398a4f7d1cdc6f3c9e8a5a6f4a0928c3abdb132541Thomas Hellstrom#define XA_TRACKER_VERSION_MAJOR 1 408a4f7d1cdc6f3c9e8a5a6f4a0928c3abdb132541Thomas Hellstrom#define XA_TRACKER_VERSION_MINOR 0 419f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_TRACKER_VERSION_PATCH 0 429f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 439f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_FLAG_SHARED (1 << 0) 449f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_FLAG_RENDER_TARGET (1 << 1) 45dc4ef916016dc4237551bad132325c71f4eb28e2Thomas Hellstrom#define XA_FLAG_SCANOUT (1 << 2) 469f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 479f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_MAP_READ (1 << 0) 489f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_MAP_WRITE (1 << 1) 499f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 509f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_ERR_NONE 0 519f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_ERR_NORES 1 529f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_ERR_INVAL 2 539f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define XA_ERR_BUSY 3 549f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 559f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromenum xa_surface_type { 569f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_other, 579f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_a, 589f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_argb, 599f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_abgr, 609f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_bgra, 619f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_z, 629f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_zs, 639f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_sz, 649f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_type_yuv_component 659f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom}; 669f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 679f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom/* 689f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * Note that these formats should not be assumed to be binary compatible with 699f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * pixman formats, but with the below macros and a format type map, 709f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * conversion should be simple. Macros for now. We might replace with 719f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * inline functions. 729f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom */ 739f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 749f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format(bpp,type,a,r,g,b) (((bpp) << 24) | \ 759f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((type) << 16) | \ 769f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((a) << 12) | \ 779f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((r) << 8) | \ 789f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((g) << 4) | \ 799f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((b))) 809f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom/* 819f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom * Non-RGBA one- and two component formats. 829f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom */ 839f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 849f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_c(bpp,type,c1,c2) (((bpp) << 24) | \ 859f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((type) << 16) | \ 869f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((c1) << 8) | \ 879f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom ((c2))) 889f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_bpp(f) (((f) >> 24) ) 899f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_type(f) (((f) >> 16) & 0xff) 909f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_a(f) (((f) >> 12) & 0x0f) 919f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_r(f) (((f) >> 8) & 0x0f) 929f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_g(f) (((f) >> 4) & 0x0f) 939f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_b(f) (((f) ) & 0x0f) 949f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_rgb(f) (((f) ) & 0xfff) 959f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_c1(f) (((f) >> 8 ) & 0xff) 969f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_c2(f) (((f) ) & 0xff) 979f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_argb_depth(f) (xa_format_a(f) + \ 989f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_r(f) + \ 999f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_g(f) + \ 1009f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_b(f)) 1019f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#define xa_format_c_depth(f) (xa_format_c1(f) + \ 1029f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_c2(f)) 1039f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1049f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromstatic inline int 1059f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromxa_format_type_is_color(uint32_t xa_format) 1069f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom{ 1079f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom return (xa_format_type(xa_format) < xa_type_z); 1089f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom} 1099f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1109f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromstatic inline unsigned int 1119f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromxa_format_depth(uint32_t xa_format) 1129f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom{ 1139f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom return ((xa_format_type_is_color(xa_format)) ? 1149f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_argb_depth(xa_format) : xa_format_c_depth(xa_format)); 1159f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom} 1169f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1179f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromenum xa_formats { 1189f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_unknown = 0, 1199f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_a8 = xa_format(8, xa_type_a, 8, 0, 0, 0), 1209f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1219f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_a8r8g8b8 = xa_format(32, xa_type_argb, 8, 8, 8, 8), 1229f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_x8r8g8b8 = xa_format(32, xa_type_argb, 0, 8, 8, 8), 1239f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_r5g6b5 = xa_format(16, xa_type_argb, 0, 5, 6, 5), 1249f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_x1r5g5b5 = xa_format(16, xa_type_argb, 0, 5, 5, 5), 1259f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1269f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_z16 = xa_format_c(16, xa_type_z, 16, 0), 1279f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_z32 = xa_format_c(32, xa_type_z, 32, 0), 1289f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_z24 = xa_format_c(32, xa_type_z, 24, 0), 1299f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1309f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_x8z24 = xa_format_c(32, xa_type_sz, 24, 0), 1319f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_s8z24 = xa_format_c(32, xa_type_sz, 24, 8), 1329f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_z24x8 = xa_format_c(32, xa_type_zs, 24, 0), 1339f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_z24s8 = xa_format_c(32, xa_type_zs, 24, 8), 1349f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1359f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom xa_format_yuv8 = xa_format_c(8, xa_type_yuv_component, 8, 0) 1369f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom}; 1379f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1389f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromstruct xa_tracker; 1399f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromstruct xa_surface; 1409f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1419f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromstruct xa_box { 1429f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom uint16_t x1, y1, x2, y2; 1439f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom}; 1449f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1459f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromextern void xa_tracker_version(int *major, int *minor, int *patch); 1469f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1479f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromextern struct xa_tracker *xa_tracker_create(int drm_fd); 1489f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1499f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromextern void xa_tracker_destroy(struct xa_tracker *xa); 1509f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1519a0c5b46344740dbc9ffa5cbf574a7812425237cThomas Hellstromextern int xa_format_check_supported(struct xa_tracker *xa, 1529a0c5b46344740dbc9ffa5cbf574a7812425237cThomas Hellstrom enum xa_formats xa_format, 1539a0c5b46344740dbc9ffa5cbf574a7812425237cThomas Hellstrom unsigned int flags); 1549a0c5b46344740dbc9ffa5cbf574a7812425237cThomas Hellstrom 1559f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromextern struct xa_surface *xa_surface_create(struct xa_tracker *xa, 1569f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom int width, 1579f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom int height, 1589f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom int depth, 1599f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom enum xa_surface_type stype, 1609f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom enum xa_formats pform, 1619f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom unsigned int flags); 1629f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1635f20fae40d3034de4dc8fdb3678000f7b17c6d75Thomas Hellstromenum xa_formats xa_surface_format(const struct xa_surface *srf); 1649f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1659f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromextern void xa_surface_destroy(struct xa_surface *srf); 1669f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1679f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromextern int xa_surface_redefine(struct xa_surface *srf, 1689f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom int width, 1699f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom int height, 1709f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom int depth, 1719f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom enum xa_surface_type stype, 1729f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom enum xa_formats rgb_format, 1739a0c5b46344740dbc9ffa5cbf574a7812425237cThomas Hellstrom unsigned int new_flags, 1749a0c5b46344740dbc9ffa5cbf574a7812425237cThomas Hellstrom int copy_contents); 1759f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1769f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstromextern int xa_surface_handle(struct xa_surface *srf, 1779f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom uint32_t * handle, unsigned int *byte_stride); 1789f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom 1799f2f5b3d7fd70663b98da5d302fcdfd5bc93db05Thomas Hellstrom#endif 180