Commit 6bc8b1f07dfb665350079ea93c373bb2670a68ae

David Turner 2000-01-14T15:36:55

bugfixes to the OS/2 graphics driver. It now works !!

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
diff --git a/demos/config/os2/gros2pm.c b/demos/config/os2/gros2pm.c
index 976f58d..e234365 100644
--- a/demos/config/os2/gros2pm.c
+++ b/demos/config/os2/gros2pm.c
@@ -10,13 +10,26 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdarg.h>
 
+#define  DEBUGxxx
 
-  static void Panic( const char* message )
+#ifdef DEBUG
+#define LOG(x)  LogMessage##x
+#else
+#define LOG(x)  /* rien */
+#endif
+
+#ifdef DEBUG
+  static void  LogMessage( const char*  fmt, ... )
   {
-    fprintf( stderr, "%s", message );
-    exit(1);
+    va_list  ap;
+
+    va_start( ap, fmt );
+    vfprintf( stderr, fmt, ap );
+    va_end( ap );
   }
+#endif
 
   typedef struct Translator
   {
@@ -58,15 +71,10 @@
 
 #define MAX_PIXEL_MODES  32
 
-  static int           num_pixel_modes = 0;
-  static grPixelMode   pixel_modes[ MAX_PIXEL_MODES ];  
-  static int           pixel_depth[ MAX_PIXEL_MODES ];
-
   static  HAB   gr_anchor;   /* device anchor block */
 
   typedef POINTL  PMBlitPoints[4];
 
-
   typedef struct grPMSurface_
   {
     grSurface  root;
@@ -107,6 +115,12 @@
 
   } grPMSurface;
 
+  /* we use a static variable to pass a pointer to the PM Surface  */
+  /* to the client window. This is a bit ugly, but it makes things */
+  /* a lot more simple..                                           */
+  static  grPMSurface*  the_surface;
+
+  static  int window_created = 0;
 
 
   static
@@ -161,6 +175,8 @@
   static
   void  done_surface( grPMSurface*  surface )
   {
+    LOG(( "Os2PM: done_surface(%08lx)\n", (long)surface ));
+
     if ( surface->frame_window )
       WinDestroyWindow( surface->frame_window );
 
@@ -174,20 +190,6 @@
 
 
 
-  static
-  void add_pixel_mode( grPixelMode  pixel_mode,
-                       int          depth )
-  {
-    if ( num_pixel_modes >= MAX_PIXEL_MODES )
-      Panic( "X11.Too many pixel modes\n" );
-      
-    pixel_modes[ num_pixel_modes ] = pixel_mode;
-    pixel_depth[ num_pixel_modes ] = depth;
-    
-    num_pixel_modes++;
-  }
-
-
 #define LOCK(x)    DosRequestMutexSem( x, SEM_INDEFINITE_WAIT );
 #define UNLOCK(x)  DosReleaseMutexSem( x )
 
@@ -222,7 +224,7 @@
   *   surfaces :
   *
   *     - hold, for each surface, its own bitmap buffer where the
-  *       rest of MiGS writes directly.
+  *       rest of the graph library writes directly.
   *
   *     - create a PM bitmap object with the same dimensions (and
   *       possibly format).
@@ -265,199 +267,30 @@
 
 
   static
-  void  convert_gray_to_pal8( grPMSurface* surface,
-                              int          x,
-                              int          y,
-                              int          w,
-                              int          h )
-  {
-    grBitmap*  target  = &surface->image;
-    grBitmap*  source  = &surface->root.bitmap;
-    byte*      write   = (byte*)target->buffer + y*target->pitch + x;
-    byte*      read    = (byte*)source->buffer + y*source->pitch + x;
-    long*      palette = surface->shades;
-    
-    while (h > 0)
-    {
-      byte*  _write = write;
-      byte*  _read  = read;
-      byte*  limit  = _write + w;
-      
-      for ( ; _write < limit; _write++, _read++ )
-        *_write = (byte) palette[ *_read ];
-
-      write += target->pitch;
-      read  += source->pitch;
-      h--;
-    }
-  }
-
-
-  static
-  void  convert_gray_to_16( grPMSurface* surface,
-                            int          x,
-                            int          y,
-                            int          w,
-                            int          h )
-  {
-    grBitmap*  target  = &surface->image;
-    grBitmap*  source  = &surface->root.bitmap;
-    byte*      write   = (byte*)target->buffer + y*target->pitch + 2*x;
-    byte*      read    = (byte*)source->buffer + y*source->pitch + x;
-    long*           palette = surface->shades;
-    
-    while (h > 0)
-    {
-      byte*  _write = write;
-      byte*  _read  = read;
-      byte*  limit  = _write + 2*w;
-      
-      for ( ; _write < limit; _write += 2, _read++ )
-        *(short*)_write = (short)palette[ *_read ];
-
-      write += target->pitch;
-      read  += source->pitch;
-      h--;
-    }
-  }
-
-
-  static
-  void  convert_gray_to_24( grPMSurface* surface,
-                            int          x,
-                            int          y,
-                            int          w,
-                            int          h )
-  {
-    grBitmap*  target  = &surface->image;
-    grBitmap*  source  = &surface->root.bitmap;
-    byte*      write   = (byte*)target->buffer + y*target->pitch + 3*x;
-    byte*      read    = (byte*)source->buffer + y*source->pitch + x;
-    
-    while (h > 0)
-    {
-      byte*  _write = write;
-      byte*  _read  = read;
-      byte*  limit  = _write + 3*w;
-      
-      for ( ; _write < limit; _write += 3, _read++ )
-      {
-        byte  color = *_read;
-        
-        _write[0] =
-        _write[1] =
-        _write[2] = color;
-      }
-
-      write += target->pitch;
-      read  += source->pitch;
-      h--;
-    }
-  }
-
-
-  static
-  void  convert_gray_to_32( grPMSurface* surface,
-                            int          x,
-                            int          y,
-                            int          w,
-                            int          h )
-  {
-    grBitmap*  target  = &surface->image;
-    grBitmap*  source  = &surface->root.bitmap;
-    byte*      write   = (byte*)target->buffer + y*target->pitch + 4*x;
-    byte*      read    = (byte*)source->buffer + y*source->pitch + x;
-    
-    while (h > 0)
-    {
-      byte*  _write = write;
-      byte*  _read  = read;
-      byte*  limit  = _write + 4*w;
-      
-      for ( ; _write < limit; _write += 4, _read++ )
-      {
-        byte  color = *_read;
-        
-        _write[0] =
-        _write[1] =
-        _write[2] =
-        _write[3] = color;
-      }
-
-      write += target->pitch;
-      read  += source->pitch;
-      h--;
-    }
-  }
-
-
-  static
-  void  convert_rectangle( grPMSurface* surface,
+  void  refresh_rectangle( grPMSurface* surface,
                            int          x,
                            int          y,
                            int          w,
                            int          h )
   {
-    int  z;
-    
-    /* first of all, clip to the surface's area */
-    if ( x   >= surface->image.width ||
-         x+w <= 0                    ||
-         y   >= surface->image.rows  ||
-         y+h <= 0 )
-      return;
- 
-    if ( x < 0 )
-    {
-      w += x;
-      x  = 0;
-    }
- 
-    z = (x + w) - surface->image.width;
-    if (z > 0)
-      w -= z;
-      
-    z = (y + h) - surface->image.rows;
-    if (z > 0)
-      h -= z;
-      
-    /* convert the rectangle to the target depth for gray surfaces */
-    if (surface->root.bitmap.mode == gr_pixel_mode_gray)
-    {
-      switch (surface->image.mode)
-      {
-        case gr_pixel_mode_pal8  :
-          convert_gray_to_pal8( surface, x, y, w, h );
-          break;
-
-        case gr_pixel_mode_rgb555:
-        case gr_pixel_mode_rgb565:
-          convert_gray_to_16  ( surface, x, y, w, h );
-          break;
-
-        case gr_pixel_mode_rgb24:
-          convert_gray_to_24  ( surface, x, y, w, h );
-          break;
-
-        case gr_pixel_mode_rgb32:
-          convert_gray_to_32  ( surface, x, y, w, h );
-          break;
-
-        default:
-          ;
-      }
-    }
-  } 
+    LOG(( "Os2PM: refresh_rectangle( %08lx, %d, %d, %d, %d )\n",
+          (long)surface, x, y, w, h ));
 
+    (void)x;
+    (void)y;
+    (void)w;
+    (void)h;
 
-  static
-  void  refresh_rectangle( grPMSurface* surface,
-                           int          x,
-                           int          y,
-                           int          w,
-                           int          h )
-  {
+    /*
     convert_rectangle( surface, x, y, w, h );
+    */
+    DosRequestMutexSem( surface->image_lock, SEM_INDEFINITE_WAIT );
+    GpiSetBitmapBits( surface->image_ps,
+                      0,
+                      surface->root.bitmap.rows,
+                      surface->root.bitmap.buffer,
+                      surface->bitmap_header );
+    DosReleaseMutexSem( surface->image_lock );
 
     WinInvalidateRect( surface->client_window, NULL, FALSE );
     WinUpdateWindow( surface->frame_window );
@@ -468,7 +301,20 @@
   void  set_title( grPMSurface* surface,
                    const char*  title )
   {
-    WinSetWindowText( surface->title_window, (PSZ)title );
+    ULONG  rc;
+
+#if 1
+    LOG(( "Os2PM: set_title( %08lx == %08lx, %s )\n",
+             (long)surface, surface->client_window, title ));
+#endif
+    LOG(( "      -- frame         = %08lx\n",
+          (long)surface->frame_window ));
+
+    LOG(( "      -- client parent = %08lx\n",
+          (long)WinQueryWindow( surface->client_window, QW_PARENT ) ));
+
+    rc = WinSetWindowText( surface->client_window, (PSZ)title );
+    LOG(( "      -- returned rc = %ld\n",rc ));
   }
 
 
@@ -500,6 +346,15 @@
     SIZEL         sizl = { 0, 0 };
     LONG          palette[256];
 
+    LOG(( "Os2PM: init_surface( %08lx, %08lx )\n",
+          (long)surface, (long)bitmap ));
+
+    LOG(( "       -- input bitmap =\n" ));
+    LOG(( "       --   mode   = %d\n", bitmap->mode ));
+    LOG(( "       --   grays  = %d\n", bitmap->grays ));
+    LOG(( "       --   width  = %d\n", bitmap->width ));
+    LOG(( "       --   height = %d\n", bitmap->rows ));
+
     /* create the bitmap - under OS/2, we support all modes as PM */
     /* handles all conversions automatically..                    */
     if ( grNewBitmap( bitmap->mode,
@@ -509,6 +364,13 @@
                       bitmap ) )
       return 0;
 
+    LOG(( "       -- output bitmap =\n" ));
+    LOG(( "       --   mode   = %d\n", bitmap->mode ));
+    LOG(( "       --   grays  = %d\n", bitmap->grays ));
+    LOG(( "       --   width  = %d\n", bitmap->width ));
+    LOG(( "       --   height = %d\n", bitmap->rows ));
+
+    bitmap->pitch = -bitmap->pitch;
     surface->root.bitmap = *bitmap;
 
     /* create the image and event lock */
@@ -536,15 +398,41 @@
     bit->cy      = surface->root.bitmap.rows;
     bit->cPlanes = 1;
 
-    bit->argbColor[0].bBlue  = 0;
+    bit->argbColor[0].bBlue  = 255;
     bit->argbColor[0].bGreen = 0;
     bit->argbColor[0].bRed   = 0;
 
-    bit->argbColor[1].bBlue  = 255;
+    bit->argbColor[1].bBlue  = 0;
     bit->argbColor[1].bGreen = 255;
-    bit->argbColor[1].bRed   = 255;
+    bit->argbColor[1].bRed   = 0;
 
-    bit->cBitCount = pixel_mode_bit_count[ surface->root.bitmap.mode ];
+    bit->cBitCount = (bitmap->mode == gr_pixel_mode_gray ? 8 : 1 );
+
+    if (bitmap->mode == gr_pixel_mode_gray)
+    {
+      RGB2*  color = bit->argbColor;
+      int    x, count;
+
+      count = bitmap->grays;
+      for ( x = 0; x < count; x++, color++ )
+      {
+        color->bBlue  =
+        color->bGreen =
+        color->bRed   = (((count-x)*255)/count);
+      }
+    }
+    else
+    {
+      RGB2*  color = bit->argbColor;
+
+      color[0].bBlue  =
+      color[0].bGreen =
+      color[0].bRed   = 0;
+
+      color[1].bBlue  =
+      color[1].bGreen =
+      color[1].bRed   = 255;
+    }
 
     surface->os2_bitmap = GpiCreateBitmap( surface->image_ps,
                                            (PBITMAPINFOHEADER2)bit,
@@ -555,6 +443,7 @@
     bit->cbFix = sizeof( BITMAPINFOHEADER2 );
     GpiQueryBitmapInfoHeader( surface->os2_bitmap,
                               (PBITMAPINFOHEADER2)bit );
+    surface->bitmap_header = bit;
 
     /* for gr_pixel_mode_gray, create a gray-levels logical palette */
     if ( bitmap->mode == gr_pixel_mode_gray )
@@ -584,6 +473,8 @@
     surface->blit_points[1].y = surface->root.bitmap.rows;
     surface->blit_points[3]   = surface->blit_points[1];
 
+    window_created = 0;
+
     /* Finally, create the event handling thread for the surface's window */
     DosCreateThread( &surface->message_thread,
                      (PFNTHREAD) RunPMWindow,
@@ -591,12 +482,15 @@
                      0UL,
                      32920 );
 
+    /* wait for the window creation */
+    for ( ; window_created == 0; )
+
     surface->root.done         = (grDoneSurfaceFunc) done_surface;
     surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle;
     surface->root.set_title    = (grSetTitleFunc)    set_title;
     surface->root.listen_event = (grListenEventFunc) listen_event;
-    
-    convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows );
+
+    /* convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows ); */
     return surface;
   }
 
@@ -617,6 +511,13 @@
     static   HMQ    queue;
              QMSG   message;
 
+    /* store the current surface pointer in "the_surface". It is a static */
+    /* variable that is only used to retrieve the pointer in the client   */
+    /* window procedure the first time is is called..                     */
+    the_surface = surface;
+
+    LOG(( "Os2PM: RunPMWindow( %08lx )\n", (long)surface ));
+     
     /* create an anchor to allow this thread to use PM */
     surface->anchor = WinInitialize(0);
     if (!surface->anchor)
@@ -648,12 +549,13 @@
     class_flags = FCF_TITLEBAR | FCF_MINBUTTON | FCF_DLGBORDER | 
                   FCF_TASKLIST | FCF_SYSMENU; 
 
+    LOG(( "Os2PM: RunPMWindow: Creating window\n" ));
     surface->frame_window = WinCreateStdWindow(
                                 HWND_DESKTOP,
                                 WS_VISIBLE,
                                 &class_flags,
                                 (PSZ) class_name,
-                                (PSZ) "FreeType PM Graphics",
+                                (PSZ) "FreeType Viewer - press F1 for help",
                                 WS_VISIBLE,
                                 0, 0,
                                 &surface->client_window );
@@ -666,13 +568,17 @@
     /* find the title window handle */
     surface->title_window = WinWindowFromID( surface->frame_window,
                                              FID_TITLEBAR );
+    LOG (( "Os2PM: RunPMWIndow: Creation succeeded\n" ));
+    LOG (( "    -- frame  = %08lx\n", surface->frame_window ));
+    LOG (( "    -- client = %08lx\n", surface->client_window ));
 
     /* set Window size and position */
     WinSetWindowPos( surface->frame_window,
                      0L,
                      (SHORT) 60,
+
                      (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) -
-                             surface->root.bitmap.rows + 100,
+                             (surface->root.bitmap.rows + 100),
 
                      (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME )*2 +
                              surface->root.bitmap.width,
@@ -683,12 +589,18 @@
 
                      SWP_SIZE | SWP_MOVE );
 
+#if 0
     /* save the handle to the current surface within the window words */
-    WinSetWindowPtr( surface->frame_window,QWL_USER, surface );
+    WinSetWindowPtr( surface->client_window,QWL_USER, surface );
+#endif
+
+    window_created = 1;
 
     /* run the message queue till the end */
     while ( WinGetMsg( surface->anchor, &message, (HWND)NULL, 0, 0 ) )
+    {
       WinDispatchMsg( surface->anchor, &message );
+    }
 
     /* clean-up */
     WinDestroyWindow( surface->frame_window );
@@ -720,8 +632,14 @@
 
      grPMSurface*  surface;
 
-    /* get the handle to the window's surface */
+    /* get the handle to the window's surface -- note that this */
+    /* value will be null when the window is created            */
     surface = (grPMSurface*)WinQueryWindowPtr( handle, QWL_USER );
+    if (!surface)
+    {
+      surface = the_surface;
+      WinSetWindowPtr( handle, QWL_USER, surface );
+    }
 
     switch( mess )
     {
@@ -743,9 +661,9 @@
                                &sizl,
                                PU_PELS | GPIT_MICRO |
                                GPIA_ASSOC | GPIF_DEFAULT );
-
       /* take the input focus */
       WinFocusChange( HWND_DESKTOP, handle, 0L );
+      LOG(( "screen_dc and screen_ps have been created\n" ));
       break;
 
     case WM_MINMAXFRAME:
@@ -775,6 +693,10 @@
       DosReleaseMutexSem( surface->image_lock );   
       break;
 
+    case WM_HELP:  /* this really is a F1 Keypress !! */
+      surface->event.key = grKeyF1;
+      goto Do_Key_Event;
+
     case WM_CHAR:
       if ( CHARMSG( &mess )->fs & KC_KEYUP )
         break;
@@ -814,61 +736,6 @@
 
 
 
-
-
-
-#if 0
-  static
-  grKey  KeySymTogrKey(   key )
-  {
-    grKey        k;
-    int          count = sizeof(key_translators)/sizeof(key_translators[0]);
-    Translator*  trans = key_translators;
-    Translator*  limit = trans + count;
-
-    k = grKeyNone;
-
-    while ( trans < limit )
-    {
-      if ( trans->xkey == key )
-      {
-        k = trans->grkey;
-        break;
-      }
-      trans++;
-    }
-
-    return k;
-  }
-
-
-
-  static  
-  void  listen_event( grPMSurface* surface,
-                      int          event_mask,
-                      grEvent*     grevent )
-  {
-    grKey           grkey;
-
-    /* XXXX : For now, ignore the event mask, and only exit when */
-    /*        a key is pressed..                                 */
-    (void)event_mask;
-
-
-    /* Now, translate the keypress to a grKey */
-    /* If this wasn't part of the simple translated keys, simply get the charcode */
-    /* from the character buffer                                                  */
-    grkey = grKEY(key_buffer[key_cursor++]);
-      
-  Set_Key:
-    grevent->type = gr_key_down;
-    grevent->key  = grkey;
-  }
-
-#endif
-
-
-
   grDevice  gr_os2pm_device =
   {
     sizeof( grPMSurface ),