1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen.
4 * Copyright 2011 Christian König.
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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 **************************************************************************/
31 #include "pipe/p_state.h"
33 #include "util/u_memory.h"
34 #include "util/u_debug.h"
35 #include "util/u_rect.h"
37 #include "vdpau_private.h"
40 * Create a VdpVideoSurface.
43 vlVdpVideoSurfaceCreate(VdpDevice device
, VdpChromaType chroma_type
,
44 uint32_t width
, uint32_t height
,
45 VdpVideoSurface
*surface
)
47 struct pipe_video_buffer tmpl
;
51 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Creating a surface\n");
53 if (!(width
&& height
)) {
54 ret
= VDP_STATUS_INVALID_SIZE
;
58 if (!vlCreateHTAB()) {
59 ret
= VDP_STATUS_RESOURCES
;
63 p_surf
= CALLOC(1, sizeof(vlVdpSurface
));
65 ret
= VDP_STATUS_RESOURCES
;
69 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
71 ret
= VDP_STATUS_INVALID_HANDLE
;
76 memset(&tmpl
, 0, sizeof(tmpl
));
77 tmpl
.buffer_format
= PIPE_FORMAT_YV12
;
78 tmpl
.chroma_format
= ChromaToPipe(chroma_type
);
81 p_surf
->video_buffer
= dev
->context
->pipe
->create_video_buffer
87 *surface
= vlAddDataHTAB(p_surf
);
89 ret
= VDP_STATUS_ERROR
;
96 p_surf
->video_buffer
->destroy(p_surf
->video_buffer
);
108 * Destroy a VdpVideoSurface.
111 vlVdpVideoSurfaceDestroy(VdpVideoSurface surface
)
113 vlVdpSurface
*p_surf
;
115 p_surf
= (vlVdpSurface
*)vlGetDataHTAB((vlHandle
)surface
);
117 return VDP_STATUS_INVALID_HANDLE
;
119 if (p_surf
->video_buffer
)
120 p_surf
->video_buffer
->destroy(p_surf
->video_buffer
);
123 return VDP_STATUS_OK
;
127 * Retrieve the parameters used to create a VdpVideoSurface.
130 vlVdpVideoSurfaceGetParameters(VdpVideoSurface surface
,
131 VdpChromaType
*chroma_type
,
132 uint32_t *width
, uint32_t *height
)
134 if (!(width
&& height
&& chroma_type
))
135 return VDP_STATUS_INVALID_POINTER
;
137 vlVdpSurface
*p_surf
= vlGetDataHTAB(surface
);
139 return VDP_STATUS_INVALID_HANDLE
;
141 *width
= p_surf
->video_buffer
->width
;
142 *height
= p_surf
->video_buffer
->height
;
143 *chroma_type
= PipeToChroma(p_surf
->video_buffer
->chroma_format
);
145 return VDP_STATUS_OK
;
149 * Copy image data from a VdpVideoSurface to application memory in a specified
153 vlVdpVideoSurfaceGetBitsYCbCr(VdpVideoSurface surface
,
154 VdpYCbCrFormat destination_ycbcr_format
,
155 void *const *destination_data
,
156 uint32_t const *destination_pitches
)
159 return VDP_STATUS_RESOURCES
;
161 vlVdpSurface
*p_surf
= vlGetDataHTAB(surface
);
163 return VDP_STATUS_INVALID_HANDLE
;
165 //if (!p_surf->psurface)
166 // return VDP_STATUS_RESOURCES;
168 //return VDP_STATUS_OK;
169 return VDP_STATUS_NO_IMPLEMENTATION
;
173 * Copy image data from application memory in a specific YCbCr format to
177 vlVdpVideoSurfacePutBitsYCbCr(VdpVideoSurface surface
,
178 VdpYCbCrFormat source_ycbcr_format
,
179 void const *const *source_data
,
180 uint32_t const *source_pitches
)
182 enum pipe_format pformat
= FormatYCBCRToPipe(source_ycbcr_format
);
183 struct pipe_context
*pipe
;
184 struct pipe_sampler_view
**sampler_views
;
188 return VDP_STATUS_RESOURCES
;
190 vlVdpSurface
*p_surf
= vlGetDataHTAB(surface
);
192 return VDP_STATUS_INVALID_HANDLE
;
194 pipe
= p_surf
->device
->context
->pipe
;
196 return VDP_STATUS_INVALID_HANDLE
;
198 if (p_surf
->video_buffer
== NULL
|| pformat
!= p_surf
->video_buffer
->buffer_format
) {
199 assert(0); // TODO Recreate resource
200 return VDP_STATUS_NO_IMPLEMENTATION
;
203 sampler_views
= p_surf
->video_buffer
->get_sampler_view_planes(p_surf
->video_buffer
);
205 return VDP_STATUS_RESOURCES
;
207 for (i
= 0; i
< 3; ++i
) { //TODO put nr of planes into util format
208 struct pipe_sampler_view
*sv
= sampler_views
[i
? i
^ 3 : 0];
209 struct pipe_box dst_box
= { 0, 0, 0, sv
->texture
->width0
, sv
->texture
->height0
, 1 };
211 struct pipe_transfer
*transfer
;
214 transfer
= pipe
->get_transfer(pipe
, sv
->texture
, 0, PIPE_TRANSFER_WRITE
, &dst_box
);
216 return VDP_STATUS_RESOURCES
;
218 map
= pipe
->transfer_map(pipe
, transfer
);
220 util_copy_rect(map
, sv
->texture
->format
, transfer
->stride
, 0, 0,
221 dst_box
.width
, dst_box
.height
,
222 source_data
[i
], source_pitches
[i
], 0, 0);
224 pipe
->transfer_unmap(pipe
, transfer
);
227 pipe
->transfer_destroy(pipe
, transfer
);
230 return VDP_STATUS_OK
;