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