1 |
dpavlin |
1 |
/* |
2 |
|
|
* PearPC |
3 |
|
|
* sysdisplay.cc - screen access functions for BeOS |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 1999-2002 Stefan Weyergraf |
6 |
|
|
* Copyright (C) 1999-2004 Sebastian Biallas (sb@biallas.net) |
7 |
|
|
* Copyright (C) 2004 Francois Revol (revol@free.fr) |
8 |
|
|
* |
9 |
|
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU General Public License version 2 as |
11 |
|
|
* published by the Free Software Foundation. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program; if not, write to the Free Software |
20 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
#include <csignal> |
24 |
|
|
#include <cstdlib> |
25 |
|
|
#include <unistd.h> |
26 |
|
|
#include <cstring> |
27 |
|
|
|
28 |
|
|
#include <AppDefs.h> |
29 |
|
|
#include <Application.h> |
30 |
|
|
#include <Bitmap.h> |
31 |
|
|
#include <Cursor.h> |
32 |
|
|
#include <GraphicsDefs.h> |
33 |
|
|
#include <InterfaceDefs.h> |
34 |
|
|
#include <List.h> |
35 |
|
|
#include <Locker.h> |
36 |
|
|
#include <Message.h> |
37 |
|
|
#include <Screen.h> |
38 |
|
|
#include <View.h> |
39 |
|
|
#include <Window.h> |
40 |
|
|
#include <WindowScreen.h> |
41 |
|
|
|
42 |
|
|
#include "system/display.h" |
43 |
|
|
#include "system/types.h" |
44 |
|
|
#include "system/systhread.h" |
45 |
|
|
#include "system/sysexcept.h" |
46 |
|
|
#include "system/sysvaccel.h" |
47 |
|
|
#include "tools/data.h" |
48 |
|
|
#include "tools/snprintf.h" |
49 |
|
|
|
50 |
|
|
#include "sysbeos.h" |
51 |
|
|
|
52 |
|
|
//#define DPRINTF(a...) |
53 |
|
|
#define DPRINTF(a...) ht_printf(a) |
54 |
|
|
|
55 |
|
|
//XXX:DEL uint gDamageAreaFirstAddr, gDamageAreaLastAddr; |
56 |
|
|
|
57 |
|
|
/*XXX:DEL |
58 |
|
|
struct { |
59 |
|
|
uint64 r_mask; |
60 |
|
|
uint64 g_mask; |
61 |
|
|
uint64 b_mask; |
62 |
|
|
} PACKED gPosixRGBMask;*/ |
63 |
|
|
|
64 |
|
|
//extern "C" void __attribute__((regparm (3))) posix_vaccel_15_to_15(uint32 pixel, byte *input, byte *output); |
65 |
|
|
//extern "C" void __attribute__((regparm (3))) posix_vaccel_15_to_32(uint32 pixel, byte *input, byte *output); |
66 |
|
|
|
67 |
|
|
#if 0 /* moved to sysbeos.cc */ |
68 |
|
|
static uint8 beos_key_to_adb_key[] = { |
69 |
|
|
/* ESC F1-F12 PRTSCR SLOCK */ |
70 |
|
|
0x35, 0x7a,0x78,0x63,0x76,0x60,0x61,0x62,0x64,0x65,0x6d,0x67,0x6f, 0xff, 0x6b,0x71, |
71 |
|
|
/* ` 1-0 - = BSPACE INS HOME P_UP NLOCK / * - */ |
72 |
|
|
0x32,0x12,0x13,0x14,0x15,0x17,0x16,0x1a,0x1c,0x19,0x1d,0x1b,0x18, 0x33, 0x72,0x73,0x74, 0x47,0x4b,0x43,0x4e, |
73 |
|
|
/* TAB qwerty... \ DEL END P_DN 7 8 9 + */ |
74 |
|
|
0x30, 0x0c,0x0d,0x0e,0x0f,0x11,0x10,0x20,0x22,0x1f,0x23,0x21,0x1e, 0x2a, 0x75,0x77,0x79, 0x59,0x5b,0x5c,0x45, |
75 |
|
|
/* CLOCK ... ENTR 4 5 6 */ |
76 |
|
|
0x39,0x00,0x01,0x02,0x03,0x05,0x04,0x26,0x28,0x25,0x29,0x27, 0x24, 0x56,0x57,0x58,/*107*/ |
77 |
|
|
/* SHIFT ... SHIFT UP 1 2 3 ENTR */ |
78 |
|
|
0x38, 0x06,0x07,0x08,0x09,0x0b,0x2d,0x2e,0x2b,0x2f,0x2c, 0x38, 0x3e, 0x53,0x54,0x55,0x4c, |
79 |
|
|
/* CTRL /WIN/ ALT SPACE ALTGR /WIN MENU/ CTRL LEFT DOWN RIGHT 0 DEL */ |
80 |
|
|
0x36,/*0,*/ 0x37, 0x31, 0x3a, /*0, 0,*/ 0x36, 0x3b, 0x3d, 0x3c, 0x52, 0x41 |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
}; |
84 |
|
|
#endif |
85 |
|
|
|
86 |
|
|
static uint8 blank_cursor_data[] = { |
87 |
|
|
0x10, /* pixels/side */ |
88 |
|
|
0x01, /* bits/pix */ |
89 |
|
|
0x00, /* hotspot y */ |
90 |
|
|
0x00, /* hotspot x */ |
91 |
|
|
/* color */ |
92 |
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
93 |
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
94 |
|
|
/* mask */ |
95 |
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
96 |
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
97 |
|
|
}; |
98 |
|
|
|
99 |
|
|
static void findMaskShiftAndSize(uint &shift, uint &size, uint bitmask) |
100 |
|
|
{ |
101 |
|
|
if (!bitmask) { |
102 |
|
|
shift = 0; |
103 |
|
|
size = 0; |
104 |
|
|
return; |
105 |
|
|
} |
106 |
|
|
shift = 0; |
107 |
|
|
while (!(bitmask & 1)) { |
108 |
|
|
shift++; |
109 |
|
|
bitmask >>= 1; |
110 |
|
|
} |
111 |
|
|
size = 0; |
112 |
|
|
while (bitmask & 1) { |
113 |
|
|
size++; |
114 |
|
|
bitmask >>= 1; |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
|
119 |
|
|
static byte *gBeOSFramebuffer = NULL; |
120 |
|
|
/* old value of framebuffer, after replacing with BBitmap::Bits() */ |
121 |
|
|
/* |
122 |
|
|
static Display *gXDisplay; |
123 |
|
|
static Window gXWindow; |
124 |
|
|
static GC gWhiteGC, gBlackGC; |
125 |
|
|
static GC gGC; |
126 |
|
|
static XImage *gXImage; |
127 |
|
|
static XImage *gMenuXImage; |
128 |
|
|
static XImage *gMouseXImage; |
129 |
|
|
static Colormap gDefaultColormap; |
130 |
|
|
*/ |
131 |
|
|
static BCursor *gBlankCursor; |
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
#define MASK(shift, size) (((1 << (size))-1)<<(shift)) |
136 |
|
|
void BeOSSystemDisplay::dumpDisplayChar(const DisplayCharacteristics &chr) |
137 |
|
|
{ |
138 |
|
|
fprintf(stderr, "\tdimensions: %d x %d pixels\n", chr.width, chr.height); |
139 |
|
|
fprintf(stderr, "\tpixel size in bytes: %d\n", chr.bytesPerPixel); |
140 |
|
|
fprintf(stderr, "\tpixel size in bits: %d\n", chr.bytesPerPixel*8); |
141 |
|
|
fprintf(stderr, "\tred_mask: %08x (%d bits)\n", MASK(chr.redShift, chr.redSize), chr.redSize); |
142 |
|
|
fprintf(stderr, "\tgreen_mask: %08x (%d bits)\n", MASK(chr.greenShift, chr.greenSize), chr.greenSize); |
143 |
|
|
fprintf(stderr, "\tblue_mask: %08x (%d bits)\n", MASK(chr.blueShift, chr.blueSize), chr.blueSize); |
144 |
|
|
fprintf(stderr, "\tdepth: %d\n", chr.redSize + chr.greenSize + chr.blueSize); |
145 |
|
|
} |
146 |
|
|
#undef MASK |
147 |
|
|
|
148 |
|
|
uint BeOSSystemDisplay::bitsPerPixelToXBitmapPad(uint bitsPerPixel) |
149 |
|
|
{ |
150 |
|
|
if (bitsPerPixel <= 8) { |
151 |
|
|
return 8; |
152 |
|
|
} else if (bitsPerPixel <= 16) { |
153 |
|
|
return 16; |
154 |
|
|
} else { |
155 |
|
|
return 32; |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
BeOSSystemDisplay::BeOSSystemDisplay(const char *name, const DisplayCharacteristics &aClientChar, int redraw_ms) |
160 |
|
|
:SystemDisplay(aClientChar, redraw_ms) |
161 |
|
|
{ |
162 |
|
|
::printf("BeOSSystemDisplay::BeOSSystemDisplay()\n"); |
163 |
|
|
sys_create_mutex(&mutex); |
164 |
|
|
mEventQueue = new Queue(true); |
165 |
|
|
mMouseEnabled = false; |
166 |
|
|
fbBitmap = NULL; |
167 |
|
|
fMenuBitmap = NULL; |
168 |
|
|
view = NULL; |
169 |
|
|
window = NULL; |
170 |
|
|
gBlankCursor = new BCursor(blank_cursor_data); |
171 |
|
|
gBeOSFramebuffer = NULL; |
172 |
|
|
gFrameBuffer = NULL; |
173 |
|
|
mTitle = strdup(name); |
174 |
|
|
mClientChar = aClientChar; |
175 |
|
|
convertCharacteristicsToHost(mBeChar, mClientChar); |
176 |
|
|
|
177 |
|
|
if (bitsPerPixelToXBitmapPad(mClientChar.bytesPerPixel*8) != mClientChar.bytesPerPixel*8) { |
178 |
|
|
ht_printf("nope. bytes per pixel is: %d. only 1,2 or 4 are allowed.\n", mClientChar.bytesPerPixel); |
179 |
|
|
exit(1); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
mMenuHeight = 28; |
183 |
|
|
|
184 |
|
|
/* framebuffer = (byte*)malloc(mClientChar.width * |
185 |
|
|
mClientChar.height * mClientChar.bytesPerPixel); |
186 |
|
|
memset(framebuffer, 0, mClientChar.width * |
187 |
|
|
mClientChar.height * mClientChar.bytesPerPixel); |
188 |
|
|
*/ |
189 |
|
|
mHomeMouseX = mClientChar.width / 2; |
190 |
|
|
mHomeMouseY = mClientChar.height / 2; |
191 |
|
|
|
192 |
|
|
mouseData = (byte*)malloc(2 * 2 * mClientChar.bytesPerPixel); |
193 |
|
|
memset(mouseData, 0, 2 * 2 * mClientChar.bytesPerPixel); |
194 |
|
|
|
195 |
|
|
BRect fbbounds(0, 0, mClientChar.width - 1, mClientChar.height - 1); |
196 |
|
|
BRect frame(fbbounds); |
197 |
|
|
#ifdef BMP_MENU |
198 |
|
|
frame.bottom += mMenuHeight; |
199 |
|
|
#endif |
200 |
|
|
BScreen bs; |
201 |
|
|
BRect sf(bs.Frame()); |
202 |
|
|
frame.OffsetBySelf((sf.Width() - frame.Width()) / 2, (sf.Height() - frame.Height()) / 2); |
203 |
|
|
|
204 |
|
|
color_space cs = B_RGB32; |
205 |
|
|
mBeChar = mClientChar; |
206 |
|
|
if (mClientChar.bytesPerPixel == 2) { |
207 |
|
|
cs = B_RGB15; |
208 |
|
|
mBeChar.redShift = 10; |
209 |
|
|
mBeChar.redSize = 5; |
210 |
|
|
mBeChar.greenShift = 5; |
211 |
|
|
mBeChar.greenSize = 5; |
212 |
|
|
mBeChar.blueShift = 0; |
213 |
|
|
mBeChar.blueSize = 5; |
214 |
|
|
/* cs = B_RGB16; |
215 |
|
|
mBeChar.redShift = 11; |
216 |
|
|
mBeChar.redSize = 5; |
217 |
|
|
mBeChar.greenShift = 5; |
218 |
|
|
mBeChar.greenSize = 6; |
219 |
|
|
mBeChar.blueShift = 0; |
220 |
|
|
mBeChar.blueSize = 5;*/ |
221 |
|
|
} else { |
222 |
|
|
mBeChar.bytesPerPixel = 4; |
223 |
|
|
mBeChar.redShift = 16; |
224 |
|
|
mBeChar.redSize = 8; |
225 |
|
|
mBeChar.greenShift = 8; |
226 |
|
|
mBeChar.greenSize = 8; |
227 |
|
|
mBeChar.blueShift = 0; |
228 |
|
|
mBeChar.blueSize = 8; |
229 |
|
|
} |
230 |
|
|
fbBitmap = new BBitmap(fbbounds, 0, cs); |
231 |
|
|
if (fbBitmap->InitCheck()) { |
232 |
|
|
fprintf(stderr, "BBitmap error 0x%08lx\n", fbBitmap->InitCheck()); |
233 |
|
|
exit(1); |
234 |
|
|
} |
235 |
|
|
mBeChar.width = fbBitmap->BytesPerRow() / mBeChar.bytesPerPixel; |
236 |
|
|
|
237 |
|
|
#if 0 |
238 |
|
|
fprintf(stderr, "BBitmap display characteristics:\n"); |
239 |
|
|
dumpDisplayChar(mBeChar); |
240 |
|
|
fprintf(stderr, "Client display characteristics:\n"); |
241 |
|
|
dumpDisplayChar(mClientChar); |
242 |
|
|
#endif |
243 |
|
|
|
244 |
|
|
|
245 |
|
|
// Maybe client and (X-)server display characeristics match |
246 |
|
|
if (0 && memcmp(&mClientChar, &mBeChar, sizeof (mClientChar)) == 0) { |
247 |
|
|
fprintf(stderr, "client and server display characteristics match!!\n"); |
248 |
|
|
gFrameBuffer = (byte *)fbBitmap->Bits(); |
249 |
|
|
gBeOSFramebuffer = NULL; |
250 |
|
|
} else { |
251 |
|
|
// Otherwise we need a second framebuffer |
252 |
|
|
gBeOSFramebuffer = (byte *)fbBitmap->Bits(); |
253 |
|
|
gFrameBuffer = (byte*)malloc(mClientChar.width * |
254 |
|
|
mClientChar.height * mClientChar.bytesPerPixel); |
255 |
|
|
memset(gFrameBuffer, 0, mClientChar.width * |
256 |
|
|
mClientChar.height * mClientChar.bytesPerPixel); |
257 |
|
|
fprintf(stderr, "gFrameBuffer = %p\n", gFrameBuffer); |
258 |
|
|
//fprintf(stderr, "client and server display characteristics DONT match :-(\n"); |
259 |
|
|
|
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
#ifdef BMP_MENU |
263 |
|
|
fbbounds.bottom += mMenuHeight; |
264 |
|
|
#endif |
265 |
|
|
|
266 |
|
|
window = new SDWindow(frame, mTitle); |
267 |
|
|
view = new SDView(this/*fbBitmap*/, fbbounds, "framebuffer"); |
268 |
|
|
window->AddChild(view); |
269 |
|
|
view->MakeFocus(true); |
270 |
|
|
//view->Invalidate(view->Bounds()); |
271 |
|
|
|
272 |
|
|
window->SetPulseRate(redraw_ms*1000); |
273 |
|
|
window->Show(); |
274 |
|
|
|
275 |
|
|
//updateTitle(); |
276 |
|
|
|
277 |
|
|
#if 0 /* XXX: remove */ |
278 |
|
|
switch (mClientChar.bytesPerPixel) { |
279 |
|
|
case 1: |
280 |
|
|
ht_printf("nyi: %s::%d", __FILE__, __LINE__); |
281 |
|
|
exit(-1); |
282 |
|
|
break; |
283 |
|
|
case 2: |
284 |
|
|
gPosixRGBMask.r_mask = 0x7c007c007c007c00ULL; |
285 |
|
|
gPosixRGBMask.g_mask = 0x03e003e003e003e0ULL; |
286 |
|
|
gPosixRGBMask.b_mask = 0x001f001f001f001fULL; |
287 |
|
|
break; |
288 |
|
|
case 4: |
289 |
|
|
gPosixRGBMask.r_mask = 0x00ff000000ff0000ULL; |
290 |
|
|
gPosixRGBMask.g_mask = 0x0000ff000000ff00ULL; |
291 |
|
|
gPosixRGBMask.b_mask = 0x000000ff000000ffULL; |
292 |
|
|
break; |
293 |
|
|
} |
294 |
|
|
#endif |
295 |
|
|
menuData = NULL; |
296 |
|
|
setExposed(true); |
297 |
|
|
::printf("BeOSSystemDisplay::BeOSSystemDisplay() end\n"); |
298 |
|
|
} |
299 |
|
|
|
300 |
|
|
BeOSSystemDisplay::~BeOSSystemDisplay() |
301 |
|
|
{ |
302 |
|
|
if (!window) return; |
303 |
|
|
window->Lock(); |
304 |
|
|
window->Quit(); |
305 |
|
|
delete fbBitmap; |
306 |
|
|
delete gBlankCursor; |
307 |
|
|
gBlankCursor = NULL; |
308 |
|
|
|
309 |
|
|
free(mTitle); |
310 |
|
|
free(mouseData); |
311 |
|
|
if (gBeOSFramebuffer) |
312 |
|
|
free(gFrameBuffer); |
313 |
|
|
gFrameBuffer = NULL; |
314 |
|
|
gBeOSFramebuffer = NULL; |
315 |
|
|
#ifdef BMP_MENU |
316 |
|
|
//if (menuData) free(menuData); |
317 |
|
|
#endif |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
void BeOSSystemDisplay::finishMenu() |
321 |
|
|
{ |
322 |
|
|
#ifdef BMP_MENU |
323 |
|
|
/* menuData = (byte*)malloc(mBeChar.width * |
324 |
|
|
mMenuHeight * mBeChar.bytesPerPixel); |
325 |
|
|
gMenuXImage = XCreateImage(gXDisplay, DefaultVisual(gXDisplay, DefaultScreen(gXDisplay)), |
326 |
|
|
mBeChar.redSize+mBeChar.greenSize+mBeChar.blueSize, ZPixmap, 0, (char*)menuData, |
327 |
|
|
mBeChar.width, mMenuHeight, |
328 |
|
|
mBeChar.bytesPerPixel*8, 0); |
329 |
|
|
*/ |
330 |
|
|
// Is this ugly? Yes! |
331 |
|
|
fillRGB(0, 0, mClientChar.width, mClientChar.height, MK_RGB(0xff, 0xff, 0xff)); |
332 |
|
|
drawMenu(); |
333 |
|
|
convertDisplayClientToServer(0, mClientChar.height-1); |
334 |
|
|
fMenuBitmap = new BBitmap(BRect(0,0,mBeChar.width-1,mMenuHeight-1), 0, fbBitmap->ColorSpace()); |
335 |
|
|
menuData = (byte *)fMenuBitmap->Bits(); |
336 |
|
|
if (gBeOSFramebuffer) { |
337 |
|
|
memmove(menuData, gBeOSFramebuffer, mBeChar.width * mMenuHeight |
338 |
|
|
* mBeChar.bytesPerPixel); |
339 |
|
|
} else { |
340 |
|
|
memmove(menuData, gFrameBuffer, mBeChar.width * mMenuHeight |
341 |
|
|
* mBeChar.bytesPerPixel); |
342 |
|
|
} |
343 |
|
|
view->LockLooper(); |
344 |
|
|
view->Invalidate(BRect(0, 0, mBeChar.width-1, mMenuHeight-1)); |
345 |
|
|
view->UnlockLooper(); |
346 |
|
|
|
347 |
|
|
/* |
348 |
|
|
if (fMenuBitmap) { |
349 |
|
|
BWindow *w = new BWindow(fMenuBitmap->Bounds(), "debug", B_TITLED_WINDOW, 0L); |
350 |
|
|
BView *v = new BView(fMenuBitmap->Bounds(), "debugview", B_FOLLOW_NONE, B_WILL_DRAW); |
351 |
|
|
w->AddChild(v); |
352 |
|
|
v->SetViewBitmap(fMenuBitmap); |
353 |
|
|
w->Show(); |
354 |
|
|
}*/ |
355 |
|
|
|
356 |
|
|
#endif |
357 |
|
|
} |
358 |
|
|
|
359 |
|
|
void BeOSSystemDisplay::convertCharacteristicsToHost(DisplayCharacteristics &aHostChar, const DisplayCharacteristics &aClientChar) |
360 |
|
|
{ |
361 |
|
|
BScreen bs; |
362 |
|
|
aHostChar = aClientChar; |
363 |
|
|
switch (bs.ColorSpace()) { |
364 |
|
|
case B_RGB32: |
365 |
|
|
case B_RGBA32: |
366 |
|
|
case B_RGB24: |
367 |
|
|
aHostChar.bytesPerPixel = 4; |
368 |
|
|
break; |
369 |
|
|
case B_RGB16: |
370 |
|
|
case B_RGB15: |
371 |
|
|
case B_RGBA15: |
372 |
|
|
aHostChar.bytesPerPixel = 2; |
373 |
|
|
break; |
374 |
|
|
case B_CMAP8: |
375 |
|
|
case B_GRAY8: |
376 |
|
|
aHostChar.bytesPerPixel = 1; |
377 |
|
|
break; |
378 |
|
|
default: |
379 |
|
|
exit(1); |
380 |
|
|
} |
381 |
|
|
aHostChar.scanLineLength = aHostChar.bytesPerPixel * bs.Frame().IntegerWidth(); |
382 |
|
|
} |
383 |
|
|
|
384 |
|
|
bool BeOSSystemDisplay::changeResolution(const DisplayCharacteristics &aCharacteristics) |
385 |
|
|
{ |
386 |
|
|
// reject resolutions bigger than desktop. |
387 |
|
|
// Not really necessary as BeOS isn't as broken as Windoze(tm). |
388 |
|
|
BScreen bs; |
389 |
|
|
BRect desktoprect(bs.Frame()); |
390 |
|
|
if (aCharacteristics.width > (desktoprect.Width() + 1) |
391 |
|
|
|| aCharacteristics.height > (desktoprect.Height() + 1)) { |
392 |
|
|
// protect user from himself |
393 |
|
|
return false; |
394 |
|
|
} |
395 |
|
|
if (!view) |
396 |
|
|
return false; |
397 |
|
|
|
398 |
|
|
//return false; |
399 |
|
|
if (!view->LockLooper()) |
400 |
|
|
return false; |
401 |
|
|
mClientChar = aCharacteristics; |
402 |
|
|
|
403 |
|
|
mHomeMouseX = mClientChar.width / 2; |
404 |
|
|
mHomeMouseY = mClientChar.height / 2; |
405 |
|
|
|
406 |
|
|
mBeChar.height = mClientChar.height; |
407 |
|
|
mBeChar.width = mClientChar.width; |
408 |
|
|
gFrameBuffer = (byte*)realloc(gFrameBuffer, mClientChar.width |
409 |
|
|
* mClientChar.height * mClientChar.bytesPerPixel); |
410 |
|
|
memset(gFrameBuffer, 0, mClientChar.width |
411 |
|
|
* mClientChar.height * mClientChar.bytesPerPixel); |
412 |
|
|
delete fbBitmap; |
413 |
|
|
fbBitmap = NULL; |
414 |
|
|
BRect fbbounds(0, 0, mClientChar.width - 1, mClientChar.height - 1); |
415 |
|
|
color_space cs = B_RGB32; |
416 |
|
|
mBeChar = mClientChar; |
417 |
|
|
if (mClientChar.bytesPerPixel == 2) { |
418 |
|
|
cs = B_RGB15; |
419 |
|
|
mBeChar.redShift = 10; |
420 |
|
|
mBeChar.redSize = 5; |
421 |
|
|
mBeChar.greenShift = 5; |
422 |
|
|
mBeChar.greenSize = 5; |
423 |
|
|
mBeChar.blueShift = 0; |
424 |
|
|
mBeChar.blueSize = 5; |
425 |
|
|
} else { |
426 |
|
|
mBeChar.bytesPerPixel = 4; |
427 |
|
|
mBeChar.redShift = 16; |
428 |
|
|
mBeChar.redSize = 8; |
429 |
|
|
mBeChar.greenShift = 8; |
430 |
|
|
mBeChar.greenSize = 8; |
431 |
|
|
mBeChar.blueShift = 0; |
432 |
|
|
mBeChar.blueSize = 8; |
433 |
|
|
} |
434 |
|
|
fbBitmap = new BBitmap(fbbounds, 0, cs); |
435 |
|
|
if (fbBitmap->InitCheck()) { |
436 |
|
|
fprintf(stderr, "BBitmap error 0x%08lx\n", fbBitmap->InitCheck()); |
437 |
|
|
exit(1); |
438 |
|
|
} |
439 |
|
|
gBeOSFramebuffer = (byte *)fbBitmap->Bits(); |
440 |
|
|
mBeChar.width = fbBitmap->BytesPerRow() / mBeChar.bytesPerPixel; |
441 |
|
|
//dumpDisplayChar(mBeChar); |
442 |
|
|
damageFrameBufferAll(); |
443 |
|
|
#ifdef BMP_MENU |
444 |
|
|
// WTF does this -1 come from ?? |
445 |
|
|
window->ResizeTo(mBeChar.width-1, mBeChar.height+mMenuHeight-1); |
446 |
|
|
#else |
447 |
|
|
window->ResizeTo(mBeChar.width-1, mBeChar.height-1); |
448 |
|
|
#endif |
449 |
|
|
BRect sf(bs.Frame()); |
450 |
|
|
window->MoveTo((sf.Width() - window->Bounds().Width()) / 2, (sf.Height() - window->Bounds().Height()) / 2); |
451 |
|
|
|
452 |
|
|
view->UnlockLooper(); |
453 |
|
|
|
454 |
|
|
// XXX: test that! |
455 |
|
|
return true; |
456 |
|
|
} |
457 |
|
|
|
458 |
|
|
void BeOSSystemDisplay::getHostCharacteristics(Container &modes) |
459 |
|
|
{ |
460 |
|
|
// FIXME: implement me |
461 |
|
|
} |
462 |
|
|
|
463 |
|
|
int BeOSSystemDisplay::getKeybLEDs() |
464 |
|
|
{ |
465 |
|
|
int r = 0; |
466 |
|
|
uint32 mods = modifiers(); |
467 |
|
|
if (mods & B_CAPS_LOCK) r |= KEYB_LED_NUM; |
468 |
|
|
if (mods & B_CAPS_LOCK) r |= KEYB_LED_CAPS; |
469 |
|
|
if (mods & B_SCROLL_LOCK) r |= KEYB_LED_SCROLL; |
470 |
|
|
return r; |
471 |
|
|
} |
472 |
|
|
|
473 |
|
|
void BeOSSystemDisplay::setKeybLEDs(int leds) |
474 |
|
|
{ |
475 |
|
|
uint32 mods = 0; |
476 |
|
|
if (leds & KEYB_LED_NUM) mods |= B_CAPS_LOCK; |
477 |
|
|
if (leds & KEYB_LED_CAPS) mods |= B_CAPS_LOCK; |
478 |
|
|
if (leds & KEYB_LED_SCROLL) mods |= B_SCROLL_LOCK; |
479 |
|
|
// XXX: warning: set_keyboard_locks() doesn't work correctly |
480 |
|
|
set_keyboard_locks(mods); |
481 |
|
|
} |
482 |
|
|
|
483 |
|
|
void BeOSSystemDisplay::updateTitle() |
484 |
|
|
{ |
485 |
|
|
String key; |
486 |
|
|
int key_toggle_mouse_grab = gKeyboard->getKeyConfig().key_toggle_mouse_grab; |
487 |
|
|
SystemKeyboard::convertKeycodeToString(key, key_toggle_mouse_grab); |
488 |
|
|
ht_snprintf(mCurTitle, sizeof mCurTitle, "%s - [%s %s mouse]", mTitle,key.contentChar(), (isMouseGrabbed() ? "disables" : "enables")); |
489 |
|
|
window->Lock(); |
490 |
|
|
window->SetTitle(mCurTitle); |
491 |
|
|
window->Unlock(); |
492 |
|
|
} |
493 |
|
|
|
494 |
|
|
int BeOSSystemDisplay::toString(char *buf, int buflen) const |
495 |
|
|
{ |
496 |
|
|
return snprintf(buf, buflen, "POSIX BeOS"); |
497 |
|
|
} |
498 |
|
|
|
499 |
|
|
void BeOSSystemDisplay::setMouseGrab(bool enable) |
500 |
|
|
{ |
501 |
|
|
SystemDisplay::setMouseGrab(enable); |
502 |
|
|
updateTitle(); |
503 |
|
|
if (!view->LockLooper()) |
504 |
|
|
return; |
505 |
|
|
if (enable) { |
506 |
|
|
mResetMouseX = mCurMouseX; |
507 |
|
|
mResetMouseY = mCurMouseY; |
508 |
|
|
view->SetViewCursor(gBlankCursor); |
509 |
|
|
|
510 |
|
|
BPoint p(mHomeMouseX, mHomeMouseY); |
511 |
|
|
view->ConvertToScreen(&p); |
512 |
|
|
set_mouse_position((int32)p.x, (int32)p.y); |
513 |
|
|
} else { |
514 |
|
|
view->SetViewCursor(B_CURSOR_SYSTEM_DEFAULT); |
515 |
|
|
|
516 |
|
|
BPoint p(mResetMouseX, mResetMouseY); |
517 |
|
|
view->ConvertToScreen(&p); |
518 |
|
|
set_mouse_position((int32)p.x, (int32)p.y); |
519 |
|
|
} |
520 |
|
|
view->UnlockLooper(); |
521 |
|
|
} |
522 |
|
|
|
523 |
|
|
void BeOSSystemDisplay::displayShow() |
524 |
|
|
{ |
525 |
|
|
uint firstDamagedLine, lastDamagedLine; |
526 |
|
|
// We've got problems with races here because gcard_write1/2/4 |
527 |
|
|
// might set gDamageAreaFirstAddr, gDamageAreaLastAddr. |
528 |
|
|
// We can't use mutexes in gcard for speed reasons. So we'll |
529 |
|
|
// try to minimize the probability of loosing the race. |
530 |
|
|
if (!isExposed()) return; |
531 |
|
|
if (gDamageAreaFirstAddr > gDamageAreaLastAddr+3) { |
532 |
|
|
return; |
533 |
|
|
} |
534 |
|
|
uint damageAreaFirstAddr = gDamageAreaFirstAddr; |
535 |
|
|
uint damageAreaLastAddr = gDamageAreaLastAddr; |
536 |
|
|
healFrameBuffer(); |
537 |
|
|
// end of race |
538 |
|
|
damageAreaLastAddr += 3; // this is a hack. For speed reasons we |
539 |
|
|
// inaccurately set gDamageAreaLastAddr |
540 |
|
|
// to the first (not last) byte accessed |
541 |
|
|
// accesses are up to 4 bytes "long". |
542 |
|
|
|
543 |
|
|
firstDamagedLine = damageAreaFirstAddr / (mClientChar.width * mClientChar.bytesPerPixel); |
544 |
|
|
lastDamagedLine = damageAreaLastAddr / (mClientChar.width * mClientChar.bytesPerPixel); |
545 |
|
|
// Overflow may happen, because of the hack used above |
546 |
|
|
// and others, that set lastAddr = 0xfffffff0 (damageFrameBufferAll()) |
547 |
|
|
if (lastDamagedLine >= mClientChar.height) { |
548 |
|
|
lastDamagedLine = mClientChar.height-1; |
549 |
|
|
} |
550 |
|
|
//convertDisplayClientToServer(firstDamagedLine, lastDamagedLine); |
551 |
|
|
// wtf, doesn't seem to work... |
552 |
|
|
sys_convert_display(mClientChar, mBeChar, gFrameBuffer, gBeOSFramebuffer, firstDamagedLine, lastDamagedLine); |
553 |
|
|
view->LockLooper(); |
554 |
|
|
|
555 |
|
|
//view->Invalidate(view->Bounds()); |
556 |
|
|
|
557 |
|
|
// supposedly faster than Invalidate() ... |
558 |
|
|
BRect bounds(view->Bounds()); |
559 |
|
|
bounds.top = firstDamagedLine; |
560 |
|
|
bounds.bottom = lastDamagedLine; |
561 |
|
|
#ifdef BMP_MENU |
562 |
|
|
bounds.OffsetBySelf(0, mMenuHeight); |
563 |
|
|
#endif |
564 |
|
|
view->Draw(bounds); |
565 |
|
|
view->Flush(); |
566 |
|
|
|
567 |
|
|
view->UnlockLooper(); |
568 |
|
|
/* |
569 |
|
|
convertDisplayClientToServer(); |
570 |
|
|
sys_lock_mutex(mutex); |
571 |
|
|
XPutImage(gXDisplay, gXWindow, gGC, gMenuXImage, 0, 0, 0, 0, |
572 |
|
|
gDisplay->mClientChar.width, |
573 |
|
|
mMenuHeight); |
574 |
|
|
XPutImage(gXDisplay, gXWindow, gGC, gXImage, 0, 0, 0, mMenuHeight, |
575 |
|
|
gDisplay->mClientChar.width, |
576 |
|
|
gDisplay->mClientChar.height); |
577 |
|
|
if (mHWCursorVisible) { |
578 |
|
|
XPutImage(gXDisplay, gXWindow, gGC, gMouseXImage, 0, 0, |
579 |
|
|
mHWCursorX, mHWCursorY, 2, 2); |
580 |
|
|
} |
581 |
|
|
sys_unlock_mutex(mutex); |
582 |
|
|
*/ |
583 |
|
|
} |
584 |
|
|
|
585 |
|
|
void BeOSSystemDisplay::convertDisplayClientToServer(uint firstLine, uint lastLine) |
586 |
|
|
{ |
587 |
|
|
if (!gBeOSFramebuffer) return; // great! nothing to do. |
588 |
|
|
byte *buf = gFrameBuffer + mClientChar.bytesPerPixel * mClientChar.width * firstLine; |
589 |
|
|
byte *bbuf = gBeOSFramebuffer + mBeChar.bytesPerPixel * mBeChar.width * firstLine; |
590 |
|
|
/* if ((mClientChar.bytesPerPixel == 2) && (mBeChar.bytesPerPixel == 2)) { |
591 |
|
|
posix_vaccel_15_to_15(mClientChar.height*mClientChar.width, buf, xbuf); |
592 |
|
|
} else if ((mClientChar.bytesPerPixel == 2) && (mBeChar.bytesPerPixel == 4)) { |
593 |
|
|
posix_vaccel_15_to_32(mClientChar.height*mClientChar.width, buf, xbuf); |
594 |
|
|
} else */ |
595 |
|
|
for (int y=firstLine; y <= lastLine; y++) { |
596 |
|
|
for (int x=0; x < mClientChar.width; x++) { |
597 |
|
|
uint r, g, b; |
598 |
|
|
uint p; |
599 |
|
|
switch (mClientChar.bytesPerPixel) { |
600 |
|
|
case 1: |
601 |
|
|
p = palette[buf[0]]; |
602 |
|
|
break; |
603 |
|
|
case 2: |
604 |
|
|
p = (buf[0] << 8) | buf[1]; |
605 |
|
|
break; |
606 |
|
|
case 4: |
607 |
|
|
p = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; |
608 |
|
|
break; |
609 |
|
|
default: |
610 |
|
|
ht_printf("internal error in %s:%d\n", __FILE__, __LINE__); |
611 |
|
|
exit(1); |
612 |
|
|
break; |
613 |
|
|
} |
614 |
|
|
r = (p >> mClientChar.redShift) & ((1<<mClientChar.redSize)-1); |
615 |
|
|
g = (p >> mClientChar.greenShift) & ((1<<mClientChar.greenSize)-1); |
616 |
|
|
b = (p >> mClientChar.blueShift) & ((1<<mClientChar.blueSize)-1); |
617 |
|
|
convertBaseColor(r, mClientChar.redSize, mBeChar.redSize); |
618 |
|
|
convertBaseColor(g, mClientChar.greenSize, mBeChar.greenSize); |
619 |
|
|
convertBaseColor(b, mClientChar.blueSize, mBeChar.blueSize); |
620 |
|
|
p = (r << mBeChar.redShift) | (g << mBeChar.greenShift) |
621 |
|
|
| (b << mBeChar.blueShift); |
622 |
|
|
switch (mBeChar.bytesPerPixel) { |
623 |
|
|
case 1: |
624 |
|
|
bbuf[0] = p; |
625 |
|
|
break; |
626 |
|
|
case 2: |
627 |
|
|
bbuf[1] = p>>8; bbuf[0] = p; |
628 |
|
|
break; |
629 |
|
|
case 4: |
630 |
|
|
*(uint32*)bbuf = p; |
631 |
|
|
break; |
632 |
|
|
} |
633 |
|
|
bbuf += mBeChar.bytesPerPixel; |
634 |
|
|
buf += mClientChar.bytesPerPixel; |
635 |
|
|
} |
636 |
|
|
} |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
#if 0 |
640 |
|
|
void BeOSSystemDisplay::queueEvent(DisplayEvent &ev) |
641 |
|
|
{ |
642 |
|
|
DisplayEvent *e = (DisplayEvent *)malloc(sizeof (DisplayEvent)); |
643 |
|
|
*e = ev; |
644 |
|
|
mEventQueue->enQueue(new Pointer(e)); |
645 |
|
|
} |
646 |
|
|
#endif |
647 |
|
|
|
648 |
|
|
void BeOSSystemDisplay::startRedrawThread(int msec) |
649 |
|
|
{ |
650 |
|
|
::printf("startRedrawTh\n"); |
651 |
|
|
window->Lock(); |
652 |
|
|
window->SetPulseRate(msec*1000); |
653 |
|
|
window->Unlock(); |
654 |
|
|
} |
655 |
|
|
|
656 |
|
|
SystemDisplay *allocSystemDisplay(const char *title, const DisplayCharacteristics &chr, int redraw_ms) |
657 |
|
|
{ |
658 |
|
|
if (gDisplay) return NULL; |
659 |
|
|
return new BeOSSystemDisplay(title, chr, redraw_ms); |
660 |
|
|
} |