From f2b019d2b3ab5ed75a824e5b46507491bd416938 Mon Sep 17 00:00:00 2001 From: Izumi Tsutsui Date: Thu, 20 Apr 2023 01:32:15 +0900 Subject: [PATCH] fb: Fix 1bpp Xservers on "whitePixel=0, blackPixel=1" VRAMs Closes: #1057 --- fb/fb.h | 3 +++ fb/fbcmap_mi.c | 35 +++++++++++++++++++++++++++++++++++ fb/fbscreen.c | 12 +++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/fb/fb.h b/fb/fb.h index d157b6956..c2c4cae78 100644 --- a/fb/fb.h +++ b/fb/fb.h @@ -734,6 +734,9 @@ fbResolveColor(unsigned short *pred, extern _X_EXPORT Bool fbInitializeColormap(ColormapPtr pmap); +extern _X_EXPORT Bool + mfbCreateColormap(ColormapPtr pmap); + extern _X_EXPORT int fbExpandDirectColors(ColormapPtr pmap, diff --git a/fb/fbcmap_mi.c b/fb/fbcmap_mi.c index c9c6d8027..a71828a11 100644 --- a/fb/fbcmap_mi.c +++ b/fb/fbcmap_mi.c @@ -66,6 +66,41 @@ fbInitializeColormap(ColormapPtr pmap) return miInitializeColormap(pmap); } +Bool +mfbCreateColormap(ColormapPtr pmap) +{ + ScreenPtr pScreen; + unsigned short red0, green0, blue0; + unsigned short red1, green1, blue1; + Pixel pix; + + pScreen = pmap->pScreen; + if (pScreen->whitePixel == 0) + { + red0 = green0 = blue0 = ~0; + red1 = green1 = blue1 = 0; + } + else + { + red0 = green0 = blue0 = 0; + red1 = green1 = blue1 = ~0; + } + + /* this is a monochrome colormap, it only has two entries, just fill + * them in by hand. If it were a more complex static map, it would be + * worth writing a for loop or three to initialize it */ + + /* this will be pixel 0 */ + pix = 0; + if (AllocColor(pmap, &red0, &green0, &blue0, &pix, 0) != Success) + return FALSE; + + /* this will be pixel 1 */ + if (AllocColor(pmap, &red1, &green1, &blue1, &pix, 0) != Success) + return FALSE; + return TRUE; +} + int fbExpandDirectColors(ColormapPtr pmap, int ndef, xColorItem * indefs, xColorItem * outdefs) diff --git a/fb/fbscreen.c b/fb/fbscreen.c index 4ab807ab5..42efaa911 100644 --- a/fb/fbscreen.c +++ b/fb/fbscreen.c @@ -100,8 +100,10 @@ fbSetupScreen(ScreenPtr pScreen, void *pbits, /* pointer to screen bitmap */ if (!fbAllocatePrivates(pScreen)) return FALSE; pScreen->defColormap = FakeClientID(0); - /* let CreateDefColormap do whatever it wants for pixels */ - pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0; + if (bpp > 1) { + /* let CreateDefColormap do whatever it wants for pixels */ + pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0; + } pScreen->QueryBestSize = fbQueryBestSize; /* SaveScreen */ pScreen->GetImage = fbGetImage; @@ -118,7 +120,11 @@ fbSetupScreen(ScreenPtr pScreen, void *pbits, /* pointer to screen bitmap */ pScreen->RealizeFont = fbRealizeFont; pScreen->UnrealizeFont = fbUnrealizeFont; pScreen->CreateGC = fbCreateGC; - pScreen->CreateColormap = fbInitializeColormap; + if (bpp == 1) { + pScreen->CreateColormap = mfbCreateColormap; + } else { + pScreen->CreateColormap = fbInitializeColormap; + } pScreen->DestroyColormap = (void (*)(ColormapPtr)) NoopDDA; pScreen->InstallColormap = fbInstallColormap; pScreen->UninstallColormap = fbUninstallColormap;