aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/sun/sunCfb24.c
blob: fa3a58e85876027f90c4c7ca65c2858f194765a9 (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
/* $Xorg: sunCfb24.c,v 1.4 2001/02/09 02:04:43 xorgcvs Exp $ */

/*

Copyright 1994, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X
CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from The Open Group.

*/
/* $XFree86: xc/programs/Xserver/hw/sun/sunCfb24.c,v 1.2 2001/10/28 03:33:10 tsi Exp $ */

/*
 * The CG8 is similar to the CG4 in that it has a mono plane, an enable 
 * plane, and a color plane. While the CG4 only has an 8-bit color
 * plane the CG8 has a 24-bit color plane. 
 *
 * If you have a CG4 you know that you can switch between the mono and
 * the color screens merely by dragging the pointer off the edge of the
 * screen, causing the other screen to be switched in. However this is
 * the cause of some consternation on the part of those people who have
 * both a CG4 and another frame buffer.
 *
 * Because of this problem, and some other considerations, I have chosen
 * to ignore the mono plane of the CG8 in this code.
 */

#define PSZ 32
#include "sun.h"
#include "cfb/cfb.h"

#define PIXPG_24BIT_COLOR 5
#define PIXPG_24BIT_COLOR_INDEX (PIXPG_24BIT_COLOR << 25)
#define PR_FORCE_UPDATE (1 << 24)

static void CG24UpdateColormap(pScreen, index, count, rmap, gmap, bmap)
    ScreenPtr	pScreen;
    int		index, count;
    u_char	*rmap, *gmap, *bmap;
{
    struct fbcmap sunCmap;

    sunCmap.index = index | PIXPG_24BIT_COLOR_INDEX | PR_FORCE_UPDATE;
    sunCmap.count = count;
    sunCmap.red = &rmap[index];
    sunCmap.green = &gmap[index];
    sunCmap.blue = &bmap[index];

    if (ioctl(sunFbs[pScreen->myNum].fd, FBIOPUTCMAP, &sunCmap) == -1)
	FatalError( "CG24UpdateColormap: FBIOPUTCMAP failed\n");
}

static void CG24StoreColors (pmap, ndef, pdefs)
    ColormapPtr pmap;
    int ndef;
    xColorItem* pdefs;
{
  u_char rmap[256], gmap[256], bmap[256];
  SetupScreen (pmap->pScreen);
  VisualPtr pVisual = pmap->pVisual;
  int i;

  if (pPrivate->installedMap != NULL && pPrivate->installedMap != pmap)
    return;
  for (i = 0; i < 256; i++) {
    rmap[i] = pmap->red[i].co.local.red >> 8;
    gmap[i] = pmap->green[i].co.local.green >> 8;
    bmap[i] = pmap->blue[i].co.local.blue >> 8;
  }
  while (ndef--) {
    i = pdefs->pixel;
    if (pdefs->flags & DoRed)
      rmap[(i & pVisual->redMask) >> pVisual->offsetRed] = (pdefs->red >> 8);
    if (pdefs->flags & DoGreen)
      gmap[(i & pVisual->greenMask) >> pVisual->offsetGreen] = (pdefs->green >> 8);
    if (pdefs->flags & DoBlue)
      bmap[(i & pVisual->blueMask) >> pVisual->offsetBlue] = (pdefs->blue >> 8);
    pdefs++;
  }
  CG24UpdateColormap (pmap->pScreen, 0, 256, rmap, gmap, bmap);
}

#define CG8_COLOR_OFFSET 0x40000

static void CG24ScreenInit (pScreen)
    ScreenPtr pScreen;
{
#ifndef STATIC_COLOR
    SetupScreen (pScreen);
#endif
    int i;

    /* Make sure the overlay plane is disabled */
    for (i = 0; i < CG8_COLOR_OFFSET; i++)
	sunFbs[pScreen->myNum].fb[i] = 0;

#ifndef STATIC_COLOR
    pScreen->InstallColormap = sunInstallColormap;
    pScreen->UninstallColormap = sunUninstallColormap;
    pScreen->ListInstalledColormaps = sunListInstalledColormaps;
    pScreen->StoreColors = CG24StoreColors;
    pPrivate->UpdateColormap = CG24UpdateColormap;
    if (sunFlipPixels) {
	Pixel pixel = pScreen->whitePixel;
	pScreen->whitePixel = pScreen->blackPixel;
	pScreen->blackPixel = pixel;
    }
#endif
}

Bool sunCG8Init (screen, pScreen, argc, argv)
    int		    screen;    	/* what screen am I going to be */
    ScreenPtr	    pScreen;  	/* The Screen to initialize */
    int		    argc;    	/* The number of the Server's arguments. */
    char	    **argv;   	/* The arguments themselves. Don't change! */
{
    sunFbs[screen].EnterLeave = (void (*)())NoopDDA;
    return sunInitCommon (screen, pScreen, (off_t) 0,
	cfb32ScreenInit, CG24ScreenInit,
	cfbCreateDefColormap, sunSaveScreen, CG8_COLOR_OFFSET);
}