Don't store references to these on the surface but on the context.
References to transfers are still stored on the surface since we allow
only a single map of a surface at a time.
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
fs_traits |= picture_format_fixups(mask_pic, 1);
}
- if (ctx->dst->srf->format == PIPE_FORMAT_L8_UNORM)
+ if (ctx->srf->format == PIPE_FORMAT_L8_UNORM)
fs_traits |= FS_DST_LUMINANCE;
shader = xa_shaders_get(ctx->shaders, vs_traits, fs_traits);
struct xa_surface *dst_srf = comp->dst->srf;
int ret;
- ret = xa_surface_psurf_create(ctx, dst_srf);
+ ret = xa_ctx_srf_create(ctx, dst_srf);
if (ret != XA_ERR_NONE)
return ret;
ctx->dst = dst_srf;
- renderer_bind_destination(ctx, dst_srf->srf,
- dst_srf->srf->width,
- dst_srf->srf->height);
+ renderer_bind_destination(ctx, ctx->srf, ctx->srf->width,
+ ctx->srf->height);
ret = bind_composite_blend_state(ctx, comp);
if (ret != XA_ERR_NONE)
ctx->comp = comp;
}
- xa_surface_psurf_destroy(dst_srf);
+ xa_ctx_srf_destroy(ctx);
return XA_ERR_NONE;
}
ctx->comp = NULL;
ctx->has_solid_color = FALSE;
- ctx->num_bound_samplers = 0;
+ xa_ctx_sampler_views_destroy(ctx);
}
static const struct xa_composite_allocation a = {
r->shaders = NULL;
}
+ xa_ctx_sampler_views_destroy(r);
+
if (r->cso) {
cso_release_all(r->cso);
cso_destroy_context(r->cso);
unsigned int transfer_direction = 0;
struct pipe_context *pipe = ctx->pipe;
+ /*
+ * A surface may only have a single map.
+ */
if (srf->transfer)
return NULL;
}
int
-xa_surface_psurf_create(struct xa_context *ctx, struct xa_surface *dst)
+xa_ctx_srf_create(struct xa_context *ctx, struct xa_surface *dst)
{
struct pipe_screen *screen = ctx->pipe->screen;
struct pipe_surface srf_templ;
- if (dst->srf)
+ if (ctx->srf)
return -XA_ERR_INVAL;
if (!screen->is_format_supported(screen, dst->tex->format,
u_surface_default_template(&srf_templ, dst->tex,
PIPE_BIND_RENDER_TARGET);
- dst->srf = ctx->pipe->create_surface(ctx->pipe, dst->tex, &srf_templ);
- if (!dst->srf)
+ ctx->srf = ctx->pipe->create_surface(ctx->pipe, dst->tex, &srf_templ);
+ if (!ctx->srf)
return -XA_ERR_NORES;
return XA_ERR_NONE;
}
void
-xa_surface_psurf_destroy(struct xa_surface *dst)
+xa_ctx_srf_destroy(struct xa_context *ctx)
{
- pipe_surface_reference(&dst->srf, NULL);
+ pipe_surface_reference(&ctx->srf, NULL);
}
int
xa_copy_prepare(struct xa_context *ctx,
struct xa_surface *dst, struct xa_surface *src)
{
- if (src == dst || dst->srf != NULL)
+ if (src == dst || ctx->srf != NULL)
return -XA_ERR_INVAL;
if (src->tex->format != dst->tex->format) {
- int ret = xa_surface_psurf_create(ctx, dst);
+ int ret = xa_ctx_srf_create(ctx, dst);
if (ret != XA_ERR_NONE)
return ret;
- renderer_copy_prepare(ctx, dst->srf, src->tex);
+ renderer_copy_prepare(ctx, ctx->srf, src->tex);
ctx->simple_copy = 0;
} else
ctx->simple_copy = 1;
ctx->src = src;
ctx->dst = dst;
+ xa_ctx_srf_destroy(ctx);
return 0;
}
0, &src_box);
} else
renderer_copy(ctx, dx, dy, sx, sy, width, height,
- (float) width, (float) height);
+ (float) ctx->src->tex->width0,
+ (float) ctx->src->tex->height0);
}
void
if (!ctx->simple_copy) {
renderer_draw_flush(ctx);
ctx->pipe->flush(ctx->pipe, &ctx->last_fence);
- xa_surface_psurf_destroy(ctx->dst);
} else
ctx->pipe->flush(ctx->pipe, &ctx->last_fence);
}
int width, height;
int ret;
- ret = xa_surface_psurf_create(ctx, dst);
+ ret = xa_ctx_srf_create(ctx, dst);
if (ret != XA_ERR_NONE)
return ret;
- if (dst->srf->format == PIPE_FORMAT_L8_UNORM)
+ if (ctx->srf->format == PIPE_FORMAT_L8_UNORM)
xa_pixel_to_float4_a8(fg, ctx->solid_color);
else
xa_pixel_to_float4(fg, ctx->solid_color);
ctx->has_solid_color = 1;
ctx->dst = dst;
- width = dst->srf->width;
- height = dst->srf->height;
+ width = ctx->srf->width;
+ height = ctx->srf->height;
#if 0
debug_printf("Color Pixel=(%d, %d, %d, %d), RGBA=(%f, %f, %f, %f)\n",
vs_traits = VS_SOLID_FILL;
fs_traits = FS_SOLID_FILL;
- renderer_bind_destination(ctx, dst->srf, width, height);
+ renderer_bind_destination(ctx, ctx->srf, width, height);
bind_solid_blend_state(ctx);
cso_set_samplers(ctx->cso, 0, NULL);
cso_set_fragment_sampler_views(ctx->cso, 0, NULL);
renderer_begin_solid(ctx);
- xa_surface_psurf_destroy(dst);
+ xa_ctx_srf_destroy(ctx);
return XA_ERR_NONE;
}
free(fence);
}
+
+void
+xa_ctx_sampler_views_destroy(struct xa_context *ctx)
+{
+ int i;
+
+ for (i = 0; i < ctx->num_bound_samplers; ++i)
+ pipe_sampler_view_reference(&ctx->bound_sampler_views[i], NULL);
+ ctx->num_bound_samplers = 0;
+}
struct pipe_resource template;
struct xa_tracker *xa;
struct pipe_resource *tex;
- struct pipe_surface *srf;
- struct pipe_sampler_view *view;
+ struct pipe_transfer *transfer;
unsigned int flags;
struct xa_format_descriptor fdesc;
- struct pipe_transfer *transfer;
struct pipe_context *mapping_pipe;
};
struct pipe_fence_handle *last_fence;
struct xa_surface *src;
struct xa_surface *dst;
+ struct pipe_surface *srf;
+
int simple_copy;
int has_solid_color;
* xa_context.c
*/
extern int
-xa_surface_psurf_create(struct xa_context *ctx, struct xa_surface *dst);
+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_surface_psurf_destroy(struct xa_surface *dst);
+xa_ctx_sampler_views_destroy(struct xa_context *ctx);
/*
* xa_renderer.c
if (!srf->tex)
goto out_no_tex;
- srf->srf = NULL;
srf->xa = xa;
srf->flags = flags;
srf->fdesc = fdesc;
struct xa_tracker *xa = srf->xa;
int save_width;
int save_height;
+ unsigned int save_format;
struct xa_format_descriptor fdesc;
+
if (xa_format == xa_format_unknown)
fdesc = xa_get_format_stype_depth(xa, stype, depth);
else
save_width = template->width0;
save_height = template->height0;
+ save_format = template->format;
template->width0 = width;
template->height0 = height;
+ template->format = fdesc.format;
texture = xa->screen->resource_create(xa->screen, template);
if (!texture) {
template->width0 = save_width;
template->height0 = save_height;
+ template->format = save_format;
return -XA_ERR_NORES;
}
- pipe_surface_reference(&srf->srf, NULL);
-
if (copy_contents) {
struct pipe_context *pipe = xa->default_ctx->pipe;
void
xa_surface_destroy(struct xa_surface *srf)
{
- pipe_surface_reference(&srf->srf, NULL);
pipe_resource_reference(&srf->tex, NULL);
free(srf);
}
{
struct pipe_sampler_state *samplers[3];
struct pipe_sampler_state sampler;
- struct pipe_sampler_view *views[3];
struct pipe_sampler_view view_templ;
unsigned int i;
for (i = 0; i < 3; ++i) {
samplers[i] = &sampler;
- if (!yuv[i]->view) {
- u_sampler_view_default_template(&view_templ,
- yuv[i]->tex, yuv[i]->tex->format);
-
- yuv[i]->view = r->pipe->create_sampler_view(r->pipe,
- yuv[i]->tex,
- &view_templ);
- }
- views[i] = yuv[i]->view;
- }
+ u_sampler_view_default_template(&view_templ, yuv[i]->tex,
+ yuv[i]->tex->format);
+ r->bound_sampler_views[i] =
+ r->pipe->create_sampler_view(r->pipe, yuv[i]->tex, &view_templ);
+ }
+ r->num_bound_samplers = 3;
cso_set_samplers(r->cso, 3, (const struct pipe_sampler_state **)samplers);
- cso_set_fragment_sampler_views(r->cso, 3, views);
+ cso_set_fragment_sampler_views(r->cso, 3, r->bound_sampler_views);
}
static void
conversion_matrix, param_bytes);
}
-static void
-xa_yuv_destroy_sampler_views(struct xa_surface *yuv[])
-{
- unsigned int i;
-
- for (i = 0; i < 3; ++i) {
- pipe_sampler_view_reference(&yuv[i]->view, NULL);
- }
-}
-
extern int
xa_yuv_planar_blit(struct xa_context *r,
int src_x,
{
float scale_x;
float scale_y;
- struct pipe_surface srf_templ;
+ int ret;
if (dst_w == 0 || dst_h == 0)
return XA_ERR_NONE;
- memset(&srf_templ, 0, sizeof(srf_templ));
- u_surface_default_template(&srf_templ, dst->tex, PIPE_BIND_RENDER_TARGET);
- dst->srf = r->pipe->create_surface(r->pipe, dst->tex, &srf_templ);
- if (!dst->srf)
+ ret = xa_ctx_srf_create(r, dst);
+ if (ret != XA_ERR_NONE)
return -XA_ERR_NORES;
- renderer_bind_destination(r, dst->srf, dst->srf->width, dst->srf->height);
+ renderer_bind_destination(r, r->srf, r->srf->width, r->srf->height);
xa_yuv_bind_blend_state(r);
xa_yuv_bind_shaders(r);
xa_yuv_bind_samplers(r, yuv);
r->pipe->flush(r->pipe, &r->last_fence);
- xa_yuv_destroy_sampler_views(yuv);
- pipe_surface_reference(&dst->srf, NULL);
+ xa_ctx_sampler_views_destroy(r);
+ xa_ctx_srf_destroy(r);
return XA_ERR_NONE;
}