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