xref: /OK3568_Linux_fs/external/xserver/composite/compinit.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun  * Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*4882a593Smuzhiyun  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*4882a593Smuzhiyun  * DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * Copyright © 2003 Keith Packard
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Permission to use, copy, modify, distribute, and sell this software and its
26*4882a593Smuzhiyun  * documentation for any purpose is hereby granted without fee, provided that
27*4882a593Smuzhiyun  * the above copyright notice appear in all copies and that both that
28*4882a593Smuzhiyun  * copyright notice and this permission notice appear in supporting
29*4882a593Smuzhiyun  * documentation, and that the name of Keith Packard not be used in
30*4882a593Smuzhiyun  * advertising or publicity pertaining to distribution of the software without
31*4882a593Smuzhiyun  * specific, written prior permission.  Keith Packard makes no
32*4882a593Smuzhiyun  * representations about the suitability of this software for any purpose.  It
33*4882a593Smuzhiyun  * is provided "as is" without express or implied warranty.
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
36*4882a593Smuzhiyun  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
37*4882a593Smuzhiyun  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
38*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
39*4882a593Smuzhiyun  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
40*4882a593Smuzhiyun  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41*4882a593Smuzhiyun  * PERFORMANCE OF THIS SOFTWARE.
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
45*4882a593Smuzhiyun #include <dix-config.h>
46*4882a593Smuzhiyun #endif
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #include "compint.h"
49*4882a593Smuzhiyun #include "compositeext.h"
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun DevPrivateKeyRec CompScreenPrivateKeyRec;
52*4882a593Smuzhiyun DevPrivateKeyRec CompWindowPrivateKeyRec;
53*4882a593Smuzhiyun DevPrivateKeyRec CompSubwindowsPrivateKeyRec;
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun static Bool
compCloseScreen(ScreenPtr pScreen)56*4882a593Smuzhiyun compCloseScreen(ScreenPtr pScreen)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
59*4882a593Smuzhiyun     Bool ret;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun     free(cs->alternateVisuals);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun     pScreen->CloseScreen = cs->CloseScreen;
64*4882a593Smuzhiyun     pScreen->InstallColormap = cs->InstallColormap;
65*4882a593Smuzhiyun     pScreen->ChangeWindowAttributes = cs->ChangeWindowAttributes;
66*4882a593Smuzhiyun     pScreen->ReparentWindow = cs->ReparentWindow;
67*4882a593Smuzhiyun     pScreen->ConfigNotify = cs->ConfigNotify;
68*4882a593Smuzhiyun     pScreen->MoveWindow = cs->MoveWindow;
69*4882a593Smuzhiyun     pScreen->ResizeWindow = cs->ResizeWindow;
70*4882a593Smuzhiyun     pScreen->ChangeBorderWidth = cs->ChangeBorderWidth;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun     pScreen->ClipNotify = cs->ClipNotify;
73*4882a593Smuzhiyun     pScreen->UnrealizeWindow = cs->UnrealizeWindow;
74*4882a593Smuzhiyun     pScreen->RealizeWindow = cs->RealizeWindow;
75*4882a593Smuzhiyun     pScreen->DestroyWindow = cs->DestroyWindow;
76*4882a593Smuzhiyun     pScreen->CreateWindow = cs->CreateWindow;
77*4882a593Smuzhiyun     pScreen->CopyWindow = cs->CopyWindow;
78*4882a593Smuzhiyun     pScreen->PositionWindow = cs->PositionWindow;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun     pScreen->GetImage = cs->GetImage;
81*4882a593Smuzhiyun     pScreen->GetSpans = cs->GetSpans;
82*4882a593Smuzhiyun     pScreen->SourceValidate = cs->SourceValidate;
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun     free(cs);
85*4882a593Smuzhiyun     dixSetPrivate(&pScreen->devPrivates, CompScreenPrivateKey, NULL);
86*4882a593Smuzhiyun     ret = (*pScreen->CloseScreen) (pScreen);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun     return ret;
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun static void
compInstallColormap(ColormapPtr pColormap)92*4882a593Smuzhiyun compInstallColormap(ColormapPtr pColormap)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun     VisualPtr pVisual = pColormap->pVisual;
95*4882a593Smuzhiyun     ScreenPtr pScreen = pColormap->pScreen;
96*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
97*4882a593Smuzhiyun     int a;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun     for (a = 0; a < cs->numAlternateVisuals; a++)
100*4882a593Smuzhiyun         if (pVisual->vid == cs->alternateVisuals[a])
101*4882a593Smuzhiyun             return;
102*4882a593Smuzhiyun     pScreen->InstallColormap = cs->InstallColormap;
103*4882a593Smuzhiyun     (*pScreen->InstallColormap) (pColormap);
104*4882a593Smuzhiyun     cs->InstallColormap = pScreen->InstallColormap;
105*4882a593Smuzhiyun     pScreen->InstallColormap = compInstallColormap;
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun static void
compCheckBackingStore(WindowPtr pWin)109*4882a593Smuzhiyun compCheckBackingStore(WindowPtr pWin)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun     if (pWin->backingStore != NotUseful && !pWin->backStorage) {
112*4882a593Smuzhiyun         compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
113*4882a593Smuzhiyun         pWin->backStorage = TRUE;
114*4882a593Smuzhiyun     }
115*4882a593Smuzhiyun     else if (pWin->backingStore == NotUseful && pWin->backStorage) {
116*4882a593Smuzhiyun         compUnredirectWindow(serverClient, pWin,
117*4882a593Smuzhiyun                              CompositeRedirectAutomatic);
118*4882a593Smuzhiyun         pWin->backStorage = FALSE;
119*4882a593Smuzhiyun     }
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /* Fake backing store via automatic redirection */
123*4882a593Smuzhiyun static Bool
compChangeWindowAttributes(WindowPtr pWin,unsigned long mask)124*4882a593Smuzhiyun compChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun     ScreenPtr pScreen = pWin->drawable.pScreen;
127*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
128*4882a593Smuzhiyun     Bool ret;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun     pScreen->ChangeWindowAttributes = cs->ChangeWindowAttributes;
131*4882a593Smuzhiyun     ret = pScreen->ChangeWindowAttributes(pWin, mask);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun     if (ret && (mask & CWBackingStore) &&
134*4882a593Smuzhiyun         pScreen->backingStoreSupport != NotUseful)
135*4882a593Smuzhiyun         compCheckBackingStore(pWin);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun     pScreen->ChangeWindowAttributes = compChangeWindowAttributes;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun     return ret;
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun static void
compGetImage(DrawablePtr pDrawable,int sx,int sy,int w,int h,unsigned int format,unsigned long planemask,char * pdstLine)143*4882a593Smuzhiyun compGetImage(DrawablePtr pDrawable,
144*4882a593Smuzhiyun              int sx, int sy,
145*4882a593Smuzhiyun              int w, int h,
146*4882a593Smuzhiyun              unsigned int format, unsigned long planemask, char *pdstLine)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun     ScreenPtr pScreen = pDrawable->pScreen;
149*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun     pScreen->GetImage = cs->GetImage;
152*4882a593Smuzhiyun     if (pDrawable->type == DRAWABLE_WINDOW)
153*4882a593Smuzhiyun         compPaintChildrenToWindow((WindowPtr) pDrawable);
154*4882a593Smuzhiyun     (*pScreen->GetImage) (pDrawable, sx, sy, w, h, format, planemask, pdstLine);
155*4882a593Smuzhiyun     cs->GetImage = pScreen->GetImage;
156*4882a593Smuzhiyun     pScreen->GetImage = compGetImage;
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun static void
compGetSpans(DrawablePtr pDrawable,int wMax,DDXPointPtr ppt,int * pwidth,int nspans,char * pdstStart)160*4882a593Smuzhiyun compGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt, int *pwidth,
161*4882a593Smuzhiyun              int nspans, char *pdstStart)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun     ScreenPtr pScreen = pDrawable->pScreen;
164*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun     pScreen->GetSpans = cs->GetSpans;
167*4882a593Smuzhiyun     if (pDrawable->type == DRAWABLE_WINDOW)
168*4882a593Smuzhiyun         compPaintChildrenToWindow((WindowPtr) pDrawable);
169*4882a593Smuzhiyun     (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
170*4882a593Smuzhiyun     cs->GetSpans = pScreen->GetSpans;
171*4882a593Smuzhiyun     pScreen->GetSpans = compGetSpans;
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun static void
compSourceValidate(DrawablePtr pDrawable,int x,int y,int width,int height,unsigned int subWindowMode)175*4882a593Smuzhiyun compSourceValidate(DrawablePtr pDrawable,
176*4882a593Smuzhiyun                    int x, int y,
177*4882a593Smuzhiyun                    int width, int height, unsigned int subWindowMode)
178*4882a593Smuzhiyun {
179*4882a593Smuzhiyun     ScreenPtr pScreen = pDrawable->pScreen;
180*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun     pScreen->SourceValidate = cs->SourceValidate;
183*4882a593Smuzhiyun     if (pDrawable->type == DRAWABLE_WINDOW && subWindowMode == IncludeInferiors)
184*4882a593Smuzhiyun         compPaintChildrenToWindow((WindowPtr) pDrawable);
185*4882a593Smuzhiyun     if (pScreen->SourceValidate)
186*4882a593Smuzhiyun         (*pScreen->SourceValidate) (pDrawable, x, y, width, height,
187*4882a593Smuzhiyun                                     subWindowMode);
188*4882a593Smuzhiyun     cs->SourceValidate = pScreen->SourceValidate;
189*4882a593Smuzhiyun     pScreen->SourceValidate = compSourceValidate;
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun /*
193*4882a593Smuzhiyun  * Add alternate visuals -- always expose an ARGB32 and RGB24 visual
194*4882a593Smuzhiyun  */
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun static DepthPtr
compFindVisuallessDepth(ScreenPtr pScreen,int d)197*4882a593Smuzhiyun compFindVisuallessDepth(ScreenPtr pScreen, int d)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun     int i;
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun     for (i = 0; i < pScreen->numDepths; i++) {
202*4882a593Smuzhiyun         DepthPtr depth = &pScreen->allowedDepths[i];
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun         if (depth->depth == d) {
205*4882a593Smuzhiyun             /*
206*4882a593Smuzhiyun              * Make sure it doesn't have visuals already
207*4882a593Smuzhiyun              */
208*4882a593Smuzhiyun             if (depth->numVids)
209*4882a593Smuzhiyun                 return 0;
210*4882a593Smuzhiyun             /*
211*4882a593Smuzhiyun              * looks fine
212*4882a593Smuzhiyun              */
213*4882a593Smuzhiyun             return depth;
214*4882a593Smuzhiyun         }
215*4882a593Smuzhiyun     }
216*4882a593Smuzhiyun     /*
217*4882a593Smuzhiyun      * If there isn't one, then it's gonna be hard to have
218*4882a593Smuzhiyun      * an associated visual
219*4882a593Smuzhiyun      */
220*4882a593Smuzhiyun     return 0;
221*4882a593Smuzhiyun }
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun /*
224*4882a593Smuzhiyun  * Add a list of visual IDs to the list of visuals to implicitly redirect.
225*4882a593Smuzhiyun  */
226*4882a593Smuzhiyun static Bool
compRegisterAlternateVisuals(CompScreenPtr cs,VisualID * vids,int nVisuals)227*4882a593Smuzhiyun compRegisterAlternateVisuals(CompScreenPtr cs, VisualID * vids, int nVisuals)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun     VisualID *p;
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun     p = reallocarray(cs->alternateVisuals,
232*4882a593Smuzhiyun                      cs->numAlternateVisuals + nVisuals, sizeof(VisualID));
233*4882a593Smuzhiyun     if (p == NULL)
234*4882a593Smuzhiyun         return FALSE;
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun     memcpy(&p[cs->numAlternateVisuals], vids, sizeof(VisualID) * nVisuals);
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun     cs->alternateVisuals = p;
239*4882a593Smuzhiyun     cs->numAlternateVisuals += nVisuals;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun     return TRUE;
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun Bool
CompositeRegisterAlternateVisuals(ScreenPtr pScreen,VisualID * vids,int nVisuals)245*4882a593Smuzhiyun CompositeRegisterAlternateVisuals(ScreenPtr pScreen, VisualID * vids,
246*4882a593Smuzhiyun                                   int nVisuals)
247*4882a593Smuzhiyun {
248*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun     return compRegisterAlternateVisuals(cs, vids, nVisuals);
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun Bool
CompositeRegisterImplicitRedirectionException(ScreenPtr pScreen,VisualID parentVisual,VisualID winVisual)254*4882a593Smuzhiyun CompositeRegisterImplicitRedirectionException(ScreenPtr pScreen,
255*4882a593Smuzhiyun                                               VisualID parentVisual,
256*4882a593Smuzhiyun                                               VisualID winVisual)
257*4882a593Smuzhiyun {
258*4882a593Smuzhiyun     CompScreenPtr cs = GetCompScreen(pScreen);
259*4882a593Smuzhiyun     CompImplicitRedirectException *p;
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun     p = reallocarray(cs->implicitRedirectExceptions,
262*4882a593Smuzhiyun                      cs->numImplicitRedirectExceptions + 1, sizeof(p[0]));
263*4882a593Smuzhiyun     if (p == NULL)
264*4882a593Smuzhiyun         return FALSE;
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun     p[cs->numImplicitRedirectExceptions].parentVisual = parentVisual;
267*4882a593Smuzhiyun     p[cs->numImplicitRedirectExceptions].winVisual = winVisual;
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun     cs->implicitRedirectExceptions = p;
270*4882a593Smuzhiyun     cs->numImplicitRedirectExceptions++;
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun     return TRUE;
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun typedef struct _alternateVisual {
276*4882a593Smuzhiyun     int depth;
277*4882a593Smuzhiyun     CARD32 format;
278*4882a593Smuzhiyun } CompAlternateVisual;
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun static CompAlternateVisual altVisuals[] = {
281*4882a593Smuzhiyun #if COMP_INCLUDE_RGB24_VISUAL
282*4882a593Smuzhiyun     {24, PICT_r8g8b8},
283*4882a593Smuzhiyun #endif
284*4882a593Smuzhiyun     {32, PICT_a8r8g8b8},
285*4882a593Smuzhiyun };
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun static Bool
compAddAlternateVisual(ScreenPtr pScreen,CompScreenPtr cs,CompAlternateVisual * alt)288*4882a593Smuzhiyun compAddAlternateVisual(ScreenPtr pScreen, CompScreenPtr cs,
289*4882a593Smuzhiyun                        CompAlternateVisual * alt)
290*4882a593Smuzhiyun {
291*4882a593Smuzhiyun     VisualPtr visual;
292*4882a593Smuzhiyun     DepthPtr depth;
293*4882a593Smuzhiyun     PictFormatPtr pPictFormat;
294*4882a593Smuzhiyun     unsigned long alphaMask;
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun     /*
297*4882a593Smuzhiyun      * The ARGB32 visual is always available.  Other alternate depth visuals
298*4882a593Smuzhiyun      * are only provided if their depth is less than the root window depth.
299*4882a593Smuzhiyun      * There's no deep reason for this.
300*4882a593Smuzhiyun      */
301*4882a593Smuzhiyun     if (alt->depth >= pScreen->rootDepth && alt->depth != 32)
302*4882a593Smuzhiyun         return FALSE;
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun     depth = compFindVisuallessDepth(pScreen, alt->depth);
305*4882a593Smuzhiyun     if (!depth)
306*4882a593Smuzhiyun         /* alt->depth doesn't exist or already has alternate visuals. */
307*4882a593Smuzhiyun         return TRUE;
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun     pPictFormat = PictureMatchFormat(pScreen, alt->depth, alt->format);
310*4882a593Smuzhiyun     if (!pPictFormat)
311*4882a593Smuzhiyun         return FALSE;
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun     if (ResizeVisualArray(pScreen, 1, depth) == FALSE) {
314*4882a593Smuzhiyun         return FALSE;
315*4882a593Smuzhiyun     }
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun     visual = pScreen->visuals + (pScreen->numVisuals - 1);      /* the new one */
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun     /* Initialize the visual */
320*4882a593Smuzhiyun     visual->bitsPerRGBValue = 8;
321*4882a593Smuzhiyun     if (PICT_FORMAT_TYPE(alt->format) == PICT_TYPE_COLOR) {
322*4882a593Smuzhiyun         visual->class = PseudoColor;
323*4882a593Smuzhiyun         visual->nplanes = PICT_FORMAT_BPP(alt->format);
324*4882a593Smuzhiyun         visual->ColormapEntries = 1 << visual->nplanes;
325*4882a593Smuzhiyun     }
326*4882a593Smuzhiyun     else {
327*4882a593Smuzhiyun         DirectFormatRec *direct = &pPictFormat->direct;
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun         visual->class = TrueColor;
330*4882a593Smuzhiyun         visual->redMask = ((unsigned long) direct->redMask) << direct->red;
331*4882a593Smuzhiyun         visual->greenMask =
332*4882a593Smuzhiyun             ((unsigned long) direct->greenMask) << direct->green;
333*4882a593Smuzhiyun         visual->blueMask = ((unsigned long) direct->blueMask) << direct->blue;
334*4882a593Smuzhiyun         alphaMask = ((unsigned long) direct->alphaMask) << direct->alpha;
335*4882a593Smuzhiyun         visual->offsetRed = direct->red;
336*4882a593Smuzhiyun         visual->offsetGreen = direct->green;
337*4882a593Smuzhiyun         visual->offsetBlue = direct->blue;
338*4882a593Smuzhiyun         /*
339*4882a593Smuzhiyun          * Include A bits in this (unlike GLX which includes only RGB)
340*4882a593Smuzhiyun          * This lets DIX compute suitable masks for colormap allocations
341*4882a593Smuzhiyun          */
342*4882a593Smuzhiyun         visual->nplanes = Ones(visual->redMask |
343*4882a593Smuzhiyun                                visual->greenMask |
344*4882a593Smuzhiyun                                visual->blueMask | alphaMask);
345*4882a593Smuzhiyun         /* find widest component */
346*4882a593Smuzhiyun         visual->ColormapEntries = (1 << max(Ones(visual->redMask),
347*4882a593Smuzhiyun                                             max(Ones(visual->greenMask),
348*4882a593Smuzhiyun                                                 Ones(visual->blueMask))));
349*4882a593Smuzhiyun     }
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun     /* remember the visual ID to detect auto-update windows */
352*4882a593Smuzhiyun     compRegisterAlternateVisuals(cs, &visual->vid, 1);
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun     return TRUE;
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun static Bool
compAddAlternateVisuals(ScreenPtr pScreen,CompScreenPtr cs)358*4882a593Smuzhiyun compAddAlternateVisuals(ScreenPtr pScreen, CompScreenPtr cs)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun     int alt, ret = 0;
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun     for (alt = 0; alt < ARRAY_SIZE(altVisuals); alt++)
363*4882a593Smuzhiyun         ret |= compAddAlternateVisual(pScreen, cs, altVisuals + alt);
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun     return ! !ret;
366*4882a593Smuzhiyun }
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun Bool
compScreenInit(ScreenPtr pScreen)369*4882a593Smuzhiyun compScreenInit(ScreenPtr pScreen)
370*4882a593Smuzhiyun {
371*4882a593Smuzhiyun     CompScreenPtr cs;
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun     if (!dixRegisterPrivateKey(&CompScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
374*4882a593Smuzhiyun         return FALSE;
375*4882a593Smuzhiyun     if (!dixRegisterPrivateKey(&CompWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
376*4882a593Smuzhiyun         return FALSE;
377*4882a593Smuzhiyun     if (!dixRegisterPrivateKey(&CompSubwindowsPrivateKeyRec, PRIVATE_WINDOW, 0))
378*4882a593Smuzhiyun         return FALSE;
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun     if (GetCompScreen(pScreen))
381*4882a593Smuzhiyun         return TRUE;
382*4882a593Smuzhiyun     cs = (CompScreenPtr) malloc(sizeof(CompScreenRec));
383*4882a593Smuzhiyun     if (!cs)
384*4882a593Smuzhiyun         return FALSE;
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun     cs->overlayWid = FakeClientID(0);
387*4882a593Smuzhiyun     cs->pOverlayWin = NULL;
388*4882a593Smuzhiyun     cs->pOverlayClients = NULL;
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun     cs->pendingScreenUpdate = FALSE;
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun     cs->numAlternateVisuals = 0;
393*4882a593Smuzhiyun     cs->alternateVisuals = NULL;
394*4882a593Smuzhiyun     cs->numImplicitRedirectExceptions = 0;
395*4882a593Smuzhiyun     cs->implicitRedirectExceptions = NULL;
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun     if (!compAddAlternateVisuals(pScreen, cs)) {
398*4882a593Smuzhiyun         free(cs);
399*4882a593Smuzhiyun         return FALSE;
400*4882a593Smuzhiyun     }
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun     if (!disableBackingStore)
403*4882a593Smuzhiyun         pScreen->backingStoreSupport = WhenMapped;
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun     cs->PositionWindow = pScreen->PositionWindow;
406*4882a593Smuzhiyun     pScreen->PositionWindow = compPositionWindow;
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun     cs->CopyWindow = pScreen->CopyWindow;
409*4882a593Smuzhiyun     pScreen->CopyWindow = compCopyWindow;
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun     cs->CreateWindow = pScreen->CreateWindow;
412*4882a593Smuzhiyun     pScreen->CreateWindow = compCreateWindow;
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun     cs->DestroyWindow = pScreen->DestroyWindow;
415*4882a593Smuzhiyun     pScreen->DestroyWindow = compDestroyWindow;
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun     cs->RealizeWindow = pScreen->RealizeWindow;
418*4882a593Smuzhiyun     pScreen->RealizeWindow = compRealizeWindow;
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun     cs->UnrealizeWindow = pScreen->UnrealizeWindow;
421*4882a593Smuzhiyun     pScreen->UnrealizeWindow = compUnrealizeWindow;
422*4882a593Smuzhiyun 
423*4882a593Smuzhiyun     cs->ClipNotify = pScreen->ClipNotify;
424*4882a593Smuzhiyun     pScreen->ClipNotify = compClipNotify;
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun     cs->ConfigNotify = pScreen->ConfigNotify;
427*4882a593Smuzhiyun     pScreen->ConfigNotify = compConfigNotify;
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun     cs->MoveWindow = pScreen->MoveWindow;
430*4882a593Smuzhiyun     pScreen->MoveWindow = compMoveWindow;
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun     cs->ResizeWindow = pScreen->ResizeWindow;
433*4882a593Smuzhiyun     pScreen->ResizeWindow = compResizeWindow;
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun     cs->ChangeBorderWidth = pScreen->ChangeBorderWidth;
436*4882a593Smuzhiyun     pScreen->ChangeBorderWidth = compChangeBorderWidth;
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun     cs->ReparentWindow = pScreen->ReparentWindow;
439*4882a593Smuzhiyun     pScreen->ReparentWindow = compReparentWindow;
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun     cs->InstallColormap = pScreen->InstallColormap;
442*4882a593Smuzhiyun     pScreen->InstallColormap = compInstallColormap;
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun     cs->ChangeWindowAttributes = pScreen->ChangeWindowAttributes;
445*4882a593Smuzhiyun     pScreen->ChangeWindowAttributes = compChangeWindowAttributes;
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun     cs->CloseScreen = pScreen->CloseScreen;
448*4882a593Smuzhiyun     pScreen->CloseScreen = compCloseScreen;
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun     cs->GetImage = pScreen->GetImage;
451*4882a593Smuzhiyun     pScreen->GetImage = compGetImage;
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun     cs->GetSpans = pScreen->GetSpans;
454*4882a593Smuzhiyun     pScreen->GetSpans = compGetSpans;
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun     cs->SourceValidate = pScreen->SourceValidate;
457*4882a593Smuzhiyun     pScreen->SourceValidate = compSourceValidate;
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun     dixSetPrivate(&pScreen->devPrivates, CompScreenPrivateKey, cs);
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun     RegisterRealChildHeadProc(CompositeRealChildHead);
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun     return TRUE;
464*4882a593Smuzhiyun }
465