xa_priv.h revision 642951fbcaa56a975422f7caddf6620f20d47721
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
36#include "pipe/p_screen.h"
37#include "pipe/p_context.h"
38#include "pipe/p_state.h"
39
40#define XA_VB_SIZE (100 * 4 * 3 * 4)
41#define XA_LAST_SURFACE_TYPE (xa_type_yuv_component + 1)
42
43struct xa_fence {
44    struct pipe_fence_handle *pipe_fence;
45    struct xa_tracker *xa;
46};
47
48struct xa_format_descriptor {
49    enum pipe_format format;
50    enum xa_formats xa_format;
51};
52
53struct xa_surface {
54    struct pipe_resource template;
55    struct xa_tracker *xa;
56    struct pipe_resource *tex;
57    struct pipe_surface *srf;
58    struct pipe_sampler_view *view;
59    unsigned int flags;
60    struct xa_format_descriptor fdesc;
61    struct pipe_transfer *transfer;
62    struct pipe_context *mapping_pipe;
63};
64
65struct xa_tracker {
66    enum xa_formats *supported_formats;
67    unsigned int format_map[XA_LAST_SURFACE_TYPE][2];
68    int d_depth_bits_last;
69    int ds_depth_bits_last;
70    struct pipe_screen *screen;
71    struct xa_context *default_ctx;
72};
73
74struct xa_context {
75    struct xa_tracker *xa;
76    struct pipe_context *pipe;
77
78    struct cso_context *cso;
79    struct xa_shaders *shaders;
80
81    struct pipe_resource *vs_const_buffer;
82    struct pipe_resource *fs_const_buffer;
83
84    float buffer[XA_VB_SIZE];
85    unsigned int buffer_size;
86    struct pipe_vertex_element velems[3];
87
88    /* number of attributes per vertex for the current
89     * draw operation */
90    unsigned int attrs_per_vertex;
91
92    unsigned int fb_width;
93    unsigned int fb_height;
94
95    struct pipe_fence_handle *last_fence;
96    struct xa_surface *src;
97    struct xa_surface *dst;
98    int simple_copy;
99};
100
101enum xa_vs_traits {
102    VS_COMPOSITE = 1 << 0,
103    VS_MASK = 1 << 1,
104    VS_SOLID_FILL = 1 << 2,
105    VS_LINGRAD_FILL = 1 << 3,
106    VS_RADGRAD_FILL = 1 << 4,
107    VS_YUV = 1 << 5,
108
109    VS_FILL = (VS_SOLID_FILL | VS_LINGRAD_FILL | VS_RADGRAD_FILL)
110};
111
112enum xa_fs_traits {
113    FS_COMPOSITE = 1 << 0,
114    FS_MASK = 1 << 1,
115    FS_SOLID_FILL = 1 << 2,
116    FS_LINGRAD_FILL = 1 << 3,
117    FS_RADGRAD_FILL = 1 << 4,
118    FS_CA_FULL = 1 << 5,	/* src.rgba * mask.rgba */
119    FS_CA_SRCALPHA = 1 << 6,	/* src.aaaa * mask.rgba */
120    FS_YUV = 1 << 7,
121    FS_SRC_REPEAT_NONE = 1 << 8,
122    FS_MASK_REPEAT_NONE = 1 << 9,
123    FS_SRC_SWIZZLE_RGB = 1 << 10,
124    FS_MASK_SWIZZLE_RGB = 1 << 11,
125    FS_SRC_SET_ALPHA = 1 << 12,
126    FS_MASK_SET_ALPHA = 1 << 13,
127    FS_SRC_LUMINANCE = 1 << 14,
128    FS_MASK_LUMINANCE = 1 << 15,
129
130    FS_FILL = (FS_SOLID_FILL | FS_LINGRAD_FILL | FS_RADGRAD_FILL),
131    FS_COMPONENT_ALPHA = (FS_CA_FULL | FS_CA_SRCALPHA)
132};
133
134struct xa_shader {
135    void *fs;
136    void *vs;
137};
138
139static inline int
140xa_min(int a, int b)
141{
142    return ((a <= b) ? a : b);
143}
144
145struct xa_shaders;
146
147/*
148 * xa_tgsi.c
149 */
150
151extern struct xa_shaders *xa_shaders_create(struct xa_context *);
152
153void xa_shaders_destroy(struct xa_shaders *shaders);
154
155struct xa_shader xa_shaders_get(struct xa_shaders *shaders,
156				unsigned vs_traits, unsigned fs_traits);
157
158/*
159 * xa_renderer.c
160 */
161void renderer_set_constants(struct xa_context *r,
162			    int shader_type, const float *params,
163			    int param_bytes);
164
165void renderer_draw_yuv(struct xa_context *r,
166		       float src_x,
167		       float src_y,
168		       float src_w,
169		       float src_h,
170		       int dst_x,
171		       int dst_y, int dst_w, int dst_h,
172		       struct xa_surface *srf[]);
173
174void renderer_bind_destination(struct xa_context *r,
175			       struct pipe_surface *surface, int width,
176			       int height);
177
178void renderer_init_state(struct xa_context *r);
179void renderer_copy_prepare(struct xa_context *r,
180			   struct pipe_surface *dst_surface,
181			   struct pipe_resource *src_texture);
182void renderer_copy(struct xa_context *r, int dx,
183		   int dy,
184		   int sx,
185		   int sy,
186		   int width, int height, float src_width, float src_height);
187
188void renderer_draw_flush(struct xa_context *r);
189
190#endif
191