1 /**********************************************************
2 * Copyright 2009-2011 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 *********************************************************
25 * Authors:
26 * Zack Rusin <zackr-at-vmware-dot-com>
27 */
28
29 #include "xa_context.h"
30 #include "xa_priv.h"
31 #include <math.h>
32 #include "cso_cache/cso_context.h"
33 #include "util/u_inlines.h"
34 #include "util/u_sampler.h"
35 #include "util/u_draw_quad.h"
36
37 #define floatsEqual(x, y) (fabsf(x - y) <= 0.00001f * MIN2(fabsf(x), fabsf(y)))
38 #define floatIsZero(x) (floatsEqual((x) + 1.0f, 1.0f))
39
40 #define NUM_COMPONENTS 4
41
42 void
43
44
45 renderer_set_constants(struct xa_context *r,
46 int shader_type, const float *params, int param_bytes);
47
48 static inline bool
is_affine(const float * matrix)49 is_affine(const float *matrix)
50 {
51 return floatIsZero(matrix[2]) && floatIsZero(matrix[5])
52 && floatsEqual(matrix[8], 1.0f);
53 }
54
55 static inline void
map_point(const float * mat,float x,float y,float * out_x,float * out_y)56 map_point(const float *mat, float x, float y, float *out_x, float *out_y)
57 {
58 if (!mat) {
59 *out_x = x;
60 *out_y = y;
61 return;
62 }
63
64 *out_x = mat[0] * x + mat[3] * y + mat[6];
65 *out_y = mat[1] * x + mat[4] * y + mat[7];
66 if (!is_affine(mat)) {
67 float w = 1 / (mat[2] * x + mat[5] * y + mat[8]);
68
69 *out_x *= w;
70 *out_y *= w;
71 }
72 }
73
74 static inline void
renderer_draw(struct xa_context * r)75 renderer_draw(struct xa_context *r)
76 {
77 int num_verts = r->buffer_size / (r->attrs_per_vertex * NUM_COMPONENTS);
78
79 if (!r->buffer_size)
80 return;
81
82 if (!r->scissor_valid) {
83 r->scissor.minx = 0;
84 r->scissor.miny = 0;
85 r->scissor.maxx = r->dst->tex->width0;
86 r->scissor.maxy = r->dst->tex->height0;
87 }
88
89 r->pipe->set_scissor_states(r->pipe, 0, 1, &r->scissor);
90
91 struct cso_velems_state velems;
92 velems.count = r->attrs_per_vertex;
93 memcpy(velems.velems, r->velems, sizeof(r->velems[0]) * velems.count);
94 for (unsigned i = 0; i < velems.count; i++)
95 velems.velems[i].src_stride = velems.count * 4 * sizeof(float);
96
97 cso_set_vertex_elements(r->cso, &velems);
98 util_draw_user_vertex_buffer(r->cso, r->buffer, MESA_PRIM_QUADS,
99 num_verts, /* verts */
100 r->attrs_per_vertex); /* attribs/vert */
101 r->buffer_size = 0;
102
103 xa_scissor_reset(r);
104 }
105
106 static inline void
renderer_draw_conditional(struct xa_context * r,int next_batch)107 renderer_draw_conditional(struct xa_context *r, int next_batch)
108 {
109 if (r->buffer_size + next_batch >= XA_VB_SIZE ||
110 (next_batch == 0 && r->buffer_size)) {
111 renderer_draw(r);
112 }
113 }
114
115 void
renderer_init_state(struct xa_context * r)116 renderer_init_state(struct xa_context *r)
117 {
118 struct pipe_depth_stencil_alpha_state dsa;
119 struct pipe_rasterizer_state raster;
120 unsigned i;
121
122 /* set common initial clip state */
123 memset(&dsa, 0, sizeof(struct pipe_depth_stencil_alpha_state));
124 cso_set_depth_stencil_alpha(r->cso, &dsa);
125
126 /* XXX: move to renderer_init_state? */
127 memset(&raster, 0, sizeof(struct pipe_rasterizer_state));
128 raster.half_pixel_center = 1;
129 raster.bottom_edge_rule = 1;
130 raster.depth_clip_near = 1;
131 raster.depth_clip_far = 1;
132 raster.scissor = 1;
133 cso_set_rasterizer(r->cso, &raster);
134
135 /* vertex elements state */
136 memset(&r->velems[0], 0, sizeof(r->velems[0]) * 3);
137 for (i = 0; i < 3; i++) {
138 r->velems[i].src_offset = i * 4 * sizeof(float);
139 r->velems[i].instance_divisor = 0;
140 r->velems[i].vertex_buffer_index = 0;
141 r->velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
142 }
143 }
144
145 static inline void
add_vertex_none(struct xa_context * r,float x,float y)146 add_vertex_none(struct xa_context *r, float x, float y)
147 {
148 float *vertex = r->buffer + r->buffer_size;
149
150 vertex[0] = x;
151 vertex[1] = y;
152 vertex[2] = 0.f; /*z */
153 vertex[3] = 1.f; /*w */
154
155 r->buffer_size += 4;
156 }
157
158 static inline void
add_vertex_1tex(struct xa_context * r,float x,float y,float s,float t)159 add_vertex_1tex(struct xa_context *r, float x, float y, float s, float t)
160 {
161 float *vertex = r->buffer + r->buffer_size;
162
163 vertex[0] = x;
164 vertex[1] = y;
165 vertex[2] = 0.f; /*z */
166 vertex[3] = 1.f; /*w */
167
168 vertex[4] = s; /*s */
169 vertex[5] = t; /*t */
170 vertex[6] = 0.f; /*r */
171 vertex[7] = 1.f; /*q */
172
173 r->buffer_size += 8;
174 }
175
176 static inline void
add_vertex_2tex(struct xa_context * r,float x,float y,float s0,float t0,float s1,float t1)177 add_vertex_2tex(struct xa_context *r,
178 float x, float y, float s0, float t0, float s1, float t1)
179 {
180 float *vertex = r->buffer + r->buffer_size;
181
182 vertex[0] = x;
183 vertex[1] = y;
184 vertex[2] = 0.f; /*z */
185 vertex[3] = 1.f; /*w */
186
187 vertex[4] = s0; /*s */
188 vertex[5] = t0; /*t */
189 vertex[6] = 0.f; /*r */
190 vertex[7] = 1.f; /*q */
191
192 vertex[8] = s1; /*s */
193 vertex[9] = t1; /*t */
194 vertex[10] = 0.f; /*r */
195 vertex[11] = 1.f; /*q */
196
197 r->buffer_size += 12;
198 }
199
200 static void
compute_src_coords(float sx,float sy,const struct pipe_resource * src,const float * src_matrix,float width,float height,float tc0[2],float tc1[2],float tc2[2],float tc3[2])201 compute_src_coords(float sx, float sy, const struct pipe_resource *src,
202 const float *src_matrix,
203 float width, float height,
204 float tc0[2], float tc1[2], float tc2[2], float tc3[2])
205 {
206 tc0[0] = sx;
207 tc0[1] = sy;
208 tc1[0] = sx + width;
209 tc1[1] = sy;
210 tc2[0] = sx + width;
211 tc2[1] = sy + height;
212 tc3[0] = sx;
213 tc3[1] = sy + height;
214
215 if (src_matrix) {
216 map_point(src_matrix, tc0[0], tc0[1], &tc0[0], &tc0[1]);
217 map_point(src_matrix, tc1[0], tc1[1], &tc1[0], &tc1[1]);
218 map_point(src_matrix, tc2[0], tc2[1], &tc2[0], &tc2[1]);
219 map_point(src_matrix, tc3[0], tc3[1], &tc3[0], &tc3[1]);
220 }
221
222 tc0[0] /= src->width0;
223 tc1[0] /= src->width0;
224 tc2[0] /= src->width0;
225 tc3[0] /= src->width0;
226 tc0[1] /= src->height0;
227 tc1[1] /= src->height0;
228 tc2[1] /= src->height0;
229 tc3[1] /= src->height0;
230 }
231
232 static void
add_vertex_data1(struct xa_context * r,float srcX,float srcY,float dstX,float dstY,float width,float height,const struct pipe_resource * src,const float * src_matrix)233 add_vertex_data1(struct xa_context *r,
234 float srcX, float srcY, float dstX, float dstY,
235 float width, float height,
236 const struct pipe_resource *src, const float *src_matrix)
237 {
238 float tc0[2], tc1[2], tc2[2], tc3[2];
239
240 compute_src_coords(srcX, srcY, src, src_matrix, width, height,
241 tc0, tc1, tc2, tc3);
242 /* 1st vertex */
243 add_vertex_1tex(r, dstX, dstY, tc0[0], tc0[1]);
244 /* 2nd vertex */
245 add_vertex_1tex(r, dstX + width, dstY, tc1[0], tc1[1]);
246 /* 3rd vertex */
247 add_vertex_1tex(r, dstX + width, dstY + height, tc2[0], tc2[1]);
248 /* 4th vertex */
249 add_vertex_1tex(r, dstX, dstY + height, tc3[0], tc3[1]);
250 }
251
252 static void
add_vertex_data2(struct xa_context * r,float srcX,float srcY,float maskX,float maskY,float dstX,float dstY,float width,float height,struct pipe_resource * src,struct pipe_resource * mask,const float * src_matrix,const float * mask_matrix)253 add_vertex_data2(struct xa_context *r,
254 float srcX, float srcY, float maskX, float maskY,
255 float dstX, float dstY, float width, float height,
256 struct pipe_resource *src,
257 struct pipe_resource *mask,
258 const float *src_matrix, const float *mask_matrix)
259 {
260 float spt0[2], spt1[2], spt2[2], spt3[2];
261 float mpt0[2], mpt1[2], mpt2[2], mpt3[2];
262
263 compute_src_coords(srcX, srcY, src, src_matrix, width, height,
264 spt0, spt1, spt2, spt3);
265 compute_src_coords(maskX, maskY, mask, mask_matrix, width, height,
266 mpt0, mpt1, mpt2, mpt3);
267
268 /* 1st vertex */
269 add_vertex_2tex(r, dstX, dstY,
270 spt0[0], spt0[1], mpt0[0], mpt0[1]);
271 /* 2nd vertex */
272 add_vertex_2tex(r, dstX + width, dstY,
273 spt1[0], spt1[1], mpt1[0], mpt1[1]);
274 /* 3rd vertex */
275 add_vertex_2tex(r, dstX + width, dstY + height,
276 spt2[0], spt2[1], mpt2[0], mpt2[1]);
277 /* 4th vertex */
278 add_vertex_2tex(r, dstX, dstY + height,
279 spt3[0], spt3[1], mpt3[0], mpt3[1]);
280 }
281
282 static void
setup_vertex_data_yuv(struct xa_context * r,float srcX,float srcY,float srcW,float srcH,float dstX,float dstY,float dstW,float dstH,struct xa_surface * srf[])283 setup_vertex_data_yuv(struct xa_context *r,
284 float srcX,
285 float srcY,
286 float srcW,
287 float srcH,
288 float dstX,
289 float dstY,
290 float dstW, float dstH, struct xa_surface *srf[])
291 {
292 float s0, t0, s1, t1;
293 float spt0[2], spt1[2];
294 struct pipe_resource *tex;
295
296 spt0[0] = srcX;
297 spt0[1] = srcY;
298 spt1[0] = srcX + srcW;
299 spt1[1] = srcY + srcH;
300
301 tex = srf[0]->tex;
302 s0 = spt0[0] / tex->width0;
303 t0 = spt0[1] / tex->height0;
304 s1 = spt1[0] / tex->width0;
305 t1 = spt1[1] / tex->height0;
306
307 /* 1st vertex */
308 add_vertex_1tex(r, dstX, dstY, s0, t0);
309 /* 2nd vertex */
310 add_vertex_1tex(r, dstX + dstW, dstY, s1, t0);
311 /* 3rd vertex */
312 add_vertex_1tex(r, dstX + dstW, dstY + dstH, s1, t1);
313 /* 4th vertex */
314 add_vertex_1tex(r, dstX, dstY + dstH, s0, t1);
315 }
316
317 /* Set up framebuffer, viewport and vertex shader constant buffer
318 * state for a particular destinaton surface. In all our rendering,
319 * these concepts are linked.
320 */
321 void
renderer_bind_destination(struct xa_context * r,struct pipe_surface * surface)322 renderer_bind_destination(struct xa_context *r,
323 struct pipe_surface *surface)
324 {
325 int width = surface->width;
326 int height = surface->height;
327
328 struct pipe_framebuffer_state fb;
329 struct pipe_viewport_state viewport;
330
331 xa_scissor_reset(r);
332
333 /* Framebuffer uses actual surface width/height
334 */
335 memset(&fb, 0, sizeof fb);
336 fb.width = surface->width;
337 fb.height = surface->height;
338 fb.nr_cbufs = 1;
339 fb.cbufs[0] = surface;
340 fb.zsbuf = NULL;
341
342 /* Viewport just touches the bit we're interested in:
343 */
344 viewport.scale[0] = width / 2.f;
345 viewport.scale[1] = height / 2.f;
346 viewport.scale[2] = 1.0;
347 viewport.translate[0] = width / 2.f;
348 viewport.translate[1] = height / 2.f;
349 viewport.translate[2] = 0.0;
350 viewport.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
351 viewport.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
352 viewport.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
353 viewport.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
354
355 /* Constant buffer set up to match viewport dimensions:
356 */
357 if (r->fb_width != width || r->fb_height != height) {
358 float vs_consts[8] = {
359 2.f / width, 2.f / height, 1, 1,
360 -1, -1, 0, 0
361 };
362
363 r->fb_width = width;
364 r->fb_height = height;
365
366 renderer_set_constants(r, PIPE_SHADER_VERTEX,
367 vs_consts, sizeof vs_consts);
368 }
369
370 cso_set_framebuffer(r->cso, &fb);
371 cso_set_viewport(r->cso, &viewport);
372 }
373
374 void
renderer_set_constants(struct xa_context * r,int shader_type,const float * params,int param_bytes)375 renderer_set_constants(struct xa_context *r,
376 int shader_type, const float *params, int param_bytes)
377 {
378 struct pipe_resource **cbuf =
379 (shader_type == PIPE_SHADER_VERTEX) ? &r->vs_const_buffer :
380 &r->fs_const_buffer;
381
382 pipe_resource_reference(cbuf, NULL);
383 *cbuf = pipe_buffer_create_const0(r->pipe->screen,
384 PIPE_BIND_CONSTANT_BUFFER,
385 PIPE_USAGE_DEFAULT,
386 param_bytes);
387
388 if (*cbuf) {
389 pipe_buffer_write(r->pipe, *cbuf, 0, param_bytes, params);
390 }
391 pipe_set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
392 }
393
394 void
renderer_copy_prepare(struct xa_context * r,struct pipe_surface * dst_surface,struct pipe_resource * src_texture,const enum xa_formats src_xa_format,const enum xa_formats dst_xa_format)395 renderer_copy_prepare(struct xa_context *r,
396 struct pipe_surface *dst_surface,
397 struct pipe_resource *src_texture,
398 const enum xa_formats src_xa_format,
399 const enum xa_formats dst_xa_format)
400 {
401 struct pipe_context *pipe = r->pipe;
402 struct pipe_screen *screen = pipe->screen;
403 struct xa_shader shader;
404 uint32_t fs_traits = FS_COMPOSITE;
405
406 assert(screen->is_format_supported(screen, dst_surface->format,
407 PIPE_TEXTURE_2D, 0, 0,
408 PIPE_BIND_RENDER_TARGET));
409 (void)screen;
410
411 renderer_bind_destination(r, dst_surface);
412
413 /* set misc state we care about */
414 {
415 struct pipe_blend_state blend;
416
417 memset(&blend, 0, sizeof(blend));
418 blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
419 blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
420 blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
421 blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
422 blend.rt[0].colormask = PIPE_MASK_RGBA;
423 cso_set_blend(r->cso, &blend);
424 }
425
426 /* sampler */
427 {
428 struct pipe_sampler_state sampler;
429 const struct pipe_sampler_state *p_sampler = &sampler;
430
431 memset(&sampler, 0, sizeof(sampler));
432 sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
433 sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
434 sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
435 sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
436 sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
437 sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
438 cso_set_samplers(r->cso, PIPE_SHADER_FRAGMENT, 1, &p_sampler);
439 r->num_bound_samplers = 1;
440 }
441
442 /* texture/sampler view */
443 {
444 struct pipe_sampler_view templ;
445 struct pipe_sampler_view *src_view;
446
447 u_sampler_view_default_template(&templ,
448 src_texture, src_texture->format);
449 src_view = pipe->create_sampler_view(pipe, src_texture, &templ);
450 pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &src_view);
451 pipe_sampler_view_reference(&src_view, NULL);
452 }
453
454 /* shaders */
455 if (src_texture->format == PIPE_FORMAT_L8_UNORM ||
456 src_texture->format == PIPE_FORMAT_R8_UNORM)
457 fs_traits |= FS_SRC_LUMINANCE;
458 if (dst_surface->format == PIPE_FORMAT_L8_UNORM ||
459 dst_surface->format == PIPE_FORMAT_R8_UNORM)
460 fs_traits |= FS_DST_LUMINANCE;
461 if (xa_format_a(dst_xa_format) != 0 &&
462 xa_format_a(src_xa_format) == 0)
463 fs_traits |= FS_SRC_SET_ALPHA;
464
465 shader = xa_shaders_get(r->shaders, VS_COMPOSITE, fs_traits);
466 cso_set_vertex_shader_handle(r->cso, shader.vs);
467 cso_set_fragment_shader_handle(r->cso, shader.fs);
468
469 r->buffer_size = 0;
470 r->attrs_per_vertex = 2;
471 }
472
473 void
renderer_copy(struct xa_context * r,int dx,int dy,int sx,int sy,int width,int height,float src_width,float src_height)474 renderer_copy(struct xa_context *r,
475 int dx,
476 int dy,
477 int sx,
478 int sy,
479 int width, int height, float src_width, float src_height)
480 {
481 float s0, t0, s1, t1;
482 float x0, y0, x1, y1;
483
484 /* XXX: could put the texcoord scaling calculation into the vertex
485 * shader.
486 */
487 s0 = sx / src_width;
488 s1 = (sx + width) / src_width;
489 t0 = sy / src_height;
490 t1 = (sy + height) / src_height;
491
492 x0 = dx;
493 x1 = dx + width;
494 y0 = dy;
495 y1 = dy + height;
496
497 /* draw quad */
498 renderer_draw_conditional(r, 4 * 8);
499 add_vertex_1tex(r, x0, y0, s0, t0);
500 add_vertex_1tex(r, x1, y0, s1, t0);
501 add_vertex_1tex(r, x1, y1, s1, t1);
502 add_vertex_1tex(r, x0, y1, s0, t1);
503 }
504
505 void
renderer_draw_yuv(struct xa_context * r,float src_x,float src_y,float src_w,float src_h,int dst_x,int dst_y,int dst_w,int dst_h,struct xa_surface * srf[])506 renderer_draw_yuv(struct xa_context *r,
507 float src_x,
508 float src_y,
509 float src_w,
510 float src_h,
511 int dst_x,
512 int dst_y, int dst_w, int dst_h, struct xa_surface *srf[])
513 {
514 const int num_attribs = 2; /*pos + tex coord */
515
516 setup_vertex_data_yuv(r,
517 src_x, src_y, src_w, src_h,
518 dst_x, dst_y, dst_w, dst_h, srf);
519
520 if (!r->scissor_valid) {
521 r->scissor.minx = 0;
522 r->scissor.miny = 0;
523 r->scissor.maxx = r->dst->tex->width0;
524 r->scissor.maxy = r->dst->tex->height0;
525 }
526
527 r->pipe->set_scissor_states(r->pipe, 0, 1, &r->scissor);
528
529 struct cso_velems_state velems;
530 velems.count = num_attribs;
531 memcpy(velems.velems, r->velems, sizeof(r->velems[0]) * velems.count);
532 for (unsigned i = 0; i < velems.count; i++)
533 velems.velems[i].src_stride = velems.count * 4 * sizeof(float);
534
535 cso_set_vertex_elements(r->cso, &velems);
536 util_draw_user_vertex_buffer(r->cso, r->buffer, MESA_PRIM_QUADS,
537 4, /* verts */
538 num_attribs); /* attribs/vert */
539 r->buffer_size = 0;
540
541 xa_scissor_reset(r);
542 }
543
544 void
renderer_begin_solid(struct xa_context * r)545 renderer_begin_solid(struct xa_context *r)
546 {
547 r->buffer_size = 0;
548 r->attrs_per_vertex = 1;
549 renderer_set_constants(r, PIPE_SHADER_FRAGMENT, r->solid_color,
550 4 * sizeof(float));
551 }
552
553 void
renderer_solid(struct xa_context * r,int x0,int y0,int x1,int y1)554 renderer_solid(struct xa_context *r,
555 int x0, int y0, int x1, int y1)
556 {
557 /*
558 * debug_printf("solid rect[(%d, %d), (%d, %d)], rgba[%f, %f, %f, %f]\n",
559 * x0, y0, x1, y1, color[0], color[1], color[2], color[3]); */
560
561 renderer_draw_conditional(r, 4 * 4);
562
563 /* 1st vertex */
564 add_vertex_none(r, x0, y0);
565 /* 2nd vertex */
566 add_vertex_none(r, x1, y0);
567 /* 3rd vertex */
568 add_vertex_none(r, x1, y1);
569 /* 4th vertex */
570 add_vertex_none(r, x0, y1);
571 }
572
573 void
renderer_draw_flush(struct xa_context * r)574 renderer_draw_flush(struct xa_context *r)
575 {
576 renderer_draw_conditional(r, 0);
577 }
578
579 void
renderer_begin_textures(struct xa_context * r)580 renderer_begin_textures(struct xa_context *r)
581 {
582 r->attrs_per_vertex = 1 + r->num_bound_samplers;
583 r->buffer_size = 0;
584 if (r->has_solid_src || r->has_solid_mask)
585 renderer_set_constants(r, PIPE_SHADER_FRAGMENT, r->solid_color,
586 4 * sizeof(float));
587 }
588
589 void
renderer_texture(struct xa_context * r,int * pos,int width,int height,const float * src_matrix,const float * mask_matrix)590 renderer_texture(struct xa_context *r,
591 int *pos,
592 int width, int height,
593 const float *src_matrix,
594 const float *mask_matrix)
595 {
596 struct pipe_sampler_view **sampler_view = r->bound_sampler_views;
597
598 #if 0
599 if (src_matrix) {
600 debug_printf("src_matrix = \n");
601 debug_printf("%f, %f, %f\n", src_matrix[0], src_matrix[1], src_matrix[2]);
602 debug_printf("%f, %f, %f\n", src_matrix[3], src_matrix[4], src_matrix[5]);
603 debug_printf("%f, %f, %f\n", src_matrix[6], src_matrix[7], src_matrix[8]);
604 }
605 if (mask_matrix) {
606 debug_printf("mask_matrix = \n");
607 debug_printf("%f, %f, %f\n", mask_matrix[0], mask_matrix[1], mask_matrix[2]);
608 debug_printf("%f, %f, %f\n", mask_matrix[3], mask_matrix[4], mask_matrix[5]);
609 debug_printf("%f, %f, %f\n", mask_matrix[6], mask_matrix[7], mask_matrix[8]);
610 }
611 #endif
612
613 switch(r->attrs_per_vertex) {
614 case 2:
615 renderer_draw_conditional(r, 4 * 8);
616 if (!r->has_solid_src) {
617 add_vertex_data1(r,
618 pos[0], pos[1], /* src */
619 pos[4], pos[5], /* dst */
620 width, height,
621 sampler_view[0]->texture, src_matrix);
622 } else {
623 add_vertex_data1(r,
624 pos[2], pos[3], /* mask */
625 pos[4], pos[5], /* dst */
626 width, height,
627 sampler_view[0]->texture, mask_matrix);
628 }
629 break;
630 case 3:
631 renderer_draw_conditional(r, 4 * 12);
632 add_vertex_data2(r,
633 pos[0], pos[1], /* src */
634 pos[2], pos[3], /* mask */
635 pos[4], pos[5], /* dst */
636 width, height,
637 sampler_view[0]->texture, sampler_view[1]->texture,
638 src_matrix, mask_matrix);
639 break;
640 default:
641 break;
642 }
643 }
644