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