2 #include "xorg_renderer.h"
4 #include "xorg_exa_tgsi.h"
6 #include "cso_cache/cso_context.h"
7 #include "util/u_draw_quad.h"
8 #include "util/u_math.h"
9 #include "util/u_memory.h"
10 #include "util/u_rect.h"
12 #include "pipe/p_inlines.h"
16 enum AxisOrientation
{
21 #define floatsEqual(x, y) (fabs(x - y) <= 0.00001f * MIN2(fabs(x), fabs(y)))
22 #define floatIsZero(x) (floatsEqual((x) + 1, 1))
24 #define NUM_COMPONENTS 4
26 static INLINE boolean
is_affine(float *matrix
)
28 return floatIsZero(matrix
[2]) && floatIsZero(matrix
[5])
29 && floatsEqual(matrix
[8], 1);
31 static INLINE
void map_point(float *mat
, float x
, float y
,
32 float *out_x
, float *out_y
)
40 *out_x
= mat
[0]*x
+ mat
[3]*y
+ mat
[6];
41 *out_y
= mat
[1]*x
+ mat
[4]*y
+ mat
[7];
42 if (!is_affine(mat
)) {
43 float w
= 1/(mat
[2]*x
+ mat
[5]*y
+ mat
[8]);
49 static INLINE
struct pipe_buffer
*
50 renderer_buffer_create(struct xorg_renderer
*r
)
52 struct pipe_buffer
*buf
=
53 pipe_user_buffer_create(r
->pipe
->screen
,
63 renderer_draw(struct xorg_renderer
*r
)
65 struct pipe_context
*pipe
= r
->pipe
;
66 struct pipe_buffer
*buf
= 0;
67 int num_verts
= r
->buffer_size
/(r
->attrs_per_vertex
* NUM_COMPONENTS
);
72 buf
= renderer_buffer_create(r
);
76 util_draw_vertex_buffer(pipe
, buf
, 0,
78 num_verts
, /* verts */
79 r
->attrs_per_vertex
); /* attribs/vert */
81 pipe_buffer_reference(&buf
, NULL
);
82 pipe
->flush(pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
87 renderer_draw_conditional(struct xorg_renderer
*r
,
90 if (r
->buffer_size
+ next_batch
>= BUF_SIZE
||
91 (next_batch
== 0 && r
->buffer_size
)) {
97 renderer_init_state(struct xorg_renderer
*r
)
99 struct pipe_depth_stencil_alpha_state dsa
;
101 /* set common initial clip state */
102 memset(&dsa
, 0, sizeof(struct pipe_depth_stencil_alpha_state
));
103 cso_set_depth_stencil_alpha(r
->cso
, &dsa
);
108 add_vertex_color(struct xorg_renderer
*r
,
112 float *vertex
= r
->buffer
+ r
->buffer_size
;
116 vertex
[2] = 0.f
; /*z*/
117 vertex
[3] = 1.f
; /*w*/
119 vertex
[4] = color
[0]; /*r*/
120 vertex
[5] = color
[1]; /*g*/
121 vertex
[6] = color
[2]; /*b*/
122 vertex
[7] = color
[3]; /*a*/
128 add_vertex_1tex(struct xorg_renderer
*r
,
129 float x
, float y
, float s
, float t
)
131 float *vertex
= r
->buffer
+ r
->buffer_size
;
135 vertex
[2] = 0.f
; /*z*/
136 vertex
[3] = 1.f
; /*w*/
140 vertex
[6] = 0.f
; /*r*/
141 vertex
[7] = 1.f
; /*q*/
147 add_vertex_data1(struct xorg_renderer
*r
,
148 float srcX
, float srcY
, float dstX
, float dstY
,
149 float width
, float height
,
150 struct pipe_texture
*src
, float *src_matrix
)
152 float s0
, t0
, s1
, t1
, s2
, t2
, s3
, t3
;
153 float pt0
[2], pt1
[2], pt2
[2], pt3
[2];
157 pt1
[0] = (srcX
+ width
);
159 pt2
[0] = (srcX
+ width
);
160 pt2
[1] = (srcY
+ height
);
162 pt3
[1] = (srcY
+ height
);
165 map_point(src_matrix
, pt0
[0], pt0
[1], &pt0
[0], &pt0
[1]);
166 map_point(src_matrix
, pt1
[0], pt1
[1], &pt1
[0], &pt1
[1]);
167 map_point(src_matrix
, pt2
[0], pt2
[1], &pt2
[0], &pt2
[1]);
168 map_point(src_matrix
, pt3
[0], pt3
[1], &pt3
[0], &pt3
[1]);
171 s0
= pt0
[0] / src
->width
[0];
172 s1
= pt1
[0] / src
->width
[0];
173 s2
= pt2
[0] / src
->width
[0];
174 s3
= pt3
[0] / src
->width
[0];
175 t0
= pt0
[1] / src
->height
[0];
176 t1
= pt1
[1] / src
->height
[0];
177 t2
= pt2
[1] / src
->height
[0];
178 t3
= pt3
[1] / src
->height
[0];
181 add_vertex_1tex(r
, dstX
, dstY
, s0
, t0
);
183 add_vertex_1tex(r
, dstX
+ width
, dstY
, s1
, t1
);
185 add_vertex_1tex(r
, dstX
+ width
, dstY
+ height
, s2
, t2
);
187 add_vertex_1tex(r
, dstX
, dstY
+ height
, s3
, t3
);
190 static struct pipe_buffer
*
191 setup_vertex_data_tex(struct xorg_renderer
*r
,
192 float x0
, float y0
, float x1
, float y1
,
193 float s0
, float t0
, float s1
, float t1
,
197 add_vertex_1tex(r
, x0
, y0
, s0
, t0
);
199 add_vertex_1tex(r
, x1
, y0
, s1
, t0
);
201 add_vertex_1tex(r
, x1
, y1
, s1
, t1
);
203 add_vertex_1tex(r
, x0
, y1
, s0
, t1
);
205 return renderer_buffer_create(r
);
209 add_vertex_2tex(struct xorg_renderer
*r
,
211 float s0
, float t0
, float s1
, float t1
)
213 float *vertex
= r
->buffer
+ r
->buffer_size
;
217 vertex
[2] = 0.f
; /*z*/
218 vertex
[3] = 1.f
; /*w*/
220 vertex
[4] = s0
; /*s*/
221 vertex
[5] = t0
; /*t*/
222 vertex
[6] = 0.f
; /*r*/
223 vertex
[7] = 1.f
; /*q*/
225 vertex
[8] = s1
; /*s*/
226 vertex
[9] = t1
; /*t*/
227 vertex
[10] = 0.f
; /*r*/
228 vertex
[11] = 1.f
; /*q*/
230 r
->buffer_size
+= 12;
234 add_vertex_data2(struct xorg_renderer
*r
,
235 float srcX
, float srcY
, float maskX
, float maskY
,
236 float dstX
, float dstY
, float width
, float height
,
237 struct pipe_texture
*src
,
238 struct pipe_texture
*mask
,
239 float *src_matrix
, float *mask_matrix
)
241 float src_s0
, src_t0
, src_s1
, src_t1
;
242 float mask_s0
, mask_t0
, mask_s1
, mask_t1
;
243 float spt0
[2], spt1
[2];
244 float mpt0
[2], mpt1
[2];
248 spt1
[0] = srcX
+ width
;
249 spt1
[1] = srcY
+ height
;
253 mpt1
[0] = maskX
+ width
;
254 mpt1
[1] = maskY
+ height
;
257 map_point(src_matrix
, spt0
[0], spt0
[1], &spt0
[0], &spt0
[1]);
258 map_point(src_matrix
, spt1
[0], spt1
[1], &spt1
[0], &spt1
[1]);
262 map_point(mask_matrix
, mpt0
[0], mpt0
[1], &mpt0
[0], &mpt0
[1]);
263 map_point(mask_matrix
, mpt1
[0], mpt1
[1], &mpt1
[0], &mpt1
[1]);
266 src_s0
= spt0
[0] / src
->width
[0];
267 src_t0
= spt0
[1] / src
->height
[0];
268 src_s1
= spt1
[0] / src
->width
[0];
269 src_t1
= spt1
[1] / src
->height
[0];
271 mask_s0
= mpt0
[0] / mask
->width
[0];
272 mask_t0
= mpt0
[1] / mask
->height
[0];
273 mask_s1
= mpt1
[0] / mask
->width
[0];
274 mask_t1
= mpt1
[1] / mask
->height
[0];
277 add_vertex_2tex(r
, dstX
, dstY
,
278 src_s0
, src_t0
, mask_s0
, mask_t0
);
280 add_vertex_2tex(r
, dstX
+ width
, dstY
,
281 src_s1
, src_t0
, mask_s1
, mask_t0
);
283 add_vertex_2tex(r
, dstX
+ width
, dstY
+ height
,
284 src_s1
, src_t1
, mask_s1
, mask_t1
);
286 add_vertex_2tex(r
, dstX
, dstY
+ height
,
287 src_s0
, src_t1
, mask_s0
, mask_t1
);
290 static struct pipe_buffer
*
291 setup_vertex_data_yuv(struct xorg_renderer
*r
,
292 float srcX
, float srcY
, float srcW
, float srcH
,
293 float dstX
, float dstY
, float dstW
, float dstH
,
294 struct pipe_texture
**tex
)
296 float s0
, t0
, s1
, t1
;
297 float spt0
[2], spt1
[2];
301 spt1
[0] = srcX
+ srcW
;
302 spt1
[1] = srcY
+ srcH
;
304 s0
= spt0
[0] / tex
[0]->width
[0];
305 t0
= spt0
[1] / tex
[0]->height
[0];
306 s1
= spt1
[0] / tex
[0]->width
[0];
307 t1
= spt1
[1] / tex
[0]->height
[0];
310 add_vertex_1tex(r
, dstX
, dstY
, s0
, t0
);
312 add_vertex_1tex(r
, dstX
+ dstW
, dstY
,
315 add_vertex_1tex(r
, dstX
+ dstW
, dstY
+ dstH
,
318 add_vertex_1tex(r
, dstX
, dstY
+ dstH
,
321 return renderer_buffer_create(r
);
326 /* Set up framebuffer, viewport and vertex shader constant buffer
327 * state for a particular destinaton surface. In all our rendering,
328 * these concepts are linked.
330 void renderer_bind_destination(struct xorg_renderer
*r
,
331 struct pipe_surface
*surface
)
334 struct pipe_framebuffer_state fb
;
335 struct pipe_viewport_state viewport
;
336 int width
= surface
->width
;
337 int height
= surface
->height
;
339 memset(&fb
, 0, sizeof fb
);
343 fb
.cbufs
[0] = surface
;
346 viewport
.scale
[0] = width
/ 2.f
;
347 viewport
.scale
[1] = height
/ 2.f
;
348 viewport
.scale
[2] = 1.0;
349 viewport
.scale
[3] = 1.0;
350 viewport
.translate
[0] = width
/ 2.f
;
351 viewport
.translate
[1] = height
/ 2.f
;
352 viewport
.translate
[2] = 0.0;
353 viewport
.translate
[3] = 0.0;
355 if (r
->fb_width
!= width
||
356 r
->fb_height
!= height
)
358 float vs_consts
[8] = {
359 2.f
/width
, 2.f
/height
, 1, 1,
364 r
->fb_height
= height
;
366 renderer_set_constants(r
, PIPE_SHADER_VERTEX
,
367 vs_consts
, sizeof vs_consts
);
370 cso_set_framebuffer(r
->cso
, &fb
);
371 cso_set_viewport(r
->cso
, &viewport
);
375 struct xorg_renderer
* renderer_create(struct pipe_context
*pipe
)
377 struct xorg_renderer
*renderer
= CALLOC_STRUCT(xorg_renderer
);
379 renderer
->pipe
= pipe
;
380 renderer
->cso
= cso_create_context(pipe
);
381 renderer
->shaders
= xorg_shaders_create(renderer
);
383 renderer_init_state(renderer
);
388 void renderer_destroy(struct xorg_renderer
*r
)
390 struct pipe_constant_buffer
*vsbuf
= &r
->vs_const_buffer
;
391 struct pipe_constant_buffer
*fsbuf
= &r
->fs_const_buffer
;
393 if (vsbuf
&& vsbuf
->buffer
)
394 pipe_buffer_reference(&vsbuf
->buffer
, NULL
);
396 if (fsbuf
&& fsbuf
->buffer
)
397 pipe_buffer_reference(&fsbuf
->buffer
, NULL
);
400 xorg_shaders_destroy(r
->shaders
);
405 cso_release_all(r
->cso
);
406 cso_destroy_context(r
->cso
);
415 void renderer_bind_rasterizer(struct xorg_renderer
*r
)
417 struct pipe_rasterizer_state raster
;
419 /* XXX: move to renderer_init_state? */
420 memset(&raster
, 0, sizeof(struct pipe_rasterizer_state
));
421 raster
.gl_rasterization_rules
= 1;
422 cso_set_rasterizer(r
->cso
, &raster
);
425 void renderer_set_constants(struct xorg_renderer
*r
,
430 struct pipe_constant_buffer
*cbuf
=
431 (shader_type
== PIPE_SHADER_VERTEX
) ? &r
->vs_const_buffer
:
434 pipe_buffer_reference(&cbuf
->buffer
, NULL
);
435 cbuf
->buffer
= pipe_buffer_create(r
->pipe
->screen
, 16,
436 PIPE_BUFFER_USAGE_CONSTANT
,
440 pipe_buffer_write(r
->pipe
->screen
, cbuf
->buffer
,
441 0, param_bytes
, params
);
443 r
->pipe
->set_constant_buffer(r
->pipe
, shader_type
, 0, cbuf
);
447 setup_fs_constant_buffer(struct xorg_renderer
*r
)
449 const int param_bytes
= 4 * sizeof(float);
450 const float fs_consts
[8] = {
453 renderer_set_constants(r
, PIPE_SHADER_FRAGMENT
,
454 fs_consts
, param_bytes
);
457 static INLINE
void shift_rectx(float coords
[4],
464 coords
[2] = MIN2(coords
[2], bounds
[2]);
465 /* bound x/y + width/height */
466 if ((coords
[0] + coords
[2]) > (bounds
[0] + bounds
[2])) {
467 coords
[2] = (bounds
[0] + bounds
[2]) - coords
[0];
472 static INLINE
void shift_recty(float coords
[4],
479 coords
[3] = MIN2(coords
[3], bounds
[3]);
480 if ((coords
[1] + coords
[3]) > (bounds
[1] + bounds
[3])) {
481 coords
[3] = (bounds
[1] + bounds
[3]) - coords
[1];
486 static INLINE
void bound_rect(float coords
[4],
487 const float bounds
[4],
490 /* if outside the bounds */
491 if (coords
[0] > (bounds
[0] + bounds
[2]) ||
492 coords
[1] > (bounds
[1] + bounds
[3]) ||
493 (coords
[0] + coords
[2]) < bounds
[0] ||
494 (coords
[1] + coords
[3]) < bounds
[1]) {
505 if (coords
[0] < bounds
[0]) {
506 shift
[0] = bounds
[0] - coords
[0];
507 coords
[2] -= shift
[0];
508 coords
[0] = bounds
[0];
513 if (coords
[1] < bounds
[1]) {
514 shift
[1] = bounds
[1] - coords
[1];
515 coords
[3] -= shift
[1];
516 coords
[1] = bounds
[1];
520 shift
[2] = bounds
[2] - coords
[2];
521 shift
[3] = bounds
[3] - coords
[3];
522 /* bound width/height */
523 coords
[2] = MIN2(coords
[2], bounds
[2]);
524 coords
[3] = MIN2(coords
[3], bounds
[3]);
526 /* bound x/y + width/height */
527 if ((coords
[0] + coords
[2]) > (bounds
[0] + bounds
[2])) {
528 coords
[2] = (bounds
[0] + bounds
[2]) - coords
[0];
530 if ((coords
[1] + coords
[3]) > (bounds
[1] + bounds
[3])) {
531 coords
[3] = (bounds
[1] + bounds
[3]) - coords
[1];
534 /* if outside the bounds */
535 if ((coords
[0] + coords
[2]) < bounds
[0] ||
536 (coords
[1] + coords
[3]) < bounds
[1]) {
545 static INLINE
void sync_size(float *src_loc
, float *dst_loc
)
547 src_loc
[2] = MIN2(src_loc
[2], dst_loc
[2]);
548 src_loc
[3] = MIN2(src_loc
[3], dst_loc
[3]);
549 dst_loc
[2] = src_loc
[2];
550 dst_loc
[3] = src_loc
[3];
553 static void renderer_copy_texture(struct xorg_renderer
*r
,
554 struct pipe_texture
*src
,
555 float sx1
, float sy1
,
556 float sx2
, float sy2
,
557 struct pipe_texture
*dst
,
558 float dx1
, float dy1
,
559 float dx2
, float dy2
)
561 struct pipe_context
*pipe
= r
->pipe
;
562 struct pipe_screen
*screen
= pipe
->screen
;
563 struct pipe_buffer
*buf
;
564 struct pipe_surface
*dst_surf
= screen
->get_tex_surface(
565 screen
, dst
, 0, 0, 0,
566 PIPE_BUFFER_USAGE_GPU_WRITE
);
567 float s0
, t0
, s1
, t1
;
568 struct xorg_shader shader
;
570 assert(src
->width
[0] != 0);
571 assert(src
->height
[0] != 0);
572 assert(dst
->width
[0] != 0);
573 assert(dst
->height
[0] != 0);
576 s0
= sx1
/ src
->width
[0];
577 s1
= sx2
/ src
->width
[0];
578 t0
= sy1
/ src
->height
[0];
579 t1
= sy2
/ src
->height
[0];
588 debug_printf("copy texture src=[%f, %f, %f, %f], dst=[%f, %f, %f, %f], tex=[%f, %f, %f, %f]\n",
589 sx1
, sy1
, sx2
, sy2
, dx1
, dy1
, dx2
, dy2
,
593 assert(screen
->is_format_supported(screen
, dst_surf
->format
,
595 PIPE_TEXTURE_USAGE_RENDER_TARGET
,
598 /* save state (restored below) */
599 cso_save_blend(r
->cso
);
600 cso_save_samplers(r
->cso
);
601 cso_save_sampler_textures(r
->cso
);
602 cso_save_framebuffer(r
->cso
);
603 cso_save_fragment_shader(r
->cso
);
604 cso_save_vertex_shader(r
->cso
);
606 cso_save_viewport(r
->cso
);
609 /* set misc state we care about */
611 struct pipe_blend_state blend
;
612 memset(&blend
, 0, sizeof(blend
));
613 blend
.rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
614 blend
.alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
615 blend
.rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
616 blend
.alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
617 blend
.colormask
= PIPE_MASK_RGBA
;
618 cso_set_blend(r
->cso
, &blend
);
623 struct pipe_sampler_state sampler
;
624 memset(&sampler
, 0, sizeof(sampler
));
625 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
626 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
627 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
628 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
629 sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
630 sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
631 sampler
.normalized_coords
= 1;
632 cso_single_sampler(r
->cso
, 0, &sampler
);
633 cso_single_sampler_done(r
->cso
);
636 renderer_bind_destination(r
, dst_surf
);
639 cso_set_sampler_textures(r
->cso
, 1, &src
);
641 renderer_bind_rasterizer(r
);
644 shader
= xorg_shaders_get(r
->shaders
,
647 cso_set_vertex_shader_handle(r
->cso
, shader
.vs
);
648 cso_set_fragment_shader_handle(r
->cso
, shader
.fs
);
650 setup_fs_constant_buffer(r
);
653 buf
= setup_vertex_data_tex(r
,
660 util_draw_vertex_buffer(r
->pipe
, buf
, 0,
663 2); /* attribs/vert */
665 pipe_buffer_reference(&buf
, NULL
);
668 /* restore state we changed */
669 cso_restore_blend(r
->cso
);
670 cso_restore_samplers(r
->cso
);
671 cso_restore_sampler_textures(r
->cso
);
672 cso_restore_framebuffer(r
->cso
);
673 cso_restore_vertex_shader(r
->cso
);
674 cso_restore_fragment_shader(r
->cso
);
675 cso_restore_viewport(r
->cso
);
677 pipe_surface_reference(&dst_surf
, NULL
);
680 static struct pipe_texture
*
681 create_sampler_texture(struct xorg_renderer
*r
,
682 struct pipe_texture
*src
)
684 enum pipe_format format
;
685 struct pipe_context
*pipe
= r
->pipe
;
686 struct pipe_screen
*screen
= pipe
->screen
;
687 struct pipe_texture
*pt
;
688 struct pipe_texture templ
;
690 pipe
->flush(pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
692 /* the coming in texture should already have that invariance */
693 debug_assert(screen
->is_format_supported(screen
, src
->format
,
695 PIPE_TEXTURE_USAGE_SAMPLER
, 0));
697 format
= src
->format
;
699 memset(&templ
, 0, sizeof(templ
));
700 templ
.target
= PIPE_TEXTURE_2D
;
701 templ
.format
= format
;
702 templ
.last_level
= 0;
703 templ
.width
[0] = src
->width
[0];
704 templ
.height
[0] = src
->height
[0];
706 pf_get_block(format
, &templ
.block
);
707 templ
.tex_usage
= PIPE_TEXTURE_USAGE_SAMPLER
;
709 pt
= screen
->texture_create(screen
, &templ
);
711 debug_assert(!pt
|| pipe_is_referenced(&pt
->reference
));
717 /* copy source framebuffer surface into texture */
718 struct pipe_surface
*ps_read
= screen
->get_tex_surface(
719 screen
, src
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ
);
720 struct pipe_surface
*ps_tex
= screen
->get_tex_surface(
721 screen
, pt
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
722 if (pipe
->surface_copy
) {
723 pipe
->surface_copy(pipe
,
727 0, 0, src
->width
[0], src
->height
[0]);
729 util_surface_copy(pipe
, FALSE
,
733 0, 0, src
->width
[0], src
->height
[0]);
735 pipe_surface_reference(&ps_read
, NULL
);
736 pipe_surface_reference(&ps_tex
, NULL
);
743 void renderer_copy_pixmap(struct xorg_renderer
*r
,
744 struct exa_pixmap_priv
*dst_priv
, int dx
, int dy
,
745 struct exa_pixmap_priv
*src_priv
, int sx
, int sy
,
746 int width
, int height
)
748 float dst_loc
[4], src_loc
[4];
749 float dst_bounds
[4], src_bounds
[4];
750 float src_shift
[4], dst_shift
[4], shift
[4];
751 struct pipe_texture
*dst
= dst_priv
->tex
;
752 struct pipe_texture
*src
= src_priv
->tex
;
754 if (r
->pipe
->is_texture_referenced(r
->pipe
, src
, 0, 0) &
755 PIPE_REFERENCED_FOR_WRITE
)
756 r
->pipe
->flush(r
->pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
764 dst_bounds
[2] = dst
->width
[0];
765 dst_bounds
[3] = dst
->height
[0];
773 src_bounds
[2] = src
->width
[0];
774 src_bounds
[3] = src
->height
[0];
776 bound_rect(src_loc
, src_bounds
, src_shift
);
777 bound_rect(dst_loc
, dst_bounds
, dst_shift
);
778 shift
[0] = src_shift
[0] - dst_shift
[0];
779 shift
[1] = src_shift
[1] - dst_shift
[1];
782 shift_rectx(src_loc
, src_bounds
, -shift
[0]);
784 shift_rectx(dst_loc
, dst_bounds
, shift
[0]);
787 shift_recty(src_loc
, src_bounds
, -shift
[1]);
789 shift_recty(dst_loc
, dst_bounds
, shift
[1]);
791 sync_size(src_loc
, dst_loc
);
793 if (src_loc
[2] >= 0 && src_loc
[3] >= 0 &&
794 dst_loc
[2] >= 0 && dst_loc
[3] >= 0) {
795 struct pipe_texture
*temp_src
= src
;
798 temp_src
= create_sampler_texture(r
, src
);
800 renderer_copy_texture(r
,
804 src_loc
[0] + src_loc
[2],
805 src_loc
[1] + src_loc
[3],
809 dst_loc
[0] + dst_loc
[2],
810 dst_loc
[1] + dst_loc
[3]);
813 pipe_texture_reference(&temp_src
, NULL
);
817 void renderer_draw_yuv(struct xorg_renderer
*r
,
818 int src_x
, int src_y
, int src_w
, int src_h
,
819 int dst_x
, int dst_y
, int dst_w
, int dst_h
,
820 struct pipe_texture
**textures
)
822 struct pipe_context
*pipe
= r
->pipe
;
823 struct pipe_buffer
*buf
= 0;
825 buf
= setup_vertex_data_yuv(r
,
826 src_x
, src_y
, src_w
, src_h
,
827 dst_x
, dst_y
, dst_w
, dst_h
,
831 const int num_attribs
= 2; /*pos + tex coord*/
833 util_draw_vertex_buffer(pipe
, buf
, 0,
836 num_attribs
); /* attribs/vert */
838 pipe_buffer_reference(&buf
, NULL
);
842 void renderer_begin_solid(struct xorg_renderer
*r
)
845 r
->attrs_per_vertex
= 2;
848 void renderer_solid(struct xorg_renderer
*r
,
854 debug_printf("solid rect[(%d, %d), (%d, %d)], rgba[%f, %f, %f, %f]\n",
855 x0, y0, x1, y1, color[0], color[1], color[2], color[3]);*/
857 renderer_draw_conditional(r
, 4 * 8);
860 add_vertex_color(r
, x0
, y0
, color
);
862 add_vertex_color(r
, x1
, y0
, color
);
864 add_vertex_color(r
, x1
, y1
, color
);
866 add_vertex_color(r
, x0
, y1
, color
);
869 void renderer_draw_flush(struct xorg_renderer
*r
)
871 renderer_draw_conditional(r
, 0);
874 void renderer_begin_textures(struct xorg_renderer
*r
,
875 struct pipe_texture
**textures
,
878 r
->attrs_per_vertex
= 1 + num_textures
;
882 void renderer_texture(struct xorg_renderer
*r
,
884 int width
, int height
,
885 struct pipe_texture
**textures
,
893 debug_printf("src_matrix = \n");
894 debug_printf("%f, %f, %f\n", src_matrix
[0], src_matrix
[1], src_matrix
[2]);
895 debug_printf("%f, %f, %f\n", src_matrix
[3], src_matrix
[4], src_matrix
[5]);
896 debug_printf("%f, %f, %f\n", src_matrix
[6], src_matrix
[7], src_matrix
[8]);
899 debug_printf("mask_matrix = \n");
900 debug_printf("%f, %f, %f\n", mask_matrix
[0], mask_matrix
[1], mask_matrix
[2]);
901 debug_printf("%f, %f, %f\n", mask_matrix
[3], mask_matrix
[4], mask_matrix
[5]);
902 debug_printf("%f, %f, %f\n", mask_matrix
[6], mask_matrix
[7], mask_matrix
[8]);
906 switch(r
->attrs_per_vertex
) {
908 renderer_draw_conditional(r
, 4 * 8);
910 pos
[0], pos
[1], /* src */
911 pos
[4], pos
[5], /* dst */
913 textures
[0], src_matrix
);
916 renderer_draw_conditional(r
, 4 * 12);
918 pos
[0], pos
[1], /* src */
919 pos
[2], pos
[3], /* mask */
920 pos
[4], pos
[5], /* dst */
922 textures
[0], textures
[1],
923 src_matrix
, mask_matrix
);
926 debug_assert(!"Unsupported number of textures");