use the -newos toolchain even if -elf is present.
[newos.git] / apps / window_server / main.cpp
blob483663f2dd858accdfa0d3627d76b9b74741fe93
1 #include <sys/syscalls.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <newos/drivers.h>
6 //#include "Renderer_vga.h"
7 #include "GraphicsContext.h"
8 #include "Window.h"
9 #include "WindowManager.h"
10 #include "Renderer_vesa.h"
12 using namespace os::gui;
14 #if 0
16 #define VENDOR 0x102b
17 #define DEVICE 0x051a
19 struct ColorMapEntry {
20 int red;
21 int green;
22 int blue;
23 } colorTable[255] = {
24 {0, 0, 0},
25 {112, 219, 147},
26 {112, 219, 147},
27 {50, 204, 153},
28 {50, 204, 153},
29 {0, 0, 0},
30 {0, 0, 0},
31 {0, 0, 255},
32 {0, 0, 255},
33 {95, 159, 159},
34 {95, 159, 159},
35 {66, 66, 111},
36 {66, 66, 111},
37 {107, 35, 142},
38 {107, 35, 142},
39 {191, 216, 216},
40 {191, 216, 216},
41 {143, 143, 188},
42 {143, 143, 188},
43 {50, 50, 204},
44 {50, 50, 204},
45 {127, 0, 255},
46 {127, 0, 255},
47 {47, 47, 79},
48 {47, 47, 79},
49 {35, 35, 142},
50 {35, 35, 142},
51 {35, 35, 142},
52 {35, 35, 142},
53 {50, 153, 204},
54 {50, 153, 204},
55 {0, 127, 255},
56 {0, 127, 255},
57 {35, 107, 142},
58 {35, 107, 142},
59 {255, 127, 0},
60 {255, 127, 0},
61 {0, 255, 255},
62 {0, 255, 255},
63 {142, 35, 35},
64 {142, 35, 35},
65 {204, 127, 50},
66 {204, 127, 50},
67 {219, 219, 112},
68 {219, 219, 112},
69 {234, 234, 173},
70 {234, 234, 173},
71 {0, 255, 0},
72 {0, 255, 0},
73 {47, 79, 47},
74 {47, 79, 47},
75 {79, 79, 47},
76 {79, 79, 47},
77 {35, 142, 35},
78 {35, 142, 35},
79 {50, 204, 50},
80 {50, 204, 50},
81 {107, 142, 35},
82 {107, 142, 35},
83 {66, 111, 66},
84 {66, 111, 66},
85 {127, 255, 0},
86 {127, 255, 0},
87 {143, 188, 143},
88 {143, 188, 143},
89 {35, 142, 107},
90 {35, 142, 107},
91 {0, 255, 127},
92 {0, 255, 127},
93 {153, 204, 50},
94 {153, 204, 50},
95 {47, 79, 79},
96 {47, 79, 79},
97 {47, 79, 79},
98 {47, 79, 79},
99 {84, 84, 84},
100 {84, 84, 84},
101 {84, 84, 84},
102 {84, 84, 84},
103 {168, 168, 168},
104 {168, 168, 168},
105 {168, 168, 168},
106 {168, 168, 168},
107 {159, 159, 95},
108 {159, 159, 95},
109 {255, 0, 255},
110 {255, 0, 255},
111 {142, 35, 107},
112 {142, 35, 107},
113 {204, 50, 50},
114 {204, 50, 50},
115 {219, 112, 219},
116 {219, 112, 219},
117 {153, 50, 204},
118 {153, 50, 204},
119 {147, 112, 219},
120 {147, 112, 219},
121 {188, 143, 143},
122 {188, 143, 143},
123 {234, 173, 234},
124 {234, 173, 234},
125 {255, 0, 0},
126 {255, 0, 0},
127 {79, 47, 47},
128 {79, 47, 47},
129 {219, 112, 147},
130 {219, 112, 147},
131 {255, 0, 127},
132 {255, 0, 127},
133 {204, 50, 153},
134 {204, 50, 153},
135 {111, 66, 66},
136 {111, 66, 66},
137 {142, 107, 35},
138 {142, 107, 35},
139 {219, 147, 112},
140 {219, 147, 112},
141 {216, 191, 216},
142 {216, 191, 216},
143 {173, 234, 234},
144 {173, 234, 234},
145 {112, 147, 219},
146 {112, 147, 219},
147 {112, 219, 219},
148 {112, 219, 219},
149 {79, 47, 79},
150 {79, 47, 79},
151 {159, 95, 159},
152 {159, 95, 159},
153 {216, 216, 191},
154 {216, 216, 191},
155 {252, 252, 252},
156 {252, 252, 252},
157 {255, 255, 0},
158 {255, 255, 0},
159 {147, 219, 112},
160 {147, 219, 112},
161 {255, 255, 255},
162 {255, 255, 255},
163 {255, 255, 255},
164 {255, 255, 255},
165 {255, 255, 255},
166 {255, 255, 255},
167 {255, 255, 255},
168 {255, 255, 255},
169 {255, 255, 255},
170 {255, 255, 255},
171 {255, 255, 255},
172 {255, 255, 255},
173 {255, 255, 255},
174 {255, 255, 255},
175 {255, 255, 255},
176 {255, 255, 255},
177 {255, 255, 255},
178 {255, 255, 255},
179 {255, 255, 255},
180 {255, 255, 255},
181 {255, 255, 255},
182 {255, 255, 255},
183 {255, 255, 255},
184 {255, 255, 255},
185 {255, 255, 255},
186 {255, 255, 255},
187 {255, 255, 255},
188 {255, 255, 255},
189 {255, 255, 255},
190 {255, 255, 255},
191 {255, 255, 255},
192 {255, 255, 255},
193 {255, 255, 255},
194 {255, 255, 255},
195 {255, 255, 255},
196 {255, 255, 255},
197 {255, 255, 255},
198 {255, 255, 255},
199 {255, 255, 255},
200 {255, 255, 255},
201 {255, 255, 255},
202 {255, 255, 255},
203 {255, 255, 255},
204 {255, 255, 255},
205 {255, 255, 255},
206 {255, 255, 255},
207 {255, 255, 255},
208 {255, 255, 255},
209 {255, 255, 255},
210 {255, 255, 255},
211 {255, 255, 255},
212 {255, 255, 255},
213 {255, 255, 255},
214 {255, 255, 255},
215 {255, 255, 255},
216 {255, 255, 255},
217 {255, 255, 255},
218 {255, 255, 255},
219 {255, 255, 255},
220 {255, 255, 255},
221 {255, 255, 255},
222 {255, 255, 255},
223 {255, 255, 255},
224 {255, 255, 255},
225 {255, 255, 255},
226 {255, 255, 255},
227 {255, 255, 255},
228 {255, 255, 255},
229 {255, 255, 255},
230 {255, 255, 255},
231 {255, 255, 255},
232 {255, 255, 255},
233 {255, 255, 255},
234 {255, 255, 255},
235 {255, 255, 255},
236 {255, 255, 255},
237 {255, 255, 255},
238 {255, 255, 255},
239 {255, 255, 255},
240 {255, 255, 255},
241 {255, 255, 255},
242 {255, 255, 255},
243 {255, 255, 255},
244 {255, 255, 255},
245 {255, 255, 255},
246 {255, 255, 255},
247 {255, 255, 255},
248 {255, 255, 255},
249 {255, 255, 255},
250 {255, 255, 255},
251 {255, 255, 255},
252 {255, 255, 255},
253 {255, 255, 255},
254 {255, 255, 255},
255 {255, 255, 255},
256 {255, 255, 255},
257 {255, 255, 255},
258 {255, 255, 255},
259 {255, 255, 255},
260 {255, 255, 255},
261 {255, 255, 255},
262 {255, 255, 255},
263 {255, 255, 255},
264 {255, 255, 255},
265 {255, 255, 255},
266 {255, 255, 255},
267 {255, 255, 255},
268 {255, 255, 255},
269 {255, 255, 255},
270 {255, 255, 255},
271 {255, 255, 255},
272 {255, 255, 255},
273 {255, 255, 255},
274 {255, 255, 255},
275 {255, 255, 255},
276 {255, 255, 255},
277 {255, 255, 255},
278 {255, 255, 255} // Transparent color
280 #endif
283 #if 0
284 char *mga_find()
286 uchar *fb;
287 pci_cfg cfg;
289 if(pci_find(&cfg,VENDOR,DEVICE)) return 0;
290 fb = (uchar *) (cfg.base[0] & 0xfffffff0);
291 if(area_create(0x100000, 0, (void**) &(fb), AREA_PHYSMAP) < 0){
292 return 0;
294 #if 1
295 { int i;
296 for(i=0;i<1024*768;i++) fb[i] = i / 3072;
298 #endif
299 return (char*) fb;
302 char *argv[] = { "/boot/www", "www", 0 };
304 int main()
306 // InitVGA();
307 // char *vmem = (char*) 0xa0000;
308 char *vmem = mga_find();
309 if(vmem == 0) return 1;
311 // area_create(64*1024, 0, (void**) &vmem, AREA_PHYSMAP);
312 memset((void*) vmem, 0, 1024 * 768);
314 Renderer *screen = new Renderer_vga((char*) vmem, 1024, 768, 1024);
315 for (int i = 0; i < 256; i++)
316 SetPalette(i, colorTable[i].red, colorTable[i].green, colorTable[i].blue);
318 new WindowManager(screen);
319 os_sleep(1000000);
320 execve(argv[0],argv,0);
321 return 0;
323 #endif
325 int vesa_find(Renderer **renderer)
327 int fd;
328 devfs_framebuffer_info fb;
329 int err;
330 void *framebuffer;
332 fd = open("/dev/graphics/vesa/fb/0", 0);
333 if(fd < 0) {
334 printf("error opening vesa device\n");
335 return -1;
338 err = ioctl(fd, IOCTL_DEVFS_GET_FRAMEBUFFER_INFO, &fb, sizeof(fb));
339 if(err < 0) {
340 printf("error getting framebuffer info\n");
341 return -2;
344 err = ioctl(fd, IOCTL_DEVFS_MAP_FRAMEBUFFER, &framebuffer, sizeof(framebuffer));
345 if(err < 0) {
346 printf("error mapping framebuffer\n");
347 return -3;
350 switch(fb.color_space) {
351 case COLOR_SPACE_RGB555:
352 *renderer = new Renderer_vesa_555((char *)framebuffer, fb.width, fb.height, fb.width * 2);
353 return 0;
354 default:
355 *renderer = 0;
356 return -4;
361 int main(int argc, char **argv)
363 Renderer *screen;
364 int err;
366 err = vesa_find(&screen);
367 if(err < 0) {
368 printf("unable to find framebuffer\n");
369 return err;
373 Rect r = screen->Bounds();
375 // clear the screen
376 screen->FillRect(r, 0xffffffff);
378 int i;
380 for(i = 0; i < 256; i++) {
381 screen->DrawLine(rand() % r.Width(), rand() % r.Height(), rand() % r.Width(), rand() % r.Height(), 0);
384 usleep(2000000);
386 for(i = 0; i < 256; i++) {
387 Rect source;
388 Rect dest;
390 usleep(10000);
392 source.SetTo(rand() % r.Width(), rand() % r.Height(), rand() % r.Width(), rand() % r.Height());
393 dest.SetTo(rand() % r.Width(), rand() % r.Height(), rand() % r.Width(), rand() % r.Height());
394 screen->CopyRect(source, dest);
398 Rect source(100, 100, 200, 200);
399 Rect dest(150, 150, 250, 250);
401 screen->CopyRect(source, dest);
404 usleep(1000000);
407 Rect source(300, 300, 400, 400);
408 Rect dest(250, 250, 350, 350);
410 screen->CopyRect(source, dest);
413 WindowManager *wm = new WindowManager(screen);
415 wm->WaitForExit();
416 return 0;