st/va: move post processing function into own file
[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 "pipe/p_video_codec.h"
29
30 #include "util/u_handle_table.h"
31 //#include "util/u_video.h"
32
33 //#include "vl/vl_vlc.h"
34 //#include "vl/vl_winsys.h"
35
36 #include "va_private.h"
37
38 VAStatus
39 vlVaHandleVAProcPipelineParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
40 {
41 struct u_rect src_rect;
42 struct u_rect dst_rect;
43 vlVaSurface *src_surface;
44 VAProcPipelineParameterBuffer *pipeline_param;
45 struct pipe_surface **surfaces;
46 struct pipe_screen *screen;
47 struct pipe_surface *psurf;
48
49 if (!drv || !context)
50 return VA_STATUS_ERROR_INVALID_CONTEXT;
51
52 if (!buf || !buf->data)
53 return VA_STATUS_ERROR_INVALID_BUFFER;
54
55 if (!context->target)
56 return VA_STATUS_ERROR_INVALID_SURFACE;
57
58 pipeline_param = (VAProcPipelineParameterBuffer *)buf->data;
59
60 src_surface = handle_table_get(drv->htab, pipeline_param->surface);
61 if (!src_surface || !src_surface->buffer)
62 return VA_STATUS_ERROR_INVALID_SURFACE;
63
64 surfaces = context->target->get_surfaces(context->target);
65
66 if (!surfaces || !surfaces[0])
67 return VA_STATUS_ERROR_INVALID_SURFACE;
68
69 screen = drv->pipe->screen;
70
71 psurf = surfaces[0];
72
73 src_rect.x0 = pipeline_param->surface_region->x;
74 src_rect.y0 = pipeline_param->surface_region->y;
75 src_rect.x1 = pipeline_param->surface_region->x + pipeline_param->surface_region->width;
76 src_rect.y1 = pipeline_param->surface_region->y + pipeline_param->surface_region->height;
77
78 dst_rect.x0 = pipeline_param->output_region->x;
79 dst_rect.y0 = pipeline_param->output_region->y;
80 dst_rect.x1 = pipeline_param->output_region->x + pipeline_param->output_region->width;
81 dst_rect.y1 = pipeline_param->output_region->y + pipeline_param->output_region->height;
82
83 vl_compositor_clear_layers(&drv->cstate);
84 vl_compositor_set_buffer_layer(&drv->cstate, &drv->compositor, 0, src_surface->buffer, &src_rect, NULL, VL_COMPOSITOR_WEAVE);
85 vl_compositor_set_layer_dst_area(&drv->cstate, 0, &dst_rect);
86 vl_compositor_render(&drv->cstate, &drv->compositor, psurf, NULL, false);
87
88 screen->fence_reference(screen, &src_surface->fence, NULL);
89 drv->pipe->flush(drv->pipe, &src_surface->fence, 0);
90
91 return VA_STATUS_SUCCESS;
92 }
93
94