~gma500/emgd/trunk

« back to all changes in this revision

Viewing changes to xorg/xorg-server-1.7.6/hw/xquartz/xpr/xprScreen.c

  • Committer: José Bernardo Bandos
  • Date: 2010-08-28 16:04:10 UTC
  • Revision ID: jbs@jbs-laptop-20100828160410-nw5zohdn37oupdv2
First step to add emgd drivers from meego

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Xplugin rootless implementation screen functions
3
 
 *
4
 
 * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
5
 
 * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
6
 
 *
7
 
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 
 * copy of this software and associated documentation files (the "Software"),
9
 
 * to deal in the Software without restriction, including without limitation
10
 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
 
 * and/or sell copies of the Software, and to permit persons to whom the
12
 
 * Software is furnished to do so, subject to the following conditions:
13
 
 *
14
 
 * The above copyright notice and this permission notice shall be included in
15
 
 * all copies or substantial portions of the Software.
16
 
 *
17
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
 
 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21
 
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
 
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
 
 * DEALINGS IN THE SOFTWARE.
24
 
 *
25
 
 * Except as contained in this notice, the name(s) of the above copyright
26
 
 * holders shall not be used in advertising or otherwise to promote the sale,
27
 
 * use or other dealings in this Software without prior written authorization.
28
 
 */
29
 
 
30
 
#include "sanitizedCarbon.h"
31
 
 
32
 
#ifdef HAVE_DIX_CONFIG_H
33
 
#include <dix-config.h>
34
 
#endif
35
 
 
36
 
#include "quartzCommon.h"
37
 
#include "inputstr.h"
38
 
#include "quartz.h"
39
 
#include "xpr.h"
40
 
#include "xprEvent.h"
41
 
#include "pseudoramiX.h"
42
 
#include "darwin.h"
43
 
#include "darwinEvents.h"
44
 
#include "rootless.h"
45
 
#include "dri.h"
46
 
#include "globals.h"
47
 
#include <Xplugin.h>
48
 
#include "applewmExt.h"
49
 
#include "micmap.h"
50
 
 
51
 
#include "rootlessCommon.h"
52
 
 
53
 
#ifdef DAMAGE
54
 
# include "damage.h"
55
 
#endif
56
 
 
57
 
/* 10.4's deferred update makes X slower.. have to live with the tearing
58
 
   for now.. */
59
 
#define XP_NO_DEFERRED_UPDATES 8
60
 
 
61
 
// Name of GLX bundle for native OpenGL
62
 
static const char *xprOpenGLBundle = "glxCGL.bundle";
63
 
 
64
 
/*
65
 
 * eventHandler
66
 
 *  Callback handler for Xplugin events.
67
 
 */
68
 
static void eventHandler(unsigned int type, const void *arg,
69
 
                         unsigned int arg_size, void *data) {
70
 
    
71
 
    switch (type) {
72
 
        case XP_EVENT_DISPLAY_CHANGED:
73
 
            DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
74
 
            DarwinSendDDXEvent(kXquartzDisplayChanged, 0);
75
 
            break;
76
 
            
77
 
        case XP_EVENT_WINDOW_STATE_CHANGED:
78
 
            if (arg_size >= sizeof(xp_window_state_event)) {
79
 
                const xp_window_state_event *ws_arg = arg;
80
 
                
81
 
                DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state);
82
 
                DarwinSendDDXEvent(kXquartzWindowState, 2,
83
 
                                          ws_arg->id, ws_arg->state);
84
 
            } else {
85
 
                DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n");
86
 
            }
87
 
            break;
88
 
            
89
 
        case XP_EVENT_WINDOW_MOVED:
90
 
            DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n");
91
 
            if (arg_size == sizeof(xp_window_id))  {
92
 
                xp_window_id id = * (xp_window_id *) arg;
93
 
                DarwinSendDDXEvent(kXquartzWindowMoved, 1, id);
94
 
            }
95
 
            break;
96
 
            
97
 
        case XP_EVENT_SURFACE_DESTROYED:
98
 
            DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n");
99
 
        case XP_EVENT_SURFACE_CHANGED:
100
 
            DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n");
101
 
            if (arg_size == sizeof(xp_surface_id)) {
102
 
                int kind;
103
 
                
104
 
                if (type == XP_EVENT_SURFACE_DESTROYED)
105
 
                    kind = AppleDRISurfaceNotifyDestroyed;
106
 
                else
107
 
                    kind = AppleDRISurfaceNotifyChanged;
108
 
                
109
 
                DRISurfaceNotify(*(xp_surface_id *) arg, kind);
110
 
            }
111
 
            break;
112
 
#ifdef XP_EVENT_SPACE_CHANGED
113
 
        case  XP_EVENT_SPACE_CHANGED:
114
 
            DEBUG_LOG("XP_EVENT_SPACE_CHANGED\n");
115
 
            if(arg_size == sizeof(uint32_t)) {
116
 
                uint32_t space_id = *(uint32_t *)arg;
117
 
                DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id);
118
 
            }
119
 
            break;
120
 
#endif
121
 
        default:
122
 
            ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type);
123
 
    }
124
 
}
125
 
 
126
 
/*
127
 
 * displayAtIndex
128
 
 *  Return the display ID for a particular display index.
129
 
 */
130
 
static CGDirectDisplayID
131
 
displayAtIndex(int index)
132
 
{
133
 
    CGError err;
134
 
    CGDisplayCount cnt;
135
 
    CGDirectDisplayID dpy[index+1];
136
 
 
137
 
    err = CGGetActiveDisplayList(index + 1, dpy, &cnt);
138
 
    if (err == kCGErrorSuccess && cnt == index + 1)
139
 
        return dpy[index];
140
 
    else
141
 
        return kCGNullDirectDisplay;
142
 
}
143
 
 
144
 
/*
145
 
 * displayScreenBounds
146
 
 *  Return the bounds of a particular display.
147
 
 */
148
 
static CGRect
149
 
displayScreenBounds(CGDirectDisplayID id)
150
 
{
151
 
    CGRect frame;
152
 
 
153
 
    frame = CGDisplayBounds(id);
154
 
 
155
 
    DEBUG_LOG("    %dx%d @ (%d,%d).\n",
156
 
              (int)frame.size.width, (int)frame.size.height,
157
 
              (int)frame.origin.x, (int)frame.origin.y);
158
 
    
159
 
    /* Remove menubar to help standard X11 window managers. */
160
 
    if (quartzEnableRootless && 
161
 
        frame.origin.x == 0 && frame.origin.y == 0) {
162
 
        frame.origin.y += aquaMenuBarHeight;
163
 
        frame.size.height -= aquaMenuBarHeight;
164
 
    }
165
 
 
166
 
    DEBUG_LOG("    %dx%d @ (%d,%d).\n",
167
 
              (int)frame.size.width, (int)frame.size.height,
168
 
              (int)frame.origin.x, (int)frame.origin.y);
169
 
 
170
 
    return frame;
171
 
}
172
 
 
173
 
/*
174
 
 * xprAddPseudoramiXScreens
175
 
 *  Add a single virtual screen encompassing all the physical screens
176
 
 *  with PseudoramiX.
177
 
 */
178
 
static void
179
 
xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
180
 
{
181
 
    CGDisplayCount i, displayCount;
182
 
    CGDirectDisplayID *displayList = NULL;
183
 
    CGRect unionRect = CGRectNull, frame;
184
 
 
185
 
    // Find all the CoreGraphics displays
186
 
    CGGetActiveDisplayList(0, NULL, &displayCount);
187
 
    DEBUG_LOG("displayCount: %d\n", (int)displayCount);
188
 
 
189
 
    if(!displayCount) {
190
 
        ErrorF("CoreGraphics has reported no connected displays.  Creating a stub 800x600 display.\n");
191
 
        *x = *y = 0;
192
 
        *width = 800;
193
 
        *height = 600;
194
 
        PseudoramiXAddScreen(*x, *y, *width, *height);
195
 
        return;
196
 
    }
197
 
 
198
 
    displayList = xalloc(displayCount * sizeof(CGDirectDisplayID));
199
 
    if(!displayList)
200
 
        FatalError("Unable to allocate memory for list of displays.\n");
201
 
    CGGetActiveDisplayList(displayCount, displayList, &displayCount);
202
 
 
203
 
    /* Get the union of all screens */
204
 
    for (i = 0; i < displayCount; i++) {
205
 
        CGDirectDisplayID dpy = displayList[i];
206
 
        frame = displayScreenBounds(dpy);
207
 
        unionRect = CGRectUnion(unionRect, frame);
208
 
    }
209
 
 
210
 
    /* Use unionRect as the screen size for the X server. */
211
 
    *x = unionRect.origin.x;
212
 
    *y = unionRect.origin.y;
213
 
    *width = unionRect.size.width;
214
 
    *height = unionRect.size.height;
215
 
 
216
 
    DEBUG_LOG("  screen union origin: (%d,%d) size: (%d,%d).\n",
217
 
              *x, *y, *width, *height);
218
 
 
219
 
    /* Tell PseudoramiX about the real screens. */
220
 
    for (i = 0; i < displayCount; i++)
221
 
    {
222
 
        CGDirectDisplayID dpy = displayList[i];
223
 
 
224
 
        frame = displayScreenBounds(dpy);
225
 
        frame.origin.x -= unionRect.origin.x;
226
 
        frame.origin.y -= unionRect.origin.y;
227
 
 
228
 
        DEBUG_LOG("    placed at X11 coordinate (%d,%d).\n",
229
 
                  (int)frame.origin.x, (int)frame.origin.y);
230
 
 
231
 
        PseudoramiXAddScreen(frame.origin.x, frame.origin.y,
232
 
                             frame.size.width, frame.size.height);
233
 
    }
234
 
 
235
 
    xfree(displayList);
236
 
}
237
 
 
238
 
/*
239
 
 * xprDisplayInit
240
 
 *  Find number of CoreGraphics displays and initialize Xplugin.
241
 
 */
242
 
static void
243
 
xprDisplayInit(void)
244
 
{
245
 
    CGDisplayCount displayCount;
246
 
 
247
 
    DEBUG_LOG("");
248
 
 
249
 
    CGGetActiveDisplayList(0, NULL, &displayCount);
250
 
 
251
 
    /* With PseudoramiX, the X server only sees one screen; only PseudoramiX
252
 
       itself knows about all of the screens. */
253
 
 
254
 
    if (noPseudoramiXExtension)
255
 
        darwinScreensFound = displayCount;
256
 
    else
257
 
        darwinScreensFound =  1;
258
 
 
259
 
    if (xp_init(XP_BACKGROUND_EVENTS | XP_NO_DEFERRED_UPDATES) != Success)
260
 
        FatalError("Could not initialize the Xplugin library.");
261
 
 
262
 
    xp_select_events(XP_EVENT_DISPLAY_CHANGED
263
 
                     | XP_EVENT_WINDOW_STATE_CHANGED
264
 
                     | XP_EVENT_WINDOW_MOVED
265
 
#ifdef XP_EVENT_SPACE_CHANGED
266
 
                     | XP_EVENT_SPACE_CHANGED
267
 
#endif
268
 
                     | XP_EVENT_SURFACE_CHANGED
269
 
                     | XP_EVENT_SURFACE_DESTROYED,
270
 
                     eventHandler, NULL);
271
 
 
272
 
    AppleDRIExtensionInit();
273
 
    xprAppleWMInit();
274
 
 
275
 
    if (!quartzEnableRootless)
276
 
        RootlessHideAllWindows();
277
 
}
278
 
 
279
 
/*
280
 
 * xprAddScreen
281
 
 *  Init the framebuffer and record pixmap parameters for the screen.
282
 
 */
283
 
static Bool
284
 
xprAddScreen(int index, ScreenPtr pScreen)
285
 
{
286
 
    DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
287
 
    int depth = darwinDesiredDepth;
288
 
 
289
 
    DEBUG_LOG("index=%d depth=%d\n", index, depth);
290
 
    
291
 
    if(depth == -1) {
292
 
        depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay);
293
 
    }
294
 
    
295
 
    switch(depth) {
296
 
        case 8: // pseudo-working
297
 
            dfb->visuals = PseudoColorMask;
298
 
            dfb->preferredCVC = PseudoColor;
299
 
            dfb->depth = 8;
300
 
            dfb->bitsPerRGB = 8;
301
 
            dfb->bitsPerPixel = 8;
302
 
            dfb->redMask = 0;
303
 
            dfb->greenMask = 0;
304
 
            dfb->blueMask = 0;
305
 
            break;
306
 
        case 15:
307
 
            dfb->visuals = TrueColorMask; //LARGE_VISUALS;
308
 
            dfb->preferredCVC = TrueColor;
309
 
            dfb->depth = 15;
310
 
            dfb->bitsPerRGB = 5;
311
 
            dfb->bitsPerPixel = 16;
312
 
            dfb->redMask   = RM_ARGB(0,5,5,5);
313
 
            dfb->greenMask = GM_ARGB(0,5,5,5);
314
 
            dfb->blueMask  = BM_ARGB(0,5,5,5);
315
 
            break;
316
 
//        case 24:
317
 
        default:
318
 
            if(depth != 24)
319
 
                ErrorF("Unsupported color depth requested.  Defaulting to 24bit. (depth=%d darwinDesiredDepth=%d CGDisplaySamplesPerPixel=%d CGDisplayBitsPerSample=%d)\n",  darwinDesiredDepth, depth, (int)CGDisplaySamplesPerPixel(kCGDirectMainDisplay), (int)CGDisplayBitsPerSample(kCGDirectMainDisplay));
320
 
            dfb->visuals = TrueColorMask; //LARGE_VISUALS;
321
 
            dfb->preferredCVC = TrueColor;
322
 
            dfb->depth = 24;
323
 
            dfb->bitsPerRGB = 8;
324
 
            dfb->bitsPerPixel = 32;
325
 
            dfb->redMask   = RM_ARGB(0,8,8,8);
326
 
            dfb->greenMask = GM_ARGB(0,8,8,8);
327
 
            dfb->blueMask  = BM_ARGB(0,8,8,8);
328
 
            break;
329
 
    }
330
 
 
331
 
    if (noPseudoramiXExtension)
332
 
    {
333
 
        CGDirectDisplayID dpy;
334
 
        CGRect frame;
335
 
 
336
 
        ErrorF("Warning: noPseudoramiXExtension!\n");
337
 
        
338
 
        dpy = displayAtIndex(index);
339
 
 
340
 
        frame = displayScreenBounds(dpy);
341
 
 
342
 
        dfb->x = frame.origin.x;
343
 
        dfb->y = frame.origin.y;
344
 
        dfb->width =  frame.size.width;
345
 
        dfb->height = frame.size.height;
346
 
    }
347
 
    else
348
 
    {
349
 
        xprAddPseudoramiXScreens(&dfb->x, &dfb->y, &dfb->width, &dfb->height);
350
 
    }
351
 
 
352
 
    /* Passing zero width (pitch) makes miCreateScreenResources set the
353
 
       screen pixmap to the framebuffer pointer, i.e. NULL. The generic
354
 
       rootless code takes care of making this work. */
355
 
    dfb->pitch = 0;
356
 
    dfb->framebuffer = NULL;
357
 
 
358
 
    DRIScreenInit(pScreen);
359
 
 
360
 
    return TRUE;
361
 
}
362
 
 
363
 
/*
364
 
 * xprSetupScreen
365
 
 *  Setup the screen for rootless access.
366
 
 */
367
 
static Bool
368
 
xprSetupScreen(int index, ScreenPtr pScreen)
369
 
{
370
 
    // Initialize accelerated rootless drawing
371
 
    // Note that this must be done before DamageSetup().
372
 
 
373
 
    // These are crashing ugly... better to be stable and not crash for now.
374
 
    //RootlessAccelInit(pScreen);
375
 
 
376
 
#ifdef DAMAGE
377
 
    // The Damage extension needs to wrap underneath the
378
 
    // generic rootless layer, so do it now.
379
 
    if (!DamageSetup(pScreen))
380
 
        return FALSE;
381
 
#endif
382
 
 
383
 
    // Initialize generic rootless code
384
 
    if (!xprInit(pScreen))
385
 
        return FALSE;
386
 
 
387
 
    return DRIFinishScreenInit(pScreen);
388
 
}
389
 
 
390
 
/*
391
 
 * xprUpdateScreen
392
 
 *  Update screen after configuation change.
393
 
 */
394
 
static void
395
 
xprUpdateScreen(ScreenPtr pScreen)
396
 
{
397
 
    rootlessGlobalOffsetX = darwinMainScreenX;
398
 
    rootlessGlobalOffsetY = darwinMainScreenY;
399
 
 
400
 
    AppleWMSetScreenOrigin(WindowTable[pScreen->myNum]);
401
 
 
402
 
    RootlessRepositionWindows(pScreen);
403
 
    RootlessUpdateScreenPixmap(pScreen);
404
 
}
405
 
 
406
 
/*
407
 
 * xprInitInput
408
 
 *  Finalize xpr specific setup.
409
 
 */
410
 
static void
411
 
xprInitInput(int argc, char **argv)
412
 
{
413
 
    int i;
414
 
 
415
 
    rootlessGlobalOffsetX = darwinMainScreenX;
416
 
    rootlessGlobalOffsetY = darwinMainScreenY;
417
 
 
418
 
    for (i = 0; i < screenInfo.numScreens; i++)
419
 
        AppleWMSetScreenOrigin(WindowTable[i]);
420
 
}
421
 
 
422
 
/*
423
 
 * Quartz display mode function list.
424
 
 */
425
 
static QuartzModeProcsRec xprModeProcs = {
426
 
    xprDisplayInit,
427
 
    xprAddScreen,
428
 
    xprSetupScreen,
429
 
    xprInitInput,
430
 
    QuartzInitCursor,
431
 
    QuartzSuspendXCursor,
432
 
    QuartzResumeXCursor,
433
 
    xprAddPseudoramiXScreens,
434
 
    xprUpdateScreen,
435
 
    xprIsX11Window,
436
 
    xprHideWindows,
437
 
    RootlessFrameForWindow,
438
 
    TopLevelParent,
439
 
    DRICreateSurface,
440
 
    DRIDestroySurface
441
 
};
442
 
 
443
 
/*
444
 
 * QuartzModeBundleInit
445
 
 *  Initialize the display mode bundle after loading.
446
 
 */
447
 
Bool
448
 
QuartzModeBundleInit(void)
449
 
{
450
 
    quartzProcs = &xprModeProcs;
451
 
    quartzOpenGLBundle = xprOpenGLBundle;
452
 
    return TRUE;
453
 
}