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
|
Constructor TX11Console.Create;
Var
s : AnsiString;
Begin
Inherited Create;
{ default flags }
FFlags := [PTC_X11_TRY_XSHM, PTC_X11_TRY_XF86VIDMODE];
FTitle := '';
Configure('/usr/share/ptcpas/ptcpas.conf');
s := fpgetenv('HOME');
If s = '' Then
s := '/';
If s[Length(s)] <> '/' Then
s := s + '/';
s := s + '.ptcpas.conf';
Configure(s);
End;
Destructor TX11Console.Destroy;
Var
I : Integer;
Begin
Close;
FreeAndNil(FX11Display);
For I := Low(FModes) To High(FModes) Do
FreeAndNil(FModes[I]);
Inherited Destroy;
End;
Procedure TX11Console.Configure(Const AFileName : String);
Var
F : Text;
S : String;
Begin
AssignFile(F, AFileName);
{$I-}
Reset(F);
{$I+}
If IOResult <> 0 Then
Exit;
While Not EoF(F) Do
Begin
{$I-}
Readln(F, S);
{$I+}
If IOResult <> 0 Then
Break;
Option(S);
End;
CloseFile(F);
End;
Function TX11Console.Option(Const AOption : String) : Boolean;
Begin
Result := True;
If AOption = 'default output' Then
Begin
{ default is windowed for now }
FFlags := FFlags - [PTC_X11_FULLSCREEN];
Exit;
End;
If AOption = 'windowed output' Then
Begin
FFlags := FFlags - [PTC_X11_FULLSCREEN];
Exit;
End;
If AOption = 'fullscreen output' Then
Begin
FFlags := FFlags + [PTC_X11_FULLSCREEN];
Exit;
End;
If AOption = 'leave window open' Then
Begin
FFlags := FFlags + [PTC_X11_LEAVE_WINDOW];
Exit;
End;
If AOption = 'leave display open' Then
Begin
FFlags := FFlags + [PTC_X11_LEAVE_DISPLAY];
Exit;
End;
If AOption = 'dga' Then
Begin
FFlags := FFlags + [PTC_X11_TRY_DGA];
Exit;
End;
If AOption = 'dga off' Then
Begin
FFlags := FFlags - [PTC_X11_TRY_DGA];
Exit;
End;
If AOption = 'xf86vidmode' Then
Begin
FFlags := FFlags + [PTC_X11_TRY_XF86VIDMODE];
Exit;
End;
If AOption = 'xf86vidmode off' Then
Begin
FFlags := FFlags - [PTC_X11_TRY_XF86VIDMODE];
Exit;
End;
If AOption = 'xrandr' Then
Begin
FFlags := FFlags + [PTC_X11_TRY_XRANDR];
Exit;
End;
If AOption = 'xrandr off' Then
Begin
FFlags := FFlags - [PTC_X11_TRY_XRANDR];
Exit;
End;
If AOption = 'xshm' Then
Begin
FFlags := FFlags + [PTC_X11_TRY_XSHM];
Exit;
End;
If AOption = 'xshm off' Then
Begin
FFlags := FFlags - [PTC_X11_TRY_XSHM];
Exit;
End;
If AOption = 'default cursor' Then
Begin
FFlags := FFlags - [PTC_X11_FULLSCREEN_CURSOR_VISIBLE, PTC_X11_WINDOWED_CURSOR_INVISIBLE];
UpdateCursor;
Exit;
End;
If AOption = 'show cursor' Then
Begin
FFlags := (FFlags - [PTC_X11_WINDOWED_CURSOR_INVISIBLE]) + [PTC_X11_FULLSCREEN_CURSOR_VISIBLE];
UpdateCursor;
Exit;
End;
If AOption = 'hide cursor' Then
Begin
FFlags := (FFlags - [PTC_X11_FULLSCREEN_CURSOR_VISIBLE]) + [PTC_X11_WINDOWED_CURSOR_INVISIBLE];
UpdateCursor;
Exit;
End;
If AOption = 'enable logging' Then
Begin
LOG_enabled := True;
Result := True;
Exit;
End;
If AOption = 'disable logging' Then
Begin
LOG_enabled := False;
Result := True;
Exit;
End;
If Assigned(FX11Display) Then
Result := FX11Display.FCopy.Option(AOption)
Else
Result := False;
End;
Function TX11Console.Modes : PPTCMode;
Var
I : Integer;
Begin
For I := Low(FModes) To High(FModes) Do
FreeAndNil(FModes[I]);
If FX11Display = Nil Then
FX11Display := CreateDisplay;
FX11Display.GetModes(FModes);
Result := @FModes[0];
End;
{TODO: Find current pixel depth}
Procedure TX11Console.Open(Const ATitle : String; APages : Integer = 0);
Var
tmp : TPTCFormat;
Begin
tmp := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
Try
Open(ATitle, tmp, APages);
Finally
tmp.Free;
End;
End;
Procedure TX11Console.Open(Const ATitle : String; Const AFormat : TPTCFormat;
APages : Integer = 0);
Begin
Open(ATitle, 640, 480, AFormat, APages);
End;
Procedure TX11Console.Open(Const ATitle : String; Const AMode : TPTCMode;
APages : Integer = 0);
Begin
Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
End;
Function TX11Console.CreateDisplay : TX11Display;
Var
display : PDisplay;
screen : Integer;
Begin
{ Check if we can open an X display }
display := XOpenDisplay(Nil);
If display = Nil Then
Raise TPTCError.Create('Cannot open X display');
{ DefaultScreen should be fine }
screen := DefaultScreen(display);
{$IFDEF ENABLE_X11_EXTENSION_XF86DGA2}
If PTC_X11_TRY_DGA In FFlags Then
Begin
Try
Result := TX11DGA2Display.Create(display, screen, FFlags + [PTC_X11_LEAVE_DISPLAY]);
Result.SetFlags(FFlags);
Exit;
Except
LOG('DGA 2.0 failed');
End;
End;
{$ENDIF ENABLE_X11_EXTENSION_XF86DGA2}
{$IFDEF ENABLE_X11_EXTENSION_XF86DGA1}
If PTC_X11_TRY_DGA In FFlags Then
Begin
Try
Result := TX11DGA1Display.Create(display, screen, FFlags + [PTC_X11_LEAVE_DISPLAY]);
Result.SetFlags(FFlags);
Except
LOG('DGA 1.0 failed');
End;
End;
{$ENDIF ENABLE_X11_EXTENSION_XF86DGA1}
Result := TX11WindowDisplay.Create(display, screen, FFlags);
End;
Procedure TX11Console.Open(Const ATitle : String; AWidth, AHeight : Integer;
Const AFormat : TPTCFormat; APages : Integer = 0);
Begin
Close;
FTitle := ATitle;
If FX11Display = Nil Then
FX11Display := CreateDisplay;
FX11Display.Open(ATitle, AWidth, AHeight, AFormat);
UpdateCursor;
End;
Procedure TX11Console.Close;
Begin
FreeAndNil(FX11Display);
End;
Procedure TX11Console.Flush;
Begin
Update;
End;
Procedure TX11Console.Finish;
Begin
Update;
End;
Procedure TX11Console.Update;
Begin
FX11Display.Update;
End;
Procedure TX11Console.Update(Const AArea : TPTCArea);
Begin
FX11Display.Update(AArea);
End;
Function TX11Console.NextEvent(Var AEvent : TPTCEvent; AWait : Boolean; Const AEventMask : TPTCEventMask) : Boolean;
Begin
Result := FX11Display.NextEvent(AEvent, AWait, AEventMask);
End;
Function TX11Console.PeekEvent(AWait : Boolean; Const AEventMask : TPTCEventMask) : TPTCEvent;
Begin
Result := FX11Display.PeekEvent(AWait, AEventMask);
End;
Procedure TX11Console.Copy(Var ASurface : TPTCBaseSurface);
Begin
{todo!...}
End;
Procedure TX11Console.Copy(Var ASurface : TPTCBaseSurface;
Const ASource, ADestination : TPTCArea);
Begin
{todo!...}
End;
Function TX11Console.Lock : Pointer;
Begin
Result := FX11Display.Lock;
End;
Procedure TX11Console.Unlock;
Begin
FX11Display.Unlock;
End;
Procedure TX11Console.Load(Const APixels : Pointer;
AWidth, AHeight, APitch : Integer;
Const AFormat : TPTCFormat;
Const APalette : TPTCPalette);
Begin
FX11Display.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette);
End;
Procedure TX11Console.Load(Const APixels : Pointer;
AWidth, AHeight, APitch : Integer;
Const AFormat : TPTCFormat;
Const APalette : TPTCPalette;
Const ASource, ADestination : TPTCArea);
Begin
FX11Display.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination);
End;
Procedure TX11Console.Save(APixels : Pointer;
AWidth, AHeight, APitch : Integer;
Const AFormat : TPTCFormat;
Const APalette : TPTCPalette);
Begin
{todo!...}
End;
Procedure TX11Console.Save(APixels : Pointer;
AWidth, AHeight, APitch : Integer;
Const AFormat : TPTCFormat;
Const APalette : TPTCPalette;
Const ASource, ADestination : TPTCArea);
Begin
{todo!...}
End;
Procedure TX11Console.Clear;
Var
tmp : TPTCColor;
Begin
If Format.Direct Then
tmp := TPTCColor.Create(0, 0, 0, 0)
Else
tmp := TPTCColor.Create(0);
Try
Clear(tmp);
Finally
tmp.Free;
End;
End;
Procedure TX11Console.Clear(Const AColor : TPTCColor);
Begin
FX11Display.Clear(AColor);
End;
Procedure TX11Console.Clear(Const AColor : TPTCColor;
Const AArea : TPTCArea);
Begin
FX11Display.Clear(AColor, AArea);
End;
Procedure TX11Console.Palette(Const APalette : TPTCPalette);
Begin
FX11Display.Palette(APalette);
End;
Function TX11Console.Palette : TPTCPalette;
Begin
Result := FX11Display.Palette;
End;
Procedure TX11Console.Clip(Const AArea : TPTCArea);
Begin
FX11Display.Clip(AArea);
End;
Function TX11Console.GetWidth : Integer;
Begin
Result := FX11Display.Width;
End;
Function TX11Console.GetHeight : Integer;
Begin
Result := FX11Display.Height;
End;
Function TX11Console.GetPitch : Integer;
Begin
Result := FX11Display.Pitch;
End;
Function TX11Console.GetPages : Integer;
Begin
Result := 2;
End;
Function TX11Console.GetArea : TPTCArea;
Begin
Result := FX11Display.Area;
End;
Function TX11Console.Clip : TPTCArea;
Begin
Result := FX11Display.Clip;
End;
Function TX11Console.GetFormat : TPTCFormat;
Begin
Result := FX11Display.Format;
End;
Function TX11Console.GetName : String;
Begin
Result := 'X11';
End;
Function TX11Console.GetTitle : String;
Begin
Result := FTitle;
End;
Function TX11Console.GetInformation : String;
Begin
If FX11Display = Nil Then
Exit('PTC X11');
Result := 'PTC X11, ';
If FX11Display.IsFullScreen Then
Result := Result + 'fullscreen '
Else
Result := Result + 'windowed ';
{ TODO: use virtual methods, instead of "is" }
If FX11Display Is TX11WindowDisplay Then
Begin
If TX11WindowDisplay(FX11Display).FPrimary <> Nil Then
Result := Result + '(' + TX11WindowDisplay(FX11Display).FPrimary.Name + ') '
Else
Result := Result + '';
End
Else
Begin
{$IFDEF ENABLE_X11_EXTENSION_XF86DGA2}
If FX11Display Is TX11DGA2Display Then
Result := Result + '(DGA) '
Else
{$ENDIF ENABLE_X11_EXTENSION_XF86DGA2}
{$IFDEF ENABLE_X11_EXTENSION_XF86DGA1}
If FX11Display Is TX11DGA1Display Then
Result := Result + '(DGA) '
Else
{$ENDIF ENABLE_X11_EXTENSION_XF86DGA1}
Begin
{...}
End;
End;
Result := Result + 'mode, ' +
IntToStr(FX11Display.Width) + 'x' +
IntToStr(FX11Display.Height) + ', ' +
IntToStr(FX11Display.Format.Bits) + ' bit';
End;
Procedure TX11Console.UpdateCursor;
Begin
If Assigned(FX11Display) Then
Begin
If FX11Display.IsFullScreen Then
FX11Display.SetCursor(PTC_X11_FULLSCREEN_CURSOR_VISIBLE In FFlags)
Else
FX11Display.SetCursor(Not (PTC_X11_WINDOWED_CURSOR_INVISIBLE In FFlags));
End;
End;
|