Merge branch 'master' into pipe-video
[mesa.git] / src / gallium / state_trackers / xorg / xvmc / subpicture.c
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include <assert.h>
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"
38
39 #define FOURCC_RGB 0x0000003
40
41 Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture,
42 unsigned short width, unsigned short height, int xvimage_id)
43 {
44 XvMCContextPrivate *context_priv;
45 XvMCSubPicturePrivate *subpicture_priv;
46 struct pipe_video_context *vpipe;
47 struct pipe_texture template;
48 struct pipe_texture *tex;
49
50 assert(dpy);
51
52 if (!context)
53 return XvMCBadContext;
54
55 context_priv = context->privData;
56 vpipe = context_priv->vctx->vpipe;
57
58 if (!subpicture)
59 return XvMCBadSubpicture;
60
61 if (width > 2048 || height > 2048)
62 return BadValue;
63
64 if (xvimage_id != FOURCC_RGB)
65 return BadMatch;
66
67 subpicture_priv = CALLOC(1, sizeof(XvMCSubPicturePrivate));
68 if (!subpicture_priv)
69 return BadAlloc;
70
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;
78 }
79 else {
80 template.width0 = util_next_power_of_two(width);
81 template.height0 = util_next_power_of_two(height);
82 }
83 template.depth0 = 1;
84 template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
85
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)
92 {
93 FREE(subpicture_priv);
94 return BadAlloc;
95 }
96
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;
109
110 SyncHandle();
111
112 return Success;
113 }
114
115 Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, short y,
116 unsigned short width, unsigned short height, unsigned int color)
117 {
118 XvMCSubPicturePrivate *subpicture_priv;
119 XvMCContextPrivate *context_priv;
120 assert(dpy);
121
122 if (!subpicture)
123 return XvMCBadSubpicture;
124
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);
131
132 return Success;
133 }
134
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)
138 {
139 assert(dpy);
140
141 if (!subpicture)
142 return XvMCBadSubpicture;
143
144 assert(image);
145
146 if (subpicture->xvimage_id != image->id)
147 return BadMatch;
148
149 /* TODO: Assert rects are within bounds? Or clip? */
150
151 return Success;
152 }
153
154 Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture)
155 {
156 XvMCSubPicturePrivate *subpicture_priv;
157
158 assert(dpy);
159
160 if (!subpicture)
161 return XvMCBadSubpicture;
162
163 subpicture_priv = subpicture->privData;
164 pipe_surface_reference(&subpicture_priv->sfc, NULL);
165 FREE(subpicture_priv);
166
167 return Success;
168 }
169
170 Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsigned char *palette)
171 {
172 assert(dpy);
173
174 if (!subpicture)
175 return XvMCBadSubpicture;
176
177 assert(palette);
178
179 /* We don't support paletted subpictures */
180 return BadMatch;
181 }
182
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)
186 {
187 assert(dpy);
188
189 if (!target_surface)
190 return XvMCBadSurface;
191
192 if (!subpicture)
193 return XvMCBadSubpicture;
194
195 if (target_surface->context_id != subpicture->context_id)
196 return BadMatch;
197
198 /* TODO: Assert rects are within bounds? Or clip? */
199 return Success;
200 }
201
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)
205 {
206 assert(dpy);
207
208 if (!source_surface || !target_surface)
209 return XvMCBadSurface;
210
211 if (!subpicture)
212 return XvMCBadSubpicture;
213
214 if (source_surface->context_id != subpicture->context_id)
215 return BadMatch;
216
217 if (source_surface->context_id != subpicture->context_id)
218 return BadMatch;
219
220 /* TODO: Assert rects are within bounds? Or clip? */
221 return Success;
222 }
223
224 Status XvMCSyncSubpicture(Display *dpy, XvMCSubpicture *subpicture)
225 {
226 assert(dpy);
227
228 if (!subpicture)
229 return XvMCBadSubpicture;
230
231 return Success;
232 }
233
234 Status XvMCFlushSubpicture(Display *dpy, XvMCSubpicture *subpicture)
235 {
236 assert(dpy);
237
238 if (!subpicture)
239 return XvMCBadSubpicture;
240
241 return Success;
242 }
243
244 Status XvMCGetSubpictureStatus(Display *dpy, XvMCSubpicture *subpicture, int *status)
245 {
246 assert(dpy);
247
248 if (!subpicture)
249 return XvMCBadSubpicture;
250
251 assert(status);
252
253 /* TODO */
254 *status = 0;
255
256 return Success;
257 }