#ifdef HAVE_CONFIG_H
#include <kdrive-config.h>
#endif
#include "kdrive.h"
#include "cursorstr.h"
static int
KdComputeCmapShift (unsigned long mask)
{
int shift;
unsigned long bit;
shift = 16;
bit = 0x80000000;
while (!(mask & bit))
{
shift--;
bit >>= 1;
}
return shift;
}
#define Shift(v,d) ((d) < 0 ? ((v) >> (-d)) : ((v) << (d)))
void
KdAllocateCursorPixels (ScreenPtr pScreen,
int fb,
CursorPtr pCursor,
Pixel *source,
Pixel *mask)
{
xColorItem sourceColor, maskColor;
int r, g, b;
KdScreenPriv(pScreen);
if (pScreenPriv->screen->fb[fb].redMask)
{
r = KdComputeCmapShift (pScreenPriv->screen->fb[fb].redMask);
g = KdComputeCmapShift (pScreenPriv->screen->fb[fb].greenMask);
b = KdComputeCmapShift (pScreenPriv->screen->fb[fb].blueMask);
*source = ((Shift(pCursor->foreRed,r) & pScreenPriv->screen->fb[fb].redMask) |
(Shift(pCursor->foreGreen,g) & pScreenPriv->screen->fb[fb].greenMask) |
(Shift(pCursor->foreBlue,b) & pScreenPriv->screen->fb[fb].blueMask));
*mask = ((Shift(pCursor->backRed,r) & pScreenPriv->screen->fb[fb].redMask) |
(Shift(pCursor->backGreen,g) & pScreenPriv->screen->fb[fb].greenMask) |
(Shift(pCursor->backBlue,b) & pScreenPriv->screen->fb[fb].blueMask));
}
else
{
*source = ~0;
*mask = ~0;
sourceColor.red = pCursor->foreRed;
sourceColor.green = pCursor->foreGreen;
sourceColor.blue = pCursor->foreBlue;
FakeAllocColor(pScreenPriv->pInstalledmap[fb], &sourceColor);
maskColor.red = pCursor->backRed;
maskColor.green = pCursor->backGreen;
maskColor.blue = pCursor->backBlue;
FakeAllocColor(pScreenPriv->pInstalledmap[fb], &maskColor);
FakeFreeColor(pScreenPriv->pInstalledmap[fb], sourceColor.pixel);
FakeFreeColor(pScreenPriv->pInstalledmap[fb], maskColor.pixel);
*source = sourceColor.pixel;
*mask = maskColor.pixel;
}
}