45
static INLINE struct pipe_resource *
46
renderer_buffer_create(struct xorg_renderer *r)
48
struct pipe_resource *buf =
49
pipe_user_buffer_create(r->pipe->screen,
53
/* XXX was: PIPE_BUFFER_USAGE_PIXEL/PIPE_BUFFER_USAGE_GPU_WRITE even though this is a vertex buffer??? */
54
PIPE_BIND_VERTEX_BUFFER);
61
46
renderer_draw(struct xorg_renderer *r)
63
struct pipe_context *pipe = r->pipe;
64
struct pipe_resource *buf = 0;
65
48
int num_verts = r->buffer_size/(r->attrs_per_vertex * NUM_COMPONENTS);
67
50
if (!r->buffer_size)
70
buf = renderer_buffer_create(r);
74
cso_set_vertex_elements(r->cso, r->attrs_per_vertex, r->velems);
76
util_draw_vertex_buffer(pipe, r->cso, buf, 0,
78
num_verts, /* verts */
79
r->attrs_per_vertex); /* attribs/vert */
81
pipe_resource_reference(&buf, NULL);
53
cso_set_vertex_elements(r->cso, r->attrs_per_vertex, r->velems);
54
util_draw_user_vertex_buffer(r->cso, r->buffer, PIPE_PRIM_QUADS,
55
num_verts, r->attrs_per_vertex);
238
213
struct pipe_resource *mask,
239
214
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];
216
float src_s0, src_t0, src_s1, src_t1, src_s2, src_t2, src_s3, src_t3;
217
float mask_s0, mask_t0, mask_s1, mask_t1, mask_s2, mask_t2, mask_s3, mask_t3;
218
float spt0[2], spt1[2], spt2[2], spt3[2];
219
float mpt0[2], mpt1[2], mpt2[2], mpt3[2];
248
spt1[0] = srcX + width;
249
spt1[1] = srcY + height;
223
spt1[0] = (srcX + width);
225
spt2[0] = (srcX + width);
226
spt2[1] = (srcY + height);
228
spt3[1] = (srcY + height);
253
mpt1[0] = maskX + width;
254
mpt1[1] = maskY + height;
232
mpt1[0] = (maskX + width);
234
mpt2[0] = (maskX + width);
235
mpt2[1] = (maskY + height);
237
mpt3[1] = (maskY + height);
256
239
if (src_matrix) {
257
240
map_point(src_matrix, spt0[0], spt0[1], &spt0[0], &spt0[1]);
258
241
map_point(src_matrix, spt1[0], spt1[1], &spt1[0], &spt1[1]);
242
map_point(src_matrix, spt2[0], spt2[1], &spt2[0], &spt2[1]);
243
map_point(src_matrix, spt3[0], spt3[1], &spt3[0], &spt3[1]);
261
246
if (mask_matrix) {
262
247
map_point(mask_matrix, mpt0[0], mpt0[1], &mpt0[0], &mpt0[1]);
263
248
map_point(mask_matrix, mpt1[0], mpt1[1], &mpt1[0], &mpt1[1]);
249
map_point(mask_matrix, mpt2[0], mpt2[1], &mpt2[0], &mpt2[1]);
250
map_point(mask_matrix, mpt3[0], mpt3[1], &mpt3[0], &mpt3[1]);
266
src_s0 = spt0[0] / src->width0;
267
src_t0 = spt0[1] / src->height0;
268
src_s1 = spt1[0] / src->width0;
269
src_t1 = spt1[1] / src->height0;
253
src_s0 = spt0[0] / src->width0;
254
src_s1 = spt1[0] / src->width0;
255
src_s2 = spt2[0] / src->width0;
256
src_s3 = spt3[0] / src->width0;
257
src_t0 = spt0[1] / src->height0;
258
src_t1 = spt1[1] / src->height0;
259
src_t2 = spt2[1] / src->height0;
260
src_t3 = spt3[1] / src->height0;
271
mask_s0 = mpt0[0] / mask->width0;
272
mask_t0 = mpt0[1] / mask->height0;
273
mask_s1 = mpt1[0] / mask->width0;
274
mask_t1 = mpt1[1] / mask->height0;
262
mask_s0 = mpt0[0] / mask->width0;
263
mask_s1 = mpt1[0] / mask->width0;
264
mask_s2 = mpt2[0] / mask->width0;
265
mask_s3 = mpt3[0] / mask->width0;
266
mask_t0 = mpt0[1] / mask->height0;
267
mask_t1 = mpt1[1] / mask->height0;
268
mask_t2 = mpt2[1] / mask->height0;
269
mask_t3 = mpt3[1] / mask->height0;
277
272
add_vertex_2tex(r, dstX, dstY,
278
273
src_s0, src_t0, mask_s0, mask_t0);
280
275
add_vertex_2tex(r, dstX + width, dstY,
281
src_s1, src_t0, mask_s1, mask_t0);
276
src_s1, src_t1, mask_s1, mask_t1);
283
278
add_vertex_2tex(r, dstX + width, dstY + height,
284
src_s1, src_t1, mask_s1, mask_t1);
279
src_s2, src_t2, mask_s2, mask_t2);
286
281
add_vertex_2tex(r, dstX, dstY + height,
287
src_s0, src_t1, mask_s0, mask_t1);
282
src_s3, src_t3, mask_s3, mask_t3);
290
static struct pipe_resource *
291
286
setup_vertex_data_yuv(struct xorg_renderer *r,
292
287
float srcX, float srcY, float srcW, float srcH,
293
288
float dstX, float dstY, float dstW, float dstH,
437
430
pipe_buffer_write(r->pipe, *cbuf,
438
431
0, param_bytes, params);
440
r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
444
void renderer_copy_prepare(struct xorg_renderer *r,
445
struct pipe_surface *dst_surface,
446
struct pipe_resource *src_texture)
448
struct pipe_context *pipe = r->pipe;
449
struct pipe_screen *screen = pipe->screen;
450
struct xorg_shader shader;
452
assert(screen->is_format_supported(screen, dst_surface->format,
454
PIPE_BIND_RENDER_TARGET));
458
/* set misc state we care about */
460
struct pipe_blend_state blend;
461
memset(&blend, 0, sizeof(blend));
462
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
463
blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
464
blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
465
blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
466
blend.rt[0].colormask = PIPE_MASK_RGBA;
467
cso_set_blend(r->cso, &blend);
472
struct pipe_sampler_state sampler;
473
memset(&sampler, 0, sizeof(sampler));
474
sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
475
sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
476
sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
477
sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
478
sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
479
sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
480
sampler.normalized_coords = 1;
481
cso_single_sampler(r->cso, 0, &sampler);
482
cso_single_sampler_done(r->cso);
485
renderer_bind_destination(r, dst_surface,
487
dst_surface->height);
489
/* texture/sampler view */
491
struct pipe_sampler_view templ;
492
struct pipe_sampler_view *src_view;
493
u_sampler_view_default_template(&templ,
495
src_texture->format);
496
src_view = pipe->create_sampler_view(pipe, src_texture, &templ);
497
cso_set_fragment_sampler_views(r->cso, 1, &src_view);
498
pipe_sampler_view_reference(&src_view, NULL);
502
shader = xorg_shaders_get(r->shaders,
505
cso_set_vertex_shader_handle(r->cso, shader.vs);
506
cso_set_fragment_shader_handle(r->cso, shader.fs);
509
r->attrs_per_vertex = 2;
512
struct pipe_resource *
513
renderer_clone_texture(struct xorg_renderer *r,
514
struct pipe_resource *src)
516
enum pipe_format format;
517
struct pipe_context *pipe = r->pipe;
518
struct pipe_screen *screen = pipe->screen;
519
struct pipe_resource *pt;
520
struct pipe_resource templ;
522
/* the coming in texture should already have that invariance */
523
debug_assert(screen->is_format_supported(screen, src->format,
525
PIPE_BIND_SAMPLER_VIEW));
527
format = src->format;
529
memset(&templ, 0, sizeof(templ));
530
templ.target = PIPE_TEXTURE_2D;
531
templ.format = format;
532
templ.last_level = 0;
533
templ.width0 = src->width0;
534
templ.height0 = src->height0;
536
templ.array_size = 1;
537
templ.bind = PIPE_BIND_SAMPLER_VIEW;
539
pt = screen->resource_create(screen, &templ);
541
debug_assert(!pt || pipe_is_referenced(&pt->reference));
547
/* copy source framebuffer surface into texture */
548
struct pipe_box src_box;
549
u_box_origin_2d(src->width0, src->height0, &src_box);
551
pipe->resource_copy_region(pipe,
554
0, 0, 0, /* destx/y/z */
563
void renderer_copy_pixmap(struct xorg_renderer *r,
566
int width, int height,
570
float s0, t0, s1, t1;
571
float x0, y0, x1, y1;
574
/* XXX: could put the texcoord scaling calculation into the vertex
578
s1 = (sx + width) / src_width;
579
t0 = sy / src_height;
580
t1 = (sy + height) / src_height;
588
renderer_draw_conditional(r, 4*8);
589
add_vertex_1tex(r, x0, y0, s0, t0);
590
add_vertex_1tex(r, x1, y0, s1, t0);
591
add_vertex_1tex(r, x1, y1, s1, t1);
592
add_vertex_1tex(r, x0, y1, s0, t1);
433
pipe_set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
600
440
int dst_x, int dst_y, int dst_w, int dst_h,
601
441
struct pipe_resource **textures)
603
struct pipe_context *pipe = r->pipe;
604
struct pipe_resource *buf = 0;
606
buf = setup_vertex_data_yuv(r,
607
src_x, src_y, src_w, src_h,
608
dst_x, dst_y, dst_w, dst_h,
612
const int num_attribs = 2; /*pos + tex coord*/
614
cso_set_vertex_elements(r->cso, num_attribs, r->velems);
616
util_draw_vertex_buffer(pipe, r->cso, buf, 0,
619
num_attribs); /* attribs/vert */
621
pipe_resource_reference(&buf, NULL);
443
const int num_attribs = 2; /*pos + tex coord*/
445
setup_vertex_data_yuv(r,
446
src_x, src_y, src_w, src_h,
447
dst_x, dst_y, dst_w, dst_h,
450
cso_set_vertex_elements(r->cso, num_attribs, r->velems);
452
util_draw_user_vertex_buffer(r->cso, r->buffer,
455
num_attribs); /* attribs/vert */
625
460
void renderer_begin_solid(struct xorg_renderer *r)