1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
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 **************************************************************************/
29 #include <X11/Xlibint.h>
30 #include <X11/extensions/XvMClib.h>
31 #include <vl_winsys.h>
32 #include <pipe/p_screen.h>
33 #include <pipe/p_video_context.h>
34 #include <pipe/p_state.h>
35 #include <util/u_memory.h>
36 #include <util/u_math.h>
37 #include "xvmc_private.h"
39 #define FOURCC_RGB 0x0000003
41 Status
XvMCCreateSubpicture(Display
*dpy
, XvMCContext
*context
, XvMCSubpicture
*subpicture
,
42 unsigned short width
, unsigned short height
, int xvimage_id
)
44 XvMCContextPrivate
*context_priv
;
45 XvMCSubpicturePrivate
*subpicture_priv
;
46 struct pipe_video_context
*vpipe
;
47 struct pipe_texture
template;
48 struct pipe_texture
*tex
;
50 XVMC_MSG(XVMC_TRACE
, "[XvMC] Creating subpicture %p.\n", subpicture
);
55 return XvMCBadContext
;
57 context_priv
= context
->privData
;
58 vpipe
= context_priv
->vctx
->vpipe
;
61 return XvMCBadSubpicture
;
63 /* TODO: Check against surface max width, height */
64 if (width
> 2048 || height
> 2048)
67 if (xvimage_id
!= FOURCC_RGB
)
70 subpicture_priv
= CALLOC(1, sizeof(XvMCSubpicturePrivate
));
74 memset(&template, 0, sizeof(struct pipe_texture
));
75 template.target
= PIPE_TEXTURE_2D
;
76 template.format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
77 template.last_level
= 0;
78 if (vpipe
->screen
->get_param(vpipe
->screen
, PIPE_CAP_NPOT_TEXTURES
)) {
79 template.width0
= width
;
80 template.height0
= height
;
83 template.width0
= util_next_power_of_two(width
);
84 template.height0
= util_next_power_of_two(height
);
87 template.tex_usage
= PIPE_TEXTURE_USAGE_SAMPLER
;
89 subpicture_priv
->context
= context
;
90 tex
= vpipe
->screen
->texture_create(vpipe
->screen
, &template);
91 subpicture_priv
->sfc
= vpipe
->screen
->get_tex_surface(vpipe
->screen
, tex
, 0, 0, 0,
92 PIPE_BUFFER_USAGE_CPU_WRITE
|
93 PIPE_BUFFER_USAGE_GPU_READ
);
94 pipe_texture_reference(&tex
, NULL
);
95 if (!subpicture_priv
->sfc
)
97 FREE(subpicture_priv
);
101 subpicture
->subpicture_id
= XAllocID(dpy
);
102 subpicture
->context_id
= context
->context_id
;
103 subpicture
->xvimage_id
= xvimage_id
;
104 subpicture
->width
= width
;
105 subpicture
->height
= height
;
106 subpicture
->num_palette_entries
= 0;
107 subpicture
->entry_bytes
= 0;
108 subpicture
->component_order
[0] = 0;
109 subpicture
->component_order
[1] = 0;
110 subpicture
->component_order
[2] = 0;
111 subpicture
->component_order
[3] = 0;
112 subpicture
->privData
= subpicture_priv
;
116 XVMC_MSG(XVMC_TRACE
, "[XvMC] Subpicture %p created.\n", subpicture
);
121 Status
XvMCClearSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
, short x
, short y
,
122 unsigned short width
, unsigned short height
, unsigned int color
)
124 XvMCSubpicturePrivate
*subpicture_priv
;
125 XvMCContextPrivate
*context_priv
;
130 return XvMCBadSubpicture
;
132 subpicture_priv
= subpicture
->privData
;
133 context_priv
= subpicture_priv
->context
->privData
;
134 /* TODO: Assert clear rect is within bounds? Or clip? */
135 context_priv
->vctx
->vpipe
->surface_fill(context_priv
->vctx
->vpipe
,
136 subpicture_priv
->sfc
, x
, y
,
137 width
, height
, color
);
142 Status
XvMCCompositeSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
, XvImage
*image
,
143 short srcx
, short srcy
, unsigned short width
, unsigned short height
,
144 short dstx
, short dsty
)
146 XvMCSubpicturePrivate
*subpicture_priv
;
147 XvMCContextPrivate
*context_priv
;
148 struct pipe_screen
*screen
;
149 struct pipe_transfer
*xfer
;
150 unsigned char *src
, *dst
;
153 XVMC_MSG(XVMC_TRACE
, "[XvMC] Compositing subpicture %p.\n", subpicture
);
158 return XvMCBadSubpicture
;
162 if (subpicture
->xvimage_id
!= image
->id
)
165 /* No planar support for now */
166 if (image
->num_planes
!= 1)
169 subpicture_priv
= subpicture
->privData
;
170 context_priv
= subpicture_priv
->context
->privData
;
171 screen
= context_priv
->vctx
->vpipe
->screen
;
173 /* TODO: Assert rects are within bounds? Or clip? */
175 xfer
= screen
->get_tex_transfer(screen
, subpicture_priv
->sfc
->texture
, 0, 0, 0,
176 PIPE_TRANSFER_WRITE
, dstx
, dsty
, width
, height
);
181 dst
= screen
->transfer_map(screen
, xfer
);
183 screen
->tex_transfer_destroy(xfer
);
190 assert(subpicture_priv
->sfc
->format
== PIPE_FORMAT_X8R8G8B8_UNORM
);
191 for (y
= 0; y
< height
; ++y
) {
192 for (x
= 0; x
< width
; ++x
, src
+= 3, dst
+= 4) {
193 /* TODO: Confirm or fix */
204 screen
->transfer_unmap(screen
, xfer
);
205 screen
->tex_transfer_destroy(xfer
);
207 XVMC_MSG(XVMC_TRACE
, "[XvMC] Subpicture %p composited.\n", subpicture
);
212 Status
XvMCDestroySubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
)
214 XvMCSubpicturePrivate
*subpicture_priv
;
216 XVMC_MSG(XVMC_TRACE
, "[XvMC] Destroying subpicture %p.\n", subpicture
);
221 return XvMCBadSubpicture
;
223 subpicture_priv
= subpicture
->privData
;
224 pipe_surface_reference(&subpicture_priv
->sfc
, NULL
);
225 FREE(subpicture_priv
);
227 XVMC_MSG(XVMC_TRACE
, "[XvMC] Subpicture %p destroyed.\n", subpicture
);
232 Status
XvMCSetSubpicturePalette(Display
*dpy
, XvMCSubpicture
*subpicture
, unsigned char *palette
)
237 return XvMCBadSubpicture
;
241 /* We don't support paletted subpictures */
245 Status
XvMCBlendSubpicture(Display
*dpy
, XvMCSurface
*target_surface
, XvMCSubpicture
*subpicture
,
246 short subx
, short suby
, unsigned short subw
, unsigned short subh
,
247 short surfx
, short surfy
, unsigned short surfw
, unsigned short surfh
)
249 XvMCSurfacePrivate
*surface_priv
;
250 XvMCSubpicturePrivate
*subpicture_priv
;
252 XVMC_MSG(XVMC_TRACE
, "[XvMC] Associating subpicture %p with surface %p.\n", subpicture
, target_surface
);
257 return XvMCBadSurface
;
260 return XvMCBadSubpicture
;
262 if (target_surface
->context_id
!= subpicture
->context_id
)
265 /* TODO: Verify against subpicture independent scaling */
267 surface_priv
= target_surface
->privData
;
268 subpicture_priv
= subpicture
->privData
;
270 /* TODO: Assert rects are within bounds? Or clip? */
272 surface_priv
->subpicture
= subpicture
;
273 surface_priv
->subx
= subx
;
274 surface_priv
->suby
= suby
;
275 surface_priv
->subw
= subw
;
276 surface_priv
->subh
= subh
;
277 surface_priv
->surfx
= surfx
;
278 surface_priv
->surfy
= surfy
;
279 surface_priv
->surfw
= surfw
;
280 surface_priv
->surfh
= surfh
;
281 subpicture_priv
->surface
= target_surface
;
286 Status
XvMCBlendSubpicture2(Display
*dpy
, XvMCSurface
*source_surface
, XvMCSurface
*target_surface
,
287 XvMCSubpicture
*subpicture
, short subx
, short suby
, unsigned short subw
, unsigned short subh
,
288 short surfx
, short surfy
, unsigned short surfw
, unsigned short surfh
)
292 if (!source_surface
|| !target_surface
)
293 return XvMCBadSurface
;
296 return XvMCBadSubpicture
;
298 if (source_surface
->context_id
!= subpicture
->context_id
)
301 if (source_surface
->context_id
!= subpicture
->context_id
)
304 /* TODO: Assert rects are within bounds? Or clip? */
309 Status
XvMCSyncSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
)
314 return XvMCBadSubpicture
;
319 Status
XvMCFlushSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
)
324 return XvMCBadSubpicture
;
329 Status
XvMCGetSubpictureStatus(Display
*dpy
, XvMCSubpicture
*subpicture
, int *status
)
334 return XvMCBadSubpicture
;