exa_priv.h revision 05b261ec
1/*
2 *
3 * Copyright (C) 2000 Keith Packard, member of The XFree86 Project, Inc.
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 EXAPRIV_H
27#define EXAPRIV_H
28
29#ifdef HAVE_DIX_CONFIG_H
30#include <dix-config.h>
31#endif
32
33#include "exa.h"
34
35#include <X11/X.h>
36#define NEED_EVENTS
37#include <X11/Xproto.h>
38#include "scrnintstr.h"
39#include "pixmapstr.h"
40#include "windowstr.h"
41#include "servermd.h"
42#include "mibstore.h"
43#include "colormapst.h"
44#include "gcstruct.h"
45#include "input.h"
46#include "mipointer.h"
47#include "mi.h"
48#include "dix.h"
49#include "fb.h"
50#include "fboverlay.h"
51#ifdef RENDER
52#include "fbpict.h"
53#endif
54#include "damage.h"
55
56#define DEBUG_TRACE_FALL	0
57#define DEBUG_MIGRATE		0
58#define DEBUG_PIXMAP		0
59#define DEBUG_OFFSCREEN		0
60
61#if DEBUG_TRACE_FALL
62#define EXA_FALLBACK(x)     					\
63do {								\
64	ErrorF("EXA fallback at %s: ", __FUNCTION__);		\
65	ErrorF x;						\
66} while (0)
67
68char
69exaDrawableLocation(DrawablePtr pDrawable);
70#else
71#define EXA_FALLBACK(x)
72#endif
73
74#if DEBUG_PIXMAP
75#define DBG_PIXMAP(a) ErrorF a
76#else
77#define DBG_PIXMAP(a)
78#endif
79
80#ifndef EXA_MAX_FB
81#define EXA_MAX_FB   FB_OVERLAY_MAX
82#endif
83
84/**
85 * This is the list of migration heuristics supported by EXA.  See
86 * exaDoMigration() for what their implementations do.
87 */
88enum ExaMigrationHeuristic {
89    ExaMigrationGreedy,
90    ExaMigrationAlways,
91    ExaMigrationSmart
92};
93
94typedef void (*EnableDisableFBAccessProcPtr)(int, Bool);
95typedef struct {
96    ExaDriverPtr info;
97    CreateGCProcPtr 		 SavedCreateGC;
98    CloseScreenProcPtr 		 SavedCloseScreen;
99    GetImageProcPtr 		 SavedGetImage;
100    GetSpansProcPtr 		 SavedGetSpans;
101    PaintWindowBackgroundProcPtr SavedPaintWindowBackground;
102    CreatePixmapProcPtr 	 SavedCreatePixmap;
103    DestroyPixmapProcPtr 	 SavedDestroyPixmap;
104    PaintWindowBorderProcPtr 	 SavedPaintWindowBorder;
105    CopyWindowProcPtr 		 SavedCopyWindow;
106#ifdef RENDER
107    CompositeProcPtr             SavedComposite;
108    RasterizeTrapezoidProcPtr	 SavedRasterizeTrapezoid;
109    AddTrianglesProcPtr		 SavedAddTriangles;
110    GlyphsProcPtr                SavedGlyphs;
111    TrapezoidsProcPtr            SavedTrapezoids;
112#endif
113    Bool			 swappedOut;
114    enum ExaMigrationHeuristic	 migration;
115    Bool			 hideOffscreenPixmapData;
116    Bool			 checkDirtyCorrectness;
117    unsigned			 disableFbCount;
118} ExaScreenPrivRec, *ExaScreenPrivPtr;
119
120/*
121 * This is the only completely portable way to
122 * compute this info.
123 */
124#ifndef BitsPerPixel
125#define BitsPerPixel(d) (\
126    PixmapWidthPaddingInfo[d].notPower2 ? \
127    (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
128    ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
129    (PixmapWidthPaddingInfo[d].padRoundUp+1)))
130#endif
131
132extern int exaScreenPrivateIndex;
133extern int exaPixmapPrivateIndex;
134#define ExaGetScreenPriv(s)	((ExaScreenPrivPtr)(s)->devPrivates[exaScreenPrivateIndex].ptr)
135#define ExaScreenPriv(s)	ExaScreenPrivPtr    pExaScr = ExaGetScreenPriv(s)
136
137/** Align an offset to an arbitrary alignment */
138#define EXA_ALIGN(offset, align) (((offset) + (align) - 1) - \
139	(((offset) + (align) - 1) % (align)))
140/** Align an offset to a power-of-two alignment */
141#define EXA_ALIGN2(offset, align) (((offset) + (align) - 1) & ~((align) - 1))
142
143#define EXA_PIXMAP_SCORE_MOVE_IN    10
144#define EXA_PIXMAP_SCORE_MAX	    20
145#define EXA_PIXMAP_SCORE_MOVE_OUT   -10
146#define EXA_PIXMAP_SCORE_MIN	    -20
147#define EXA_PIXMAP_SCORE_PINNED	    1000
148#define EXA_PIXMAP_SCORE_INIT	    1001
149
150#define ExaGetPixmapPriv(p)	((ExaPixmapPrivPtr)(p)->devPrivates[exaPixmapPrivateIndex].ptr)
151#define ExaSetPixmapPriv(p,a)	((p)->devPrivates[exaPixmapPrivateIndex].ptr = (pointer) (a))
152#define ExaPixmapPriv(p)	ExaPixmapPrivPtr pExaPixmap = ExaGetPixmapPriv(p)
153
154typedef struct {
155    ExaOffscreenArea *area;
156    int		    score;	/**< score for the move-in vs move-out heuristic */
157
158    CARD8	    *sys_ptr;	/**< pointer to pixmap data in system memory */
159    int		    sys_pitch;	/**< pitch of pixmap in system memory */
160
161    CARD8	    *fb_ptr;	/**< pointer to pixmap data in framebuffer memory */
162    int		    fb_pitch;	/**< pitch of pixmap in framebuffer memory */
163    unsigned int    fb_size;	/**< size of pixmap in framebuffer memory */
164
165    /**
166     * The damage record contains the areas of the pixmap's current location
167     * (framebuffer or system) that have been damaged compared to the other
168     * location.
169     */
170    DamagePtr	    pDamage;
171    /**
172     * The valid region marks the valid bits of a drawable (at least, as it's
173     * derived from damage, which may be overreported).
174     */
175    RegionRec	    validReg;
176} ExaPixmapPrivRec, *ExaPixmapPrivPtr;
177
178typedef struct _ExaMigrationRec {
179    Bool as_dst;
180    Bool as_src;
181    PixmapPtr pPix;
182} ExaMigrationRec, *ExaMigrationPtr;
183
184/**
185 * exaDDXDriverInit must be implemented by the DDX using EXA, and is the place
186 * to set EXA options or hook in screen functions to handle using EXA as the AA.
187  */
188void exaDDXDriverInit (ScreenPtr pScreen);
189
190/* exa_unaccel.c */
191void
192exaPrepareAccessGC(GCPtr pGC);
193
194void
195exaFinishAccessGC(GCPtr pGC);
196
197void
198ExaCheckFillSpans  (DrawablePtr pDrawable, GCPtr pGC, int nspans,
199		   DDXPointPtr ppt, int *pwidth, int fSorted);
200
201void
202ExaCheckSetSpans (DrawablePtr pDrawable, GCPtr pGC, char *psrc,
203		 DDXPointPtr ppt, int *pwidth, int nspans, int fSorted);
204
205void
206ExaCheckPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth,
207		 int x, int y, int w, int h, int leftPad, int format,
208		 char *bits);
209
210RegionPtr
211ExaCheckCopyArea (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
212		 int srcx, int srcy, int w, int h, int dstx, int dsty);
213
214RegionPtr
215ExaCheckCopyPlane (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
216		  int srcx, int srcy, int w, int h, int dstx, int dsty,
217		  unsigned long bitPlane);
218
219void
220ExaCheckPolyPoint (DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
221		  DDXPointPtr pptInit);
222
223void
224ExaCheckPolylines (DrawablePtr pDrawable, GCPtr pGC,
225		  int mode, int npt, DDXPointPtr ppt);
226
227void
228ExaCheckPolySegment (DrawablePtr pDrawable, GCPtr pGC,
229		    int nsegInit, xSegment *pSegInit);
230
231void
232ExaCheckPolyArc (DrawablePtr pDrawable, GCPtr pGC,
233		int narcs, xArc *pArcs);
234
235void
236ExaCheckPolyFillRect (DrawablePtr pDrawable, GCPtr pGC,
237		     int nrect, xRectangle *prect);
238
239void
240ExaCheckImageGlyphBlt (DrawablePtr pDrawable, GCPtr pGC,
241		      int x, int y, unsigned int nglyph,
242		      CharInfoPtr *ppci, pointer pglyphBase);
243
244void
245ExaCheckPolyGlyphBlt (DrawablePtr pDrawable, GCPtr pGC,
246		     int x, int y, unsigned int nglyph,
247		     CharInfoPtr *ppci, pointer pglyphBase);
248
249void
250ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
251		   DrawablePtr pDrawable,
252		   int w, int h, int x, int y);
253
254void
255ExaCheckGetImage (DrawablePtr pDrawable,
256		 int x, int y, int w, int h,
257		 unsigned int format, unsigned long planeMask,
258		 char *d);
259
260void
261ExaCheckGetSpans (DrawablePtr pDrawable,
262		 int wMax,
263		 DDXPointPtr ppt,
264		 int *pwidth,
265		 int nspans,
266		 char *pdstStart);
267
268void
269ExaCheckSaveAreas (PixmapPtr	pPixmap,
270		  RegionPtr	prgnSave,
271		  int		xorg,
272		  int		yorg,
273		  WindowPtr	pWin);
274
275void
276ExaCheckRestoreAreas (PixmapPtr	pPixmap,
277		     RegionPtr	prgnSave,
278		     int	xorg,
279		     int    	yorg,
280		     WindowPtr	pWin);
281
282void
283ExaCheckPaintWindow (WindowPtr pWin, RegionPtr pRegion, int what);
284
285CARD32
286exaGetPixmapFirstPixel (PixmapPtr pPixmap);
287
288/* exa_accel.c */
289void
290exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
291
292Bool
293exaFillRegionTiled (DrawablePtr	pDrawable, RegionPtr pRegion, PixmapPtr pTile,
294		    DDXPointPtr pPatOrg, CARD32 planemask, CARD32 alu);
295
296void
297exaPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what);
298
299void
300exaGetImage (DrawablePtr pDrawable, int x, int y, int w, int h,
301	     unsigned int format, unsigned long planeMask, char *d);
302
303void
304exaGetSpans (DrawablePtr pDrawable, int wMax, DDXPointPtr ppt, int *pwidth,
305	     int nspans, char *pdstStart);
306
307extern const GCOps exaOps;
308
309#ifdef RENDER
310void
311ExaCheckComposite (CARD8      op,
312		  PicturePtr pSrc,
313		  PicturePtr pMask,
314		  PicturePtr pDst,
315		  INT16      xSrc,
316		  INT16      ySrc,
317		  INT16      xMask,
318		  INT16      yMask,
319		  INT16      xDst,
320		  INT16      yDst,
321		  CARD16     width,
322		  CARD16     height);
323#endif
324
325/* exa_offscreen.c */
326void
327ExaOffscreenSwapOut (ScreenPtr pScreen);
328
329void
330ExaOffscreenSwapIn (ScreenPtr pScreen);
331
332Bool
333exaOffscreenInit(ScreenPtr pScreen);
334
335void
336ExaOffscreenFini (ScreenPtr pScreen);
337
338/* exa.c */
339void
340exaPrepareAccess(DrawablePtr pDrawable, int index);
341
342void
343exaFinishAccess(DrawablePtr pDrawable, int index);
344
345void
346exaPixmapDirty(PixmapPtr pPix, int x1, int y1, int x2, int y2);
347
348void
349exaGetDrawableDeltas (DrawablePtr pDrawable, PixmapPtr pPixmap,
350		      int *xp, int *yp);
351
352Bool
353exaDrawableIsOffscreen (DrawablePtr pDrawable);
354
355Bool
356exaPixmapIsOffscreen(PixmapPtr p);
357
358PixmapPtr
359exaGetOffscreenPixmap (DrawablePtr pDrawable, int *xp, int *yp);
360
361PixmapPtr
362exaGetDrawablePixmap(DrawablePtr pDrawable);
363
364RegionPtr
365exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
366	    int srcx, int srcy, int width, int height, int dstx, int dsty);
367
368void
369exaCopyNtoN (DrawablePtr    pSrcDrawable,
370	     DrawablePtr    pDstDrawable,
371	     GCPtr	    pGC,
372	     BoxPtr	    pbox,
373	     int	    nbox,
374	     int	    dx,
375	     int	    dy,
376	     Bool	    reverse,
377	     Bool	    upsidedown,
378	     Pixel	    bitplane,
379	     void	    *closure);
380
381/* exa_render.c */
382void
383exaComposite(CARD8	op,
384	     PicturePtr pSrc,
385	     PicturePtr pMask,
386	     PicturePtr pDst,
387	     INT16	xSrc,
388	     INT16	ySrc,
389	     INT16	xMask,
390	     INT16	yMask,
391	     INT16	xDst,
392	     INT16	yDst,
393	     CARD16	width,
394	     CARD16	height);
395
396void
397exaTrapezoids (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
398               PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
399               int ntrap, xTrapezoid *traps);
400
401void
402exaRasterizeTrapezoid (PicturePtr pPicture, xTrapezoid  *trap,
403		       int x_off, int y_off);
404
405void
406exaAddTriangles (PicturePtr pPicture, INT16 x_off, INT16 y_off, int ntri,
407		 xTriangle *tris);
408
409void
410exaGlyphs (CARD8	op,
411	  PicturePtr	pSrc,
412	  PicturePtr	pDst,
413	  PictFormatPtr	maskFormat,
414	  INT16		xSrc,
415	  INT16		ySrc,
416	  int		nlist,
417	  GlyphListPtr	list,
418	  GlyphPtr	*glyphs);
419
420/* exa_migration.c */
421void
422exaDoMigration (ExaMigrationPtr pixmaps, int npixmaps, Bool can_accel);
423
424void
425exaPixmapSave (ScreenPtr pScreen, ExaOffscreenArea *area);
426
427#endif /* EXAPRIV_H */
428