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 static INLINE boolean
is_affine(float *matrix
)
26 return floatIsZero(matrix
[2]) && floatIsZero(matrix
[5])
27 && floatsEqual(matrix
[8], 1);
29 static INLINE
void map_point(float *mat
, float x
, float y
,
30 float *out_x
, float *out_y
)
38 *out_x
= mat
[0]*x
+ mat
[3]*y
+ mat
[6];
39 *out_y
= mat
[1]*x
+ mat
[4]*y
+ mat
[7];
40 if (!is_affine(mat
)) {
41 float w
= 1/(mat
[2]*x
+ mat
[5]*y
+ mat
[8]);
47 static INLINE
struct pipe_buffer
*
48 renderer_buffer_create(struct xorg_renderer
*r
)
50 struct pipe_buffer
*buf
=
51 pipe_user_buffer_create(r
->pipe
->screen
,
61 renderer_draw(struct xorg_renderer
*r
)
63 struct pipe_context
*pipe
= r
->pipe
;
64 struct pipe_buffer
*buf
= 0;
69 buf
= renderer_buffer_create(r
);
73 util_draw_vertex_buffer(pipe
, buf
, 0,
76 r
->num_attributes
); /* attribs/vert */
78 pipe_buffer_reference(&buf
, NULL
);
83 renderer_draw_conditional(struct xorg_renderer
*r
,
86 if (r
->num_vertices
+ next_batch
>= BUF_SIZE
||
87 (next_batch
== 0 && r
->num_vertices
))
92 renderer_init_state(struct xorg_renderer
*r
)
94 struct pipe_depth_stencil_alpha_state dsa
;
96 /* set common initial clip state */
97 memset(&dsa
, 0, sizeof(struct pipe_depth_stencil_alpha_state
));
98 cso_set_depth_stencil_alpha(r
->cso
, &dsa
);
103 add_vertex_color(struct xorg_renderer
*r
,
107 float *vertex
= r
->vertices
+ r
->num_vertices
;
111 vertex
[2] = 0.f
; /*z*/
112 vertex
[3] = 1.f
; /*w*/
114 vertex
[4] = color
[0]; /*r*/
115 vertex
[5] = color
[1]; /*g*/
116 vertex
[6] = color
[2]; /*b*/
117 vertex
[7] = color
[3]; /*a*/
119 r
->num_vertices
+= 8;
123 add_vertex_1tex(struct xorg_renderer
*r
,
124 float x
, float y
, float s
, float t
)
126 float *vertex
= r
->vertices
+ r
->num_vertices
;
130 vertex
[2] = 0.f
; /*z*/
131 vertex
[3] = 1.f
; /*w*/
135 vertex
[6] = 0.f
; /*r*/
136 vertex
[7] = 1.f
; /*q*/
138 r
->num_vertices
+= 8;
142 add_vertex_data1(struct xorg_renderer
*r
,
143 float srcX
, float srcY
, float dstX
, float dstY
,
144 float width
, float height
,
145 struct pipe_texture
*src
, float *src_matrix
)
147 float s0
, t0
, s1
, t1
;
148 float pt0
[2], pt1
[2];
152 pt1
[0] = (srcX
+ width
);
153 pt1
[1] = (srcY
+ height
);
156 map_point(src_matrix
, pt0
[0], pt0
[1], &pt0
[0], &pt0
[1]);
157 map_point(src_matrix
, pt1
[0], pt1
[1], &pt1
[0], &pt1
[1]);
160 s0
= pt0
[0] / src
->width
[0];
161 s1
= pt1
[0] / src
->width
[0];
162 t0
= pt0
[1] / src
->height
[0];
163 t1
= pt1
[1] / src
->height
[0];
166 add_vertex_1tex(r
, dstX
, dstY
, s0
, t0
);
168 add_vertex_1tex(r
, dstX
+ width
, dstY
, s1
, t0
);
170 add_vertex_1tex(r
, dstX
+ width
, dstY
+ height
, s1
, t1
);
172 add_vertex_1tex(r
, dstX
, dstY
+ height
, s0
, t1
);
175 static struct pipe_buffer
*
176 setup_vertex_data_tex(struct xorg_renderer
*r
,
177 float x0
, float y0
, float x1
, float y1
,
178 float s0
, float t0
, float s1
, float t1
,
182 add_vertex_1tex(r
, x0
, y0
, s0
, t0
);
184 add_vertex_1tex(r
, x1
, y0
, s1
, t0
);
186 add_vertex_1tex(r
, x1
, y1
, s1
, t1
);
188 add_vertex_1tex(r
, x0
, y1
, s0
, t1
);
190 return renderer_buffer_create(r
);
194 add_vertex_2tex(struct xorg_renderer
*r
,
196 float s0
, float t0
, float s1
, float t1
)
198 float *vertex
= r
->vertices
+ r
->num_vertices
;
202 vertex
[2] = 0.f
; /*z*/
203 vertex
[3] = 1.f
; /*w*/
205 vertex
[4] = s0
; /*s*/
206 vertex
[5] = t0
; /*t*/
207 vertex
[6] = 0.f
; /*r*/
208 vertex
[7] = 1.f
; /*q*/
210 vertex
[8] = s1
; /*s*/
211 vertex
[9] = t1
; /*t*/
212 vertex
[10] = 0.f
; /*r*/
213 vertex
[11] = 1.f
; /*q*/
215 r
->num_vertices
+= 12;
219 add_vertex_data2(struct xorg_renderer
*r
,
220 float srcX
, float srcY
, float maskX
, float maskY
,
221 float dstX
, float dstY
, float width
, float height
,
222 struct pipe_texture
*src
,
223 struct pipe_texture
*mask
,
224 float *src_matrix
, float *mask_matrix
)
226 float src_s0
, src_t0
, src_s1
, src_t1
;
227 float mask_s0
, mask_t0
, mask_s1
, mask_t1
;
228 float spt0
[2], spt1
[2];
229 float mpt0
[2], mpt1
[2];
233 spt1
[0] = srcX
+ width
;
234 spt1
[1] = srcY
+ height
;
238 mpt1
[0] = maskX
+ width
;
239 mpt1
[1] = maskY
+ height
;
242 map_point(src_matrix
, spt0
[0], spt0
[1], &spt0
[0], &spt0
[1]);
243 map_point(src_matrix
, spt1
[0], spt1
[1], &spt1
[0], &spt1
[1]);
247 map_point(mask_matrix
, mpt0
[0], mpt0
[1], &mpt0
[0], &mpt0
[1]);
248 map_point(mask_matrix
, mpt1
[0], mpt1
[1], &mpt1
[0], &mpt1
[1]);
251 src_s0
= spt0
[0] / src
->width
[0];
252 src_t0
= spt0
[1] / src
->height
[0];
253 src_s1
= spt1
[0] / src
->width
[0];
254 src_t1
= spt1
[1] / src
->height
[0];
256 mask_s0
= mpt0
[0] / mask
->width
[0];
257 mask_t0
= mpt0
[1] / mask
->height
[0];
258 mask_s1
= mpt1
[0] / mask
->width
[0];
259 mask_t1
= mpt1
[1] / mask
->height
[0];
262 add_vertex_2tex(r
, dstX
, dstY
,
263 src_s0
, src_t0
, mask_s0
, mask_t0
);
265 add_vertex_2tex(r
, dstX
+ width
, dstY
,
266 src_s1
, src_t0
, mask_s1
, mask_t0
);
268 add_vertex_2tex(r
, dstX
+ width
, dstY
+ height
,
269 src_s1
, src_t1
, mask_s1
, mask_t1
);
271 add_vertex_2tex(r
, dstX
, dstY
+ height
,
272 src_s0
, src_t1
, mask_s0
, mask_t1
);
275 static struct pipe_buffer
*
276 setup_vertex_data_yuv(struct xorg_renderer
*r
,
277 float srcX
, float srcY
, float srcW
, float srcH
,
278 float dstX
, float dstY
, float dstW
, float dstH
,
279 struct pipe_texture
**tex
)
281 float s0
, t0
, s1
, t1
;
282 float spt0
[2], spt1
[2];
286 spt1
[0] = srcX
+ srcW
;
287 spt1
[1] = srcY
+ srcH
;
289 s0
= spt0
[0] / tex
[0]->width
[0];
290 t0
= spt0
[1] / tex
[0]->height
[0];
291 s1
= spt1
[0] / tex
[0]->width
[0];
292 t1
= spt1
[1] / tex
[0]->height
[0];
295 add_vertex_1tex(r
, dstX
, dstY
, s0
, t0
);
297 add_vertex_1tex(r
, dstX
+ dstW
, dstY
,
300 add_vertex_1tex(r
, dstX
+ dstW
, dstY
+ dstH
,
303 add_vertex_1tex(r
, dstX
, dstY
+ dstH
,
306 return renderer_buffer_create(r
);
312 set_viewport(struct xorg_renderer
*r
, int width
, int height
,
313 enum AxisOrientation orientation
)
315 struct pipe_viewport_state viewport
;
316 float y_scale
= (orientation
== Y0_BOTTOM
) ? -2.f
: 2.f
;
318 viewport
.scale
[0] = width
/ 2.f
;
319 viewport
.scale
[1] = height
/ y_scale
;
320 viewport
.scale
[2] = 1.0;
321 viewport
.scale
[3] = 1.0;
322 viewport
.translate
[0] = width
/ 2.f
;
323 viewport
.translate
[1] = height
/ 2.f
;
324 viewport
.translate
[2] = 0.0;
325 viewport
.translate
[3] = 0.0;
327 cso_set_viewport(r
->cso
, &viewport
);
332 struct xorg_renderer
* renderer_create(struct pipe_context
*pipe
)
334 struct xorg_renderer
*renderer
= CALLOC_STRUCT(xorg_renderer
);
336 renderer
->pipe
= pipe
;
337 renderer
->cso
= cso_create_context(pipe
);
338 renderer
->shaders
= xorg_shaders_create(renderer
);
340 renderer_init_state(renderer
);
345 void renderer_destroy(struct xorg_renderer
*r
)
347 struct pipe_constant_buffer
*vsbuf
= &r
->vs_const_buffer
;
348 struct pipe_constant_buffer
*fsbuf
= &r
->fs_const_buffer
;
350 if (vsbuf
&& vsbuf
->buffer
)
351 pipe_buffer_reference(&vsbuf
->buffer
, NULL
);
353 if (fsbuf
&& fsbuf
->buffer
)
354 pipe_buffer_reference(&fsbuf
->buffer
, NULL
);
357 xorg_shaders_destroy(r
->shaders
);
362 cso_release_all(r
->cso
);
363 cso_destroy_context(r
->cso
);
368 void renderer_bind_framebuffer(struct xorg_renderer
*r
,
369 struct exa_pixmap_priv
*priv
)
372 struct pipe_framebuffer_state state
;
373 struct pipe_surface
*surface
= xorg_gpu_surface(r
->pipe
->screen
, priv
);
374 memset(&state
, 0, sizeof(struct pipe_framebuffer_state
));
376 state
.width
= priv
->tex
->width
[0];
377 state
.height
= priv
->tex
->height
[0];
380 state
.cbufs
[0] = surface
;
381 for (i
= 1; i
< PIPE_MAX_COLOR_BUFS
; ++i
)
384 /* currently we don't use depth/stencil */
387 cso_set_framebuffer(r
->cso
, &state
);
389 /* we do fire and forget for the framebuffer, this is the forget part */
390 pipe_surface_reference(&surface
, NULL
);
393 void renderer_bind_viewport(struct xorg_renderer
*r
,
394 struct exa_pixmap_priv
*dst
)
396 int width
= dst
->tex
->width
[0];
397 int height
= dst
->tex
->height
[0];
399 /*debug_printf("Bind viewport (%d, %d)\n", width, height);*/
401 set_viewport(r
, width
, height
, Y0_TOP
);
404 void renderer_bind_rasterizer(struct xorg_renderer
*r
)
406 struct pipe_rasterizer_state raster
;
408 /* XXX: move to renderer_init_state? */
409 memset(&raster
, 0, sizeof(struct pipe_rasterizer_state
));
410 raster
.gl_rasterization_rules
= 1;
411 cso_set_rasterizer(r
->cso
, &raster
);
414 void renderer_set_constants(struct xorg_renderer
*r
,
419 struct pipe_constant_buffer
*cbuf
=
420 (shader_type
== PIPE_SHADER_VERTEX
) ? &r
->vs_const_buffer
:
423 pipe_buffer_reference(&cbuf
->buffer
, NULL
);
424 cbuf
->buffer
= pipe_buffer_create(r
->pipe
->screen
, 16,
425 PIPE_BUFFER_USAGE_CONSTANT
,
429 pipe_buffer_write(r
->pipe
->screen
, cbuf
->buffer
,
430 0, param_bytes
, params
);
432 r
->pipe
->set_constant_buffer(r
->pipe
, shader_type
, 0, cbuf
);
436 setup_vs_constant_buffer(struct xorg_renderer
*r
,
437 int width
, int height
)
439 const int param_bytes
= 8 * sizeof(float);
440 float vs_consts
[8] = {
441 2.f
/width
, 2.f
/height
, 1, 1,
444 renderer_set_constants(r
, PIPE_SHADER_VERTEX
,
445 vs_consts
, param_bytes
);
449 setup_fs_constant_buffer(struct xorg_renderer
*r
)
451 const int param_bytes
= 4 * sizeof(float);
452 const float fs_consts
[8] = {
455 renderer_set_constants(r
, PIPE_SHADER_FRAGMENT
,
456 fs_consts
, param_bytes
);
459 static INLINE
void shift_rectx(float coords
[4],
466 coords
[2] = MIN2(coords
[2], bounds
[2]);
467 /* bound x/y + width/height */
468 if ((coords
[0] + coords
[2]) > (bounds
[0] + bounds
[2])) {
469 coords
[2] = (bounds
[0] + bounds
[2]) - coords
[0];
474 static INLINE
void shift_recty(float coords
[4],
481 coords
[3] = MIN2(coords
[3], bounds
[3]);
482 if ((coords
[1] + coords
[3]) > (bounds
[1] + bounds
[3])) {
483 coords
[3] = (bounds
[1] + bounds
[3]) - coords
[1];
488 static INLINE
void bound_rect(float coords
[4],
489 const float bounds
[4],
492 /* if outside the bounds */
493 if (coords
[0] > (bounds
[0] + bounds
[2]) ||
494 coords
[1] > (bounds
[1] + bounds
[3]) ||
495 (coords
[0] + coords
[2]) < bounds
[0] ||
496 (coords
[1] + coords
[3]) < bounds
[1]) {
507 if (coords
[0] < bounds
[0]) {
508 shift
[0] = bounds
[0] - coords
[0];
509 coords
[2] -= shift
[0];
510 coords
[0] = bounds
[0];
515 if (coords
[1] < bounds
[1]) {
516 shift
[1] = bounds
[1] - coords
[1];
517 coords
[3] -= shift
[1];
518 coords
[1] = bounds
[1];
522 shift
[2] = bounds
[2] - coords
[2];
523 shift
[3] = bounds
[3] - coords
[3];
524 /* bound width/height */
525 coords
[2] = MIN2(coords
[2], bounds
[2]);
526 coords
[3] = MIN2(coords
[3], bounds
[3]);
528 /* bound x/y + width/height */
529 if ((coords
[0] + coords
[2]) > (bounds
[0] + bounds
[2])) {
530 coords
[2] = (bounds
[0] + bounds
[2]) - coords
[0];
532 if ((coords
[1] + coords
[3]) > (bounds
[1] + bounds
[3])) {
533 coords
[3] = (bounds
[1] + bounds
[3]) - coords
[1];
536 /* if outside the bounds */
537 if ((coords
[0] + coords
[2]) < bounds
[0] ||
538 (coords
[1] + coords
[3]) < bounds
[1]) {
547 static INLINE
void sync_size(float *src_loc
, float *dst_loc
)
549 src_loc
[2] = MIN2(src_loc
[2], dst_loc
[2]);
550 src_loc
[3] = MIN2(src_loc
[3], dst_loc
[3]);
551 dst_loc
[2] = src_loc
[2];
552 dst_loc
[3] = src_loc
[3];
555 static void renderer_copy_texture(struct xorg_renderer
*r
,
556 struct pipe_texture
*src
,
557 float sx1
, float sy1
,
558 float sx2
, float sy2
,
559 struct pipe_texture
*dst
,
560 float dx1
, float dy1
,
561 float dx2
, float dy2
)
563 struct pipe_context
*pipe
= r
->pipe
;
564 struct pipe_screen
*screen
= pipe
->screen
;
565 struct pipe_buffer
*buf
;
566 struct pipe_surface
*dst_surf
= screen
->get_tex_surface(
567 screen
, dst
, 0, 0, 0,
568 PIPE_BUFFER_USAGE_GPU_WRITE
);
569 struct pipe_framebuffer_state fb
;
570 float s0
, t0
, s1
, t1
;
571 struct xorg_shader shader
;
573 assert(src
->width
[0] != 0);
574 assert(src
->height
[0] != 0);
575 assert(dst
->width
[0] != 0);
576 assert(dst
->height
[0] != 0);
579 s0
= sx1
/ src
->width
[0];
580 s1
= sx2
/ src
->width
[0];
581 t0
= sy1
/ src
->height
[0];
582 t1
= sy2
/ src
->height
[0];
591 debug_printf("copy texture src=[%f, %f, %f, %f], dst=[%f, %f, %f, %f], tex=[%f, %f, %f, %f]\n",
592 sx1
, sy1
, sx2
, sy2
, dx1
, dy1
, dx2
, dy2
,
596 assert(screen
->is_format_supported(screen
, dst_surf
->format
,
598 PIPE_TEXTURE_USAGE_RENDER_TARGET
,
601 /* save state (restored below) */
602 cso_save_blend(r
->cso
);
603 cso_save_samplers(r
->cso
);
604 cso_save_sampler_textures(r
->cso
);
605 cso_save_framebuffer(r
->cso
);
606 cso_save_fragment_shader(r
->cso
);
607 cso_save_vertex_shader(r
->cso
);
609 cso_save_viewport(r
->cso
);
612 /* set misc state we care about */
614 struct pipe_blend_state blend
;
615 memset(&blend
, 0, sizeof(blend
));
616 blend
.rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
617 blend
.alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
618 blend
.rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
619 blend
.alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
620 blend
.colormask
= PIPE_MASK_RGBA
;
621 cso_set_blend(r
->cso
, &blend
);
626 struct pipe_sampler_state sampler
;
627 memset(&sampler
, 0, sizeof(sampler
));
628 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
629 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
630 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
631 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
632 sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
633 sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
634 sampler
.normalized_coords
= 1;
635 cso_single_sampler(r
->cso
, 0, &sampler
);
636 cso_single_sampler_done(r
->cso
);
639 set_viewport(r
, dst_surf
->width
, dst_surf
->height
, Y0_TOP
);
642 cso_set_sampler_textures(r
->cso
, 1, &src
);
644 renderer_bind_rasterizer(r
);
647 shader
= xorg_shaders_get(r
->shaders
,
650 cso_set_vertex_shader_handle(r
->cso
, shader
.vs
);
651 cso_set_fragment_shader_handle(r
->cso
, shader
.fs
);
654 memset(&fb
, 0, sizeof(fb
));
655 fb
.width
= dst_surf
->width
;
656 fb
.height
= dst_surf
->height
;
658 fb
.cbufs
[0] = dst_surf
;
661 for (i
= 1; i
< PIPE_MAX_COLOR_BUFS
; ++i
)
664 cso_set_framebuffer(r
->cso
, &fb
);
665 setup_vs_constant_buffer(r
, fb
.width
, fb
.height
);
666 setup_fs_constant_buffer(r
);
669 buf
= setup_vertex_data_tex(r
,
676 util_draw_vertex_buffer(r
->pipe
, buf
, 0,
679 2); /* attribs/vert */
681 pipe_buffer_reference(&buf
, NULL
);
684 /* restore state we changed */
685 cso_restore_blend(r
->cso
);
686 cso_restore_samplers(r
->cso
);
687 cso_restore_sampler_textures(r
->cso
);
688 cso_restore_framebuffer(r
->cso
);
689 cso_restore_vertex_shader(r
->cso
);
690 cso_restore_fragment_shader(r
->cso
);
691 cso_restore_viewport(r
->cso
);
693 pipe_surface_reference(&dst_surf
, NULL
);
696 static struct pipe_texture
*
697 create_sampler_texture(struct xorg_renderer
*r
,
698 struct pipe_texture
*src
)
700 enum pipe_format format
;
701 struct pipe_context
*pipe
= r
->pipe
;
702 struct pipe_screen
*screen
= pipe
->screen
;
703 struct pipe_texture
*pt
;
704 struct pipe_texture templ
;
706 pipe
->flush(pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
708 /* the coming in texture should already have that invariance */
709 debug_assert(screen
->is_format_supported(screen
, src
->format
,
711 PIPE_TEXTURE_USAGE_SAMPLER
, 0));
713 format
= src
->format
;
715 memset(&templ
, 0, sizeof(templ
));
716 templ
.target
= PIPE_TEXTURE_2D
;
717 templ
.format
= format
;
718 templ
.last_level
= 0;
719 templ
.width
[0] = src
->width
[0];
720 templ
.height
[0] = src
->height
[0];
722 pf_get_block(format
, &templ
.block
);
723 templ
.tex_usage
= PIPE_TEXTURE_USAGE_SAMPLER
;
725 pt
= screen
->texture_create(screen
, &templ
);
727 debug_assert(!pt
|| pipe_is_referenced(&pt
->reference
));
733 /* copy source framebuffer surface into texture */
734 struct pipe_surface
*ps_read
= screen
->get_tex_surface(
735 screen
, src
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ
);
736 struct pipe_surface
*ps_tex
= screen
->get_tex_surface(
737 screen
, pt
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
738 if (pipe
->surface_copy
) {
739 pipe
->surface_copy(pipe
,
743 0, 0, src
->width
[0], src
->height
[0]);
745 util_surface_copy(pipe
, FALSE
,
749 0, 0, src
->width
[0], src
->height
[0]);
751 pipe_surface_reference(&ps_read
, NULL
);
752 pipe_surface_reference(&ps_tex
, NULL
);
759 void renderer_copy_pixmap(struct xorg_renderer
*r
,
760 struct exa_pixmap_priv
*dst_priv
, int dx
, int dy
,
761 struct exa_pixmap_priv
*src_priv
, int sx
, int sy
,
762 int width
, int height
)
764 float dst_loc
[4], src_loc
[4];
765 float dst_bounds
[4], src_bounds
[4];
766 float src_shift
[4], dst_shift
[4], shift
[4];
767 struct pipe_texture
*dst
= dst_priv
->tex
;
768 struct pipe_texture
*src
= src_priv
->tex
;
770 if (r
->pipe
->is_texture_referenced(r
->pipe
, src
, 0, 0) &
771 PIPE_REFERENCED_FOR_WRITE
)
772 r
->pipe
->flush(r
->pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
780 dst_bounds
[2] = dst
->width
[0];
781 dst_bounds
[3] = dst
->height
[0];
789 src_bounds
[2] = src
->width
[0];
790 src_bounds
[3] = src
->height
[0];
792 bound_rect(src_loc
, src_bounds
, src_shift
);
793 bound_rect(dst_loc
, dst_bounds
, dst_shift
);
794 shift
[0] = src_shift
[0] - dst_shift
[0];
795 shift
[1] = src_shift
[1] - dst_shift
[1];
798 shift_rectx(src_loc
, src_bounds
, -shift
[0]);
800 shift_rectx(dst_loc
, dst_bounds
, shift
[0]);
803 shift_recty(src_loc
, src_bounds
, -shift
[1]);
805 shift_recty(dst_loc
, dst_bounds
, shift
[1]);
807 sync_size(src_loc
, dst_loc
);
809 if (src_loc
[2] >= 0 && src_loc
[3] >= 0 &&
810 dst_loc
[2] >= 0 && dst_loc
[3] >= 0) {
811 struct pipe_texture
*temp_src
= src
;
814 temp_src
= create_sampler_texture(r
, src
);
816 renderer_copy_texture(r
,
820 src_loc
[0] + src_loc
[2],
821 src_loc
[1] + src_loc
[3],
825 dst_loc
[0] + dst_loc
[2],
826 dst_loc
[1] + dst_loc
[3]);
829 pipe_texture_reference(&temp_src
, NULL
);
833 void renderer_draw_yuv(struct xorg_renderer
*r
,
834 int src_x
, int src_y
, int src_w
, int src_h
,
835 int dst_x
, int dst_y
, int dst_w
, int dst_h
,
836 struct pipe_texture
**textures
)
838 struct pipe_context
*pipe
= r
->pipe
;
839 struct pipe_buffer
*buf
= 0;
841 buf
= setup_vertex_data_yuv(r
,
842 src_x
, src_y
, src_w
, src_h
,
843 dst_x
, dst_y
, dst_w
, dst_h
,
847 const int num_attribs
= 2; /*pos + tex coord*/
849 util_draw_vertex_buffer(pipe
, buf
, 0,
852 num_attribs
); /* attribs/vert */
854 pipe_buffer_reference(&buf
, NULL
);
858 void renderer_begin_solid(struct xorg_renderer
*r
)
861 r
->num_attributes
= 2;
864 void renderer_solid(struct xorg_renderer
*r
,
870 debug_printf("solid rect[(%d, %d), (%d, %d)], rgba[%f, %f, %f, %f]\n",
871 x0, y0, x1, y1, color[0], color[1], color[2], color[3]);*/
873 renderer_draw_conditional(r
, 4 * 8);
876 add_vertex_color(r
, x0
, y0
, color
);
878 add_vertex_color(r
, x1
, y0
, color
);
880 add_vertex_color(r
, x1
, y1
, color
);
882 add_vertex_color(r
, x0
, y1
, color
);
885 void renderer_draw_flush(struct xorg_renderer
*r
)
887 renderer_draw_conditional(r
, 0);
890 void renderer_begin_textures(struct xorg_renderer
*r
,
891 struct pipe_texture
**textures
,
894 r
->num_attributes
= 1 + num_textures
;
897 void renderer_texture(struct xorg_renderer
*r
,
899 int width
, int height
,
900 struct pipe_texture
**textures
,
908 debug_printf("src_matrix = \n");
909 debug_printf("%f, %f, %f\n", src_matrix
[0], src_matrix
[1], src_matrix
[2]);
910 debug_printf("%f, %f, %f\n", src_matrix
[3], src_matrix
[4], src_matrix
[5]);
911 debug_printf("%f, %f, %f\n", src_matrix
[6], src_matrix
[7], src_matrix
[8]);
914 debug_printf("mask_matrix = \n");
915 debug_printf("%f, %f, %f\n", mask_matrix
[0], mask_matrix
[1], mask_matrix
[2]);
916 debug_printf("%f, %f, %f\n", mask_matrix
[3], mask_matrix
[4], mask_matrix
[5]);
917 debug_printf("%f, %f, %f\n", mask_matrix
[6], mask_matrix
[7], mask_matrix
[8]);
921 switch(r
->num_attributes
) {
923 renderer_draw_conditional(r
, 4 * 8);
925 pos
[0], pos
[1], /* src */
926 pos
[4], pos
[5], /* dst */
928 textures
[0], src_matrix
);
931 renderer_draw_conditional(r
, 4 * 12);
933 pos
[0], pos
[1], /* src */
934 pos
[2], pos
[3], /* mask */
935 pos
[4], pos
[5], /* dst */
937 textures
[0], textures
[1],
938 src_matrix
, mask_matrix
);
941 debug_assert(!"Unsupported number of textures");
947 void renderer_draw_textures(struct xorg_renderer
*r
,
949 int width
, int height
,
950 struct pipe_texture
**textures
,
952 float *src_matrix
, float *mask_matrix
)
956 debug_printf("src_matrix = \n");
957 debug_printf("%f, %f, %f\n", src_matrix
[0], src_matrix
[1], src_matrix
[2]);
958 debug_printf("%f, %f, %f\n", src_matrix
[3], src_matrix
[4], src_matrix
[5]);
959 debug_printf("%f, %f, %f\n", src_matrix
[6], src_matrix
[7], src_matrix
[8]);
962 debug_printf("mask_matrix = \n");
963 debug_printf("%f, %f, %f\n", mask_matrix
[0], mask_matrix
[1], mask_matrix
[2]);
964 debug_printf("%f, %f, %f\n", mask_matrix
[3], mask_matrix
[4], mask_matrix
[5]);
965 debug_printf("%f, %f, %f\n", mask_matrix
[6], mask_matrix
[7], mask_matrix
[8]);
969 r
->num_attributes
= 1 + num_textures
;
970 switch(num_textures
) {
973 pos
[0], pos
[1], /* src */
974 pos
[4], pos
[5], /* dst */
976 textures
[0], src_matrix
);
980 pos
[0], pos
[1], /* src */
981 pos
[2], pos
[3], /* mask */
982 pos
[4], pos
[5], /* dst */
984 textures
[0], textures
[1],
985 src_matrix
, mask_matrix
);
989 debug_assert(!"Unsupported number of textures");