|
|
1.1 root 1: /*-
2: * sunBW2.c --
3: * Functions for handling the sun BWTWO board.
4: *
5: * Copyright (c) 1987 by the Regents of the University of California
6: * Copyright (c) 1987 by Adam de Boor, UC Berkeley
7: *
8: * Permission to use, copy, modify, and distribute this
9: * software and its documentation for any purpose and without
10: * fee is hereby granted, provided that the above copyright
11: * notice appear in all copies. The University of California
12: * makes no representations about the suitability of this
13: * software for any purpose. It is provided "as is" without
14: * express or implied warranty.
15: *
16: *
17: */
18:
19: /************************************************************
20: Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
21:
22: All Rights Reserved
23:
24: Permission to use, copy, modify, and distribute this
25: software and its documentation for any purpose and without
26: fee is hereby granted, provided that the above copyright no-
27: tice appear in all copies and that both that copyright no-
28: tice and this permission notice appear in supporting docu-
29: mentation, and that the names of Sun or MIT not be used in
30: advertising or publicity pertaining to distribution of the
31: software without specific prior written permission. Sun and
32: M.I.T. make no representations about the suitability of this
33: software for any purpose. It is provided "as is" without any
34: express or implied warranty.
35:
36: SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
37: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
38: NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-
39: ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
41: PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
42: OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
43: THE USE OR PERFORMANCE OF THIS SOFTWARE.
44:
45: ********************************************************/
46:
47:
48: /*-
49: * Copyright (c) 1987 by Sun Microsystems, Inc.
50: */
51:
52: #include "sun.h"
53: #include "resource.h"
54:
55: #include <sys/mman.h>
56:
57: /*-
58: *-----------------------------------------------------------------------
59: * sunBW2SaveScreen --
60: * Disable the video on the frame buffer to save the screen.
61: *
62: * Results:
63: * None.
64: *
65: * Side Effects:
66: * Video enable state changes.
67: *
68: *-----------------------------------------------------------------------
69: */
70: static Bool
71: sunBW2SaveScreen (pScreen, on)
72: ScreenPtr pScreen;
73: Bool on;
74: {
75: switch (on) {
76: case SCREEN_SAVER_FORCER:
77: SetTimeSinceLastInputEvent();
78: case SCREEN_SAVER_OFF:
79: screenSaved = FALSE;
1.1.1.2 ! root 80: (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOVIDON, 0);
1.1 root 81: break;
82: case SCREEN_SAVER_ON:
83: default:
84: screenSaved = TRUE;
1.1.1.2 ! root 85: (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOVIDOFF, 0);
1.1 root 86: break;
87: }
88: return TRUE;
89: }
90:
91: /*-
92: *-----------------------------------------------------------------------
93: * sunBW2CloseScreen --
94: * called to ensure video is enabled when server exits.
95: *
96: * Results:
97: * Screen is unsaved.
98: *
99: * Side Effects:
100: * None
101: *
102: *-----------------------------------------------------------------------
103: */
104: /*ARGSUSED*/
105: static Bool
106: sunBW2CloseScreen(i, pScreen)
107: int i;
108: ScreenPtr pScreen;
109: {
110: return (pScreen->SaveScreen(pScreen, SCREEN_SAVER_OFF));
111: }
112:
113: /*-
114: *-----------------------------------------------------------------------
115: * sunBW2ResolveColor --
116: * Resolve an RGB value into some sort of thing we can handle.
117: * Just looks to see if the intensity of the color is greater than
118: * 1/2 and sets it to 'white' (all ones) if so and 'black' (all zeroes)
119: * if not.
120: *
121: * Results:
122: * *pred, *pgreen and *pblue are overwritten with the resolved color.
123: *
124: * Side Effects:
125: * see above.
126: *
127: *-----------------------------------------------------------------------
128: */
129: /*ARGSUSED*/
130: static void
131: sunBW2ResolveColor(pred, pgreen, pblue, pVisual)
132: unsigned short *pred;
133: unsigned short *pgreen;
134: unsigned short *pblue;
135: VisualPtr pVisual;
136: {
137: /*
138: * Gets intensity from RGB. If intensity is >= half, pick white, else
139: * pick black. This may well be more trouble than it's worth.
140: */
141: *pred = *pgreen = *pblue =
142: (((39L * *pred +
143: 50L * *pgreen +
144: 11L * *pblue) >> 8) >= (((1<<8)-1)*50)) ? ~0 : 0;
145: }
146:
147: /*-
148: *-----------------------------------------------------------------------
149: * sunBW2CreateColormap --
150: * create a bw colormap
151: *
152: * Results:
153: * None
154: *
155: * Side Effects:
156: * allocate two pixels
157: *
158: *-----------------------------------------------------------------------
159: */
160: void
161: sunBW2CreateColormap(pmap)
162: ColormapPtr pmap;
163: {
164: int red, green, blue, pix;
165:
166: /* this is a monochrome colormap, it only has two entries, just fill
167: * them in by hand. If it were a more complex static map, it would be
168: * worth writing a for loop or three to initialize it */
169:
170: /* this will be pixel 0 */
171: red = green = blue = ~0;
172: AllocColor(pmap, &red, &green, &blue, &pix, 0);
173:
174: /* this will be pixel 1 */
175: red = green = blue = 0;
176: AllocColor(pmap, &red, &green, &blue, &pix, 0);
177:
178: }
179:
180: /*-
181: *-----------------------------------------------------------------------
182: * sunBW2DestroyColormap --
183: * destroy a bw colormap
184: *
185: * Results:
186: * None
187: *
188: * Side Effects:
189: * None
190: *
191: *-----------------------------------------------------------------------
192: */
193: /*ARGSUSED*/
194: void
195: sunBW2DestroyColormap(pmap)
196: ColormapPtr pmap;
197: {
198: }
199:
200: /*-
201: *-----------------------------------------------------------------------
202: * sunBW2Init --
203: * Attempt to find and initialize a bw2 framebuffer
204: *
205: * Results:
206: * None
207: *
208: * Side Effects:
209: * Most of the elements of the ScreenRec are filled in. The
210: * video is enabled for the frame buffer...
211: *
212: *-----------------------------------------------------------------------
213: */
214: /*ARGSUSED*/
215: static Bool
216: sunBW2Init (index, pScreen, argc, argv)
217: int index; /* The index of pScreen in the ScreenInfo */
218: ScreenPtr pScreen; /* The Screen to initialize */
219: int argc; /* The number of the Server's arguments. */
220: char **argv; /* The arguments themselves. Don't change! */
221: {
222: ColormapPtr pColormap;
223:
224: if (!mfbScreenInit(index, pScreen,
225: sunFbs[index].fb,
226: sunFbs[index].info.fb_width,
227: sunFbs[index].info.fb_height, 90, 90))
228: return (FALSE);
229:
230: pScreen->SaveScreen = sunBW2SaveScreen;
231: pScreen->RealizeCursor = sunRealizeCursor;
232: pScreen->UnrealizeCursor = sunUnrealizeCursor;
233: pScreen->DisplayCursor = sunDisplayCursor;
234: pScreen->SetCursorPosition = sunSetCursorPosition;
235: pScreen->CursorLimits = sunCursorLimits;
236: pScreen->PointerNonInterestBox = sunPointerNonInterestBox;
237: pScreen->ConstrainCursor = sunConstrainCursor;
238: pScreen->RecolorCursor = sunRecolorCursor;
239: pScreen->ResolveColor = sunBW2ResolveColor;
240: pScreen->CreateColormap = sunBW2CreateColormap;
241: pScreen->DestroyColormap = sunBW2DestroyColormap;
242: pScreen->RegionCreate = miRegionCreate;
243: pScreen->RegionCopy = miRegionCopy;
244: pScreen->RegionDestroy = miRegionDestroy;
245: pScreen->Intersect = miIntersect;
246: pScreen->Inverse = miInverse;
247: pScreen->Union = miUnion;
248: pScreen->Subtract = miSubtract;
249: pScreen->RegionReset = miRegionReset;
250: pScreen->TranslateRegion = miTranslateRegion;
251: pScreen->RectIn = miRectIn;
252: pScreen->PointInRegion = miPointInRegion;
253: pScreen->whitePixel = 0;
254: pScreen->blackPixel = 1;
255:
256: if (CreateColormap(pScreen->defColormap, pScreen,
257: LookupID(pScreen->rootVisual, RT_VISUALID, RC_CORE),
258: &pColormap, AllocNone, 0) != Success
259: || pColormap == NULL)
260: FatalError("Can't create colormap in sunBW2Init()\n");
261: mfbInstallColormap(pColormap);
262:
263: /*
264: * Enable video output...?
265: */
266: (void) sunBW2SaveScreen(pScreen, SCREEN_SAVER_FORCER);
267:
268: sunScreenInit(pScreen);
269: return (TRUE);
270:
271: }
272:
273: /*-
274: *-----------------------------------------------------------------------
275: * sunBW2Probe --
276: * Attempt to find and initialize a bw2 framebuffer
277: *
278: * Results:
279: * None
280: *
281: * Side Effects:
282: * Memory is allocated for the frame buffer and the buffer is mapped.
283: *
284: *-----------------------------------------------------------------------
285: */
286:
287: Bool
288: sunBW2Probe(pScreenInfo, index, fbNum, argc, argv)
289: ScreenInfo *pScreenInfo; /* The screenInfo struct */
290: int index; /* The index of pScreen in the ScreenInfo */
291: int fbNum; /* Index into the sunFbData array */
292: int argc; /* The number of the Server's arguments. */
293: char **argv; /* The arguments themselves. Don't change! */
294: {
295: int i, oldNumScreens;
296:
297: if (sunFbData[fbNum].probeStatus == probedAndFailed) {
298: return FALSE;
299: }
300:
301: if (sunFbData[fbNum].probeStatus == neverProbed) {
302: int fd;
303: struct fbtype fbType;
304: char *bitmap = (char *)NULL;
305: char *valloc();
306:
307: if ((fd = sunOpenFrameBuffer(FBTYPE_SUN2BW, &fbType, index, fbNum,
308: argc, argv)) < 0) {
309: sunFbData[fbNum].probeStatus = probedAndFailed;
310: return FALSE;
311: }
312:
313: bitmap = valloc(fbType.fb_size);
314: if (bitmap == (char *) NULL) {
315: ErrorF("Could not allocate room for frame buffer.\n");
316: sunFbData[fbNum].probeStatus = probedAndFailed;
317: (void) close(fd);
318: return FALSE;
319: }
320: if (mmap(bitmap, fbType.fb_size, PROT_READ|PROT_WRITE, fd, 0) < 0) {
321: ErrorF("Mapping bw2");
322: sunFbData[fbNum].probeStatus = probedAndFailed;
323: (void) close(fd);
324: return FALSE;
325: }
326:
327: sunFbs[index].fb = (pointer) bitmap;
328: sunFbs[index].fd = fd;
329: sunFbs[index].info = fbType;
330: sunFbs[index].EnterLeave = NoopDDA;
331: sunFbData[fbNum].probeStatus = probedAndSucceeded;
332:
333: }
334:
335: /*
336: * If we've ever successfully probed this device, do the following.
337: */
338: oldNumScreens = pScreenInfo->numScreens;
339: i = AddScreen(sunBW2Init, argc, argv);
340: pScreenInfo->screen[index].CloseScreen = sunBW2CloseScreen;
341: return (i > oldNumScreens);
342: }
343:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.