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