1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include <vdpau/vdpau.h>
30 #include "util/u_memory.h"
31 #include "util/u_sampler.h"
33 #include "vdpau_private.h"
36 * Create a VdpBitmapSurface.
39 vlVdpBitmapSurfaceCreate(VdpDevice device
,
40 VdpRGBAFormat rgba_format
,
41 uint32_t width
, uint32_t height
,
42 VdpBool frequently_accessed
,
43 VdpBitmapSurface
*surface
)
45 struct pipe_context
*pipe
;
46 struct pipe_resource res_tmpl
, *res
;
47 struct pipe_sampler_view sv_templ
;
49 vlVdpBitmapSurface
*vlsurface
= NULL
;
51 if (!(width
&& height
))
52 return VDP_STATUS_INVALID_SIZE
;
54 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
56 return VDP_STATUS_INVALID_HANDLE
;
60 return VDP_STATUS_INVALID_HANDLE
;
63 return VDP_STATUS_INVALID_POINTER
;
65 vlsurface
= CALLOC(1, sizeof(vlVdpBitmapSurface
));
67 return VDP_STATUS_RESOURCES
;
69 vlsurface
->device
= dev
;
71 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
72 res_tmpl
.target
= PIPE_TEXTURE_2D
;
73 res_tmpl
.format
= FormatRGBAToPipe(rgba_format
);
74 res_tmpl
.width0
= width
;
75 res_tmpl
.height0
= height
;
77 res_tmpl
.array_size
= 1;
78 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
79 res_tmpl
.usage
= frequently_accessed
? PIPE_USAGE_DYNAMIC
: PIPE_USAGE_STATIC
;
81 pipe_mutex_lock(dev
->mutex
);
82 res
= pipe
->screen
->resource_create(pipe
->screen
, &res_tmpl
);
84 pipe_mutex_unlock(dev
->mutex
);
86 return VDP_STATUS_RESOURCES
;
89 vlVdpDefaultSamplerViewTemplate(&sv_templ
, res
);
90 vlsurface
->sampler_view
= pipe
->create_sampler_view(pipe
, res
, &sv_templ
);
92 pipe_resource_reference(&res
, NULL
);
93 pipe_mutex_unlock(dev
->mutex
);
95 if (!vlsurface
->sampler_view
) {
97 return VDP_STATUS_RESOURCES
;
100 *surface
= vlAddDataHTAB(vlsurface
);
103 return VDP_STATUS_ERROR
;
106 return VDP_STATUS_OK
;
110 * Destroy a VdpBitmapSurface.
113 vlVdpBitmapSurfaceDestroy(VdpBitmapSurface surface
)
115 vlVdpBitmapSurface
*vlsurface
;
117 vlsurface
= vlGetDataHTAB(surface
);
119 return VDP_STATUS_INVALID_HANDLE
;
121 pipe_mutex_lock(vlsurface
->device
->mutex
);
122 pipe_sampler_view_reference(&vlsurface
->sampler_view
, NULL
);
123 pipe_mutex_unlock(vlsurface
->device
->mutex
);
125 vlRemoveDataHTAB(surface
);
128 return VDP_STATUS_OK
;
132 * Retrieve the parameters used to create a VdpBitmapSurface.
135 vlVdpBitmapSurfaceGetParameters(VdpBitmapSurface surface
,
136 VdpRGBAFormat
*rgba_format
,
137 uint32_t *width
, uint32_t *height
,
138 VdpBool
*frequently_accessed
)
140 vlVdpBitmapSurface
*vlsurface
;
141 struct pipe_resource
*res
;
143 vlsurface
= vlGetDataHTAB(surface
);
145 return VDP_STATUS_INVALID_HANDLE
;
147 if (!(rgba_format
&& width
&& height
&& frequently_accessed
))
148 return VDP_STATUS_INVALID_POINTER
;
150 res
= vlsurface
->sampler_view
->texture
;
151 *rgba_format
= PipeToFormatRGBA(res
->format
);
152 *width
= res
->width0
;
153 *height
= res
->height0
;
154 *frequently_accessed
= res
->usage
== PIPE_USAGE_DYNAMIC
;
156 return VDP_STATUS_OK
;
160 * Copy image data from application memory in the surface's native format to
161 * a VdpBitmapSurface.
164 vlVdpBitmapSurfacePutBitsNative(VdpBitmapSurface surface
,
165 void const *const *source_data
,
166 uint32_t const *source_pitches
,
167 VdpRect
const *destination_rect
)
169 vlVdpBitmapSurface
*vlsurface
;
170 struct pipe_box dst_box
;
171 struct pipe_context
*pipe
;
173 vlsurface
= vlGetDataHTAB(surface
);
175 return VDP_STATUS_INVALID_HANDLE
;
177 if (!(source_data
&& source_pitches
))
178 return VDP_STATUS_INVALID_POINTER
;
180 pipe
= vlsurface
->device
->context
;
182 pipe_mutex_lock(vlsurface
->device
->mutex
);
184 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
186 dst_box
= RectToPipeBox(destination_rect
, vlsurface
->sampler_view
->texture
);
187 pipe
->transfer_inline_write(pipe
, vlsurface
->sampler_view
->texture
, 0,
188 PIPE_TRANSFER_WRITE
, &dst_box
, *source_data
,
191 pipe_mutex_unlock(vlsurface
->device
->mutex
);
193 return VDP_STATUS_OK
;