st/va: remove fence handling v3
[mesa.git] / src / gallium / state_trackers / va / postproc.c
1 /**************************************************************************
2 *
3 * Copyright 2015 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "util/u_handle_table.h"
29
30 #include "va_private.h"
31
32 static const VARectangle *
33 vlVaRegionDefault(const VARectangle *region, struct pipe_video_buffer *buf,
34 VARectangle *def)
35 {
36 if (region)
37 return region;
38
39 def->x = 0;
40 def->y = 0;
41 def->width = buf->width;
42 def->height = buf->height;
43
44 return def;
45 }
46
47 VAStatus
48 vlVaHandleVAProcPipelineParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
49 {
50 VARectangle def_src_region, def_dst_region;
51 const VARectangle *src_region, *dst_region;
52 struct u_rect src_rect;
53 struct u_rect dst_rect;
54 vlVaSurface *src_surface;
55 VAProcPipelineParameterBuffer *pipeline_param;
56 struct pipe_surface **surfaces;
57 struct pipe_surface *psurf;
58
59 if (!drv || !context)
60 return VA_STATUS_ERROR_INVALID_CONTEXT;
61
62 if (!buf || !buf->data)
63 return VA_STATUS_ERROR_INVALID_BUFFER;
64
65 if (!context->target)
66 return VA_STATUS_ERROR_INVALID_SURFACE;
67
68 pipeline_param = (VAProcPipelineParameterBuffer *)buf->data;
69
70 src_surface = handle_table_get(drv->htab, pipeline_param->surface);
71 if (!src_surface || !src_surface->buffer)
72 return VA_STATUS_ERROR_INVALID_SURFACE;
73
74 surfaces = context->target->get_surfaces(context->target);
75
76 if (!surfaces || !surfaces[0])
77 return VA_STATUS_ERROR_INVALID_SURFACE;
78
79 psurf = surfaces[0];
80
81 src_region = vlVaRegionDefault(pipeline_param->surface_region, src_surface->buffer, &def_src_region);
82 dst_region = vlVaRegionDefault(pipeline_param->output_region, context->target, &def_dst_region);
83
84 src_rect.x0 = src_region->x;
85 src_rect.y0 = src_region->y;
86 src_rect.x1 = src_region->x + src_region->width;
87 src_rect.y1 = src_region->y + src_region->height;
88
89 dst_rect.x0 = dst_region->x;
90 dst_rect.y0 = dst_region->y;
91 dst_rect.x1 = dst_region->x + dst_region->width;
92 dst_rect.y1 = dst_region->y + dst_region->height;
93
94 vl_compositor_clear_layers(&drv->cstate);
95 vl_compositor_set_buffer_layer(&drv->cstate, &drv->compositor, 0, src_surface->buffer, &src_rect, NULL, VL_COMPOSITOR_WEAVE);
96 vl_compositor_set_layer_dst_area(&drv->cstate, 0, &dst_rect);
97 vl_compositor_render(&drv->cstate, &drv->compositor, psurf, NULL, false);
98
99 // TODO: figure out why this is necessary for DMA-buf sharing
100 drv->pipe->flush(drv->pipe, NULL, 0);
101
102 return VA_STATUS_SUCCESS;
103 }
104
105