Initial code release
[adaptation/xorg-x11-drv-intel.git] / uxa / uxa-priv.h
1 /*
2  *
3  * Copyright © 2000,2008 Keith Packard
4  *             2005 Zack Rusin, Trolltech
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of Keith Packard not be used in
11  * advertising or publicity pertaining to distribution of the software without
12  * specific, written prior permission.  Keith Packard makes no
13  * representations about the suitability of this software for any purpose.  It
14  * is provided "as is" without express or implied warranty.
15  *
16  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
21  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
22  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23  * SOFTWARE.
24  */
25
26 #ifndef UXAPRIV_H
27 #define UXAPRIV_H
28
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 #ifdef HAVE_DIX_CONFIG_H
33 #include <dix-config.h>
34 #else
35 #include <xorg-server.h>
36 #endif
37 #include "xf86.h"
38
39 #include "uxa.h"
40
41 #include <X11/X.h>
42 #include <X11/Xproto.h>
43 #include "scrnintstr.h"
44 #include "pixmapstr.h"
45 #include "windowstr.h"
46 #include "servermd.h"
47 #include "mibstore.h"
48 #include "colormapst.h"
49 #include "gcstruct.h"
50 #include "input.h"
51 #include "mipointer.h"
52 #include "mi.h"
53 #include "dix.h"
54 #include "fb.h"
55 #include "fboverlay.h"
56 #ifdef RENDER
57 //#include "fbpict.h"
58 #include "glyphstr.h"
59 #endif
60 #include "damage.h"
61
62 /* Provide substitutes for gcc's __FUNCTION__ on other compilers */
63 #if !defined(__GNUC__) && !defined(__FUNCTION__)
64 # if defined(__STDC__) && (__STDC_VERSION__>=199901L)   /* C99 */
65 #  define __FUNCTION__ __func__
66 # else
67 #  define __FUNCTION__ ""
68 # endif
69 #endif
70
71 /* 1.6 and earlier server compat */
72 #ifndef miGetCompositeClip
73 #define miCopyRegion fbCopyRegion
74 #define miDoCopy fbDoCopy
75 #endif
76
77 #define DEBUG_MIGRATE           0
78 #define DEBUG_PIXMAP            0
79 #define DEBUG_OFFSCREEN         0
80 #define DEBUG_GLYPH_CACHE       0
81
82 #define UXA_FALLBACK(x)                                         \
83 if (uxa_get_screen(screen)->fallback_debug) {                   \
84         ErrorF("UXA fallback at %s: ", __FUNCTION__);           \
85         ErrorF x;                                               \
86 }
87
88 char uxa_drawable_location(DrawablePtr pDrawable);
89
90 #if DEBUG_PIXMAP
91 #define DBG_PIXMAP(a) ErrorF a
92 #else
93 #define DBG_PIXMAP(a)
94 #endif
95
96 typedef struct {
97         PicturePtr picture;     /* Where the glyphs of the cache are stored */
98         GlyphPtr *glyphs;
99         uint16_t count;
100         uint16_t evict;
101 } uxa_glyph_cache_t;
102
103 #define UXA_NUM_GLYPH_CACHE_FORMATS 2
104
105 typedef struct {
106         uint32_t color;
107         PicturePtr picture;
108 } uxa_solid_cache_t;
109
110 #define UXA_NUM_SOLID_CACHE 16
111
112 typedef void (*EnableDisableFBAccessProcPtr) (int, Bool);
113 typedef struct {
114         uxa_driver_t *info;
115         CreateGCProcPtr SavedCreateGC;
116         CloseScreenProcPtr SavedCloseScreen;
117         GetImageProcPtr SavedGetImage;
118         GetSpansProcPtr SavedGetSpans;
119         CreatePixmapProcPtr SavedCreatePixmap;
120         DestroyPixmapProcPtr SavedDestroyPixmap;
121         CopyWindowProcPtr SavedCopyWindow;
122         ChangeWindowAttributesProcPtr SavedChangeWindowAttributes;
123         BitmapToRegionProcPtr SavedBitmapToRegion;
124 #ifdef RENDER
125         CompositeProcPtr SavedComposite;
126         CompositeRectsProcPtr SavedCompositeRects;
127         TrianglesProcPtr SavedTriangles;
128         GlyphsProcPtr SavedGlyphs;
129         TrapezoidsProcPtr SavedTrapezoids;
130         AddTrapsProcPtr SavedAddTraps;
131         UnrealizeGlyphProcPtr SavedUnrealizeGlyph;
132 #endif
133         EnableDisableFBAccessProcPtr SavedEnableDisableFBAccess;
134
135         Bool force_fallback;
136         Bool fallback_debug;
137         Bool swappedOut;
138         unsigned disableFbCount;
139         unsigned offScreenCounter;
140
141         uxa_glyph_cache_t glyphCaches[UXA_NUM_GLYPH_CACHE_FORMATS];
142         Bool glyph_cache_initialized;
143
144         PicturePtr solid_clear, solid_black, solid_white;
145         uxa_solid_cache_t solid_cache[UXA_NUM_SOLID_CACHE];
146         int solid_cache_size;
147 } uxa_screen_t;
148
149 /*
150  * This is the only completely portable way to
151  * compute this info.
152  */
153 #ifndef BitsPerPixel
154 #define BitsPerPixel(d) (\
155     PixmapWidthPaddingInfo[d].notPower2 ? \
156     (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
157     ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
158     (PixmapWidthPaddingInfo[d].padRoundUp+1)))
159 #endif
160
161 #if HAS_DEVPRIVATEKEYREC
162 extern DevPrivateKeyRec uxa_screen_index;
163 #else
164 extern int uxa_screen_index;
165 #endif
166
167 static inline uxa_screen_t *uxa_get_screen(ScreenPtr screen)
168 {
169 #if HAS_DEVPRIVATEKEYREC
170         return dixGetPrivate(&screen->devPrivates, &uxa_screen_index);
171 #else
172         return dixLookupPrivate(&screen->devPrivates, &uxa_screen_index);
173 #endif
174 }
175
176 /** Align an offset to an arbitrary alignment */
177 #define UXA_ALIGN(offset, align) (((offset) + (align) - 1) - \
178         (((offset) + (align) - 1) % (align)))
179 /** Align an offset to a power-of-two alignment */
180 #define UXA_ALIGN2(offset, align) (((offset) + (align) - 1) & ~((align) - 1))
181
182 typedef struct {
183         INT16 xSrc;
184         INT16 ySrc;
185         INT16 xDst;
186         INT16 yDst;
187         INT16 width;
188         INT16 height;
189 } uxa_composite_rect_t;
190
191 /**
192  * exaDDXDriverInit must be implemented by the DDX using EXA, and is the place
193  * to set EXA options or hook in screen functions to handle using EXA as the AA.
194   */
195 void exaDDXDriverInit(ScreenPtr pScreen);
196
197 Bool uxa_prepare_access_window(WindowPtr pWin);
198
199 void uxa_finish_access_window(WindowPtr pWin);
200
201 /* uxa-unaccel.c */
202 Bool uxa_prepare_access_gc(GCPtr pGC);
203
204 void uxa_finish_access_gc(GCPtr pGC);
205
206 void
207 uxa_check_fill_spans(DrawablePtr pDrawable, GCPtr pGC, int nspans,
208                      DDXPointPtr ppt, int *pwidth, int fSorted);
209
210 void
211 uxa_check_set_spans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
212                     DDXPointPtr ppt, int *pwidth, int nspans, int fSorted);
213
214 void
215 uxa_check_put_image(DrawablePtr pDrawable, GCPtr pGC, int depth,
216                     int x, int y, int w, int h, int leftPad, int format,
217                     char *bits);
218
219 RegionPtr
220 uxa_check_copy_area(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
221                     int srcx, int srcy, int w, int h, int dstx, int dsty);
222
223 RegionPtr
224 uxa_check_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
225                      int srcx, int srcy, int w, int h, int dstx, int dsty,
226                      unsigned long bitPlane);
227
228 void
229 uxa_check_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
230                      DDXPointPtr pptInit);
231
232 void
233 uxa_check_poly_lines(DrawablePtr pDrawable, GCPtr pGC,
234                      int mode, int npt, DDXPointPtr ppt);
235
236 void
237 uxa_check_poly_segment(DrawablePtr pDrawable, GCPtr pGC,
238                        int nsegInit, xSegment * pSegInit);
239
240 void
241 uxa_check_poly_arc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc * pArcs);
242
243 void
244 uxa_check_poly_fill_rect(DrawablePtr pDrawable, GCPtr pGC,
245                          int nrect, xRectangle * prect);
246
247 void
248 uxa_check_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
249                           int x, int y, unsigned int nglyph,
250                           CharInfoPtr * ppci, pointer pglyphBase);
251
252 void
253 uxa_check_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
254                          int x, int y, unsigned int nglyph,
255                          CharInfoPtr * ppci, pointer pglyphBase);
256
257 void
258 uxa_check_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
259                       DrawablePtr pDrawable, int w, int h, int x, int y);
260
261 void
262 uxa_check_get_spans(DrawablePtr pDrawable,
263                     int wMax,
264                     DDXPointPtr ppt, int *pwidth, int nspans, char *pdstStart);
265
266 void uxa_check_paint_window(WindowPtr pWin, RegionPtr pRegion, int what);
267
268 void
269 uxa_check_add_traps(PicturePtr pPicture,
270                     INT16 x_off, INT16 y_off, int ntrap, xTrap * traps);
271
272 /* uxa-accel.c */
273
274 static _X_INLINE Bool
275 uxa_gc_reads_destination(DrawablePtr pDrawable, unsigned long planemask,
276                          unsigned int fillStyle, unsigned char alu)
277 {
278         return ((alu != GXcopy && alu != GXclear && alu != GXset &&
279                  alu != GXcopyInverted) || fillStyle == FillStippled ||
280                 !UXA_PM_IS_SOLID(pDrawable, planemask));
281 }
282
283 void uxa_copy_window(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
284
285 Bool
286 uxa_fill_region_tiled(DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile,
287                       DDXPointPtr pPatOrg, CARD32 planemask, CARD32 alu);
288
289 void uxa_paint_window(WindowPtr pWin, RegionPtr pRegion, int what);
290
291 void
292 uxa_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
293               unsigned int format, unsigned long planeMask, char *d);
294
295 extern const GCOps uxa_ops;
296
297 #ifdef RENDER
298
299 /* XXX these are in fbpict.h, which is not installed */
300 void
301 fbComposite(CARD8 op,
302             PicturePtr pSrc,
303             PicturePtr pMask,
304             PicturePtr pDst,
305             INT16 xSrc,
306             INT16 ySrc,
307             INT16 xMask,
308             INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
309
310 void
311 fbAddTraps(PicturePtr pPicture,
312            INT16 xOff, INT16 yOff, int ntrap, xTrap * traps);
313
314 void
315 uxa_check_composite(CARD8 op,
316                     PicturePtr pSrc,
317                     PicturePtr pMask,
318                     PicturePtr pDst,
319                     INT16 xSrc,
320                     INT16 ySrc,
321                     INT16 xMask,
322                     INT16 yMask,
323                     INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
324 #endif
325
326 /* uxa.c */
327 Bool uxa_prepare_access(DrawablePtr pDrawable, uxa_access_t access);
328
329 void uxa_finish_access(DrawablePtr pDrawable);
330
331 void
332 uxa_get_drawable_deltas(DrawablePtr pDrawable, PixmapPtr pPixmap,
333                         int *xp, int *yp);
334
335 Bool uxa_drawable_is_offscreen(DrawablePtr pDrawable);
336
337 Bool uxa_pixmap_is_offscreen(PixmapPtr p);
338
339 PixmapPtr uxa_get_offscreen_pixmap(DrawablePtr pDrawable, int *xp, int *yp);
340
341 PixmapPtr uxa_get_drawable_pixmap(DrawablePtr pDrawable);
342
343 RegionPtr
344 uxa_copy_area(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
345               int srcx, int srcy, int width, int height, int dstx, int dsty);
346
347 void
348 uxa_copy_n_to_n(DrawablePtr pSrcDrawable,
349                 DrawablePtr pDstDrawable,
350                 GCPtr pGC,
351                 BoxPtr pbox,
352                 int nbox,
353                 int dx,
354                 int dy,
355                 Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
356
357 /* uxa_render.c */
358 Bool uxa_op_reads_destination(CARD8 op);
359
360 void
361 uxa_composite(CARD8 op,
362               PicturePtr pSrc,
363               PicturePtr pMask,
364               PicturePtr pDst,
365               INT16 xSrc,
366               INT16 ySrc,
367               INT16 xMask,
368               INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
369
370 void
371 uxa_composite_rects(CARD8 op,
372                     PicturePtr pSrc,
373                     PicturePtr pDst, int nrect, uxa_composite_rect_t * rects);
374
375 void
376 uxa_solid_rects (CARD8          op,
377                  PicturePtr     dst,
378                  xRenderColor  *color,
379                  int            num_rects,
380                  xRectangle    *rects);
381
382 void
383 uxa_trapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
384                PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
385                int ntrap, xTrapezoid * traps);
386
387 void
388 uxa_triangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
389               PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
390               int ntri, xTriangle * tris);
391
392 PicturePtr
393 uxa_acquire_solid(ScreenPtr screen, SourcePict *source);
394
395 PicturePtr
396 uxa_acquire_drawable(ScreenPtr pScreen,
397                      PicturePtr pSrc,
398                      INT16 x, INT16 y,
399                      CARD16 width, CARD16 height,
400                      INT16 * out_x, INT16 * out_y);
401
402 PicturePtr
403 uxa_acquire_pattern(ScreenPtr pScreen,
404                     PicturePtr pSrc,
405                     pixman_format_code_t format,
406                     INT16 x, INT16 y,
407                     CARD16 width, CARD16 height);
408
409 Bool
410 uxa_get_rgba_from_pixel(CARD32 pixel,
411                         CARD16 * red,
412                         CARD16 * green,
413                         CARD16 * blue,
414                         CARD16 * alpha,
415                         CARD32 format);
416
417 /* uxa_glyph.c */
418 Bool uxa_glyphs_init(ScreenPtr pScreen);
419
420 void uxa_glyphs_fini(ScreenPtr pScreen);
421
422 void
423 uxa_glyphs(CARD8 op,
424            PicturePtr pSrc,
425            PicturePtr pDst,
426            PictFormatPtr maskFormat,
427            INT16 xSrc,
428            INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs);
429
430 void
431 uxa_glyph_unrealize(ScreenPtr pScreen,
432                     GlyphPtr pGlyph);
433
434 #endif /* UXAPRIV_H */