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
;
53 return XvMCBadContext
;
55 context_priv
= context
->privData
;
56 vpipe
= context_priv
->vctx
->vpipe
;
59 return XvMCBadSubpicture
;
61 if (width
> 2048 || height
> 2048)
64 if (xvimage_id
!= FOURCC_RGB
)
67 subpicture_priv
= CALLOC(1, sizeof(XvMCSubPicturePrivate
));
71 memset(&template, 0, sizeof(struct pipe_texture
));
72 template.target
= PIPE_TEXTURE_2D
;
73 template.format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
74 template.last_level
= 0;
75 if (vpipe
->screen
->get_param(vpipe
->screen
, PIPE_CAP_NPOT_TEXTURES
)) {
76 template.width0
= width
;
77 template.height0
= height
;
80 template.width0
= util_next_power_of_two(width
);
81 template.height0
= util_next_power_of_two(height
);
84 template.tex_usage
= PIPE_TEXTURE_USAGE_SAMPLER
| PIPE_TEXTURE_USAGE_RENDER_TARGET
;
86 subpicture_priv
->context
= context
;
87 tex
= vpipe
->screen
->texture_create(vpipe
->screen
, &template);
88 subpicture_priv
->sfc
= vpipe
->screen
->get_tex_surface(vpipe
->screen
, tex
, 0, 0, 0,
89 PIPE_BUFFER_USAGE_GPU_READ_WRITE
);
90 pipe_texture_reference(&tex
, NULL
);
91 if (!subpicture_priv
->sfc
)
93 FREE(subpicture_priv
);
97 subpicture
->subpicture_id
= XAllocID(dpy
);
98 subpicture
->context_id
= context
->context_id
;
99 subpicture
->xvimage_id
= xvimage_id
;
100 subpicture
->width
= width
;
101 subpicture
->height
= height
;
102 subpicture
->num_palette_entries
= 0;
103 subpicture
->entry_bytes
= 0;
104 subpicture
->component_order
[0] = 0;
105 subpicture
->component_order
[1] = 0;
106 subpicture
->component_order
[2] = 0;
107 subpicture
->component_order
[3] = 0;
108 subpicture
->privData
= subpicture_priv
;
115 Status
XvMCClearSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
, short x
, short y
,
116 unsigned short width
, unsigned short height
, unsigned int color
)
118 XvMCSubPicturePrivate
*subpicture_priv
;
119 XvMCContextPrivate
*context_priv
;
123 return XvMCBadSubpicture
;
125 subpicture_priv
= subpicture
->privData
;
126 context_priv
= subpicture_priv
->context
->privData
;
127 /* TODO: Assert clear rect is within bounds? Or clip? */
128 context_priv
->vctx
->vpipe
->surface_fill(context_priv
->vctx
->vpipe
,
129 subpicture_priv
->sfc
, x
, y
,
130 width
, height
, color
);
135 Status
XvMCCompositeSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
, XvImage
*image
,
136 short srcx
, short srcy
, unsigned short width
, unsigned short height
,
137 short dstx
, short dsty
)
142 return XvMCBadSubpicture
;
146 if (subpicture
->xvimage_id
!= image
->id
)
149 /* TODO: Assert rects are within bounds? Or clip? */
154 Status
XvMCDestroySubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
)
156 XvMCSubPicturePrivate
*subpicture_priv
;
161 return XvMCBadSubpicture
;
163 subpicture_priv
= subpicture
->privData
;
164 pipe_surface_reference(&subpicture_priv
->sfc
, NULL
);
165 FREE(subpicture_priv
);
170 Status
XvMCSetSubpicturePalette(Display
*dpy
, XvMCSubpicture
*subpicture
, unsigned char *palette
)
175 return XvMCBadSubpicture
;
179 /* We don't support paletted subpictures */
183 Status
XvMCBlendSubpicture(Display
*dpy
, XvMCSurface
*target_surface
, XvMCSubpicture
*subpicture
,
184 short subx
, short suby
, unsigned short subw
, unsigned short subh
,
185 short surfx
, short surfy
, unsigned short surfw
, unsigned short surfh
)
190 return XvMCBadSurface
;
193 return XvMCBadSubpicture
;
195 if (target_surface
->context_id
!= subpicture
->context_id
)
198 /* TODO: Assert rects are within bounds? Or clip? */
202 Status
XvMCBlendSubpicture2(Display
*dpy
, XvMCSurface
*source_surface
, XvMCSurface
*target_surface
,
203 XvMCSubpicture
*subpicture
, short subx
, short suby
, unsigned short subw
, unsigned short subh
,
204 short surfx
, short surfy
, unsigned short surfw
, unsigned short surfh
)
208 if (!source_surface
|| !target_surface
)
209 return XvMCBadSurface
;
212 return XvMCBadSubpicture
;
214 if (source_surface
->context_id
!= subpicture
->context_id
)
217 if (source_surface
->context_id
!= subpicture
->context_id
)
220 /* TODO: Assert rects are within bounds? Or clip? */
224 Status
XvMCSyncSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
)
229 return XvMCBadSubpicture
;
234 Status
XvMCFlushSubpicture(Display
*dpy
, XvMCSubpicture
*subpicture
)
239 return XvMCBadSubpicture
;
244 Status
XvMCGetSubpictureStatus(Display
*dpy
, XvMCSubpicture
*subpicture
, int *status
)
249 return XvMCBadSubpicture
;