Merge branch 'master' of ssh://cgit.freedesktop.org/~tball/mesa-gallium-vdpau into...
[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 <assert.h>
30 #include <pipe/p_context.h>
31 #include <util/u_inlines.h>
32 #include <util/u_memory.h>
33 #include <util/u_keymap.h>
34 #include <util/u_sampler.h>
35 #include <tgsi/tgsi_ureg.h>
36 #include "vl_csc.h"
37
38 struct vertex_shader_consts
39 {
40 struct vertex4f dst_scale;
41 struct vertex4f dst_trans;
42 struct vertex4f src_scale;
43 struct vertex4f src_trans;
44 };
45
46 struct fragment_shader_consts
47 {
48 float matrix[16];
49 };
50
51 static bool
52 u_video_rects_equal(struct pipe_video_rect *a, struct pipe_video_rect *b)
53 {
54 assert(a && b);
55
56 if (a->x != b->x)
57 return false;
58 if (a->y != b->y)
59 return false;
60 if (a->w != b->w)
61 return false;
62 if (a->h != b->h)
63 return false;
64
65 return true;
66 }
67
68 static bool
69 create_vert_shader(struct vl_compositor *c)
70 {
71 struct ureg_program *shader;
72 struct ureg_src vpos, vtex;
73 struct ureg_dst o_vpos, o_vtex;
74
75 shader = ureg_create(TGSI_PROCESSOR_VERTEX);
76 if (!shader)
77 return false;
78
79 vpos = ureg_DECL_vs_input(shader, 0);
80 vtex = ureg_DECL_vs_input(shader, 1);
81 o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, 0);
82 o_vtex = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, 1);
83
84 /*
85 * o_vpos = vpos
86 * o_vtex = vtex
87 */
88 ureg_MOV(shader, o_vpos, vpos);
89 ureg_MOV(shader, o_vtex, vtex);
90
91 ureg_END(shader);
92
93 c->vertex_shader = ureg_create_shader_and_destroy(shader, c->pipe);
94 if (!c->vertex_shader)
95 return false;
96
97 return true;
98 }
99
100 static bool
101 create_frag_shader_ycbcr_2_rgb(struct vl_compositor *c)
102 {
103 struct ureg_program *shader;
104 struct ureg_src tc;
105 struct ureg_src csc[4];
106 struct ureg_src sampler;
107 struct ureg_dst texel;
108 struct ureg_dst fragment;
109 unsigned i;
110
111 shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
112 if (!shader)
113 return false;
114
115 tc = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, 1, TGSI_INTERPOLATE_LINEAR);
116 for (i = 0; i < 4; ++i)
117 csc[i] = ureg_DECL_constant(shader, i);
118 sampler = ureg_DECL_sampler(shader, 0);
119 texel = ureg_DECL_temporary(shader);
120 fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
121
122 /*
123 * texel = tex(tc, sampler)
124 * fragment = csc * texel
125 */
126 ureg_TEX(shader, texel, TGSI_TEXTURE_2D, tc, sampler);
127 for (i = 0; i < 4; ++i)
128 ureg_DP4(shader, ureg_writemask(fragment, TGSI_WRITEMASK_X << i), csc[i], ureg_src(texel));
129
130 ureg_release_temporary(shader, texel);
131 ureg_END(shader);
132
133 c->fragment_shader.ycbcr_2_rgb = ureg_create_shader_and_destroy(shader, c->pipe);
134 if (!c->fragment_shader.ycbcr_2_rgb)
135 return false;
136
137 return true;
138 }
139
140 static bool
141 create_frag_shader_rgb_2_rgb(struct vl_compositor *c)
142 {
143 struct ureg_program *shader;
144 struct ureg_src tc;
145 struct ureg_src sampler;
146 struct ureg_dst fragment;
147
148 shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
149 if (!shader)
150 return false;
151
152 tc = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, 1, TGSI_INTERPOLATE_LINEAR);
153 sampler = ureg_DECL_sampler(shader, 0);
154 fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
155
156 /*
157 * fragment = tex(tc, sampler)
158 */
159 ureg_TEX(shader, fragment, TGSI_TEXTURE_2D, tc, sampler);
160 ureg_END(shader);
161
162 c->fragment_shader.rgb_2_rgb = ureg_create_shader_and_destroy(shader, c->pipe);
163 if (!c->fragment_shader.rgb_2_rgb)
164 return false;
165
166 return true;
167 }
168
169 static bool
170 init_pipe_state(struct vl_compositor *c)
171 {
172 struct pipe_sampler_state sampler;
173
174 assert(c);
175
176 c->fb_state.nr_cbufs = 1;
177 c->fb_state.zsbuf = NULL;
178
179 sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
180 sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
181 sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
182 sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
183 sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
184 sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
185 sampler.compare_mode = PIPE_TEX_COMPARE_NONE;
186 sampler.compare_func = PIPE_FUNC_ALWAYS;
187 sampler.normalized_coords = 1;
188 /*sampler.lod_bias = ;*/
189 /*sampler.min_lod = ;*/
190 /*sampler.max_lod = ;*/
191 /*sampler.border_color[i] = ;*/
192 /*sampler.max_anisotropy = ;*/
193 c->sampler = c->pipe->create_sampler_state(c->pipe, &sampler);
194
195 return true;
196 }
197
198 static void cleanup_pipe_state(struct vl_compositor *c)
199 {
200 assert(c);
201
202 c->pipe->delete_sampler_state(c->pipe, c->sampler);
203 }
204
205 static bool
206 init_shaders(struct vl_compositor *c)
207 {
208 assert(c);
209
210 if (!create_vert_shader(c)) {
211 debug_printf("Unable to create vertex shader.\n");
212 return false;
213 }
214 if (!create_frag_shader_ycbcr_2_rgb(c)) {
215 debug_printf("Unable to create YCbCr-to-RGB fragment shader.\n");
216 return false;
217 }
218 if (!create_frag_shader_rgb_2_rgb(c)) {
219 debug_printf("Unable to create RGB-to-RGB fragment shader.\n");
220 return false;
221 }
222
223 return true;
224 }
225
226 static void cleanup_shaders(struct vl_compositor *c)
227 {
228 assert(c);
229
230 c->pipe->delete_vs_state(c->pipe, c->vertex_shader);
231 c->pipe->delete_fs_state(c->pipe, c->fragment_shader.ycbcr_2_rgb);
232 c->pipe->delete_fs_state(c->pipe, c->fragment_shader.rgb_2_rgb);
233 }
234
235 static bool
236 init_buffers(struct vl_compositor *c)
237 {
238 struct fragment_shader_consts fsc;
239 struct pipe_vertex_element vertex_elems[2];
240
241 assert(c);
242
243 /*
244 * Create our vertex buffer and vertex buffer elements
245 */
246 c->vertex_buf.stride = sizeof(struct vertex4f);
247 c->vertex_buf.max_index = (VL_COMPOSITOR_MAX_LAYERS + 2) * 6 - 1;
248 c->vertex_buf.buffer_offset = 0;
249 /* XXX: Create with DYNAMIC or STREAM */
250 c->vertex_buf.buffer = pipe_buffer_create
251 (
252 c->pipe->screen,
253 PIPE_BIND_VERTEX_BUFFER,
254 sizeof(struct vertex4f) * (VL_COMPOSITOR_MAX_LAYERS + 2) * 6
255 );
256
257 vertex_elems[0].src_offset = 0;
258 vertex_elems[0].instance_divisor = 0;
259 vertex_elems[0].vertex_buffer_index = 0;
260 vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT;
261 vertex_elems[1].src_offset = sizeof(struct vertex2f);
262 vertex_elems[1].instance_divisor = 0;
263 vertex_elems[1].vertex_buffer_index = 0;
264 vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
265 c->vertex_elems_state = c->pipe->create_vertex_elements_state(c->pipe, 2, vertex_elems);
266
267 /*
268 * Create our fragment shader's constant buffer
269 * Const buffer contains the color conversion matrix and bias vectors
270 */
271 /* XXX: Create with IMMUTABLE/STATIC... although it does change every once in a long while... */
272 c->fs_const_buf = pipe_buffer_create
273 (
274 c->pipe->screen,
275 PIPE_BIND_CONSTANT_BUFFER,
276 sizeof(struct fragment_shader_consts)
277 );
278
279 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_IDENTITY, NULL, true, fsc.matrix);
280
281 vl_compositor_set_csc_matrix(c, fsc.matrix);
282
283 return true;
284 }
285
286 static void
287 cleanup_buffers(struct vl_compositor *c)
288 {
289 assert(c);
290
291 c->pipe->delete_vertex_elements_state(c->pipe, c->vertex_elems_state);
292 pipe_resource_reference(&c->vertex_buf.buffer, NULL);
293 pipe_resource_reference(&c->fs_const_buf, NULL);
294 }
295
296 static void
297 texview_map_delete(const struct keymap *map,
298 const void *key, void *data,
299 void *user)
300 {
301 struct pipe_sampler_view *sv = (struct pipe_sampler_view*)data;
302
303 assert(map);
304 assert(key);
305 assert(data);
306 assert(user);
307
308 pipe_sampler_view_reference(&sv, NULL);
309 }
310
311 bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe)
312 {
313 unsigned i;
314
315 assert(compositor);
316
317 memset(compositor, 0, sizeof(struct vl_compositor));
318
319 compositor->pipe = pipe;
320
321 compositor->texview_map = util_new_keymap(sizeof(struct pipe_surface*), -1,
322 texview_map_delete);
323 if (!compositor->texview_map)
324 return false;
325
326 if (!init_pipe_state(compositor)) {
327 util_delete_keymap(compositor->texview_map, compositor->pipe);
328 return false;
329 }
330 if (!init_shaders(compositor)) {
331 util_delete_keymap(compositor->texview_map, compositor->pipe);
332 cleanup_pipe_state(compositor);
333 return false;
334 }
335 if (!init_buffers(compositor)) {
336 util_delete_keymap(compositor->texview_map, compositor->pipe);
337 cleanup_shaders(compositor);
338 cleanup_pipe_state(compositor);
339 return false;
340 }
341
342 compositor->fb_state.width = 0;
343 compositor->fb_state.height = 0;
344 compositor->bg = NULL;
345 compositor->dirty_bg = false;
346 for (i = 0; i < VL_COMPOSITOR_MAX_LAYERS; ++i)
347 compositor->layers[i] = NULL;
348 compositor->dirty_layers = 0;
349
350 return true;
351 }
352
353 void vl_compositor_cleanup(struct vl_compositor *compositor)
354 {
355 assert(compositor);
356
357 util_delete_keymap(compositor->texview_map, compositor->pipe);
358 cleanup_buffers(compositor);
359 cleanup_shaders(compositor);
360 cleanup_pipe_state(compositor);
361 }
362
363 void vl_compositor_set_background(struct vl_compositor *compositor,
364 struct pipe_surface *bg, struct pipe_video_rect *bg_src_rect)
365 {
366 assert(compositor);
367 assert((bg && bg_src_rect) || (!bg && !bg_src_rect));
368
369 if (compositor->bg != bg ||
370 !u_video_rects_equal(&compositor->bg_src_rect, bg_src_rect)) {
371 pipe_surface_reference(&compositor->bg, bg);
372 /*if (!u_video_rects_equal(&compositor->bg_src_rect, bg_src_rect))*/
373 compositor->bg_src_rect = *bg_src_rect;
374 compositor->dirty_bg = true;
375 }
376 }
377
378 void vl_compositor_set_layers(struct vl_compositor *compositor,
379 struct pipe_surface *layers[],
380 struct pipe_video_rect *src_rects[],
381 struct pipe_video_rect *dst_rects[],
382 unsigned num_layers)
383 {
384 unsigned i;
385
386 assert(compositor);
387 assert(num_layers <= VL_COMPOSITOR_MAX_LAYERS);
388
389 for (i = 0; i < num_layers; ++i)
390 {
391 assert((layers[i] && src_rects[i] && dst_rects[i]) ||
392 (!layers[i] && !src_rects[i] && !dst_rects[i]));
393
394 if (compositor->layers[i] != layers[i] ||
395 !u_video_rects_equal(&compositor->layer_src_rects[i], src_rects[i]) ||
396 !u_video_rects_equal(&compositor->layer_dst_rects[i], dst_rects[i]))
397 {
398 pipe_surface_reference(&compositor->layers[i], layers[i]);
399 /*if (!u_video_rects_equal(&compositor->layer_src_rects[i], src_rects[i]))*/
400 compositor->layer_src_rects[i] = *src_rects[i];
401 /*if (!u_video_rects_equal(&compositor->layer_dst_rects[i], dst_rects[i]))*/
402 compositor->layer_dst_rects[i] = *dst_rects[i];
403 compositor->dirty_layers |= 1 << i;
404 }
405
406 if (layers[i])
407 compositor->dirty_layers |= 1 << i;
408 }
409
410 for (; i < VL_COMPOSITOR_MAX_LAYERS; ++i)
411 pipe_surface_reference(&compositor->layers[i], NULL);
412 }
413
414 static void gen_rect_verts(unsigned pos,
415 struct pipe_video_rect *src_rect,
416 struct vertex2f *src_inv_size,
417 struct pipe_video_rect *dst_rect,
418 struct vertex2f *dst_inv_size,
419 struct vertex4f *vb)
420 {
421 assert(pos < VL_COMPOSITOR_MAX_LAYERS + 2);
422 assert(src_rect);
423 assert(src_inv_size);
424 assert((dst_rect && dst_inv_size) /*|| (!dst_rect && !dst_inv_size)*/);
425 assert(vb);
426
427 vb[pos * 6 + 0].x = dst_rect->x * dst_inv_size->x;
428 vb[pos * 6 + 0].y = dst_rect->y * dst_inv_size->y;
429 vb[pos * 6 + 0].z = src_rect->x * src_inv_size->x;
430 vb[pos * 6 + 0].w = src_rect->y * src_inv_size->y;
431
432 vb[pos * 6 + 1].x = dst_rect->x * dst_inv_size->x;
433 vb[pos * 6 + 1].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
434 vb[pos * 6 + 1].z = src_rect->x * src_inv_size->x;
435 vb[pos * 6 + 1].w = (src_rect->y + src_rect->h) * src_inv_size->y;
436
437 vb[pos * 6 + 2].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
438 vb[pos * 6 + 2].y = dst_rect->y * dst_inv_size->y;
439 vb[pos * 6 + 2].z = (src_rect->x + src_rect->w) * src_inv_size->x;
440 vb[pos * 6 + 2].w = src_rect->y * src_inv_size->y;
441
442 vb[pos * 6 + 3].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
443 vb[pos * 6 + 3].y = dst_rect->y * dst_inv_size->y;
444 vb[pos * 6 + 3].z = (src_rect->x + src_rect->w) * src_inv_size->x;
445 vb[pos * 6 + 3].w = src_rect->y * src_inv_size->y;
446
447 vb[pos * 6 + 4].x = dst_rect->x * dst_inv_size->x;
448 vb[pos * 6 + 4].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
449 vb[pos * 6 + 4].z = src_rect->x * src_inv_size->x;
450 vb[pos * 6 + 4].w = (src_rect->y + src_rect->h) * src_inv_size->y;
451
452 vb[pos * 6 + 5].x = (dst_rect->x + dst_rect->w) * dst_inv_size->x;
453 vb[pos * 6 + 5].y = (dst_rect->y + dst_rect->h) * dst_inv_size->y;
454 vb[pos * 6 + 5].z = (src_rect->x + src_rect->w) * src_inv_size->x;
455 vb[pos * 6 + 5].w = (src_rect->y + src_rect->h) * src_inv_size->y;
456 }
457
458 static unsigned gen_data(struct vl_compositor *c,
459 struct pipe_surface *src_surface,
460 struct pipe_video_rect *src_rect,
461 struct pipe_video_rect *dst_rect,
462 struct pipe_surface **textures,
463 void **frag_shaders)
464 {
465 void *vb;
466 struct pipe_transfer *buf_transfer;
467 unsigned num_rects = 0;
468 unsigned i;
469
470 assert(c);
471 assert(src_surface);
472 assert(src_rect);
473 assert(dst_rect);
474 assert(textures);
475
476 vb = pipe_buffer_map(c->pipe, c->vertex_buf.buffer,
477 PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
478 &buf_transfer);
479
480 if (!vb)
481 return 0;
482
483 if (c->dirty_bg) {
484 struct vertex2f bg_inv_size = {1.0f / c->bg->width, 1.0f / c->bg->height};
485 gen_rect_verts(num_rects, &c->bg_src_rect, &bg_inv_size, NULL, NULL, vb);
486 textures[num_rects] = c->bg;
487 /* XXX: Hack */
488 frag_shaders[num_rects] = c->fragment_shader.rgb_2_rgb;
489 ++num_rects;
490 c->dirty_bg = false;
491 }
492
493 {
494 struct vertex2f src_inv_size = { 1.0f / src_surface->width, 1.0f / src_surface->height};
495 gen_rect_verts(num_rects, src_rect, &src_inv_size, dst_rect, &c->fb_inv_size, vb);
496 textures[num_rects] = src_surface;
497 /* XXX: Hack, sort of */
498 frag_shaders[num_rects] = c->fragment_shader.ycbcr_2_rgb;
499 ++num_rects;
500 }
501
502 for (i = 0; c->dirty_layers > 0; i++) {
503 assert(i < VL_COMPOSITOR_MAX_LAYERS);
504
505 if (c->dirty_layers & (1 << i)) {
506 struct vertex2f layer_inv_size = {1.0f / c->layers[i]->width, 1.0f / c->layers[i]->height};
507 gen_rect_verts(num_rects, &c->layer_src_rects[i], &layer_inv_size,
508 &c->layer_dst_rects[i], &c->fb_inv_size, vb);
509 textures[num_rects] = c->layers[i];
510 /* XXX: Hack */
511 frag_shaders[num_rects] = c->fragment_shader.rgb_2_rgb;
512 ++num_rects;
513 c->dirty_layers &= ~(1 << i);
514 }
515 }
516
517 pipe_buffer_unmap(c->pipe, c->vertex_buf.buffer, buf_transfer);
518
519 return num_rects;
520 }
521
522 static void draw_layers(struct vl_compositor *c,
523 struct pipe_surface *src_surface,
524 struct pipe_video_rect *src_rect,
525 struct pipe_video_rect *dst_rect)
526 {
527 unsigned num_rects;
528 struct pipe_surface *src_surfaces[VL_COMPOSITOR_MAX_LAYERS + 2];
529 void *frag_shaders[VL_COMPOSITOR_MAX_LAYERS + 2];
530 unsigned i;
531
532 assert(c);
533 assert(src_surface);
534 assert(src_rect);
535 assert(dst_rect);
536
537 num_rects = gen_data(c, src_surface, src_rect, dst_rect, src_surfaces, frag_shaders);
538
539 for (i = 0; i < num_rects; ++i) {
540 boolean delete_view = FALSE;
541 struct pipe_sampler_view *surface_view = (struct pipe_sampler_view*)util_keymap_lookup(c->texview_map,
542 &src_surfaces[i]);
543 if (!surface_view) {
544 struct pipe_sampler_view templat;
545 u_sampler_view_default_template(&templat, src_surfaces[i]->texture,
546 src_surfaces[i]->texture->format);
547 surface_view = c->pipe->create_sampler_view(c->pipe, src_surfaces[i]->texture,
548 &templat);
549 if (!surface_view)
550 return;
551
552 delete_view = !util_keymap_insert(c->texview_map, &src_surfaces[i],
553 surface_view, c->pipe);
554 }
555
556 c->pipe->bind_fs_state(c->pipe, frag_shaders[i]);
557 c->pipe->set_fragment_sampler_views(c->pipe, 1, &surface_view);
558
559
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, compositor->fs_const_buf,
637 buf_transfer);
638 }