Imported Upstream version 1.11.4
[ubuntu-omap:xserver.git] / hw / xfree86 / xaa / xaaOffscreen.c
1
2 /*
3    Copyright (c) 1999 -  The XFree86 Project Inc.
4
5    Written by Mark Vojkovich
6
7 */ 
8
9 #ifdef HAVE_XORG_CONFIG_H
10 #include <xorg-config.h>
11 #endif
12
13 #include "misc.h"
14 #include "xf86.h"
15 #include "xf86_OSproc.h"
16
17 #include <X11/X.h>
18 #include "scrnintstr.h"
19 #include "pixmapstr.h"
20 #include "windowstr.h"
21 #include "xf86str.h"
22 #include "mi.h"
23 #include "miline.h"
24 #include "xaa.h"
25 #include "xaalocal.h"
26 #include "xaawrap.h"
27 #include "xf86fbman.h"
28 #include "servermd.h"
29
30 void
31 XAAMoveOutOffscreenPixmaps(ScreenPtr pScreen)
32 {
33     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
34     PixmapLinkPtr pLink = infoRec->OffscreenPixmaps;
35     XAAPixmapPtr pPriv;
36     
37     while(pLink) {
38         pPriv = XAA_GET_PIXMAP_PRIVATE(pLink->pPix);
39         pLink->area = pPriv->offscreenArea;
40         XAAMoveOutOffscreenPixmap(pLink->pPix); 
41         pLink = pLink->next;
42     }    
43 }
44
45
46
47 void
48 XAAMoveInOffscreenPixmaps(ScreenPtr pScreen)
49 {
50     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
51     PixmapLinkPtr pLink = infoRec->OffscreenPixmaps;
52     PixmapPtr pPix, pScreenPix, tmpPix;
53     pointer data;
54     XAAPixmapPtr pPriv;
55     GCPtr pGC;
56     FBAreaPtr area;
57
58     pScreenPix = (*pScreen->GetScreenPixmap)(pScreen);
59
60     while(pLink) {
61         pPix = pLink->pPix;
62         pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
63         area = pLink->area;
64
65         data = pPix->devPrivate.ptr;
66         tmpPix = GetScratchPixmapHeader(pScreen, 
67                 pPix->drawable.width, pPix->drawable.height, 
68                 pPix->drawable.depth, pPix->drawable.bitsPerPixel, 
69                 pPix->devKind, data);
70
71         pPriv->freeData = FALSE;
72
73         pPix->drawable.x = area->box.x1;
74         pPix->drawable.y = area->box.y1;
75         pPix->devKind = pScreenPix->devKind;
76         pPix->devPrivate.ptr = pScreenPix->devPrivate.ptr;
77         pPix->drawable.bitsPerPixel = infoRec->pScrn->bitsPerPixel;
78         pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
79
80         if(!tmpPix) {
81             pPriv->offscreenArea = area;
82             free(data);
83             pLink = pLink->next;
84             continue;
85         }
86         
87         pGC = GetScratchGC(pPix->drawable.depth, pScreen);
88         ValidateGC((DrawablePtr)pPix, pGC);
89
90         (*pGC->ops->CopyArea)((DrawablePtr)tmpPix, (DrawablePtr)pPix, pGC, 
91                 0, 0, pPix->drawable.width, pPix->drawable.height, 0, 0);       
92
93         free(data);
94         tmpPix->devPrivate.ptr = NULL;
95
96         FreeScratchGC(pGC);
97         FreeScratchPixmapHeader(tmpPix);
98
99         pPriv->offscreenArea = area;
100         pLink->area = NULL;
101         pLink = pLink->next;
102     }    
103 }
104
105
106 void
107 XAARemoveAreaCallback(FBAreaPtr area)
108 {
109     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(area->pScreen);
110     PixmapPtr pPix = (PixmapPtr)area->devPrivate.ptr;
111     XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
112
113     XAAMoveOutOffscreenPixmap(pPix);
114
115     pPriv->flags &= ~OFFSCREEN; 
116
117     DELIST_OFFSCREEN_PIXMAP(pPix);
118 }
119
120 void
121 XAAMoveOutOffscreenPixmap(PixmapPtr pPix) 
122 {
123     ScreenPtr pScreen = pPix->drawable.pScreen;
124     XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
125     int width, height, devKind, bitsPerPixel;
126     PixmapPtr tmpPix;
127     unsigned char *data;
128     GCPtr pGC;
129
130     width = pPix->drawable.width;
131     height = pPix->drawable.height;
132     bitsPerPixel = pPix->drawable.bitsPerPixel;
133
134     devKind = BitmapBytePad(width * bitsPerPixel);
135     if(!(data = malloc(devKind * height)))
136         FatalError("Out of memory\n");
137
138     tmpPix = GetScratchPixmapHeader(pScreen, width, height, 
139                 pPix->drawable.depth, bitsPerPixel, devKind, data);
140     if(!tmpPix) {
141         free(data);
142         FatalError("Out of memory\n");
143     }
144
145     pGC = GetScratchGC(pPix->drawable.depth, pScreen);
146     ValidateGC((DrawablePtr)tmpPix, pGC);
147
148     (*pGC->ops->CopyArea)((DrawablePtr)pPix, (DrawablePtr)tmpPix,
149                 pGC, 0, 0, width, height, 0, 0);        
150
151     FreeScratchGC(pGC);
152     FreeScratchPixmapHeader(tmpPix);
153
154     pPix->drawable.x = 0;
155     pPix->drawable.y = 0;
156     pPix->devKind = devKind;
157     pPix->devPrivate.ptr = data;
158     pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
159
160     pPriv->offscreenArea = NULL;
161     pPriv->freeData = TRUE;
162 }