Merge remote-tracking branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / state_trackers / vdpau / output.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Thomas Balling Sørensen.
4 * Copyright 2011 Christian König.
5 * All Rights Reserved.
6 *
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:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
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.
26 *
27 **************************************************************************/
28
29 #include <vdpau/vdpau.h>
30
31 #include <util/u_debug.h>
32 #include <util/u_memory.h>
33 #include <util/u_sampler.h>
34
35 #include "vdpau_private.h"
36
37 VdpStatus
38 vlVdpOutputSurfaceCreate(VdpDevice device,
39 VdpRGBAFormat rgba_format,
40 uint32_t width, uint32_t height,
41 VdpOutputSurface *surface)
42 {
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;
47
48 vlVdpOutputSurface *vlsurface = NULL;
49
50 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating output surface\n");
51 if (!(width && height))
52 return VDP_STATUS_INVALID_SIZE;
53
54 vlVdpDevice *dev = vlGetDataHTAB(device);
55 if (!dev)
56 return VDP_STATUS_INVALID_HANDLE;
57
58 pipe = dev->context->pipe;
59 if (!pipe)
60 return VDP_STATUS_INVALID_HANDLE;
61
62 vlsurface = CALLOC(1, sizeof(vlVdpOutputSurface));
63 if (!vlsurface)
64 return VDP_STATUS_RESOURCES;
65
66 memset(&res_tmpl, 0, sizeof(res_tmpl));
67
68 res_tmpl.target = PIPE_TEXTURE_2D;
69 res_tmpl.format = FormatRGBAToPipe(rgba_format);
70 res_tmpl.width0 = width;
71 res_tmpl.height0 = height;
72 res_tmpl.depth0 = 1;
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;
76
77 res = pipe->screen->resource_create(pipe->screen, &res_tmpl);
78 if (!res) {
79 FREE(dev);
80 return VDP_STATUS_ERROR;
81 }
82
83 memset(&sv_templ, 0, sizeof(sv_templ));
84 u_sampler_view_default_template(&sv_templ, res, res->format);
85
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;
88
89 vlsurface->sampler_view = pipe->create_sampler_view(pipe, res, &sv_templ);
90 if (!vlsurface->sampler_view) {
91 FREE(dev);
92 return VDP_STATUS_ERROR;
93 }
94
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) {
100 FREE(dev);
101 return VDP_STATUS_ERROR;
102 }
103
104 *surface = vlAddDataHTAB(vlsurface);
105 if (*surface == 0) {
106 FREE(dev);
107 return VDP_STATUS_ERROR;
108 }
109
110 return VDP_STATUS_OK;
111 }
112
113 VdpStatus
114 vlVdpOutputSurfaceDestroy(VdpOutputSurface surface)
115 {
116 vlVdpOutputSurface *vlsurface;
117
118 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying output surface\n");
119
120 vlsurface = vlGetDataHTAB(surface);
121 if (!vlsurface)
122 return VDP_STATUS_INVALID_HANDLE;
123
124 pipe_surface_reference(&vlsurface->surface, NULL);
125 pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
126
127 vlRemoveDataHTAB(surface);
128 FREE(vlsurface);
129
130 return VDP_STATUS_OK;
131 }
132
133 VdpStatus
134 vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface,
135 VdpRGBAFormat *rgba_format,
136 uint32_t *width, uint32_t *height)
137 {
138 vlVdpOutputSurface *vlsurface;
139
140 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] getting surface parameters\n");
141
142 vlsurface = vlGetDataHTAB(surface);
143 if (!vlsurface)
144 return VDP_STATUS_INVALID_HANDLE;
145
146 *rgba_format = PipeToFormatRGBA(vlsurface->sampler_view->texture->format);
147 *width = vlsurface->sampler_view->texture->width0;
148 *height = vlsurface->sampler_view->texture->height0;
149
150 return VDP_STATUS_OK;
151 }
152
153 VdpStatus
154 vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface,
155 VdpRect const *source_rect,
156 void *const *destination_data,
157 uint32_t const *destination_pitches)
158 {
159 return VDP_STATUS_NO_IMPLEMENTATION;
160 }
161
162 VdpStatus
163 vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface,
164 void const *const *source_data,
165 uint32_t const *source_pitches,
166 VdpRect const *destination_rect)
167 {
168 return VDP_STATUS_NO_IMPLEMENTATION;
169 }
170
171 VdpStatus
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)
179 {
180 return VDP_STATUS_NO_IMPLEMENTATION;
181 }
182
183 VdpStatus
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)
190 {
191 return VDP_STATUS_NO_IMPLEMENTATION;
192 }
193
194 VdpStatus
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,
201 uint32_t flags)
202 {
203 return VDP_STATUS_NO_IMPLEMENTATION;
204 }
205
206 VdpStatus
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,
213 uint32_t flags)
214 {
215 return VDP_STATUS_NO_IMPLEMENTATION;
216 }