summaryrefslogtreecommitdiff
path: root/drv/imped_scrn.c
blob: 8c2e1d94926e0b0f5da4ea1f86685ba2cf73478c (plain)
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
/* impedance layer screen functions - replaces
 *
 * fb/mi as the bottom layer of wrapping for protocol level screens
 */

#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif

#include <stdlib.h>

#include "windowstr.h"
#include "servermd.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include "imped.h"
#include "mi.h"
#include "micmap.h"

static DevPrivateKeyRec impedWinPrivateKeyRec;
static DevPrivateKey
impedGetWinPrivateKey (void)
{
    return &impedWinPrivateKeyRec;
}

#define impedGetWindowPixmap(pWin) ((PixmapPtr)                         \
                                    dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, impedGetWinPrivateKey()))

static Bool
impedAllocatePrivates(ScreenPtr pScreen)
{
    if (!dixRegisterPrivateKey(&impedWinPrivateKeyRec, PRIVATE_WINDOW, 0))
        return FALSE;

    return TRUE;
}

static Bool
impedCreateScreenResources(ScreenPtr pScreen)
{
    ScreenPtr iter;
    Bool ret = TRUE;
    int i;
    PixmapPtr pPixmap;
    xorg_list_init(&pScreen->gc_list);
    xorg_list_init(&pScreen->pixmap_list);
    xorg_list_init(&pScreen->picture_list);

    ret = miCreateScreenResources(pScreen);
    if (!ret)
	return ret;


    /* have to fixup the screen pixmap linkages */
    pPixmap = pScreen->GetScreenPixmap(pScreen);
    i = 0;
    xorg_list_for_each_entry(iter, &pScreen->gpu_screen_list, gpu_screen_head) {
	iter->SetScreenPixmap(pPixmap->gpu[i]);
	i++;
    }

    xorg_list_for_each_entry(iter, &pScreen->gpu_screen_list, gpu_screen_head) {
	ret = iter->CreateScreenResources(iter);
    }


    return ret;
}

static Bool
impedCreateWindow(WindowPtr pWin)
{
    dixSetPrivate(&pWin->devPrivates, impedGetWinPrivateKey(),
                  impedGetScreenPixmap(pWin->drawable.pScreen));
    return TRUE;
}

static Bool
impedPositionWindow(WindowPtr pWin, int x, int y)
{
    return TRUE;
}

static Bool
impedDestroyWindow(WindowPtr pWin)
{
    return TRUE;
}

static Bool
impedMapWindow(WindowPtr pWindow)
{
    return TRUE;
}


static Bool
impedUnmapWindow(WindowPtr pWindow)
{
    return TRUE;
}

static void
impedCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
{

}

static Bool
impedChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
{
    return FALSE;
}

static Bool
impedRealizeFont(ScreenPtr pScreen, FontPtr pFont)
{
    return TRUE;
}

static Bool
impedUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
{
    return TRUE;
}

static void
impedGetImage (DrawablePtr          pDrawable,
               int                  x,
               int                  y,
               int                  w,
               int                  h,
               unsigned int    format,
               unsigned long   planeMask,
               char         *d)
{

}

static void
impedGetSpans(DrawablePtr       pDrawable, 
              int               wMax, 
              DDXPointPtr       ppt, 
              int               *pwidth, 
              int               nspans, 
              char              *pchardstStart)
{
}

static PixmapPtr
impedCreatePixmap (ScreenPtr pScreen, int width, int height, int depth,
                   unsigned usage_hint)
{
    PixmapPtr pPixmap;
    pPixmap = AllocatePixmap(pScreen, 0);
    if (!pPixmap)
	return NULL;

    pPixmap->drawable.type = DRAWABLE_PIXMAP;
    pPixmap->drawable.class = 0;
    pPixmap->drawable.pScreen = pScreen;
    pPixmap->drawable.depth = depth;
    pPixmap->drawable.bitsPerPixel = BitsPerPixel (depth);
    pPixmap->drawable.id = 0;
    pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
    pPixmap->drawable.x = 0;
    pPixmap->drawable.y = 0;
    pPixmap->drawable.width = width;
    pPixmap->drawable.height = height;
    pPixmap->devKind = width;
    pPixmap->refcnt = 1;

#ifdef COMPOSITE
    pPixmap->screen_x = 0;
    pPixmap->screen_y = 0;
#endif
    pPixmap->usage_hint = usage_hint;

    xorg_list_add(&pPixmap->member, &pScreen->pixmap_list);

    {
	ScreenPtr iter;
        int i = 0;
        xorg_list_for_each_entry(iter, &pScreen->gpu_screen_list, gpu_screen_head) {
            pPixmap->gpu[i] = iter->CreatePixmap(iter, width, height, depth, usage_hint);
            i++;
        }
    }
    return pPixmap;
}

static Bool
impedModifyPixmapHeader(PixmapPtr pPixmap, int w, int h, int d,
                        int bpp, int devKind, pointer pPixData)
{
    return TRUE;
}
static void
impedQueryBestSize (int class, 
                    unsigned short *width, unsigned short *height,
                    ScreenPtr pScreen)
{

}

static RegionPtr
impedBitmapToRegion(PixmapPtr pPix)
{
    return NULL;
}

static Bool
impedDestroyPixmap(PixmapPtr pPixmap)
{
    return FALSE;
}

Bool
impedCloseScreen (ScreenPtr pScreen)
{
    return FALSE;
}

static void 
impedBlockHandler(ScreenPtr pScreen, pointer blockData, pointer pTimeout,
                  pointer pReadmask)
{
}

PixmapPtr
_impedGetWindowPixmap (WindowPtr pWindow)
{
    return impedGetWindowPixmap (pWindow);
}

void
_impedSetWindowPixmap (WindowPtr pWindow, PixmapPtr pPixmap)
{
    dixSetPrivate(&pWindow->devPrivates, impedGetWinPrivateKey(), pPixmap);
}


Bool
impedSetupScreen(ScreenPtr pScreen)
{

    if (!impedAllocatePrivates(pScreen))
        return FALSE;
    pScreen->defColormap = FakeClientID(0);

    pScreen->ChangeWindowAttributes = impedChangeWindowAttributes;
    pScreen->CreateWindow = impedCreateWindow;
    pScreen->CopyWindow = impedCopyWindow;
    pScreen->PositionWindow = impedPositionWindow;
    pScreen->RealizeWindow = impedMapWindow;
    pScreen->UnrealizeWindow = impedUnmapWindow;
    pScreen->DestroyWindow = impedDestroyWindow;
    pScreen->GetImage = impedGetImage;
    pScreen->GetSpans = impedGetSpans;
    pScreen->GetWindowPixmap = _impedGetWindowPixmap;
    pScreen->SetWindowPixmap = _impedSetWindowPixmap;

    pScreen->RealizeFont = impedRealizeFont;
    pScreen->UnrealizeFont = impedUnrealizeFont;

    pScreen->CreateColormap = miInitializeColormap;
    pScreen->DestroyColormap = (void (*)(ColormapPtr))NoopDDA;
    pScreen->InstallColormap = miInstallColormap;
    pScreen->UninstallColormap = miUninstallColormap;
    pScreen->ListInstalledColormaps = miListInstalledColormaps;
    pScreen->StoreColors = (void (*)(ColormapPtr, int, xColorItem *))NoopDDA;
    pScreen->ResolveColor = miResolveColor;

    pScreen->CreatePixmap = impedCreatePixmap;
    pScreen->DestroyPixmap = impedDestroyPixmap;

    pScreen->CreateGC = impedCreateGC;

    pScreen->QueryBestSize = impedQueryBestSize;

    pScreen->BitmapToRegion = impedBitmapToRegion;

    /* replace miCloseScreen */

    //    drvmiSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);

    //    xorg_list_init(&pScreen->unattached_list);
    xorg_list_init(&pScreen->gpu_screen_list);
    xorg_list_init(&pScreen->offload_slave_list);
    xorg_list_init(&pScreen->output_slave_list);
    xorg_list_init(&pScreen->unattached_list);
    return TRUE;
}

Bool impedFinishScreenInit(ScreenPtr pScreen,
                           pointer pbits,
                           int          xsize,
                           int          ysize,
                           int          dpix,
                           int          dpiy,
                           int          width,
                           int          bpp)
{
    VisualPtr   visuals;
    DepthPtr    depths;
    int         nvisuals;
    int         ndepths;
    int         rootdepth;
    VisualID    defaultVisual;
    int         imagebpp = bpp;
    //    impedScreenPrivPtr imped_screen;
    rootdepth = 0;

    if (!miInitVisuals(&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
                       &defaultVisual, 8, ((unsigned long)1<<(imagebpp - 1)), -1))
        return FALSE;
    if (!miScreenInit(pScreen, NULL,  xsize, ysize, dpix, dpiy, width,
                      rootdepth, ndepths, depths, defaultVisual,
                      nvisuals, visuals))
        return FALSE;

    //    imped_screen = impedGetScreen(pScreen); 
    pScreen->ModifyPixmapHeader = impedModifyPixmapHeader;
    pScreen->CreateScreenResources = impedCreateScreenResources;
    pScreen->BlockHandler = impedBlockHandler;
    //    imped_screen->SavedCloseScreen = pScreen->CloseScreen;
    //    pScreen->CloseScreen = impedCloseScreen;

    return TRUE;
}

void
impedAttachUnboundScreen(ScreenPtr pScreen, ScreenPtr new)
{
    xorg_list_add(&new->unattached_head, &pScreen->unattached_list);
}

void
impedAttachScreen(ScreenPtr pScreen, ScreenPtr slave)
{
    xorg_list_add(&slave->gpu_screen_head, &pScreen->gpu_screen_list);
    slave->protocol_master = pScreen;
    pScreen->gpu[pScreen->num_gpu] = slave;
    pScreen->num_gpu++;
}

void
impedAttachOutputSlave(ScreenPtr pScreen, ScreenPtr slave, int index)
{
    xorg_list_add(&slave->output_head, &pScreen->output_slave_list);
    slave->protocol_master = pScreen;
    slave->output_master = pScreen;
}

void
impedAttachOffloadSlave(ScreenPtr pScreen, ScreenPtr slave, int index)
{
    xorg_list_add(&slave->offload_head, &pScreen->offload_slave_list);    
    slave->protocol_master = pScreen;
    slave->offload_master = pScreen;
}

void
impedDetachOutputSlave(ScreenPtr pScreen, ScreenPtr slave)
{
    xorg_list_del(&slave->output_head);
    slave->output_master = NULL;
    slave->protocol_master = NULL;
}

void
impedDetachOffloadSlave(ScreenPtr pScreen, ScreenPtr slave)
{
    xorg_list_del(&slave->offload_head);
    slave->offload_master = NULL;
    slave->protocol_master = NULL;
}

void
impedDetachAllSlaves(ScreenPtr pScreen)
{
    ScreenPtr iter, safe;

    xorg_list_for_each_entry_safe(iter, safe, &pScreen->offload_slave_list, offload_head) {
        impedDetachOffloadSlave(iter->protocol_master, iter);
    }


    xorg_list_for_each_entry_safe(iter, safe, &pScreen->output_slave_list, output_head) {
        impedDetachOutputSlave(iter->protocol_master, iter);
    }

}

void
impedMigrateOutputSlaves(ScreenPtr pOldMaster, ScreenPtr pNewMaster)
{

}