exa_priv.h revision 4642e01f
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#ifdef MITSHM
39#include "shmint.h"
40#endif
41#include "scrnintstr.h"
42#include "pixmapstr.h"
43#include "windowstr.h"
44#include "servermd.h"
45#include "mibstore.h"
46#include "colormapst.h"
47#include "gcstruct.h"
48#include "input.h"
49#include "mipointer.h"
50#include "mi.h"
51#include "dix.h"
52#include "fb.h"
53#include "fboverlay.h"
54#ifdef RENDER
55#include "fbpict.h"
56#include "glyphstr.h"
57#endif
58#include "damage.h"
59
60#define DEBUG_TRACE_FALL	0
61#define DEBUG_MIGRATE		0
62#define DEBUG_PIXMAP		0
63#define DEBUG_OFFSCREEN		0
64#define DEBUG_GLYPH_CACHE	0
65
66#if DEBUG_TRACE_FALL
67#define EXA_FALLBACK(x)     					\
68do {								\
69	ErrorF("EXA fallback at %s: ", __FUNCTION__);		\
70	ErrorF x;						\
71} while (0)
72
73char
74exaDrawableLocation(DrawablePtr pDrawable);
75#else
76#define EXA_FALLBACK(x)
77#endif
78
79#if DEBUG_PIXMAP
80#define DBG_PIXMAP(a) ErrorF a
81#else
82#define DBG_PIXMAP(a)
83#endif
84
85#ifndef EXA_MAX_FB
86#define EXA_MAX_FB   FB_OVERLAY_MAX
87#endif
88
89/**
90 * This is the list of migration heuristics supported by EXA.  See
91 * exaDoMigration() for what their implementations do.
92 */
93enum ExaMigrationHeuristic {
94    ExaMigrationGreedy,
95    ExaMigrationAlways,
96    ExaMigrationSmart
97};
98
99typedef struct {
100    unsigned char sha1[20];
101} ExaCachedGlyphRec, *ExaCachedGlyphPtr;
102
103typedef struct {
104    /* The identity of the cache, statically configured at initialization */
105    unsigned int format;
106    int glyphWidth;
107    int glyphHeight;
108
109    int size; /* Size of cache; eventually this should be dynamically determined */
110
111    /* Hash table mapping from glyph sha1 to position in the glyph; we use
112     * open addressing with a hash table size determined based on size and large
113     * enough so that we always have a good amount of free space, so we can
114     * use linear probing. (Linear probing is preferrable to double hashing
115     * here because it allows us to easily remove entries.)
116     */
117    int *hashEntries;
118    int hashSize;
119
120    ExaCachedGlyphPtr glyphs;
121    int glyphCount; /* Current number of glyphs */
122
123    PicturePtr picture;   /* Where the glyphs of the cache are stored */
124    int yOffset;          /* y location within the picture where the cache starts */
125    int columns;          /* Number of columns the glyphs are layed out in */
126    int evictionPosition; /* Next random position to evict a glyph */
127} ExaGlyphCacheRec, *ExaGlyphCachePtr;
128
129#define EXA_NUM_GLYPH_CACHES 4
130
131typedef void (*EnableDisableFBAccessProcPtr)(int, Bool);
132typedef struct {
133    ExaDriverPtr info;
134    CreateGCProcPtr 		 SavedCreateGC;
135    CloseScreenProcPtr 		 SavedCloseScreen;
136    GetImageProcPtr 		 SavedGetImage;
137    GetSpansProcPtr 		 SavedGetSpans;
138    CreatePixmapProcPtr 	 SavedCreatePixmap;
139    DestroyPixmapProcPtr 	 SavedDestroyPixmap;
140    CopyWindowProcPtr 		 SavedCopyWindow;
141    ChangeWindowAttributesProcPtr SavedChangeWindowAttributes;
142    BitmapToRegionProcPtr        SavedBitmapToRegion;
143    CreateScreenResourcesProcPtr SavedCreateScreenResources;
144    ModifyPixmapHeaderProcPtr    SavedModifyPixmapHeader;
145#ifdef RENDER
146    CompositeProcPtr             SavedComposite;
147    TrianglesProcPtr		 SavedTriangles;
148    GlyphsProcPtr                SavedGlyphs;
149    TrapezoidsProcPtr            SavedTrapezoids;
150    AddTrapsProcPtr		 SavedAddTraps;
151#endif
152
153    Bool			 swappedOut;
154    enum ExaMigrationHeuristic	 migration;
155    Bool			 checkDirtyCorrectness;
156    unsigned			 disableFbCount;
157    Bool			 optimize_migration;
158    unsigned			 offScreenCounter;
159
160    ExaGlyphCacheRec             glyphCaches[EXA_NUM_GLYPH_CACHES];
161} ExaScreenPrivRec, *ExaScreenPrivPtr;
162
163/*
164 * This is the only completely portable way to
165 * compute this info.
166 */
167#ifndef BitsPerPixel
168#define BitsPerPixel(d) (\
169    PixmapWidthPaddingInfo[d].notPower2 ? \
170    (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
171    ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
172    (PixmapWidthPaddingInfo[d].padRoundUp+1)))
173#endif
174
175extern DevPrivateKey exaScreenPrivateKey;
176extern DevPrivateKey exaPixmapPrivateKey;
177#define ExaGetScreenPriv(s) ((ExaScreenPrivPtr)dixLookupPrivate(&(s)->devPrivates, exaScreenPrivateKey))
178#define ExaScreenPriv(s)	ExaScreenPrivPtr    pExaScr = ExaGetScreenPriv(s)
179
180/** Align an offset to an arbitrary alignment */
181#define EXA_ALIGN(offset, align) (((offset) + (align) - 1) - \
182	(((offset) + (align) - 1) % (align)))
183/** Align an offset to a power-of-two alignment */
184#define EXA_ALIGN2(offset, align) (((offset) + (align) - 1) & ~((align) - 1))
185
186#define EXA_PIXMAP_SCORE_MOVE_IN    10
187#define EXA_PIXMAP_SCORE_MAX	    20
188#define EXA_PIXMAP_SCORE_MOVE_OUT   -10
189#define EXA_PIXMAP_SCORE_MIN	    -20
190#define EXA_PIXMAP_SCORE_PINNED	    1000
191#define EXA_PIXMAP_SCORE_INIT	    1001
192
193#define ExaGetPixmapPriv(p) ((ExaPixmapPrivPtr)dixLookupPrivate(&(p)->devPrivates, exaPixmapPrivateKey))
194#define ExaSetPixmapPriv(p,a) dixSetPrivate(&(p)->devPrivates, exaPixmapPrivateKey, a)
195#define ExaPixmapPriv(p)	ExaPixmapPrivPtr pExaPixmap = ExaGetPixmapPriv(p)
196
197#define EXA_RANGE_PITCH (1 << 0)
198#define EXA_RANGE_WIDTH (1 << 1)
199#define EXA_RANGE_HEIGHT (1 << 2)
200
201typedef struct {
202    ExaOffscreenArea *area;
203    int		    score;	/**< score for the move-in vs move-out heuristic */
204    Bool	    offscreen;
205
206    CARD8	    *sys_ptr;	/**< pointer to pixmap data in system memory */
207    int		    sys_pitch;	/**< pitch of pixmap in system memory */
208
209    CARD8	    *fb_ptr;	/**< pointer to pixmap data in framebuffer memory */
210    int		    fb_pitch;	/**< pitch of pixmap in framebuffer memory */
211    unsigned int    fb_size;	/**< size of pixmap in framebuffer memory */
212
213    /**
214     * Holds information about whether this pixmap can be used for
215     * acceleration (== 0) or not (> 0).
216     *
217     * Contains a OR'ed combination of the following values:
218     * EXA_RANGE_PITCH - set if the pixmap's pitch is out of range
219     * EXA_RANGE_WIDTH - set if the pixmap's width is out of range
220     * EXA_RANGE_HEIGHT - set if the pixmap's height is out of range
221     */
222    unsigned int    accel_blocked;
223
224    /**
225     * The damage record contains the areas of the pixmap's current location
226     * (framebuffer or system) that have been damaged compared to the other
227     * location.
228     */
229    DamagePtr	    pDamage;
230    /**
231     * The valid regions mark the valid bits (at least, as they're derived from
232     * damage, which may be overreported) of a pixmap's system and FB copies.
233     */
234    RegionRec	    validSys, validFB;
235    /**
236     * Driver private storage per EXA pixmap
237     */
238    void *driverPriv;
239} ExaPixmapPrivRec, *ExaPixmapPrivPtr;
240
241typedef struct _ExaMigrationRec {
242    Bool as_dst;
243    Bool as_src;
244    PixmapPtr pPix;
245    RegionPtr pReg;
246} ExaMigrationRec, *ExaMigrationPtr;
247
248typedef struct {
249    INT16 xSrc;
250    INT16 ySrc;
251    INT16 xDst;
252    INT16 yDst;
253    INT16 width;
254    INT16 height;
255} ExaCompositeRectRec, *ExaCompositeRectPtr;
256
257/**
258 * exaDDXDriverInit must be implemented by the DDX using EXA, and is the place
259 * to set EXA options or hook in screen functions to handle using EXA as the AA.
260  */
261void exaDDXDriverInit (ScreenPtr pScreen);
262
263/* exa_unaccel.c */
264void
265exaPrepareAccessGC(GCPtr pGC);
266
267void
268exaFinishAccessGC(GCPtr pGC);
269
270void
271ExaCheckFillSpans  (DrawablePtr pDrawable, GCPtr pGC, int nspans,
272		   DDXPointPtr ppt, int *pwidth, int fSorted);
273
274void
275ExaCheckSetSpans (DrawablePtr pDrawable, GCPtr pGC, char *psrc,
276		 DDXPointPtr ppt, int *pwidth, int nspans, int fSorted);
277
278void
279ExaCheckPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth,
280		 int x, int y, int w, int h, int leftPad, int format,
281		 char *bits);
282
283RegionPtr
284ExaCheckCopyArea (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
285		 int srcx, int srcy, int w, int h, int dstx, int dsty);
286
287RegionPtr
288ExaCheckCopyPlane (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
289		  int srcx, int srcy, int w, int h, int dstx, int dsty,
290		  unsigned long bitPlane);
291
292void
293ExaCheckPolyPoint (DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
294		  DDXPointPtr pptInit);
295
296void
297ExaCheckPolylines (DrawablePtr pDrawable, GCPtr pGC,
298		  int mode, int npt, DDXPointPtr ppt);
299
300void
301ExaCheckPolySegment (DrawablePtr pDrawable, GCPtr pGC,
302		    int nsegInit, xSegment *pSegInit);
303
304void
305ExaCheckPolyArc (DrawablePtr pDrawable, GCPtr pGC,
306		int narcs, xArc *pArcs);
307
308void
309ExaCheckPolyFillRect (DrawablePtr pDrawable, GCPtr pGC,
310		     int nrect, xRectangle *prect);
311
312void
313ExaCheckImageGlyphBlt (DrawablePtr pDrawable, GCPtr pGC,
314		      int x, int y, unsigned int nglyph,
315		      CharInfoPtr *ppci, pointer pglyphBase);
316
317void
318ExaCheckPolyGlyphBlt (DrawablePtr pDrawable, GCPtr pGC,
319		     int x, int y, unsigned int nglyph,
320		     CharInfoPtr *ppci, pointer pglyphBase);
321
322void
323ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
324		   DrawablePtr pDrawable,
325		   int w, int h, int x, int y);
326
327void
328ExaCheckGetSpans (DrawablePtr pDrawable,
329		 int wMax,
330		 DDXPointPtr ppt,
331		 int *pwidth,
332		 int nspans,
333		 char *pdstStart);
334
335void
336ExaCheckAddTraps (PicturePtr	pPicture,
337		  INT16		x_off,
338		  INT16		y_off,
339		  int		ntrap,
340		  xTrap		*traps);
341
342/* exa_accel.c */
343
344static _X_INLINE Bool
345exaGCReadsDestination(DrawablePtr pDrawable, unsigned long planemask,
346		      unsigned int fillStyle, unsigned char alu)
347{
348    return ((alu != GXcopy && alu != GXclear &&alu != GXset &&
349	     alu != GXcopyInverted) || fillStyle == FillStippled ||
350	    !EXA_PM_IS_SOLID(pDrawable, planemask));
351}
352
353void
354exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
355
356Bool
357exaFillRegionTiled (DrawablePtr	pDrawable, RegionPtr pRegion, PixmapPtr pTile,
358		    DDXPointPtr pPatOrg, CARD32 planemask, CARD32 alu);
359
360void
361exaGetImage (DrawablePtr pDrawable, int x, int y, int w, int h,
362	     unsigned int format, unsigned long planeMask, char *d);
363
364extern const GCOps exaOps;
365
366#ifdef RENDER
367void
368ExaCheckComposite (CARD8      op,
369		  PicturePtr pSrc,
370		  PicturePtr pMask,
371		  PicturePtr pDst,
372		  INT16      xSrc,
373		  INT16      ySrc,
374		  INT16      xMask,
375		  INT16      yMask,
376		  INT16      xDst,
377		  INT16      yDst,
378		  CARD16     width,
379		  CARD16     height);
380#endif
381
382/* exa_offscreen.c */
383void
384ExaOffscreenSwapOut (ScreenPtr pScreen);
385
386void
387ExaOffscreenSwapIn (ScreenPtr pScreen);
388
389Bool
390exaOffscreenInit(ScreenPtr pScreen);
391
392void
393ExaOffscreenFini (ScreenPtr pScreen);
394
395/* exa.c */
396void
397ExaDoPrepareAccess(DrawablePtr pDrawable, int index);
398
399void
400exaPrepareAccessReg(DrawablePtr pDrawable, int index, RegionPtr pReg);
401
402void
403exaPrepareAccess(DrawablePtr pDrawable, int index);
404
405void
406exaFinishAccess(DrawablePtr pDrawable, int index);
407
408void
409exaPixmapDirty(PixmapPtr pPix, int x1, int y1, int x2, int y2);
410
411void
412exaGetDrawableDeltas (DrawablePtr pDrawable, PixmapPtr pPixmap,
413		      int *xp, int *yp);
414
415Bool
416exaPixmapIsOffscreen(PixmapPtr p);
417
418PixmapPtr
419exaGetOffscreenPixmap (DrawablePtr pDrawable, int *xp, int *yp);
420
421PixmapPtr
422exaGetDrawablePixmap(DrawablePtr pDrawable);
423
424RegionPtr
425exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
426	    int srcx, int srcy, int width, int height, int dstx, int dsty);
427
428void
429exaCopyNtoN (DrawablePtr    pSrcDrawable,
430	     DrawablePtr    pDstDrawable,
431	     GCPtr	    pGC,
432	     BoxPtr	    pbox,
433	     int	    nbox,
434	     int	    dx,
435	     int	    dy,
436	     Bool	    reverse,
437	     Bool	    upsidedown,
438	     Pixel	    bitplane,
439	     void	    *closure);
440
441/* exa_render.c */
442Bool
443exaOpReadsDestination (CARD8 op);
444
445void
446exaComposite(CARD8	op,
447	     PicturePtr pSrc,
448	     PicturePtr pMask,
449	     PicturePtr pDst,
450	     INT16	xSrc,
451	     INT16	ySrc,
452	     INT16	xMask,
453	     INT16	yMask,
454	     INT16	xDst,
455	     INT16	yDst,
456	     CARD16	width,
457	     CARD16	height);
458
459void
460exaCompositeRects(CARD8	              op,
461		  PicturePtr	      Src,
462		  PicturePtr	      pDst,
463		  int                 nrect,
464		  ExaCompositeRectPtr rects);
465
466void
467exaTrapezoids (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
468               PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
469               int ntrap, xTrapezoid *traps);
470
471void
472exaTriangles (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
473	      PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
474	      int ntri, xTriangle *tris);
475
476/* exa_glyph.c */
477void
478exaGlyphsInit(ScreenPtr pScreen);
479
480void
481exaGlyphsFini (ScreenPtr pScreen);
482
483void
484exaGlyphs (CARD8	op,
485	  PicturePtr	pSrc,
486	  PicturePtr	pDst,
487	  PictFormatPtr	maskFormat,
488	  INT16		xSrc,
489	  INT16		ySrc,
490	  int		nlist,
491	  GlyphListPtr	list,
492	  GlyphPtr	*glyphs);
493
494/* exa_migration.c */
495void
496exaDoMigration (ExaMigrationPtr pixmaps, int npixmaps, Bool can_accel);
497
498void
499exaPixmapSave (ScreenPtr pScreen, ExaOffscreenArea *area);
500
501#endif /* EXAPRIV_H */
502