output.c revision 06ddbc3b8e58a6cf22708263a8b7d16cf1db5dbc
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
37VdpStatus
38vlVdpOutputSurfaceCreate(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_video_context *context;
45   struct pipe_resource res_tmpl, *res;
46   struct pipe_sampler_view sv_templ;
47   struct pipe_surface surf_templ;
48
49   vlVdpOutputSurface *vlsurface = NULL;
50
51   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating output surface\n");
52   if (!(width && height))
53      return VDP_STATUS_INVALID_SIZE;
54
55   vlVdpDevice *dev = vlGetDataHTAB(device);
56   if (!dev)
57      return VDP_STATUS_INVALID_HANDLE;
58
59   pipe = dev->context->pipe;
60   context = dev->context->vpipe;
61   if (!pipe || !context)
62      return VDP_STATUS_INVALID_HANDLE;
63
64   vlsurface = CALLOC(1, sizeof(vlVdpOutputSurface));
65   if (!vlsurface)
66      return VDP_STATUS_RESOURCES;
67
68   memset(&res_tmpl, 0, sizeof(res_tmpl));
69
70   res_tmpl.target = PIPE_TEXTURE_2D;
71   res_tmpl.format = FormatRGBAToPipe(rgba_format);
72   res_tmpl.width0 = width;
73   res_tmpl.height0 = height;
74   res_tmpl.depth0 = 1;
75   res_tmpl.array_size = 1;
76   res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
77   res_tmpl.usage = PIPE_USAGE_STATIC;
78
79   res = context->screen->resource_create(context->screen, &res_tmpl);
80   if (!res) {
81      FREE(dev);
82      return VDP_STATUS_ERROR;
83   }
84
85   memset(&sv_templ, 0, sizeof(sv_templ));
86   u_sampler_view_default_template(&sv_templ, res, res->format);
87
88   // as long as we don't have a background picture we don't want an alpha channel
89   sv_templ.swizzle_a = PIPE_SWIZZLE_ONE;
90
91   vlsurface->sampler_view = pipe->create_sampler_view(pipe, res, &sv_templ);
92   if (!vlsurface->sampler_view) {
93      FREE(dev);
94      return VDP_STATUS_ERROR;
95   }
96
97   memset(&surf_templ, 0, sizeof(surf_templ));
98   surf_templ.format = res->format;
99   surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
100   vlsurface->surface = pipe->create_surface(pipe, res, &surf_templ);
101   if (!vlsurface->surface) {
102      FREE(dev);
103      return VDP_STATUS_ERROR;
104   }
105
106   *surface = vlAddDataHTAB(vlsurface);
107   if (*surface == 0) {
108      FREE(dev);
109      return VDP_STATUS_ERROR;
110   }
111
112   return VDP_STATUS_OK;
113}
114
115VdpStatus
116vlVdpOutputSurfaceDestroy(VdpOutputSurface surface)
117{
118   vlVdpOutputSurface *vlsurface;
119
120   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying output surface\n");
121
122   vlsurface = vlGetDataHTAB(surface);
123   if (!vlsurface)
124      return VDP_STATUS_INVALID_HANDLE;
125
126   pipe_surface_reference(&vlsurface->surface, NULL);
127   pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
128
129   vlRemoveDataHTAB(surface);
130   FREE(vlsurface);
131
132   return VDP_STATUS_OK;
133}
134
135VdpStatus
136vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface,
137                                VdpRGBAFormat *rgba_format,
138                                uint32_t *width, uint32_t *height)
139{
140   return VDP_STATUS_NO_IMPLEMENTATION;
141}
142
143VdpStatus
144vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface,
145                                VdpRect const *source_rect,
146                                void *const *destination_data,
147                                uint32_t const *destination_pitches)
148{
149   return VDP_STATUS_NO_IMPLEMENTATION;
150}
151
152VdpStatus
153vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface,
154                                void const *const *source_data,
155                                uint32_t const *source_pitches,
156                                VdpRect const *destination_rect)
157{
158   return VDP_STATUS_NO_IMPLEMENTATION;
159}
160
161VdpStatus
162vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface,
163                                 VdpIndexedFormat source_indexed_format,
164                                 void const *const *source_data,
165                                 uint32_t const *source_pitch,
166                                 VdpRect const *destination_rect,
167                                 VdpColorTableFormat color_table_format,
168                                 void const *color_table)
169{
170   return VDP_STATUS_NO_IMPLEMENTATION;
171}
172
173VdpStatus
174vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface,
175                               VdpYCbCrFormat source_ycbcr_format,
176                               void const *const *source_data,
177                               uint32_t const *source_pitches,
178                               VdpRect const *destination_rect,
179                               VdpCSCMatrix const *csc_matrix)
180{
181   return VDP_STATUS_NO_IMPLEMENTATION;
182}
183
184VdpStatus
185vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface,
186                                      VdpRect const *destination_rect,
187                                      VdpOutputSurface source_surface,
188                                      VdpRect const *source_rect,
189                                      VdpColor const *colors,
190                                      VdpOutputSurfaceRenderBlendState const *blend_state,
191                                      uint32_t flags)
192{
193   return VDP_STATUS_NO_IMPLEMENTATION;
194}
195
196VdpStatus
197vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface,
198                                      VdpRect const *destination_rect,
199                                      VdpBitmapSurface source_surface,
200                                      VdpRect const *source_rect,
201                                      VdpColor const *colors,
202                                      VdpOutputSurfaceRenderBlendState const *blend_state,
203                                      uint32_t flags)
204{
205   return VDP_STATUS_NO_IMPLEMENTATION;
206}
207