1#ifndef SNA_RENDER_H 2#define SNA_RENDER_H 3 4#include "compiler.h" 5 6#include <picturestr.h> 7 8#include <stdbool.h> 9#include <stdint.h> 10#include <pthread.h> 11#include "atomic.h" 12 13#define GRADIENT_CACHE_SIZE 16 14 15#define GXinvalid 0xff 16 17struct sna; 18struct sna_glyph; 19struct sna_video; 20struct sna_video_frame; 21struct brw_compile; 22 23struct sna_composite_rectangles { 24 struct sna_coordinate { 25 int16_t x, y; 26 } src, mask, dst; 27 int16_t width, height; 28}; 29 30struct sna_composite_op { 31 fastcall void (*blt)(struct sna *sna, const struct sna_composite_op *op, 32 const struct sna_composite_rectangles *r); 33 fastcall void (*box)(struct sna *sna, 34 const struct sna_composite_op *op, 35 const BoxRec *box); 36 void (*boxes)(struct sna *sna, const struct sna_composite_op *op, 37 const BoxRec *box, int nbox); 38 void (*thread_boxes)(struct sna *sna, const struct sna_composite_op *op, 39 const BoxRec *box, int nbox); 40 void (*done)(struct sna *sna, const struct sna_composite_op *op); 41 42 struct sna_damage **damage; 43 44 uint32_t op; 45 46 struct { 47 PixmapPtr pixmap; /* XXX */ 48 CARD32 format; 49 struct kgem_bo *bo; 50 int16_t x, y; 51 uint16_t width, height; 52 } dst; 53 54 struct sna_composite_channel { 55 struct kgem_bo *bo; 56 PictTransform *transform; 57 uint16_t width; 58 uint16_t height; 59 uint32_t pict_format; 60 uint32_t card_format; 61 uint32_t filter; 62 uint32_t repeat; 63 uint32_t is_affine : 1; 64 uint32_t is_solid : 1; 65 uint32_t is_linear : 1; 66 uint32_t is_opaque : 1; 67 uint32_t alpha_fixup : 1; 68 uint32_t rb_reversed : 1; 69 int16_t offset[2]; 70 float scale[2]; 71 72 pixman_transform_t embedded_transform; 73 74 union { 75 struct { 76 float dx, dy, offset; 77 } linear; 78 struct { 79 uint32_t pixel; 80 } gen2; 81 struct gen3_shader_channel { 82 int type; 83 uint32_t mode; 84 uint32_t constants; 85 } gen3; 86 } u; 87 } src, mask; 88 uint32_t is_affine : 1; 89 uint32_t has_component_alpha : 1; 90 uint32_t need_magic_ca_pass : 1; 91 uint32_t rb_reversed : 1; 92 93 int16_t floats_per_vertex; 94 int16_t floats_per_rect; 95 fastcall void (*prim_emit)(struct sna *sna, 96 const struct sna_composite_op *op, 97 const struct sna_composite_rectangles *r); 98 fastcall void (*emit_boxes)(const struct sna_composite_op *op, 99 const BoxRec *box, int nbox, 100 float *v); 101 102 struct sna_composite_redirect { 103 struct kgem_bo *real_bo; 104 struct sna_damage **real_damage, *damage; 105 BoxRec box; 106 } redirect; 107 108 union { 109 struct sna_blt_state { 110 PixmapPtr src_pixmap; 111 int16_t sx, sy; 112 113 uint32_t inplace :1; 114 uint32_t overwrites:1; 115 uint32_t bpp : 6; 116 uint32_t alu : 4; 117 118 uint32_t cmd; 119 uint32_t br13; 120 uint32_t pitch[2]; 121 uint32_t pixel; 122 struct kgem_bo *bo[2]; 123 } blt; 124 125 struct { 126 float constants[8]; 127 uint32_t num_constants; 128 } gen3; 129 130 struct { 131 int wm_kernel; 132 int ve_id; 133 } gen4; 134 135 struct { 136 int16_t wm_kernel; 137 int16_t ve_id; 138 } gen5; 139 140 struct { 141 uint32_t flags; 142 } gen6; 143 144 struct { 145 uint32_t flags; 146 } gen7; 147 148 struct { 149 uint32_t flags; 150 } gen8; 151 } u; 152 153 void *priv; 154}; 155 156struct sna_opacity_box { 157 BoxRec box; 158 float alpha; 159} tightly_packed; 160 161struct sna_composite_spans_op { 162 struct sna_composite_op base; 163 164 fastcall void (*box)(struct sna *sna, 165 const struct sna_composite_spans_op *op, 166 const BoxRec *box, 167 float opacity); 168 void (*boxes)(struct sna *sna, 169 const struct sna_composite_spans_op *op, 170 const BoxRec *box, int nbox, 171 float opacity); 172 173 fastcall void (*thread_boxes)(struct sna *sna, 174 const struct sna_composite_spans_op *op, 175 const struct sna_opacity_box *box, 176 int nbox); 177 178 fastcall void (*done)(struct sna *sna, 179 const struct sna_composite_spans_op *op); 180 181 fastcall void (*prim_emit)(struct sna *sna, 182 const struct sna_composite_spans_op *op, 183 const BoxRec *box, 184 float opacity); 185 fastcall void (*emit_boxes)(const struct sna_composite_spans_op *op, 186 const struct sna_opacity_box *box, int nbox, 187 float *v); 188}; 189 190struct sna_fill_op { 191 struct sna_composite_op base; 192 193 void (*blt)(struct sna *sna, const struct sna_fill_op *op, 194 int16_t x, int16_t y, int16_t w, int16_t h); 195 fastcall void (*box)(struct sna *sna, 196 const struct sna_fill_op *op, 197 const BoxRec *box); 198 fastcall void (*boxes)(struct sna *sna, 199 const struct sna_fill_op *op, 200 const BoxRec *box, 201 int count); 202 fastcall void (*points)(struct sna *sna, 203 const struct sna_fill_op *op, 204 int16_t dx, int16_t dy, 205 const DDXPointRec *points, 206 int count); 207 void (*done)(struct sna *sna, const struct sna_fill_op *op); 208}; 209 210struct sna_copy_op { 211 struct sna_composite_op base; 212 213 void (*blt)(struct sna *sna, const struct sna_copy_op *op, 214 int16_t sx, int16_t sy, 215 int16_t w, int16_t h, 216 int16_t dx, int16_t dy); 217 void (*done)(struct sna *sna, const struct sna_copy_op *op); 218}; 219 220struct sna_render { 221 pthread_mutex_t lock; 222 pthread_cond_t wait; 223 int active; 224 225 int max_3d_size; 226 int max_3d_pitch; 227 228 unsigned prefer_gpu; 229#define PREFER_GPU_BLT 0x1 230#define PREFER_GPU_RENDER 0x2 231#define PREFER_GPU_SPANS 0x4 232 233 bool (*composite)(struct sna *sna, uint8_t op, 234 PicturePtr dst, PicturePtr src, PicturePtr mask, 235 int16_t src_x, int16_t src_y, 236 int16_t msk_x, int16_t msk_y, 237 int16_t dst_x, int16_t dst_y, 238 int16_t w, int16_t h, 239 unsigned flags, 240 struct sna_composite_op *tmp); 241#define COMPOSITE_PARTIAL 0x1 242#define COMPOSITE_FALLBACK 0x80000000 243 244 bool (*check_composite_spans)(struct sna *sna, uint8_t op, 245 PicturePtr dst, PicturePtr src, 246 int16_t w, int16_t h, unsigned flags); 247 bool (*composite_spans)(struct sna *sna, uint8_t op, 248 PicturePtr dst, PicturePtr src, 249 int16_t src_x, int16_t src_y, 250 int16_t dst_x, int16_t dst_y, 251 int16_t w, int16_t h, 252 unsigned flags, 253 struct sna_composite_spans_op *tmp); 254#define COMPOSITE_SPANS_RECTILINEAR 0x1 255#define COMPOSITE_SPANS_INPLACE_HINT 0x2 256 257 bool (*video)(struct sna *sna, 258 struct sna_video *video, 259 struct sna_video_frame *frame, 260 RegionPtr dstRegion, 261 PixmapPtr pixmap); 262 263 bool (*fill_boxes)(struct sna *sna, 264 CARD8 op, 265 PictFormat format, 266 const xRenderColor *color, 267 const DrawableRec *dst, struct kgem_bo *dst_bo, 268 const BoxRec *box, int n); 269 bool (*fill)(struct sna *sna, uint8_t alu, 270 PixmapPtr dst, struct kgem_bo *dst_bo, 271 uint32_t color, unsigned flags, 272 struct sna_fill_op *tmp); 273#define FILL_BOXES 0x1 274#define FILL_POINTS 0x2 275#define FILL_SPANS 0x4 276 bool (*fill_one)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo, 277 uint32_t color, 278 int16_t x1, int16_t y1, int16_t x2, int16_t y2, 279 uint8_t alu); 280 bool (*clear)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo); 281 282 bool (*copy_boxes)(struct sna *sna, uint8_t alu, 283 const DrawableRec *src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 284 const DrawableRec *dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 285 const BoxRec *box, int n, unsigned flags); 286#define COPY_LAST 0x1 287#define COPY_SYNC 0x2 288#define COPY_NO_OVERLAP 0x4 289 290 bool (*copy)(struct sna *sna, uint8_t alu, 291 PixmapPtr src, struct kgem_bo *src_bo, 292 PixmapPtr dst, struct kgem_bo *dst_bo, 293 struct sna_copy_op *op); 294 295 void (*flush)(struct sna *sna); 296 void (*reset)(struct sna *sna); 297 void (*fini)(struct sna *sna); 298 299 struct sna_alpha_cache { 300 struct kgem_bo *cache_bo; 301 struct kgem_bo *bo[256+7]; 302 } alpha_cache; 303 304 struct sna_solid_cache { 305 struct kgem_bo *cache_bo; 306 struct kgem_bo *bo[1024]; 307 uint32_t color[1024]; 308 int last; 309 int size; 310 int dirty; 311 } solid_cache; 312 313 struct { 314 struct sna_gradient_cache { 315 struct kgem_bo *bo; 316 int nstops; 317 PictGradientStop *stops; 318 } cache[GRADIENT_CACHE_SIZE]; 319 int size; 320 } gradient_cache; 321 322 struct sna_glyph_cache{ 323 PicturePtr picture; 324 struct sna_glyph **glyphs; 325 uint16_t count; 326 uint16_t evict; 327 } glyph[2]; 328 pixman_image_t *white_image; 329 PicturePtr white_picture; 330 331 uint16_t vb_id; 332 uint16_t vertex_offset; 333 uint16_t vertex_start; 334 uint16_t vertex_index; 335 uint16_t vertex_used; 336 uint16_t vertex_size; 337 uint16_t vertex_reloc[16]; 338 int nvertex_reloc; 339 340 struct kgem_bo *vbo; 341 float *vertices; 342 343 float vertex_data[1024]; 344}; 345 346struct gen2_render_state { 347 uint32_t target; 348 bool need_invariant; 349 uint32_t logic_op_enabled; 350 uint32_t ls1, ls2, vft; 351 uint32_t diffuse; 352 uint32_t specular; 353}; 354 355struct gen3_render_state { 356 uint32_t current_dst; 357 bool need_invariant; 358 uint32_t tex_count; 359 uint32_t last_drawrect_limit; 360 uint32_t last_target; 361 uint32_t last_blend; 362 uint32_t last_constants; 363 uint32_t last_sampler; 364 uint32_t last_shader; 365 uint32_t last_diffuse; 366 uint32_t last_specular; 367 368 uint16_t last_vertex_offset; 369 uint16_t floats_per_vertex; 370 uint16_t last_floats_per_vertex; 371 372 uint32_t tex_map[4]; 373 uint32_t tex_handle[2]; 374 uint32_t tex_delta[2]; 375}; 376 377struct gen4_render_state { 378 struct kgem_bo *general_bo; 379 380 uint32_t vs; 381 uint32_t sf; 382 uint32_t wm; 383 uint32_t cc; 384 385 int ve_id; 386 uint32_t drawrect_offset; 387 uint32_t drawrect_limit; 388 uint32_t last_pipelined_pointers; 389 uint16_t last_primitive; 390 int16_t floats_per_vertex; 391 uint16_t surface_table; 392 393 bool needs_invariant; 394 bool needs_urb; 395}; 396 397struct gen5_render_state { 398 struct kgem_bo *general_bo; 399 400 uint32_t vs; 401 uint32_t sf[2]; 402 uint32_t wm; 403 uint32_t cc; 404 405 int ve_id; 406 uint32_t drawrect_offset; 407 uint32_t drawrect_limit; 408 uint32_t last_pipelined_pointers; 409 uint16_t last_primitive; 410 int16_t floats_per_vertex; 411 uint16_t surface_table; 412 413 bool needs_invariant; 414}; 415 416enum { 417 GEN6_WM_KERNEL_NOMASK = 0, 418 GEN6_WM_KERNEL_NOMASK_P, 419 420 GEN6_WM_KERNEL_MASK, 421 GEN6_WM_KERNEL_MASK_P, 422 423 GEN6_WM_KERNEL_MASKCA, 424 GEN6_WM_KERNEL_MASKCA_P, 425 426 GEN6_WM_KERNEL_MASKSA, 427 GEN6_WM_KERNEL_MASKSA_P, 428 429 GEN6_WM_KERNEL_OPACITY, 430 GEN6_WM_KERNEL_OPACITY_P, 431 432 GEN6_WM_KERNEL_VIDEO_PLANAR, 433 GEN6_WM_KERNEL_VIDEO_PACKED, 434 GEN6_KERNEL_COUNT 435}; 436 437struct gen6_render_state { 438 unsigned gt; 439 const struct gt_info *info; 440 struct kgem_bo *general_bo; 441 442 uint32_t vs_state; 443 uint32_t sf_state; 444 uint32_t sf_mask_state; 445 uint32_t wm_state; 446 uint32_t wm_kernel[GEN6_KERNEL_COUNT][3]; 447 448 uint32_t cc_blend; 449 450 uint32_t drawrect_offset; 451 uint32_t drawrect_limit; 452 uint32_t blend; 453 uint32_t samplers; 454 uint32_t kernel; 455 456 uint16_t num_sf_outputs; 457 uint16_t ve_id; 458 uint16_t last_primitive; 459 int16_t floats_per_vertex; 460 uint16_t surface_table; 461 462 bool needs_invariant; 463 bool first_state_packet; 464}; 465 466enum { 467 GEN7_WM_KERNEL_NOMASK = 0, 468 GEN7_WM_KERNEL_NOMASK_P, 469 470 GEN7_WM_KERNEL_MASK, 471 GEN7_WM_KERNEL_MASK_P, 472 473 GEN7_WM_KERNEL_MASKCA, 474 GEN7_WM_KERNEL_MASKCA_P, 475 476 GEN7_WM_KERNEL_MASKSA, 477 GEN7_WM_KERNEL_MASKSA_P, 478 479 GEN7_WM_KERNEL_OPACITY, 480 GEN7_WM_KERNEL_OPACITY_P, 481 482 GEN7_WM_KERNEL_VIDEO_PLANAR, 483 GEN7_WM_KERNEL_VIDEO_PACKED, 484 GEN7_WM_KERNEL_COUNT 485}; 486 487struct gen7_render_state { 488 unsigned gt; 489 const struct gt_info *info; 490 struct kgem_bo *general_bo; 491 492 uint32_t vs_state; 493 uint32_t sf_state; 494 uint32_t sf_mask_state; 495 uint32_t wm_state; 496 uint32_t wm_kernel[GEN7_WM_KERNEL_COUNT][3]; 497 498 uint32_t cc_blend; 499 500 uint32_t drawrect_offset; 501 uint32_t drawrect_limit; 502 uint32_t blend; 503 uint32_t samplers; 504 uint32_t kernel; 505 506 uint16_t num_sf_outputs; 507 uint16_t ve_id; 508 uint16_t last_primitive; 509 int16_t floats_per_vertex; 510 uint16_t surface_table; 511 uint16_t pipe_controls_since_stall; 512 513 bool needs_invariant; 514 bool emit_flush; 515}; 516 517 518enum { 519 GEN8_WM_KERNEL_NOMASK = 0, 520 GEN8_WM_KERNEL_NOMASK_P, 521 522 GEN8_WM_KERNEL_MASK, 523 GEN8_WM_KERNEL_MASK_P, 524 525 GEN8_WM_KERNEL_MASKCA, 526 GEN8_WM_KERNEL_MASKCA_P, 527 528 GEN8_WM_KERNEL_MASKSA, 529 GEN8_WM_KERNEL_MASKSA_P, 530 531 GEN8_WM_KERNEL_OPACITY, 532 GEN8_WM_KERNEL_OPACITY_P, 533 534 GEN8_WM_KERNEL_VIDEO_PLANAR, 535 GEN8_WM_KERNEL_VIDEO_PACKED, 536 GEN8_WM_KERNEL_COUNT 537}; 538 539struct gen8_render_state { 540 unsigned gt; 541 542 struct kgem_bo *general_bo; 543 544 uint32_t vs_state; 545 uint32_t sf_state; 546 uint32_t sf_mask_state; 547 uint32_t wm_state; 548 uint32_t wm_kernel[GEN8_WM_KERNEL_COUNT][3]; 549 550 uint32_t cc_blend; 551 552 uint32_t drawrect_offset; 553 uint32_t drawrect_limit; 554 uint32_t blend; 555 uint32_t samplers; 556 uint32_t kernel; 557 558 uint16_t num_sf_outputs; 559 uint16_t ve_id; 560 uint16_t last_primitive; 561 int16_t floats_per_vertex; 562 uint16_t surface_table; 563 564 bool needs_invariant; 565 bool emit_flush; 566}; 567 568struct sna_static_stream { 569 uint32_t size, used; 570 uint8_t *data; 571}; 572 573int sna_static_stream_init(struct sna_static_stream *stream); 574uint32_t sna_static_stream_add(struct sna_static_stream *stream, 575 const void *data, uint32_t len, uint32_t align); 576void *sna_static_stream_map(struct sna_static_stream *stream, 577 uint32_t len, uint32_t align); 578uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream, 579 void *ptr); 580unsigned sna_static_stream_compile_sf(struct sna *sna, 581 struct sna_static_stream *stream, 582 bool (*compile)(struct brw_compile *)); 583 584unsigned sna_static_stream_compile_wm(struct sna *sna, 585 struct sna_static_stream *stream, 586 bool (*compile)(struct brw_compile *, int), 587 int width); 588struct kgem_bo *sna_static_stream_fini(struct sna *sna, 589 struct sna_static_stream *stream); 590 591struct kgem_bo * 592sna_render_get_solid(struct sna *sna, 593 uint32_t color); 594 595void 596sna_render_flush_solid(struct sna *sna); 597 598struct kgem_bo * 599sna_render_get_gradient(struct sna *sna, 600 PictGradient *pattern); 601 602bool 603sna_gradient_is_opaque(const PictGradient *gradient); 604 605uint32_t sna_rgba_for_color(uint32_t color, int depth); 606uint32_t sna_rgba_to_color(uint32_t rgba, uint32_t format); 607bool sna_get_rgba_from_pixel(uint32_t pixel, 608 uint16_t *red, 609 uint16_t *green, 610 uint16_t *blue, 611 uint16_t *alpha, 612 uint32_t format); 613bool sna_picture_is_solid(PicturePtr picture, uint32_t *color); 614 615const char *no_render_init(struct sna *sna); 616const char *gen2_render_init(struct sna *sna, const char *backend); 617const char *gen3_render_init(struct sna *sna, const char *backend); 618const char *gen4_render_init(struct sna *sna, const char *backend); 619const char *gen5_render_init(struct sna *sna, const char *backend); 620const char *gen6_render_init(struct sna *sna, const char *backend); 621const char *gen7_render_init(struct sna *sna, const char *backend); 622const char *gen8_render_init(struct sna *sna, const char *backend); 623 624void sna_render_mark_wedged(struct sna *sna); 625 626bool sna_tiling_composite(uint32_t op, 627 PicturePtr src, 628 PicturePtr mask, 629 PicturePtr dst, 630 int16_t src_x, int16_t src_y, 631 int16_t mask_x, int16_t mask_y, 632 int16_t dst_x, int16_t dst_y, 633 int16_t width, int16_t height, 634 struct sna_composite_op *tmp); 635bool sna_tiling_composite_spans(uint32_t op, 636 PicturePtr src, 637 PicturePtr dst, 638 int16_t src_x, int16_t src_y, 639 int16_t dst_x, int16_t dst_y, 640 int16_t width, int16_t height, 641 unsigned flags, 642 struct sna_composite_spans_op *tmp); 643bool sna_tiling_fill_boxes(struct sna *sna, 644 CARD8 op, 645 PictFormat format, 646 const xRenderColor *color, 647 const DrawableRec *dst, struct kgem_bo *dst_bo, 648 const BoxRec *box, int n); 649 650bool sna_tiling_copy_boxes(struct sna *sna, uint8_t alu, 651 const DrawableRec *src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 652 const DrawableRec *dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 653 const BoxRec *box, int n); 654 655bool sna_tiling_blt_copy_boxes(struct sna *sna, uint8_t alu, 656 struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 657 struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 658 int bpp, const BoxRec *box, int nbox); 659 660bool sna_tiling_blt_composite(struct sna *sna, 661 struct sna_composite_op *op, 662 struct kgem_bo *bo, 663 int bpp, 664 uint32_t alpha_fixup); 665 666bool sna_blt_composite(struct sna *sna, 667 uint32_t op, 668 PicturePtr src, 669 PicturePtr dst, 670 int16_t src_x, int16_t src_y, 671 int16_t dst_x, int16_t dst_y, 672 int16_t width, int16_t height, 673 unsigned flags, 674 struct sna_composite_op *tmp); 675bool sna_blt_composite__convert(struct sna *sna, 676 int x, int y, 677 int width, int height, 678 struct sna_composite_op *tmp); 679 680bool sna_blt_fill(struct sna *sna, uint8_t alu, 681 struct kgem_bo *bo, 682 int bpp, 683 uint32_t pixel, 684 struct sna_fill_op *fill); 685 686bool sna_blt_copy(struct sna *sna, uint8_t alu, 687 struct kgem_bo *src, 688 struct kgem_bo *dst, 689 int bpp, 690 struct sna_copy_op *copy); 691 692bool sna_blt_fill_boxes(struct sna *sna, uint8_t alu, 693 struct kgem_bo *bo, 694 int bpp, 695 uint32_t pixel, 696 const BoxRec *box, int n); 697 698bool sna_blt_copy_boxes(struct sna *sna, uint8_t alu, 699 struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 700 struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 701 int bpp, 702 const BoxRec *box, int n); 703bool sna_blt_copy_boxes__with_alpha(struct sna *sna, uint8_t alu, 704 struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 705 struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 706 int bpp, int alpha_fixup, 707 const BoxRec *box, int nbox); 708bool sna_blt_copy_boxes_fallback(struct sna *sna, uint8_t alu, 709 const DrawableRec *src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 710 const DrawableRec *dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 711 const BoxRec *box, int nbox); 712 713bool memcpy_copy_boxes(struct sna *sna, uint8_t op, 714 const DrawableRec *src_draw, struct kgem_bo *src_bo, int16_t sx, int16_t sy, 715 const DrawableRec *dst_draw, struct kgem_bo *dst_bo, int16_t dx, int16_t dy, 716 const BoxRec *box, int n, unsigned flags); 717 718bool _sna_get_pixel_from_rgba(uint32_t *pixel, 719 uint16_t red, 720 uint16_t green, 721 uint16_t blue, 722 uint16_t alpha, 723 uint32_t format); 724 725static inline bool 726sna_get_pixel_from_rgba(uint32_t * pixel, 727 uint16_t red, 728 uint16_t green, 729 uint16_t blue, 730 uint16_t alpha, 731 uint32_t format) 732{ 733 switch (format) { 734 case PICT_x8r8g8b8: 735 alpha = 0xffff; 736 /* fall through to re-use a8r8g8b8 expansion */ 737 case PICT_a8r8g8b8: 738 *pixel = ((alpha >> 8 << 24) | 739 (red >> 8 << 16) | 740 (green & 0xff00) | 741 (blue >> 8)); 742 return TRUE; 743 case PICT_a8: 744 *pixel = alpha >> 8; 745 return TRUE; 746 } 747 748 return _sna_get_pixel_from_rgba(pixel, red, green, blue, alpha, format); 749} 750 751struct kgem_bo * 752__sna_render_pixmap_bo(struct sna *sna, 753 PixmapPtr pixmap, 754 const BoxRec *box, 755 bool blt); 756 757int 758sna_render_pixmap_bo(struct sna *sna, 759 struct sna_composite_channel *channel, 760 PixmapPtr pixmap, 761 int16_t x, int16_t y, 762 int16_t w, int16_t h, 763 int16_t dst_x, int16_t dst_y); 764 765bool 766sna_render_pixmap_partial(struct sna *sna, 767 const DrawableRec *draw, 768 struct kgem_bo *bo, 769 struct sna_composite_channel *channel, 770 int16_t x, int16_t y, 771 int16_t w, int16_t h); 772 773int 774sna_render_picture_extract(struct sna *sna, 775 PicturePtr picture, 776 struct sna_composite_channel *channel, 777 int16_t x, int16_t y, 778 int16_t w, int16_t h, 779 int16_t dst_x, int16_t dst_y); 780 781int 782sna_render_picture_approximate_gradient(struct sna *sna, 783 PicturePtr picture, 784 struct sna_composite_channel *channel, 785 int16_t x, int16_t y, 786 int16_t w, int16_t h, 787 int16_t dst_x, int16_t dst_y); 788 789int 790sna_render_picture_fixup(struct sna *sna, 791 PicturePtr picture, 792 struct sna_composite_channel *channel, 793 int16_t x, int16_t y, 794 int16_t w, int16_t h, 795 int16_t dst_x, int16_t dst_y); 796 797int 798sna_render_picture_convert(struct sna *sna, 799 PicturePtr picture, 800 struct sna_composite_channel *channel, 801 PixmapPtr pixmap, 802 int16_t x, int16_t y, 803 int16_t w, int16_t h, 804 int16_t dst_x, int16_t dst_y, 805 bool fixup_alpha); 806 807inline static void sna_render_composite_redirect_init(struct sna_composite_op *op) 808{ 809 struct sna_composite_redirect *t = &op->redirect; 810 t->real_bo = NULL; 811 t->damage = NULL; 812} 813 814bool 815sna_render_composite_redirect(struct sna *sna, 816 struct sna_composite_op *op, 817 int x, int y, int width, int height, 818 bool partial); 819 820void 821sna_render_composite_redirect_done(struct sna *sna, 822 const struct sna_composite_op *op); 823 824bool 825sna_render_copy_boxes__overlap(struct sna *sna, uint8_t alu, 826 const DrawableRec *draw, struct kgem_bo *bo, 827 int16_t src_dx, int16_t src_dy, 828 int16_t dst_dx, int16_t dst_dy, 829 const BoxRec *box, int n, const BoxRec *extents); 830 831bool 832sna_composite_mask_is_opaque(PicturePtr mask); 833 834void sna_vertex_init(struct sna *sna); 835 836static inline void sna_vertex_lock(struct sna_render *r) 837{ 838 pthread_mutex_lock(&r->lock); 839} 840 841static inline void sna_vertex_acquire__locked(struct sna_render *r) 842{ 843 r->active++; 844} 845 846static inline void sna_vertex_unlock(struct sna_render *r) 847{ 848 pthread_mutex_unlock(&r->lock); 849} 850 851static inline void sna_vertex_release__locked(struct sna_render *r) 852{ 853 assert(r->active > 0); 854 if (--r->active == 0) 855 pthread_cond_signal(&r->wait); 856} 857 858static inline bool sna_vertex_wait__locked(struct sna_render *r) 859{ 860 bool was_active = r->active; 861 while (r->active) 862 pthread_cond_wait(&r->wait, &r->lock); 863 return was_active; 864} 865 866#define alphaless(format) PICT_FORMAT(PICT_FORMAT_BPP(format), \ 867 PICT_FORMAT_TYPE(format), \ 868 0, \ 869 PICT_FORMAT_R(format), \ 870 PICT_FORMAT_G(format), \ 871 PICT_FORMAT_B(format)) 872 873#endif /* SNA_RENDER_H */ 874