initial commit
[profile/ivi/xorg-x11-server.git] / hw / dmx / dmxcb.c
1 /*
2  * Copyright 2001-2004 Red Hat Inc., Durham, North Carolina.
3  *
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation on the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial
16  * portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27
28 /*
29  * Authors:
30  *   Rickard E. (Rik) Faith <faith@redhat.com>
31  *
32  */
33
34 /** \file
35  * This code queries and modifies the connection block. */
36
37 #ifdef HAVE_DMX_CONFIG_H
38 #include <dmx-config.h>
39 #endif
40
41 #include "dmx.h"
42 #include "dmxcb.h"
43 #include "dmxinput.h"
44 #include "dmxlog.h"
45
46 extern int     connBlockScreenStart;
47
48 #ifdef PANORAMIX
49 extern int     PanoramiXPixWidth;
50 extern int     PanoramiXPixHeight;
51 extern int     PanoramiXNumScreens;
52 #endif
53
54        int     dmxGlobalWidth, dmxGlobalHeight;
55
56 /** We may want the wall dimensions to be different from the bounding
57  * box dimensions that Xinerama computes, so save those and update them
58  * here.
59  */
60 void dmxSetWidthHeight(int width, int height)
61 {
62     dmxGlobalWidth  = width;
63     dmxGlobalHeight = height;
64 }
65
66 /** Computes the global bounding box for DMX.  This may be larger than
67  * the one computed by Xinerama because of the DMX configuration
68  * file. */
69 void dmxComputeWidthHeight(DMXRecomputeFlag flag)
70 {
71     int           i;
72     DMXScreenInfo *dmxScreen;
73     int           w = 0;
74     int           h = 0;
75     
76     for (i = 0; i < dmxNumScreens; i++) {
77                                 /* Don't use root* here because this is
78                                  * the global bounding box. */
79         dmxScreen = &dmxScreens[i];
80         if (w < dmxScreen->scrnWidth + dmxScreen->rootXOrigin)
81             w = dmxScreen->scrnWidth + dmxScreen->rootXOrigin;
82         if (h < dmxScreen->scrnHeight + dmxScreen->rootYOrigin)
83             h = dmxScreen->scrnHeight + dmxScreen->rootYOrigin;
84     }
85     if (!dmxGlobalWidth && !dmxGlobalHeight) {
86         dmxLog(dmxInfo, "Using %dx%d as global bounding box\n", w, h);
87     } else {
88         switch (flag) {
89         case DMX_NO_RECOMPUTE_BOUNDING_BOX:
90             dmxLog(dmxInfo,
91                    "Using old bounding box (%dx%d) instead of new (%dx%d)\n",
92                    dmxGlobalWidth, dmxGlobalHeight, w, h);
93             w = dmxGlobalWidth;
94             h = dmxGlobalHeight;
95             break;
96         case DMX_RECOMPUTE_BOUNDING_BOX:
97             dmxLog(dmxInfo,
98                    "Using %dx%d as global bounding box, instead of %dx%d\n",
99                    w, h, dmxGlobalWidth, dmxGlobalHeight);
100             break;
101         }
102     }
103         
104     dmxGlobalWidth  = w;
105     dmxGlobalHeight = h;
106 }
107
108 /** A callback routine that hooks into Xinerama and provides a
109  * convenient place to print summary log information during server
110  * startup.  This routine does not modify any values. */
111 void dmxConnectionBlockCallback(void)
112 {
113     xWindowRoot *root   = (xWindowRoot *)(ConnectionInfo+connBlockScreenStart);
114     int         offset  = connBlockScreenStart + sizeof(xWindowRoot);
115     int         i;
116     Bool        *found  = NULL;
117
118     MAXSCREENSALLOC(found);
119     if (!found)
120         dmxLog(dmxFatal, "dmxConnectionBlockCallback: out of memory\n");
121
122     dmxLog(dmxInfo, "===== Start of Summary =====\n");
123 #ifdef PANORAMIX
124     if (!noPanoramiXExtension) {
125         if (dmxGlobalWidth && dmxGlobalHeight
126             && (dmxGlobalWidth != PanoramiXPixWidth
127                 || dmxGlobalHeight != PanoramiXPixHeight)) {
128             dmxLog(dmxInfo,
129                    "Changing Xinerama dimensions from %d %d to %d %d\n",
130                    PanoramiXPixWidth, PanoramiXPixHeight,
131                    dmxGlobalWidth, dmxGlobalHeight);
132             PanoramiXPixWidth  = root->pixWidth  = dmxGlobalWidth;
133             PanoramiXPixHeight = root->pixHeight = dmxGlobalHeight;
134         } else {
135             dmxGlobalWidth  = PanoramiXPixWidth;
136             dmxGlobalHeight = PanoramiXPixHeight;
137         }
138         dmxLog(dmxInfo, "%d screens configured with Xinerama (%d %d)\n",
139                PanoramiXNumScreens, PanoramiXPixWidth, PanoramiXPixHeight);
140         for (i = 0; i < PanoramiXNumScreens; i++) found[i] = FALSE;
141     } else {
142 #endif
143                                 /* This never happens because we're
144                                  * either called from a Xinerama
145                                  * callback or during reconfiguration
146                                  * (which only works with Xinerama on).
147                                  * In any case, be reasonable. */
148         dmxLog(dmxInfo, "%d screens configured (%d %d)\n",
149                screenInfo.numScreens, root->pixWidth, root->pixHeight);
150 #ifdef PANORAMIX
151     }
152 #endif
153
154     for (i = 0; i < root->nDepths; i++) {
155         xDepth      *depth  = (xDepth *)(ConnectionInfo + offset);
156         int         voffset = offset + sizeof(xDepth);
157         xVisualType *visual = (xVisualType *)(ConnectionInfo + voffset);
158         int         j;
159         
160         dmxLog(dmxInfo, "%d visuals at depth %d:\n",
161                depth->nVisuals, depth->depth);
162         for (j = 0; j < depth->nVisuals; j++, visual++) {
163             XVisualInfo vi;
164             
165             vi.visual        = NULL;
166             vi.visualid      = visual->visualID;
167             vi.screen        = 0;
168             vi.depth         = depth->depth;
169             vi.class         = visual->class;
170             vi.red_mask      = visual->redMask;
171             vi.green_mask    = visual->greenMask;
172             vi.blue_mask     = visual->blueMask;
173             vi.colormap_size = visual->colormapEntries;
174             vi.bits_per_rgb  = visual->bitsPerRGB;
175             dmxLogVisual(NULL, &vi, 0);
176
177 #ifdef PANORAMIX
178             if (!noPanoramiXExtension) {
179                 int  k;
180                 for (k = 0; k < PanoramiXNumScreens; k++) {
181                     DMXScreenInfo *dmxScreen = &dmxScreens[k];
182
183                     if (dmxScreen->beDisplay) {
184                         XVisualInfo *pvi =
185                             &dmxScreen->beVisuals[dmxScreen->beDefVisualIndex];
186                         if (pvi->depth == depth->depth &&
187                             pvi->class == visual->class)
188                             found[k] = TRUE;
189                     } else {
190                         /* Screen #k is detatched, so it always succeeds */
191                         found[k] = TRUE;
192                     }
193                 }
194             }
195 #endif
196         }
197         offset = voffset + depth->nVisuals * sizeof(xVisualType);
198     }
199
200     dmxInputLogDevices();
201     dmxLog(dmxInfo, "===== End of Summary =====\n");
202
203 #ifdef PANORAMIX
204     if (!noPanoramiXExtension) {
205         Bool fatal = FALSE;
206         for (i = 0; i < PanoramiXNumScreens; i++) {
207             fatal |= !found[i];
208             if (!found[i]) {
209                 dmxLog(dmxError,
210                        "The default visual for screen #%d does not match "
211                        "any of the\n", i);
212                 dmxLog(dmxError,
213                        "consolidated visuals from Xinerama (listed above)\n");
214             }
215         }
216         if (fatal)
217             dmxLog(dmxFatal,
218                    "dmxConnectionBlockCallback: invalid screen(s) found");
219     }
220 #endif
221     MAXSCREENSFREE(found);
222 }