glamor_priv.h 33.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Copyright © 2008 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Eric Anholt <eric@anholt.net>
 *
 */
#ifndef GLAMOR_PRIV_H
#define GLAMOR_PRIV_H

30
#include "dix-config.h"
Zhigang Gong's avatar
Zhigang Gong committed
31

32
#include "glamor.h"
33
#include "xvdix.h"
Zhigang Gong's avatar
Zhigang Gong committed
34

35
36
37
38
39
#if XSYNC
#include "misyncshm.h"
#include "misyncstr.h"
#endif

40
#include <epoxy/gl.h>
41
42
43
44
#if GLAMOR_HAS_GBM
#define MESA_EGL_NO_X11_HEADERS
#include <epoxy/egl.h>
#endif
45

46
47
48
49
#define GLAMOR_DEFAULT_PRECISION  \
    "#ifdef GL_ES\n"              \
    "precision mediump float;\n"  \
    "#endif\n"
50

51
52
#include "glyphstr.h"

53
#include "glamor_debug.h"
54
#include "glamor_context.h"
55
#include "glamor_program.h"
56

57
#include <list.h>
He Junyan's avatar
He Junyan committed
58

59
struct glamor_pixmap_private;
60

61
typedef struct glamor_composite_shader {
Emma Anholt's avatar
Emma Anholt committed
62
63
64
65
66
67
68
69
70
71
72
73
74
    GLuint prog;
    GLint dest_to_dest_uniform_location;
    GLint dest_to_source_uniform_location;
    GLint dest_to_mask_uniform_location;
    GLint source_uniform_location;
    GLint mask_uniform_location;
    GLint source_wh;
    GLint mask_wh;
    GLint source_repeat_mode;
    GLint mask_repeat_mode;
    union {
        float source_solid_color[4];
        struct {
75
            PixmapPtr source_pixmap;
Emma Anholt's avatar
Emma Anholt committed
76
77
78
79
80
81
82
            PicturePtr source;
        };
    };

    union {
        float mask_solid_color[4];
        struct {
83
            PixmapPtr mask_pixmap;
Emma Anholt's avatar
Emma Anholt committed
84
85
86
            PicturePtr mask;
        };
    };
87
} glamor_composite_shader;
88

89
enum shader_source {
Emma Anholt's avatar
Emma Anholt committed
90
91
92
93
    SHADER_SOURCE_SOLID,
    SHADER_SOURCE_TEXTURE,
    SHADER_SOURCE_TEXTURE_ALPHA,
    SHADER_SOURCE_COUNT,
94
95
96
};

enum shader_mask {
Emma Anholt's avatar
Emma Anholt committed
97
98
99
100
101
    SHADER_MASK_NONE,
    SHADER_MASK_SOLID,
    SHADER_MASK_TEXTURE,
    SHADER_MASK_TEXTURE_ALPHA,
    SHADER_MASK_COUNT,
102
103
};

104
enum shader_in {
Emma Anholt's avatar
Emma Anholt committed
105
106
107
108
109
    SHADER_IN_SOURCE_ONLY,
    SHADER_IN_NORMAL,
    SHADER_IN_CA_SOURCE,
    SHADER_IN_CA_ALPHA,
    SHADER_IN_COUNT,
110
111
};

112
struct shader_key {
Emma Anholt's avatar
Emma Anholt committed
113
114
115
    enum shader_source source;
    enum shader_mask mask;
    enum shader_in in;
116
117
};

118
struct blendinfo {
Emma Anholt's avatar
Emma Anholt committed
119
120
121
122
    Bool dest_alpha;
    Bool source_alpha;
    GLenum source_blend;
    GLenum dest_blend;
123
124
125
};

typedef struct {
Emma Anholt's avatar
Emma Anholt committed
126
127
128
129
130
131
132
133
    INT16 x_src;
    INT16 y_src;
    INT16 x_mask;
    INT16 y_mask;
    INT16 x_dst;
    INT16 y_dst;
    INT16 width;
    INT16 height;
134
135
136
} glamor_composite_rect_t;

enum glamor_vertex_type {
Emma Anholt's avatar
Emma Anholt committed
137
138
139
    GLAMOR_VERTEX_POS,
    GLAMOR_VERTEX_SOURCE,
    GLAMOR_VERTEX_MASK
140
141
};

142
enum gradient_shader {
Emma Anholt's avatar
Emma Anholt committed
143
144
145
146
    SHADER_GRADIENT_LINEAR,
    SHADER_GRADIENT_RADIAL,
    SHADER_GRADIENT_CONICAL,
    SHADER_GRADIENT_COUNT,
147
148
};

149
150
struct glamor_screen_private;
struct glamor_pixmap_private;
151
152

enum glamor_gl_flavor {
Emma Anholt's avatar
Emma Anholt committed
153
154
    GLAMOR_GL_DESKTOP,          // OPENGL API
    GLAMOR_GL_ES2               // OPENGL ES2.0 API
155
156
};

Zhigang Gong's avatar
Zhigang Gong committed
157
#define GLAMOR_COMPOSITE_VBO_VERT_CNT (64*1024)
158

Emma Anholt's avatar
Emma Anholt committed
159
160
struct glamor_saved_procs {
    CloseScreenProcPtr close_screen;
161
    CreateScreenResourcesProcPtr create_screen_resources;
Emma Anholt's avatar
Emma Anholt committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    CreateGCProcPtr create_gc;
    CreatePixmapProcPtr create_pixmap;
    DestroyPixmapProcPtr destroy_pixmap;
    GetSpansProcPtr get_spans;
    GetImageProcPtr get_image;
    CompositeProcPtr composite;
    CompositeRectsProcPtr composite_rects;
    TrapezoidsProcPtr trapezoids;
    GlyphsProcPtr glyphs;
    ChangeWindowAttributesProcPtr change_window_attributes;
    CopyWindowProcPtr copy_window;
    BitmapToRegionProcPtr bitmap_to_region;
    TrianglesProcPtr triangles;
    AddTrapsProcPtr addtraps;
    CreatePictureProcPtr create_picture;
    DestroyPictureProcPtr destroy_picture;
    SetWindowPixmapProcPtr set_window_pixmap;
179
180
181
#if XSYNC
    SyncScreenFuncsRec sync_screen_funcs;
#endif
182
    ScreenBlockHandlerProcPtr block_handler;
183
};
Zhigang Gong's avatar
Zhigang Gong committed
184

185
186
#define CACHE_FORMAT_COUNT 3

187
188
189
190
191
#define CACHE_BUCKET_WCOUNT 4
#define CACHE_BUCKET_HCOUNT 4

#define GLAMOR_TICK_AFTER(t0, t1) 	\
	(((int)(t1) - (int)(t0)) < 0)
192

193
typedef struct glamor_screen_private {
Emma Anholt's avatar
Emma Anholt committed
194
195
    unsigned int tick;
    enum glamor_gl_flavor gl_flavor;
196
    int glsl_version;
197
198
199
200
201
202
203
204
205
    Bool has_pack_invert;
    Bool has_fbo_blit;
    Bool has_map_buffer_range;
    Bool has_buffer_storage;
    Bool has_khr_debug;
    Bool has_nv_texture_barrier;
    Bool has_pack_subimage;
    Bool has_unpack_subimage;
    Bool has_rw_pbo;
206
    Bool use_quads;
Emma Anholt's avatar
Emma Anholt committed
207
208
209
210
211
212
    int max_fbo_size;

    struct xorg_list
        fbo_cache[CACHE_FORMAT_COUNT][CACHE_BUCKET_WCOUNT][CACHE_BUCKET_HCOUNT];
    unsigned long fbo_cache_watermark;

213
214
215
    /* glamor point shader */
    glamor_program point_prog;

216
217
218
    /* glamor spans shaders */
    glamor_program_fill fill_spans_program;

219
220
221
    /* glamor rect shaders */
    glamor_program_fill poly_fill_rect_program;

222
223
224
    /* glamor glyphblt shaders */
    glamor_program_fill poly_glyph_blt_progs;

225
226
227
228
229
    /* glamor text shaders */
    glamor_program_fill poly_text_progs;
    glamor_program      te_text_prog;
    glamor_program      image_text_prog;

230
231
232
233
    /* glamor copy shaders */
    glamor_program      copy_area_prog;
    glamor_program      copy_plane_prog;

234
235
236
237
238
239
    /* glamor line shader */
    glamor_program_fill poly_line_program;

    /* glamor segment shaders */
    glamor_program_fill poly_segment_program;

240
241
242
243
    /*  glamor dash line shader */
    glamor_program_fill on_off_dash_line_progs;
    glamor_program      double_dash_line_prog;

244
245
246
247
248
249
250
251
    /* glamor composite_glyphs shaders */
    glamor_program_render       glyphs_program;
    struct glamor_glyph_atlas   *glyph_atlas_a;
    struct glamor_glyph_atlas   *glyph_atlas_argb;
    int                         glyph_atlas_dim;
    int                         glyph_max_dim;
    char                        *glyph_defines;

252
253
    /** Vertex buffer for all GPU rendering. */
    GLuint vbo;
254
    /** Next offset within the VBO that glamor_get_vbo_space() will use. */
Emma Anholt's avatar
Emma Anholt committed
255
256
    int vbo_offset;
    int vbo_size;
257
258
259
260
261
262
    /**
     * Pointer to glamor_get_vbo_space()'s current VBO mapping.
     *
     * Note that this is not necessarily equal to the pointer returned
     * by glamor_get_vbo_space(), so it can't be used in place of that.
     */
Emma Anholt's avatar
Emma Anholt committed
263
264
    char *vb;
    int vb_stride;
265
266
267
268
269
270
271
272

    /** Cached index buffer for translating GL_QUADS to triangles. */
    GLuint ib;
    /** Index buffer type: GL_UNSIGNED_SHORT or GL_UNSIGNED_INT */
    GLenum ib_type;
    /** Number of quads the index buffer has indices for. */
    unsigned ib_size;

Emma Anholt's avatar
Emma Anholt committed
273
    Bool has_source_coords, has_mask_coords;
274
    int render_nr_quads;
Emma Anholt's avatar
Emma Anholt committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
    glamor_composite_shader composite_shader[SHADER_SOURCE_COUNT]
        [SHADER_MASK_COUNT]
        [SHADER_IN_COUNT];

    /* shaders to restore a texture to another texture. */
    GLint finish_access_prog[2];
    GLint finish_access_revert[2];
    GLint finish_access_swap_rb[2];

    /* glamor gradient, 0 for small nstops, 1 for
       large nstops and 2 for dynamic generate. */
    GLint gradient_prog[SHADER_GRADIENT_COUNT][3];
    int linear_max_nstops;
    int radial_max_nstops;

    int screen_fbo;
    struct glamor_saved_procs saved_procs;
    char delayed_fallback_string[GLAMOR_DELAYED_STRING_MAX + 1];
    int delayed_fallback_pending;
    int flags;
    ScreenPtr screen;
    int dri3_enabled;

    /* xv */
    GLint xv_prog;
300
301

    struct glamor_context ctx;
302
303
} glamor_screen_private;

304
typedef enum glamor_access {
Emma Anholt's avatar
Emma Anholt committed
305
306
    GLAMOR_ACCESS_RO,
    GLAMOR_ACCESS_RW,
307
308
} glamor_access_t;

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
enum glamor_fbo_state {
    /** There is no storage attached to the pixmap. */
    GLAMOR_FBO_UNATTACHED,
    /**
     * The pixmap has FBO storage attached, but devPrivate.ptr doesn't
     * point at anything.
     */
    GLAMOR_FBO_NORMAL,
    /**
     * The FBO is present and can be accessed as a linear memory
     * mapping through devPrivate.ptr.
     */
    GLAMOR_FBO_DOWNLOADED,
};

324
325
326
327
328
/* glamor_pixmap_fbo:
 * @list:    to be used to link to the cache pool list.
 * @expire:  when push to cache pool list, set a expire count.
 * 	     will be freed when glamor_priv->tick is equal or
 * 	     larger than this expire count in block handler.
329
330
331
332
 * @pbo_valid: The pbo has a valid copy of the pixmap's data.
 * @tex:     attached texture.
 * @fb:      attached fbo.
 * @pbo:     attached pbo.
333
334
 * @width:   width of this fbo.
 * @height:  height of this fbo.
335
 * @external set when the texture was not created by glamor
336
337
338
339
 * @format:  internal format of this fbo's texture.
 * @type:    internal type of this fbo's texture.
 * @glamor_priv: point to glamor private data.
 */
340
typedef struct glamor_pixmap_fbo {
Emma Anholt's avatar
Emma Anholt committed
341
342
343
344
345
346
347
348
    struct xorg_list list;
    unsigned int expire;
    unsigned char pbo_valid;
    GLuint tex;
    GLuint fb;
    GLuint pbo;
    int width;
    int height;
349
    Bool external;
Emma Anholt's avatar
Emma Anholt committed
350
351
    GLenum format;
    GLenum type;
352
353
} glamor_pixmap_fbo;

354
355
356
357
358
/*
 * glamor_pixmap_private - glamor pixmap's private structure.
 * @gl_tex:  The pixmap is in a gl texture originally.
 * @is_picture: The drawable is attached to a picture.
 * @pict_format: the corresponding picture's format.
359
 * @pixmap: The corresponding pixmap's pointer.
360
361
362
363
364
365
366
367
 * @box: current fbo's coords in the whole pixmap.
 * @block_w: block width of this large pixmap.
 * @block_h: block height of this large pixmap.
 * @block_wcnt: block count in one block row.
 * @block_hcnt: block count in one block column.
 * @nbox: total block count.
 * @box_array: contains each block's corresponding box.
 * @fbo_array: contains each block's fbo pointer.
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
 *
 * For GLAMOR_TEXTURE_LARGE, nbox should larger than 1.
 * And the box and fbo will both have nbox elements.
 * and box[i] store the relatively coords in this pixmap
 * of the fbo[i]. The reason why use boxes not region to
 * represent this structure is we may need to use overlapped
 * boxes for one pixmap for some special reason.
 *
 * pixmap
 * ******************
 * *  fbo0 * fbo1   *
 * *       *        *
 * ******************
 * *  fbo2 * fbo3   *
 * *       *        *
 * ******************
 *
 * Let's assume the texture has size of 1024x1024
 * box[0] = {0,0,1024,1024}
 * box[1] = {1024,0,2048,2048}
 * ...
 *
 * For GLAMOR_TEXTURE_ATLAS nbox should be 1. And box
 * and fbo both has one elements, and the box store
 * the relatively coords in the fbo of this pixmap:
 *
 * fbo
 * ******************
 * *   pixmap       *
 * *   *********    *
 * *   *       *    *
 * *   *********    *
 * *                *
 * ******************
 *
 * Assume the pixmap is at the (100,100) relatively to
 * the fbo's origin.
 * box[0]={100, 100, 1124, 1124};
 *
 * Considering large pixmap is not a normal case, to keep
 * it simple, I designe it as the following way.
 * When deal with a large pixmap, it split the working
 * rectangle into serval boxes, and each box fit into a
 * corresponding fbo. And then the rendering function will
 * loop from the left-top box to the right-bottom box,
 * each time, we will set current box and current fbo
 * to the box and fbo elements. Thus the inner routines
 * can handle it as normal, only the coords calculation need
 * to aware of it's large pixmap.
417
 **/
418

Emma Anholt's avatar
Emma Anholt committed
419
420
421
typedef struct glamor_pixmap_clipped_regions {
    int block_idx;
    RegionPtr region;
422
423
} glamor_pixmap_clipped_regions;

424
typedef struct glamor_pixmap_private {
Emma Anholt's avatar
Emma Anholt committed
425
    glamor_pixmap_type_t type;
426
    enum glamor_fbo_state gl_fbo;
427
428
429
430
431
432
    /**
     * If devPrivate.ptr is non-NULL (meaning we're within
     * glamor_prepare_access), determies whether we should re-upload
     * that data on glamor_finish_access().
     */
    glamor_access_t map_access;
Emma Anholt's avatar
Emma Anholt committed
433
434
435
    unsigned char is_picture:1;
    unsigned char gl_tex:1;
    glamor_pixmap_fbo *fbo;
436
    BoxRec box;
Emma Anholt's avatar
Emma Anholt committed
437
438
    int drm_stride;
    PicturePtr picture;
439
440
441
    GLuint pbo;
    RegionRec prepare_region;
    Bool prepared;
442
443
444
#if GLAMOR_HAS_GBM
    EGLImageKHR image;
#endif
Emma Anholt's avatar
Emma Anholt committed
445
446
447
448
449
450
451
    int block_w;
    int block_h;
    int block_wcnt;
    int block_hcnt;
    BoxPtr box_array;
    glamor_pixmap_fbo **fbo_array;
} glamor_pixmap_private;
Emma Anholt's avatar
Emma Anholt committed
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
extern DevPrivateKeyRec glamor_pixmap_private_key;

static inline glamor_pixmap_private *
glamor_get_pixmap_private(PixmapPtr pixmap)
{
    glamor_pixmap_private *priv;

    if (pixmap == NULL)
        return NULL;

    priv = dixLookupPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
    if (!priv) {
        glamor_set_pixmap_type(pixmap, GLAMOR_MEMORY);
        priv = dixLookupPrivate(&pixmap->devPrivates,
                                &glamor_pixmap_private_key);
    }
    return priv;
}

void glamor_set_pixmap_private(PixmapPtr pixmap, glamor_pixmap_private *priv);

474
/*
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
 * Returns TRUE if pixmap has no image object
 */
static inline Bool
glamor_pixmap_drm_only(PixmapPtr pixmap)
{
    glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);

    return priv && priv->type == GLAMOR_DRM_ONLY;
}

/*
 * Returns TRUE if pixmap is plain memory (not a GL object at all)
 */
static inline Bool
glamor_pixmap_is_memory(PixmapPtr pixmap)
{
    glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);

    return !priv || priv->type == GLAMOR_MEMORY;
}

/*
 * Returns TRUE if pixmap requires multiple textures to hold it
 */
static inline Bool
glamor_pixmap_priv_is_large(glamor_pixmap_private *priv)
{
502
    return priv && (priv->block_wcnt > 1 || priv->block_hcnt > 1);
503
504
505
506
507
}

static inline Bool
glamor_pixmap_priv_is_small(glamor_pixmap_private *priv)
{
508
    return priv && priv->block_wcnt <= 1 && priv->block_hcnt <= 1;
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
}

static inline Bool
glamor_pixmap_is_large(PixmapPtr pixmap)
{
    glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);

    return priv && glamor_pixmap_priv_is_large(priv);
}
/*
 * Returns TRUE if pixmap has an FBO
 */
static inline Bool
glamor_pixmap_has_fbo(PixmapPtr pixmap)
{
    glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);

    return priv && priv->gl_fbo == GLAMOR_FBO_NORMAL;
}
528

529
530
531
static inline void
glamor_set_pixmap_fbo_current(glamor_pixmap_private *priv, int idx)
{
532
    if (glamor_pixmap_priv_is_large(priv)) {
533
534
        priv->fbo = priv->fbo_array[idx];
        priv->box = priv->box_array[idx];
535
536
537
    }
}

538
539
540
static inline glamor_pixmap_fbo *
glamor_pixmap_fbo_at(glamor_pixmap_private *priv, int x, int y)
{
541
542
543
    assert(x < priv->block_wcnt);
    assert(y < priv->block_hcnt);
    return priv->fbo_array[y * priv->block_wcnt + x];
544
545
546
547
548
}

static inline BoxPtr
glamor_pixmap_box_at(glamor_pixmap_private *priv, int x, int y)
{
549
550
551
    assert(x < priv->block_wcnt);
    assert(y < priv->block_hcnt);
    return &priv->box_array[y * priv->block_wcnt + x];
552
553
554
555
556
}

static inline int
glamor_pixmap_wcnt(glamor_pixmap_private *priv)
{
557
    return priv->block_wcnt;
558
559
560
561
562
}

static inline int
glamor_pixmap_hcnt(glamor_pixmap_private *priv)
{
563
    return priv->block_hcnt;
564
565
566
567
568
569
}

#define glamor_pixmap_loop(priv, x, y)                  \
    for (y = 0; y < glamor_pixmap_hcnt(priv); y++)      \
        for (x = 0; x < glamor_pixmap_wcnt(priv); x++)

570
/*
571
572
573
574
575
576
577
578
579
 * Pixmap dynamic status, used by dynamic upload feature.
 *
 * GLAMOR_NONE:  initial status, don't need to do anything.
 * GLAMOR_UPLOAD_PENDING: marked as need to be uploaded to gl texture.
 * GLAMOR_UPLOAD_DONE: the pixmap has been uploaded successfully.
 * GLAMOR_UPLOAD_FAILED: fail to upload the pixmap.
 *
 * */
typedef enum glamor_pixmap_status {
Emma Anholt's avatar
Emma Anholt committed
580
581
582
583
    GLAMOR_NONE,
    GLAMOR_UPLOAD_PENDING,
    GLAMOR_UPLOAD_DONE,
    GLAMOR_UPLOAD_FAILED
Zhigang Gong's avatar
Zhigang Gong committed
584
} glamor_pixmap_status_t;
585

586
587
588
589
/* GC private structure. Currently holds only any computed dash pixmap */

typedef struct {
    PixmapPtr   dash;
590
591
    PixmapPtr   stipple;
    DamagePtr   stipple_damage;
592
593
594
} glamor_gc_private;

extern DevPrivateKeyRec glamor_gc_private_key;
595
596
extern DevPrivateKeyRec glamor_screen_private_key;

597
598
599
static inline glamor_screen_private *
glamor_get_screen_private(ScreenPtr screen)
{
Emma Anholt's avatar
Emma Anholt committed
600
    return (glamor_screen_private *)
601
        dixLookupPrivate(&screen->devPrivates, &glamor_screen_private_key);
602
}
Zhigang Gong's avatar
Zhigang Gong committed
603

604
static inline void
605
glamor_set_screen_private(ScreenPtr screen, glamor_screen_private *priv)
606
{
607
    dixSetPrivate(&screen->devPrivates, &glamor_screen_private_key, priv);
608
609
}

610
611
612
613
614
615
static inline glamor_gc_private *
glamor_get_gc_private(GCPtr gc)
{
    return dixLookupPrivate(&gc->devPrivates, &glamor_gc_private_key);
}

616
617
618
619
620
/**
 * Returns TRUE if the given planemask covers all the significant bits in the
 * pixel values for pDrawable.
 */
static inline Bool
621
glamor_pm_is_solid(int depth, unsigned long planemask)
622
{
623
624
    return (planemask & FbFullMask(depth)) ==
        FbFullMask(depth);
625
626
}

627
628
extern int glamor_debug_level;

629
630
631
/* glamor.c */
PixmapPtr glamor_get_drawable_pixmap(DrawablePtr drawable);

Emma Anholt's avatar
Emma Anholt committed
632
633
glamor_pixmap_fbo *glamor_pixmap_detach_fbo(glamor_pixmap_private *
                                            pixmap_priv);
634
void glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo);
Emma Anholt's avatar
Emma Anholt committed
635
636
637
638
glamor_pixmap_fbo *glamor_create_fbo_from_tex(glamor_screen_private *
                                              glamor_priv, int w, int h,
                                              GLenum format, GLint tex,
                                              int flag);
639
glamor_pixmap_fbo *glamor_create_fbo(glamor_screen_private *glamor_priv, int w,
Emma Anholt's avatar
Emma Anholt committed
640
                                     int h, GLenum format, int flag);
641
642
643
644
void glamor_destroy_fbo(glamor_screen_private *glamor_priv,
                        glamor_pixmap_fbo *fbo);
void glamor_pixmap_destroy_fbo(glamor_screen_private *glamor_priv,
                               glamor_pixmap_private *priv);
645
646
void glamor_init_pixmap_fbo(ScreenPtr screen);
void glamor_fini_pixmap_fbo(ScreenPtr screen);
647
Bool glamor_pixmap_fbo_fixup(ScreenPtr screen, PixmapPtr pixmap);
648
void glamor_fbo_expire(glamor_screen_private *glamor_priv);
649

650
glamor_pixmap_fbo *glamor_create_fbo_array(glamor_screen_private *glamor_priv,
Emma Anholt's avatar
Emma Anholt committed
651
652
653
                                           int w, int h, GLenum format,
                                           int flag, int block_w, int block_h,
                                           glamor_pixmap_private *);
654

655
656
657
void glamor_gldrawarrays_quads_using_indices(glamor_screen_private *glamor_priv,
                                             unsigned count);

658
/* glamor_core.c */
659
void glamor_init_finish_access_shaders(ScreenPtr screen);
660

661
Bool glamor_get_drawable_location(const DrawablePtr drawable);
662
void glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap,
Emma Anholt's avatar
Emma Anholt committed
663
                                int *x, int *y);
664
GLint glamor_compile_glsl_prog(GLenum type, const char *source);
665
666
void glamor_link_glsl_prog(ScreenPtr screen, GLint prog,
                           const char *format, ...) _X_ATTRIBUTE_PRINTF(3,4);
Zhigang Gong's avatar
Zhigang Gong committed
667
void glamor_get_color_4f_from_pixel(PixmapPtr pixmap,
668
                                    unsigned long fg_pixel, GLfloat *color);
669
670

int glamor_set_destination_pixmap(PixmapPtr pixmap);
671
672
int glamor_set_destination_pixmap_priv(glamor_screen_private *glamor_priv, PixmapPtr pixmap, glamor_pixmap_private *pixmap_priv);
void glamor_set_destination_pixmap_fbo(glamor_screen_private *glamor_priv, glamor_pixmap_fbo *, int, int, int, int);
673
674

/* nc means no check. caller must ensure this pixmap has valid fbo.
675
 * usually use the GLAMOR_PIXMAP_PRIV_HAS_FBO firstly.
676
 * */
677
void glamor_set_destination_pixmap_priv_nc(glamor_screen_private *glamor_priv, PixmapPtr pixmap, glamor_pixmap_private *pixmap_priv);
678

Emma Anholt's avatar
Emma Anholt committed
679
680
681
682
683
glamor_pixmap_fbo *glamor_es2_pixmap_read_prepare(PixmapPtr source, int x,
                                                  int y, int w, int h,
                                                  GLenum format, GLenum type,
                                                  int no_alpha, int revert,
                                                  int swap_rb);
684

685
Bool glamor_set_alu(ScreenPtr screen, unsigned char alu);
686
Bool glamor_set_planemask(int depth, unsigned long planemask);
687
RegionPtr glamor_bitmap_to_region(PixmapPtr pixmap);
Zhigang Gong's avatar
Zhigang Gong committed
688

689
690
691
void
glamor_track_stipple(GCPtr gc);

692
/* glamor_render.c */
693
694
695
696
Bool glamor_composite_clipped_region(CARD8 op,
                                     PicturePtr source,
                                     PicturePtr mask,
                                     PicturePtr dest,
697
698
699
                                     PixmapPtr source_pixmap,
                                     PixmapPtr mask_pixmap,
                                     PixmapPtr dest_pixmap,
700
701
702
703
704
                                     RegionPtr region,
                                     int x_source,
                                     int y_source,
                                     int x_mask, int y_mask,
                                     int x_dest, int y_dest);
705

706
void glamor_composite(CARD8 op,
Emma Anholt's avatar
Emma Anholt committed
707
708
709
710
711
712
713
714
                      PicturePtr pSrc,
                      PicturePtr pMask,
                      PicturePtr pDst,
                      INT16 xSrc,
                      INT16 ySrc,
                      INT16 xMask,
                      INT16 yMask,
                      INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
715

Emma Anholt's avatar
Emma Anholt committed
716
717
void glamor_composite_rects(CARD8 op,
                            PicturePtr pDst,
718
                            xRenderColor *color, int nRect, xRectangle *rects);
719
720
721
722
PicturePtr glamor_convert_gradient_picture(ScreenPtr screen,
                                           PicturePtr source,
                                           int x_source,
                                           int y_source, int width, int height);
723

724
void *glamor_setup_composite_vbo(ScreenPtr screen, int n_verts);
725

RobinHe's avatar
RobinHe committed
726
727
/* glamor_trapezoid.c */
void glamor_trapezoids(CARD8 op,
Emma Anholt's avatar
Emma Anholt committed
728
729
                       PicturePtr src, PicturePtr dst,
                       PictFormatPtr mask_format, INT16 x_src, INT16 y_src,
730
                       int ntrap, xTrapezoid *traps);
731

732
/* glamor_gradient.c */
733
void glamor_init_gradient_shader(ScreenPtr screen);
734
735
736
737
738
739
740
741
742
743
PicturePtr glamor_generate_linear_gradient_picture(ScreenPtr screen,
                                                   PicturePtr src_picture,
                                                   int x_source, int y_source,
                                                   int width, int height,
                                                   PictFormatShort format);
PicturePtr glamor_generate_radial_gradient_picture(ScreenPtr screen,
                                                   PicturePtr src_picture,
                                                   int x_source, int y_source,
                                                   int width, int height,
                                                   PictFormatShort format);
744

745
/* glamor_triangles.c */
746
747
748
749
750
void glamor_triangles(CARD8 op,
                      PicturePtr pSrc,
                      PicturePtr pDst,
                      PictFormatPtr maskFormat,
                      INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris);
751
752
753

/* glamor_pixmap.c */

Zhigang Gong's avatar
Zhigang Gong committed
754
void glamor_pixmap_init(ScreenPtr screen);
755
void glamor_pixmap_fini(ScreenPtr screen);
Emma Anholt's avatar
Emma Anholt committed
756

757
758
759
760
761
762
763
764
765
766
767
/* glamor_vbo.c */

void glamor_init_vbo(ScreenPtr screen);
void glamor_fini_vbo(ScreenPtr screen);

void *
glamor_get_vbo_space(ScreenPtr screen, unsigned size, char **vbo_offset);

void
glamor_put_vbo_space(ScreenPtr screen);

768
/**
769
770
771
772
 * According to the flag,
 * if the flag is GLAMOR_CREATE_FBO_NO_FBO then just ensure
 * the fbo has a valid texture. Otherwise, it will ensure
 * the fbo has valid texture and attach to a valid fb.
773
 * If the fbo already has a valid glfbo then do nothing.
774
 */
775
Bool glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag);
776
777
778
779
780
781

/**
 * Upload a pixmap to gl texture. Used by dynamic pixmap
 * uploading feature. The pixmap must be a software pixmap.
 * This function will change current FBO and current shaders.
 */
782
783
784
785
786
787
788
enum glamor_pixmap_status glamor_upload_pixmap_to_texture(PixmapPtr pixmap);

Bool glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
                                         int h, int stride, void *bits,
                                         int pbo);

glamor_pixmap_clipped_regions *
789
glamor_compute_clipped_regions(PixmapPtr pixmap,
790
791
792
793
794
                               RegionPtr region, int *clipped_nbox,
                               int repeat_type, int reverse,
                               int upsidedown);

glamor_pixmap_clipped_regions *
795
glamor_compute_clipped_regions_ext(PixmapPtr pixmap,
796
797
798
799
800
                                   RegionPtr region, int *n_region,
                                   int inner_block_w, int inner_block_h,
                                   int reverse, int upsidedown);

glamor_pixmap_clipped_regions *
801
glamor_compute_transform_clipped_regions(PixmapPtr pixmap,
802
803
804
805
806
807
808
809
810
811
                                         struct pixman_transform *transform,
                                         RegionPtr region,
                                         int *n_region, int dx, int dy,
                                         int repeat_type, int reverse,
                                         int upsidedown);

Bool glamor_composite_largepixmap_region(CARD8 op,
                                         PicturePtr source,
                                         PicturePtr mask,
                                         PicturePtr dest,
812
813
814
                                         PixmapPtr source_pixmap,
                                         PixmapPtr mask_pixmap,
                                         PixmapPtr dest_pixmap,
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
                                         RegionPtr region, Bool force_clip,
                                         INT16 x_source,
                                         INT16 y_source,
                                         INT16 x_mask,
                                         INT16 y_mask,
                                         INT16 x_dest, INT16 y_dest,
                                         CARD16 width, CARD16 height);

Bool glamor_get_transform_block_size(struct pixman_transform *transform,
                                     int block_w, int block_h,
                                     int *transformed_block_w,
                                     int *transformed_block_h);

void glamor_get_transform_extent_from_box(struct pixman_box32 *temp_box,
                                          struct pixman_transform *transform);
830

831
/**
832
833
834
 * Upload a picture to gl texture. Similar to the
 * glamor_upload_pixmap_to_texture. Used in rendering.
 **/
835
enum glamor_pixmap_status glamor_upload_picture_to_texture(PicturePtr picture);
836

837
838
839
840
841
/**
 * Upload bits to a pixmap's texture. This function will
 * convert the bits to the specified format/type format
 * if the conversion is unavoidable.
 **/
Emma Anholt's avatar
Emma Anholt committed
842
843
844
Bool glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
                                          GLenum type, int no_alpha, int revert,
                                          int swap_rb, void *bits);
845

Zhigang Gong's avatar
Zhigang Gong committed
846
int glamor_create_picture(PicturePtr picture);
847

848
849
void glamor_set_window_pixmap(WindowPtr pWindow, PixmapPtr pPixmap);

Zhigang Gong's avatar
Zhigang Gong committed
850
void glamor_destroy_picture(PicturePtr picture);
851

852
853
void glamor_picture_format_fixup(PicturePtr picture,
                                 glamor_pixmap_private *pixmap_priv);
Zhigang Gong's avatar
Zhigang Gong committed
854

855
856
void glamor_add_traps(PicturePtr pPicture,
                      INT16 x_off, INT16 y_off, int ntrap, xTrap *traps);
Zhigang Gong's avatar
Zhigang Gong committed
857

858
859
860
861
862
863
864
865
866
867
868
869
870
/* glamor_text.c */
int glamor_poly_text8(DrawablePtr pDrawable, GCPtr pGC,
                      int x, int y, int count, char *chars);

int glamor_poly_text16(DrawablePtr pDrawable, GCPtr pGC,
                       int x, int y, int count, unsigned short *chars);

void glamor_image_text8(DrawablePtr pDrawable, GCPtr pGC,
                        int x, int y, int count, char *chars);

void glamor_image_text16(DrawablePtr pDrawable, GCPtr pGC,
                         int x, int y, int count, unsigned short *chars);

871
872
873
874
875
876
877
878
879
880
881
882
883
884
/* glamor_spans.c */
void
glamor_fill_spans(DrawablePtr drawable,
                  GCPtr gc,
                  int n, DDXPointPtr points, int *widths, int sorted);

void
glamor_get_spans(DrawablePtr drawable, int wmax,
                 DDXPointPtr points, int *widths, int count, char *dst);

void
glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
                 DDXPointPtr points, int *widths, int numPoints, int sorted);

885
886
887
888
889
/* glamor_rects.c */
void
glamor_poly_fill_rect(DrawablePtr drawable,
                      GCPtr gc, int nrect, xRectangle *prect);

890
891
892
893
894
895
896
897
/* glamor_image.c */
void
glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
                 int w, int h, int leftPad, int format, char *bits);

void
glamor_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
                 unsigned int format, unsigned long planeMask, char *d);
898
899
900
901
902
903
904
905
906
907
908

/* glamor_dash.c */
Bool
glamor_poly_lines_dash_gl(DrawablePtr drawable, GCPtr gc,
                          int mode, int n, DDXPointPtr points);

Bool
glamor_poly_segment_dash_gl(DrawablePtr drawable, GCPtr gc,
                            int nseg, xSegment *segs);

/* glamor_lines.c */
909
910
911
912
913
914
915
916
void
glamor_poly_lines(DrawablePtr drawable, GCPtr gc,
                  int mode, int n, DDXPointPtr points);

/*  glamor_segs.c */
void
glamor_poly_segment(DrawablePtr drawable, GCPtr gc,
                    int nseg, xSegment *segs);
917

918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
/* glamor_copy.c */
void
glamor_copy(DrawablePtr src,
            DrawablePtr dst,
            GCPtr gc,
            BoxPtr box,
            int nbox,
            int dx,
            int dy,
            Bool reverse,
            Bool upsidedown,
            Pixel bitplane,
            void *closure);

RegionPtr
glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
                 int srcx, int srcy, int width, int height, int dstx, int dsty);

RegionPtr
glamor_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
                  int srcx, int srcy, int width, int height, int dstx, int dsty,
                  unsigned long bitplane);

941
/* glamor_glyphblt.c */
942
943
void glamor_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
                            int x, int y, unsigned int nglyph,
944
                            CharInfoPtr *ppci, void *pglyphBase);
Zhigang Gong's avatar
Zhigang Gong committed
945

946
947
void glamor_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
                           int x, int y, unsigned int nglyph,
948
                           CharInfoPtr *ppci, void *pglyphBase);
Emma Anholt's avatar
Emma Anholt committed
949

950
951
void glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
                        DrawablePtr pDrawable, int w, int h, int x, int y);
Zhigang Gong's avatar
Zhigang Gong committed
952

953
954
void glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
                       DDXPointPtr ppt);
Emma Anholt's avatar
Emma Anholt committed
955

956
957
958
959
void glamor_composite_rectangles(CARD8 op,
                                 PicturePtr dst,
                                 xRenderColor *color,
                                 int num_rects, xRectangle *rects);
960

961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
/* glamor_composite_glyphs.c */
Bool
glamor_composite_glyphs_init(ScreenPtr pScreen);

void
glamor_composite_glyphs_fini(ScreenPtr pScreen);

void
glamor_composite_glyphs(CARD8 op,
                        PicturePtr src,
                        PicturePtr dst,
                        PictFormatPtr mask_format,
                        INT16 x_src,
                        INT16 y_src, int nlist,
                        GlyphListPtr list, GlyphPtr *glyphs);

977
978
979
980
981
982
983
/* glamor_sync.c */
Bool
glamor_sync_init(ScreenPtr screen);

void
glamor_sync_close(ScreenPtr screen);

984
985
986
987
988
989
990
991
992
993
/* glamor_util.c */
void
glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
             unsigned long fg_pixel);

void
glamor_solid_boxes(PixmapPtr pixmap,
                   BoxPtr box, int nbox, unsigned long fg_pixel);


Dave Airlie's avatar
Dave Airlie committed
994
995
/* glamor_xv */
typedef struct {
Emma Anholt's avatar
Emma Anholt committed
996
997
    uint32_t transform_index;
    uint32_t gamma;             /* gamma value x 1000 */
Dave Airlie's avatar
Dave Airlie committed
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
    int brightness;
    int saturation;
    int hue;
    int contrast;

    DrawablePtr pDraw;
    PixmapPtr pPixmap;
    uint32_t src_pitch;
    uint8_t *src_addr;
    int src_w, src_h, dst_w, dst_h;
    int src_x, src_y, drw_x, drw_y;
    int w, h;
Emma Anholt's avatar
Emma Anholt committed
1010
1011
    RegionRec clip;
    PixmapPtr src_pix[3];       /* y, u, v for planar */
Dave Airlie's avatar
Dave Airlie committed
1012
1013
1014
    int src_pix_w, src_pix_h;
} glamor_port_private;

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
extern XvAttributeRec glamor_xv_attributes[];
extern int glamor_xv_num_attributes;
extern XvImageRec glamor_xv_images[];
extern int glamor_xv_num_images;

void glamor_xv_init_port(glamor_port_private *port_priv);
void glamor_xv_stop_video(glamor_port_private *port_priv);
int glamor_xv_set_port_attribute(glamor_port_private *port_priv,
                                 Atom attribute, INT32 value);
int glamor_xv_get_port_attribute(glamor_port_private *port_priv,
                                 Atom attribute, INT32 *value);
int glamor_xv_query_image_attributes(int id,
                                     unsigned short *w, unsigned short *h,
                                     int *pitches, int *offsets);
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
int glamor_xv_put_image(glamor_port_private *port_priv,
                        DrawablePtr pDrawable,
                        short src_x, short src_y,
                        short drw_x, short drw_y,
                        short src_w, short src_h,
                        short drw_w, short drw_h,
                        int id,
                        unsigned char *buf,
                        short width,
                        short height,
                        Bool sync,
                        RegionPtr clipBoxes);
1041
1042
void glamor_xv_core_init(ScreenPtr screen);
void glamor_xv_render(glamor_port_private *port_priv);
Dave Airlie's avatar
Dave Airlie committed
1043

Zhigang Gong's avatar
Zhigang Gong committed
1044
#include"glamor_utils.h"
1045

1046
/* Dynamic pixmap upload to texture if needed.
1047
1048
 * Sometimes, the target is a gl texture pixmap/picture,
 * but the source or mask is in cpu memory. In that case,
1049
 * upload the source/mask to gl texture and then avoid
1050
1051
1052
 * fallback the whole process to cpu. Most of the time,
 * this will increase performance obviously. */

1053
#define GLAMOR_PIXMAP_DYNAMIC_UPLOAD
1054
#define GLAMOR_GRADIENT_SHADER
Zhigang Gong's avatar
Zhigang Gong committed
1055
#define GLAMOR_TEXTURED_LARGE_PIXMAP 1
1056
#define WALKAROUND_LARGE_TEXTURE_MAP
1057
#if 0
Emma Anholt's avatar
Emma Anholt committed
1058
#define MAX_FBO_SIZE 32         /* For test purpose only. */
1059
#endif
1060

1061
1062
#include "glamor_font.h"

1063
1064
#define GLAMOR_MIN_ALU_INSTRUCTIONS 128 /* Minimum required number of native ALU instructions */

Emma Anholt's avatar
Emma Anholt committed
1065
#endif                          /* GLAMOR_PRIV_H */