[g3dvl] static usage for intermediate buffer
[mesa.git] / src / gallium / auxiliary / vl / vl_compositor.c
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "vl_compositor.h"
29 #include "util/u_draw.h"
30 #include <assert.h>
31 #include <pipe/p_context.h>
32 #include <util/u_inlines.h>
33 #include <util/u_memory.h>
34 #include <util/u_keymap.h>
35 #include <util/u_sampler.h>
36 #include <tgsi/tgsi_ureg.h>
37 #include "vl_csc.h"
38
39 struct vertex_shader_consts
40 {
41 struct vertex4f dst_scale;
42 struct vertex4f dst_trans;
43 struct vertex4f src_scale;
44 struct vertex4f src_trans;
45 };
46
47 struct fragment_shader_consts
48 {
49 float matrix[16];
50 };
51
52 static bool
53 u_video_rects_equal(struct pipe_video_rect *a, struct pipe_video_rect *b)
54 {
55 assert(a && b);
56
57 if (a->x != b->x)
58 return false;
59 if (a->y != b->y)
60 return false;
61 if (a->w != b->w)
62 return false;
63 if (a->h != b->h)
64 return false;
65
66 return true;
67 }
68
69 static bool
70 create_vert_shader(struct vl_compositor *c)
71 {
72 struct ureg_program *shader;
73 struct ureg_src vpos, vtex;
74 struct ureg_dst o_vpos, o_vtex;
75
76 shader = ureg_create(TGSI_PROCESSOR_VERTEX);
77 if (!shader)
78 return false;
79
80 vpos = ureg_DECL_vs_input(shader, 0);
81 vtex = ureg_DECL_vs_input(shader, 1);
82 o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, 0);
83 o_vtex = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, 1);
84
85 /*
86 * o_vpos = vpos
87 * o_vtex = vtex
88 */
89 ureg_MOV(shader, o_vpos, vpos);
90 ureg_MOV(shader, o_vtex, vtex);
91
92 ureg_END(shader);
93
94 c->vertex_shader = ureg_create_shader_and_destroy(shader, c->pipe);
95 if (!c->vertex_shader)
96 return false;
97
98 return true;
99 }
100
101 static bool
102 create_frag_shader_ycbcr_2_rgb(struct vl_compositor *c)
103 {
104 struct ureg_program *shader;
105 struct ureg_src tc;
106 struct ureg_src csc[4];
107 struct ureg_src sampler;
108 struct ureg_dst texel;
109 struct ureg_dst fragment;
110 unsigned i;
111
112 shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
113 if (!shader)
114 return false;
115
116 tc = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, 1, TGSI_INTERPOLATE_LINEAR);
117 for (i = 0; i < 4; ++i)
118 csc[i] = ureg_DECL_constant(shader, i);
119 sampler = ureg_DECL_sampler(shader, 0);
120 texel = ureg_DECL_temporary(shader);
121 fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
122
123 /*
124 * texel = tex(tc, sampler)
125 * fragment = csc * texel
126 */
127 ureg_TEX(shader, texel, TGSI_TEXTURE_2D, tc, sampler);
128 for (i = 0; i < 4; ++i)
129 ureg_DP4(shader, ureg_writemask(fragment, TGSI_WRITEMASK_X << i), csc[i], ureg_src(texel));
130
131 ureg_release_temporary(shader, texel);
132 ureg_END(shader);
133
134 c->fragment_shader.ycbcr_2_rgb = ureg_create_shader_and_destroy(shader, c->pipe);
135 if (!c->fragment_shader.ycbcr_2_rgb)
136 return false;
137
138 return true;
139 }
140
141 static bool
142 create_frag_shader_rgb_2_rgb(struct vl_compositor *c)
143 {
144 struct ureg_program *shader;
145 struct ureg_src tc;
146 struct ureg_src sampler;
147 struct ureg_dst fragment;
148
149 shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
150 if (!shader)
151 return false;
152
153 tc = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, 1, TGSI_INTERPOLATE_LINEAR);
154 sampler = ureg_DECL_sampler(shader, 0);
155 fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
156
157 /*
158 * fragment = tex(tc, sampler)
159 */
160 ureg_TEX(shader, fragment, TGSI_TEXTURE_2D, tc, sampler);
161 ureg_END(shader);
162
163 c->fragment_shader.rgb_2_rgb = ureg_create_shader_and_destroy(shader, c->pipe);
164 if (!c->fragment_shader.rgb_2_rgb)
165 return false;
166
167 return true;
168 }
169
170 static bool
171 init_pipe_state(struct vl_compositor *c)
172 {
173 struct pipe_sampler_state sampler;
174
175 assert(c);
176
177 c->fb_state.nr_cbufs = 1;
178 c->fb_state.zsbuf = NULL;
179
180 memset(&sampler, 0, sizeof(sampler));
181 sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
182 sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
183 sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
184 sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
185 sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
186 sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
187 sampler.compare_mode = PIPE_TEX_COMPARE_NONE;
188 sampler.compare_func = PIPE_FUNC_ALWAYS;
189 sampler.normalized_coords = 1;
190 /*sampler.lod_bias = ;*/
191 /*sampler.min_lod = ;*/
192 /*sampler.max_lod = ;*/
193 /*sampler.border_color[i] = ;*/
194 /*sampler.max_anisotropy = ;*/
195 c->sampler = c->pipe->create_sampler_state(c->pipe, &sampler);
196
197 return true;
198 }
199
200 static void cleanup_pipe_state(struct vl_compositor *c)
201 {
202 assert(c);
203
204 c->pipe->delete_sampler_state(c->pipe, c->sampler);
205 }
206
207 static bool
208 init_shaders(struct vl_compositor *c)
209 {
210 assert(c);
211
212 if (!create_vert_shader(c)) {
213 debug_printf("Unable to create vertex shader.\n");
214 return false;
215 }
216 if (!create_frag_shader_ycbcr_2_rgb(c)) {
217 debug_printf("Unable to create YCbCr-to-RGB fragment shader.\n");
218 return false;
219 }
220 if (!create_frag_shader_rgb_2_rgb(c)) {
221 debug_printf("Unable to create RGB-to-RGB fragment shader.\n");
222 return false;
223 }
224
225 return true;
226 }
227
228 static void cleanup_shaders(struct vl_compositor *c)
229 {
230 assert(c);
231
232 c->pipe->delete_vs_state(c->pipe, c->vertex_shader);
233 c->pipe->delete_fs_state(c->pipe, c->fragment_shader.ycbcr_2_rgb);
234 c->pipe->delete_fs_state(c->pipe, c->fragment_shader.rgb_2_rgb);
235 }
236
237 static bool
238 init_buffers(struct vl_compositor *c)
239 {
240 struct fragment_shader_consts fsc;
241 struct pipe_vertex_element vertex_elems[2];
242
243 assert(c);
244
245 /*
246 * Create our vertex buffer and vertex buffer elements
247 */
248 c->vertex_buf.stride = sizeof(struct vertex4f);
249 c->vertex_buf.max_index = (VL_COMPOSITOR_MAX_LAYERS + 2) * 6 - 1;
250 c->vertex_buf.buffer_offset = 0;
251 /* XXX: Create with DYNAMIC or STREAM */
252 c->vertex_buf.buffer = pipe_buffer_create
253 (
254 c->pipe->screen,
255 PIPE_BIND_VERTEX_BUFFER,
256 sizeof(struct vertex4f) * (VL_COMPOSITOR_MAX_LAYERS + 2) * 6
257 );
258
259 vertex_elems[0].src_offset = 0;
260 vertex_elems[0].instance_divisor = 0;
261 vertex_elems[0].vertex_buffer_index = 0;
262 vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT;
263 vertex_elems[1].src_offset = sizeof(struct vertex2f);
264 vertex_elems[1].instance_divisor = 0;
265 vertex_elems[1].vertex_buffer_index = 0;
266 vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
267 c->vertex_elems_state = c->pipe->create_vertex_elements_state(c->pipe, 2, vertex_elems);
268
269 /*
270 * Create our fragment shader's constant buffer
271 * Const buffer contains the color conversion matrix and bias vectors
272 */
273 /* XXX: Create with IMMUTABLE/STATIC... although it does change every once in a long while... */
274 c->fs_const_buf = pipe_buffer_create
275 (
276 c->pipe->screen,
277 PIPE_BIND_CONSTANT_BUFFER,
278 sizeof(struct fragment_shader_consts)
279 );
280
281 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_IDENTITY, NULL, true, fsc.matrix);
282
283 vl_compositor_set_csc_matrix(c, fsc.matrix);
284
285 return true;
286 }
287
288 static void
289 cleanup_buffers(struct vl_compositor *c)
290 {
291 assert(c);
292
293 c->pipe->delete_vertex_elements_state(c->pipe, c->vertex_elems_state);
294 pipe_resource_reference(&c->vertex_buf.buffer, NULL);
295 pipe_resource_reference(&c->fs_const_buf, NULL);
296 }
297
298 static void
299 texview_map_delete(const struct keymap *map,
300 const void *key, void *data,
301 void *user)
302 {
303 struct pipe_sampler_view *sv = (struct pipe_sampler_view*)data;
304
305 assert(map);
306 assert(key);
307 assert(data);
308 assert(user);
309
310 pipe_sampler_view_reference(&sv, NULL);
311 }
312
313 bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe)
314 {
315 unsigned i;
316
317 assert(compositor);
318
319 memset(compositor, 0, sizeof(struct vl_compositor));
320
321 compositor->pipe = pipe;
322
323 compositor->texview_map = util_new_keymap(sizeof(struct pipe_surface*), -1,
324 texview_map_delete);
325 if (!compositor->texview_map)
326 return false;
327
328 if (!init_pipe_state(compositor)) {
329 util_delete_keymap(compositor->texview_map, compositor->pipe);
330 return false;
331 }
332 if (!init_shaders(compositor)) {
333 util_delete_keymap(compositor->texview_map, compositor->pipe);
334 cleanup_pipe_state(compositor);
335 return false;
336 }
337 if (!init_buffers(compositor)) {
338 util_delete_keymap(compositor->texview_map, compositor->pipe);
339 cleanup_shaders(compositor);
340 cleanup_pipe_state(compositor);
341 return false;
342 }
343
344 compositor->fb_state.width = 0;
345 compositor->fb_state.height = 0;
346 compositor->bg = NULL;
347 compositor->dirty_bg = false;
348 for (i = 0; i < VL_COMPOSITOR_MAX_LAYERS; ++i)
349 compositor->layers[i] = NULL;
350 compositor->dirty_layers = 0;
351
352 return true;
353 }
354
355 void vl_compositor_cleanup(struct vl_compositor *compositor)
356 {
357 assert(compositor);
358
359 util_delete_keymap(compositor->texview_map, compositor->pipe);
360 cleanup_buffers(compositor);
361 cleanup_shaders(compositor);
362 cleanup_pipe_state(compositor);
363 }
364
365 void vl_compositor_set_background(struct vl_compositor *compositor,
366 struct pipe_surface *bg, struct pipe_video_rect *bg_src_rect)
367 {
368 assert(compositor);
369 assert((bg && bg_src_rect) || (!bg && !bg_src_rect));
370
371 if (compositor->bg != bg ||
372 !u_video_rects_equal(&compositor->bg_src_rect, bg_src_rect)) {
373 pipe_surface_reference(&compositor->bg, bg);
374 /*if (!u_video_rects_equal(&compositor->bg_src_rect, bg_src_rect))*/
375 compositor->bg_src_rect = *bg_src_rect;
376 compositor->dirty_bg = true;
377 }
378 }
379
380 void vl_compositor_set_layers(struct vl_compositor *compositor,
381 struct pipe_surface *layers[],
382 struct pipe_video_rect *src_rects[],
383 struct pipe_video_rect *dst_rects[],
384 unsigned num_layers)
385 {
386 unsigned i;
387
388 assert(compositor);
389 assert(num_layers <= VL_COMPOSITOR_MAX_LAYERS);
390
391 for (i = 0; i < num_layers; ++i)
392 {
393 assert((layers[i] && src_rects[i] && dst_rects[i]) ||
394 (!layers[i] && !src_rects[i] && !dst_rects[i]));
395
396 if (compositor->layers[i] != layers[i] ||
397 !u_video_rects_equal(&compositor->layer_src_rects[i], src_rects[i]) ||
398 !u_video_rects_equal(&compositor->layer_dst_rects[i], dst_rects[i]))
399 {
400 pipe_surface_reference(&compositor->layers[i], layers[i]);
401 /*if (!u_video_rects_equal(&compositor->layer_src_rects[i], src_rects[i]))*/
402 compositor->layer_src_rects[i] = *src_rects[i];
403 /*if (!u_video_rects_equal(&compositor->layer_dst_rects[i], dst_rects[i]))*/
404 compositor->layer_dst_rects[i] = *dst_rects[i];
405 compositor->dirty_layers |= 1 << i;
406 }
407
408 if (layers[i])
409 compositor->dirty_layers |= 1 << i;
410 }
411
412 for (; i < VL_COMPOSITOR_MAX_LAYERS; ++i)
413 pipe_surface_reference(&compositor->layers[i], NULL);
414 }
415
416 static void gen_rect_verts(unsigned pos,
417 struct pipe_video_rect *src_rect,
418 struct vertex2f *src_inv_size,
419 struct pipe_video_rect *dst_rect,
420 struct vertex2f *dst_inv_size,
421 struct vertex4f *vb)
422 {
423 assert(pos < VL_COMPOSITOR_MAX_LAYERS + 2);
424 assert(src_rect);
425 assert(src_inv_size);
426 assert((dst_rect && dst_inv_size) /*|| (!dst_rect && !dst_inv_size)*/);
427 assert(vb);
428
429 vb[pos * 6 + 0].x = dst_rect->x * dst_inv_size->x;
430 vb[pos * 6 + 0].y = dst_rect->y * dst_inv_size->y;
431 vb[pos * 6 + 0].z = src_rect->x * src_inv_size->x;
432 vb[pos * 6 + 0].w = src_rect->y * src_inv_size->y;
433
434 vb[pos * 6 + 1].x = dst_rect->x * dst_inv_size->x;
435 vb[pos * 6 + 1].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
436 vb[pos * 6 + 1].z = src_rect->x * src_inv_size->x;
437 vb[pos * 6 + 1].w = (src_rect->y + src_rect->h) * src_inv_size->y;
438
439 vb[pos * 6 + 2].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
440 vb[pos * 6 + 2].y = dst_rect->y * dst_inv_size->y;
441 vb[pos * 6 + 2].z = (src_rect->x + src_rect->w) * src_inv_size->x;
442 vb[pos * 6 + 2].w = src_rect->y * src_inv_size->y;
443
444 vb[pos * 6 + 3].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
445 vb[pos * 6 + 3].y = dst_rect->y * dst_inv_size->y;
446 vb[pos * 6 + 3].z = (src_rect->x + src_rect->w) * src_inv_size->x;
447 vb[pos * 6 + 3].w = src_rect->y * src_inv_size->y;
448
449 vb[pos * 6 + 4].x = dst_rect->x * dst_inv_size->x;
450 vb[pos * 6 + 4].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
451 vb[pos * 6 + 4].z = src_rect->x * src_inv_size->x;
452 vb[pos * 6 + 4].w = (src_rect->y + src_rect->h) * src_inv_size->y;
453
454 vb[pos * 6 + 5].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
455 vb[pos * 6 + 5].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
456 vb[pos * 6 + 5].z = (src_rect->x + src_rect->w) * src_inv_size->x;
457 vb[pos * 6 + 5].w = (src_rect->y + src_rect->h) * src_inv_size->y;
458 }
459
460 static unsigned gen_data(struct vl_compositor *c,
461 struct pipe_surface *src_surface,
462 struct pipe_video_rect *src_rect,
463 struct pipe_video_rect *dst_rect,
464 struct pipe_surface **textures,
465 void **frag_shaders)
466 {
467 void *vb;
468 struct pipe_transfer *buf_transfer;
469 unsigned num_rects = 0;
470 unsigned i;
471
472 assert(c);
473 assert(src_surface);
474 assert(src_rect);
475 assert(dst_rect);
476 assert(textures);
477
478 vb = pipe_buffer_map(c->pipe, c->vertex_buf.buffer,
479 PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
480 &buf_transfer);
481
482 if (!vb)
483 return 0;
484
485 if (c->dirty_bg) {
486 struct vertex2f bg_inv_size = {1.0f / c->bg->width, 1.0f / c->bg->height};
487 gen_rect_verts(num_rects, &c->bg_src_rect, &bg_inv_size, NULL, NULL, vb);
488 textures[num_rects] = c->bg;
489 /* XXX: Hack */
490 frag_shaders[num_rects] = c->fragment_shader.rgb_2_rgb;
491 ++num_rects;
492 c->dirty_bg = false;
493 }
494
495 {
496 struct vertex2f src_inv_size = { 1.0f / src_surface->width, 1.0f / src_surface->height};
497 gen_rect_verts(num_rects, src_rect, &src_inv_size, dst_rect, &c->fb_inv_size, vb);
498 textures[num_rects] = src_surface;
499 /* XXX: Hack, sort of */
500 frag_shaders[num_rects] = c->fragment_shader.ycbcr_2_rgb;
501 ++num_rects;
502 }
503
504 for (i = 0; c->dirty_layers > 0; i++) {
505 assert(i < VL_COMPOSITOR_MAX_LAYERS);
506
507 if (c->dirty_layers & (1 << i)) {
508 struct vertex2f layer_inv_size = {1.0f / c->layers[i]->width, 1.0f / c->layers[i]->height};
509 gen_rect_verts(num_rects, &c->layer_src_rects[i], &layer_inv_size,
510 &c->layer_dst_rects[i], &c->fb_inv_size, vb);
511 textures[num_rects] = c->layers[i];
512 /* XXX: Hack */
513 frag_shaders[num_rects] = c->fragment_shader.rgb_2_rgb;
514 ++num_rects;
515 c->dirty_layers &= ~(1 << i);
516 }
517 }
518
519 pipe_buffer_unmap(c->pipe, buf_transfer);
520
521 return num_rects;
522 }
523
524 static void draw_layers(struct vl_compositor *c,
525 struct pipe_surface *src_surface,
526 struct pipe_video_rect *src_rect,
527 struct pipe_video_rect *dst_rect)
528 {
529 unsigned num_rects;
530 struct pipe_surface *src_surfaces[VL_COMPOSITOR_MAX_LAYERS + 2];
531 void *frag_shaders[VL_COMPOSITOR_MAX_LAYERS + 2];
532 unsigned i;
533
534 assert(c);
535 assert(src_surface);
536 assert(src_rect);
537 assert(dst_rect);
538
539 num_rects = gen_data(c, src_surface, src_rect, dst_rect, src_surfaces, frag_shaders);
540
541 for (i = 0; i < num_rects; ++i) {
542 boolean delete_view = FALSE;
543 struct pipe_sampler_view *surface_view = (struct pipe_sampler_view*)util_keymap_lookup(c->texview_map,
544 &src_surfaces[i]);
545 if (!surface_view) {
546 struct pipe_sampler_view templat;
547 u_sampler_view_default_template(&templat, src_surfaces[i]->texture,
548 src_surfaces[i]->texture->format);
549 surface_view = c->pipe->create_sampler_view(c->pipe, src_surfaces[i]->texture,
550 &templat);
551 if (!surface_view)
552 return;
553
554 delete_view = !util_keymap_insert(c->texview_map, &src_surfaces[i],
555 surface_view, c->pipe);
556 }
557
558 c->pipe->bind_fs_state(c->pipe, frag_shaders[i]);
559 c->pipe->set_fragment_sampler_views(c->pipe, 1, &surface_view);
560 util_draw_arrays(c->pipe, PIPE_PRIM_TRIANGLES, i * 6, 6);
561
562 if (delete_view) {
563 pipe_sampler_view_reference(&surface_view, NULL);
564 }
565 }
566 }
567
568 void vl_compositor_render(struct vl_compositor *compositor,
569 struct pipe_surface *src_surface,
570 enum pipe_mpeg12_picture_type picture_type,
571 /*unsigned num_past_surfaces,
572 struct pipe_surface *past_surfaces,
573 unsigned num_future_surfaces,
574 struct pipe_surface *future_surfaces,*/
575 struct pipe_video_rect *src_area,
576 struct pipe_surface *dst_surface,
577 struct pipe_video_rect *dst_area,
578 struct pipe_fence_handle **fence)
579 {
580 assert(compositor);
581 assert(src_surface);
582 assert(src_area);
583 assert(dst_surface);
584 assert(dst_area);
585 assert(picture_type == PIPE_MPEG12_PICTURE_TYPE_FRAME);
586
587 if (compositor->fb_state.width != dst_surface->width) {
588 compositor->fb_inv_size.x = 1.0f / dst_surface->width;
589 compositor->fb_state.width = dst_surface->width;
590 }
591 if (compositor->fb_state.height != dst_surface->height) {
592 compositor->fb_inv_size.y = 1.0f / dst_surface->height;
593 compositor->fb_state.height = dst_surface->height;
594 }
595
596 compositor->fb_state.cbufs[0] = dst_surface;
597
598 compositor->viewport.scale[0] = compositor->fb_state.width;
599 compositor->viewport.scale[1] = compositor->fb_state.height;
600 compositor->viewport.scale[2] = 1;
601 compositor->viewport.scale[3] = 1;
602 compositor->viewport.translate[0] = 0;
603 compositor->viewport.translate[1] = 0;
604 compositor->viewport.translate[2] = 0;
605 compositor->viewport.translate[3] = 0;
606
607 compositor->pipe->set_framebuffer_state(compositor->pipe, &compositor->fb_state);
608 compositor->pipe->set_viewport_state(compositor->pipe, &compositor->viewport);
609 compositor->pipe->bind_fragment_sampler_states(compositor->pipe, 1, &compositor->sampler);
610 compositor->pipe->bind_vs_state(compositor->pipe, compositor->vertex_shader);
611 compositor->pipe->set_vertex_buffers(compositor->pipe, 1, &compositor->vertex_buf);
612 compositor->pipe->bind_vertex_elements_state(compositor->pipe, compositor->vertex_elems_state);
613 compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_FRAGMENT, 0, compositor->fs_const_buf);
614
615 draw_layers(compositor, src_surface, src_area, dst_area);
616
617 assert(!compositor->dirty_bg && !compositor->dirty_layers);
618 compositor->pipe->flush(compositor->pipe, PIPE_FLUSH_RENDER_CACHE, fence);
619 }
620
621 void vl_compositor_set_csc_matrix(struct vl_compositor *compositor, const float *mat)
622 {
623 struct pipe_transfer *buf_transfer;
624
625 assert(compositor);
626
627 memcpy
628 (
629 pipe_buffer_map(compositor->pipe, compositor->fs_const_buf,
630 PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
631 &buf_transfer),
632 mat,
633 sizeof(struct fragment_shader_consts)
634 );
635
636 pipe_buffer_unmap(compositor->pipe, buf_transfer);
637 }