Merge commit 'origin/gallium-0.2' into gallium-0.2
[mesa.git] / src / gallium / state_trackers / g3dvl / vl_surface.c
1 #define VL_INTERNAL
2 #include "vl_surface.h"
3 #include <assert.h>
4 #include <string.h>
5 #include <pipe/p_screen.h>
6 #include <pipe/p_state.h>
7 #include <pipe/p_inlines.h>
8 #include <util/u_memory.h>
9 #include <vl_winsys.h>
10 #include "vl_screen.h"
11 #include "vl_context.h"
12 #include "vl_render.h"
13 #include "vl_csc.h"
14 #include "vl_util.h"
15
16 int vlCreateSurface
17 (
18 struct vlScreen *screen,
19 unsigned int width,
20 unsigned int height,
21 enum vlFormat format,
22 struct vlSurface **surface
23 )
24 {
25 struct vlSurface *sfc;
26 struct pipe_texture template;
27
28 assert(screen);
29 assert(surface);
30
31 sfc = CALLOC_STRUCT(vlSurface);
32
33 if (!sfc)
34 return 1;
35
36 sfc->screen = screen;
37 sfc->width = width;
38 sfc->height = height;
39 sfc->format = format;
40
41 memset(&template, 0, sizeof(struct pipe_texture));
42 template.target = PIPE_TEXTURE_2D;
43 template.format = PIPE_FORMAT_A8R8G8B8_UNORM;
44 template.last_level = 0;
45 template.width[0] = vlRoundUpPOT(sfc->width);
46 template.height[0] = vlRoundUpPOT(sfc->height);
47 template.depth[0] = 1;
48 template.compressed = 0;
49 pf_get_block(template.format, &template.block);
50 template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
51
52 sfc->texture = vlGetPipeScreen(screen)->texture_create(vlGetPipeScreen(screen), &template);
53
54 if (!sfc->texture)
55 {
56 FREE(sfc);
57 return 1;
58 }
59
60 *surface = sfc;
61
62 return 0;
63 }
64
65 int vlDestroySurface
66 (
67 struct vlSurface *surface
68 )
69 {
70 assert(surface);
71
72 pipe_texture_reference(&surface->texture, NULL);
73 FREE(surface);
74
75 return 0;
76 }
77
78 int vlRenderMacroBlocksMpeg2
79 (
80 struct vlMpeg2MacroBlockBatch *batch,
81 struct vlSurface *surface
82 )
83 {
84 assert(batch);
85 assert(surface);
86 assert(surface->context);
87
88 surface->context->render->vlBegin(surface->context->render);
89
90 surface->context->render->vlRenderMacroBlocksMpeg2
91 (
92 surface->context->render,
93 batch,
94 surface
95 );
96
97 surface->context->render->vlEnd(surface->context->render);
98
99 return 0;
100 }
101
102 int vlPutPicture
103 (
104 struct vlSurface *surface,
105 vlNativeDrawable drawable,
106 int srcx,
107 int srcy,
108 int srcw,
109 int srch,
110 int destx,
111 int desty,
112 int destw,
113 int desth,
114 int drawable_w,
115 int drawable_h,
116 enum vlPictureType picture_type
117 )
118 {
119 struct vlCSC *csc;
120 struct pipe_context *pipe;
121
122 assert(surface);
123 assert(surface->context);
124
125 surface->context->render->vlFlush(surface->context->render);
126
127 csc = surface->context->csc;
128 pipe = surface->context->pipe;
129
130 csc->vlResizeFrameBuffer(csc, drawable_w, drawable_h);
131
132 csc->vlBegin(csc);
133
134 csc->vlPutPicture
135 (
136 csc,
137 surface,
138 srcx,
139 srcy,
140 srcw,
141 srch,
142 destx,
143 desty,
144 destw,
145 desth,
146 picture_type
147 );
148
149 csc->vlEnd(csc);
150
151 pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, &surface->disp_fence);
152
153 bind_pipe_drawable(pipe, drawable);
154
155 pipe->screen->flush_frontbuffer
156 (
157 pipe->screen,
158 csc->vlGetFrameBuffer(csc),
159 pipe->priv
160 );
161
162 return 0;
163 }
164
165 int vlSurfaceGetStatus
166 (
167 struct vlSurface *surface,
168 enum vlResourceStatus *status
169 )
170 {
171 assert(surface);
172 assert(surface->context);
173 assert(status);
174
175 if (surface->render_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->render_fence, 0))
176 {
177 *status = vlResourceStatusRendering;
178 return 0;
179 }
180
181 if (surface->disp_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->disp_fence, 0))
182 {
183 *status = vlResourceStatusDisplaying;
184 return 0;
185 }
186
187 *status = vlResourceStatusFree;
188
189 return 0;
190 }
191
192 int vlSurfaceFlush
193 (
194 struct vlSurface *surface
195 )
196 {
197 assert(surface);
198 assert(surface->context);
199
200 surface->context->render->vlFlush(surface->context->render);
201
202 return 0;
203 }
204
205 int vlSurfaceSync
206 (
207 struct vlSurface *surface
208 )
209 {
210 assert(surface);
211 assert(surface->context);
212 assert(surface->render_fence);
213
214 surface->context->pipe->screen->fence_finish(surface->context->pipe->screen, surface->render_fence, 0);
215
216 return 0;
217 }
218
219 struct vlScreen* vlSurfaceGetScreen
220 (
221 struct vlSurface *surface
222 )
223 {
224 assert(surface);
225
226 return surface->screen;
227 }
228
229 struct vlContext* vlBindToContext
230 (
231 struct vlSurface *surface,
232 struct vlContext *context
233 )
234 {
235 struct vlContext *old;
236
237 assert(surface);
238
239 old = surface->context;
240 surface->context = context;
241
242 return old;
243 }