summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/xa/xa_priv.h
blob: 13a0e86f66ded42f443cc3521f7a9044f5dd2d5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**********************************************************
 * Copyright 2009-2011 VMware, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *********************************************************
 * Authors:
 * Zack Rusin <zackr-at-vmware-dot-com>
 * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
 */

#ifndef _XA_PRIV_H_
#define _XA_PRIV_H_

#include "xa_tracker.h"
#include "xa_context.h"
#include "xa_composite.h"

#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"

#include "util/u_math.h"

#if defined(__GNUC__)
#define XA_EXPORT __attribute__ ((visibility("default")))
#else
#define XA_EXPORT
#endif

#define XA_VB_SIZE (100 * 4 * 3 * 4)
#define XA_LAST_SURFACE_TYPE (xa_type_yuv_component + 1)
#define XA_MAX_SAMPLERS 3

struct xa_fence {
    struct pipe_fence_handle *pipe_fence;
    struct xa_tracker *xa;
};

struct xa_format_descriptor {
    enum pipe_format format;
    enum xa_formats xa_format;
};

struct xa_surface {
    int refcount;
    struct pipe_resource template;
    struct xa_tracker *xa;
    struct pipe_resource *tex;
    struct pipe_transfer *transfer;
    unsigned int flags;
    struct xa_format_descriptor fdesc;
    struct pipe_context *mapping_pipe;
};

struct xa_tracker {
    enum xa_formats *supported_formats;
    unsigned int format_map[XA_LAST_SURFACE_TYPE][2];
    int d_depth_bits_last;
    int ds_depth_bits_last;
    struct pipe_loader_device *dev;
    struct pipe_screen *screen;
    struct xa_context *default_ctx;
};

struct xa_context {
    struct xa_tracker *xa;
    struct pipe_context *pipe;

    struct cso_context *cso;
    struct xa_shaders *shaders;

    struct pipe_resource *vs_const_buffer;
    struct pipe_resource *fs_const_buffer;

    float buffer[XA_VB_SIZE];
    unsigned int buffer_size;
    struct pipe_vertex_element velems[3];

    /* number of attributes per vertex for the current
     * draw operation */
    unsigned int attrs_per_vertex;

    unsigned int fb_width;
    unsigned int fb_height;

    struct pipe_fence_handle *last_fence;
    struct xa_surface *src;
    struct xa_surface *dst;
    struct pipe_surface *srf;

    /* destination scissor state.. we scissor out untouched parts
     * of the dst for the benefit of tilers:
     */
    struct pipe_scissor_state scissor;
    int scissor_valid;

    int simple_copy;

    int has_solid_color;
    float solid_color[4];

    unsigned int num_bound_samplers;
    struct pipe_sampler_view *bound_sampler_views[XA_MAX_SAMPLERS];
    const struct xa_composite *comp;
};

static inline void
xa_scissor_reset(struct xa_context *ctx)
{
    ctx->scissor.maxx = 0;
    ctx->scissor.maxy = 0;
    ctx->scissor.minx = ~0;
    ctx->scissor.miny = ~0;
    ctx->scissor_valid = FALSE;
}

static inline void
xa_scissor_update(struct xa_context *ctx, unsigned minx, unsigned miny,
		unsigned maxx, unsigned maxy)
{
    ctx->scissor.maxx = MAX2(ctx->scissor.maxx, maxx);
    ctx->scissor.maxy = MAX2(ctx->scissor.maxy, maxy);
    ctx->scissor.minx = MIN2(ctx->scissor.minx, minx);
    ctx->scissor.miny = MIN2(ctx->scissor.miny, miny);
    ctx->scissor_valid = TRUE;
}

enum xa_vs_traits {
    VS_COMPOSITE = 1 << 0,
    VS_MASK = 1 << 1,
    VS_SOLID_FILL = 1 << 2,
    VS_LINGRAD_FILL = 1 << 3,
    VS_RADGRAD_FILL = 1 << 4,
    VS_YUV = 1 << 5,

    VS_FILL = (VS_SOLID_FILL | VS_LINGRAD_FILL | VS_RADGRAD_FILL)
};

enum xa_fs_traits {
    FS_COMPOSITE = 1 << 0,
    FS_MASK = 1 << 1,
    FS_SOLID_FILL = 1 << 2,
    FS_LINGRAD_FILL = 1 << 3,
    FS_RADGRAD_FILL = 1 << 4,
    FS_CA_FULL = 1 << 5,	/* src.rgba * mask.rgba */
    FS_CA_SRCALPHA = 1 << 6,	/* src.aaaa * mask.rgba */
    FS_YUV = 1 << 7,
    FS_SRC_REPEAT_NONE = 1 << 8,
    FS_MASK_REPEAT_NONE = 1 << 9,
    FS_SRC_SWIZZLE_RGB = 1 << 10,
    FS_MASK_SWIZZLE_RGB = 1 << 11,
    FS_SRC_SET_ALPHA = 1 << 12,
    FS_MASK_SET_ALPHA = 1 << 13,
    FS_SRC_LUMINANCE = 1 << 14,
    FS_MASK_LUMINANCE = 1 << 15,
    FS_DST_LUMINANCE = 1 << 16,

    FS_FILL = (FS_SOLID_FILL | FS_LINGRAD_FILL | FS_RADGRAD_FILL),
    FS_COMPONENT_ALPHA = (FS_CA_FULL | FS_CA_SRCALPHA)
};

struct xa_shader {
    void *fs;
    void *vs;
};

struct xa_shaders;

/*
 * Inline utilities
 */

static inline int
xa_min(int a, int b)
{
    return ((a <= b) ? a : b);
}

static inline void
xa_pixel_to_float4(uint32_t pixel, float *color)
{
    uint32_t	    r, g, b, a;

    a = (pixel >> 24) & 0xff;
    r = (pixel >> 16) & 0xff;
    g = (pixel >>  8) & 0xff;
    b = (pixel >>  0) & 0xff;
    color[0] = ((float)r) / 255.;
    color[1] = ((float)g) / 255.;
    color[2] = ((float)b) / 255.;
    color[3] = ((float)a) / 255.;
}

static inline void
xa_pixel_to_float4_a8(uint32_t pixel, float *color)
{
    uint32_t a;

    a = (pixel >> 24) & 0xff;
    color[0] = ((float)a) / 255.;
    color[1] = ((float)a) / 255.;
    color[2] = ((float)a) / 255.;
    color[3] = ((float)a) / 255.;
}

/*
 * xa_tgsi.c
 */

extern struct xa_shaders *xa_shaders_create(struct xa_context *);

void xa_shaders_destroy(struct xa_shaders *shaders);

struct xa_shader xa_shaders_get(struct xa_shaders *shaders,
				unsigned vs_traits, unsigned fs_traits);

/*
 * xa_context.c
 */
extern void
xa_context_flush(struct xa_context *ctx);

extern int
xa_ctx_srf_create(struct xa_context *ctx, struct xa_surface *dst);

extern void
xa_ctx_srf_destroy(struct xa_context *ctx);

extern void
xa_ctx_sampler_views_destroy(struct xa_context *ctx);

/*
 * xa_renderer.c
 */
void renderer_set_constants(struct xa_context *r,
			    int shader_type, const float *params,
			    int param_bytes);

void renderer_draw_yuv(struct xa_context *r,
		       float src_x,
		       float src_y,
		       float src_w,
		       float src_h,
		       int dst_x,
		       int dst_y, int dst_w, int dst_h,
		       struct xa_surface *srf[]);

void renderer_bind_destination(struct xa_context *r,
			       struct pipe_surface *surface);

void renderer_init_state(struct xa_context *r);
void renderer_copy_prepare(struct xa_context *r,
			   struct pipe_surface *dst_surface,
			   struct pipe_resource *src_texture,
			   const enum xa_formats src_xa_format,
			   const enum xa_formats dst_xa_format);

void renderer_copy(struct xa_context *r, int dx,
		   int dy,
		   int sx,
		   int sy,
		   int width, int height, float src_width, float src_height);

void renderer_draw_flush(struct xa_context *r);

void renderer_begin_solid(struct xa_context *r);
void renderer_solid(struct xa_context *r,
		    int x0, int y0, int x1, int y1, float *color);
void
renderer_begin_textures(struct xa_context *r);

void
renderer_texture(struct xa_context *r,
		 int *pos,
		 int width, int height,
		 const float *src_matrix,
		 const float *mask_matrix);

#endif