Subversion Repositories Kolibri OS

Rev

Rev 3769 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3254 Serge 1
/**************************************************************************
2
 
3
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4
Copyright © 2002 David Dawes
5
 
6
All Rights Reserved.
7
 
8
Permission is hereby granted, free of charge, to any person obtaining a
9
copy of this software and associated documentation files (the
10
"Software"), to deal in the Software without restriction, including
11
without limitation the rights to use, copy, modify, merge, publish,
12
distribute, sub license, and/or sell copies of the Software, and to
13
permit persons to whom the Software is furnished to do so, subject to
14
the following conditions:
15
 
16
The above copyright notice and this permission notice (including the
17
next paragraph) shall be included in all copies or substantial portions
18
of the Software.
19
 
20
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
24
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
 
28
**************************************************************************/
29
 
30
/*
31
 * Authors:
32
 *   Keith Whitwell 
33
 *   David Dawes 
34
 *
35
 */
36
 
37
#ifndef _SNA_H_
38
#define _SNA_H_
39
 
4251 Serge 40
#include 
41
 
3254 Serge 42
#ifdef HAVE_CONFIG_H
43
#include "config.h"
44
#endif
45
 
4251 Serge 46
#include "compiler.h"
47
 
48
 
3254 Serge 49
#include 
50
#include 
3263 Serge 51
#include 
4251 Serge 52
#include 
3254 Serge 53
 
54
#include "intel_driver.h"
55
#include "pciaccess.h"
56
 
4251 Serge 57
#include 
58
#include 
3254 Serge 59
 
4251 Serge 60
#ifdef HAVE_DRI2_H
61
#include 
62
#endif
3254 Serge 63
 
4251 Serge 64
#if HAVE_UDEV
65
#include 
66
#endif
3254 Serge 67
 
4251 Serge 68
#if 0
69
#include 
3254 Serge 70
 
4251 Serge 71
#include 
72
#if XF86_CRTC_VERSION >= 5
73
#define HAS_PIXMAP_SHARING 1
74
#endif
75
 
76
#include 
77
#include 
78
#include 
79
#include 
80
#include 
81
#include 
82
 
83
#include 
84
 
85
#include 
86
 
87
#include "../compat-api.h"
88
 
89
#endif
90
 
91
#include 
92
 
93
#define ErrorF printf
94
 
95
#if HAS_DEBUG_FULL
96
#define DBG(x) ErrorF x
97
#else
98
#define DBG(x)
99
#endif
100
 
101
#define DEBUG_NO_BLT 0
102
 
103
#define DEBUG_FLUSH_BATCH 0
104
 
105
#define TEST_ALL 0
106
#define TEST_ACCEL (TEST_ALL || 0)
107
#define TEST_BATCH (TEST_ALL || 0)
108
#define TEST_BLT (TEST_ALL || 0)
109
#define TEST_COMPOSITE (TEST_ALL || 0)
110
#define TEST_DAMAGE (TEST_ALL || 0)
111
#define TEST_GRADIENT (TEST_ALL || 0)
112
#define TEST_GLYPHS (TEST_ALL || 0)
113
#define TEST_IO (TEST_ALL || 0)
114
#define TEST_KGEM (TEST_ALL || 0)
115
#define TEST_RENDER (TEST_ALL || 0)
116
 
3258 Serge 117
int drmIoctl(int fd, unsigned long request, void *arg);
3254 Serge 118
 
3258 Serge 119
 
3254 Serge 120
#define PIXMAN_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) |    \
121
                                        ((type) << 16) |    \
122
                                        ((a) << 12)    |    \
123
                                        ((r) << 8) |        \
124
                                        ((g) << 4) |        \
125
                                        ((b)))
126
#define PIXMAN_TYPE_OTHER	0
127
#define PIXMAN_TYPE_A		1
128
#define PIXMAN_TYPE_ARGB	2
129
#define PIXMAN_TYPE_ABGR	3
130
#define PIXMAN_TYPE_COLOR	4
131
#define PIXMAN_TYPE_GRAY	5
132
#define PIXMAN_TYPE_YUY2	6
133
#define PIXMAN_TYPE_YV12	7
134
#define PIXMAN_TYPE_BGRA	8
135
#define PIXMAN_TYPE_RGBA	9
136
#define PIXMAN_TYPE_ARGB_SRGB	10
137
 
138
/* 32bpp formats */
139
typedef enum {
140
    PIXMAN_a8r8g8b8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,8,8,8,8),
141
    PIXMAN_x8r8g8b8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,8,8,8),
142
    PIXMAN_a8b8g8r8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,8,8,8,8),
143
    PIXMAN_x8b8g8r8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,0,8,8,8),
144
    PIXMAN_b8g8r8a8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,8,8,8,8),
145
    PIXMAN_b8g8r8x8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,0,8,8,8),
146
    PIXMAN_r8g8b8a8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,8,8,8,8),
147
    PIXMAN_r8g8b8x8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,0,8,8,8),
148
    PIXMAN_x14r6g6b6 =   PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,6,6,6),
149
    PIXMAN_x2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,10,10,10),
150
    PIXMAN_a2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,2,10,10,10),
151
    PIXMAN_x2b10g10r10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,0,10,10,10),
3278 Serge 152
    PIXMAN_a2b10g10r10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,2,10,10,10),
3254 Serge 153
 
4251 Serge 154
/* sRGB formats */
155
    PIXMAN_a8r8g8b8_sRGB = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB_SRGB,8,8,8,8),
156
 
157
/* 24bpp formats */
158
    PIXMAN_r8g8b8 =	 PIXMAN_FORMAT(24,PIXMAN_TYPE_ARGB,0,8,8,8),
159
    PIXMAN_b8g8r8 =	 PIXMAN_FORMAT(24,PIXMAN_TYPE_ABGR,0,8,8,8),
160
 
161
/* 16bpp formats */
162
    PIXMAN_r5g6b5 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,0,5,6,5),
163
    PIXMAN_b5g6r5 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,0,5,6,5),
164
 
165
    PIXMAN_a1r5g5b5 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,1,5,5,5),
166
    PIXMAN_x1r5g5b5 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,0,5,5,5),
167
    PIXMAN_a1b5g5r5 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,1,5,5,5),
168
    PIXMAN_x1b5g5r5 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,0,5,5,5),
169
    PIXMAN_a4r4g4b4 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,4,4,4,4),
170
    PIXMAN_x4r4g4b4 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,0,4,4,4),
171
    PIXMAN_a4b4g4r4 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,4,4,4,4),
172
    PIXMAN_x4b4g4r4 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,0,4,4,4),
173
 
174
/* 8bpp formats */
175
    PIXMAN_a8 =		 PIXMAN_FORMAT(8,PIXMAN_TYPE_A,8,0,0,0),
176
    PIXMAN_r3g3b2 =	 PIXMAN_FORMAT(8,PIXMAN_TYPE_ARGB,0,3,3,2),
177
    PIXMAN_b2g3r3 =	 PIXMAN_FORMAT(8,PIXMAN_TYPE_ABGR,0,3,3,2),
178
    PIXMAN_a2r2g2b2 =	 PIXMAN_FORMAT(8,PIXMAN_TYPE_ARGB,2,2,2,2),
179
    PIXMAN_a2b2g2r2 =	 PIXMAN_FORMAT(8,PIXMAN_TYPE_ABGR,2,2,2,2),
180
 
181
    PIXMAN_c8 =		 PIXMAN_FORMAT(8,PIXMAN_TYPE_COLOR,0,0,0,0),
182
    PIXMAN_g8 =		 PIXMAN_FORMAT(8,PIXMAN_TYPE_GRAY,0,0,0,0),
183
 
184
    PIXMAN_x4a4 =	 PIXMAN_FORMAT(8,PIXMAN_TYPE_A,4,0,0,0),
185
 
186
    PIXMAN_x4c4 =	 PIXMAN_FORMAT(8,PIXMAN_TYPE_COLOR,0,0,0,0),
187
    PIXMAN_x4g4 =	 PIXMAN_FORMAT(8,PIXMAN_TYPE_GRAY,0,0,0,0),
188
 
189
/* 4bpp formats */
190
    PIXMAN_a4 =		 PIXMAN_FORMAT(4,PIXMAN_TYPE_A,4,0,0,0),
191
    PIXMAN_r1g2b1 =	 PIXMAN_FORMAT(4,PIXMAN_TYPE_ARGB,0,1,2,1),
192
    PIXMAN_b1g2r1 =	 PIXMAN_FORMAT(4,PIXMAN_TYPE_ABGR,0,1,2,1),
193
    PIXMAN_a1r1g1b1 =	 PIXMAN_FORMAT(4,PIXMAN_TYPE_ARGB,1,1,1,1),
194
    PIXMAN_a1b1g1r1 =	 PIXMAN_FORMAT(4,PIXMAN_TYPE_ABGR,1,1,1,1),
195
 
196
    PIXMAN_c4 =		 PIXMAN_FORMAT(4,PIXMAN_TYPE_COLOR,0,0,0,0),
197
    PIXMAN_g4 =		 PIXMAN_FORMAT(4,PIXMAN_TYPE_GRAY,0,0,0,0),
198
 
199
/* 1bpp formats */
200
    PIXMAN_a1 =		 PIXMAN_FORMAT(1,PIXMAN_TYPE_A,1,0,0,0),
201
 
202
    PIXMAN_g1 =		 PIXMAN_FORMAT(1,PIXMAN_TYPE_GRAY,0,0,0,0),
203
 
204
/* YUV formats */
205
    PIXMAN_yuy2 =	 PIXMAN_FORMAT(16,PIXMAN_TYPE_YUY2,0,0,0,0),
206
    PIXMAN_yv12 =	 PIXMAN_FORMAT(12,PIXMAN_TYPE_YV12,0,0,0,0)
207
 
3254 Serge 208
} pixman_format_code_t;
209
 
3278 Serge 210
typedef enum _PictFormatShort {
3254 Serge 211
 
4251 Serge 212
    PICT_a2r10g10b10 = PIXMAN_a2r10g10b10,
213
    PICT_x2r10g10b10 = PIXMAN_x2r10g10b10,
214
    PICT_a2b10g10r10 = PIXMAN_a2b10g10r10,
215
    PICT_x2b10g10r10 = PIXMAN_x2b10g10r10,
216
 
3278 Serge 217
    PICT_a8r8g8b8 = PIXMAN_a8r8g8b8,
218
    PICT_x8r8g8b8 = PIXMAN_x8r8g8b8,
219
    PICT_a8b8g8r8 = PIXMAN_a8b8g8r8,
220
    PICT_x8b8g8r8 = PIXMAN_x8b8g8r8,
221
    PICT_b8g8r8a8 = PIXMAN_b8g8r8a8,
222
    PICT_b8g8r8x8 = PIXMAN_b8g8r8x8,
223
 
4251 Serge 224
/* 24bpp formats */
225
    PICT_r8g8b8 = PIXMAN_r8g8b8,
226
    PICT_b8g8r8 = PIXMAN_b8g8r8,
227
 
228
/* 16bpp formats */
229
    PICT_r5g6b5 = PIXMAN_r5g6b5,
230
    PICT_b5g6r5 = PIXMAN_b5g6r5,
231
 
232
    PICT_a1r5g5b5 = PIXMAN_a1r5g5b5,
233
    PICT_x1r5g5b5 = PIXMAN_x1r5g5b5,
234
    PICT_a1b5g5r5 = PIXMAN_a1b5g5r5,
235
    PICT_x1b5g5r5 = PIXMAN_x1b5g5r5,
236
    PICT_a4r4g4b4 = PIXMAN_a4r4g4b4,
237
    PICT_x4r4g4b4 = PIXMAN_x4r4g4b4,
238
    PICT_a4b4g4r4 = PIXMAN_a4b4g4r4,
239
    PICT_x4b4g4r4 = PIXMAN_x4b4g4r4,
240
 
3278 Serge 241
/* 8bpp formats */
242
    PICT_a8 = PIXMAN_a8,
4251 Serge 243
    PICT_r3g3b2 = PIXMAN_r3g3b2,
244
    PICT_b2g3r3 = PIXMAN_b2g3r3,
245
    PICT_a2r2g2b2 = PIXMAN_a2r2g2b2,
246
    PICT_a2b2g2r2 = PIXMAN_a2b2g2r2,
3278 Serge 247
 
4251 Serge 248
    PICT_c8 = PIXMAN_c8,
249
    PICT_g8 = PIXMAN_g8,
250
 
251
    PICT_x4a4 = PIXMAN_x4a4,
252
 
253
    PICT_x4c4 = PIXMAN_x4c4,
254
    PICT_x4g4 = PIXMAN_x4g4,
255
 
3278 Serge 256
/* 4bpp formats */
4251 Serge 257
    PICT_a4 = PIXMAN_a4,
258
    PICT_r1g2b1 = PIXMAN_r1g2b1,
259
    PICT_b1g2r1 = PIXMAN_b1g2r1,
260
    PICT_a1r1g1b1 = PIXMAN_a1r1g1b1,
261
    PICT_a1b1g1r1 = PIXMAN_a1b1g1r1,
262
 
263
    PICT_c4 = PIXMAN_c4,
264
    PICT_g4 = PIXMAN_g4,
265
 
266
/* 1bpp formats */
267
    PICT_a1 = PIXMAN_a1,
268
 
269
    PICT_g1 = PIXMAN_g1
3278 Serge 270
} PictFormatShort;
271
 
3291 Serge 272
#define PIXMAN_FORMAT_A(f)	(((f) >> 12) & 0x0f)
3299 Serge 273
#define PIXMAN_FORMAT_RGB(f)	(((f)      ) & 0xfff)
3291 Serge 274
 
275
#define PICT_FORMAT_A(f)	PIXMAN_FORMAT_A(f)
276
 
3278 Serge 277
#define RepeatNone                          0
278
#define RepeatNormal                        1
279
#define RepeatPad                           2
280
#define RepeatReflect                       3
281
 
282
#define PictFilterNearest	0
283
#define PictFilterBilinear	1
284
 
285
#define PictFilterFast		2
286
#define PictFilterGood		3
287
#define PictFilterBest		4
288
 
289
#define PictFilterConvolution	5
290
 
291
typedef int32_t			pixman_fixed_16_16_t;
292
typedef pixman_fixed_16_16_t	pixman_fixed_t;
293
 
294
struct pixman_transform
295
{
296
    pixman_fixed_t	matrix[3][3];
297
};
298
 
3254 Serge 299
typedef unsigned long   Picture;
300
typedef unsigned long   PictFormat;
301
 
302
typedef struct _Pixmap  *PixmapPtr;
303
typedef struct _Picture *PicturePtr;
3278 Serge 304
typedef struct _Drawable *DrawablePtr;
305
typedef struct _PictFormat *PictFormatPtr;
3254 Serge 306
 
3278 Serge 307
typedef struct pixman_transform PictTransform, *PictTransformPtr;
308
 
309
 
310
 
3254 Serge 311
typedef struct _Drawable {
312
    unsigned char type;         /* DRAWABLE_ */
313
    unsigned char class;        /* specific to type */
314
    unsigned char depth;
315
    unsigned char bitsPerPixel;
316
    unsigned int   id;           /* resource id */
317
    short x;                    /* window: screen absolute, pixmap: 0 */
318
    short y;                    /* window: screen absolute, pixmap: 0 */
319
    unsigned short width;
320
    unsigned short height;
321
} DrawableRec;
322
 
323
/*
324
 * PIXMAP -- device dependent
325
 */
326
 
327
typedef struct _Pixmap {
328
    DrawableRec drawable;
329
//    PrivateRec *devPrivates;
330
    int refcnt;
331
    int devKind;                /* This is the pitch of the pixmap, typically width*bpp/8. */
332
//    DevUnion devPrivate;        /* When !NULL, devPrivate.ptr points to the raw pixel data. */
333
#ifdef COMPOSITE
334
    short screen_x;
335
    short screen_y;
336
#endif
337
    unsigned usage_hint;        /* see CREATE_PIXMAP_USAGE_* */
338
 
339
    PixmapPtr master_pixmap;    /* pointer to master copy of pixmap for pixmap sharing */
340
} PixmapRec;
341
 
3278 Serge 342
typedef struct _PictFormat {
343
    uint32_t id;
344
    uint32_t format;              /* except bpp */
345
    unsigned char type;
346
    unsigned char depth;
347
//    DirectFormatRec direct;
348
//   IndexFormatRec index;
349
} PictFormatRec;
3254 Serge 350
 
3278 Serge 351
typedef struct _Picture {
352
    DrawablePtr pDrawable;
353
//    PictFormatPtr pFormat;
354
    PictFormatShort format;     /* PICT_FORMAT */
355
    int refcnt;
356
    uint32_t id;
357
    unsigned int repeat:1;
358
    unsigned int graphicsExposures:1;
359
    unsigned int subWindowMode:1;
360
    unsigned int polyEdge:1;
361
    unsigned int polyMode:1;
362
    unsigned int freeCompClip:1;
363
    unsigned int clientClipType:2;
364
    unsigned int componentAlpha:1;
365
    unsigned int repeatType:2;
366
    unsigned int filter:3;
367
//    unsigned int stateChanges:CPLastBit;
368
//    unsigned int unused:18 - CPLastBit;
369
 
370
//    PicturePtr alphaMap;
371
 
372
//    PictTransform *transform;
373
 
374
//    SourcePictPtr pSourcePict;
375
//    xFixed *filter_params;
376
//    int filter_nparams;
377
} PictureRec;
378
 
379
#define PolyModePrecise			    0
380
#define PolyModeImprecise		    1
381
 
382
 
3263 Serge 383
struct sna_fb
384
{
385
    uint32_t  width;
386
    uint32_t  height;
387
    uint32_t  pitch;
388
    uint32_t  tiling;
4251 Serge 389
 
3263 Serge 390
    struct kgem_bo *fb_bo;
391
};
3254 Serge 392
 
393
struct pixman_box16
394
{
395
    int16_t x1, y1, x2, y2;
396
};
397
 
398
typedef struct pixman_box16 BoxRec;
399
typedef unsigned int   CARD32;
400
typedef unsigned short CARD16;
401
 
402
#include "sna_render.h"
403
#include "kgem.h"
404
 
405
#define GXclear                 0x0
406
#define GXcopy                  0x3
407
 
408
#define PictOpClear             0
409
#define PictOpSrc               1
410
#define PictOpDst               2
411
#define PictOpOver              3
412
#define PictOpOverReverse       4
413
#define PictOpIn                5
414
#define PictOpInReverse         6
415
#define PictOpOut               7
416
#define PictOpOutReverse        8
417
#define PictOpAtop              9
418
#define PictOpAtopReverse       10
419
#define PictOpXor               11
420
#define PictOpAdd               12
421
#define PictOpSaturate          13
422
#define PictOpMaximum           13
423
 
424
 
4251 Serge 425
#define SNA_CURSOR_X			64
426
#define SNA_CURSOR_Y			SNA_CURSOR_X
3254 Serge 427
 
4251 Serge 428
struct sna_client {
429
	int is_compositor; /* only 4 bits used */
430
};
431
 
432
 
433
//#define assert(x)
434
 
435
 
3254 Serge 436
struct sna {
4251 Serge 437
	struct kgem kgem;
438
 
439
	unsigned scrn;
440
 
3254 Serge 441
    unsigned flags;
442
#define SNA_NO_WAIT		0x1
443
#define SNA_NO_FLIP		0x2
444
#define SNA_TRIPLE_BUFFER	0x4
445
#define SNA_TEAR_FREE		0x10
446
#define SNA_FORCE_SHADOW	0x20
4251 Serge 447
#define SNA_FLUSH_GTT		0x40
448
#define SNA_IS_HOSTED		0x80
449
#define SNA_PERFORMANCE		0x100
450
#define SNA_POWERSAVE		0x200
451
#define SNA_REPROBE		0x80000000
3254 Serge 452
 
4251 Serge 453
	unsigned cpu_features;
454
#define MMX 0x1
455
#define SSE 0x2
456
#define SSE2 0x4
457
#define SSE3 0x8
458
#define SSSE3 0x10
459
#define SSE4_1 0x20
460
#define SSE4_2 0x40
461
#define AVX 0x80
462
#define AVX2 0x100
463
 
3254 Serge 464
	struct list flush_pixmaps;
465
	struct list active_pixmaps;
466
 
467
 
468
 
469
 
470
 
471
    unsigned int tiling;
472
#define SNA_TILING_FB       0x1
473
#define SNA_TILING_2D       0x2
474
#define SNA_TILING_ALL     (~0)
475
 
476
	struct pci_device *PciInfo;
477
	const struct intel_device_info *info;
478
 
479
//    PicturePtr clear;
480
    struct {
481
        uint32_t fill_bo;
482
        uint32_t fill_pixel;
483
        uint32_t fill_alu;
484
    } blt_state;
485
    union {
3280 Serge 486
        struct gen3_render_state gen3;
487
        struct gen4_render_state gen4;
488
        struct gen5_render_state gen5;
3254 Serge 489
        struct gen6_render_state gen6;
490
		struct gen7_render_state gen7;
491
    } render_state;
492
 
493
 
494
    /* Broken-out options. */
495
//    OptionInfoPtr Options;
496
 
497
    /* Driver phase/state information */
498
//    Bool suspended;
499
 
500
    struct sna_render render;
501
 
502
#if DEBUG_MEMORY
503
	struct {
4251 Serge 504
		int pixmap_allocs;
3254 Serge 505
	       int cpu_bo_allocs;
506
	       size_t shadow_pixels_bytes;
507
	       size_t cpu_bo_bytes;
508
	} debug_memory;
509
#endif
510
};
511
 
3280 Serge 512
static inline struct sna *
513
to_sna_from_kgem(struct kgem *kgem)
514
{
515
	return container_of(kgem, struct sna, kgem);
516
}
3254 Serge 517
 
518
#ifndef ARRAY_SIZE
519
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
520
#endif
521
 
522
#ifndef ALIGN
523
#define ALIGN(i,m)	(((i) + (m) - 1) & ~((m) - 1))
524
#endif
525
 
526
#ifndef MIN
527
#define MIN(a,b)	((a) <= (b) ? (a) : (b))
528
#endif
529
 
530
#ifndef MAX
531
#define MAX(a,b)	((a) >= (b) ? (a) : (b))
532
#endif
4251 Serge 533
static inline bool
534
_sna_transform_point(const PictTransform *transform,
535
		     int64_t x, int64_t y, int64_t result[3])
536
{
537
	int j;
538
 
539
	for (j = 0; j < 3; j++)
540
		result[j] = (transform->matrix[j][0] * x +
541
			     transform->matrix[j][1] * y +
542
			     transform->matrix[j][2]);
543
 
544
	return result[2] != 0;
545
}
546
 
547
static inline void
548
_sna_get_transformed_coordinates(int x, int y,
549
				 const PictTransform *transform,
550
				 float *x_out, float *y_out)
551
{
552
 
553
	int64_t result[3];
554
 
555
	_sna_transform_point(transform, x, y, result);
556
	*x_out = result[0] / (double)result[2];
557
	*y_out = result[1] / (double)result[2];
558
}
559
 
560
static inline void
561
_sna_get_transformed_scaled(int x, int y,
562
			    const PictTransform *transform, const float *sf,
563
			    float *x_out, float *y_out)
564
{
565
	*x_out = sf[0] * (transform->matrix[0][0] * x +
566
			  transform->matrix[0][1] * y +
567
			  transform->matrix[0][2]);
568
 
569
	*y_out = sf[1] * (transform->matrix[1][0] * x +
570
			  transform->matrix[1][1] * y +
571
			  transform->matrix[1][2]);
572
}
573
 
574
void
575
sna_get_transformed_coordinates(int x, int y,
576
				const PictTransform *transform,
577
				float *x_out, float *y_out);
578
 
579
void
580
sna_get_transformed_coordinates_3d(int x, int y,
581
				   const PictTransform *transform,
582
				   float *x_out, float *y_out, float *z_out);
583
 
584
bool sna_transform_is_affine(const PictTransform *t);
585
bool sna_transform_is_integer_translation(const PictTransform *t,
586
					  int16_t *tx, int16_t *ty);
587
bool sna_transform_is_translation(const PictTransform *t,
588
				  pixman_fixed_t *tx, pixman_fixed_t *ty);
589
static inline bool
590
sna_affine_transform_is_rotation(const PictTransform *t)
591
{
592
	assert(sna_transform_is_affine(t));
593
	return t->matrix[0][1] | t->matrix[1][0];
594
}
595
 
596
static inline bool
597
sna_transform_equal(const PictTransform *a, const PictTransform *b)
598
{
599
	if (a == b)
600
		return true;
601
 
602
	if (a == NULL || b == NULL)
603
		return false;
604
 
605
	return memcmp(a, b, sizeof(*a)) == 0;
606
}
3254 Serge 607
#endif /* _SNA_H */