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
);
86 renderer_draw_conditional(struct xorg_renderer
*r
,
89 if (r
->buffer_size
+ next_batch
>= BUF_SIZE
||
90 (next_batch
== 0 && r
->buffer_size
)) {
96 renderer_init_state(struct xorg_renderer
*r
)
98 struct pipe_depth_stencil_alpha_state dsa
;
100 /* set common initial clip state */
101 memset(&dsa
, 0, sizeof(struct pipe_depth_stencil_alpha_state
));
102 cso_set_depth_stencil_alpha(r
->cso
, &dsa
);
107 add_vertex_color(struct xorg_renderer
*r
,
111 float *vertex
= r
->buffer
+ r
->buffer_size
;
115 vertex
[2] = 0.f
; /*z*/
116 vertex
[3] = 1.f
; /*w*/
118 vertex
[4] = color
[0]; /*r*/
119 vertex
[5] = color
[1]; /*g*/
120 vertex
[6] = color
[2]; /*b*/
121 vertex
[7] = color
[3]; /*a*/
127 add_vertex_1tex(struct xorg_renderer
*r
,
128 float x
, float y
, float s
, float t
)
130 float *vertex
= r
->buffer
+ r
->buffer_size
;
134 vertex
[2] = 0.f
; /*z*/
135 vertex
[3] = 1.f
; /*w*/
139 vertex
[6] = 0.f
; /*r*/
140 vertex
[7] = 1.f
; /*q*/
146 add_vertex_data1(struct xorg_renderer
*r
,
147 float srcX
, float srcY
, float dstX
, float dstY
,
148 float width
, float height
,
149 struct pipe_texture
*src
, float *src_matrix
)
151 float s0
, t0
, s1
, t1
, s2
, t2
, s3
, t3
;
152 float pt0
[2], pt1
[2], pt2
[2], pt3
[2];
156 pt1
[0] = (srcX
+ width
);
158 pt2
[0] = (srcX
+ width
);
159 pt2
[1] = (srcY
+ height
);
161 pt3
[1] = (srcY
+ height
);
164 map_point(src_matrix
, pt0
[0], pt0
[1], &pt0
[0], &pt0
[1]);
165 map_point(src_matrix
, pt1
[0], pt1
[1], &pt1
[0], &pt1
[1]);
166 map_point(src_matrix
, pt2
[0], pt2
[1], &pt2
[0], &pt2
[1]);
167 map_point(src_matrix
, pt3
[0], pt3
[1], &pt3
[0], &pt3
[1]);
170 s0
= pt0
[0] / src
->width
[0];
171 s1
= pt1
[0] / src
->width
[0];
172 s2
= pt2
[0] / src
->width
[0];
173 s3
= pt3
[0] / src
->width
[0];
174 t0
= pt0
[1] / src
->height
[0];
175 t1
= pt1
[1] / src
->height
[0];
176 t2
= pt2
[1] / src
->height
[0];
177 t3
= pt3
[1] / src
->height
[0];
180 add_vertex_1tex(r
, dstX
, dstY
, s0
, t0
);
182 add_vertex_1tex(r
, dstX
+ width
, dstY
, s1
, t1
);
184 add_vertex_1tex(r
, dstX
+ width
, dstY
+ height
, s2
, t2
);
186 add_vertex_1tex(r
, dstX
, dstY
+ height
, s3
, t3
);
189 static struct pipe_buffer
*
190 setup_vertex_data_tex(struct xorg_renderer
*r
,
191 float x0
, float y0
, float x1
, float y1
,
192 float s0
, float t0
, float s1
, float t1
,
196 add_vertex_1tex(r
, x0
, y0
, s0
, t0
);
198 add_vertex_1tex(r
, x1
, y0
, s1
, t0
);
200 add_vertex_1tex(r
, x1
, y1
, s1
, t1
);
202 add_vertex_1tex(r
, x0
, y1
, s0
, t1
);
204 return renderer_buffer_create(r
);
208 add_vertex_2tex(struct xorg_renderer
*r
,
210 float s0
, float t0
, float s1
, float t1
)
212 float *vertex
= r
->buffer
+ r
->buffer_size
;
216 vertex
[2] = 0.f
; /*z*/
217 vertex
[3] = 1.f
; /*w*/
219 vertex
[4] = s0
; /*s*/
220 vertex
[5] = t0
; /*t*/
221 vertex
[6] = 0.f
; /*r*/
222 vertex
[7] = 1.f
; /*q*/
224 vertex
[8] = s1
; /*s*/
225 vertex
[9] = t1
; /*t*/
226 vertex
[10] = 0.f
; /*r*/
227 vertex
[11] = 1.f
; /*q*/
229 r
->buffer_size
+= 12;
233 add_vertex_data2(struct xorg_renderer
*r
,
234 float srcX
, float srcY
, float maskX
, float maskY
,
235 float dstX
, float dstY
, float width
, float height
,
236 struct pipe_texture
*src
,
237 struct pipe_texture
*mask
,
238 float *src_matrix
, float *mask_matrix
)
240 float src_s0
, src_t0
, src_s1
, src_t1
;
241 float mask_s0
, mask_t0
, mask_s1
, mask_t1
;
242 float spt0
[2], spt1
[2];
243 float mpt0
[2], mpt1
[2];
247 spt1
[0] = srcX
+ width
;
248 spt1
[1] = srcY
+ height
;
252 mpt1
[0] = maskX
+ width
;
253 mpt1
[1] = maskY
+ height
;
256 map_point(src_matrix
, spt0
[0], spt0
[1], &spt0
[0], &spt0
[1]);
257 map_point(src_matrix
, spt1
[0], spt1
[1], &spt1
[0], &spt1
[1]);
261 map_point(mask_matrix
, mpt0
[0], mpt0
[1], &mpt0
[0], &mpt0
[1]);
262 map_point(mask_matrix
, mpt1
[0], mpt1
[1], &mpt1
[0], &mpt1
[1]);
265 src_s0
= spt0
[0] / src
->width
[0];
266 src_t0
= spt0
[1] / src
->height
[0];
267 src_s1
= spt1
[0] / src
->width
[0];
268 src_t1
= spt1
[1] / src
->height
[0];
270 mask_s0
= mpt0
[0] / mask
->width
[0];
271 mask_t0
= mpt0
[1] / mask
->height
[0];
272 mask_s1
= mpt1
[0] / mask
->width
[0];
273 mask_t1
= mpt1
[1] / mask
->height
[0];
276 add_vertex_2tex(r
, dstX
, dstY
,
277 src_s0
, src_t0
, mask_s0
, mask_t0
);
279 add_vertex_2tex(r
, dstX
+ width
, dstY
,
280 src_s1
, src_t0
, mask_s1
, mask_t0
);
282 add_vertex_2tex(r
, dstX
+ width
, dstY
+ height
,
283 src_s1
, src_t1
, mask_s1
, mask_t1
);
285 add_vertex_2tex(r
, dstX
, dstY
+ height
,
286 src_s0
, src_t1
, mask_s0
, mask_t1
);
289 static struct pipe_buffer
*
290 setup_vertex_data_yuv(struct xorg_renderer
*r
,
291 float srcX
, float srcY
, float srcW
, float srcH
,
292 float dstX
, float dstY
, float dstW
, float dstH
,
293 struct pipe_texture
**tex
)
295 float s0
, t0
, s1
, t1
;
296 float spt0
[2], spt1
[2];
300 spt1
[0] = srcX
+ srcW
;
301 spt1
[1] = srcY
+ srcH
;
303 s0
= spt0
[0] / tex
[0]->width
[0];
304 t0
= spt0
[1] / tex
[0]->height
[0];
305 s1
= spt1
[0] / tex
[0]->width
[0];
306 t1
= spt1
[1] / tex
[0]->height
[0];
309 add_vertex_1tex(r
, dstX
, dstY
, s0
, t0
);
311 add_vertex_1tex(r
, dstX
+ dstW
, dstY
,
314 add_vertex_1tex(r
, dstX
+ dstW
, dstY
+ dstH
,
317 add_vertex_1tex(r
, dstX
, dstY
+ dstH
,
320 return renderer_buffer_create(r
);
326 set_viewport(struct xorg_renderer
*r
, int width
, int height
,
327 enum AxisOrientation orientation
)
329 struct pipe_viewport_state viewport
;
330 float y_scale
= (orientation
== Y0_BOTTOM
) ? -2.f
: 2.f
;
332 viewport
.scale
[0] = width
/ 2.f
;
333 viewport
.scale
[1] = height
/ y_scale
;
334 viewport
.scale
[2] = 1.0;
335 viewport
.scale
[3] = 1.0;
336 viewport
.translate
[0] = width
/ 2.f
;
337 viewport
.translate
[1] = height
/ 2.f
;
338 viewport
.translate
[2] = 0.0;
339 viewport
.translate
[3] = 0.0;
341 cso_set_viewport(r
->cso
, &viewport
);
346 struct xorg_renderer
* renderer_create(struct pipe_context
*pipe
)
348 struct xorg_renderer
*renderer
= CALLOC_STRUCT(xorg_renderer
);
350 renderer
->pipe
= pipe
;
351 renderer
->cso
= cso_create_context(pipe
);
352 renderer
->shaders
= xorg_shaders_create(renderer
);
354 renderer_init_state(renderer
);
359 void renderer_destroy(struct xorg_renderer
*r
)
361 struct pipe_constant_buffer
*vsbuf
= &r
->vs_const_buffer
;
362 struct pipe_constant_buffer
*fsbuf
= &r
->fs_const_buffer
;
364 if (vsbuf
&& vsbuf
->buffer
)
365 pipe_buffer_reference(&vsbuf
->buffer
, NULL
);
367 if (fsbuf
&& fsbuf
->buffer
)
368 pipe_buffer_reference(&fsbuf
->buffer
, NULL
);
371 xorg_shaders_destroy(r
->shaders
);
376 cso_release_all(r
->cso
);
377 cso_destroy_context(r
->cso
);
382 void renderer_bind_framebuffer(struct xorg_renderer
*r
,
383 struct exa_pixmap_priv
*priv
)
386 struct pipe_framebuffer_state state
;
387 struct pipe_surface
*surface
= xorg_gpu_surface(r
->pipe
->screen
, priv
);
388 memset(&state
, 0, sizeof(struct pipe_framebuffer_state
));
390 state
.width
= priv
->tex
->width
[0];
391 state
.height
= priv
->tex
->height
[0];
394 state
.cbufs
[0] = surface
;
395 for (i
= 1; i
< PIPE_MAX_COLOR_BUFS
; ++i
)
398 /* currently we don't use depth/stencil */
401 cso_set_framebuffer(r
->cso
, &state
);
403 /* we do fire and forget for the framebuffer, this is the forget part */
404 pipe_surface_reference(&surface
, NULL
);
407 void renderer_bind_viewport(struct xorg_renderer
*r
,
408 struct exa_pixmap_priv
*dst
)
410 int width
= dst
->tex
->width
[0];
411 int height
= dst
->tex
->height
[0];
413 /*debug_printf("Bind viewport (%d, %d)\n", width, height);*/
415 set_viewport(r
, width
, height
, Y0_TOP
);
418 void renderer_bind_rasterizer(struct xorg_renderer
*r
)
420 struct pipe_rasterizer_state raster
;
422 /* XXX: move to renderer_init_state? */
423 memset(&raster
, 0, sizeof(struct pipe_rasterizer_state
));
424 raster
.gl_rasterization_rules
= 1;
425 cso_set_rasterizer(r
->cso
, &raster
);
428 void renderer_set_constants(struct xorg_renderer
*r
,
433 struct pipe_constant_buffer
*cbuf
=
434 (shader_type
== PIPE_SHADER_VERTEX
) ? &r
->vs_const_buffer
:
437 pipe_buffer_reference(&cbuf
->buffer
, NULL
);
438 cbuf
->buffer
= pipe_buffer_create(r
->pipe
->screen
, 16,
439 PIPE_BUFFER_USAGE_CONSTANT
,
443 pipe_buffer_write(r
->pipe
->screen
, cbuf
->buffer
,
444 0, param_bytes
, params
);
446 r
->pipe
->set_constant_buffer(r
->pipe
, shader_type
, 0, cbuf
);
450 setup_vs_constant_buffer(struct xorg_renderer
*r
,
451 int width
, int height
)
453 const int param_bytes
= 8 * sizeof(float);
454 float vs_consts
[8] = {
455 2.f
/width
, 2.f
/height
, 1, 1,
458 renderer_set_constants(r
, PIPE_SHADER_VERTEX
,
459 vs_consts
, param_bytes
);
463 setup_fs_constant_buffer(struct xorg_renderer
*r
)
465 const int param_bytes
= 4 * sizeof(float);
466 const float fs_consts
[8] = {
469 renderer_set_constants(r
, PIPE_SHADER_FRAGMENT
,
470 fs_consts
, param_bytes
);
473 static INLINE
void shift_rectx(float coords
[4],
480 coords
[2] = MIN2(coords
[2], bounds
[2]);
481 /* bound x/y + width/height */
482 if ((coords
[0] + coords
[2]) > (bounds
[0] + bounds
[2])) {
483 coords
[2] = (bounds
[0] + bounds
[2]) - coords
[0];
488 static INLINE
void shift_recty(float coords
[4],
495 coords
[3] = MIN2(coords
[3], bounds
[3]);
496 if ((coords
[1] + coords
[3]) > (bounds
[1] + bounds
[3])) {
497 coords
[3] = (bounds
[1] + bounds
[3]) - coords
[1];
502 static INLINE
void bound_rect(float coords
[4],
503 const float bounds
[4],
506 /* if outside the bounds */
507 if (coords
[0] > (bounds
[0] + bounds
[2]) ||
508 coords
[1] > (bounds
[1] + bounds
[3]) ||
509 (coords
[0] + coords
[2]) < bounds
[0] ||
510 (coords
[1] + coords
[3]) < bounds
[1]) {
521 if (coords
[0] < bounds
[0]) {
522 shift
[0] = bounds
[0] - coords
[0];
523 coords
[2] -= shift
[0];
524 coords
[0] = bounds
[0];
529 if (coords
[1] < bounds
[1]) {
530 shift
[1] = bounds
[1] - coords
[1];
531 coords
[3] -= shift
[1];
532 coords
[1] = bounds
[1];
536 shift
[2] = bounds
[2] - coords
[2];
537 shift
[3] = bounds
[3] - coords
[3];
538 /* bound width/height */
539 coords
[2] = MIN2(coords
[2], bounds
[2]);
540 coords
[3] = MIN2(coords
[3], bounds
[3]);
542 /* bound x/y + width/height */
543 if ((coords
[0] + coords
[2]) > (bounds
[0] + bounds
[2])) {
544 coords
[2] = (bounds
[0] + bounds
[2]) - coords
[0];
546 if ((coords
[1] + coords
[3]) > (bounds
[1] + bounds
[3])) {
547 coords
[3] = (bounds
[1] + bounds
[3]) - coords
[1];
550 /* if outside the bounds */
551 if ((coords
[0] + coords
[2]) < bounds
[0] ||
552 (coords
[1] + coords
[3]) < bounds
[1]) {
561 static INLINE
void sync_size(float *src_loc
, float *dst_loc
)
563 src_loc
[2] = MIN2(src_loc
[2], dst_loc
[2]);
564 src_loc
[3] = MIN2(src_loc
[3], dst_loc
[3]);
565 dst_loc
[2] = src_loc
[2];
566 dst_loc
[3] = src_loc
[3];
569 static void renderer_copy_texture(struct xorg_renderer
*r
,
570 struct pipe_texture
*src
,
571 float sx1
, float sy1
,
572 float sx2
, float sy2
,
573 struct pipe_texture
*dst
,
574 float dx1
, float dy1
,
575 float dx2
, float dy2
)
577 struct pipe_context
*pipe
= r
->pipe
;
578 struct pipe_screen
*screen
= pipe
->screen
;
579 struct pipe_buffer
*buf
;
580 struct pipe_surface
*dst_surf
= screen
->get_tex_surface(
581 screen
, dst
, 0, 0, 0,
582 PIPE_BUFFER_USAGE_GPU_WRITE
);
583 struct pipe_framebuffer_state fb
;
584 float s0
, t0
, s1
, t1
;
585 struct xorg_shader shader
;
587 assert(src
->width
[0] != 0);
588 assert(src
->height
[0] != 0);
589 assert(dst
->width
[0] != 0);
590 assert(dst
->height
[0] != 0);
593 s0
= sx1
/ src
->width
[0];
594 s1
= sx2
/ src
->width
[0];
595 t0
= sy1
/ src
->height
[0];
596 t1
= sy2
/ src
->height
[0];
605 debug_printf("copy texture src=[%f, %f, %f, %f], dst=[%f, %f, %f, %f], tex=[%f, %f, %f, %f]\n",
606 sx1
, sy1
, sx2
, sy2
, dx1
, dy1
, dx2
, dy2
,
610 assert(screen
->is_format_supported(screen
, dst_surf
->format
,
612 PIPE_TEXTURE_USAGE_RENDER_TARGET
,
615 /* save state (restored below) */
616 cso_save_blend(r
->cso
);
617 cso_save_samplers(r
->cso
);
618 cso_save_sampler_textures(r
->cso
);
619 cso_save_framebuffer(r
->cso
);
620 cso_save_fragment_shader(r
->cso
);
621 cso_save_vertex_shader(r
->cso
);
623 cso_save_viewport(r
->cso
);
626 /* set misc state we care about */
628 struct pipe_blend_state blend
;
629 memset(&blend
, 0, sizeof(blend
));
630 blend
.rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
631 blend
.alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
632 blend
.rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
633 blend
.alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
634 blend
.colormask
= PIPE_MASK_RGBA
;
635 cso_set_blend(r
->cso
, &blend
);
640 struct pipe_sampler_state sampler
;
641 memset(&sampler
, 0, sizeof(sampler
));
642 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
643 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
644 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
645 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
646 sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
647 sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
648 sampler
.normalized_coords
= 1;
649 cso_single_sampler(r
->cso
, 0, &sampler
);
650 cso_single_sampler_done(r
->cso
);
653 set_viewport(r
, dst_surf
->width
, dst_surf
->height
, Y0_TOP
);
656 cso_set_sampler_textures(r
->cso
, 1, &src
);
658 renderer_bind_rasterizer(r
);
661 shader
= xorg_shaders_get(r
->shaders
,
664 cso_set_vertex_shader_handle(r
->cso
, shader
.vs
);
665 cso_set_fragment_shader_handle(r
->cso
, shader
.fs
);
668 memset(&fb
, 0, sizeof(fb
));
669 fb
.width
= dst_surf
->width
;
670 fb
.height
= dst_surf
->height
;
672 fb
.cbufs
[0] = dst_surf
;
675 for (i
= 1; i
< PIPE_MAX_COLOR_BUFS
; ++i
)
678 cso_set_framebuffer(r
->cso
, &fb
);
679 setup_vs_constant_buffer(r
, fb
.width
, fb
.height
);
680 setup_fs_constant_buffer(r
);
683 buf
= setup_vertex_data_tex(r
,
690 util_draw_vertex_buffer(r
->pipe
, buf
, 0,
693 2); /* attribs/vert */
695 pipe_buffer_reference(&buf
, NULL
);
698 /* restore state we changed */
699 cso_restore_blend(r
->cso
);
700 cso_restore_samplers(r
->cso
);
701 cso_restore_sampler_textures(r
->cso
);
702 cso_restore_framebuffer(r
->cso
);
703 cso_restore_vertex_shader(r
->cso
);
704 cso_restore_fragment_shader(r
->cso
);
705 cso_restore_viewport(r
->cso
);
707 pipe_surface_reference(&dst_surf
, NULL
);
710 static struct pipe_texture
*
711 create_sampler_texture(struct xorg_renderer
*r
,
712 struct pipe_texture
*src
)
714 enum pipe_format format
;
715 struct pipe_context
*pipe
= r
->pipe
;
716 struct pipe_screen
*screen
= pipe
->screen
;
717 struct pipe_texture
*pt
;
718 struct pipe_texture templ
;
720 pipe
->flush(pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
722 /* the coming in texture should already have that invariance */
723 debug_assert(screen
->is_format_supported(screen
, src
->format
,
725 PIPE_TEXTURE_USAGE_SAMPLER
, 0));
727 format
= src
->format
;
729 memset(&templ
, 0, sizeof(templ
));
730 templ
.target
= PIPE_TEXTURE_2D
;
731 templ
.format
= format
;
732 templ
.last_level
= 0;
733 templ
.width
[0] = src
->width
[0];
734 templ
.height
[0] = src
->height
[0];
736 pf_get_block(format
, &templ
.block
);
737 templ
.tex_usage
= PIPE_TEXTURE_USAGE_SAMPLER
;
739 pt
= screen
->texture_create(screen
, &templ
);
741 debug_assert(!pt
|| pipe_is_referenced(&pt
->reference
));
747 /* copy source framebuffer surface into texture */
748 struct pipe_surface
*ps_read
= screen
->get_tex_surface(
749 screen
, src
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ
);
750 struct pipe_surface
*ps_tex
= screen
->get_tex_surface(
751 screen
, pt
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
752 if (pipe
->surface_copy
) {
753 pipe
->surface_copy(pipe
,
757 0, 0, src
->width
[0], src
->height
[0]);
759 util_surface_copy(pipe
, FALSE
,
763 0, 0, src
->width
[0], src
->height
[0]);
765 pipe_surface_reference(&ps_read
, NULL
);
766 pipe_surface_reference(&ps_tex
, NULL
);
773 void renderer_copy_pixmap(struct xorg_renderer
*r
,
774 struct exa_pixmap_priv
*dst_priv
, int dx
, int dy
,
775 struct exa_pixmap_priv
*src_priv
, int sx
, int sy
,
776 int width
, int height
)
778 float dst_loc
[4], src_loc
[4];
779 float dst_bounds
[4], src_bounds
[4];
780 float src_shift
[4], dst_shift
[4], shift
[4];
781 struct pipe_texture
*dst
= dst_priv
->tex
;
782 struct pipe_texture
*src
= src_priv
->tex
;
784 if (r
->pipe
->is_texture_referenced(r
->pipe
, src
, 0, 0) &
785 PIPE_REFERENCED_FOR_WRITE
)
786 r
->pipe
->flush(r
->pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
794 dst_bounds
[2] = dst
->width
[0];
795 dst_bounds
[3] = dst
->height
[0];
803 src_bounds
[2] = src
->width
[0];
804 src_bounds
[3] = src
->height
[0];
806 bound_rect(src_loc
, src_bounds
, src_shift
);
807 bound_rect(dst_loc
, dst_bounds
, dst_shift
);
808 shift
[0] = src_shift
[0] - dst_shift
[0];
809 shift
[1] = src_shift
[1] - dst_shift
[1];
812 shift_rectx(src_loc
, src_bounds
, -shift
[0]);
814 shift_rectx(dst_loc
, dst_bounds
, shift
[0]);
817 shift_recty(src_loc
, src_bounds
, -shift
[1]);
819 shift_recty(dst_loc
, dst_bounds
, shift
[1]);
821 sync_size(src_loc
, dst_loc
);
823 if (src_loc
[2] >= 0 && src_loc
[3] >= 0 &&
824 dst_loc
[2] >= 0 && dst_loc
[3] >= 0) {
825 struct pipe_texture
*temp_src
= src
;
828 temp_src
= create_sampler_texture(r
, src
);
830 renderer_copy_texture(r
,
834 src_loc
[0] + src_loc
[2],
835 src_loc
[1] + src_loc
[3],
839 dst_loc
[0] + dst_loc
[2],
840 dst_loc
[1] + dst_loc
[3]);
843 pipe_texture_reference(&temp_src
, NULL
);
847 void renderer_draw_yuv(struct xorg_renderer
*r
,
848 int src_x
, int src_y
, int src_w
, int src_h
,
849 int dst_x
, int dst_y
, int dst_w
, int dst_h
,
850 struct pipe_texture
**textures
)
852 struct pipe_context
*pipe
= r
->pipe
;
853 struct pipe_buffer
*buf
= 0;
855 buf
= setup_vertex_data_yuv(r
,
856 src_x
, src_y
, src_w
, src_h
,
857 dst_x
, dst_y
, dst_w
, dst_h
,
861 const int num_attribs
= 2; /*pos + tex coord*/
863 util_draw_vertex_buffer(pipe
, buf
, 0,
866 num_attribs
); /* attribs/vert */
868 pipe_buffer_reference(&buf
, NULL
);
872 void renderer_begin_solid(struct xorg_renderer
*r
)
875 r
->attrs_per_vertex
= 2;
878 void renderer_solid(struct xorg_renderer
*r
,
884 debug_printf("solid rect[(%d, %d), (%d, %d)], rgba[%f, %f, %f, %f]\n",
885 x0, y0, x1, y1, color[0], color[1], color[2], color[3]);*/
887 renderer_draw_conditional(r
, 4 * 8);
890 add_vertex_color(r
, x0
, y0
, color
);
892 add_vertex_color(r
, x1
, y0
, color
);
894 add_vertex_color(r
, x1
, y1
, color
);
896 add_vertex_color(r
, x0
, y1
, color
);
899 void renderer_draw_flush(struct xorg_renderer
*r
)
901 renderer_draw_conditional(r
, 0);
904 void renderer_begin_textures(struct xorg_renderer
*r
,
905 struct pipe_texture
**textures
,
908 r
->attrs_per_vertex
= 1 + num_textures
;
912 void renderer_texture(struct xorg_renderer
*r
,
914 int width
, int height
,
915 struct pipe_texture
**textures
,
923 debug_printf("src_matrix = \n");
924 debug_printf("%f, %f, %f\n", src_matrix
[0], src_matrix
[1], src_matrix
[2]);
925 debug_printf("%f, %f, %f\n", src_matrix
[3], src_matrix
[4], src_matrix
[5]);
926 debug_printf("%f, %f, %f\n", src_matrix
[6], src_matrix
[7], src_matrix
[8]);
929 debug_printf("mask_matrix = \n");
930 debug_printf("%f, %f, %f\n", mask_matrix
[0], mask_matrix
[1], mask_matrix
[2]);
931 debug_printf("%f, %f, %f\n", mask_matrix
[3], mask_matrix
[4], mask_matrix
[5]);
932 debug_printf("%f, %f, %f\n", mask_matrix
[6], mask_matrix
[7], mask_matrix
[8]);
936 switch(r
->attrs_per_vertex
) {
938 renderer_draw_conditional(r
, 4 * 8);
940 pos
[0], pos
[1], /* src */
941 pos
[4], pos
[5], /* dst */
943 textures
[0], src_matrix
);
946 renderer_draw_conditional(r
, 4 * 12);
948 pos
[0], pos
[1], /* src */
949 pos
[2], pos
[3], /* mask */
950 pos
[4], pos
[5], /* dst */
952 textures
[0], textures
[1],
953 src_matrix
, mask_matrix
);
956 debug_assert(!"Unsupported number of textures");