Path: blob/21.2-virgl/src/gallium/frontends/xa/xa_priv.h
4561 views
/**********************************************************1* Copyright 2009-2011 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23*********************************************************24* Authors:25* Zack Rusin <zackr-at-vmware-dot-com>26* Thomas Hellstrom <thellstrom-at-vmware-dot-com>27*/2829#ifndef _XA_PRIV_H_30#define _XA_PRIV_H_3132#include "xa_tracker.h"33#include "xa_context.h"34#include "xa_composite.h"3536#include "pipe/p_screen.h"37#include "pipe/p_context.h"38#include "pipe/p_state.h"3940#include "util/u_math.h"4142#if defined(__GNUC__)43#define XA_EXPORT __attribute__ ((visibility("default")))44#else45#define XA_EXPORT46#endif4748#define XA_VB_SIZE (100 * 4 * 3 * 4)49#define XA_LAST_SURFACE_TYPE (xa_type_yuv_component + 1)50#define XA_MAX_SAMPLERS 35152struct xa_fence {53struct pipe_fence_handle *pipe_fence;54struct xa_tracker *xa;55};5657struct xa_format_descriptor {58enum pipe_format format;59enum xa_formats xa_format;60};6162struct xa_surface {63int refcount;64struct pipe_resource template;65struct xa_tracker *xa;66struct pipe_resource *tex;67struct pipe_transfer *transfer;68unsigned int flags;69struct xa_format_descriptor fdesc;70struct pipe_context *mapping_pipe;71};7273struct xa_tracker {74enum xa_formats *supported_formats;75unsigned int format_map[XA_LAST_SURFACE_TYPE][2];76struct pipe_loader_device *dev;77struct pipe_screen *screen;78struct xa_context *default_ctx;79};8081struct xa_context {82struct xa_tracker *xa;83struct pipe_context *pipe;8485struct cso_context *cso;86struct xa_shaders *shaders;8788struct pipe_resource *vs_const_buffer;89struct pipe_resource *fs_const_buffer;9091float buffer[XA_VB_SIZE];92unsigned int buffer_size;93struct pipe_vertex_element velems[3];9495/* number of attributes per vertex for the current96* draw operation */97unsigned int attrs_per_vertex;9899unsigned int fb_width;100unsigned int fb_height;101102struct pipe_fence_handle *last_fence;103struct xa_surface *src;104struct xa_surface *dst;105struct pipe_surface *srf;106107/* destination scissor state.. we scissor out untouched parts108* of the dst for the benefit of tilers:109*/110struct pipe_scissor_state scissor;111int scissor_valid;112113int simple_copy;114115int has_solid_src;116int has_solid_mask;117float solid_color[4];118119unsigned int num_bound_samplers;120struct pipe_sampler_view *bound_sampler_views[XA_MAX_SAMPLERS];121const struct xa_composite *comp;122};123124static inline void125xa_scissor_reset(struct xa_context *ctx)126{127ctx->scissor.maxx = 0;128ctx->scissor.maxy = 0;129ctx->scissor.minx = ~0;130ctx->scissor.miny = ~0;131ctx->scissor_valid = FALSE;132}133134static inline void135xa_scissor_update(struct xa_context *ctx, unsigned minx, unsigned miny,136unsigned maxx, unsigned maxy)137{138ctx->scissor.maxx = MAX2(ctx->scissor.maxx, maxx);139ctx->scissor.maxy = MAX2(ctx->scissor.maxy, maxy);140ctx->scissor.minx = MIN2(ctx->scissor.minx, minx);141ctx->scissor.miny = MIN2(ctx->scissor.miny, miny);142ctx->scissor_valid = TRUE;143}144145enum xa_vs_traits {146VS_COMPOSITE = 1 << 0,147VS_MASK = 1 << 1,148VS_SRC_SRC = 1 << 2,149VS_MASK_SRC = 1 << 3,150VS_YUV = 1 << 4,151};152153enum xa_fs_traits {154FS_COMPOSITE = 1 << 0,155FS_MASK = 1 << 1,156FS_SRC_SRC = 1 << 2,157FS_MASK_SRC = 1 << 3,158FS_YUV = 1 << 4,159FS_SRC_REPEAT_NONE = 1 << 5,160FS_MASK_REPEAT_NONE = 1 << 6,161FS_SRC_SWIZZLE_RGB = 1 << 7,162FS_MASK_SWIZZLE_RGB = 1 << 8,163FS_SRC_SET_ALPHA = 1 << 9,164FS_MASK_SET_ALPHA = 1 << 10,165FS_SRC_LUMINANCE = 1 << 11,166FS_MASK_LUMINANCE = 1 << 12,167FS_DST_LUMINANCE = 1 << 13,168FS_CA = 1 << 14,169};170171struct xa_shader {172void *fs;173void *vs;174};175176struct xa_shaders;177178/*179* Inline utilities180*/181182static inline int183xa_min(int a, int b)184{185return ((a <= b) ? a : b);186}187188static inline void189xa_pixel_to_float4(uint32_t pixel, float *color)190{191uint32_t r, g, b, a;192193a = (pixel >> 24) & 0xff;194r = (pixel >> 16) & 0xff;195g = (pixel >> 8) & 0xff;196b = (pixel >> 0) & 0xff;197color[0] = ((float)r) / 255.;198color[1] = ((float)g) / 255.;199color[2] = ((float)b) / 255.;200color[3] = ((float)a) / 255.;201}202203static inline void204xa_pixel_to_float4_a8(uint32_t pixel, float *color)205{206uint32_t a;207208a = (pixel >> 24) & 0xff;209color[0] = ((float)a) / 255.;210color[1] = ((float)a) / 255.;211color[2] = ((float)a) / 255.;212color[3] = ((float)a) / 255.;213}214215/*216* xa_tgsi.c217*/218219extern struct xa_shaders *xa_shaders_create(struct xa_context *);220221void xa_shaders_destroy(struct xa_shaders *shaders);222223struct xa_shader xa_shaders_get(struct xa_shaders *shaders,224unsigned vs_traits, unsigned fs_traits);225226/*227* xa_context.c228*/229extern void230xa_context_flush(struct xa_context *ctx);231232extern int233xa_ctx_srf_create(struct xa_context *ctx, struct xa_surface *dst);234235extern void236xa_ctx_srf_destroy(struct xa_context *ctx);237238extern void239xa_ctx_sampler_views_destroy(struct xa_context *ctx);240241/*242* xa_renderer.c243*/244void renderer_set_constants(struct xa_context *r,245int shader_type, const float *params,246int param_bytes);247248void renderer_draw_yuv(struct xa_context *r,249float src_x,250float src_y,251float src_w,252float src_h,253int dst_x,254int dst_y, int dst_w, int dst_h,255struct xa_surface *srf[]);256257void renderer_bind_destination(struct xa_context *r,258struct pipe_surface *surface);259260void renderer_init_state(struct xa_context *r);261void renderer_copy_prepare(struct xa_context *r,262struct pipe_surface *dst_surface,263struct pipe_resource *src_texture,264const enum xa_formats src_xa_format,265const enum xa_formats dst_xa_format);266267void renderer_copy(struct xa_context *r, int dx,268int dy,269int sx,270int sy,271int width, int height, float src_width, float src_height);272273void renderer_draw_flush(struct xa_context *r);274275void renderer_begin_solid(struct xa_context *r);276void renderer_solid(struct xa_context *r,277int x0, int y0, int x1, int y1);278void279renderer_begin_textures(struct xa_context *r);280281void282renderer_texture(struct xa_context *r,283int *pos,284int width, int height,285const float *src_matrix,286const float *mask_matrix);287288#endif289290291