~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xnest/Screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: Screen.c,v 1.3 2000/08/17 19:53:28 cpqbld Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1993 by Davor Matic
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software
 
7
and its documentation for any purpose is hereby granted without fee,
 
8
provided that the above copyright notice appear in all copies and that
 
9
both that copyright notice and this permission notice appear in
 
10
supporting documentation.  Davor Matic makes no representations about
 
11
the suitability of this software for any purpose.  It is provided "as
 
12
is" without express or implied warranty.
 
13
 
 
14
*/
 
15
/* $XFree86: xc/programs/Xserver/hw/xnest/Screen.c,v 3.12 2003/11/14 22:25:59 dawes Exp $ */
 
16
 
 
17
#ifdef HAVE_XNEST_CONFIG_H
 
18
#include <xnest-config.h>
 
19
#endif
 
20
 
 
21
#include <X11/X.h>
 
22
#include <X11/Xproto.h>
 
23
#include "scrnintstr.h"
 
24
#include "dix.h"
 
25
#include "mi.h"
 
26
#include "mibstore.h"
 
27
#include "micmap.h"
 
28
#include "colormapst.h"
 
29
#include "resource.h"
 
30
 
 
31
#include "Xnest.h"
 
32
 
 
33
#include "Display.h"
 
34
#include "Screen.h"
 
35
#include "XNGC.h"
 
36
#include "GCOps.h"
 
37
#include "Drawable.h"
 
38
#include "XNFont.h"
 
39
#include "Color.h"
 
40
#include "XNCursor.h"
 
41
#include "Visual.h"
 
42
#include "Events.h"
 
43
#include "Init.h"
 
44
#include "mipointer.h"
 
45
#include "Args.h"
 
46
 
 
47
Window xnestDefaultWindows[MAXSCREENS];
 
48
Window xnestScreenSaverWindows[MAXSCREENS];
 
49
 
 
50
#ifdef GLXEXT
 
51
extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
 
52
#endif
 
53
 
 
54
#ifdef PIXPRIV
 
55
int xnestScreenGeneration = -1;
 
56
#endif
 
57
 
 
58
ScreenPtr
 
59
xnestScreen(Window window)
 
60
{
 
61
  int i;
 
62
  
 
63
  for (i = 0; i < xnestNumScreens; i++)
 
64
    if (xnestDefaultWindows[i] == window) 
 
65
      return screenInfo.screens[i];
 
66
 
 
67
  return NULL;
 
68
}
 
69
 
 
70
static int
 
71
offset(unsigned long mask)
 
72
{
 
73
  int count;
 
74
  
 
75
  for (count = 0; !(mask & 1) && count < 32; count++)
 
76
    mask >>= 1;
 
77
  
 
78
  return count;
 
79
}
 
80
 
 
81
static Bool
 
82
xnestSaveScreen(ScreenPtr pScreen, int what)
 
83
{
 
84
  if (xnestSoftwareScreenSaver)
 
85
    return False;
 
86
  else {
 
87
    switch (what) {
 
88
    case SCREEN_SAVER_ON:
 
89
      XMapRaised(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
 
90
      xnestSetScreenSaverColormapWindow(pScreen);
 
91
      break;
 
92
      
 
93
    case SCREEN_SAVER_OFF:
 
94
      XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
 
95
      xnestSetInstalledColormapWindows(pScreen);
 
96
      break;
 
97
      
 
98
    case SCREEN_SAVER_FORCER:
 
99
      lastEventTime = GetTimeInMillis();
 
100
      XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
 
101
      xnestSetInstalledColormapWindows(pScreen);
 
102
      break;
 
103
      
 
104
    case SCREEN_SAVER_CYCLE:
 
105
      XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
 
106
      xnestSetInstalledColormapWindows(pScreen);
 
107
      break;
 
108
    }
 
109
    return True;
 
110
  }
 
111
}
 
112
 
 
113
static Bool
 
114
xnestCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y)
 
115
{
 
116
    return FALSE;
 
117
}
 
118
 
 
119
static void
 
120
xnestCrossScreen(ScreenPtr pScreen, Bool entering)
 
121
{
 
122
}
 
123
 
 
124
static miPointerScreenFuncRec xnestPointerCursorFuncs =
 
125
{
 
126
    xnestCursorOffScreen,
 
127
    xnestCrossScreen,
 
128
    miPointerWarpCursor
 
129
};
 
130
 
 
131
static miPointerSpriteFuncRec xnestPointerSpriteFuncs = 
 
132
{
 
133
    xnestRealizeCursor,
 
134
    xnestUnrealizeCursor,
 
135
    xnestSetCursor,
 
136
    xnestMoveCursor,
 
137
};
 
138
 
 
139
Bool
 
140
xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
 
141
{
 
142
  VisualPtr visuals;
 
143
  DepthPtr depths;
 
144
  int numVisuals, numDepths;
 
145
  int i, j, depthIndex;
 
146
  unsigned long valuemask;
 
147
  XSetWindowAttributes attributes;
 
148
  XWindowAttributes gattributes;
 
149
  XSizeHints sizeHints;
 
150
  VisualID defaultVisual;
 
151
  int rootDepth;
 
152
 
 
153
  if (!(AllocateWindowPrivate(pScreen, xnestWindowPrivateIndex,
 
154
                            sizeof(xnestPrivWin))  &&
 
155
          AllocateGCPrivate(pScreen, xnestGCPrivateIndex, 
 
156
                            sizeof(xnestPrivGC)))) 
 
157
    return False;
 
158
 
 
159
#ifdef PIXPRIV
 
160
  if (xnestScreenGeneration != serverGeneration) {
 
161
      if ((xnestPixmapPrivateIndex = AllocatePixmapPrivateIndex()) < 0)
 
162
          return False;
 
163
      xnestScreenGeneration = serverGeneration;
 
164
  }
 
165
  
 
166
  if (!AllocatePixmapPrivate(pScreen,xnestPixmapPrivateIndex,
 
167
                             sizeof (xnestPrivPixmap)))
 
168
      return False;
 
169
#endif
 
170
  visuals = (VisualPtr)xalloc(xnestNumVisuals * sizeof(VisualRec));
 
171
  numVisuals = 0;
 
172
 
 
173
  depths = (DepthPtr)xalloc(MAXDEPTH * sizeof(DepthRec));
 
174
  depths[0].depth = 1;
 
175
  depths[0].numVids = 0;
 
176
  depths[0].vids = (VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
 
177
  numDepths = 1;
 
178
 
 
179
  for (i = 0; i < xnestNumVisuals; i++) {
 
180
    visuals[numVisuals].class = xnestVisuals[i].class;
 
181
    visuals[numVisuals].bitsPerRGBValue = xnestVisuals[i].bits_per_rgb;
 
182
    visuals[numVisuals].ColormapEntries = xnestVisuals[i].colormap_size;
 
183
    visuals[numVisuals].nplanes = xnestVisuals[i].depth;
 
184
    visuals[numVisuals].redMask = xnestVisuals[i].red_mask;
 
185
    visuals[numVisuals].greenMask = xnestVisuals[i].green_mask;
 
186
    visuals[numVisuals].blueMask = xnestVisuals[i].blue_mask;
 
187
    visuals[numVisuals].offsetRed = offset(xnestVisuals[i].red_mask);
 
188
    visuals[numVisuals].offsetGreen = offset(xnestVisuals[i].green_mask);
 
189
    visuals[numVisuals].offsetBlue = offset(xnestVisuals[i].blue_mask);
 
190
 
 
191
    /* Check for and remove duplicates. */
 
192
    for (j = 0; j < numVisuals; j++) {
 
193
      if (visuals[numVisuals].class           == visuals[j].class           &&
 
194
          visuals[numVisuals].bitsPerRGBValue == visuals[j].bitsPerRGBValue &&
 
195
          visuals[numVisuals].ColormapEntries == visuals[j].ColormapEntries &&
 
196
          visuals[numVisuals].nplanes         == visuals[j].nplanes         &&
 
197
          visuals[numVisuals].redMask         == visuals[j].redMask         &&
 
198
          visuals[numVisuals].greenMask       == visuals[j].greenMask       &&
 
199
          visuals[numVisuals].blueMask        == visuals[j].blueMask        &&
 
200
          visuals[numVisuals].offsetRed       == visuals[j].offsetRed       &&
 
201
          visuals[numVisuals].offsetGreen     == visuals[j].offsetGreen     &&
 
202
          visuals[numVisuals].offsetBlue      == visuals[j].offsetBlue)
 
203
        break;
 
204
    }
 
205
    if (j < numVisuals)
 
206
      break;
 
207
 
 
208
    visuals[numVisuals].vid = FakeClientID(0);
 
209
 
 
210
    depthIndex = UNDEFINED;
 
211
    for (j = 0; j < numDepths; j++)
 
212
      if (depths[j].depth == xnestVisuals[i].depth) {
 
213
        depthIndex = j;
 
214
        break;
 
215
      }
 
216
    
 
217
    if (depthIndex == UNDEFINED) {
 
218
      depthIndex = numDepths;
 
219
      depths[depthIndex].depth = xnestVisuals[i].depth;
 
220
      depths[depthIndex].numVids = 0;
 
221
      depths[depthIndex].vids = 
 
222
        (VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
 
223
      numDepths++;
 
224
    }
 
225
    if (depths[depthIndex].numVids >= MAXVISUALSPERDEPTH) {
 
226
        FatalError("Visual table overflow");
 
227
    }
 
228
    depths[depthIndex].vids[depths[depthIndex].numVids] = 
 
229
      visuals[numVisuals].vid;
 
230
    depths[depthIndex].numVids++;
 
231
    
 
232
    numVisuals++;
 
233
  }
 
234
  visuals = (VisualPtr)xrealloc(visuals, numVisuals * sizeof(VisualRec));
 
235
 
 
236
  defaultVisual = visuals[xnestDefaultVisualIndex].vid;
 
237
  rootDepth = visuals[xnestDefaultVisualIndex].nplanes;
 
238
 
 
239
#ifdef GLXEXT
 
240
  {
 
241
    miInitVisualsProcPtr proc = NULL;
 
242
 
 
243
    GlxWrapInitVisuals(&proc);
 
244
    /* GlxInitVisuals ignores the last three arguments. */
 
245
    proc(&visuals, &depths, &numVisuals, &numDepths,
 
246
         &rootDepth, &defaultVisual, 0, 0, 0);
 
247
  }
 
248
#endif
 
249
 
 
250
  if (xnestParentWindow != 0) {
 
251
    XGetWindowAttributes(xnestDisplay, xnestParentWindow, &gattributes);
 
252
    xnestWidth = gattributes.width;
 
253
    xnestHeight = gattributes.height;
 
254
  }
 
255
 
 
256
  /* myNum */
 
257
  /* id */
 
258
  miScreenInit(pScreen, NULL, xnestWidth, xnestHeight, 1, 1, xnestWidth,
 
259
               rootDepth,
 
260
               numDepths, depths,
 
261
               defaultVisual, /* root visual */
 
262
               numVisuals, visuals);
 
263
 
 
264
/*  miInitializeBackingStore(pScreen); */
 
265
 
 
266
  pScreen->defColormap = (Colormap) FakeClientID(0);
 
267
  pScreen->minInstalledCmaps = MINCMAPS;
 
268
  pScreen->maxInstalledCmaps = MAXCMAPS;
 
269
  pScreen->backingStoreSupport = NotUseful;
 
270
  pScreen->saveUnderSupport = NotUseful;
 
271
  pScreen->whitePixel = xnestWhitePixel;
 
272
  pScreen->blackPixel = xnestBlackPixel;
 
273
  /* rgf */
 
274
  /* GCperDepth */
 
275
  /* PixmapPerDepth */
 
276
  pScreen->devPrivate = NULL;
 
277
  /* WindowPrivateLen */
 
278
  /* WindowPrivateSizes */
 
279
  /* totalWindowSize */
 
280
  /* GCPrivateLen */
 
281
  /* GCPrivateSizes */
 
282
  /* totalGCSize */
 
283
 
 
284
  /* Random screen procedures */
 
285
 
 
286
  pScreen->QueryBestSize = xnestQueryBestSize;
 
287
  pScreen->SaveScreen = xnestSaveScreen;
 
288
  pScreen->GetImage = xnestGetImage;
 
289
  pScreen->GetSpans = xnestGetSpans;
 
290
  pScreen->PointerNonInterestBox = NULL;
 
291
  pScreen->SourceValidate = NULL;
 
292
 
 
293
  /* Window Procedures */
 
294
  
 
295
  pScreen->CreateWindow = xnestCreateWindow;
 
296
  pScreen->DestroyWindow = xnestDestroyWindow;
 
297
  pScreen->PositionWindow = xnestPositionWindow;
 
298
  pScreen->ChangeWindowAttributes = xnestChangeWindowAttributes;
 
299
  pScreen->RealizeWindow = xnestRealizeWindow;
 
300
  pScreen->UnrealizeWindow = xnestUnrealizeWindow;
 
301
  pScreen->PostValidateTree = NULL;
 
302
  pScreen->WindowExposures = xnestWindowExposures;
 
303
  pScreen->PaintWindowBackground = xnestPaintWindowBackground;
 
304
  pScreen->PaintWindowBorder = xnestPaintWindowBorder;
 
305
  pScreen->CopyWindow = xnestCopyWindow;
 
306
  pScreen->ClipNotify = xnestClipNotify;
 
307
 
 
308
  /* Pixmap procedures */
 
309
 
 
310
  pScreen->CreatePixmap = xnestCreatePixmap;
 
311
  pScreen->DestroyPixmap = xnestDestroyPixmap;
 
312
 
 
313
  /* Backing store procedures */
 
314
  
 
315
  pScreen->SaveDoomedAreas = NULL;
 
316
  pScreen->RestoreAreas = NULL;
 
317
  pScreen->ExposeCopy = NULL;
 
318
  pScreen->TranslateBackingStore = NULL;
 
319
  pScreen->ClearBackingStore = NULL;
 
320
  pScreen->DrawGuarantee = NULL;
 
321
 
 
322
  /* Font procedures */
 
323
 
 
324
  pScreen->RealizeFont = xnestRealizeFont;
 
325
  pScreen->UnrealizeFont = xnestUnrealizeFont;
 
326
 
 
327
  /* GC procedures */
 
328
  
 
329
  pScreen->CreateGC = xnestCreateGC;
 
330
 
 
331
  /* Colormap procedures */
 
332
 
 
333
  pScreen->CreateColormap = xnestCreateColormap;
 
334
  pScreen->DestroyColormap = xnestDestroyColormap;
 
335
  pScreen->InstallColormap = xnestInstallColormap;
 
336
  pScreen->UninstallColormap = xnestUninstallColormap;
 
337
  pScreen->ListInstalledColormaps = xnestListInstalledColormaps;
 
338
  pScreen->StoreColors = xnestStoreColors;
 
339
  pScreen->ResolveColor = xnestResolveColor;
 
340
 
 
341
   pScreen->BitmapToRegion = xnestPixmapToRegion;
 
342
 
 
343
  /* OS layer procedures */
 
344
 
 
345
  pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA;
 
346
  pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA;
 
347
  pScreen->blockData = NULL;
 
348
  pScreen->wakeupData = NULL;
 
349
 
 
350
  miPointerInitialize (pScreen, &xnestPointerSpriteFuncs, 
 
351
                       &xnestPointerCursorFuncs, True);
 
352
 
 
353
  pScreen->mmWidth = xnestWidth * DisplayWidthMM(xnestDisplay, 
 
354
                       DefaultScreen(xnestDisplay)) / 
 
355
                         DisplayWidth(xnestDisplay, 
 
356
                           DefaultScreen(xnestDisplay));
 
357
  pScreen->mmHeight = xnestHeight * DisplayHeightMM(xnestDisplay, 
 
358
                        DefaultScreen(xnestDisplay)) /
 
359
                          DisplayHeight(xnestDisplay, 
 
360
                            DefaultScreen(xnestDisplay));
 
361
 
 
362
  /* overwrite miCloseScreen with our own */
 
363
  pScreen->CloseScreen = xnestCloseScreen;
 
364
 
 
365
  if (!miScreenDevPrivateInit(pScreen, xnestWidth, NULL))
 
366
      return FALSE;
 
367
 
 
368
#ifdef SHAPE
 
369
  /* overwrite miSetShape with our own */
 
370
  pScreen->SetShape = xnestSetShape;
 
371
#endif /* SHAPE */
 
372
 
 
373
  /* devPrivates */
 
374
 
 
375
#define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32)
 
376
    
 
377
  if (xnestDoFullGeneration) {
 
378
 
 
379
    valuemask = CWBackPixel | CWEventMask | CWColormap;
 
380
    attributes.background_pixel = xnestWhitePixel;
 
381
    attributes.event_mask = xnestEventMask;
 
382
    attributes.colormap = xnestDefaultVisualColormap(xnestDefaultVisual(pScreen));
 
383
    
 
384
    if (xnestParentWindow != 0) {
 
385
      xnestDefaultWindows[pScreen->myNum] = xnestParentWindow;
 
386
      XSelectInput (xnestDisplay, xnestDefaultWindows[pScreen->myNum],
 
387
                    xnestEventMask);
 
388
    } else
 
389
      xnestDefaultWindows[pScreen->myNum] = 
 
390
        XCreateWindow(xnestDisplay, 
 
391
                      DefaultRootWindow(xnestDisplay),
 
392
                      xnestX + POSITION_OFFSET,
 
393
                      xnestY + POSITION_OFFSET,
 
394
                      xnestWidth, xnestHeight,
 
395
                      xnestBorderWidth,
 
396
                      pScreen->rootDepth,
 
397
                      InputOutput,
 
398
                      xnestDefaultVisual(pScreen),
 
399
                      valuemask, &attributes);
 
400
 
 
401
    if (!xnestWindowName)
 
402
      xnestWindowName = argv[0];
 
403
    
 
404
    sizeHints.flags = PPosition | PSize | PMaxSize;
 
405
    sizeHints.x = xnestX + POSITION_OFFSET;
 
406
    sizeHints.y = xnestY + POSITION_OFFSET;
 
407
    sizeHints.width = sizeHints.max_width = xnestWidth;
 
408
    sizeHints.height = sizeHints.max_height = xnestHeight;
 
409
    if (xnestUserGeometry & XValue || xnestUserGeometry & YValue)
 
410
      sizeHints.flags |= USPosition;
 
411
    if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue)
 
412
      sizeHints.flags |= USSize;
 
413
    XSetStandardProperties(xnestDisplay, 
 
414
                           xnestDefaultWindows[pScreen->myNum], 
 
415
                           xnestWindowName, 
 
416
                           xnestWindowName, 
 
417
                           xnestIconBitmap,
 
418
                           argv, argc, &sizeHints);
 
419
    
 
420
    XMapWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum]);
 
421
 
 
422
    valuemask = CWBackPixmap | CWColormap;
 
423
    attributes.background_pixmap = xnestScreenSaverPixmap;
 
424
    attributes.colormap = 
 
425
      DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay));
 
426
    xnestScreenSaverWindows[pScreen->myNum] =
 
427
      XCreateWindow(xnestDisplay, 
 
428
                    xnestDefaultWindows[pScreen->myNum],
 
429
                    0, 0, xnestWidth, xnestHeight, 0,
 
430
                    DefaultDepth(xnestDisplay, DefaultScreen(xnestDisplay)),
 
431
                    InputOutput, 
 
432
                    DefaultVisual(xnestDisplay, DefaultScreen(xnestDisplay)),
 
433
                    valuemask, &attributes);
 
434
  }
 
435
  
 
436
  if (!xnestCreateDefaultColormap(pScreen)) return False;
 
437
  
 
438
  return True;
 
439
}
 
440
 
 
441
Bool
 
442
xnestCloseScreen(int index, ScreenPtr pScreen)
 
443
{
 
444
  int i;
 
445
  
 
446
  for (i = 0; i < pScreen->numDepths; i++)
 
447
    xfree(pScreen->allowedDepths[i].vids);
 
448
  xfree(pScreen->allowedDepths);
 
449
  xfree(pScreen->visuals);
 
450
  xfree(pScreen->devPrivate);
 
451
 
 
452
  /*
 
453
    If xnestDoFullGeneration all x resources will be destroyed upon closing
 
454
    the display connection.  There is no need to generate extra protocol.
 
455
    */
 
456
 
 
457
  return True;
 
458
}