g3dvl: Modularized rendering, refactored to accommodate VAAPI, other APIs.
[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 csc = surface->context->csc;
117 pipe = surface->context->pipe;
118
119 csc->vlResizeFrameBuffer(csc, destw, desth);
120
121 csc->vlBegin(csc);
122
123 csc->vlPutPicture
124 (
125 csc,
126 surface,
127 srcx,
128 srcy,
129 srcw,
130 srch,
131 destx,
132 desty,
133 destw,
134 desth,
135 picture_type
136 );
137
138 csc->vlEnd(csc);
139
140 pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
141 bind_pipe_drawable(pipe, drawable);
142 /* TODO: Need to take destx, desty into consideration */
143 pipe->winsys->flush_frontbuffer
144 (
145 pipe->winsys,
146 csc->vlGetFrameBuffer(csc),
147 pipe->priv
148 );
149
150 return 0;
151 }
152
153 struct vlScreen* vlSurfaceGetScreen
154 (
155 struct vlSurface *surface
156 )
157 {
158 assert(surface);
159
160 return surface->screen;
161 }
162
163 struct vlContext* vlBindToContext
164 (
165 struct vlSurface *surface,
166 struct vlContext *context
167 )
168 {
169 struct vlContext *old;
170
171 assert(surface);
172
173 old = surface->context;
174 surface->context = context;
175
176 return old;
177 }