Skip to content

Commit

Permalink
Use FBIO_GETRGBOFFS to get RGB offsets.
Browse files Browse the repository at this point in the history
Use the new FBIO_GETRGBOFFS framebuffer ioctl to get the correct
RGB offsets. This fixes wrong colors on PowerPC64 (big-endian).
  • Loading branch information
luporl authored and luporl committed Mar 1, 2021
1 parent bac5e21 commit dcd019a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/scfb_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ ScfbPreInit(ScrnInfoPtr pScrn, int flags)
const char *reqSym = NULL, *s;
Gamma zeros = {0.0, 0.0, 0.0};
DisplayModePtr mode;
struct fb_rgboffs offs;

if (flags & PROBE_DETECT) return FALSE;

Expand Down Expand Up @@ -412,6 +413,14 @@ ScfbPreInit(ScrnInfoPtr pScrn, int flags)
fPtr->info.vi_pixel_size;
}

if (ioctl(fPtr->fd, FBIO_GETRGBOFFS, &offs) == -1) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"ioctl FBIO_GETRGBOFFS fail: %s. "
"Falling back to default color format.\n",
strerror(errno));
memset(&offs, 0, sizeof(offs));
}

/* Handle depth */
default_depth = fPtr->info.vi_depth <= 24 ? fPtr->info.vi_depth : 24;
if (!xf86SetDepthBpp(pScrn, default_depth, default_depth,
Expand All @@ -437,6 +446,24 @@ ScfbPreInit(ScrnInfoPtr pScrn, int flags)
if (pScrn->depth > 8) {
rgb zeros = { 0, 0, 0 }, masks = { 0, 0, 0 };

/*
* If FBIO_GETRGBOFFS returned any non-zero offset, set
* the RGB masks appropriately.
*
* Due to a bug in Xorg server that causes it to calculate
* the wrong offsets when masks are explicitly passed,
* avoid modifying the masks if they correspond to the
* default values used by X.
* This issue was reported at
* https://gitlab.freedesktop.org/xorg/xserver/-/issues/1112
*/
if ((offs.red != 0 || offs.green != 0 || offs.blue != 0) &&
!(offs.red == 16 && offs.green == 8 && offs.blue == 0)) {
masks.red = 0xff << offs.red;
masks.green = 0xff << offs.green;
masks.blue = 0xff << offs.blue;
}

if (!xf86SetWeight(pScrn, zeros, masks))
return FALSE;
}
Expand Down

0 comments on commit dcd019a

Please sign in to comment.