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