1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "pipe/p_screen.h"
31 #include "util/u_memory.h"
32 #include "util/u_handle_table.h"
33 #include "util/u_rect.h"
35 #include "vl/vl_compositor.h"
36 #include "vl/vl_winsys.h"
38 #include "va_private.h"
41 vlVaCreateSurfaces(VADriverContextP ctx
, int width
, int height
, int format
,
42 int num_surfaces
, VASurfaceID
*surfaces
)
44 struct pipe_video_buffer templat
= {};
45 struct pipe_screen
*pscreen
;
50 return VA_STATUS_ERROR_INVALID_CONTEXT
;
52 if (!(width
&& height
))
53 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT
;
55 drv
= VL_VA_DRIVER(ctx
);
56 pscreen
= VL_VA_PSCREEN(ctx
);
58 templat
.buffer_format
= pscreen
->get_video_param
61 PIPE_VIDEO_PROFILE_UNKNOWN
,
62 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
63 PIPE_VIDEO_CAP_PREFERED_FORMAT
65 templat
.chroma_format
= ChromaToPipe(format
);
66 templat
.width
= width
;
67 templat
.height
= height
;
68 templat
.interlaced
= pscreen
->get_video_param
71 PIPE_VIDEO_PROFILE_UNKNOWN
,
72 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
73 PIPE_VIDEO_CAP_PREFERS_INTERLACED
76 for (i
= 0; i
< num_surfaces
; ++i
) {
77 vlVaSurface
*surf
= CALLOC(1, sizeof(vlVaSurface
));
81 surf
->templat
= templat
;
82 surfaces
[i
] = handle_table_add(drv
->htab
, surf
);
85 return VA_STATUS_SUCCESS
;
89 vlVaDestroySurfaces(ctx
, surfaces
, i
);
91 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
95 vlVaDestroySurfaces(VADriverContextP ctx
, VASurfaceID
*surface_list
, int num_surfaces
)
101 return VA_STATUS_ERROR_INVALID_CONTEXT
;
103 drv
= VL_VA_DRIVER(ctx
);
104 for (i
= 0; i
< num_surfaces
; ++i
) {
105 vlVaSurface
*surf
= handle_table_get(drv
->htab
, surface_list
[i
]);
107 surf
->buffer
->destroy(surf
->buffer
);
109 drv
->pipe
->screen
->fence_reference(drv
->pipe
->screen
, &surf
->fence
, NULL
);
111 handle_table_remove(drv
->htab
, surface_list
[i
]);
114 return VA_STATUS_SUCCESS
;
118 vlVaSyncSurface(VADriverContextP ctx
, VASurfaceID render_target
)
121 return VA_STATUS_ERROR_INVALID_CONTEXT
;
123 return VA_STATUS_SUCCESS
;
127 vlVaQuerySurfaceStatus(VADriverContextP ctx
, VASurfaceID render_target
, VASurfaceStatus
*status
)
130 return VA_STATUS_ERROR_INVALID_CONTEXT
;
132 return VA_STATUS_SUCCESS
;
136 vlVaQuerySurfaceError(VADriverContextP ctx
, VASurfaceID render_target
, VAStatus error_status
, void **error_info
)
139 return VA_STATUS_ERROR_INVALID_CONTEXT
;
141 return VA_STATUS_ERROR_UNIMPLEMENTED
;
145 vlVaPutSurface(VADriverContextP ctx
, VASurfaceID surface_id
, void* draw
, short srcx
, short srcy
,
146 unsigned short srcw
, unsigned short srch
, short destx
, short desty
,
147 unsigned short destw
, unsigned short desth
, VARectangle
*cliprects
,
148 unsigned int number_cliprects
, unsigned int flags
)
152 struct pipe_screen
*screen
;
153 struct pipe_resource
*tex
;
154 struct pipe_surface surf_templ
, *surf_draw
;
155 struct u_rect src_rect
, *dirty_area
;
158 return VA_STATUS_ERROR_INVALID_CONTEXT
;
160 drv
= VL_VA_DRIVER(ctx
);
161 surf
= handle_table_get(drv
->htab
, surface_id
);
163 return VA_STATUS_ERROR_INVALID_SURFACE
;
165 screen
= drv
->pipe
->screen
;
168 screen
->fence_finish(screen
, surf
->fence
, PIPE_TIMEOUT_INFINITE
);
169 screen
->fence_reference(screen
, &surf
->fence
, NULL
);
172 tex
= vl_screen_texture_from_drawable(drv
->vscreen
, (Drawable
)draw
);
174 return VA_STATUS_ERROR_INVALID_DISPLAY
;
176 dirty_area
= vl_screen_get_dirty_area(drv
->vscreen
);
178 memset(&surf_templ
, 0, sizeof(surf_templ
));
179 surf_templ
.format
= tex
->format
;
180 surf_draw
= drv
->pipe
->create_surface(drv
->pipe
, tex
, &surf_templ
);
182 pipe_resource_reference(&tex
, NULL
);
183 return VA_STATUS_ERROR_INVALID_DISPLAY
;
188 src_rect
.x1
= srcw
+ srcx
;
189 src_rect
.y1
= srch
+ srcy
;
191 vl_compositor_clear_layers(&drv
->cstate
);
192 vl_compositor_set_buffer_layer(&drv
->cstate
, &drv
->compositor
, 0, surf
->buffer
, &src_rect
, NULL
, VL_COMPOSITOR_WEAVE
);
193 vl_compositor_render(&drv
->cstate
, &drv
->compositor
, surf_draw
, dirty_area
, true);
195 screen
->flush_frontbuffer
198 vl_screen_get_private(drv
->vscreen
), NULL
201 screen
->fence_reference(screen
, &surf
->fence
, NULL
);
202 drv
->pipe
->flush(drv
->pipe
, &surf
->fence
, 0);
204 pipe_resource_reference(&tex
, NULL
);
205 pipe_surface_reference(&surf_draw
, NULL
);
207 return VA_STATUS_SUCCESS
;
211 vlVaLockSurface(VADriverContextP ctx
, VASurfaceID surface
, unsigned int *fourcc
,
212 unsigned int *luma_stride
, unsigned int *chroma_u_stride
, unsigned int *chroma_v_stride
,
213 unsigned int *luma_offset
, unsigned int *chroma_u_offset
, unsigned int *chroma_v_offset
,
214 unsigned int *buffer_name
, void **buffer
)
217 return VA_STATUS_ERROR_INVALID_CONTEXT
;
219 return VA_STATUS_ERROR_UNIMPLEMENTED
;
223 vlVaUnlockSurface(VADriverContextP ctx
, VASurfaceID surface
)
226 return VA_STATUS_ERROR_INVALID_CONTEXT
;
228 return VA_STATUS_ERROR_UNIMPLEMENTED
;