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 "colormapst.h"
48#include "gcstruct.h"
49#include "input.h"
50#include "mipointer.h"
51#include "mi.h"
52#include "dix.h"
53#include "fb.h"
54#include "fboverlay.h"
55#ifdef RENDER
56#include "fbpict.h"
57#include "glyphstr.h"
58#endif
59#include "damage.h"
60
61#include "../src/compat-api.h"
62
63/* Provide substitutes for gcc's __FUNCTION__ on other compilers */
64#if !defined(__GNUC__) && !defined(__FUNCTION__)
65# if defined(__STDC__) && (__STDC_VERSION__>=199901L)	/* C99 */
66#  define __FUNCTION__ __func__
67# else
68#  define __FUNCTION__ ""
69# endif
70#endif
71
72/* 1.6 and earlier server compat */
73#ifndef miGetCompositeClip
74#define miCopyRegion fbCopyRegion
75#define miDoCopy fbDoCopy
76#endif
77
78#define DEBUG_MIGRATE		0
79#define DEBUG_PIXMAP		0
80#define DEBUG_OFFSCREEN		0
81#define DEBUG_GLYPH_CACHE	0
82
83#define UXA_FALLBACK(x)     					\
84if (uxa_get_screen(screen)->fallback_debug) {			\
85	ErrorF("UXA fallback at %s: ", __FUNCTION__);		\
86	ErrorF x;						\
87}
88
89char uxa_drawable_location(DrawablePtr pDrawable);
90
91#if DEBUG_PIXMAP
92#define DBG_PIXMAP(a) ErrorF a
93#else
94#define DBG_PIXMAP(a)
95#endif
96
97typedef struct {
98	PicturePtr picture;	/* Where the glyphs of the cache are stored */
99	GlyphPtr *glyphs;
100	uint16_t count;
101	uint16_t evict;
102} uxa_glyph_cache_t;
103
104#define UXA_NUM_GLYPH_CACHE_FORMATS 2
105
106typedef struct {
107	uint32_t color;
108	PicturePtr picture;
109} uxa_solid_cache_t;
110
111#define UXA_NUM_SOLID_CACHE 16
112
113typedef void (*EnableDisableFBAccessProcPtr) (int, Bool);
114typedef struct {
115	uxa_driver_t *info;
116	CreateGCProcPtr SavedCreateGC;
117	CloseScreenProcPtr SavedCloseScreen;
118	GetImageProcPtr SavedGetImage;
119	GetSpansProcPtr SavedGetSpans;
120	CreatePixmapProcPtr SavedCreatePixmap;
121	DestroyPixmapProcPtr SavedDestroyPixmap;
122	CopyWindowProcPtr SavedCopyWindow;
123	ChangeWindowAttributesProcPtr SavedChangeWindowAttributes;
124	BitmapToRegionProcPtr SavedBitmapToRegion;
125#ifdef RENDER
126	CompositeProcPtr SavedComposite;
127	TrianglesProcPtr SavedTriangles;
128	GlyphsProcPtr SavedGlyphs;
129	TrapezoidsProcPtr SavedTrapezoids;
130	AddTrapsProcPtr SavedAddTraps;
131	UnrealizeGlyphProcPtr SavedUnrealizeGlyph;
132#endif
133
134	Bool force_fallback;
135	Bool fallback_debug;
136
137	uxa_glyph_cache_t glyphCaches[UXA_NUM_GLYPH_CACHE_FORMATS];
138	Bool glyph_cache_initialized;
139
140	PicturePtr solid_clear, solid_black, solid_white;
141	uxa_solid_cache_t solid_cache[UXA_NUM_SOLID_CACHE];
142	int solid_cache_size;
143} uxa_screen_t;
144
145/*
146 * This is the only completely portable way to
147 * compute this info.
148 */
149#ifndef BitsPerPixel
150#define BitsPerPixel(d) (\
151    PixmapWidthPaddingInfo[d].notPower2 ? \
152    (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
153    ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
154    (PixmapWidthPaddingInfo[d].padRoundUp+1)))
155#endif
156
157#if HAS_DEVPRIVATEKEYREC
158extern DevPrivateKeyRec uxa_screen_index;
159#else
160extern int uxa_screen_index;
161#endif
162
163static inline uxa_screen_t *uxa_get_screen(ScreenPtr screen)
164{
165#if HAS_DEVPRIVATEKEYREC
166	return dixGetPrivate(&screen->devPrivates, &uxa_screen_index);
167#else
168	return dixLookupPrivate(&screen->devPrivates, &uxa_screen_index);
169#endif
170}
171
172/** Align an offset to an arbitrary alignment */
173#define UXA_ALIGN(offset, align) (((offset) + (align) - 1) - \
174	(((offset) + (align) - 1) % (align)))
175/** Align an offset to a power-of-two alignment */
176#define UXA_ALIGN2(offset, align) (((offset) + (align) - 1) & ~((align) - 1))
177
178typedef struct {
179	INT16 xSrc;
180	INT16 ySrc;
181	INT16 xDst;
182	INT16 yDst;
183	INT16 width;
184	INT16 height;
185} uxa_composite_rect_t;
186
187/**
188 * exaDDXDriverInit must be implemented by the DDX using EXA, and is the place
189 * to set EXA options or hook in screen functions to handle using EXA as the AA.
190  */
191void exaDDXDriverInit(ScreenPtr pScreen);
192
193Bool uxa_prepare_access_window(WindowPtr pWin);
194
195void uxa_finish_access_window(WindowPtr pWin);
196
197/* uxa-unaccel.c */
198Bool uxa_prepare_access_gc(GCPtr pGC);
199
200void uxa_finish_access_gc(GCPtr pGC);
201
202void
203uxa_check_fill_spans(DrawablePtr pDrawable, GCPtr pGC, int nspans,
204		     DDXPointPtr ppt, int *pwidth, int fSorted);
205
206void
207uxa_check_set_spans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
208		    DDXPointPtr ppt, int *pwidth, int nspans, int fSorted);
209
210void
211uxa_check_put_image(DrawablePtr pDrawable, GCPtr pGC, int depth,
212		    int x, int y, int w, int h, int leftPad, int format,
213		    char *bits);
214
215RegionPtr
216uxa_check_copy_area(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
217		    int srcx, int srcy, int w, int h, int dstx, int dsty);
218
219RegionPtr
220uxa_check_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
221		     int srcx, int srcy, int w, int h, int dstx, int dsty,
222		     unsigned long bitPlane);
223
224void
225uxa_check_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
226		     DDXPointPtr pptInit);
227
228void
229uxa_check_poly_lines(DrawablePtr pDrawable, GCPtr pGC,
230		     int mode, int npt, DDXPointPtr ppt);
231
232void
233uxa_check_poly_segment(DrawablePtr pDrawable, GCPtr pGC,
234		       int nsegInit, xSegment * pSegInit);
235
236void
237uxa_check_poly_arc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc * pArcs);
238
239void
240uxa_check_poly_fill_rect(DrawablePtr pDrawable, GCPtr pGC,
241			 int nrect, xRectangle * prect);
242
243void
244uxa_check_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
245			  int x, int y, unsigned int nglyph,
246			  CharInfoPtr * ppci, pointer pglyphBase);
247
248void
249uxa_check_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
250			 int x, int y, unsigned int nglyph,
251			 CharInfoPtr * ppci, pointer pglyphBase);
252
253void
254uxa_check_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
255		      DrawablePtr pDrawable, int w, int h, int x, int y);
256
257void
258uxa_check_get_spans(DrawablePtr pDrawable,
259		    int wMax,
260		    DDXPointPtr ppt, int *pwidth, int nspans, char *pdstStart);
261
262void uxa_check_paint_window(WindowPtr pWin, RegionPtr pRegion, int what);
263
264void
265uxa_check_add_traps(PicturePtr pPicture,
266		    INT16 x_off, INT16 y_off, int ntrap, xTrap * traps);
267
268/* uxa-accel.c */
269
270static _X_INLINE Bool
271uxa_gc_reads_destination(DrawablePtr pDrawable, unsigned long planemask,
272			 unsigned int fillStyle, unsigned char alu)
273{
274	return ((alu != GXcopy && alu != GXclear && alu != GXset &&
275		 alu != GXcopyInverted) || fillStyle == FillStippled ||
276		!UXA_PM_IS_SOLID(pDrawable, planemask));
277}
278
279void uxa_copy_window(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
280
281Bool
282uxa_fill_region_tiled(DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile,
283		      DDXPointPtr pPatOrg, CARD32 planemask, CARD32 alu);
284
285void uxa_paint_window(WindowPtr pWin, RegionPtr pRegion, int what);
286
287void
288uxa_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
289	      unsigned int format, unsigned long planeMask, char *d);
290
291void
292uxa_get_spans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
293	      int *pwidth, int nspans, char *pdstStart);
294
295void
296uxa_add_traps(PicturePtr pPicture,
297	      INT16 x_off, INT16 y_off, int ntrap, xTrap * traps);
298
299extern const GCOps uxa_ops;
300
301#ifdef RENDER
302
303void
304uxa_check_composite(CARD8 op,
305		    PicturePtr pSrc,
306		    PicturePtr pMask,
307		    PicturePtr pDst,
308		    INT16 xSrc,
309		    INT16 ySrc,
310		    INT16 xMask,
311		    INT16 yMask,
312		    INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
313#endif
314
315/* uxa.c */
316Bool uxa_prepare_access(DrawablePtr pDrawable, uxa_access_t access);
317void uxa_finish_access(DrawablePtr pDrawable, uxa_access_t access);
318
319Bool uxa_picture_prepare_access(PicturePtr picture, int mode);
320void uxa_picture_finish_access(PicturePtr picture, int mode);
321
322void
323uxa_get_drawable_deltas(DrawablePtr pDrawable, PixmapPtr pPixmap,
324			int *xp, int *yp);
325
326Bool uxa_drawable_is_offscreen(DrawablePtr pDrawable);
327
328Bool uxa_pixmap_is_offscreen(PixmapPtr p);
329
330PixmapPtr uxa_get_offscreen_pixmap(DrawablePtr pDrawable, int *xp, int *yp);
331
332PixmapPtr uxa_get_drawable_pixmap(DrawablePtr pDrawable);
333
334RegionPtr
335uxa_copy_area(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
336	      int srcx, int srcy, int width, int height, int dstx, int dsty);
337
338void
339uxa_copy_n_to_n(DrawablePtr pSrcDrawable,
340		DrawablePtr pDstDrawable,
341		GCPtr pGC,
342		BoxPtr pbox,
343		int nbox,
344		int dx,
345		int dy,
346		Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
347
348/* uxa_render.c */
349Bool uxa_op_reads_destination(CARD8 op);
350
351void
352uxa_composite(CARD8 op,
353	      PicturePtr pSrc,
354	      PicturePtr pMask,
355	      PicturePtr pDst,
356	      INT16 xSrc,
357	      INT16 ySrc,
358	      INT16 xMask,
359	      INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
360
361void
362uxa_composite_rects(CARD8 op,
363		    PicturePtr pSrc,
364		    PicturePtr pDst, int nrect, uxa_composite_rect_t * rects);
365
366void
367uxa_solid_rects (CARD8		op,
368		 PicturePtr	dst,
369		 xRenderColor  *color,
370		 int		num_rects,
371		 xRectangle    *rects);
372
373void
374uxa_trapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
375	       PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
376	       int ntrap, xTrapezoid * traps);
377
378void
379uxa_triangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
380	      PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
381	      int ntri, xTriangle * tris);
382
383PicturePtr
384uxa_acquire_solid(ScreenPtr screen, SourcePict *source);
385
386PicturePtr
387uxa_acquire_drawable(ScreenPtr pScreen,
388		     PicturePtr pSrc,
389		     INT16 x, INT16 y,
390		     CARD16 width, CARD16 height,
391		     INT16 * out_x, INT16 * out_y);
392
393PicturePtr
394uxa_acquire_pattern(ScreenPtr pScreen,
395		    PicturePtr pSrc,
396		    pixman_format_code_t format,
397		    INT16 x, INT16 y,
398		    CARD16 width, CARD16 height);
399
400Bool
401uxa_get_rgba_from_pixel(CARD32 pixel,
402			CARD16 * red,
403			CARD16 * green,
404			CARD16 * blue,
405			CARD16 * alpha,
406			CARD32 format);
407
408/* uxa_glyph.c */
409Bool uxa_glyphs_init(ScreenPtr pScreen);
410
411void uxa_glyphs_fini(ScreenPtr pScreen);
412
413void
414uxa_glyphs(CARD8 op,
415	   PicturePtr pSrc,
416	   PicturePtr pDst,
417	   PictFormatPtr maskFormat,
418	   INT16 xSrc,
419	   INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs);
420
421void
422uxa_glyph_unrealize(ScreenPtr pScreen,
423		    GlyphPtr pGlyph);
424
425#endif /* UXAPRIV_H */
426