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 **************************************************************************/
29 #include <vdpau/vdpau.h>
31 #include <util/u_debug.h>
32 #include <util/u_memory.h>
33 #include <util/u_sampler.h>
35 #include "vdpau_private.h"
38 vlVdpOutputSurfaceCreate(VdpDevice device
,
39 VdpRGBAFormat rgba_format
,
40 uint32_t width
, uint32_t height
,
41 VdpOutputSurface
*surface
)
43 struct pipe_context
*pipe
;
44 struct pipe_resource res_tmpl
, *res
;
45 struct pipe_sampler_view sv_templ
;
46 struct pipe_surface surf_templ
;
48 vlVdpOutputSurface
*vlsurface
= NULL
;
50 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Creating output surface\n");
51 if (!(width
&& height
))
52 return VDP_STATUS_INVALID_SIZE
;
54 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
56 return VDP_STATUS_INVALID_HANDLE
;
58 pipe
= dev
->context
->pipe
;
60 return VDP_STATUS_INVALID_HANDLE
;
62 vlsurface
= CALLOC(1, sizeof(vlVdpOutputSurface
));
64 return VDP_STATUS_RESOURCES
;
66 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
68 res_tmpl
.target
= PIPE_TEXTURE_2D
;
69 res_tmpl
.format
= FormatRGBAToPipe(rgba_format
);
70 res_tmpl
.width0
= width
;
71 res_tmpl
.height0
= height
;
73 res_tmpl
.array_size
= 1;
74 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
75 res_tmpl
.usage
= PIPE_USAGE_STATIC
;
77 res
= pipe
->screen
->resource_create(pipe
->screen
, &res_tmpl
);
80 return VDP_STATUS_ERROR
;
83 memset(&sv_templ
, 0, sizeof(sv_templ
));
84 u_sampler_view_default_template(&sv_templ
, res
, res
->format
);
86 // as long as we don't have a background picture we don't want an alpha channel
87 sv_templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
89 vlsurface
->sampler_view
= pipe
->create_sampler_view(pipe
, res
, &sv_templ
);
90 if (!vlsurface
->sampler_view
) {
92 return VDP_STATUS_ERROR
;
95 memset(&surf_templ
, 0, sizeof(surf_templ
));
96 surf_templ
.format
= res
->format
;
97 surf_templ
.usage
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
98 vlsurface
->surface
= pipe
->create_surface(pipe
, res
, &surf_templ
);
99 if (!vlsurface
->surface
) {
101 return VDP_STATUS_ERROR
;
104 *surface
= vlAddDataHTAB(vlsurface
);
107 return VDP_STATUS_ERROR
;
110 return VDP_STATUS_OK
;
114 vlVdpOutputSurfaceDestroy(VdpOutputSurface surface
)
116 vlVdpOutputSurface
*vlsurface
;
118 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Destroying output surface\n");
120 vlsurface
= vlGetDataHTAB(surface
);
122 return VDP_STATUS_INVALID_HANDLE
;
124 pipe_surface_reference(&vlsurface
->surface
, NULL
);
125 pipe_sampler_view_reference(&vlsurface
->sampler_view
, NULL
);
127 vlRemoveDataHTAB(surface
);
130 return VDP_STATUS_OK
;
134 vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface
,
135 VdpRGBAFormat
*rgba_format
,
136 uint32_t *width
, uint32_t *height
)
138 vlVdpOutputSurface
*vlsurface
;
140 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] getting surface parameters\n");
142 vlsurface
= vlGetDataHTAB(surface
);
144 return VDP_STATUS_INVALID_HANDLE
;
146 *rgba_format
= PipeToFormatRGBA(vlsurface
->sampler_view
->texture
->format
);
147 *width
= vlsurface
->sampler_view
->texture
->width0
;
148 *height
= vlsurface
->sampler_view
->texture
->height0
;
150 return VDP_STATUS_OK
;
154 vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface
,
155 VdpRect
const *source_rect
,
156 void *const *destination_data
,
157 uint32_t const *destination_pitches
)
159 return VDP_STATUS_NO_IMPLEMENTATION
;
163 vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface
,
164 void const *const *source_data
,
165 uint32_t const *source_pitches
,
166 VdpRect
const *destination_rect
)
168 return VDP_STATUS_NO_IMPLEMENTATION
;
172 vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface
,
173 VdpIndexedFormat source_indexed_format
,
174 void const *const *source_data
,
175 uint32_t const *source_pitch
,
176 VdpRect
const *destination_rect
,
177 VdpColorTableFormat color_table_format
,
178 void const *color_table
)
180 return VDP_STATUS_NO_IMPLEMENTATION
;
184 vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface
,
185 VdpYCbCrFormat source_ycbcr_format
,
186 void const *const *source_data
,
187 uint32_t const *source_pitches
,
188 VdpRect
const *destination_rect
,
189 VdpCSCMatrix
const *csc_matrix
)
191 return VDP_STATUS_NO_IMPLEMENTATION
;
195 vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface
,
196 VdpRect
const *destination_rect
,
197 VdpOutputSurface source_surface
,
198 VdpRect
const *source_rect
,
199 VdpColor
const *colors
,
200 VdpOutputSurfaceRenderBlendState
const *blend_state
,
203 return VDP_STATUS_NO_IMPLEMENTATION
;
207 vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface
,
208 VdpRect
const *destination_rect
,
209 VdpBitmapSurface source_surface
,
210 VdpRect
const *source_rect
,
211 VdpColor
const *colors
,
212 VdpOutputSurfaceRenderBlendState
const *blend_state
,
215 return VDP_STATUS_NO_IMPLEMENTATION
;