summaryrefslogtreecommitdiff
blob: 7b59e646b441263e03656d30fc8a1aacd27ca789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
diff --git a/hw/xfree86/xaa/xaaOffscreen.c b/hw/xfree86/xaa/xaaOffscreen.c
index cd0d9a9..8fa5d6d 100644
--- a/hw/xfree86/xaa/xaaOffscreen.c
+++ b/hw/xfree86/xaa/xaaOffscreen.c
@@ -90,12 +90,11 @@ XAAMoveInOffscreenPixmaps(ScreenPtr pScreen)
 	(*pGC->ops->CopyArea)((DrawablePtr)tmpPix, (DrawablePtr)pPix, pGC, 
 		0, 0, pPix->drawable.width, pPix->drawable.height, 0, 0);	
 
-	free(data);
-	tmpPix->devPrivate.ptr = NULL;
-
 	FreeScratchGC(pGC);
 	FreeScratchPixmapHeader(tmpPix);
 
+	free(data);
+
 	pPriv->offscreenArea = area;
 	pLink->area = NULL;
 	pLink = pLink->next;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 192c8c3..3f73175 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3855,7 +3855,6 @@ AddScreen(
 	return -1;
     }
     pScreen->myNum = i;
-    pScreen->totalPixmapSize = 0;	/* computed in CreateScratchPixmapForScreen */
     pScreen->ClipNotify = 0;	/* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
 
diff --git a/dix/main.c b/dix/main.c
index 955b7ea..7eadf36 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -206,12 +206,11 @@ int main(int argc, char *argv[], char *envp[])
 	if (screenInfo.numScreens < 1)
 	    FatalError("no screens found");
 	InitExtensions(argc, argv);
+	InitPixmaps();
 
 	for (i = 0; i < screenInfo.numScreens; i++)
 	{
 	    ScreenPtr pScreen = screenInfo.screens[i];
-	    if (!CreateScratchPixmapsForScreen(i))
-		FatalError("failed to create scratch pixmaps");
 	    if (pScreen->CreateScreenResources &&
 		!(*pScreen->CreateScreenResources)(pScreen))
 		FatalError("failed to create screen resources");
@@ -321,7 +320,6 @@ int main(int argc, char *argv[], char *envp[])
 
 	for (i = screenInfo.numScreens - 1; i >= 0; i--)
 	{
-	    FreeScratchPixmapsForScreen(i);
 	    FreeGCperDepth(i);
 	    FreeDefaultStipple(i);
 	    (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]);
diff --git a/dix/pixmap.c b/dix/pixmap.c
index cbb5e7f..0b43592 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -53,20 +53,19 @@ PixmapPtr
 GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth, 
                        int bitsPerPixel, int devKind, pointer pPixData)
 {
-    PixmapPtr pPixmap = pScreen->pScratchPixmap;
+    PixmapPtr pPixmap;
 
-    if (pPixmap)
-	pScreen->pScratchPixmap = NULL;
-    else
-	/* width and height of 0 means don't allocate any pixmap data */
-	pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth, 0);
-
-    if (pPixmap) {
-	if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
-					   bitsPerPixel, devKind, pPixData))
-	    return pPixmap;
-	(*pScreen->DestroyPixmap)(pPixmap);
-    }
+    /* width and height of 0 means don't allocate any pixmap data */
+    pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth,
+				       CREATE_PIXMAP_USAGE_SCRATCH_HEADER);
+    if (pPixmap == NullPixmap)
+	return NullPixmap;
+
+    if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
+				       bitsPerPixel, devKind, pPixData))
+	return pPixmap;
+
+    (*pScreen->DestroyPixmap)(pPixmap);
     return NullPixmap;
 }
 
@@ -79,33 +78,22 @@ FreeScratchPixmapHeader(PixmapPtr pPixmap)
     {
 	ScreenPtr pScreen = pPixmap->drawable.pScreen;
 
-	pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */
-	if (pScreen->pScratchPixmap)
-	    (*pScreen->DestroyPixmap)(pPixmap);
-	else
-	    pScreen->pScratchPixmap = pPixmap;
+	if (pPixmap->refcnt != 1)
+		FatalError("Scratch pixmap still in use when finalized, refcnt=%d\n",
+			   pPixmap->refcnt);
+
+	(*pScreen->DestroyPixmap)(pPixmap);
     }
 }
 
 
-Bool
-CreateScratchPixmapsForScreen(int scrnum)
+void
+InitPixmaps(void)
 {
     unsigned int	pixmap_size;
 
     pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP);
-    screenInfo.screens[scrnum]->totalPixmapSize = BitmapBytePad(pixmap_size * 8);
-
-    /* let it be created on first use */
-    screenInfo.screens[scrnum]->pScratchPixmap = NULL;
-    return TRUE;
-}
-
-
-void
-FreeScratchPixmapsForScreen(int scrnum)
-{
-    FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
+    screenInfo.totalPixmapSize = BitmapBytePad(pixmap_size * 8);
 }
 
 
@@ -115,12 +103,12 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
 {
     PixmapPtr pPixmap;
 
-    assert(pScreen->totalPixmapSize > 0);
+    assert(screenInfo.totalPixmapSize > 0);
 
-    if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize)
+    if (screenInfo.totalPixmapSize > ((size_t)-1) - pixDataSize)
 	return NullPixmap;
     
-    pPixmap = malloc(pScreen->totalPixmapSize + pixDataSize);
+    pPixmap = malloc(screenInfo.totalPixmapSize + pixDataSize);
     if (!pPixmap)
 	return NullPixmap;
 
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index a356c67..aebdff0 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -42,7 +42,7 @@ fbCreatePixmapBpp (ScreenPtr pScreen, int width, int height, int depth, int bpp,
     if (paddedWidth / 4 > 32767 || height > 32767)
 	return NullPixmap;
     datasize = height * paddedWidth;
-    base = pScreen->totalPixmapSize;
+    base = screenInfo.totalPixmapSize;
     adjust = 0;
     if (base & 7)
 	adjust = 8 - (base & 7);
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 2a5c805..cf7557e 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -82,7 +82,7 @@ typedef enum {
  * mask is 0xFFFF0000.
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
-#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(11, 0)
+#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(12, 0)
 #define ABI_XINPUT_VERSION	SET_ABI_VERSION(13, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(5, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
diff --git a/include/pixmap.h b/include/pixmap.h
index 014a111..daab76c 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -103,11 +103,8 @@ extern _X_EXPORT PixmapPtr GetScratchPixmapHeader(
 extern _X_EXPORT void FreeScratchPixmapHeader(
     PixmapPtr /*pPixmap*/);
 
-extern _X_EXPORT Bool CreateScratchPixmapsForScreen(
-    int /*scrnum*/);
-
-extern _X_EXPORT void FreeScratchPixmapsForScreen(
-    int /*scrnum*/);
+extern _X_EXPORT void InitPixmaps(
+    void);
 
 extern _X_EXPORT PixmapPtr AllocatePixmap(
     ScreenPtr /*pScreen*/,
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index a9357e8..617eadb 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -202,6 +202,8 @@ typedef    void (* ClipNotifyProcPtr)(
 #define CREATE_PIXMAP_USAGE_BACKING_PIXMAP              2
 /* pixmap will contain a glyph */
 #define CREATE_PIXMAP_USAGE_GLYPH_PICTURE               3
+/* pixmap will only be as a header for transient (e.g. on-stack) pixels */
+#define CREATE_PIXMAP_USAGE_SCRATCH_HEADER              4
 
 typedef    PixmapPtr (* CreatePixmapProcPtr)(
 	ScreenPtr /*pScreen*/,
@@ -518,10 +520,6 @@ typedef struct _Screen {
     GetScreenPixmapProcPtr	GetScreenPixmap;
     SetScreenPixmapProcPtr	SetScreenPixmap;
 
-    PixmapPtr pScratchPixmap;		/* scratch pixmap "pool" */
-
-    unsigned int		totalPixmapSize;
-
     MarkWindowProcPtr		MarkWindow;
     MarkOverlappedWindowsProcPtr MarkOverlappedWindows;
     ConfigNotifyProcPtr		ConfigNotify;
@@ -556,6 +554,8 @@ typedef struct _ScreenInfo {
     int		bitmapScanlineUnit;
     int		bitmapScanlinePad;
     int		bitmapBitOrder;
+    unsigned int totalPixmapSize;
+
     int		numPixmapFormats;
     PixmapFormatRec
 		formats[MAXFORMATS];
From patchwork Mon Jun  6 05:36:08 2011
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [3/4] shm: Replace open-coded version of GetScratchPixmapHeader
Date: Mon, 06 Jun 2011 13:36:08 -0000
From: Chris Wilson <chris@chris-wilson.co.uk>
X-Patchwork-Id: 5802
Message-Id: <1307338569-31221-4-git-send-email-chris@chris-wilson.co.uk>
To: xorg-devel@lists.x.org

fbShmCreatePixmap() was just another variant of wrapping an arbitrary
data pointer within a pixmap, ala GetScratchPixmapHeader().

By using the common version, the fbShmCreatePixmap() is also updated to
pass the information that the pixmap contents are not part of the ddx
address space.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

---
Xext/shm.c |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/Xext/shm.c b/Xext/shm.c
index b08af82..c6a3aee 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -1018,18 +1018,10 @@ static PixmapPtr
 fbShmCreatePixmap (ScreenPtr pScreen,
 		   int width, int height, int depth, char *addr)
 {
-    PixmapPtr pPixmap;
-
-    pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth, 0);
-    if (!pPixmap)
-	return NullPixmap;
-
-    if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
-	    BitsPerPixel(depth), PixmapBytePad(width, depth), (pointer)addr)) {
-	(*pScreen->DestroyPixmap)(pPixmap);
-	return NullPixmap;
-    }
-    return pPixmap;
+    return GetScratchPixmapHeader(pScreen, width, height, depth,
+				  BitsPerPixel(depth),
+				  PixmapBytePad(width, depth),
+				  addr);
 }
 
 static int
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index 5cc476a..46d481b 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -63,7 +63,6 @@ typedef struct {
   CloseScreenProcPtr			CloseScreen;
   CopyWindowProcPtr			CopyWindow;
   CreateGCProcPtr			CreateGC;
-  ModifyPixmapHeaderProcPtr		ModifyPixmapHeader;
   CompositeProcPtr Composite;
   Bool				(*EnterVT)(int, int);
   void				(*LeaveVT)(int, int);
@@ -172,7 +171,6 @@ ShadowFBInit2 (
     pPriv->CloseScreen = pScreen->CloseScreen;
     pPriv->CopyWindow = pScreen->CopyWindow;
     pPriv->CreateGC = pScreen->CreateGC;
-    pPriv->ModifyPixmapHeader = pScreen->ModifyPixmapHeader;
 
     pPriv->EnterVT = pScrn->EnterVT;
     pPriv->LeaveVT = pScrn->LeaveVT;
@@ -248,7 +246,6 @@ ShadowCloseScreen (int i, ScreenPtr pScreen)
     pScreen->CloseScreen = pPriv->CloseScreen;
     pScreen->CopyWindow = pPriv->CopyWindow;
     pScreen->CreateGC = pPriv->CreateGC;
-    pScreen->ModifyPixmapHeader = pPriv->ModifyPixmapHeader;
 
     pScrn->EnterVT = pPriv->EnterVT;
     pScrn->LeaveVT = pPriv->LeaveVT;