17ec681f3Smrg/********************************************************** 27ec681f3Smrg * Copyright 2009-2011 VMware, Inc. All rights reserved. 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person 57ec681f3Smrg * obtaining a copy of this software and associated documentation 67ec681f3Smrg * files (the "Software"), to deal in the Software without 77ec681f3Smrg * restriction, including without limitation the rights to use, copy, 87ec681f3Smrg * modify, merge, publish, distribute, sublicense, and/or sell copies 97ec681f3Smrg * of the Software, and to permit persons to whom the Software is 107ec681f3Smrg * furnished to do so, subject to the following conditions: 117ec681f3Smrg * 127ec681f3Smrg * The above copyright notice and this permission notice shall be 137ec681f3Smrg * included in all copies or substantial portions of the Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 167ec681f3Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 177ec681f3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 187ec681f3Smrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 197ec681f3Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 207ec681f3Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 217ec681f3Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 227ec681f3Smrg * SOFTWARE. 237ec681f3Smrg * 247ec681f3Smrg * The format encoding idea is partially borrowed from libpixman, but it is not 257ec681f3Smrg * considered a "substantial part of the software", so the pixman copyright 267ec681f3Smrg * is left out for simplicity, and acknowledgment is instead given in this way. 277ec681f3Smrg * 287ec681f3Smrg ********************************************************* 297ec681f3Smrg * Authors: 307ec681f3Smrg * Zack Rusin <zackr-at-vmware-dot-com> 317ec681f3Smrg * Thomas Hellstrom <thellstrom-at-vmware-dot-com> 327ec681f3Smrg */ 337ec681f3Smrg 347ec681f3Smrg#ifndef _XA_TRACKER_H_ 357ec681f3Smrg#define _XA_TRACKER_H_ 367ec681f3Smrg 377ec681f3Smrg#include <stdint.h> 387ec681f3Smrg 397ec681f3Smrg#define XA_TRACKER_VERSION_MAJOR @XA_MAJOR@ 407ec681f3Smrg#define XA_TRACKER_VERSION_MINOR @XA_MINOR@ 417ec681f3Smrg#define XA_TRACKER_VERSION_PATCH @XA_PATCH@ 427ec681f3Smrg 437ec681f3Smrg#define XA_FLAG_SHARED (1 << 0) 447ec681f3Smrg#define XA_FLAG_RENDER_TARGET (1 << 1) 457ec681f3Smrg#define XA_FLAG_SCANOUT (1 << 2) 467ec681f3Smrg 477ec681f3Smrg#define XA_MAP_READ (1 << 0) 487ec681f3Smrg#define XA_MAP_WRITE (1 << 1) 497ec681f3Smrg#define XA_MAP_MAP_DIRECTLY (1 << 2) 507ec681f3Smrg#define XA_MAP_UNSYNCHRONIZED (1 << 3) 517ec681f3Smrg#define XA_MAP_DONTBLOCK (1 << 4) 527ec681f3Smrg#define XA_MAP_DISCARD_WHOLE_RESOURCE (1 << 5) 537ec681f3Smrg 547ec681f3Smrg#define XA_ERR_NONE 0 557ec681f3Smrg#define XA_ERR_NORES 1 567ec681f3Smrg#define XA_ERR_INVAL 2 577ec681f3Smrg#define XA_ERR_BUSY 3 587ec681f3Smrg 597ec681f3Smrgenum xa_surface_type { 607ec681f3Smrg xa_type_other, 617ec681f3Smrg xa_type_a, 627ec681f3Smrg xa_type_argb, 637ec681f3Smrg xa_type_abgr, 647ec681f3Smrg xa_type_bgra, 657ec681f3Smrg xa_type_z, 667ec681f3Smrg xa_type_zs, 677ec681f3Smrg xa_type_sz, 687ec681f3Smrg xa_type_yuv_component 697ec681f3Smrg}; 707ec681f3Smrg 717ec681f3Smrg/* 727ec681f3Smrg * Note that these formats should not be assumed to be binary compatible with 737ec681f3Smrg * pixman formats, but with the below macros and a format type map, 747ec681f3Smrg * conversion should be simple. Macros for now. We might replace with 757ec681f3Smrg * inline functions. 767ec681f3Smrg */ 777ec681f3Smrg 787ec681f3Smrg#define xa_format(bpp,type,a,r,g,b) (((bpp) << 24) | \ 797ec681f3Smrg ((type) << 16) | \ 807ec681f3Smrg ((a) << 12) | \ 817ec681f3Smrg ((r) << 8) | \ 827ec681f3Smrg ((g) << 4) | \ 837ec681f3Smrg ((b))) 847ec681f3Smrg/* 857ec681f3Smrg * Non-RGBA one- and two component formats. 867ec681f3Smrg */ 877ec681f3Smrg 887ec681f3Smrg#define xa_format_c(bpp,type,c1,c2) (((bpp) << 24) | \ 897ec681f3Smrg ((type) << 16) | \ 907ec681f3Smrg ((c1) << 8) | \ 917ec681f3Smrg ((c2))) 927ec681f3Smrg#define xa_format_bpp(f) (((f) >> 24) ) 937ec681f3Smrg#define xa_format_type(f) (((f) >> 16) & 0xff) 947ec681f3Smrg#define xa_format_a(f) (((f) >> 12) & 0x0f) 957ec681f3Smrg#define xa_format_r(f) (((f) >> 8) & 0x0f) 967ec681f3Smrg#define xa_format_g(f) (((f) >> 4) & 0x0f) 977ec681f3Smrg#define xa_format_b(f) (((f) ) & 0x0f) 987ec681f3Smrg#define xa_format_rgb(f) (((f) ) & 0xfff) 997ec681f3Smrg#define xa_format_c1(f) (((f) >> 8 ) & 0xff) 1007ec681f3Smrg#define xa_format_c2(f) (((f) ) & 0xff) 1017ec681f3Smrg#define xa_format_argb_depth(f) (xa_format_a(f) + \ 1027ec681f3Smrg xa_format_r(f) + \ 1037ec681f3Smrg xa_format_g(f) + \ 1047ec681f3Smrg xa_format_b(f)) 1057ec681f3Smrg#define xa_format_c_depth(f) (xa_format_c1(f) + \ 1067ec681f3Smrg xa_format_c2(f)) 1077ec681f3Smrg 1087ec681f3Smrgstatic inline int 1097ec681f3Smrgxa_format_type_is_color(uint32_t xa_format) 1107ec681f3Smrg{ 1117ec681f3Smrg return (xa_format_type(xa_format) < xa_type_z); 1127ec681f3Smrg} 1137ec681f3Smrg 1147ec681f3Smrgstatic inline unsigned int 1157ec681f3Smrgxa_format_depth(uint32_t xa_format) 1167ec681f3Smrg{ 1177ec681f3Smrg return ((xa_format_type_is_color(xa_format)) ? 1187ec681f3Smrg xa_format_argb_depth(xa_format) : xa_format_c_depth(xa_format)); 1197ec681f3Smrg} 1207ec681f3Smrg 1217ec681f3Smrgenum xa_formats { 1227ec681f3Smrg xa_format_unknown = 0, 1237ec681f3Smrg xa_format_a8 = xa_format(8, xa_type_a, 8, 0, 0, 0), 1247ec681f3Smrg 1257ec681f3Smrg xa_format_a8r8g8b8 = xa_format(32, xa_type_argb, 8, 8, 8, 8), 1267ec681f3Smrg xa_format_x8r8g8b8 = xa_format(32, xa_type_argb, 0, 8, 8, 8), 1277ec681f3Smrg xa_format_r5g6b5 = xa_format(16, xa_type_argb, 0, 5, 6, 5), 1287ec681f3Smrg xa_format_x1r5g5b5 = xa_format(16, xa_type_argb, 0, 5, 5, 5), 1297ec681f3Smrg xa_format_a4r4g4b4 = xa_format(16, xa_type_argb, 4, 4, 4, 4), 1307ec681f3Smrg xa_format_a2b10g10r10 = xa_format(32, xa_type_abgr, 2, 10, 10, 10), 1317ec681f3Smrg xa_format_x2b10g10r10 = xa_format(32, xa_type_abgr, 0, 10, 10, 10), 1327ec681f3Smrg xa_format_b8g8r8a8 = xa_format(32, xa_type_bgra, 8, 8, 8, 8), 1337ec681f3Smrg xa_format_b8g8r8x8 = xa_format(32, xa_type_bgra, 0, 8, 8, 8), 1347ec681f3Smrg 1357ec681f3Smrg xa_format_z16 = xa_format_c(16, xa_type_z, 16, 0), 1367ec681f3Smrg xa_format_z32 = xa_format_c(32, xa_type_z, 32, 0), 1377ec681f3Smrg xa_format_z24 = xa_format_c(32, xa_type_z, 24, 0), 1387ec681f3Smrg 1397ec681f3Smrg xa_format_x8z24 = xa_format_c(32, xa_type_sz, 24, 0), 1407ec681f3Smrg xa_format_s8z24 = xa_format_c(32, xa_type_sz, 24, 8), 1417ec681f3Smrg xa_format_z24x8 = xa_format_c(32, xa_type_zs, 24, 0), 1427ec681f3Smrg xa_format_z24s8 = xa_format_c(32, xa_type_zs, 24, 8), 1437ec681f3Smrg 1447ec681f3Smrg xa_format_yuv8 = xa_format_c(8, xa_type_yuv_component, 8, 0) 1457ec681f3Smrg}; 1467ec681f3Smrg 1477ec681f3Smrgstruct xa_tracker; 1487ec681f3Smrgstruct xa_surface; 1497ec681f3Smrg 1507ec681f3Smrgstruct xa_box { 1517ec681f3Smrg uint16_t x1, y1, x2, y2; 1527ec681f3Smrg}; 1537ec681f3Smrg 1547ec681f3Smrgenum xa_handle_type { 1557ec681f3Smrg xa_handle_type_shared, 1567ec681f3Smrg xa_handle_type_kms, 1577ec681f3Smrg xa_handle_type_fd, 1587ec681f3Smrg}; 1597ec681f3Smrg 1607ec681f3Smrgextern void xa_tracker_version(int *major, int *minor, int *patch); 1617ec681f3Smrg 1627ec681f3Smrgextern struct xa_tracker *xa_tracker_create(int drm_fd); 1637ec681f3Smrg 1647ec681f3Smrgextern void xa_tracker_destroy(struct xa_tracker *xa); 1657ec681f3Smrg 1667ec681f3Smrgextern int xa_format_check_supported(struct xa_tracker *xa, 1677ec681f3Smrg enum xa_formats xa_format, 1687ec681f3Smrg unsigned int flags); 1697ec681f3Smrg 1707ec681f3Smrgextern struct xa_surface *xa_surface_create(struct xa_tracker *xa, 1717ec681f3Smrg int width, 1727ec681f3Smrg int height, 1737ec681f3Smrg int depth, 1747ec681f3Smrg enum xa_surface_type stype, 1757ec681f3Smrg enum xa_formats pform, 1767ec681f3Smrg unsigned int flags); 1777ec681f3Smrg 1787ec681f3Smrgextern struct xa_surface * xa_surface_from_handle(struct xa_tracker *xa, 1797ec681f3Smrg int width, 1807ec681f3Smrg int height, 1817ec681f3Smrg int depth, 1827ec681f3Smrg enum xa_surface_type stype, 1837ec681f3Smrg enum xa_formats pform, 1847ec681f3Smrg unsigned int flags, 1857ec681f3Smrg uint32_t handle, uint32_t stride); 1867ec681f3Smrgextern struct xa_surface * 1877ec681f3Smrgxa_surface_from_handle2(struct xa_tracker *xa, 1887ec681f3Smrg int width, 1897ec681f3Smrg int height, 1907ec681f3Smrg int depth, 1917ec681f3Smrg enum xa_surface_type stype, 1927ec681f3Smrg enum xa_formats xa_format, 1937ec681f3Smrg unsigned int flags, 1947ec681f3Smrg enum xa_handle_type type, 1957ec681f3Smrg uint32_t handle, 1967ec681f3Smrg uint32_t stride); 1977ec681f3Smrg 1987ec681f3Smrgenum xa_formats xa_surface_format(const struct xa_surface *srf); 1997ec681f3Smrg 2007ec681f3Smrgextern struct xa_surface *xa_surface_ref(struct xa_surface *srf); 2017ec681f3Smrgextern void xa_surface_unref(struct xa_surface *srf); 2027ec681f3Smrg 2037ec681f3Smrgextern int xa_surface_redefine(struct xa_surface *srf, 2047ec681f3Smrg int width, 2057ec681f3Smrg int height, 2067ec681f3Smrg int depth, 2077ec681f3Smrg enum xa_surface_type stype, 2087ec681f3Smrg enum xa_formats rgb_format, 2097ec681f3Smrg unsigned int new_flags, 2107ec681f3Smrg int copy_contents); 2117ec681f3Smrg 2127ec681f3Smrgextern int xa_surface_handle(struct xa_surface *srf, 2137ec681f3Smrg enum xa_handle_type type, 2147ec681f3Smrg uint32_t * handle, 2157ec681f3Smrg unsigned int *byte_stride); 2167ec681f3Smrg 2177ec681f3Smrg#endif 218