e8f67a12276ee53ef94530a55f2d6571b77998af
[mesa.git] / src / gallium / state_trackers / xa / xa_priv.h
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 *********************************************************
25 * Authors:
26 * Zack Rusin <zackr-at-vmware-dot-com>
27 * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
28 */
29
30 #ifndef _XA_PRIV_H_
31 #define _XA_PRIV_H_
32
33 #include "xa_tracker.h"
34 #include "xa_context.h"
35 #include "xa_composite.h"
36
37 #include "pipe/p_screen.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_state.h"
40
41 #define XA_VB_SIZE (100 * 4 * 3 * 4)
42 #define XA_LAST_SURFACE_TYPE (xa_type_yuv_component + 1)
43 #define XA_MAX_SAMPLERS 3
44
45 struct xa_fence {
46 struct pipe_fence_handle *pipe_fence;
47 struct xa_tracker *xa;
48 };
49
50 struct xa_format_descriptor {
51 enum pipe_format format;
52 enum xa_formats xa_format;
53 };
54
55 struct xa_surface {
56 struct pipe_resource template;
57 struct xa_tracker *xa;
58 struct pipe_resource *tex;
59 struct pipe_surface *srf;
60 struct pipe_sampler_view *view;
61 unsigned int flags;
62 struct xa_format_descriptor fdesc;
63 struct pipe_transfer *transfer;
64 struct pipe_context *mapping_pipe;
65 };
66
67 struct xa_tracker {
68 enum xa_formats *supported_formats;
69 unsigned int format_map[XA_LAST_SURFACE_TYPE][2];
70 int d_depth_bits_last;
71 int ds_depth_bits_last;
72 struct pipe_screen *screen;
73 struct xa_context *default_ctx;
74 };
75
76 struct xa_context {
77 struct xa_tracker *xa;
78 struct pipe_context *pipe;
79
80 struct cso_context *cso;
81 struct xa_shaders *shaders;
82
83 struct pipe_resource *vs_const_buffer;
84 struct pipe_resource *fs_const_buffer;
85
86 float buffer[XA_VB_SIZE];
87 unsigned int buffer_size;
88 struct pipe_vertex_element velems[3];
89
90 /* number of attributes per vertex for the current
91 * draw operation */
92 unsigned int attrs_per_vertex;
93
94 unsigned int fb_width;
95 unsigned int fb_height;
96
97 struct pipe_fence_handle *last_fence;
98 struct xa_surface *src;
99 struct xa_surface *dst;
100 int simple_copy;
101
102 int has_solid_color;
103 float solid_color[4];
104
105 unsigned int num_bound_samplers;
106 struct pipe_sampler_view *bound_sampler_views[XA_MAX_SAMPLERS];
107 const struct xa_composite *comp;
108 };
109
110 enum xa_vs_traits {
111 VS_COMPOSITE = 1 << 0,
112 VS_MASK = 1 << 1,
113 VS_SOLID_FILL = 1 << 2,
114 VS_LINGRAD_FILL = 1 << 3,
115 VS_RADGRAD_FILL = 1 << 4,
116 VS_YUV = 1 << 5,
117
118 VS_FILL = (VS_SOLID_FILL | VS_LINGRAD_FILL | VS_RADGRAD_FILL)
119 };
120
121 enum xa_fs_traits {
122 FS_COMPOSITE = 1 << 0,
123 FS_MASK = 1 << 1,
124 FS_SOLID_FILL = 1 << 2,
125 FS_LINGRAD_FILL = 1 << 3,
126 FS_RADGRAD_FILL = 1 << 4,
127 FS_CA_FULL = 1 << 5, /* src.rgba * mask.rgba */
128 FS_CA_SRCALPHA = 1 << 6, /* src.aaaa * mask.rgba */
129 FS_YUV = 1 << 7,
130 FS_SRC_REPEAT_NONE = 1 << 8,
131 FS_MASK_REPEAT_NONE = 1 << 9,
132 FS_SRC_SWIZZLE_RGB = 1 << 10,
133 FS_MASK_SWIZZLE_RGB = 1 << 11,
134 FS_SRC_SET_ALPHA = 1 << 12,
135 FS_MASK_SET_ALPHA = 1 << 13,
136 FS_SRC_LUMINANCE = 1 << 14,
137 FS_MASK_LUMINANCE = 1 << 15,
138 FS_DST_LUMINANCE = 1 << 16,
139
140 FS_FILL = (FS_SOLID_FILL | FS_LINGRAD_FILL | FS_RADGRAD_FILL),
141 FS_COMPONENT_ALPHA = (FS_CA_FULL | FS_CA_SRCALPHA)
142 };
143
144 struct xa_shader {
145 void *fs;
146 void *vs;
147 };
148
149 struct xa_shaders;
150
151 /*
152 * Inline utilities
153 */
154
155 static INLINE int
156 xa_min(int a, int b)
157 {
158 return ((a <= b) ? a : b);
159 }
160
161 static INLINE void
162 xa_pixel_to_float4(uint32_t pixel, float *color)
163 {
164 uint32_t r, g, b, a;
165
166 a = (pixel >> 24) & 0xff;
167 r = (pixel >> 16) & 0xff;
168 g = (pixel >> 8) & 0xff;
169 b = (pixel >> 0) & 0xff;
170 color[0] = ((float)r) / 255.;
171 color[1] = ((float)g) / 255.;
172 color[2] = ((float)b) / 255.;
173 color[3] = ((float)a) / 255.;
174 }
175
176 static INLINE void
177 xa_pixel_to_float4_a8(uint32_t pixel, float *color)
178 {
179 uint32_t a;
180
181 a = (pixel >> 24) & 0xff;
182 color[0] = ((float)a) / 255.;
183 color[1] = ((float)a) / 255.;
184 color[2] = ((float)a) / 255.;
185 color[3] = ((float)a) / 255.;
186 }
187
188 /*
189 * xa_tgsi.c
190 */
191
192 extern struct xa_shaders *xa_shaders_create(struct xa_context *);
193
194 void xa_shaders_destroy(struct xa_shaders *shaders);
195
196 struct xa_shader xa_shaders_get(struct xa_shaders *shaders,
197 unsigned vs_traits, unsigned fs_traits);
198
199 /*
200 * xa_context.c
201 */
202 extern int
203 xa_surface_psurf_create(struct xa_context *ctx, struct xa_surface *dst);
204
205 extern void
206 xa_surface_psurf_destroy(struct xa_surface *dst);
207
208 /*
209 * xa_renderer.c
210 */
211 void renderer_set_constants(struct xa_context *r,
212 int shader_type, const float *params,
213 int param_bytes);
214
215 void renderer_draw_yuv(struct xa_context *r,
216 float src_x,
217 float src_y,
218 float src_w,
219 float src_h,
220 int dst_x,
221 int dst_y, int dst_w, int dst_h,
222 struct xa_surface *srf[]);
223
224 void renderer_bind_destination(struct xa_context *r,
225 struct pipe_surface *surface, int width,
226 int height);
227
228 void renderer_init_state(struct xa_context *r);
229 void renderer_copy_prepare(struct xa_context *r,
230 struct pipe_surface *dst_surface,
231 struct pipe_resource *src_texture);
232 void renderer_copy(struct xa_context *r, int dx,
233 int dy,
234 int sx,
235 int sy,
236 int width, int height, float src_width, float src_height);
237
238 void renderer_draw_flush(struct xa_context *r);
239
240 void renderer_begin_solid(struct xa_context *r);
241 void renderer_solid(struct xa_context *r,
242 int x0, int y0, int x1, int y1, float *color);
243 void
244 renderer_begin_textures(struct xa_context *r);
245
246 void
247 renderer_texture(struct xa_context *r,
248 int *pos,
249 int width, int height,
250 const float *src_matrix,
251 const float *mask_matrix);
252
253 #endif