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
) {
91 pipe_resource_reference(&res
, NULL
);
93 return VDP_STATUS_ERROR
;
96 memset(&surf_templ
, 0, sizeof(surf_templ
));
97 surf_templ
.format
= res
->format
;
98 surf_templ
.usage
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
99 vlsurface
->surface
= pipe
->create_surface(pipe
, res
, &surf_templ
);
100 if (!vlsurface
->surface
) {
101 pipe_resource_reference(&res
, NULL
);
103 return VDP_STATUS_ERROR
;
106 *surface
= vlAddDataHTAB(vlsurface
);
108 pipe_resource_reference(&res
, NULL
);
110 return VDP_STATUS_ERROR
;
113 pipe_resource_reference(&res
, NULL
);
115 return VDP_STATUS_OK
;
119 vlVdpOutputSurfaceDestroy(VdpOutputSurface surface
)
121 vlVdpOutputSurface
*vlsurface
;
123 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Destroying output surface\n");
125 vlsurface
= vlGetDataHTAB(surface
);
127 return VDP_STATUS_INVALID_HANDLE
;
129 pipe_surface_reference(&vlsurface
->surface
, NULL
);
130 pipe_sampler_view_reference(&vlsurface
->sampler_view
, NULL
);
132 vlRemoveDataHTAB(surface
);
135 return VDP_STATUS_OK
;
139 vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface
,
140 VdpRGBAFormat
*rgba_format
,
141 uint32_t *width
, uint32_t *height
)
143 vlVdpOutputSurface
*vlsurface
;
145 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] getting surface parameters\n");
147 vlsurface
= vlGetDataHTAB(surface
);
149 return VDP_STATUS_INVALID_HANDLE
;
151 *rgba_format
= PipeToFormatRGBA(vlsurface
->sampler_view
->texture
->format
);
152 *width
= vlsurface
->sampler_view
->texture
->width0
;
153 *height
= vlsurface
->sampler_view
->texture
->height0
;
155 return VDP_STATUS_OK
;
159 vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface
,
160 VdpRect
const *source_rect
,
161 void *const *destination_data
,
162 uint32_t const *destination_pitches
)
164 return VDP_STATUS_NO_IMPLEMENTATION
;
168 vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface
,
169 void const *const *source_data
,
170 uint32_t const *source_pitches
,
171 VdpRect
const *destination_rect
)
173 return VDP_STATUS_NO_IMPLEMENTATION
;
177 vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface
,
178 VdpIndexedFormat source_indexed_format
,
179 void const *const *source_data
,
180 uint32_t const *source_pitch
,
181 VdpRect
const *destination_rect
,
182 VdpColorTableFormat color_table_format
,
183 void const *color_table
)
185 return VDP_STATUS_NO_IMPLEMENTATION
;
189 vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface
,
190 VdpYCbCrFormat source_ycbcr_format
,
191 void const *const *source_data
,
192 uint32_t const *source_pitches
,
193 VdpRect
const *destination_rect
,
194 VdpCSCMatrix
const *csc_matrix
)
196 return VDP_STATUS_NO_IMPLEMENTATION
;
200 vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface
,
201 VdpRect
const *destination_rect
,
202 VdpOutputSurface source_surface
,
203 VdpRect
const *source_rect
,
204 VdpColor
const *colors
,
205 VdpOutputSurfaceRenderBlendState
const *blend_state
,
208 return VDP_STATUS_NO_IMPLEMENTATION
;
212 vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface
,
213 VdpRect
const *destination_rect
,
214 VdpBitmapSurface source_surface
,
215 VdpRect
const *source_rect
,
216 VdpColor
const *colors
,
217 VdpOutputSurfaceRenderBlendState
const *blend_state
,
220 return VDP_STATUS_NO_IMPLEMENTATION
;