Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef SNA_RENDER_H
  2. #define SNA_RENDER_H
  3.  
  4. typedef int Bool;
  5.  
  6. #define GRADIENT_CACHE_SIZE 16
  7.  
  8. struct sna;
  9.  
  10. struct sna_composite_rectangles {
  11.         struct sna_coordinate {
  12.                 int16_t x, y;
  13.         } src, mask, dst;
  14.         int16_t width, height;
  15. };
  16.  
  17. struct sna_composite_op {
  18.     fastcall void (*blt)(struct sna *sna, const struct sna_composite_op *op,
  19.                  const struct sna_composite_rectangles *r);
  20.     fastcall void (*box)(struct sna *sna,
  21.                  const struct sna_composite_op *op,
  22.                  const BoxRec *box);
  23.     void (*boxes)(struct sna *sna, const struct sna_composite_op *op,
  24.               const BoxRec *box, int nbox);
  25.     void (*done)(struct sna *sna, const struct sna_composite_op *op);
  26.  
  27.     struct sna_damage **damage;
  28.  
  29.     uint32_t op;
  30.  
  31.     struct {
  32.         bitmap_t *pixmap;
  33.         CARD32    format;
  34.         struct kgem_bo *bo;
  35.         int16_t   x, y;
  36.         uint16_t  width, height;
  37.     } dst;
  38.  
  39.     struct sna_composite_channel {
  40.         struct kgem_bo *bo;
  41. //        PictTransform *transform;
  42.         uint16_t width;
  43.         uint16_t height;
  44.         uint32_t pict_format;
  45.         uint32_t card_format;
  46.         uint32_t filter;
  47.         uint32_t repeat;
  48.         uint32_t is_affine : 1;
  49.         uint32_t is_solid : 1;
  50.         uint32_t is_linear : 1;
  51.         uint32_t is_opaque : 1;
  52.         uint32_t alpha_fixup : 1;
  53.         uint32_t rb_reversed : 1;
  54.         int16_t offset[2];
  55.         float scale[2];
  56.  
  57. //        pixman_transform_t embedded_transform;
  58.  
  59.         union {
  60.             struct {
  61.                 uint32_t pixel;
  62.                 float linear_dx;
  63.                 float linear_dy;
  64.                 float linear_offset;
  65.             } gen2;
  66.             struct gen3_shader_channel {
  67.                 int type;
  68.                 uint32_t mode;
  69.                 uint32_t constants;
  70.             } gen3;
  71.         } u;
  72.     } src, mask;
  73.     uint32_t is_affine : 1;
  74.     uint32_t has_component_alpha : 1;
  75.     uint32_t need_magic_ca_pass : 1;
  76.     uint32_t rb_reversed : 1;
  77.  
  78.     int16_t floats_per_vertex;
  79.     int16_t floats_per_rect;
  80.     fastcall void (*prim_emit)(struct sna *sna,
  81.                    const struct sna_composite_op *op,
  82.                    const struct sna_composite_rectangles *r);
  83.  
  84.     struct sna_composite_redirect {
  85.         struct kgem_bo *real_bo;
  86.         struct sna_damage **real_damage, *damage;
  87.         BoxRec box;
  88.     } redirect;
  89.  
  90.     union {
  91.         struct sna_blt_state {
  92.             bitmap_t *src_pixmap;
  93.             int16_t sx, sy;
  94.  
  95.             uint32_t inplace :1;
  96.             uint32_t overwrites:1;
  97.             uint32_t bpp : 6;
  98.  
  99.             uint32_t cmd;
  100.             uint32_t br13;
  101.             uint32_t pitch[2];
  102.             uint32_t pixel;
  103.             struct kgem_bo *bo[2];
  104.         } blt;
  105.  
  106.         struct {
  107.             float constants[8];
  108.             uint32_t num_constants;
  109.         } gen3;
  110.  
  111.         struct {
  112.             int wm_kernel;
  113.             int ve_id;
  114.         } gen4;
  115.  
  116.         struct {
  117.             int wm_kernel;
  118.             int ve_id;
  119.         } gen5;
  120.  
  121.         struct {
  122.             int wm_kernel;
  123.             int nr_surfaces;
  124.             int nr_inputs;
  125.             int ve_id;
  126.         } gen6;
  127.  
  128.         struct {
  129.             int wm_kernel;
  130.             int nr_surfaces;
  131.             int nr_inputs;
  132.             int ve_id;
  133.         } gen7;
  134.  
  135.         void *priv;
  136.     } u;
  137. };
  138.  
  139.  
  140. struct sna_render {
  141.         int max_3d_size;
  142.         int max_3d_pitch;
  143.  
  144. /*
  145.         Bool (*composite)(struct sna *sna, uint8_t op,
  146.                           PicturePtr dst, PicturePtr src, PicturePtr mask,
  147.                           int16_t src_x, int16_t src_y,
  148.                           int16_t msk_x, int16_t msk_y,
  149.                           int16_t dst_x, int16_t dst_y,
  150.                           int16_t w, int16_t h,
  151.                           struct sna_composite_op *tmp);
  152.  
  153.         Bool (*composite_spans)(struct sna *sna, uint8_t op,
  154.                                 PicturePtr dst, PicturePtr src,
  155.                                 int16_t src_x, int16_t src_y,
  156.                                 int16_t dst_x, int16_t dst_y,
  157.                                 int16_t w, int16_t h,
  158.                                 unsigned flags,
  159.                                 struct sna_composite_spans_op *tmp);
  160. #define COMPOSITE_SPANS_RECTILINEAR 0x1
  161.  
  162.         Bool (*video)(struct sna *sna,
  163.                       struct sna_video *video,
  164.                       struct sna_video_frame *frame,
  165.                       RegionPtr dstRegion,
  166.                       short src_w, short src_h,
  167.                       short drw_w, short drw_h,
  168.                       PixmapPtr pixmap);
  169.  
  170.         Bool (*fill_boxes)(struct sna *sna,
  171.                            CARD8 op,
  172.                            PictFormat format,
  173.                            const xRenderColor *color,
  174.                            PixmapPtr dst, struct kgem_bo *dst_bo,
  175.                            const BoxRec *box, int n);
  176.         Bool (*fill)(struct sna *sna, uint8_t alu,
  177.                      PixmapPtr dst, struct kgem_bo *dst_bo,
  178.                      uint32_t color,
  179.                      struct sna_fill_op *tmp);
  180.         Bool (*fill_one)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo,
  181.                          uint32_t color,
  182.                          int16_t x1, int16_t y1, int16_t x2, int16_t y2,
  183.                          uint8_t alu);
  184. */
  185.     Bool (*clear)(struct sna *sna, bitmap_t *dst, struct kgem_bo *dst_bo);
  186. /*
  187.         Bool (*copy_boxes)(struct sna *sna, uint8_t alu,
  188.                            PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
  189.                            PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
  190.                            const BoxRec *box, int n);
  191. */
  192.         Bool (*copy)(struct sna *sna, uint8_t alu,
  193.              bitmap_t *src, struct kgem_bo *src_bo,
  194.              bitmap_t *dst, struct kgem_bo *dst_bo,
  195.              int dst_x, int dst_y, int src_x, int src_y,
  196.              int w, int h);
  197.  
  198.         void (*flush)(struct sna *sna);
  199.         void (*reset)(struct sna *sna);
  200.         void (*fini)(struct sna *sna);
  201.  
  202. //   struct sna_alpha_cache {
  203. //       struct kgem_bo *cache_bo;
  204. //       struct kgem_bo *bo[256];
  205. //   } alpha_cache;
  206.  
  207.     struct sna_solid_cache {
  208.          struct kgem_bo *cache_bo;
  209.          uint32_t color[1024];
  210.          struct kgem_bo *bo[1024];
  211.          int last;
  212.          int size;
  213.          int dirty;
  214.     } solid_cache;
  215.  
  216. //   struct {
  217. //       struct sna_gradient_cache {
  218. //           struct kgem_bo *bo;
  219. //           int nstops;
  220. //           PictGradientStop *stops;
  221. //       } cache[GRADIENT_CACHE_SIZE];
  222. //       int size;
  223. //   } gradient_cache;
  224.  
  225. //   struct sna_glyph_cache{
  226. //       PicturePtr picture;
  227. //       struct sna_glyph **glyphs;
  228. //       uint16_t count;
  229. //       uint16_t evict;
  230. //   } glyph[2];
  231.  
  232.         uint16_t vertex_start;
  233.         uint16_t vertex_index;
  234.         uint16_t vertex_used;
  235.         uint16_t vertex_size;
  236.         uint16_t vertex_reloc[8];
  237.  
  238.     struct kgem_bo *vbo;
  239.         float *vertices;
  240.  
  241.         float vertex_data[1024];
  242. };
  243.  
  244. enum {
  245.         GEN6_WM_KERNEL_NOMASK = 0,
  246.         GEN6_WM_KERNEL_NOMASK_PROJECTIVE,
  247.  
  248.     GEN6_KERNEL_COUNT
  249. };
  250.  
  251. struct gen6_render_state {
  252.     struct kgem_bo *general_bo;
  253.  
  254.         uint32_t vs_state;
  255.         uint32_t sf_state;
  256.         uint32_t sf_mask_state;
  257.         uint32_t wm_state;
  258.         uint32_t wm_kernel[GEN6_KERNEL_COUNT];
  259.  
  260.         uint32_t cc_vp;
  261.         uint32_t cc_blend;
  262.  
  263.         uint32_t drawrect_offset;
  264.         uint32_t drawrect_limit;
  265.         uint32_t blend;
  266.         uint32_t samplers;
  267.         uint32_t kernel;
  268.  
  269.         uint16_t num_sf_outputs;
  270.         uint16_t vb_id;
  271.         uint16_t ve_id;
  272.         uint16_t vertex_offset;
  273.         uint16_t last_primitive;
  274.         int16_t floats_per_vertex;
  275.         uint16_t surface_table;
  276.  
  277.         Bool needs_invariant;
  278. };
  279.  
  280. enum {
  281.         GEN7_WM_KERNEL_NOMASK = 0,
  282.         GEN7_WM_KERNEL_NOMASK_PROJECTIVE,
  283.  
  284.         GEN7_WM_KERNEL_MASK,
  285.         GEN7_WM_KERNEL_MASK_PROJECTIVE,
  286.  
  287.         GEN7_WM_KERNEL_MASKCA,
  288.         GEN7_WM_KERNEL_MASKCA_PROJECTIVE,
  289.  
  290.         GEN7_WM_KERNEL_MASKCA_SRCALPHA,
  291.         GEN7_WM_KERNEL_MASKCA_SRCALPHA_PROJECTIVE,
  292.  
  293.         GEN7_WM_KERNEL_VIDEO_PLANAR,
  294.         GEN7_WM_KERNEL_VIDEO_PACKED,
  295.         GEN7_KERNEL_COUNT
  296. };
  297.  
  298.  
  299. struct sna_static_stream {
  300.         uint32_t size, used;
  301.         uint8_t *data;
  302. };
  303.  
  304. int sna_static_stream_init(struct sna_static_stream *stream);
  305. uint32_t sna_static_stream_add(struct sna_static_stream *stream,
  306.                                const void *data, uint32_t len, uint32_t align);
  307. void *sna_static_stream_map(struct sna_static_stream *stream,
  308.                             uint32_t len, uint32_t align);
  309. uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream,
  310.                                     void *ptr);
  311. struct kgem_bo *sna_static_stream_fini(struct sna *sna,
  312.                                        struct sna_static_stream *stream);
  313.  
  314. /*
  315. struct kgem_bo *
  316. sna_render_get_solid(struct sna *sna,
  317.                      uint32_t color);
  318.  
  319. void
  320. sna_render_flush_solid(struct sna *sna);
  321.  
  322. struct kgem_bo *
  323. sna_render_get_gradient(struct sna *sna,
  324.                         PictGradient *pattern);
  325.  
  326. uint32_t sna_rgba_for_color(uint32_t color, int depth);
  327. Bool sna_picture_is_solid(PicturePtr picture, uint32_t *color);
  328. */
  329. void no_render_init(struct sna *sna);
  330.  
  331. Bool gen2_render_init(struct sna *sna);
  332. Bool gen3_render_init(struct sna *sna);
  333. Bool gen4_render_init(struct sna *sna);
  334. Bool gen5_render_init(struct sna *sna);
  335. Bool gen6_render_init(struct sna *sna);
  336. Bool gen7_render_init(struct sna *sna);
  337. /*
  338. Bool sna_tiling_composite(uint32_t op,
  339.                           PicturePtr src,
  340.                           PicturePtr mask,
  341.                           PicturePtr dst,
  342.                           int16_t src_x, int16_t src_y,
  343.                           int16_t mask_x, int16_t mask_y,
  344.                           int16_t dst_x, int16_t dst_y,
  345.                           int16_t width, int16_t height,
  346.                           struct sna_composite_op *tmp);
  347. Bool sna_tiling_fill_boxes(struct sna *sna,
  348.                            CARD8 op,
  349.                            PictFormat format,
  350.                            const xRenderColor *color,
  351.                            PixmapPtr dst, struct kgem_bo *dst_bo,
  352.                            const BoxRec *box, int n);
  353.  
  354. Bool sna_tiling_copy_boxes(struct sna *sna, uint8_t alu,
  355.                            PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
  356.                            PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
  357.                            const BoxRec *box, int n);
  358.  
  359. Bool sna_tiling_blt_copy_boxes(struct sna *sna, uint8_t alu,
  360.                                struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
  361.                                struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
  362.                                int bpp, const BoxRec *box, int nbox);
  363.  
  364. Bool sna_blt_composite(struct sna *sna,
  365.                        uint32_t op,
  366.                        PicturePtr src,
  367.                        PicturePtr dst,
  368.                        int16_t src_x, int16_t src_y,
  369.                        int16_t dst_x, int16_t dst_y,
  370.                        int16_t width, int16_t height,
  371.                        struct sna_composite_op *tmp);
  372.  
  373. bool sna_blt_fill(struct sna *sna, uint8_t alu,
  374.                   struct kgem_bo *bo,
  375.                   int bpp,
  376.                   uint32_t pixel,
  377.                   struct sna_fill_op *fill);
  378.  
  379. bool sna_blt_copy(struct sna *sna, uint8_t alu,
  380.                   struct kgem_bo *src,
  381.                   struct kgem_bo *dst,
  382.                   int bpp,
  383.                   struct sna_copy_op *copy);
  384.  
  385. Bool sna_blt_fill_boxes(struct sna *sna, uint8_t alu,
  386.                         struct kgem_bo *bo,
  387.                         int bpp,
  388.                         uint32_t pixel,
  389.                         const BoxRec *box, int n);
  390.  
  391. Bool sna_blt_copy_boxes(struct sna *sna, uint8_t alu,
  392.                         struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
  393.                         struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
  394.                         int bpp,
  395.                         const BoxRec *box, int n);
  396. Bool sna_blt_copy_boxes_fallback(struct sna *sna, uint8_t alu,
  397.                                  PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
  398.                                  PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
  399.                                  const BoxRec *box, int nbox);
  400.  
  401. Bool _sna_get_pixel_from_rgba(uint32_t *pixel,
  402.                              uint16_t red,
  403.                              uint16_t green,
  404.                              uint16_t blue,
  405.                              uint16_t alpha,
  406.                              uint32_t format);
  407.  
  408. static inline Bool
  409. sna_get_pixel_from_rgba(uint32_t * pixel,
  410.                         uint16_t red,
  411.                         uint16_t green,
  412.                         uint16_t blue,
  413.                         uint16_t alpha,
  414.                         uint32_t format)
  415. {
  416.         switch (format) {
  417.         case PICT_x8r8g8b8:
  418.                 alpha = 0xffff;
  419.         case PICT_a8r8g8b8:
  420.                 *pixel = ((alpha >> 8 << 24) |
  421.                           (red >> 8 << 16) |
  422.                           (green & 0xff00) |
  423.                           (blue >> 8));
  424.                 return TRUE;
  425.         case PICT_a8:
  426.                 *pixel = alpha >> 8;
  427.                 return TRUE;
  428.         }
  429.  
  430.         return _sna_get_pixel_from_rgba(pixel, red, green, blue, alpha, format);
  431. }
  432.  
  433. int
  434. sna_render_pixmap_bo(struct sna *sna,
  435.                      struct sna_composite_channel *channel,
  436.                      PixmapPtr pixmap,
  437.                      int16_t x, int16_t y,
  438.                      int16_t w, int16_t h,
  439.                      int16_t dst_x, int16_t dst_y);
  440.  
  441. bool
  442. sna_render_pixmap_partial(struct sna *sna,
  443.                           PixmapPtr pixmap,
  444.                           struct kgem_bo *bo,
  445.                           struct sna_composite_channel *channel,
  446.                           int16_t x, int16_t y,
  447.                           int16_t w, int16_t h);
  448.  
  449. int
  450. sna_render_picture_extract(struct sna *sna,
  451.                            PicturePtr picture,
  452.                            struct sna_composite_channel *channel,
  453.                            int16_t x, int16_t y,
  454.                            int16_t w, int16_t h,
  455.                            int16_t dst_x, int16_t dst_y);
  456.  
  457. int
  458. sna_render_picture_fixup(struct sna *sna,
  459.                          PicturePtr picture,
  460.                          struct sna_composite_channel *channel,
  461.                          int16_t x, int16_t y,
  462.                          int16_t w, int16_t h,
  463.                          int16_t dst_x, int16_t dst_y);
  464.  
  465. int
  466. sna_render_picture_convert(struct sna *sna,
  467.                            PicturePtr picture,
  468.                            struct sna_composite_channel *channel,
  469.                            PixmapPtr pixmap,
  470.                            int16_t x, int16_t y,
  471.                            int16_t w, int16_t h,
  472.                            int16_t dst_x, int16_t dst_y);
  473.  
  474. inline static void sna_render_composite_redirect_init(struct sna_composite_op *op)
  475. {
  476.         struct sna_composite_redirect *t = &op->redirect;
  477.         t->real_bo = NULL;
  478.         t->damage = NULL;
  479. }
  480.  
  481. Bool
  482. sna_render_composite_redirect(struct sna *sna,
  483.                               struct sna_composite_op *op,
  484.                               int x, int y, int width, int height);
  485.  
  486. void
  487. sna_render_composite_redirect_done(struct sna *sna,
  488.                                    const struct sna_composite_op *op);
  489.  
  490. bool
  491. sna_composite_mask_is_opaque(PicturePtr mask);
  492. */
  493.  
  494. #endif /* SNA_RENDER_H */
  495.