-static INLINE struct pipe_surface * setup_framebuffer(struct vg_image *dst)
-{
- struct vg_context *ctx = vg_current_context();
- struct pipe_context *pipe = ctx->pipe;
- struct pipe_framebuffer_state fb;
- struct pipe_surface *dst_surf = pipe->screen->get_tex_surface(
- pipe->screen, dst->sampler_view->texture, 0, 0, 0,
- PIPE_BIND_RENDER_TARGET);
-
- /* drawing dest */
- memset(&fb, 0, sizeof(fb));
- fb.width = dst->x + dst_surf->width;
- fb.height = dst->y + dst_surf->height;
- fb.nr_cbufs = 1;
- fb.cbufs[0] = dst_surf;
- {
- VGint i;
- for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)
- fb.cbufs[i] = 0;
- }
- cso_set_framebuffer(ctx->cso_context, &fb);
-
- return dst_surf;
-}
-
-static void setup_viewport(struct vg_image *dst)
-{
- struct vg_context *ctx = vg_current_context();
- vg_set_viewport(ctx, VEGA_Y0_TOP);
-}
-
-static void setup_blend()
-{
- struct vg_context *ctx = vg_current_context();
- struct pipe_blend_state blend;
- memset(&blend, 0, sizeof(blend));
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
- if (ctx->state.vg.filter_channel_mask & VG_RED)
- blend.rt[0].colormask |= PIPE_MASK_R;
- if (ctx->state.vg.filter_channel_mask & VG_GREEN)
- blend.rt[0].colormask |= PIPE_MASK_G;
- if (ctx->state.vg.filter_channel_mask & VG_BLUE)
- blend.rt[0].colormask |= PIPE_MASK_B;
- if (ctx->state.vg.filter_channel_mask & VG_ALPHA)
- blend.rt[0].colormask |= PIPE_MASK_A;
- blend.rt[0].blend_enable = 0;
- cso_set_blend(ctx->cso_context, &blend);
-}
-
-static void setup_constant_buffer(struct vg_context *ctx, const void *buffer,
- VGint param_bytes)
-{
- struct pipe_context *pipe = ctx->pipe;
- struct pipe_resource **cbuf = &ctx->filter.buffer;
-
- /* We always need to get a new buffer, to keep the drivers simple and
- * avoid gratuitous rendering synchronization. */
- pipe_resource_reference(cbuf, NULL);
-
- *cbuf = pipe_buffer_create(pipe->screen,
- PIPE_BIND_CONSTANT_BUFFER,
- param_bytes);
-
- if (*cbuf) {
- st_no_flush_pipe_buffer_write(ctx, *cbuf,
- 0, param_bytes, buffer);
- }
-
- ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, *cbuf);
-}
-
-static void setup_samplers(struct vg_context *ctx, struct filter_info *info)
-{
- struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
- struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
- struct pipe_sampler_state sampler[3];
- int num_samplers = 0;
- int num_textures = 0;
-
- samplers[0] = NULL;
- samplers[1] = NULL;
- samplers[2] = NULL;
- samplers[3] = NULL;
- sampler_views[0] = NULL;
- sampler_views[1] = NULL;
- sampler_views[2] = NULL;
- sampler_views[3] = NULL;
-
- memset(&sampler[0], 0, sizeof(struct pipe_sampler_state));
- sampler[0].wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler[0].wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler[0].wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler[0].min_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
- sampler[0].mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
- sampler[0].normalized_coords = 1;
-
- switch(info->tiling_mode) {
- case VG_TILE_FILL:
- sampler[0].wrap_s = PIPE_TEX_WRAP_CLAMP_TO_BORDER;
- sampler[0].wrap_t = PIPE_TEX_WRAP_CLAMP_TO_BORDER;
- memcpy(sampler[0].border_color,
- ctx->state.vg.tile_fill_color,
- sizeof(VGfloat) * 4);
- break;
- case VG_TILE_PAD:
- sampler[0].wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler[0].wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- break;
- case VG_TILE_REPEAT:
- sampler[0].wrap_s = PIPE_TEX_WRAP_REPEAT;
- sampler[0].wrap_t = PIPE_TEX_WRAP_REPEAT;
- break;
- case VG_TILE_REFLECT:
- sampler[0].wrap_s = PIPE_TEX_WRAP_MIRROR_REPEAT;
- sampler[0].wrap_t = PIPE_TEX_WRAP_MIRROR_REPEAT;
- break;
- default:
- debug_assert(!"Unknown tiling mode");
- }
-
- samplers[0] = &sampler[0];
- sampler_views[0] = info->src->sampler_view;
- ++num_samplers;
- ++num_textures;
-
- if (info->extra_texture_view) {
- memcpy(&sampler[1], &sampler[0], sizeof(struct pipe_sampler_state));
- samplers[1] = &sampler[1];
- sampler_views[1] = info->extra_texture_view;
- ++num_samplers;
- ++num_textures;
- }
-
-
- cso_set_samplers(ctx->cso_context, num_samplers, (const struct pipe_sampler_state **)samplers);
- cso_set_fragment_sampler_views(ctx->cso_context, num_textures, sampler_views);
-}
-