Home | History | Annotate | Line # | Download | only in glamor
      1 /*
      2  * Copyright  2008 Intel Corporation
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the "Software"),
      6  * to deal in the Software without restriction, including without limitation
      7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  * and/or sell copies of the Software, and to permit persons to whom the
      9  * Software is furnished to do so, subject to the following conditions:
     10  *
     11  * The above copyright notice and this permission notice (including the next
     12  * paragraph) shall be included in all copies or substantial portions of the
     13  * Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     21  * IN THE SOFTWARE.
     22  *
     23  * Authors:
     24  *    Eric Anholt <eric (at) anholt.net>
     25  *
     26  */
     27 #ifndef GLAMOR_PRIV_H
     28 #define GLAMOR_PRIV_H
     29 
     30 #include "dix-config.h"
     31 
     32 #include "glamor.h"
     33 #include "xvdix.h"
     34 
     35 #if XSYNC
     36 #include "misyncshm.h"
     37 #include "misyncstr.h"
     38 #endif
     39 
     40 #include <epoxy/gl.h>
     41 #ifdef GLAMOR_HAS_GBM
     42 #define MESA_EGL_NO_X11_HEADERS
     43 #define EGL_NO_X11
     44 #include <epoxy/egl.h>
     45 #endif
     46 
     47 #define GLAMOR_DEFAULT_PRECISION  \
     48     "#ifdef GL_ES\n"              \
     49     "precision mediump float;\n"  \
     50     "#endif\n"
     51 
     52 #define GLAMOR_DEFAULT_POINT_SIZE  \
     53     "#ifdef GL_ES\n"              \
     54     "       gl_PointSize = 1.0;\n"  \
     55     "#endif\n"
     56 
     57 #define GLAMOR_COMPAT_DEFINES_VS  \
     58     "#define in attribute\n" \
     59     "#define out varying\n"  \
     60 
     61 #define GLAMOR_COMPAT_DEFINES_FS  \
     62     "#if __VERSION__ < 130\n" \
     63     "#define in varying\n"  \
     64     "#define frag_color gl_FragColor\n" \
     65     "#define texture texture2D\n" \
     66     "#else\n" \
     67     "out vec4 frag_color;\n" \
     68     "#endif\n"
     69 
     70 #include "glyphstr.h"
     71 
     72 #include "glamor_debug.h"
     73 #include "glamor_context.h"
     74 #include "glamor_program.h"
     75 
     76 #include <list.h>
     77 
     78 struct glamor_pixmap_private;
     79 
     80 typedef struct glamor_composite_shader {
     81     GLuint prog;
     82     GLint dest_to_dest_uniform_location;
     83     GLint dest_to_source_uniform_location;
     84     GLint dest_to_mask_uniform_location;
     85     GLint source_uniform_location;
     86     GLint mask_uniform_location;
     87     GLint source_wh;
     88     GLint mask_wh;
     89     GLint source_repeat_mode;
     90     GLint mask_repeat_mode;
     91     union {
     92         float source_solid_color[4];
     93         struct {
     94             PixmapPtr source_pixmap;
     95             PicturePtr source;
     96         };
     97     };
     98 
     99     union {
    100         float mask_solid_color[4];
    101         struct {
    102             PixmapPtr mask_pixmap;
    103             PicturePtr mask;
    104         };
    105     };
    106 } glamor_composite_shader;
    107 
    108 enum ca_state {
    109     CA_NONE,
    110     CA_TWO_PASS,
    111     CA_DUAL_BLEND,
    112 };
    113 
    114 enum shader_source {
    115     SHADER_SOURCE_SOLID,
    116     SHADER_SOURCE_TEXTURE,
    117     SHADER_SOURCE_TEXTURE_ALPHA,
    118     SHADER_SOURCE_COUNT,
    119 };
    120 
    121 enum shader_mask {
    122     SHADER_MASK_NONE,
    123     SHADER_MASK_SOLID,
    124     SHADER_MASK_TEXTURE,
    125     SHADER_MASK_TEXTURE_ALPHA,
    126     SHADER_MASK_COUNT,
    127 };
    128 
    129 enum shader_dest_swizzle {
    130     SHADER_DEST_SWIZZLE_DEFAULT,
    131     SHADER_DEST_SWIZZLE_ALPHA_TO_RED,
    132     SHADER_DEST_SWIZZLE_COUNT,
    133 };
    134 
    135 struct shader_key {
    136     enum shader_source source;
    137     enum shader_mask mask;
    138     glamor_program_alpha in;
    139     enum shader_dest_swizzle dest_swizzle;
    140 };
    141 
    142 struct blendinfo {
    143     Bool dest_alpha;
    144     Bool source_alpha;
    145     GLenum source_blend;
    146     GLenum dest_blend;
    147 };
    148 
    149 typedef struct {
    150     INT16 x_src;
    151     INT16 y_src;
    152     INT16 x_mask;
    153     INT16 y_mask;
    154     INT16 x_dst;
    155     INT16 y_dst;
    156     INT16 width;
    157     INT16 height;
    158 } glamor_composite_rect_t;
    159 
    160 enum glamor_vertex_type {
    161     GLAMOR_VERTEX_POS,
    162     GLAMOR_VERTEX_SOURCE,
    163     GLAMOR_VERTEX_MASK
    164 };
    165 
    166 enum gradient_shader {
    167     SHADER_GRADIENT_LINEAR,
    168     SHADER_GRADIENT_RADIAL,
    169     SHADER_GRADIENT_CONICAL,
    170     SHADER_GRADIENT_COUNT,
    171 };
    172 
    173 struct glamor_screen_private;
    174 struct glamor_pixmap_private;
    175 
    176 #define GLAMOR_COMPOSITE_VBO_VERT_CNT (64*1024)
    177 
    178 struct glamor_format {
    179     /** X Server's "depth" value */
    180     int depth;
    181     /** GL internalformat for creating textures of this type */
    182     GLenum internalformat;
    183     /** GL format transferring pixels in/out of textures of this type. */
    184     GLenum format;
    185     /** GL type transferring pixels in/out of textures of this type. */
    186     GLenum type;
    187     /* Render PICT_* matching GL's channel layout for pixels
    188      * transferred using format/type.
    189      */
    190     CARD32 render_format;
    191     /**
    192      * Whether rendering is supported in GL at all (i.e. without pixel data conversion
    193      * just before upload)
    194      */
    195     Bool rendering_supported;
    196     /**
    197      * Whether image with this depth is framebuffer-complete in GL.
    198      * This flag is set on GL ES when rendering is supported without
    199      * conversion, but reading from framebuffer can bring some caveats
    200      * like different format combination or incomplete framebuffer.
    201      */
    202     Bool texture_only;
    203 };
    204 
    205 struct glamor_saved_procs {
    206     CloseScreenProcPtr close_screen;
    207     CreateGCProcPtr create_gc;
    208     CreatePixmapProcPtr create_pixmap;
    209     DestroyPixmapProcPtr destroy_pixmap;
    210     GetSpansProcPtr get_spans;
    211     GetImageProcPtr get_image;
    212     CompositeProcPtr composite;
    213     CompositeRectsProcPtr composite_rects;
    214     TrapezoidsProcPtr trapezoids;
    215     GlyphsProcPtr glyphs;
    216     ChangeWindowAttributesProcPtr change_window_attributes;
    217     CopyWindowProcPtr copy_window;
    218     BitmapToRegionProcPtr bitmap_to_region;
    219     TrianglesProcPtr triangles;
    220     AddTrapsProcPtr addtraps;
    221 #if XSYNC
    222     SyncScreenFuncsRec sync_screen_funcs;
    223 #endif
    224     ScreenBlockHandlerProcPtr block_handler;
    225 };
    226 
    227 typedef struct glamor_screen_private {
    228     Bool is_gles;
    229     int glsl_version;
    230     Bool has_pack_invert;
    231     Bool has_fbo_blit;
    232     Bool has_map_buffer_range;
    233     Bool has_buffer_storage;
    234     Bool has_khr_debug;
    235     Bool has_mesa_tile_raster_order;
    236     Bool has_nv_texture_barrier;
    237     Bool has_pack_subimage;
    238     Bool has_unpack_subimage;
    239     Bool has_rw_pbo;
    240     Bool use_quads;
    241     Bool has_dual_blend;
    242     Bool has_clear_texture;
    243     Bool has_texture_swizzle;
    244     Bool has_rg;
    245     Bool is_core_profile;
    246     Bool can_copyplane;
    247     Bool use_gpu_shader4;
    248     int max_fbo_size;
    249     Bool enable_gradient_shader;
    250 
    251     /**
    252      * Stores information about supported formats. Note, that this list contains all
    253      * supported pixel formats, including these that are not supported on GL side
    254      * directly, but are converted to another format instead.
    255      */
    256     struct glamor_format formats[33];
    257     struct glamor_format cbcr_format;
    258 
    259     /* glamor point shader */
    260     glamor_program point_prog;
    261 
    262     /* glamor spans shaders */
    263     glamor_program_fill fill_spans_program;
    264 
    265     /* glamor rect shaders */
    266     glamor_program_fill poly_fill_rect_program;
    267 
    268     /* glamor glyphblt shaders */
    269     glamor_program_fill poly_glyph_blt_progs;
    270 
    271     /* glamor text shaders */
    272     glamor_program_fill poly_text_progs;
    273     glamor_program      te_text_prog;
    274     glamor_program      image_text_prog;
    275 
    276     /* glamor copy shaders */
    277     glamor_program      copy_area_prog;
    278     glamor_program      copy_plane_prog;
    279 
    280     /* glamor line shader */
    281     glamor_program_fill poly_line_program;
    282 
    283     /* glamor segment shaders */
    284     glamor_program_fill poly_segment_program;
    285 
    286     /*  glamor dash line shader */
    287     glamor_program_fill on_off_dash_line_progs;
    288     glamor_program      double_dash_line_prog;
    289 
    290     /* glamor composite_glyphs shaders */
    291     glamor_program_render       glyphs_program;
    292     struct glamor_glyph_atlas   *glyph_atlas_a;
    293     struct glamor_glyph_atlas   *glyph_atlas_argb;
    294     int                         glyph_atlas_dim;
    295     int                         glyph_max_dim;
    296     char                        *glyph_defines;
    297 
    298     /** Vertex buffer for all GPU rendering. */
    299     GLuint vao;
    300     GLuint vbo;
    301     /** Next offset within the VBO that glamor_get_vbo_space() will use. */
    302     int vbo_offset;
    303     int vbo_size;
    304     Bool vbo_mapped;
    305     /**
    306      * Pointer to glamor_get_vbo_space()'s current VBO mapping.
    307      *
    308      * Note that this is not necessarily equal to the pointer returned
    309      * by glamor_get_vbo_space(), so it can't be used in place of that.
    310      */
    311     char *vb;
    312     int vb_stride;
    313 
    314     /** Cached index buffer for translating GL_QUADS to triangles. */
    315     GLuint ib;
    316     /** Index buffer type: GL_UNSIGNED_SHORT or GL_UNSIGNED_INT */
    317     GLenum ib_type;
    318     /** Number of quads the index buffer has indices for. */
    319     unsigned ib_size;
    320 
    321     Bool has_source_coords, has_mask_coords;
    322     int render_nr_quads;
    323     glamor_composite_shader composite_shader[SHADER_SOURCE_COUNT]
    324         [SHADER_MASK_COUNT]
    325         [glamor_program_alpha_count]
    326         [SHADER_DEST_SWIZZLE_COUNT];
    327 
    328     /* glamor gradient, 0 for small nstops, 1 for
    329        large nstops and 2 for dynamic generate. */
    330     GLint gradient_prog[SHADER_GRADIENT_COUNT][3];
    331     int linear_max_nstops;
    332     int radial_max_nstops;
    333 
    334     struct glamor_saved_procs saved_procs;
    335     GetDrawableModifiersFuncPtr get_drawable_modifiers;
    336     int flags;
    337     ScreenPtr screen;
    338     int dri3_enabled;
    339 
    340     Bool suppress_gl_out_of_memory_logging;
    341     Bool logged_any_fbo_allocation_failure;
    342     Bool logged_any_pbo_allocation_failure;
    343 
    344     /* xv */
    345     glamor_program xv_prog;
    346 
    347     struct glamor_context ctx;
    348 } glamor_screen_private;
    349 
    350 typedef enum glamor_access {
    351     GLAMOR_ACCESS_RO,
    352     GLAMOR_ACCESS_RW,
    353 } glamor_access_t;
    354 
    355 enum glamor_fbo_state {
    356     /** There is no storage attached to the pixmap. */
    357     GLAMOR_FBO_UNATTACHED,
    358     /**
    359      * The pixmap has FBO storage attached, but devPrivate.ptr doesn't
    360      * point at anything.
    361      */
    362     GLAMOR_FBO_NORMAL,
    363 };
    364 
    365 typedef struct glamor_pixmap_fbo {
    366     GLuint tex; /**< GL texture name */
    367     GLuint fb; /**< GL FBO name */
    368     int width; /**< width in pixels */
    369     int height; /**< height in pixels */
    370     Bool is_red;
    371 } glamor_pixmap_fbo;
    372 
    373 typedef struct glamor_pixmap_clipped_regions {
    374     int block_idx;
    375     RegionPtr region;
    376 } glamor_pixmap_clipped_regions;
    377 
    378 typedef struct glamor_pixmap_private {
    379     glamor_pixmap_type_t type;
    380     enum glamor_fbo_state gl_fbo;
    381     /**
    382      * If devPrivate.ptr is non-NULL (meaning we're within
    383      * glamor_prepare_access), determies whether we should re-upload
    384      * that data on glamor_finish_access().
    385      */
    386     glamor_access_t map_access;
    387     glamor_pixmap_fbo *fbo;
    388     /** current fbo's coords in the whole pixmap. */
    389     BoxRec box;
    390     GLuint pbo;
    391     RegionRec prepare_region;
    392     Bool prepared;
    393 #ifdef GLAMOR_HAS_GBM
    394     EGLImageKHR image;
    395     Bool used_modifiers;
    396 #endif
    397     /** block width of this large pixmap. */
    398     int block_w;
    399     /** block height of this large pixmap. */
    400     int block_h;
    401 
    402     /** block_wcnt: block count in one block row. */
    403     int block_wcnt;
    404     /** block_hcnt: block count in one block column. */
    405     int block_hcnt;
    406 
    407     /**
    408      * The list of boxes for the bounds of the FBOs making up the
    409      * pixmap.
    410      *
    411      * For a 2048x2048 pixmap with GL FBO size limits of 1024x1024:
    412      *
    413      * ******************
    414      * *  fbo0 * fbo1   *
    415      * *       *        *
    416      * ******************
    417      * *  fbo2 * fbo3   *
    418      * *       *        *
    419      * ******************
    420      *
    421      * box[0] = {0,0,1024,1024}
    422      * box[1] = {1024,0,2048,2048}
    423      * ...
    424      */
    425     BoxPtr box_array;
    426 
    427     /**
    428      * Array of fbo structs containing the actual GL texture/fbo
    429      * names.
    430      */
    431     glamor_pixmap_fbo **fbo_array;
    432 
    433     Bool is_cbcr;
    434 } glamor_pixmap_private;
    435 
    436 extern DevPrivateKeyRec glamor_pixmap_private_key;
    437 
    438 static inline glamor_pixmap_private *
    439 glamor_get_pixmap_private(PixmapPtr pixmap)
    440 {
    441     if (pixmap == NULL)
    442         return NULL;
    443 
    444     return dixLookupPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
    445 }
    446 
    447 /*
    448  * Returns TRUE if pixmap has no image object
    449  */
    450 static inline Bool
    451 glamor_pixmap_drm_only(PixmapPtr pixmap)
    452 {
    453     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
    454 
    455     return priv->type == GLAMOR_DRM_ONLY;
    456 }
    457 
    458 /*
    459  * Returns TRUE if pixmap is plain memory (not a GL object at all)
    460  */
    461 static inline Bool
    462 glamor_pixmap_is_memory(PixmapPtr pixmap)
    463 {
    464     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
    465 
    466     return priv->type == GLAMOR_MEMORY;
    467 }
    468 
    469 /*
    470  * Returns TRUE if pixmap requires multiple textures to hold it
    471  */
    472 static inline Bool
    473 glamor_pixmap_priv_is_large(glamor_pixmap_private *priv)
    474 {
    475     return priv->block_wcnt > 1 || priv->block_hcnt > 1;
    476 }
    477 
    478 static inline Bool
    479 glamor_pixmap_priv_is_small(glamor_pixmap_private *priv)
    480 {
    481     return priv->block_wcnt <= 1 && priv->block_hcnt <= 1;
    482 }
    483 
    484 static inline Bool
    485 glamor_pixmap_is_large(PixmapPtr pixmap)
    486 {
    487     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
    488 
    489     return glamor_pixmap_priv_is_large(priv);
    490 }
    491 /*
    492  * Returns TRUE if pixmap has an FBO
    493  */
    494 static inline Bool
    495 glamor_pixmap_has_fbo(PixmapPtr pixmap)
    496 {
    497     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
    498 
    499     return priv->gl_fbo == GLAMOR_FBO_NORMAL;
    500 }
    501 
    502 static inline void
    503 glamor_set_pixmap_fbo_current(glamor_pixmap_private *priv, int idx)
    504 {
    505     if (glamor_pixmap_priv_is_large(priv)) {
    506         priv->fbo = priv->fbo_array[idx];
    507         priv->box = priv->box_array[idx];
    508     }
    509 }
    510 
    511 static inline glamor_pixmap_fbo *
    512 glamor_pixmap_fbo_at(glamor_pixmap_private *priv, int box)
    513 {
    514     assert(box < priv->block_wcnt * priv->block_hcnt);
    515     return priv->fbo_array[box];
    516 }
    517 
    518 static inline BoxPtr
    519 glamor_pixmap_box_at(glamor_pixmap_private *priv, int box)
    520 {
    521     assert(box < priv->block_wcnt * priv->block_hcnt);
    522     return &priv->box_array[box];
    523 }
    524 
    525 static inline int
    526 glamor_pixmap_wcnt(glamor_pixmap_private *priv)
    527 {
    528     return priv->block_wcnt;
    529 }
    530 
    531 static inline int
    532 glamor_pixmap_hcnt(glamor_pixmap_private *priv)
    533 {
    534     return priv->block_hcnt;
    535 }
    536 
    537 #define glamor_pixmap_loop(priv, box_index)                            \
    538     for (box_index = 0; box_index < glamor_pixmap_hcnt(priv) *         \
    539              glamor_pixmap_wcnt(priv); box_index++)                    \
    540 
    541 /* GC private structure. Currently holds only any computed dash pixmap */
    542 
    543 typedef struct {
    544     PixmapPtr   dash;
    545     PixmapPtr   stipple;
    546     DamagePtr   stipple_damage;
    547 } glamor_gc_private;
    548 
    549 extern DevPrivateKeyRec glamor_gc_private_key;
    550 extern DevPrivateKeyRec glamor_screen_private_key;
    551 
    552 extern glamor_screen_private *
    553 glamor_get_screen_private(ScreenPtr screen);
    554 
    555 extern void
    556 glamor_set_screen_private(ScreenPtr screen, glamor_screen_private *priv);
    557 
    558 static inline glamor_gc_private *
    559 glamor_get_gc_private(GCPtr gc)
    560 {
    561     return dixLookupPrivate(&gc->devPrivates, &glamor_gc_private_key);
    562 }
    563 
    564 /**
    565  * Returns TRUE if the given planemask covers all the significant bits in the
    566  * pixel values for pDrawable.
    567  */
    568 static inline Bool
    569 glamor_pm_is_solid(int depth, unsigned long planemask)
    570 {
    571     return (planemask & FbFullMask(depth)) ==
    572         FbFullMask(depth);
    573 }
    574 
    575 extern int glamor_debug_level;
    576 
    577 /* glamor.c */
    578 PixmapPtr glamor_get_drawable_pixmap(DrawablePtr drawable);
    579 
    580 glamor_pixmap_fbo *glamor_pixmap_detach_fbo(glamor_pixmap_private *
    581                                             pixmap_priv);
    582 void glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo);
    583 glamor_pixmap_fbo *glamor_create_fbo_from_tex(glamor_screen_private *
    584                                               glamor_priv, PixmapPtr pixmap,
    585                                               int w, int h, GLint tex,
    586                                               int flag);
    587 glamor_pixmap_fbo *glamor_create_fbo(glamor_screen_private *glamor_priv,
    588                                      PixmapPtr pixmap, int w, int h, int flag);
    589 void glamor_destroy_fbo(glamor_screen_private *glamor_priv,
    590                         glamor_pixmap_fbo *fbo);
    591 void glamor_pixmap_destroy_fbo(PixmapPtr pixmap);
    592 Bool glamor_pixmap_fbo_fixup(ScreenPtr screen, PixmapPtr pixmap);
    593 void glamor_pixmap_clear_fbo(glamor_screen_private *glamor_priv, glamor_pixmap_fbo *fbo,
    594                              const struct glamor_format *pixmap_format);
    595 
    596 const struct glamor_format *glamor_format_for_pixmap(PixmapPtr pixmap);
    597 
    598 /* Return whether 'picture' is alpha-only */
    599 static inline Bool glamor_picture_is_alpha(PicturePtr picture)
    600 {
    601     return picture->format == PICT_a1 || picture->format == PICT_a8;
    602 }
    603 
    604 /* Return whether 'picture' is storing alpha bits in the red channel */
    605 static inline Bool
    606 glamor_picture_red_is_alpha(PicturePtr picture)
    607 {
    608     /* True when the picture is alpha only and the screen is using GL_RED for alpha pictures */
    609     return glamor_picture_is_alpha(picture) &&
    610         glamor_get_screen_private(picture->pDrawable->pScreen)->formats[8].format == GL_RED;
    611 }
    612 
    613 void glamor_bind_texture(glamor_screen_private *glamor_priv,
    614                          GLenum texture,
    615                          glamor_pixmap_fbo *fbo,
    616                          Bool destination_red);
    617 
    618 glamor_pixmap_fbo *glamor_create_fbo_array(glamor_screen_private *glamor_priv,
    619                                            PixmapPtr pixmap,
    620                                            int flag, int block_w, int block_h,
    621                                            glamor_pixmap_private *);
    622 
    623 void glamor_gldrawarrays_quads_using_indices(glamor_screen_private *glamor_priv,
    624                                              unsigned count);
    625 
    626 /* glamor_core.c */
    627 Bool glamor_get_drawable_location(const DrawablePtr drawable);
    628 void glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap,
    629                                 int *x, int *y);
    630 GLint glamor_compile_glsl_prog(GLenum type, const char *source);
    631 Bool glamor_link_glsl_prog(ScreenPtr screen, GLint prog,
    632                            const char *format, ...) _X_ATTRIBUTE_PRINTF(3,4);
    633 void glamor_get_color_4f_from_pixel(PixmapPtr pixmap,
    634                                     unsigned long fg_pixel, GLfloat *color);
    635 
    636 int glamor_set_destination_pixmap(PixmapPtr pixmap);
    637 int glamor_set_destination_pixmap_priv(glamor_screen_private *glamor_priv, PixmapPtr pixmap, glamor_pixmap_private *pixmap_priv);
    638 void glamor_set_destination_pixmap_fbo(glamor_screen_private *glamor_priv, glamor_pixmap_fbo *, int, int, int, int);
    639 
    640 /* nc means no check. caller must ensure this pixmap has valid fbo.
    641  * usually use the GLAMOR_PIXMAP_PRIV_HAS_FBO firstly.
    642  * */
    643 void glamor_set_destination_pixmap_priv_nc(glamor_screen_private *glamor_priv, PixmapPtr pixmap, glamor_pixmap_private *pixmap_priv);
    644 
    645 Bool glamor_set_alu(ScreenPtr screen, unsigned char alu);
    646 Bool glamor_set_planemask(int depth, unsigned long planemask);
    647 RegionPtr glamor_bitmap_to_region(PixmapPtr pixmap);
    648 
    649 void
    650 glamor_track_stipple(GCPtr gc);
    651 
    652 /* glamor_render.c */
    653 Bool glamor_composite_clipped_region(CARD8 op,
    654                                      PicturePtr source,
    655                                      PicturePtr mask,
    656                                      PicturePtr dest,
    657                                      PixmapPtr source_pixmap,
    658                                      PixmapPtr mask_pixmap,
    659                                      PixmapPtr dest_pixmap,
    660                                      RegionPtr region,
    661                                      int x_source,
    662                                      int y_source,
    663                                      int x_mask, int y_mask,
    664                                      int x_dest, int y_dest);
    665 
    666 void glamor_composite(CARD8 op,
    667                       PicturePtr pSrc,
    668                       PicturePtr pMask,
    669                       PicturePtr pDst,
    670                       INT16 xSrc,
    671                       INT16 ySrc,
    672                       INT16 xMask,
    673                       INT16 yMask,
    674                       INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
    675 
    676 void glamor_composite_rects(CARD8 op,
    677                             PicturePtr pDst,
    678                             xRenderColor *color, int nRect, xRectangle *rects);
    679 
    680 /* glamor_trapezoid.c */
    681 void glamor_trapezoids(CARD8 op,
    682                        PicturePtr src, PicturePtr dst,
    683                        PictFormatPtr mask_format, INT16 x_src, INT16 y_src,
    684                        int ntrap, xTrapezoid *traps);
    685 
    686 /* glamor_gradient.c */
    687 Bool glamor_init_gradient_shader(ScreenPtr screen);
    688 PicturePtr glamor_generate_linear_gradient_picture(ScreenPtr screen,
    689                                                    PicturePtr src_picture,
    690                                                    int x_source, int y_source,
    691                                                    int width, int height,
    692                                                    PictFormatShort format);
    693 PicturePtr glamor_generate_radial_gradient_picture(ScreenPtr screen,
    694                                                    PicturePtr src_picture,
    695                                                    int x_source, int y_source,
    696                                                    int width, int height,
    697                                                    PictFormatShort format);
    698 
    699 /* glamor_triangles.c */
    700 void glamor_triangles(CARD8 op,
    701                       PicturePtr pSrc,
    702                       PicturePtr pDst,
    703                       PictFormatPtr maskFormat,
    704                       INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris);
    705 
    706 /* glamor_pixmap.c */
    707 
    708 void glamor_pixmap_init(ScreenPtr screen);
    709 void glamor_pixmap_fini(ScreenPtr screen);
    710 
    711 /* glamor_vbo.c */
    712 
    713 void glamor_init_vbo(ScreenPtr screen);
    714 void glamor_fini_vbo(ScreenPtr screen);
    715 
    716 void *
    717 glamor_get_vbo_space(ScreenPtr screen, unsigned size, char **vbo_offset);
    718 
    719 void
    720 glamor_put_vbo_space(ScreenPtr screen);
    721 
    722 /**
    723  * According to the flag,
    724  * if the flag is GLAMOR_CREATE_FBO_NO_FBO then just ensure
    725  * the fbo has a valid texture. Otherwise, it will ensure
    726  * the fbo has valid texture and attach to a valid fb.
    727  * If the fbo already has a valid glfbo then do nothing.
    728  */
    729 Bool glamor_pixmap_ensure_fbo(PixmapPtr pixmap, int flag);
    730 
    731 glamor_pixmap_clipped_regions *
    732 glamor_compute_clipped_regions(PixmapPtr pixmap,
    733                                RegionPtr region, int *clipped_nbox,
    734                                int repeat_type, int reverse,
    735                                int upsidedown);
    736 
    737 glamor_pixmap_clipped_regions *
    738 glamor_compute_clipped_regions_ext(PixmapPtr pixmap,
    739                                    RegionPtr region, int *n_region,
    740                                    int inner_block_w, int inner_block_h,
    741                                    int reverse, int upsidedown);
    742 
    743 Bool glamor_composite_largepixmap_region(CARD8 op,
    744                                          PicturePtr source,
    745                                          PicturePtr mask,
    746                                          PicturePtr dest,
    747                                          PixmapPtr source_pixmap,
    748                                          PixmapPtr mask_pixmap,
    749                                          PixmapPtr dest_pixmap,
    750                                          RegionPtr region, Bool force_clip,
    751                                          INT16 x_source,
    752                                          INT16 y_source,
    753                                          INT16 x_mask,
    754                                          INT16 y_mask,
    755                                          INT16 x_dest, INT16 y_dest,
    756                                          CARD16 width, CARD16 height);
    757 
    758 /**
    759  * Upload a picture to gl texture. Similar to the
    760  * glamor_upload_pixmap_to_texture. Used in rendering.
    761  **/
    762 Bool glamor_upload_picture_to_texture(PicturePtr picture);
    763 
    764 void glamor_add_traps(PicturePtr pPicture,
    765                       INT16 x_off, INT16 y_off, int ntrap, xTrap *traps);
    766 
    767 /* glamor_text.c */
    768 int glamor_poly_text8(DrawablePtr pDrawable, GCPtr pGC,
    769                       int x, int y, int count, char *chars);
    770 
    771 int glamor_poly_text16(DrawablePtr pDrawable, GCPtr pGC,
    772                        int x, int y, int count, unsigned short *chars);
    773 
    774 void glamor_image_text8(DrawablePtr pDrawable, GCPtr pGC,
    775                         int x, int y, int count, char *chars);
    776 
    777 void glamor_image_text16(DrawablePtr pDrawable, GCPtr pGC,
    778                          int x, int y, int count, unsigned short *chars);
    779 
    780 /* glamor_spans.c */
    781 void
    782 glamor_fill_spans(DrawablePtr drawable,
    783                   GCPtr gc,
    784                   int n, DDXPointPtr points, int *widths, int sorted);
    785 
    786 void
    787 glamor_get_spans(DrawablePtr drawable, int wmax,
    788                  DDXPointPtr points, int *widths, int count, char *dst);
    789 
    790 void
    791 glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
    792                  DDXPointPtr points, int *widths, int numPoints, int sorted);
    793 
    794 /* glamor_rects.c */
    795 void
    796 glamor_poly_fill_rect(DrawablePtr drawable,
    797                       GCPtr gc, int nrect, xRectangle *prect);
    798 
    799 /* glamor_image.c */
    800 void
    801 glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
    802                  int w, int h, int leftPad, int format, char *bits);
    803 
    804 void
    805 glamor_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
    806                  unsigned int format, unsigned long planeMask, char *d);
    807 
    808 /* glamor_dash.c */
    809 Bool
    810 glamor_poly_lines_dash_gl(DrawablePtr drawable, GCPtr gc,
    811                           int mode, int n, DDXPointPtr points);
    812 
    813 Bool
    814 glamor_poly_segment_dash_gl(DrawablePtr drawable, GCPtr gc,
    815                             int nseg, xSegment *segs);
    816 
    817 /* glamor_lines.c */
    818 void
    819 glamor_poly_lines(DrawablePtr drawable, GCPtr gc,
    820                   int mode, int n, DDXPointPtr points);
    821 
    822 /*  glamor_segs.c */
    823 void
    824 glamor_poly_segment(DrawablePtr drawable, GCPtr gc,
    825                     int nseg, xSegment *segs);
    826 
    827 /* glamor_copy.c */
    828 void
    829 glamor_copy(DrawablePtr src,
    830             DrawablePtr dst,
    831             GCPtr gc,
    832             BoxPtr box,
    833             int nbox,
    834             int dx,
    835             int dy,
    836             Bool reverse,
    837             Bool upsidedown,
    838             Pixel bitplane,
    839             void *closure);
    840 
    841 RegionPtr
    842 glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
    843                  int srcx, int srcy, int width, int height, int dstx, int dsty);
    844 
    845 RegionPtr
    846 glamor_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
    847                   int srcx, int srcy, int width, int height, int dstx, int dsty,
    848                   unsigned long bitplane);
    849 
    850 /* glamor_glyphblt.c */
    851 void glamor_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
    852                             int x, int y, unsigned int nglyph,
    853                             CharInfoPtr *ppci, void *pglyphBase);
    854 
    855 void glamor_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
    856                            int x, int y, unsigned int nglyph,
    857                            CharInfoPtr *ppci, void *pglyphBase);
    858 
    859 void glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
    860                         DrawablePtr pDrawable, int w, int h, int x, int y);
    861 
    862 void glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
    863                        DDXPointPtr ppt);
    864 
    865 void glamor_composite_rectangles(CARD8 op,
    866                                  PicturePtr dst,
    867                                  xRenderColor *color,
    868                                  int num_rects, xRectangle *rects);
    869 
    870 /* glamor_composite_glyphs.c */
    871 Bool
    872 glamor_composite_glyphs_init(ScreenPtr pScreen);
    873 
    874 void
    875 glamor_composite_glyphs_fini(ScreenPtr pScreen);
    876 
    877 void
    878 glamor_composite_glyphs(CARD8 op,
    879                         PicturePtr src,
    880                         PicturePtr dst,
    881                         PictFormatPtr mask_format,
    882                         INT16 x_src,
    883                         INT16 y_src, int nlist,
    884                         GlyphListPtr list, GlyphPtr *glyphs);
    885 
    886 /* glamor_sync.c */
    887 Bool
    888 glamor_sync_init(ScreenPtr screen);
    889 
    890 void
    891 glamor_sync_close(ScreenPtr screen);
    892 
    893 /* glamor_util.c */
    894 void
    895 glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
    896              unsigned long fg_pixel);
    897 
    898 void
    899 glamor_solid_boxes(PixmapPtr pixmap,
    900                    BoxPtr box, int nbox, unsigned long fg_pixel);
    901 
    902 
    903 /* glamor_xv */
    904 typedef struct {
    905     uint32_t transform_index;
    906     uint32_t gamma;             /* gamma value x 1000 */
    907     int brightness;
    908     int saturation;
    909     int hue;
    910     int contrast;
    911 
    912     DrawablePtr pDraw;
    913     PixmapPtr pPixmap;
    914     uint32_t src_pitch;
    915     uint8_t *src_addr;
    916     int src_w, src_h, dst_w, dst_h;
    917     int src_x, src_y, drw_x, drw_y;
    918     int w, h;
    919     RegionRec clip;
    920     PixmapPtr src_pix[3];       /* y, u, v for planar */
    921     int src_pix_w, src_pix_h;
    922     /* Port optimization */
    923     int prev_fmt;
    924     glamor_program xv_prog;
    925 } glamor_port_private;
    926 
    927 extern XvAttributeRec glamor_xv_attributes[];
    928 extern int glamor_xv_num_attributes;
    929 extern XvImageRec glamor_xv_images[];
    930 extern int glamor_xv_num_images;
    931 
    932 void glamor_xv_init_port(glamor_port_private *port_priv);
    933 void glamor_xv_stop_video(glamor_port_private *port_priv);
    934 int glamor_xv_set_port_attribute(glamor_port_private *port_priv,
    935                                  Atom attribute, INT32 value);
    936 int glamor_xv_get_port_attribute(glamor_port_private *port_priv,
    937                                  Atom attribute, INT32 *value);
    938 int glamor_xv_query_image_attributes(int id,
    939                                      unsigned short *w, unsigned short *h,
    940                                      int *pitches, int *offsets);
    941 int glamor_xv_put_image(glamor_port_private *port_priv,
    942                         DrawablePtr pDrawable,
    943                         short src_x, short src_y,
    944                         short drw_x, short drw_y,
    945                         short src_w, short src_h,
    946                         short drw_w, short drw_h,
    947                         int id,
    948                         unsigned char *buf,
    949                         short width,
    950                         short height,
    951                         Bool sync,
    952                         RegionPtr clipBoxes);
    953 void glamor_xv_core_init(ScreenPtr screen);
    954 void glamor_xv_render(glamor_port_private *port_priv, int id);
    955 
    956 #include "glamor_utils.h"
    957 
    958 #if 0
    959 #define MAX_FBO_SIZE 32         /* For test purpose only. */
    960 #endif
    961 
    962 #include "glamor_font.h"
    963 
    964 #endif                          /* GLAMOR_PRIV_H */
    965