output.c revision e0cc970a54660035942ef8f8db122835e1407676
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
34#include "vdpau_private.h"
35
36VdpStatus
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   VDPAU_MSG(VDPAU_TRACE, "[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
85   // as long as we don't have a background picture we don't want an alpha channel
86   sv_templ.swizzle_a = PIPE_SWIZZLE_ONE;
87
88   vlsurface->sampler_view = context->create_sampler_view(context, res, &sv_templ);
89   if (!vlsurface->sampler_view) {
90      FREE(dev);
91      return VDP_STATUS_ERROR;
92   }
93
94   memset(&surf_templ, 0, sizeof(surf_templ));
95   surf_templ.format = res->format;
96   surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
97   vlsurface->surface = context->create_surface(context, res, &surf_templ);
98   if (!vlsurface->surface) {
99      FREE(dev);
100      return VDP_STATUS_ERROR;
101   }
102
103   *surface = vlAddDataHTAB(vlsurface);
104   if (*surface == 0) {
105      FREE(dev);
106      return VDP_STATUS_ERROR;
107   }
108
109   return VDP_STATUS_OK;
110}
111
112VdpStatus
113vlVdpOutputSurfaceDestroy(VdpOutputSurface surface)
114{
115   vlVdpOutputSurface *vlsurface;
116
117   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying output surface\n");
118
119   vlsurface = vlGetDataHTAB(surface);
120   if (!vlsurface)
121      return VDP_STATUS_INVALID_HANDLE;
122
123   pipe_surface_reference(&vlsurface->surface, NULL);
124   pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
125
126   vlRemoveDataHTAB(surface);
127   FREE(vlsurface);
128
129   return VDP_STATUS_OK;
130}
131
132VdpStatus
133vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface,
134                                VdpRGBAFormat *rgba_format,
135                                uint32_t *width, uint32_t *height)
136{
137   return VDP_STATUS_NO_IMPLEMENTATION;
138}
139
140VdpStatus
141vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface,
142                                VdpRect const *source_rect,
143                                void *const *destination_data,
144                                uint32_t const *destination_pitches)
145{
146   return VDP_STATUS_NO_IMPLEMENTATION;
147}
148
149VdpStatus
150vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface,
151                                void const *const *source_data,
152                                uint32_t const *source_pitches,
153                                VdpRect const *destination_rect)
154{
155   return VDP_STATUS_NO_IMPLEMENTATION;
156}
157
158VdpStatus
159vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface,
160                                 VdpIndexedFormat source_indexed_format,
161                                 void const *const *source_data,
162                                 uint32_t const *source_pitch,
163                                 VdpRect const *destination_rect,
164                                 VdpColorTableFormat color_table_format,
165                                 void const *color_table)
166{
167   return VDP_STATUS_NO_IMPLEMENTATION;
168}
169
170VdpStatus
171vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface,
172                               VdpYCbCrFormat source_ycbcr_format,
173                               void const *const *source_data,
174                               uint32_t const *source_pitches,
175                               VdpRect const *destination_rect,
176                               VdpCSCMatrix const *csc_matrix)
177{
178   return VDP_STATUS_NO_IMPLEMENTATION;
179}
180
181VdpStatus
182vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface,
183                                      VdpRect const *destination_rect,
184                                      VdpOutputSurface source_surface,
185                                      VdpRect const *source_rect,
186                                      VdpColor const *colors,
187                                      VdpOutputSurfaceRenderBlendState const *blend_state,
188                                      uint32_t flags)
189{
190   return VDP_STATUS_NO_IMPLEMENTATION;
191}
192
193VdpStatus
194vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface,
195                                      VdpRect const *destination_rect,
196                                      VdpBitmapSurface source_surface,
197                                      VdpRect const *source_rect,
198                                      VdpColor const *colors,
199                                      VdpOutputSurfaceRenderBlendState const *blend_state,
200                                      uint32_t flags)
201{
202   return VDP_STATUS_NO_IMPLEMENTATION;
203}
204