output.c revision 2516a4654463322fede7cd17085dc4dbe92d324e
1d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)/**************************************************************************
2d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) *
3d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * Copyright 2010 Thomas Balling Sørensen.
4d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * Copyright 2011 Christian König.
5d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * All Rights Reserved.
6d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) *
7d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * Permission is hereby granted, free of charge, to any person obtaining a
8d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * copy of this software and associated documentation files (the
9d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * "Software"), to deal in the Software without restriction, including
10d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * without limitation the rights to use, copy, modify, merge, publish,
11d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * distribute, sub license, and/or sell copies of the Software, and to
12d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * permit persons to whom the Software is furnished to do so, subject to
13c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) * the following conditions:
14d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) *
15d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * The above copyright notice and this permission notice (including the
16d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * next paragraph) shall be included in all copies or substantial portions
175d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) * of the Software.
18d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) *
19d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
235d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) *
27d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) **************************************************************************/
28d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
29d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include <vdpau/vdpau.h>
30d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
31d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include <util/u_debug.h>
32d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include <util/u_memory.h>
33d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
34d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "vdpau_private.h"
35d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
36c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)VdpStatus
37vlVdpOutputSurfaceCreate(VdpDevice device,
38                         VdpRGBAFormat rgba_format,
39                         uint32_t width, uint32_t height,
40                         VdpOutputSurface  *surface)
41{
42   struct pipe_video_context *context;
43   struct pipe_resource res_tmpl, *res;
44   struct pipe_sampler_view sv_templ;
45   struct pipe_surface surf_templ;
46
47   vlVdpOutputSurface *vlsurface = NULL;
48
49   debug_printf("[VDPAU] Creating output surface\n");
50   if (!(width && height))
51      return VDP_STATUS_INVALID_SIZE;
52
53   vlVdpDevice *dev = vlGetDataHTAB(device);
54   if (!dev)
55      return VDP_STATUS_INVALID_HANDLE;
56
57   context = dev->context->vpipe;
58   if (!context)
59      return VDP_STATUS_INVALID_HANDLE;
60
61   vlsurface = CALLOC(1, sizeof(vlVdpOutputSurface));
62   if (!vlsurface)
63      return VDP_STATUS_RESOURCES;
64
65   memset(&res_tmpl, 0, sizeof(res_tmpl));
66
67   res_tmpl.target = PIPE_TEXTURE_2D;
68   res_tmpl.format = FormatRGBAToPipe(rgba_format);
69   res_tmpl.width0 = width;
70   res_tmpl.height0 = height;
71   res_tmpl.depth0 = 1;
72   res_tmpl.array_size = 1;
73   res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
74   res_tmpl.usage = PIPE_USAGE_STATIC;
75
76   res = context->screen->resource_create(context->screen, &res_tmpl);
77   if (!res) {
78      FREE(dev);
79      return VDP_STATUS_ERROR;
80   }
81
82   memset(&sv_templ, 0, sizeof(sv_templ));
83   u_sampler_view_default_template(&sv_templ, res, res->format);
84   vlsurface->sampler_view = context->create_sampler_view(context, res, &sv_templ);
85   if (!vlsurface->sampler_view) {
86      FREE(dev);
87      return VDP_STATUS_ERROR;
88   }
89
90   memset(&surf_templ, 0, sizeof(surf_templ));
91   surf_templ.format = res->format;
92   surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
93   vlsurface->surface = context->create_surface(context, res, &surf_templ);
94   if (!vlsurface->surface) {
95      FREE(dev);
96      return VDP_STATUS_ERROR;
97   }
98
99   *surface = vlAddDataHTAB(vlsurface);
100   if (*surface == 0) {
101      FREE(dev);
102      return VDP_STATUS_ERROR;
103   }
104
105   return VDP_STATUS_OK;
106}
107
108VdpStatus
109vlVdpOutputSurfaceDestroy(VdpOutputSurface surface)
110{
111   vlVdpOutputSurface *vlsurface;
112
113   debug_printf("[VDPAU] Destroying output surface\n");
114
115   vlsurface = vlGetDataHTAB(surface);
116   if (!vlsurface)
117      return VDP_STATUS_INVALID_HANDLE;
118
119   pipe_surface_reference(&vlsurface->surface, NULL);
120   pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
121
122   vlRemoveDataHTAB(surface);
123   FREE(vlsurface);
124
125   return VDP_STATUS_OK;
126}
127
128VdpStatus
129vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface,
130                                VdpRGBAFormat *rgba_format,
131                                uint32_t *width, uint32_t *height)
132{
133   return VDP_STATUS_NO_IMPLEMENTATION;
134}
135
136VdpStatus
137vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface,
138                                VdpRect const *source_rect,
139                                void *const *destination_data,
140                                uint32_t const *destination_pitches)
141{
142   return VDP_STATUS_NO_IMPLEMENTATION;
143}
144
145VdpStatus
146vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface,
147                                void const *const *source_data,
148                                uint32_t const *source_pitches,
149                                VdpRect const *destination_rect)
150{
151   return VDP_STATUS_NO_IMPLEMENTATION;
152}
153
154VdpStatus
155vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface,
156                                 VdpIndexedFormat source_indexed_format,
157                                 void const *const *source_data,
158                                 uint32_t const *source_pitch,
159                                 VdpRect const *destination_rect,
160                                 VdpColorTableFormat color_table_format,
161                                 void const *color_table)
162{
163   return VDP_STATUS_NO_IMPLEMENTATION;
164}
165
166VdpStatus
167vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface,
168                               VdpYCbCrFormat source_ycbcr_format,
169                               void const *const *source_data,
170                               uint32_t const *source_pitches,
171                               VdpRect const *destination_rect,
172                               VdpCSCMatrix const *csc_matrix)
173{
174   return VDP_STATUS_NO_IMPLEMENTATION;
175}
176
177VdpStatus
178vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface,
179                                      VdpRect const *destination_rect,
180                                      VdpOutputSurface source_surface,
181                                      VdpRect const *source_rect,
182                                      VdpColor const *colors,
183                                      VdpOutputSurfaceRenderBlendState const *blend_state,
184                                      uint32_t flags)
185{
186   return VDP_STATUS_NO_IMPLEMENTATION;
187}
188
189VdpStatus
190vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface,
191                                      VdpRect const *destination_rect,
192                                      VdpBitmapSurface source_surface,
193                                      VdpRect const *source_rect,
194                                      VdpColor const *colors,
195                                      VdpOutputSurfaceRenderBlendState const *blend_state,
196                                      uint32_t flags)
197{
198   return VDP_STATUS_NO_IMPLEMENTATION;
199}
200