1 /**********************************************************
2 * Copyright 2009-2011 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 *********************************************************
26 * Zack Rusin <zackr-at-vmware-dot-com>
27 * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
33 #include "xa_tracker.h"
34 #include "xa_context.h"
35 #include "xa_composite.h"
37 #include "pipe/p_screen.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_state.h"
41 #include "util/u_math.h"
44 #define XA_EXPORT __attribute__ ((visibility("default")))
49 #define XA_VB_SIZE (100 * 4 * 3 * 4)
50 #define XA_LAST_SURFACE_TYPE (xa_type_yuv_component + 1)
51 #define XA_MAX_SAMPLERS 3
54 struct pipe_fence_handle
*pipe_fence
;
55 struct xa_tracker
*xa
;
58 struct xa_format_descriptor
{
59 enum pipe_format format
;
60 enum xa_formats xa_format
;
65 struct pipe_resource
template;
66 struct xa_tracker
*xa
;
67 struct pipe_resource
*tex
;
68 struct pipe_transfer
*transfer
;
70 struct xa_format_descriptor fdesc
;
71 struct pipe_context
*mapping_pipe
;
75 enum xa_formats
*supported_formats
;
76 unsigned int format_map
[XA_LAST_SURFACE_TYPE
][2];
77 int d_depth_bits_last
;
78 int ds_depth_bits_last
;
79 struct pipe_loader_device
*dev
;
80 struct pipe_screen
*screen
;
81 struct xa_context
*default_ctx
;
85 struct xa_tracker
*xa
;
86 struct pipe_context
*pipe
;
88 struct cso_context
*cso
;
89 struct xa_shaders
*shaders
;
91 struct pipe_resource
*vs_const_buffer
;
92 struct pipe_resource
*fs_const_buffer
;
94 float buffer
[XA_VB_SIZE
];
95 unsigned int buffer_size
;
96 struct pipe_vertex_element velems
[3];
98 /* number of attributes per vertex for the current
100 unsigned int attrs_per_vertex
;
102 unsigned int fb_width
;
103 unsigned int fb_height
;
105 struct pipe_fence_handle
*last_fence
;
106 struct xa_surface
*src
;
107 struct xa_surface
*dst
;
108 struct pipe_surface
*srf
;
110 /* destination scissor state.. we scissor out untouched parts
111 * of the dst for the benefit of tilers:
113 struct pipe_scissor_state scissor
;
119 float solid_color
[4];
121 unsigned int num_bound_samplers
;
122 struct pipe_sampler_view
*bound_sampler_views
[XA_MAX_SAMPLERS
];
123 const struct xa_composite
*comp
;
127 xa_scissor_reset(struct xa_context
*ctx
)
129 ctx
->scissor
.maxx
= 0;
130 ctx
->scissor
.maxy
= 0;
131 ctx
->scissor
.minx
= ~0;
132 ctx
->scissor
.miny
= ~0;
133 ctx
->scissor_valid
= FALSE
;
137 xa_scissor_update(struct xa_context
*ctx
, unsigned minx
, unsigned miny
,
138 unsigned maxx
, unsigned maxy
)
140 ctx
->scissor
.maxx
= MAX2(ctx
->scissor
.maxx
, maxx
);
141 ctx
->scissor
.maxy
= MAX2(ctx
->scissor
.maxy
, maxy
);
142 ctx
->scissor
.minx
= MIN2(ctx
->scissor
.minx
, minx
);
143 ctx
->scissor
.miny
= MIN2(ctx
->scissor
.miny
, miny
);
144 ctx
->scissor_valid
= TRUE
;
148 VS_COMPOSITE
= 1 << 0,
150 VS_SOLID_FILL
= 1 << 2,
151 VS_LINGRAD_FILL
= 1 << 3,
152 VS_RADGRAD_FILL
= 1 << 4,
155 VS_FILL
= (VS_SOLID_FILL
| VS_LINGRAD_FILL
| VS_RADGRAD_FILL
)
159 FS_COMPOSITE
= 1 << 0,
161 FS_SOLID_FILL
= 1 << 2,
162 FS_LINGRAD_FILL
= 1 << 3,
163 FS_RADGRAD_FILL
= 1 << 4,
164 FS_CA_FULL
= 1 << 5, /* src.rgba * mask.rgba */
165 FS_CA_SRCALPHA
= 1 << 6, /* src.aaaa * mask.rgba */
167 FS_SRC_REPEAT_NONE
= 1 << 8,
168 FS_MASK_REPEAT_NONE
= 1 << 9,
169 FS_SRC_SWIZZLE_RGB
= 1 << 10,
170 FS_MASK_SWIZZLE_RGB
= 1 << 11,
171 FS_SRC_SET_ALPHA
= 1 << 12,
172 FS_MASK_SET_ALPHA
= 1 << 13,
173 FS_SRC_LUMINANCE
= 1 << 14,
174 FS_MASK_LUMINANCE
= 1 << 15,
175 FS_DST_LUMINANCE
= 1 << 16,
177 FS_FILL
= (FS_SOLID_FILL
| FS_LINGRAD_FILL
| FS_RADGRAD_FILL
),
178 FS_COMPONENT_ALPHA
= (FS_CA_FULL
| FS_CA_SRCALPHA
)
195 return ((a
<= b
) ? a
: b
);
199 xa_pixel_to_float4(uint32_t pixel
, float *color
)
203 a
= (pixel
>> 24) & 0xff;
204 r
= (pixel
>> 16) & 0xff;
205 g
= (pixel
>> 8) & 0xff;
206 b
= (pixel
>> 0) & 0xff;
207 color
[0] = ((float)r
) / 255.;
208 color
[1] = ((float)g
) / 255.;
209 color
[2] = ((float)b
) / 255.;
210 color
[3] = ((float)a
) / 255.;
214 xa_pixel_to_float4_a8(uint32_t pixel
, float *color
)
218 a
= (pixel
>> 24) & 0xff;
219 color
[0] = ((float)a
) / 255.;
220 color
[1] = ((float)a
) / 255.;
221 color
[2] = ((float)a
) / 255.;
222 color
[3] = ((float)a
) / 255.;
229 extern struct xa_shaders
*xa_shaders_create(struct xa_context
*);
231 void xa_shaders_destroy(struct xa_shaders
*shaders
);
233 struct xa_shader
xa_shaders_get(struct xa_shaders
*shaders
,
234 unsigned vs_traits
, unsigned fs_traits
);
240 xa_context_flush(struct xa_context
*ctx
);
243 xa_ctx_srf_create(struct xa_context
*ctx
, struct xa_surface
*dst
);
246 xa_ctx_srf_destroy(struct xa_context
*ctx
);
249 xa_ctx_sampler_views_destroy(struct xa_context
*ctx
);
254 void renderer_set_constants(struct xa_context
*r
,
255 int shader_type
, const float *params
,
258 void renderer_draw_yuv(struct xa_context
*r
,
264 int dst_y
, int dst_w
, int dst_h
,
265 struct xa_surface
*srf
[]);
267 void renderer_bind_destination(struct xa_context
*r
,
268 struct pipe_surface
*surface
);
270 void renderer_init_state(struct xa_context
*r
);
271 void renderer_copy_prepare(struct xa_context
*r
,
272 struct pipe_surface
*dst_surface
,
273 struct pipe_resource
*src_texture
,
274 const enum xa_formats src_xa_format
,
275 const enum xa_formats dst_xa_format
);
277 void renderer_copy(struct xa_context
*r
, int dx
,
281 int width
, int height
, float src_width
, float src_height
);
283 void renderer_draw_flush(struct xa_context
*r
);
285 void renderer_begin_solid(struct xa_context
*r
);
286 void renderer_solid(struct xa_context
*r
,
287 int x0
, int y0
, int x1
, int y1
, float *color
);
289 renderer_begin_textures(struct xa_context
*r
);
292 renderer_texture(struct xa_context
*r
,
294 int width
, int height
,
295 const float *src_matrix
,
296 const float *mask_matrix
);