glamor_priv.h 24.3 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
31
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
Zhigang Gong's avatar
Zhigang Gong committed
32
#include <xorg-config.h>
33
34
35
#endif


36
#include "glamor.h"
Zhigang Gong's avatar
Zhigang Gong committed
37
38
39
40
41
42
43
44
45
46
47
48
49

#ifdef GLAMOR_GLES2

#define GL_BGRA                                 GL_BGRA_EXT
#define GL_COLOR_INDEX                          0x1900
#define GL_BITMAP                               0x1A00
#define GL_UNSIGNED_INT_8_8_8_8                 0x8035
#define GL_UNSIGNED_INT_8_8_8_8_REV             0x8367
#define GL_UNSIGNED_INT_2_10_10_10_REV          0x8368
#define GL_UNSIGNED_SHORT_5_6_5_REV             0x8364
#define GL_UNSIGNED_SHORT_1_5_5_5_REV           0x8366
#define GL_UNSIGNED_SHORT_4_4_4_4_REV           0x8365

50
51
52
53
54
55
56
57
58
59
#define GL_PIXEL_PACK_BUFFER              0x88EB
#define GL_PIXEL_UNPACK_BUFFER            0x88EC
#define GL_CLAMP_TO_BORDER                0x812D

#define GL_READ_WRITE                     0x88BA
#define GL_READ_ONLY                      0x88B8
#define GL_WRITE_ONLY                     0x88B9
#define GL_STREAM_DRAW                    0x88E0
#define GL_STREAM_READ                    0x88E1
#define GL_PACK_ROW_LENGTH                      0x0D02
60
#define GL_UNPACK_ROW_LENGTH                    0x0CF2
61

62
63
64
65
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56

66
67
#define GL_PACK_INVERT_MESA               0x8758

68
69
70
71
72
#define glMapBuffer(x, y)    NULL
#define glUnmapBuffer(x)
#define glRasterPos2i(x,y)
#define glDrawPixels(x,y,z,a,b)

Zhigang Gong's avatar
Zhigang Gong committed
73
74
#endif

75
#define GL_GLEXT_PROTOTYPES
Zhigang Gong's avatar
Zhigang Gong committed
76
#ifdef GLAMOR_GLES2
77
78
79
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
Zhigang Gong's avatar
Zhigang Gong committed
80
81
#include <GL/gl.h>
#include <GL/glext.h>
82
83
#endif

84

85
86
87
88
#ifdef RENDER
#include "glyphstr.h"
#endif

89
90
91

#include "glamor_debug.h"

Zhigang Gong's avatar
Zhigang Gong committed
92
93
94
#define glamor_check_fbo_size(_glamor_,_w_, _h_)    ((_w_) > 0 && (_h_) > 0 \
                                                    && (_w_) < _glamor_->max_fbo_size  \
                                                    && (_h_) < _glamor_->max_fbo_size)
95
96
97
98
99
100
101
102
103
104
105
106

#define glamor_check_fbo_depth(_depth_) (			\
                                         _depth_ == 8		\
	                                 || _depth_ == 15	\
                                         || _depth_ == 16	\
                                         || _depth_ == 24	\
                                         || _depth_ == 30	\
                                         || _depth_ == 32)


#define GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) (pixmap_priv->is_picture == 1)
#define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)    (pixmap_priv->gl_fbo == 1)
107

108
typedef struct glamor_transform_uniforms {
109
110
111
112
  GLint x_bias;
  GLint x_scale;
  GLint y_bias;
  GLint y_scale;
113
114
} glamor_transform_uniforms;

115
typedef struct glamor_composite_shader {
116
117
118
119
120
121
  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;
122
123
} glamor_composite_shader;

124
typedef struct {
125
126
127
128
129
130
131
132
  INT16 x_src;
  INT16 y_src;
  INT16 x_mask;
  INT16 y_mask;
  INT16 x_dst;
  INT16 y_dst;
  INT16 width;
  INT16 height;
133
134
135
} glamor_composite_rect_t;

typedef struct {
136
  unsigned char sha1[20];
137
138
139
} glamor_cached_glyph_t;

typedef struct {
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  /* The identity of the cache, statically configured at initialization */
  unsigned int format;
  int glyph_width;
  int glyph_height;

  /* Size of cache; eventually this should be dynamically determined */
  int size;

  /* Hash table mapping from glyph sha1 to position in the glyph; we use
   * open addressing with a hash table size determined based on size and large
   * enough so that we always have a good amount of free space, so we can
   * use linear probing. (Linear probing is preferrable to double hashing
   * here because it allows us to easily remove entries.)
   */
  int *hash_entries;
  int hash_size;

  glamor_cached_glyph_t *glyphs;
  int glyph_count;		/* Current number of glyphs */

  PicturePtr picture;	/* Where the glyphs of the cache are stored */
  int y_offset;		/* y location within the picture where the cache starts */
  int columns;		/* Number of columns the glyphs are layed out in */
  int eviction_position;	/* Next random position to evict a glyph */
164
165
166
167
} glamor_glyph_cache_t;

#define GLAMOR_NUM_GLYPH_CACHES 4

168
169
170
171
172
173
enum glamor_vertex_type {
     GLAMOR_VERTEX_POS,
     GLAMOR_VERTEX_SOURCE,
     GLAMOR_VERTEX_MASK
};

174
enum shader_source {
175
176
177
178
  SHADER_SOURCE_SOLID,
  SHADER_SOURCE_TEXTURE,
  SHADER_SOURCE_TEXTURE_ALPHA,
  SHADER_SOURCE_COUNT,
179
180
181
};

enum shader_mask {
182
183
184
185
186
  SHADER_MASK_NONE,
  SHADER_MASK_SOLID,
  SHADER_MASK_TEXTURE,
  SHADER_MASK_TEXTURE_ALPHA,
  SHADER_MASK_COUNT,
187
188
};

189
enum shader_in {
190
191
192
193
194
  SHADER_IN_SOURCE_ONLY,
  SHADER_IN_NORMAL,
  SHADER_IN_CA_SOURCE,
  SHADER_IN_CA_ALPHA,
  SHADER_IN_COUNT,
195
196
};

197
198
199
200
struct glamor_screen_private;
struct glamor_pixmap_private;
typedef void (*glamor_pixmap_validate_function_t)(struct glamor_screen_private*, 
					          struct glamor_pixmap_private*);
201
202
203
204
205
206

enum glamor_gl_flavor {
   GLAMOR_GL_DESKTOP,        // OPENGL API
   GLAMOR_GL_ES2             // OPENGL ES2.0 API
};

207
#define GLAMOR_CREATE_PIXMAP_CPU  0x100
208
typedef struct glamor_screen_private {
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  CloseScreenProcPtr saved_close_screen;
  CreateGCProcPtr saved_create_gc;
  CreatePixmapProcPtr saved_create_pixmap;
  DestroyPixmapProcPtr saved_destroy_pixmap;
  GetSpansProcPtr saved_get_spans;
  GetImageProcPtr saved_get_image;
  CompositeProcPtr saved_composite;
  TrapezoidsProcPtr saved_trapezoids;
  GlyphsProcPtr saved_glyphs;
  ChangeWindowAttributesProcPtr saved_change_window_attributes;
  CopyWindowProcPtr saved_copy_window;
  BitmapToRegionProcPtr saved_bitmap_to_region;
  TrianglesProcPtr saved_triangles;
  CreatePictureProcPtr saved_create_picture;
  DestroyPictureProcPtr saved_destroy_picture;

  int yInverted;
  int screen_fbo;
  GLuint vbo;
  int vbo_offset;
  int vbo_size;
  char *vb;
  int vb_stride;
232
  enum glamor_gl_flavor gl_flavor;
Zhigang Gong's avatar
Zhigang Gong committed
233
234
235
  int has_pack_invert;
  int has_fbo_blit;
  int max_fbo_size;
236
237

  /* glamor_finishaccess */
238
  GLint finish_access_prog[2];
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

  /* glamor_solid */
  GLint solid_prog;
  GLint solid_color_uniform_location;

  /* glamor_tile */
  GLint tile_prog;

  /* glamor_putimage */
  GLint put_image_xybitmap_prog;
  glamor_transform_uniforms put_image_xybitmap_transform;
  GLint put_image_xybitmap_fg_uniform_location;
  GLint put_image_xybitmap_bg_uniform_location;

  /* glamor_composite */
  glamor_composite_shader composite_shader[SHADER_SOURCE_COUNT]
  [SHADER_MASK_COUNT]
  [SHADER_IN_COUNT];
  Bool has_source_coords, has_mask_coords;
  int render_nr_verts;
259
  glamor_pixmap_validate_function_t *pixmap_validate_funcs;
260
261
262
  glamor_glyph_cache_t glyph_caches[GLAMOR_NUM_GLYPH_CACHES];
  char delayed_fallback_string[GLAMOR_DELAYED_STRING_MAX + 1];
  int  delayed_fallback_pending;
263
264
} glamor_screen_private;

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
typedef enum glamor_access {
  GLAMOR_ACCESS_RO,
  GLAMOR_ACCESS_RW,
  GLAMOR_ACCESS_WO,
} glamor_access_t;

/*
 * glamor_pixmap_private - glamor pixmap's private structure.
 * @gl_fbo:  The pixmap is attached to a fbo originally.
 * @gl_tex:  The pixmap is in a gl texture originally.
 * @pbo_valid: The pbo has a valid copy of the pixmap's data.
 * @is_picture: The drawable is attached to a picture.
 * @tex:     attached texture.
 * @fb:      attached fbo.
 * @pbo:     attached pbo.
 * @access_mode: access mode during the prepare/finish pair.
 * @pict_format: the corresponding picture's format.
282
 * #pending_op: currently only support pending filling.
283
284
 * @container: The corresponding pixmap's pointer.
 **/
285

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#define GLAMOR_PIXMAP_PRIV_NEED_VALIDATE(pixmap_priv)  \
	(GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv) \
	&& (pixmap_priv->pending_op.type != GLAMOR_PENDING_NONE))

#define GLAMOR_PIXMAP_PRIV_NO_PENDING(pixmap_priv)   \
	(pixmap_priv->pending_op.type == GLAMOR_PENDING_NONE)

enum _glamor_pending_op_type{
    GLAMOR_PENDING_NONE,
    GLAMOR_PENDING_FILL
};

typedef struct _glamor_pending_fill {
    unsigned int type;
    GLfloat color4fv[4];
    CARD32  colori;
} glamor_pending_fill;

typedef union _glamor_pending_op {
    unsigned int type;
    glamor_pending_fill fill;
} glamor_pending_op;


Emma Anholt's avatar
Emma Anholt committed
310
typedef struct glamor_pixmap_private {
311
312
313
314
315
316
317
318
319
  unsigned char gl_fbo:1;
  unsigned char gl_tex:1;
  unsigned char pbo_valid:1;
  unsigned char is_picture:1;
  GLuint tex;			
  GLuint fb;
  GLuint pbo;                
  glamor_access_t access_mode;
  PictFormatShort pict_format;
320
  glamor_pending_op pending_op;
321
  PixmapPtr container;
Emma Anholt's avatar
Emma Anholt committed
322
323
} glamor_pixmap_private;

324
325
326
#define GLAMOR_CHECK_PENDING_FILL(_glamor_priv_, _pixmap_priv_) do \
  { \
      if (_pixmap_priv_->pending_op.type == GLAMOR_PENDING_FILL) { \
327
328
        glUseProgram(_glamor_priv_->solid_prog); \
        glUniform4fv(_glamor_priv_->solid_color_uniform_location, 1,  \
329
330
331
332
333
                        _pixmap_priv_->pending_op.fill.color4fv); \
      } \
  } while(0)
 

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* 
 * 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 {
  GLAMOR_NONE,
  GLAMOR_UPLOAD_PENDING,
  GLAMOR_UPLOAD_DONE,
  GLAMOR_UPLOAD_FAILED
} glamor_pixmap_status_t; 


351
extern DevPrivateKey glamor_screen_private_key;
Emma Anholt's avatar
Emma Anholt committed
352
extern DevPrivateKey glamor_pixmap_private_key;
353
354
355
static inline glamor_screen_private *
glamor_get_screen_private(ScreenPtr screen)
{
356
357
  return (glamor_screen_private *)dixLookupPrivate(&screen->devPrivates,
						   glamor_screen_private_key);
358
}
Emma Anholt's avatar
Emma Anholt committed
359
360
361
static inline glamor_pixmap_private *
glamor_get_pixmap_private(PixmapPtr pixmap)
{
362
  return dixLookupPrivate(&pixmap->devPrivates, glamor_pixmap_private_key);
Emma Anholt's avatar
Emma Anholt committed
363
}
364

365
366
367
368
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define ALIGN(i,m)	(((i) + (m) - 1) & ~((m) - 1))
#define MIN(a,b)	((a) < (b) ? (a) : (b))

369
/**
370
 * Borrow from uxa.
371
 */
372
373
static inline CARD32
format_for_depth(int depth)
374
{
375
376
377
378
379
380
381
382
383
384
385
386
387
  switch (depth) {
  case 1: return PICT_a1;
  case 4: return PICT_a4;
  case 8: return PICT_a8;
  case 15: return PICT_x1r5g5b5;
  case 16: return PICT_r5g6b5;
  default:
  case 24: return PICT_x8r8g8b8;
#if XORG_VERSION_CURRENT >= 10699900
  case 30: return PICT_x2r10g10b10;
#endif
  case 32: return PICT_a8r8g8b8;
  }
388
389
}

390
391
static inline CARD32
format_for_pixmap(PixmapPtr pixmap)
392
{
393
394
  glamor_pixmap_private *pixmap_priv;
  PictFormatShort pict_format;
395

396
397
398
399
400
401
402
  pixmap_priv = glamor_get_pixmap_private(pixmap);
  if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
    pict_format = pixmap_priv->pict_format;
  else
    pict_format = format_for_depth(pixmap->drawable.depth);

  return pict_format;
403
404
}

405
406
/*
 * Map picture's format to the correct gl texture format and type.
407
 * no_alpha is used to indicate whehter we need to wire alpha to 1. 
408
409
410
411
412
413
414
 *
 * Return 0 if find a matched texture type. Otherwise return -1.
 **/
static inline int 
glamor_get_tex_format_type_from_pictformat(PictFormatShort format,
					   GLenum *tex_format, 
					   GLenum *tex_type,
415
					   int *no_alpha)
416
{
417
  *no_alpha = 0;
418
419
420
421
422
423
  switch (format) {
  case PICT_a1:
    *tex_format = GL_COLOR_INDEX;
    *tex_type = GL_BITMAP;
    break;
  case PICT_b8g8r8x8:
424
    *no_alpha = 1;
425
426
427
428
429
430
  case PICT_b8g8r8a8:
    *tex_format = GL_BGRA;
    *tex_type = GL_UNSIGNED_INT_8_8_8_8;
    break;

  case PICT_x8r8g8b8:
431
    *no_alpha = 1;
432
433
434
435
436
  case PICT_a8r8g8b8:
    *tex_format = GL_BGRA;
    *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
    break;
  case PICT_x8b8g8r8:
437
    *no_alpha = 1;
438
439
440
441
442
  case PICT_a8b8g8r8:
    *tex_format = GL_RGBA;
    *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
    break;
  case PICT_x2r10g10b10:
443
    *no_alpha = 1;
444
445
446
447
448
  case PICT_a2r10g10b10:
    *tex_format = GL_BGRA;
    *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
    break;
  case PICT_x2b10g10r10:
449
    *no_alpha = 1;
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  case PICT_a2b10g10r10:
    *tex_format = GL_RGBA;
    *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
    break;
 
  case PICT_r5g6b5:
    *tex_format = GL_RGB;
    *tex_type = GL_UNSIGNED_SHORT_5_6_5;
    break;
  case PICT_b5g6r5:
    *tex_format = GL_RGB;
    *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
    break;
  case PICT_x1b5g5r5:
464
    *no_alpha = 1;
465
466
467
468
469
470
  case PICT_a1b5g5r5:
    *tex_format = GL_RGBA;
    *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
    break;
               
  case PICT_x1r5g5b5:
471
    *no_alpha = 1;
472
473
474
475
476
477
478
479
480
  case PICT_a1r5g5b5:
    *tex_format = GL_BGRA;
    *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
    break;
  case PICT_a8:
    *tex_format = GL_ALPHA;
    *tex_type = GL_UNSIGNED_BYTE;
    break;
  case PICT_x4r4g4b4:
481
    *no_alpha = 1;
482
483
484
485
486
487
  case PICT_a4r4g4b4:
    *tex_format = GL_BGRA;
    *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
    break;

  case PICT_x4b4g4r4:
488
    *no_alpha = 1;
489
490
491
492
493
494
495
496
497
498
  case PICT_a4b4g4r4:
    *tex_format = GL_RGBA;
    *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
    break;
 
  default:
    LogMessageVerb(X_INFO, 0, "fail to get matched format for %x \n", format);
    return -1;
  }
  return 0;
499
500
}

501
502
503
504
505
506

static inline int 
glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
                                       GLenum *format, 
                                       GLenum *type, 
                                       int *ax)
507
{
508
509
  glamor_pixmap_private *pixmap_priv;
  PictFormatShort pict_format;
510

511
512
513
514
515
516
517
518
  pixmap_priv = glamor_get_pixmap_private(pixmap);
  if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
    pict_format = pixmap_priv->pict_format;
  else
    pict_format = format_for_depth(pixmap->drawable.depth);

  return glamor_get_tex_format_type_from_pictformat(pict_format, 
						    format, type, ax);  
519
520
}

521
522
523
524
525
526
527
528
529

/* borrowed from uxa */
static inline Bool
glamor_get_rgba_from_pixel(CARD32 pixel,
			   float * red,
			   float * green,
			   float * blue,
			   float * alpha,
			   CARD32 format)
530
{
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
  int rbits, bbits, gbits, abits;
  int rshift, bshift, gshift, ashift;

  rbits = PICT_FORMAT_R(format);
  gbits = PICT_FORMAT_G(format);
  bbits = PICT_FORMAT_B(format);
  abits = PICT_FORMAT_A(format);

  if (PICT_FORMAT_TYPE(format) == PICT_TYPE_A) {
    rshift = gshift = bshift = ashift = 0;
  } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) {
    bshift = 0;
    gshift = bbits;
    rshift = gshift + gbits;
    ashift = rshift + rbits;
  } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
    rshift = 0;
    gshift = rbits;
    bshift = gshift + gbits;
    ashift = bshift + bbits;
#if XORG_VERSION_CURRENT >= 10699900
  } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
    ashift = 0;
    rshift = abits;
    if (abits == 0)
      rshift = PICT_FORMAT_BPP(format) - (rbits+gbits+bbits);
    gshift = rshift + rbits;
    bshift = gshift + gbits;
#endif
  } else {
    return FALSE;
  }
#define COLOR_INT_TO_FLOAT(_fc_, _p_, _s_, _bits_)	\
  *_fc_ = (((_p_) >> (_s_)) & (( 1 << (_bits_)) - 1))	\
    / (float)((1<<(_bits_)) - 1) 

  if (rbits) 
    COLOR_INT_TO_FLOAT(red, pixel, rshift, rbits);
  else
    *red = 0;

  if (gbits) 
    COLOR_INT_TO_FLOAT(green, pixel, gshift, gbits);
  else
    *green = 0;

  if (bbits) 
    COLOR_INT_TO_FLOAT(blue, pixel, bshift, bbits);
  else
    *blue = 0;

  if (abits) 
    COLOR_INT_TO_FLOAT(alpha, pixel, ashift, abits);
  else
    *alpha = 1;

  return TRUE;
}

590

591
592
593
594
595
596
597
598
599
/**
 * Returns TRUE if the given planemask covers all the significant bits in the
 * pixel values for pDrawable.
 */
static inline Bool
glamor_pm_is_solid(DrawablePtr drawable, unsigned long planemask)
{
  return (planemask & FbFullMask(drawable->depth)) ==
    FbFullMask(drawable->depth);
600
601
}

602
603
extern int glamor_debug_level;

604
605
606
/* glamor.c */
PixmapPtr glamor_get_drawable_pixmap(DrawablePtr drawable);

607
608
609
Bool glamor_close_screen(int idx, ScreenPtr screen);


610
611
612
613
/* glamor_copyarea.c */
RegionPtr
glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
		 int srcx, int srcy, int width, int height, int dstx, int dsty);
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
void
glamor_copy_n_to_n(DrawablePtr src,
		   DrawablePtr dst,
		   GCPtr gc,
		   BoxPtr box,
		   int nbox,
		   int		dx,
		   int		dy,
		   Bool		reverse,
		   Bool		upsidedown,
		   Pixel		bitplane,
		   void		*closure);

/* glamor_copywindow.c */
void glamor_copy_window(WindowPtr win, DDXPointRec old_origin,
			RegionPtr src_region);

631
/* glamor_core.c */
632
633
634
635
Bool glamor_prepare_access(DrawablePtr drawable, glamor_access_t access);
void glamor_finish_access(DrawablePtr drawable);
Bool glamor_prepare_access_window(WindowPtr window);
void glamor_finish_access_window(WindowPtr window);
636
637
Bool glamor_prepare_access_gc(GCPtr gc);
void glamor_finish_access_gc(GCPtr gc);
638
void glamor_init_finish_access_shaders(ScreenPtr screen);
639
const Bool glamor_get_drawable_location(const DrawablePtr drawable);
640
641
void glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap,
				int *x, int *y);
642
Bool glamor_create_gc(GCPtr gc);
643
Bool glamor_stipple(PixmapPtr pixmap, PixmapPtr stipple,
644
645
646
647
		    int x, int y, int width, int height,
		    unsigned char alu, unsigned long planemask,
		    unsigned long fg_pixel, unsigned long bg_pixel,
		    int stipple_x, int stipple_y);
648
649
650
651
GLint glamor_compile_glsl_prog(GLenum type, const char *source);
void glamor_link_glsl_prog(GLint prog);
void glamor_get_color_4f_from_pixel(PixmapPtr pixmap, unsigned long fg_pixel,
				    GLfloat *color);
652
653
654
655
656
657
658
659
660

int glamor_set_destination_pixmap(PixmapPtr pixmap);
int glamor_set_destination_pixmap_priv(glamor_pixmap_private *pixmap_priv);

/* nc means no check. caller must ensure this pixmap has valid fbo.
 * usually use the GLAMOR_PIXMAP_PRIV_HAS_FBO firstly. 
 * */
void glamor_set_destination_pixmap_priv_nc(glamor_pixmap_private *pixmap_priv);

661
void glamor_set_alu(unsigned char alu);
662
Bool glamor_set_planemask(PixmapPtr pixmap, unsigned long planemask);
663
664
665
666
void glamor_get_transform_uniform_locations(GLint prog,
					    glamor_transform_uniforms *uniform_locations);
void glamor_set_transform_for_pixmap(PixmapPtr pixmap,
				     glamor_transform_uniforms *uniform_locations);
667
668
Bool glamor_change_window_attributes(WindowPtr pWin, unsigned long mask);
RegionPtr glamor_bitmap_to_region(PixmapPtr pixmap);
Zhigang Gong's avatar
Zhigang Gong committed
669
670
671
672
673
674
675
676
677
Bool glamor_gl_has_extension(char *extension);
int  glamor_gl_get_version(void);

#define GLAMOR_GL_VERSION_ENCODE(major, minor) ( \
          ((major) * 256)                       \
        + ((minor) *   1))



678
679
680
681
682
683
684
685

/* glamor_fill.c */
void glamor_fill(DrawablePtr drawable,
		 GCPtr gc,
		 int x,
		 int y,
		 int width,
		 int height);
686
Bool glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
687
688
		  unsigned char alu, unsigned long planemask,
		  unsigned long fg_pixel);
689
690
void glamor_solid_fail_region(PixmapPtr pixmap,
			      int x, int y, int width, int height);
691
692
693
694
695
696
697
698

/* glamor_fillspans.c */
void glamor_fill_spans(DrawablePtr drawable,
		       GCPtr	gc,
		       int n,
		       DDXPointPtr points,
		       int *widths,
		       int sorted);
699

700
701
void glamor_init_solid_shader(ScreenPtr screen);

702
703
704
705
706
707
708
709
710
/* glamor_getspans.c */
void
glamor_get_spans(DrawablePtr drawable,
		 int wmax,
		 DDXPointPtr points,
		 int *widths,
		 int nspans,
		 char *dst_start);

711
712
713
714
715
716
717
718
719
720
/* glamor_glyphs.c */
void glamor_glyphs_init(ScreenPtr screen);
void glamor_glyphs_fini(ScreenPtr screen);
void glamor_glyphs(CARD8 op,
		   PicturePtr pSrc,
		   PicturePtr pDst,
		   PictFormatPtr maskFormat,
		   INT16 xSrc,
		   INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs);

721
722
723
724
/* glamor_setspans.c */
void glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
		      DDXPointPtr points, int *widths, int n, int sorted);

725
726
727
728
729
730
731
/* glamor_polyfillrect.c */
void
glamor_poly_fill_rect(DrawablePtr drawable,
		      GCPtr gc,
		      int nrect,
		      xRectangle *prect);

732
733
734
735
736
/* glamor_polylines.c */
void
glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n,
		  DDXPointPtr points);

737
738
739
740
/* glamor_putimage.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);
741
void glamor_init_putimage_shaders(ScreenPtr screen);
742

743
744
745
746
747
748
749
750
751
752
753
754
755
/* glamor_render.c */
void glamor_composite(CARD8 op,
		      PicturePtr pSrc,
		      PicturePtr pMask,
		      PicturePtr pDst,
		      INT16 xSrc,
		      INT16 ySrc,
		      INT16 xMask,
		      INT16 yMask,
		      INT16 xDst,
		      INT16 yDst,
		      CARD16 width,
		      CARD16 height);
Emma Anholt's avatar
Emma Anholt committed
756
757
758
759
void glamor_trapezoids(CARD8 op,
		       PicturePtr src, PicturePtr dst,
		       PictFormatPtr mask_format, INT16 x_src, INT16 y_src,
		       int ntrap, xTrapezoid *traps);
760
void glamor_init_composite_shaders(ScreenPtr screen);
761
762
763
void glamor_composite_rects(CARD8 op,
			    PicturePtr src, PicturePtr dst,
			    int nrect, glamor_composite_rect_t *rects);
764

765
/* glamor_tile.c */
766
Bool glamor_tile(PixmapPtr pixmap, PixmapPtr tile,
767
768
769
770
771
		 int x, int y, int width, int height,
		 unsigned char alu, unsigned long planemask,
		 int tile_x, int tile_y);
void glamor_init_tile_shader(ScreenPtr screen);

772
/* glamor_triangles.c */
773
774
void
glamor_triangles (CARD8	    op,
775
776
777
778
779
780
781
782
783
784
		  PicturePtr    pSrc,
		  PicturePtr    pDst,
		  PictFormatPtr maskFormat,
		  INT16	    xSrc,
		  INT16	    ySrc,
		  int	    ntris,
		  xTriangle    *tris);

/* glamor_pixmap.c */

785
786
void
glamor_pixmap_init(ScreenPtr screen);
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
/** 
 * Download a pixmap's texture to cpu memory. If success,
 * One copy of current pixmap's texture will be put into
 * the pixmap->devPrivate.ptr. Will use pbo to map to 
 * the pointer if possible.
 * The pixmap must be a gl texture pixmap. gl_fbo and
 * gl_tex must be 1. Used by glamor_prepare_access.
 *
 */
Bool 
glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access);

/**
 * Restore a pixmap's data which is downloaded by 
 * glamor_download_pixmap_to_cpu to its original 
 * gl texture. Used by glamor_finish_access. 
 *
 * The pixmap must be
 * in texture originally. In other word, the gl_fbo
 * must be 1.
 **/
void
glamor_restore_pixmap_to_texture(PixmapPtr pixmap);
810
811
812
813
814
815
816
817
818
819
/**
 * Ensure to have a fbo attached to the pixmap. 
 * If the pixmap already has one fbo then do nothing.
 * Otherwise, it will generate a new fbo, and bind
 * the pixmap's texture to the fbo. 
 * The pixmap must has a valid texture before call this
 * API, othersie, it will trigger a assert.
 */
void
glamor_pixmap_ensure_fb(PixmapPtr pixmap);
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842

/**
 * 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.
 */
enum glamor_pixmap_status 
glamor_upload_pixmap_to_texture(PixmapPtr pixmap);

/** 
 * Upload a picture to gl texture. Similar to the
 * glamor_upload_pixmap_to_texture. Used in rendering.
 **/
enum glamor_pixmap_status 
glamor_upload_picture_to_texture(PicturePtr picture);

/**
 * Destroy all the resources allocated on the uploading
 * phase, includs the tex and fbo.
 **/
void
glamor_destroy_upload_pixmap(PixmapPtr pixmap);

843
844
void
glamor_validate_pixmap(PixmapPtr pixmap);
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872

int
glamor_create_picture(PicturePtr picture);

Bool
glamor_prepare_access_picture(PicturePtr picture, glamor_access_t access);

void
glamor_finish_access_picture(PicturePtr picture);

void
glamor_destroy_picture(PicturePtr picture);

enum glamor_pixmap_status 
glamor_upload_picture_to_texture(PicturePtr picture);

void 
glamor_picture_format_fixup(PicturePtr picture, glamor_pixmap_private *pixmap_priv);

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


#define GLAMOR_PIXMAP_DYNAMIC_UPLOAD 
873
#define GLAMOR_DELAYED_FILLING
874

875
876
877

#include"glamor_utils.h" 

878
#endif /* GLAMOR_PRIV_H */