Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[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 <stdlib.h>
5 #include <string.h>
6 #include <pipe/p_screen.h>
7 #include <pipe/p_state.h>
8 #include <pipe/p_inlines.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(1, sizeof(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 *surface = sfc;
55
56 return 0;
57 }
58
59 int vlDestroySurface
60 (
61 struct vlSurface *surface
62 )
63 {
64 assert(surface);
65
66 pipe_texture_release(&surface->texture);
67 free(surface);
68
69 return 0;
70 }
71
72 int vlRenderMacroBlocksMpeg2
73 (
74 struct vlMpeg2MacroBlockBatch *batch,
75 struct vlSurface *surface
76 )
77 {
78 assert(batch);
79 assert(surface);
80
81 surface->context->render->vlBegin(surface->context->render);
82
83 surface->context->render->vlRenderMacroBlocksMpeg2
84 (
85 surface->context->render,
86 batch,
87 surface
88 );
89
90 surface->context->render->vlEnd(surface->context->render);
91
92 return 0;
93 }
94
95 int vlPutPicture
96 (
97 struct vlSurface *surface,
98 vlNativeDrawable drawable,
99 int srcx,
100 int srcy,
101 int srcw,
102 int srch,
103 int destx,
104 int desty,
105 int destw,
106 int desth,
107 enum vlPictureType picture_type
108 )
109 {
110 struct vlCSC *csc;
111 struct pipe_context *pipe;
112
113 assert(surface);
114 assert(surface->context);
115
116 surface->context->render->vlFlush(surface->context->render);
117
118 csc = surface->context->csc;
119 pipe = surface->context->pipe;
120
121 csc->vlResizeFrameBuffer(csc, destw, desth);
122
123 csc->vlBegin(csc);
124
125 csc->vlPutPicture
126 (
127 csc,
128 surface,
129 srcx,
130 srcy,
131 srcw,
132 srch,
133 destx,
134 desty,
135 destw,
136 desth,
137 picture_type
138 );
139
140 csc->vlEnd(csc);
141
142 pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
143 bind_pipe_drawable(pipe, drawable);
144 /* TODO: Need to take destx, desty into consideration */
145 pipe->winsys->flush_frontbuffer
146 (
147 pipe->winsys,
148 csc->vlGetFrameBuffer(csc),
149 pipe->priv
150 );
151
152 return 0;
153 }
154
155 struct vlScreen* vlSurfaceGetScreen
156 (
157 struct vlSurface *surface
158 )
159 {
160 assert(surface);
161
162 return surface->screen;
163 }
164
165 struct vlContext* vlBindToContext
166 (
167 struct vlSurface *surface,
168 struct vlContext *context
169 )
170 {
171 struct vlContext *old;
172
173 assert(surface);
174
175 old = surface->context;
176 surface->context = context;
177
178 return old;
179 }