dix: Stop recycling scratch pixmaps

The minimal performance wins we gain by recycling pixmaps at this layer are
not worth the code complexity nor the interference with memory analysis
tools like malloc history, ASan, etc.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston Sequoia 2022-12-14 23:45:56 -08:00
parent 762096628c
commit 6ee937b3be
2 changed files with 12 additions and 19 deletions

View File

@ -44,8 +44,13 @@ from The Open Group.
#include "picturestr.h" #include "picturestr.h"
#include "randrstr.h" #include "randrstr.h"
/* /*
* Scratch pixmap management and device independent pixmap allocation * Scratch pixmap APIs are provided for source and binary compatability. In
* function. * older versions, DIX would store a freed scratch pixmap for future use. This
* optimization is not really that impactful on modern systems with decent
* system heap management and modern CPUs, and it interferes with memory
* analysis tools such as ASan, malloc history, etc.
*
* Now, these entry points just allocte/free pixmaps.
*/ */
/* callable by ddx */ /* callable by ddx */
@ -53,14 +58,7 @@ PixmapPtr
GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth, GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth,
int bitsPerPixel, int devKind, void *pPixData) int bitsPerPixel, int devKind, void *pPixData)
{ {
PixmapPtr pPixmap = pScreen->pScratchPixmap; PixmapPtr pPixmap = (*pScreen->CreatePixmap) (pScreen, 0, 0, depth, 0);
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 (pPixmap) {
if ((*pScreen->ModifyPixmapHeader) (pPixmap, width, height, depth, if ((*pScreen->ModifyPixmapHeader) (pPixmap, width, height, depth,
bitsPerPixel, devKind, pPixData)) bitsPerPixel, devKind, pPixData))
@ -76,12 +74,8 @@ FreeScratchPixmapHeader(PixmapPtr pPixmap)
{ {
if (pPixmap) { if (pPixmap) {
ScreenPtr pScreen = pPixmap->drawable.pScreen; ScreenPtr pScreen = pPixmap->drawable.pScreen;
pPixmap->devPrivate.ptr = NULL; /* help catch/avoid heap-use-after-free */
pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */ (*pScreen->DestroyPixmap)(pPixmap);
if (pScreen->pScratchPixmap)
(*pScreen->DestroyPixmap) (pPixmap);
else
pScreen->pScratchPixmap = pPixmap;
} }
} }
@ -94,7 +88,7 @@ CreateScratchPixmapsForScreen(ScreenPtr pScreen)
pScreen->totalPixmapSize = pScreen->totalPixmapSize =
BitmapBytePad(pixmap_size * 8); BitmapBytePad(pixmap_size * 8);
/* let it be created on first use */ /* NULL this out as it is no longer used */
pScreen->pScratchPixmap = NULL; pScreen->pScratchPixmap = NULL;
return TRUE; return TRUE;
} }
@ -102,7 +96,6 @@ CreateScratchPixmapsForScreen(ScreenPtr pScreen)
void void
FreeScratchPixmapsForScreen(ScreenPtr pScreen) FreeScratchPixmapsForScreen(ScreenPtr pScreen)
{ {
FreeScratchPixmapHeader(pScreen->pScratchPixmap);
} }
/* callable by ddx */ /* callable by ddx */

View File

@ -604,7 +604,7 @@ typedef struct _Screen {
SetScreenPixmapProcPtr SetScreenPixmap; SetScreenPixmapProcPtr SetScreenPixmap;
NameWindowPixmapProcPtr NameWindowPixmap; NameWindowPixmapProcPtr NameWindowPixmap;
PixmapPtr pScratchPixmap; /* scratch pixmap "pool" */ PixmapPtr pScratchPixmap; /* scratch pixmap "pool" (unused / NULL in modern servers) */
unsigned int totalPixmapSize; unsigned int totalPixmapSize;