1 | | #ifdef HAVE_CONFIG_H |
2 | | #include "config.h" |
3 | | #endif |
4 | | |
5 | | #include "xf86.h" |
6 | | #include "xf86_OSproc.h" |
7 | | #include "dgaproc.h" |
8 | | #include "dummy.h" |
9 | | |
10 | | static Bool DUMMY_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **, |
11 | | int *, int *, int *); |
12 | | static Bool DUMMY_SetMode(ScrnInfoPtr, DGAModePtr); |
13 | | static int DUMMY_GetViewport(ScrnInfoPtr); |
14 | | static void DUMMY_SetViewport(ScrnInfoPtr, int, int, int); |
15 | | |
16 | | static |
17 | | DGAFunctionRec DUMMYDGAFuncs = { |
18 | | DUMMY_OpenFramebuffer, |
19 | | NULL, |
20 | | DUMMY_SetMode, |
21 | | DUMMY_SetViewport, |
22 | | DUMMY_GetViewport, |
23 | | NULL, |
24 | | NULL, |
25 | | NULL, |
26 | | #if 0 |
27 | | DUMMY_BlitTransRect |
28 | | #else |
29 | | NULL |
30 | | #endif |
31 | | }; |
32 | | |
33 | | Bool |
34 | | DUMMYDGAInit(ScreenPtr pScreen) |
35 | | { |
36 | | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
37 | | DUMMYPtr pDUMMY = DUMMYPTR(pScrn); |
38 | | DGAModePtr modes = NULL, newmodes = NULL, currentMode; |
39 | | DisplayModePtr pMode, firstMode; |
40 | | int Bpp = pScrn->bitsPerPixel >> 3; |
41 | | int num = 0, imlines, pixlines; |
42 | | |
43 | | imlines = (pScrn->videoRam * 1024) / |
44 | | (pScrn->displayWidth * (pScrn->bitsPerPixel >> 3)); |
45 | | |
46 | | pixlines = imlines; |
47 | | |
48 | | pMode = firstMode = pScrn->modes; |
49 | | |
50 | | while(pMode) { |
51 | | |
52 | | newmodes = realloc(modes, (num + 1) * sizeof(DGAModeRec)); |
53 | | |
54 | | if(!newmodes) { |
55 | | free(modes); |
56 | | return FALSE; |
57 | | } |
58 | | modes = newmodes; |
59 | | |
60 | | currentMode = modes + num; |
61 | | num++; |
62 | | |
63 | | currentMode->mode = pMode; |
64 | | currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE; |
65 | | if(pMode->Flags & V_DBLSCAN) |
66 | | currentMode->flags |= DGA_DOUBLESCAN; |
67 | | if(pMode->Flags & V_INTERLACE) |
68 | | currentMode->flags |= DGA_INTERLACED; |
69 | | currentMode->byteOrder = pScrn->imageByteOrder; |
70 | | currentMode->depth = pScrn->depth; |
71 | | currentMode->bitsPerPixel = pScrn->bitsPerPixel; |
72 | | currentMode->red_mask = pScrn->mask.red; |
73 | | currentMode->green_mask = pScrn->mask.green; |
74 | | currentMode->blue_mask = pScrn->mask.blue; |
75 | | currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor; |
76 | | currentMode->viewportWidth = pMode->HDisplay; |
77 | | currentMode->viewportHeight = pMode->VDisplay; |
78 | | currentMode->xViewportStep = 1; |
79 | | currentMode->yViewportStep = 1; |
80 | | currentMode->viewportFlags = DGA_FLIP_RETRACE; |
81 | | currentMode->offset = 0; |
82 | | currentMode->address = (unsigned char *)pDUMMY->FBBase; |
83 | | |
84 | | currentMode->bytesPerScanline = |
85 | | ((pScrn->displayWidth * Bpp) + 3) & ~3L; |
86 | | currentMode->imageWidth = pScrn->displayWidth; |
87 | | currentMode->imageHeight = imlines; |
88 | | currentMode->pixmapWidth = currentMode->imageWidth; |
89 | | currentMode->pixmapHeight = pixlines; |
90 | | currentMode->maxViewportX = currentMode->imageWidth - |
91 | | currentMode->viewportWidth; |
92 | | currentMode->maxViewportY = currentMode->imageHeight - |
93 | | currentMode->viewportHeight; |
94 | | |
95 | | pMode = pMode->next; |
96 | | if(pMode == firstMode) |
97 | | break; |
98 | | } |
99 | | |
100 | | pDUMMY->numDGAModes = num; |
101 | | pDUMMY->DGAModes = modes; |
102 | | |
103 | | return DGAInit(pScreen, &DUMMYDGAFuncs, modes, num); |
104 | | } |
105 | | |
106 | | static DisplayModePtr DUMMYSavedDGAModes[MAXSCREENS]; |
107 | | |
108 | | static Bool |
109 | | DUMMY_SetMode( |
110 | | ScrnInfoPtr pScrn, |
111 | | DGAModePtr pMode |
112 | | ){ |
113 | | int index = pScrn->pScreen->myNum; |
114 | | DUMMYPtr pDUMMY = DUMMYPTR(pScrn); |
115 | | |
116 | | if(!pMode) { /* restore the original mode */ |
117 | | if(pDUMMY->DGAactive) { |
118 | | pScrn->currentMode = DUMMYSavedDGAModes[index]; |
119 | | DUMMYSwitchMode(SWITCH_MODE_ARGS(pScrn, pScrn->currentMode)); |
120 | | DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, 0, 0)); |
121 | | pDUMMY->DGAactive = FALSE; |
122 | | } |
123 | | } else { |
124 | | if(!pDUMMY->DGAactive) { /* save the old parameters */ |
125 | | DUMMYSavedDGAModes[index] = pScrn->currentMode; |
126 | | pDUMMY->DGAactive = TRUE; |
127 | | } |
128 | | |
129 | | DUMMYSwitchMode(SWITCH_MODE_ARGS(pScrn, pMode->mode)); |
130 | | } |
131 | | |
132 | | return TRUE; |
133 | | } |
134 | | |
135 | | static int |
136 | | DUMMY_GetViewport( |
137 | | ScrnInfoPtr pScrn |
138 | | ){ |
139 | | DUMMYPtr pDUMMY = DUMMYPTR(pScrn); |
140 | | |
141 | | return pDUMMY->DGAViewportStatus; |
142 | | } |
143 | | |
144 | | static void |
145 | | DUMMY_SetViewport( |
146 | | ScrnInfoPtr pScrn, |
147 | | int x, int y, |
148 | | int flags |
149 | | ){ |
150 | | DUMMYPtr pDUMMY = DUMMYPTR(pScrn); |
151 | | |
152 | | DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, x, y)); |
153 | | pDUMMY->DGAViewportStatus = 0; |
154 | | } |
155 | | |
156 | | |
157 | | static Bool |
158 | | DUMMY_OpenFramebuffer( |
159 | | ScrnInfoPtr pScrn, |
160 | | char **name, |
161 | | unsigned char **mem, |
162 | | int *size, |
163 | | int *offset, |
164 | | int *flags |
165 | | ){ |
166 | | DUMMYPtr pDUMMY = DUMMYPTR(pScrn); |
167 | | |
168 | | *name = NULL; /* no special device */ |
169 | | *mem = (unsigned char*)pDUMMY->FBBase; |
170 | | *size = pScrn->videoRam * 1024; |
171 | | *offset = 0; |
172 | | *flags = DGA_NEED_ROOT; |
173 | | |
174 | | return TRUE; |
175 | | } |