• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**********************************************************
2 * Copyright 2009-2011 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * 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 @XA_MAJOR@
40#define XA_TRACKER_VERSION_MINOR @XA_MINOR@
41#define XA_TRACKER_VERSION_PATCH @XA_PATCH@
42
43#define XA_FLAG_SHARED         (1 << 0)
44#define XA_FLAG_RENDER_TARGET  (1 << 1)
45#define XA_FLAG_SCANOUT        (1 << 2)
46
47#define XA_MAP_READ                     (1 << 0)
48#define XA_MAP_WRITE                    (1 << 1)
49#define XA_MAP_MAP_DIRECTLY             (1 << 2)
50#define XA_MAP_UNSYNCHRONIZED           (1 << 3)
51#define XA_MAP_DONTBLOCK                (1 << 4)
52#define XA_MAP_DISCARD_WHOLE_RESOURCE   (1 << 5)
53
54#define XA_ERR_NONE            0
55#define XA_ERR_NORES           1
56#define XA_ERR_INVAL           2
57#define XA_ERR_BUSY            3
58
59enum xa_surface_type {
60    xa_type_other,
61    xa_type_a,
62    xa_type_argb,
63    xa_type_abgr,
64    xa_type_bgra,
65    xa_type_z,
66    xa_type_zs,
67    xa_type_sz,
68    xa_type_yuv_component
69};
70
71/*
72 * Note that these formats should not be assumed to be binary compatible with
73 * pixman formats, but with the below macros and a format type map,
74 * conversion should be simple. Macros for now. We might replace with
75 * inline functions.
76 */
77
78#define xa_format(bpp,type,a,r,g,b)	(((bpp) << 24) |  \
79					 ((type) << 16) | \
80					 ((a) << 12) |	  \
81					 ((r) << 8) |	  \
82					 ((g) << 4) |	  \
83					 ((b)))
84/*
85 *  Non-RGBA one- and two component formats.
86 */
87
88#define xa_format_c(bpp,type,c1,c2) (((bpp) << 24) |	  \
89				     ((type) << 16) |	  \
90				     ((c1) << 8) |	  \
91				     ((c2)))
92#define xa_format_bpp(f)	(((f) >> 24)       )
93#define xa_format_type(f)	(((f) >> 16) & 0xff)
94#define xa_format_a(f)	(((f) >> 12) & 0x0f)
95#define xa_format_r(f)	(((f) >>  8) & 0x0f)
96#define xa_format_g(f)	(((f) >>  4) & 0x0f)
97#define xa_format_b(f)	(((f)      ) & 0x0f)
98#define xa_format_rgb(f)	(((f)      ) & 0xfff)
99#define xa_format_c1(f)          (((f) >> 8 ) & 0xff)
100#define xa_format_c2(f)          (((f)      ) & 0xff)
101#define xa_format_argb_depth(f)	(xa_format_a(f) +	\
102				 xa_format_r(f) +	\
103				 xa_format_g(f) +	\
104				 xa_format_b(f))
105#define xa_format_c_depth(f)    (xa_format_c1(f) + \
106				 xa_format_c2(f))
107
108static inline int
109xa_format_type_is_color(uint32_t xa_format)
110{
111    return (xa_format_type(xa_format) < xa_type_z);
112}
113
114static inline unsigned int
115xa_format_depth(uint32_t xa_format)
116{
117    return ((xa_format_type_is_color(xa_format)) ?
118	    xa_format_argb_depth(xa_format) : xa_format_c_depth(xa_format));
119}
120
121enum xa_formats {
122    xa_format_unknown = 0,
123    xa_format_a8 = xa_format(8, xa_type_a, 8, 0, 0, 0),
124
125    xa_format_a8r8g8b8 = xa_format(32, xa_type_argb, 8, 8, 8, 8),
126    xa_format_x8r8g8b8 = xa_format(32, xa_type_argb, 0, 8, 8, 8),
127    xa_format_r5g6b5 = xa_format(16, xa_type_argb, 0, 5, 6, 5),
128    xa_format_x1r5g5b5 = xa_format(16, xa_type_argb, 0, 5, 5, 5),
129
130    xa_format_z16 = xa_format_c(16, xa_type_z, 16, 0),
131    xa_format_z32 = xa_format_c(32, xa_type_z, 32, 0),
132    xa_format_z24 = xa_format_c(32, xa_type_z, 24, 0),
133
134    xa_format_x8z24 = xa_format_c(32, xa_type_sz, 24, 0),
135    xa_format_s8z24 = xa_format_c(32, xa_type_sz, 24, 8),
136    xa_format_z24x8 = xa_format_c(32, xa_type_zs, 24, 0),
137    xa_format_z24s8 = xa_format_c(32, xa_type_zs, 24, 8),
138
139    xa_format_yuv8 = xa_format_c(8, xa_type_yuv_component, 8, 0)
140};
141
142struct xa_tracker;
143struct xa_surface;
144
145struct xa_box {
146    uint16_t x1, y1, x2, y2;
147};
148
149enum xa_handle_type {
150    xa_handle_type_shared,
151    xa_handle_type_kms,
152    xa_handle_type_fd,
153};
154
155extern void xa_tracker_version(int *major, int *minor, int *patch);
156
157extern struct xa_tracker *xa_tracker_create(int drm_fd);
158
159extern void xa_tracker_destroy(struct xa_tracker *xa);
160
161extern int xa_format_check_supported(struct xa_tracker *xa,
162				     enum xa_formats xa_format,
163				     unsigned int flags);
164
165extern struct xa_surface *xa_surface_create(struct xa_tracker *xa,
166					    int width,
167					    int height,
168					    int depth,
169					    enum xa_surface_type stype,
170					    enum xa_formats pform,
171					    unsigned int flags);
172
173extern struct xa_surface * xa_surface_from_handle(struct xa_tracker *xa,
174					    int width,
175					    int height,
176					    int depth,
177					    enum xa_surface_type stype,
178					    enum xa_formats pform,
179					    unsigned int flags,
180					    uint32_t handle, uint32_t stride);
181extern struct xa_surface *
182xa_surface_from_handle2(struct xa_tracker *xa,
183                        int width,
184                        int height,
185                        int depth,
186                        enum xa_surface_type stype,
187                        enum xa_formats xa_format,
188                        unsigned int flags,
189                        enum xa_handle_type type,
190                        uint32_t handle,
191                        uint32_t stride);
192
193enum xa_formats xa_surface_format(const struct xa_surface *srf);
194
195extern struct xa_surface *xa_surface_ref(struct xa_surface *srf);
196extern void xa_surface_unref(struct xa_surface *srf);
197
198extern int xa_surface_redefine(struct xa_surface *srf,
199			       int width,
200			       int height,
201			       int depth,
202			       enum xa_surface_type stype,
203			       enum xa_formats rgb_format,
204			       unsigned int new_flags,
205			       int copy_contents);
206
207extern int xa_surface_handle(struct xa_surface *srf,
208			     enum xa_handle_type type,
209			     uint32_t * handle,
210			     unsigned int *byte_stride);
211
212#endif
213