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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
|
/*
* Copyright © 1999 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "kdrive.h"
#include <mivalidate.h>
#include <dixstruct.h>
#include "privates.h"
#ifdef RANDR
#include <randrstr.h>
#endif
#ifdef XV
#include "kxv.h"
#endif
#ifdef DPMSExtension
#include "dpmsproc.h"
#endif
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#if defined(CONFIG_UDEV) || defined(CONFIG_HAL)
#include <hotplug.h>
#endif
/* This stub can be safely removed once we can
* split input and GPU parts in hotplug.h et al. */
#include <systemd-logind.h>
typedef struct _kdDepths {
CARD8 depth;
CARD8 bpp;
} KdDepths;
KdDepths kdDepths[] = {
{1, 1},
{4, 4},
{8, 8},
{15, 16},
{16, 16},
{24, 32},
{32, 32}
};
#define NUM_KD_DEPTHS (sizeof (kdDepths) / sizeof (kdDepths[0]))
#define KD_DEFAULT_BUTTONS 5
DevPrivateKeyRec kdScreenPrivateKeyRec;
static unsigned long kdGeneration;
Bool kdEmulateMiddleButton;
Bool kdRawPointerCoordinates;
Bool kdDisableZaphod;
static Bool kdEnabled;
static int kdSubpixelOrder;
static char *kdSwitchCmd;
static DDXPointRec kdOrigin;
Bool kdHasPointer = FALSE;
Bool kdHasKbd = FALSE;
const char *kdGlobalXkbRules = NULL;
const char *kdGlobalXkbModel = NULL;
const char *kdGlobalXkbLayout = NULL;
const char *kdGlobalXkbVariant = NULL;
const char *kdGlobalXkbOptions = NULL;
static Bool kdCaughtSignal = FALSE;
void
KdDisableScreen(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
if (!pScreenPriv->enabled)
return;
if (!pScreenPriv->closed)
SetRootClip(pScreen, ROOT_CLIP_NONE);
KdDisableColormap(pScreen);
if (!pScreenPriv->screen->dumb && pScreenPriv->card->cfuncs->disableAccel)
(*pScreenPriv->card->cfuncs->disableAccel) (pScreen);
pScreenPriv->enabled = FALSE;
}
static void
KdDoSwitchCmd(const char *reason)
{
if (kdSwitchCmd) {
char *command;
int ret;
if (asprintf(&command, "%s %s", kdSwitchCmd, reason) == -1)
return;
/* Ignore the return value from system; I'm not sure
* there's anything more useful to be done when
* it fails
*/
ret = system(command);
(void) ret;
free(command);
}
}
static void
KdSuspend(void)
{
KdCardInfo *card;
KdScreenInfo *screen;
if (kdEnabled) {
for (card = kdCardInfo; card; card = card->next) {
for (screen = card->screenList; screen; screen = screen->next)
if (screen->mynum == card->selected && screen->pScreen)
KdDisableScreen(screen->pScreen);
}
KdDisableInput();
KdDoSwitchCmd("suspend");
}
}
static void
KdDisableScreens(void)
{
KdSuspend();
kdEnabled = FALSE;
}
Bool
KdEnableScreen(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
if (pScreenPriv->enabled)
return TRUE;
pScreenPriv->enabled = TRUE;
pScreenPriv->dpmsState = KD_DPMS_NORMAL;
pScreenPriv->card->selected = pScreenPriv->screen->mynum;
if (!pScreenPriv->screen->dumb && pScreenPriv->card->cfuncs->enableAccel)
(*pScreenPriv->card->cfuncs->enableAccel) (pScreen);
KdEnableColormap(pScreen);
SetRootClip(pScreen, ROOT_CLIP_FULL);
return TRUE;
}
void
AbortDDX(enum ExitCode error)
{
KdDisableScreens();
if (kdCaughtSignal)
OsAbort();
}
void
ddxGiveUp(enum ExitCode error)
{
AbortDDX(error);
}
static Bool kdDumbDriver;
static Bool kdSoftCursor;
const char *
KdParseFindNext(const char *cur, const char *delim, char *save, char *last)
{
while (*cur && !strchr(delim, *cur)) {
*save++ = *cur++;
}
*save = 0;
*last = *cur;
if (*cur)
cur++;
return cur;
}
Rotation
KdAddRotation(Rotation a, Rotation b)
{
Rotation rotate = (a & RR_Rotate_All) * (b & RR_Rotate_All);
Rotation reflect = (a & RR_Reflect_All) ^ (b & RR_Reflect_All);
if (rotate > RR_Rotate_270)
rotate /= (RR_Rotate_270 * RR_Rotate_90);
return reflect | rotate;
}
Rotation
KdSubRotation(Rotation a, Rotation b)
{
Rotation rotate = (a & RR_Rotate_All) * 16 / (b & RR_Rotate_All);
Rotation reflect = (a & RR_Reflect_All) ^ (b & RR_Reflect_All);
if (rotate > RR_Rotate_270)
rotate /= (RR_Rotate_270 * RR_Rotate_90);
return reflect | rotate;
}
void
KdParseScreen(KdScreenInfo * screen, const char *arg)
{
char delim;
char save[1024];
int i;
int pixels, mm;
screen->dumb = kdDumbDriver;
screen->softCursor = kdSoftCursor;
screen->origin = kdOrigin;
screen->randr = RR_Rotate_0;
screen->x = 0;
screen->y = 0;
screen->width = 0;
screen->height = 0;
screen->width_mm = 0;
screen->height_mm = 0;
screen->subpixel_order = kdSubpixelOrder;
screen->rate = 0;
screen->fb.depth = 0;
if (!arg)
return;
if (strlen(arg) >= sizeof(save))
return;
for (i = 0; i < 2; i++) {
arg = KdParseFindNext(arg, "x/+@XY", save, &delim);
if (!save[0])
return;
pixels = atoi(save);
mm = 0;
if (delim == '/') {
arg = KdParseFindNext(arg, "x+@XY", save, &delim);
if (!save[0])
return;
mm = atoi(save);
}
if (i == 0) {
screen->width = pixels;
screen->width_mm = mm;
}
else {
screen->height = pixels;
screen->height_mm = mm;
}
if (delim != 'x' && delim != '+' && delim != '@' &&
delim != 'X' && delim != 'Y' &&
(delim != '\0' || i == 0))
return;
}
kdOrigin.x += screen->width;
kdOrigin.y = 0;
kdDumbDriver = FALSE;
kdSoftCursor = FALSE;
kdSubpixelOrder = SubPixelUnknown;
if (delim == '+') {
arg = KdParseFindNext(arg, "+@xXY", save, &delim);
if (save[0])
screen->x = atoi(save);
}
if (delim == '+') {
arg = KdParseFindNext(arg, "@xXY", save, &delim);
if (save[0])
screen->y = atoi(save);
}
if (delim == '@') {
arg = KdParseFindNext(arg, "xXY", save, &delim);
if (save[0]) {
int rotate = atoi(save);
if (rotate < 45)
screen->randr = RR_Rotate_0;
else if (rotate < 135)
screen->randr = RR_Rotate_90;
else if (rotate < 225)
screen->randr = RR_Rotate_180;
else if (rotate < 315)
screen->randr = RR_Rotate_270;
else
screen->randr = RR_Rotate_0;
}
}
if (delim == 'X') {
arg = KdParseFindNext(arg, "xY", save, &delim);
screen->randr |= RR_Reflect_X;
}
if (delim == 'Y') {
arg = KdParseFindNext(arg, "xY", save, &delim);
screen->randr |= RR_Reflect_Y;
}
arg = KdParseFindNext(arg, "x/,", save, &delim);
if (save[0]) {
screen->fb.depth = atoi(save);
if (delim == '/') {
arg = KdParseFindNext(arg, "x,", save, &delim);
if (save[0])
screen->fb.bitsPerPixel = atoi(save);
}
else
screen->fb.bitsPerPixel = 0;
}
if (delim == 'x') {
arg = KdParseFindNext(arg, "x", save, &delim);
if (save[0])
screen->rate = atoi(save);
}
}
static void
KdParseRgba(char *rgba)
{
if (!strcmp(rgba, "rgb"))
kdSubpixelOrder = SubPixelHorizontalRGB;
else if (!strcmp(rgba, "bgr"))
kdSubpixelOrder = SubPixelHorizontalBGR;
else if (!strcmp(rgba, "vrgb"))
kdSubpixelOrder = SubPixelVerticalRGB;
else if (!strcmp(rgba, "vbgr"))
kdSubpixelOrder = SubPixelVerticalBGR;
else if (!strcmp(rgba, "none"))
kdSubpixelOrder = SubPixelNone;
else
kdSubpixelOrder = SubPixelUnknown;
}
void
KdUseMsg(void)
{
ErrorF("\nTinyX Device Dependent Usage:\n");
ErrorF
("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM][+[-]XOFFSET][+[-]YOFFSET][@ROTATION][X][Y][xDEPTH/BPP[xFREQ]] Specify screen characteristics\n");
ErrorF
("-rgba rgb/bgr/vrgb/vbgr/none Specify subpixel ordering for LCD panels\n");
ErrorF
("-mouse driver [,n,,options] Specify the pointer driver and its options (n is the number of buttons)\n");
ErrorF
("-keybd driver [,,options] Specify the keyboard driver and its options\n");
ErrorF("-xkb-rules Set default XkbRules value (can be overriden by -keybd options)\n");
ErrorF("-xkb-model Set default XkbModel value (can be overriden by -keybd options)\n");
ErrorF("-xkb-layout Set default XkbLayout value (can be overriden by -keybd options)\n");
ErrorF("-xkb-variant Set default XkbVariant value (can be overriden by -keybd options)\n");
ErrorF("-xkb-options Set default XkbOptions value (can be overriden by -keybd options)\n");
ErrorF("-zaphod Disable cursor screen switching\n");
ErrorF("-2button Emulate 3 button mouse\n");
ErrorF("-3button Disable 3 button mouse emulation\n");
ErrorF
("-rawcoord Don't transform pointer coordinates on rotation\n");
ErrorF("-dumb Disable hardware acceleration\n");
ErrorF("-softCursor Force software cursor\n");
ErrorF("-videoTest Start the server, pause momentarily and exit\n");
ErrorF
("-origin X,Y Locates the next screen in the the virtual screen (Xinerama)\n");
ErrorF("-switchCmd Command to execute on vt switch\n");
ErrorF
("vtxx Use virtual terminal xx instead of the next available\n");
}
int
KdProcessArgument(int argc, char **argv, int i)
{
KdCardInfo *card;
KdScreenInfo *screen;
if (!strcmp(argv[i], "-screen")) {
if ((i + 1) < argc) {
card = KdCardInfoLast();
if (!card) {
InitCard(0);
card = KdCardInfoLast();
}
if (card) {
screen = KdScreenInfoAdd(card);
KdParseScreen(screen, argv[i + 1]);
}
else
ErrorF("No matching card found!\n");
}
else
UseMsg();
return 2;
}
if (!strcmp(argv[i], "-zaphod")) {
kdDisableZaphod = TRUE;
return 1;
}
if (!strcmp(argv[i], "-3button")) {
kdEmulateMiddleButton = FALSE;
return 1;
}
if (!strcmp(argv[i], "-2button")) {
kdEmulateMiddleButton = TRUE;
return 1;
}
if (!strcmp(argv[i], "-rawcoord")) {
kdRawPointerCoordinates = 1;
return 1;
}
if (!strcmp(argv[i], "-dumb")) {
kdDumbDriver = TRUE;
return 1;
}
if (!strcmp(argv[i], "-softCursor")) {
kdSoftCursor = TRUE;
return 1;
}
if (!strcmp(argv[i], "-origin")) {
if ((i + 1) < argc) {
char *x = argv[i + 1];
char *y = strchr(x, ',');
if (x)
kdOrigin.x = atoi(x);
else
kdOrigin.x = 0;
if (y)
kdOrigin.y = atoi(y + 1);
else
kdOrigin.y = 0;
}
else
UseMsg();
return 2;
}
if (!strcmp(argv[i], "-rgba")) {
if ((i + 1) < argc)
KdParseRgba(argv[i + 1]);
else
UseMsg();
return 2;
}
if (!strcmp(argv[i], "-switchCmd")) {
if ((i + 1) < argc)
kdSwitchCmd = argv[i + 1];
else
UseMsg();
return 2;
}
if (!strcmp(argv[i], "-xkb-rules")) {
if (i + 1 >= argc) {
UseMsg();
FatalError("Missing argument for option -xkb-rules.\n");
}
kdGlobalXkbRules = argv[i + 1];
return 2;
}
if (!strcmp(argv[i], "-xkb-model")) {
if (i + 1 >= argc) {
UseMsg();
FatalError("Missing argument for option -xkb-model.\n");
}
kdGlobalXkbModel = argv[i + 1];
return 2;
}
if (!strcmp(argv[i], "-xkb-layout")) {
if (i + 1 >= argc) {
UseMsg();
FatalError("Missing argument for option -xkb-layout.\n");
}
kdGlobalXkbLayout = argv[i + 1];
return 2;
}
if (!strcmp(argv[i], "-xkb-variant")) {
if (i + 1 >= argc) {
UseMsg();
FatalError("Missing argument for option -xkb-variant.\n");
}
kdGlobalXkbVariant = argv[i + 1];
return 2;
}
if (!strcmp(argv[i], "-xkb-options")) {
if (i + 1 >= argc) {
UseMsg();
FatalError("Missing argument for option -xkb-options.\n");
}
kdGlobalXkbOptions = argv[i + 1];
return 2;
}
if (!strcmp(argv[i], "-mouse") || !strcmp(argv[i], "-pointer")) {
if (i + 1 >= argc)
UseMsg();
KdAddConfigPointer(argv[i + 1]);
kdHasPointer = TRUE;
return 2;
}
if (!strcmp(argv[i], "-keybd")) {
if (i + 1 >= argc)
UseMsg();
KdAddConfigKeyboard(argv[i + 1]);
kdHasKbd = TRUE;
return 2;
}
return 0;
}
static Bool
KdAllocatePrivates(ScreenPtr pScreen)
{
KdPrivScreenPtr pScreenPriv;
if (kdGeneration != serverGeneration)
kdGeneration = serverGeneration;
if (!dixRegisterPrivateKey(&kdScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
return FALSE;
pScreenPriv = calloc(1, sizeof(*pScreenPriv));
if (!pScreenPriv)
return FALSE;
KdSetScreenPriv(pScreen, pScreenPriv);
return TRUE;
}
static Bool
KdCreateScreenResources(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
KdCardInfo *card = pScreenPriv->card;
Bool ret;
pScreen->CreateScreenResources = pScreenPriv->CreateScreenResources;
if (pScreen->CreateScreenResources)
ret = (*pScreen->CreateScreenResources) (pScreen);
else
ret = -1;
pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources;
pScreen->CreateScreenResources = KdCreateScreenResources;
if (ret && card->cfuncs->createRes)
ret = (*card->cfuncs->createRes) (pScreen);
return ret;
}
static Bool
KdCloseScreen(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
KdCardInfo *card = pScreenPriv->card;
Bool ret;
if (card->cfuncs->closeScreen)
(*card->cfuncs->closeScreen)(pScreen);
pScreenPriv->closed = TRUE;
pScreen->CloseScreen = pScreenPriv->CloseScreen;
if (pScreen->CloseScreen)
ret = (*pScreen->CloseScreen) (pScreen);
else
ret = TRUE;
if (screen->mynum == card->selected)
KdDisableScreen(pScreen);
if (!pScreenPriv->screen->dumb && card->cfuncs->finiAccel)
(*card->cfuncs->finiAccel) (pScreen);
if (card->cfuncs->scrfini)
(*card->cfuncs->scrfini) (screen);
/*
* Clean up card when last screen is closed, DIX closes them in
* reverse order, thus we check for when the first in the list is closed
*/
if (screen == card->screenList) {
if (card->cfuncs->cardfini)
(*card->cfuncs->cardfini) (card);
/*
* Clean up OS when last card is closed
*/
if (card == kdCardInfo) {
kdEnabled = FALSE;
}
}
pScreenPriv->screen->pScreen = 0;
free((void *) pScreenPriv);
return ret;
}
static Bool
KdSaveScreen(ScreenPtr pScreen, int on)
{
return FALSE;
}
static Bool
KdCreateWindow(WindowPtr pWin)
{
#ifndef PHOENIX
if (!pWin->parent) {
KdScreenPriv(pWin->drawable.pScreen);
if (!pScreenPriv->enabled) {
RegionEmpty(&pWin->borderClip);
RegionBreak(&pWin->clipList);
}
}
#endif
return fbCreateWindow(pWin);
}
void
KdSetSubpixelOrder(ScreenPtr pScreen, Rotation randr)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
int subpixel_order = screen->subpixel_order;
Rotation subpixel_dir;
int i;
static struct {
int subpixel_order;
Rotation direction;
} orders[] = {
{SubPixelHorizontalRGB, RR_Rotate_0},
{SubPixelHorizontalBGR, RR_Rotate_180},
{SubPixelVerticalRGB, RR_Rotate_270},
{SubPixelVerticalBGR, RR_Rotate_90},
};
static struct {
int bit;
int normal;
int reflect;
} reflects[] = {
{RR_Reflect_X, SubPixelHorizontalRGB, SubPixelHorizontalBGR},
{RR_Reflect_X, SubPixelHorizontalBGR, SubPixelHorizontalRGB},
{RR_Reflect_Y, SubPixelVerticalRGB, SubPixelVerticalBGR},
{RR_Reflect_Y, SubPixelVerticalRGB, SubPixelVerticalRGB},
};
/* map subpixel to direction */
for (i = 0; i < 4; i++)
if (orders[i].subpixel_order == subpixel_order)
break;
if (i < 4) {
subpixel_dir =
KdAddRotation(randr & RR_Rotate_All, orders[i].direction);
/* map back to subpixel order */
for (i = 0; i < 4; i++)
if (orders[i].direction & subpixel_dir) {
subpixel_order = orders[i].subpixel_order;
break;
}
/* reflect */
for (i = 0; i < 4; i++)
if ((randr & reflects[i].bit) &&
reflects[i].normal == subpixel_order) {
subpixel_order = reflects[i].reflect;
break;
}
}
PictureSetSubpixelOrder(pScreen, subpixel_order);
}
/* Pass through AddScreen, which doesn't take any closure */
static KdScreenInfo *kdCurrentScreen;
static Bool
KdScreenInit(ScreenPtr pScreen, int argc, char **argv)
{
KdScreenInfo *screen = kdCurrentScreen;
KdCardInfo *card = screen->card;
KdPrivScreenPtr pScreenPriv;
/*
* note that screen->fb is set up for the nominal orientation
* of the screen; that means if randr is rotated, the values
* there should reflect a rotated frame buffer (or shadow).
*/
Bool rotated = (screen->randr & (RR_Rotate_90 | RR_Rotate_270)) != 0;
int width, height, *width_mmp, *height_mmp;
KdAllocatePrivates(pScreen);
pScreenPriv = KdGetScreenPriv(pScreen);
if (!rotated) {
width = screen->width;
height = screen->height;
width_mmp = &screen->width_mm;
height_mmp = &screen->height_mm;
}
else {
width = screen->height;
height = screen->width;
width_mmp = &screen->height_mm;
height_mmp = &screen->width_mm;
}
screen->pScreen = pScreen;
pScreenPriv->screen = screen;
pScreenPriv->card = card;
pScreenPriv->bytesPerPixel = screen->fb.bitsPerPixel >> 3;
pScreenPriv->dpmsState = KD_DPMS_NORMAL;
pScreen->x = screen->origin.x;
pScreen->y = screen->origin.y;
if (!monitorResolution)
monitorResolution = 75;
/*
* This is done in this order so that backing store wraps
* our GC functions; fbFinishScreenInit initializes MI
* backing store
*/
if (!fbSetupScreen(pScreen,
screen->fb.frameBuffer,
width, height,
monitorResolution, monitorResolution,
screen->fb.pixelStride, screen->fb.bitsPerPixel)) {
return FALSE;
}
/*
* Set colormap functions
*/
pScreen->InstallColormap = KdInstallColormap;
pScreen->UninstallColormap = KdUninstallColormap;
pScreen->ListInstalledColormaps = KdListInstalledColormaps;
pScreen->StoreColors = KdStoreColors;
pScreen->SaveScreen = KdSaveScreen;
pScreen->CreateWindow = KdCreateWindow;
if (!fbFinishScreenInit(pScreen,
screen->fb.frameBuffer,
width, height,
monitorResolution, monitorResolution,
screen->fb.pixelStride, screen->fb.bitsPerPixel)) {
return FALSE;
}
/*
* Fix screen sizes; for some reason mi takes dpi instead of mm.
* Rounding errors are annoying
*/
if (*width_mmp)
pScreen->mmWidth = *width_mmp;
else
*width_mmp = pScreen->mmWidth;
if (*height_mmp)
pScreen->mmHeight = *height_mmp;
else
*height_mmp = pScreen->mmHeight;
/*
* Plug in our own block/wakeup handlers.
* miScreenInit installs NoopDDA in both places
*/
pScreen->BlockHandler = KdBlockHandler;
pScreen->WakeupHandler = KdWakeupHandler;
if (!fbPictureInit(pScreen, 0, 0))
return FALSE;
if (card->cfuncs->initScreen)
if (!(*card->cfuncs->initScreen) (pScreen))
return FALSE;
if (!screen->dumb && card->cfuncs->initAccel)
if (!(*card->cfuncs->initAccel) (pScreen))
screen->dumb = TRUE;
if (card->cfuncs->finishInitScreen)
if (!(*card->cfuncs->finishInitScreen) (pScreen))
return FALSE;
/*
* Wrap CloseScreen, the order now is:
* KdCloseScreen
* fbCloseScreen
*/
pScreenPriv->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = KdCloseScreen;
pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources;
pScreen->CreateScreenResources = KdCreateScreenResources;
if (screen->softCursor ||
!card->cfuncs->initCursor || !(*card->cfuncs->initCursor) (pScreen)) {
/* Use MI for cursor display and event queueing. */
screen->softCursor = TRUE;
miDCInitialize(pScreen, &kdPointerScreenFuncs);
}
if (!fbCreateDefColormap(pScreen)) {
return FALSE;
}
KdSetSubpixelOrder(pScreen, screen->randr);
/*
* Enable the hardware
*/
kdEnabled = TRUE;
if (screen->mynum == card->selected) {
pScreenPriv->enabled = TRUE;
KdEnableColormap(pScreen);
if (!screen->dumb && card->cfuncs->enableAccel)
(*card->cfuncs->enableAccel) (pScreen);
}
return TRUE;
}
static void
KdInitScreen(ScreenInfo * pScreenInfo,
KdScreenInfo * screen, int argc, char **argv)
{
KdCardInfo *card = screen->card;
if (!(*card->cfuncs->scrinit) (screen))
FatalError("Screen initialization failed!\n");
if (!card->cfuncs->initAccel)
screen->dumb = TRUE;
if (!card->cfuncs->initCursor)
screen->softCursor = TRUE;
}
static Bool
KdSetPixmapFormats(ScreenInfo * pScreenInfo)
{
CARD8 depthToBpp[33]; /* depth -> bpp map */
KdCardInfo *card;
KdScreenInfo *screen;
int i;
int bpp;
PixmapFormatRec *format;
for (i = 1; i <= 32; i++)
depthToBpp[i] = 0;
/*
* Generate mappings between bitsPerPixel and depth,
* also ensure that all screens comply with protocol
* restrictions on equivalent formats for the same
* depth on different screens
*/
for (card = kdCardInfo; card; card = card->next) {
for (screen = card->screenList; screen; screen = screen->next) {
bpp = screen->fb.bitsPerPixel;
if (bpp == 24)
bpp = 32;
if (!depthToBpp[screen->fb.depth])
depthToBpp[screen->fb.depth] = bpp;
else if (depthToBpp[screen->fb.depth] != bpp)
return FALSE;
}
}
/*
* Fill in additional formats
*/
for (i = 0; i < NUM_KD_DEPTHS; i++)
if (!depthToBpp[kdDepths[i].depth])
depthToBpp[kdDepths[i].depth] = kdDepths[i].bpp;
pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
pScreenInfo->numPixmapFormats = 0;
for (i = 1; i <= 32; i++) {
if (depthToBpp[i]) {
format = &pScreenInfo->formats[pScreenInfo->numPixmapFormats++];
format->depth = i;
format->bitsPerPixel = depthToBpp[i];
format->scanlinePad = BITMAP_SCANLINE_PAD;
}
}
return TRUE;
}
static void
KdAddScreen(ScreenInfo * pScreenInfo,
KdScreenInfo * screen, int argc, char **argv)
{
int i;
/*
* Fill in fb visual type masks for this screen
*/
for (i = 0; i < pScreenInfo->numPixmapFormats; i++) {
unsigned long visuals;
Pixel rm, gm, bm;
visuals = 0;
rm = gm = bm = 0;
if (pScreenInfo->formats[i].depth == screen->fb.depth) {
visuals = screen->fb.visuals;
rm = screen->fb.redMask;
gm = screen->fb.greenMask;
bm = screen->fb.blueMask;
}
fbSetVisualTypesAndMasks(pScreenInfo->formats[i].depth,
visuals, 8, rm, gm, bm);
}
kdCurrentScreen = screen;
AddScreen(KdScreenInit, argc, argv);
}
static int
KdSignalWrapper(int signum)
{
kdCaughtSignal = TRUE;
return 1; /* use generic OS layer cleanup & abort */
}
void
KdInitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
{
KdCardInfo *card;
KdScreenInfo *screen;
if (!kdCardInfo) {
InitCard(0);
if (!(card = KdCardInfoLast()))
FatalError("No matching cards found!\n");
screen = KdScreenInfoAdd(card);
KdParseScreen(screen, 0);
}
/*
* Initialize all of the screens for all of the cards
*/
for (card = kdCardInfo; card; card = card->next) {
int ret = 1;
if (card->cfuncs->cardinit)
ret = (*card->cfuncs->cardinit) (card);
if (ret) {
for (screen = card->screenList; screen; screen = screen->next)
KdInitScreen(pScreenInfo, screen, argc, argv);
}
}
/*
* Merge the various pixmap formats together, this can fail
* when two screens share depth but not bitsPerPixel
*/
if (!KdSetPixmapFormats(pScreenInfo))
return;
/*
* Add all of the screens
*/
for (card = kdCardInfo; card; card = card->next)
for (screen = card->screenList; screen; screen = screen->next)
KdAddScreen(pScreenInfo, screen, argc, argv);
OsRegisterSigWrapper(KdSignalWrapper);
#if defined(CONFIG_UDEV) || defined(CONFIG_HAL)
if (SeatId) /* Enable input hot-plugging */
config_pre_init();
#endif
}
void
OsVendorFatalError(const char *f, va_list args)
{
}
/* These stubs can be safely removed once we can
* split input and GPU parts in hotplug.h et al. */
#ifdef CONFIG_UDEV_KMS
void
NewGPUDeviceRequest(struct OdevAttributes *attribs)
{
}
void
DeleteGPUDeviceRequest(struct OdevAttributes *attribs)
{
}
#endif
struct xf86_platform_device *
xf86_find_platform_device_by_devnum(int major, int minor)
{
return NULL;
}
#ifdef SYSTEMD_LOGIND
void
systemd_logind_vtenter(void)
{
}
void
systemd_logind_release_fd(int major, int minor, int fd)
{
close(fd);
}
#endif
|