gallium: make g3dvl build again
[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 pf_get_block(template.format, &template.block);
49 template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
50
51 sfc->texture = vlGetPipeScreen(screen)->texture_create(vlGetPipeScreen(screen), &template);
52
53 if (!sfc->texture)
54 {
55 FREE(sfc);
56 return 1;
57 }
58
59 *surface = sfc;
60
61 return 0;
62 }
63
64 int vlDestroySurface
65 (
66 struct vlSurface *surface
67 )
68 {
69 assert(surface);
70
71 pipe_texture_reference(&surface->texture, NULL);
72 FREE(surface);
73
74 return 0;
75 }
76
77 int vlRenderMacroBlocksMpeg2
78 (
79 struct vlMpeg2MacroBlockBatch *batch,
80 struct vlSurface *surface
81 )
82 {
83 assert(batch);
84 assert(surface);
85 assert(surface->context);
86
87 surface->context->render->vlBegin(surface->context->render);
88
89 surface->context->render->vlRenderMacroBlocksMpeg2
90 (
91 surface->context->render,
92 batch,
93 surface
94 );
95
96 surface->context->render->vlEnd(surface->context->render);
97
98 return 0;
99 }
100
101 int vlPutPicture
102 (
103 struct vlSurface *surface,
104 vlNativeDrawable drawable,
105 int srcx,
106 int srcy,
107 int srcw,
108 int srch,
109 int destx,
110 int desty,
111 int destw,
112 int desth,
113 int drawable_w,
114 int drawable_h,
115 enum vlPictureType picture_type
116 )
117 {
118 struct vlCSC *csc;
119 struct pipe_context *pipe;
120
121 assert(surface);
122 assert(surface->context);
123
124 surface->context->render->vlFlush(surface->context->render);
125
126 csc = surface->context->csc;
127 pipe = surface->context->pipe;
128
129 csc->vlResizeFrameBuffer(csc, drawable_w, drawable_h);
130
131 csc->vlBegin(csc);
132
133 csc->vlPutPicture
134 (
135 csc,
136 surface,
137 srcx,
138 srcy,
139 srcw,
140 srch,
141 destx,
142 desty,
143 destw,
144 desth,
145 picture_type
146 );
147
148 csc->vlEnd(csc);
149
150 pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, &surface->disp_fence);
151
152 bind_pipe_drawable(pipe, drawable);
153
154 pipe->screen->flush_frontbuffer
155 (
156 pipe->screen,
157 csc->vlGetFrameBuffer(csc),
158 pipe->priv
159 );
160
161 return 0;
162 }
163
164 int vlSurfaceGetStatus
165 (
166 struct vlSurface *surface,
167 enum vlResourceStatus *status
168 )
169 {
170 assert(surface);
171 assert(surface->context);
172 assert(status);
173
174 if (surface->render_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->render_fence, 0))
175 {
176 *status = vlResourceStatusRendering;
177 return 0;
178 }
179
180 if (surface->disp_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->disp_fence, 0))
181 {
182 *status = vlResourceStatusDisplaying;
183 return 0;
184 }
185
186 *status = vlResourceStatusFree;
187
188 return 0;
189 }
190
191 int vlSurfaceFlush
192 (
193 struct vlSurface *surface
194 )
195 {
196 assert(surface);
197 assert(surface->context);
198
199 surface->context->render->vlFlush(surface->context->render);
200
201 return 0;
202 }
203
204 int vlSurfaceSync
205 (
206 struct vlSurface *surface
207 )
208 {
209 assert(surface);
210 assert(surface->context);
211 assert(surface->render_fence);
212
213 surface->context->pipe->screen->fence_finish(surface->context->pipe->screen, surface->render_fence, 0);
214
215 return 0;
216 }
217
218 struct vlScreen* vlSurfaceGetScreen
219 (
220 struct vlSurface *surface
221 )
222 {
223 assert(surface);
224
225 return surface->screen;
226 }
227
228 struct vlContext* vlBindToContext
229 (
230 struct vlSurface *surface,
231 struct vlContext *context
232 )
233 {
234 struct vlContext *old;
235
236 assert(surface);
237
238 old = surface->context;
239 surface->context = context;
240
241 return old;
242 }