miscrinit.c revision f7df2e56
105b261ecSmrg/*
205b261ecSmrg
305b261ecSmrgCopyright 1990, 1998  The Open Group
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that
705b261ecSmrgthe above copyright notice appear in all copies and that both that
805b261ecSmrgcopyright notice and this permission notice appear in supporting
905b261ecSmrgdocumentation.
1005b261ecSmrg
1105b261ecSmrgThe above copyright notice and this permission notice shall be included
1205b261ecSmrgin all copies or substantial portions of the Software.
1305b261ecSmrg
1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1505b261ecSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1605b261ecSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1705b261ecSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
1805b261ecSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1905b261ecSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2005b261ecSmrgOTHER DEALINGS IN THE SOFTWARE.
2105b261ecSmrg
2205b261ecSmrgExcept as contained in this notice, the name of The Open Group shall
2305b261ecSmrgnot be used in advertising or otherwise to promote the sale, use or
2405b261ecSmrgother dealings in this Software without prior written authorization
2505b261ecSmrgfrom The Open Group.
2605b261ecSmrg
2705b261ecSmrg*/
2805b261ecSmrg
2905b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
3005b261ecSmrg#include <dix-config.h>
3105b261ecSmrg#endif
3205b261ecSmrg
3305b261ecSmrg#include <X11/X.h>
3405b261ecSmrg#include "servermd.h"
3505b261ecSmrg#include "misc.h"
3605b261ecSmrg#include "mi.h"
3705b261ecSmrg#include "scrnintstr.h"
3805b261ecSmrg#include "pixmapstr.h"
3905b261ecSmrg#include "dix.h"
4005b261ecSmrg#include "miline.h"
4105b261ecSmrg#ifdef MITSHM
424202a189Smrg#include <X11/extensions/shm.h>
434202a189Smrg#include "shmint.h"
4405b261ecSmrg#endif
4505b261ecSmrg
4605b261ecSmrg/* We use this structure to propogate some information from miScreenInit to
4705b261ecSmrg * miCreateScreenResources.  miScreenInit allocates the structure, fills it
48f7df2e56Smrg * in, and puts it into pScreen->devPrivate.  miCreateScreenResources
4905b261ecSmrg * extracts the info and frees the structure.  We could've accomplished the
5005b261ecSmrg * same thing by adding fields to the screen structure, but they would have
5105b261ecSmrg * ended up being redundant, and would have exposed this mi implementation
5205b261ecSmrg * detail to the whole server.
5305b261ecSmrg */
5405b261ecSmrg
55f7df2e56Smrgtypedef struct {
56f7df2e56Smrg    void *pbits;                /* pointer to framebuffer */
57f7df2e56Smrg    int width;                  /* delta to add to a framebuffer addr to move one row down */
5805b261ecSmrg} miScreenInitParmsRec, *miScreenInitParmsPtr;
5905b261ecSmrg
6005b261ecSmrg/* this plugs into pScreen->ModifyPixmapHeader */
614202a189SmrgBool
624642e01fSmrgmiModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth,
63f7df2e56Smrg                     int bitsPerPixel, int devKind, void *pPixData)
6405b261ecSmrg{
6505b261ecSmrg    if (!pPixmap)
66f7df2e56Smrg        return FALSE;
6705b261ecSmrg
6805b261ecSmrg    /*
6905b261ecSmrg     * If all arguments are specified, reinitialize everything (including
7005b261ecSmrg     * validated state).
7105b261ecSmrg     */
7205b261ecSmrg    if ((width > 0) && (height > 0) && (depth > 0) && (bitsPerPixel > 0) &&
73f7df2e56Smrg        (devKind > 0) && pPixData) {
74f7df2e56Smrg        pPixmap->drawable.depth = depth;
75f7df2e56Smrg        pPixmap->drawable.bitsPerPixel = bitsPerPixel;
76f7df2e56Smrg        pPixmap->drawable.id = 0;
77f7df2e56Smrg        pPixmap->drawable.x = 0;
78f7df2e56Smrg        pPixmap->drawable.y = 0;
79f7df2e56Smrg        pPixmap->drawable.width = width;
80f7df2e56Smrg        pPixmap->drawable.height = height;
81f7df2e56Smrg        pPixmap->devKind = devKind;
82f7df2e56Smrg        pPixmap->refcnt = 1;
83f7df2e56Smrg        pPixmap->devPrivate.ptr = pPixData;
84f7df2e56Smrg    }
85f7df2e56Smrg    else {
86f7df2e56Smrg        /*
87f7df2e56Smrg         * Only modify specified fields, keeping all others intact.
88f7df2e56Smrg         */
89f7df2e56Smrg
90f7df2e56Smrg        if (width > 0)
91f7df2e56Smrg            pPixmap->drawable.width = width;
92f7df2e56Smrg
93f7df2e56Smrg        if (height > 0)
94f7df2e56Smrg            pPixmap->drawable.height = height;
95f7df2e56Smrg
96f7df2e56Smrg        if (depth > 0)
97f7df2e56Smrg            pPixmap->drawable.depth = depth;
98f7df2e56Smrg
99f7df2e56Smrg        if (bitsPerPixel > 0)
100f7df2e56Smrg            pPixmap->drawable.bitsPerPixel = bitsPerPixel;
101f7df2e56Smrg        else if ((bitsPerPixel < 0) && (depth > 0))
102f7df2e56Smrg            pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth);
103f7df2e56Smrg
104f7df2e56Smrg        /*
105f7df2e56Smrg         * CAVEAT:  Non-SI DDXen may use devKind and devPrivate fields for
106f7df2e56Smrg         *          other purposes.
107f7df2e56Smrg         */
108f7df2e56Smrg        if (devKind > 0)
109f7df2e56Smrg            pPixmap->devKind = devKind;
110f7df2e56Smrg        else if ((devKind < 0) && ((width > 0) || (depth > 0)))
111f7df2e56Smrg            pPixmap->devKind = PixmapBytePad(pPixmap->drawable.width,
112f7df2e56Smrg                                             pPixmap->drawable.depth);
113f7df2e56Smrg
114f7df2e56Smrg        if (pPixData)
115f7df2e56Smrg            pPixmap->devPrivate.ptr = pPixData;
11605b261ecSmrg    }
1174202a189Smrg    pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
11805b261ecSmrg    return TRUE;
11905b261ecSmrg}
12005b261ecSmrg
12105b261ecSmrgstatic Bool
122f7df2e56SmrgmiCloseScreen(ScreenPtr pScreen)
12305b261ecSmrg{
124f7df2e56Smrg    return ((*pScreen->DestroyPixmap) ((PixmapPtr) pScreen->devPrivate));
12505b261ecSmrg}
12605b261ecSmrg
12705b261ecSmrg/* With the introduction of pixmap privates, the "screen pixmap" can no
12805b261ecSmrg * longer be created in miScreenInit, since all the modules that could
12905b261ecSmrg * possibly ask for pixmap private space have not been initialized at
13005b261ecSmrg * that time.  pScreen->CreateScreenResources is called after all
13105b261ecSmrg * possible private-requesting modules have been inited; we create the
13205b261ecSmrg * screen pixmap here.
13305b261ecSmrg */
1344202a189SmrgBool
1354642e01fSmrgmiCreateScreenResources(ScreenPtr pScreen)
13605b261ecSmrg{
13705b261ecSmrg    miScreenInitParmsPtr pScrInitParms;
138f7df2e56Smrg    void *value;
13905b261ecSmrg
140f7df2e56Smrg    pScrInitParms = (miScreenInitParmsPtr) pScreen->devPrivate;
14105b261ecSmrg
14205b261ecSmrg    /* if width is non-zero, pScreen->devPrivate will be a pixmap
14305b261ecSmrg     * else it will just take the value pbits
14405b261ecSmrg     */
145f7df2e56Smrg    if (pScrInitParms->width) {
146f7df2e56Smrg        PixmapPtr pPixmap;
147f7df2e56Smrg
148f7df2e56Smrg        /* create a pixmap with no data, then redirect it to point to
149f7df2e56Smrg         * the screen
150f7df2e56Smrg         */
151f7df2e56Smrg        pPixmap =
152f7df2e56Smrg            (*pScreen->CreatePixmap) (pScreen, 0, 0, pScreen->rootDepth, 0);
153f7df2e56Smrg        if (!pPixmap)
154f7df2e56Smrg            return FALSE;
155f7df2e56Smrg
156f7df2e56Smrg        if (!(*pScreen->ModifyPixmapHeader) (pPixmap, pScreen->width,
157f7df2e56Smrg                                             pScreen->height,
158f7df2e56Smrg                                             pScreen->rootDepth,
159f7df2e56Smrg                                             BitsPerPixel(pScreen->rootDepth),
160f7df2e56Smrg                                             PixmapBytePad(pScrInitParms->width,
161f7df2e56Smrg                                                           pScreen->rootDepth),
162f7df2e56Smrg                                             pScrInitParms->pbits))
163f7df2e56Smrg            return FALSE;
164f7df2e56Smrg        value = (void *) pPixmap;
16505b261ecSmrg    }
166f7df2e56Smrg    else {
167f7df2e56Smrg        value = pScrInitParms->pbits;
16805b261ecSmrg    }
169f7df2e56Smrg    free(pScreen->devPrivate);  /* freeing miScreenInitParmsRec */
170f7df2e56Smrg    pScreen->devPrivate = value;        /* pPixmap or pbits */
17105b261ecSmrg    return TRUE;
17205b261ecSmrg}
17305b261ecSmrg
17405b261ecSmrgBool
175f7df2e56SmrgmiScreenDevPrivateInit(ScreenPtr pScreen, int width, void *pbits)
17605b261ecSmrg{
17705b261ecSmrg    miScreenInitParmsPtr pScrInitParms;
17805b261ecSmrg
17905b261ecSmrg    /* Stash pbits and width in a short-lived miScreenInitParmsRec attached
18005b261ecSmrg     * to the screen, until CreateScreenResources can put them in the
18105b261ecSmrg     * screen pixmap.
18205b261ecSmrg     */
1834202a189Smrg    pScrInitParms = malloc(sizeof(miScreenInitParmsRec));
18405b261ecSmrg    if (!pScrInitParms)
185f7df2e56Smrg        return FALSE;
18605b261ecSmrg    pScrInitParms->pbits = pbits;
18705b261ecSmrg    pScrInitParms->width = width;
188f7df2e56Smrg    pScreen->devPrivate = (void *) pScrInitParms;
18905b261ecSmrg    return TRUE;
19005b261ecSmrg}
19105b261ecSmrg
1924642e01fSmrgstatic PixmapPtr
1934642e01fSmrgmiGetScreenPixmap(ScreenPtr pScreen)
1944642e01fSmrg{
195f7df2e56Smrg    return (PixmapPtr) (pScreen->devPrivate);
1964642e01fSmrg}
1974642e01fSmrg
1984642e01fSmrgstatic void
1994642e01fSmrgmiSetScreenPixmap(PixmapPtr pPix)
2004642e01fSmrg{
2014642e01fSmrg    if (pPix)
202f7df2e56Smrg        pPix->drawable.pScreen->devPrivate = (void *) pPix;
2034642e01fSmrg}
2044642e01fSmrg
2054202a189SmrgBool
206f7df2e56SmrgmiScreenInit(ScreenPtr pScreen, void *pbits,  /* pointer to screen bits */
207f7df2e56Smrg             int xsize, int ysize,      /* in pixels */
208f7df2e56Smrg             int dpix, int dpiy,        /* dots per inch */
209f7df2e56Smrg             int width,         /* pixel width of frame buffer */
210f7df2e56Smrg             int rootDepth,     /* depth of root window */
211f7df2e56Smrg             int numDepths,     /* number of depths supported */
212f7df2e56Smrg             DepthRec * depths, /* supported depths */
213f7df2e56Smrg             VisualID rootVisual,       /* root visual */
214f7df2e56Smrg             int numVisuals,    /* number of visuals supported */
215f7df2e56Smrg             VisualRec * visuals        /* supported visuals */
2164642e01fSmrg    )
21705b261ecSmrg{
21805b261ecSmrg    pScreen->width = xsize;
21905b261ecSmrg    pScreen->height = ysize;
22005b261ecSmrg    pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10);
22105b261ecSmrg    pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10);
22205b261ecSmrg    pScreen->numDepths = numDepths;
22305b261ecSmrg    pScreen->rootDepth = rootDepth;
22405b261ecSmrg    pScreen->allowedDepths = depths;
22505b261ecSmrg    pScreen->rootVisual = rootVisual;
22605b261ecSmrg    /* defColormap */
22705b261ecSmrg    pScreen->minInstalledCmaps = 1;
22805b261ecSmrg    pScreen->maxInstalledCmaps = 1;
22905b261ecSmrg    pScreen->backingStoreSupport = NotUseful;
23005b261ecSmrg    pScreen->saveUnderSupport = NotUseful;
23105b261ecSmrg    /* whitePixel, blackPixel */
23205b261ecSmrg    pScreen->ModifyPixmapHeader = miModifyPixmapHeader;
23305b261ecSmrg    pScreen->CreateScreenResources = miCreateScreenResources;
23405b261ecSmrg    pScreen->GetScreenPixmap = miGetScreenPixmap;
23505b261ecSmrg    pScreen->SetScreenPixmap = miSetScreenPixmap;
23605b261ecSmrg    pScreen->numVisuals = numVisuals;
23705b261ecSmrg    pScreen->visuals = visuals;
238f7df2e56Smrg    if (width) {
23905b261ecSmrg#ifdef MITSHM
240f7df2e56Smrg        ShmRegisterFbFuncs(pScreen);
24105b261ecSmrg#endif
242f7df2e56Smrg        pScreen->CloseScreen = miCloseScreen;
24305b261ecSmrg    }
24405b261ecSmrg    /* else CloseScreen */
24505b261ecSmrg    /* QueryBestSize, SaveScreen, GetImage, GetSpans */
24605b261ecSmrg    pScreen->SourceValidate = (SourceValidateProcPtr) 0;
24705b261ecSmrg    /* CreateWindow, DestroyWindow, PositionWindow, ChangeWindowAttributes */
24805b261ecSmrg    /* RealizeWindow, UnrealizeWindow */
24905b261ecSmrg    pScreen->ValidateTree = miValidateTree;
25005b261ecSmrg    pScreen->PostValidateTree = (PostValidateTreeProcPtr) 0;
25105b261ecSmrg    pScreen->WindowExposures = miWindowExposures;
2524642e01fSmrg    /* CopyWindow */
25305b261ecSmrg    pScreen->ClearToBackground = miClearToBackground;
25405b261ecSmrg    pScreen->ClipNotify = (ClipNotifyProcPtr) 0;
25505b261ecSmrg    pScreen->RestackWindow = (RestackWindowProcPtr) 0;
256f7df2e56Smrg    pScreen->PaintWindow = miPaintWindow;
25705b261ecSmrg    /* CreatePixmap, DestroyPixmap */
25805b261ecSmrg    /* RealizeFont, UnrealizeFont */
25905b261ecSmrg    /* CreateGC */
26005b261ecSmrg    /* CreateColormap, DestroyColormap, InstallColormap, UninstallColormap */
26105b261ecSmrg    /* ListInstalledColormaps, StoreColors, ResolveColor */
26205b261ecSmrg    /* BitmapToRegion */
263f7df2e56Smrg    pScreen->BlockHandler = (ScreenBlockHandlerProcPtr) NoopDDA;
264f7df2e56Smrg    pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr) NoopDDA;
26505b261ecSmrg    pScreen->MarkWindow = miMarkWindow;
26605b261ecSmrg    pScreen->MarkOverlappedWindows = miMarkOverlappedWindows;
26705b261ecSmrg    pScreen->MoveWindow = miMoveWindow;
268f7df2e56Smrg    pScreen->ResizeWindow = miResizeWindow;
26905b261ecSmrg    pScreen->GetLayerWindow = miGetLayerWindow;
27005b261ecSmrg    pScreen->HandleExposures = miHandleValidateExposures;
27105b261ecSmrg    pScreen->ReparentWindow = (ReparentWindowProcPtr) 0;
27205b261ecSmrg    pScreen->ChangeBorderWidth = miChangeBorderWidth;
27305b261ecSmrg    pScreen->SetShape = miSetShape;
27405b261ecSmrg    pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
275f7df2e56Smrg    pScreen->XYToWindow = miXYToWindow;
27605b261ecSmrg
27705b261ecSmrg    miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);
27805b261ecSmrg
27905b261ecSmrg    return miScreenDevPrivateInit(pScreen, width, pbits);
28005b261ecSmrg}
28105b261ecSmrg
2824202a189SmrgDevPrivateKeyRec miZeroLineScreenKeyRec;
28305b261ecSmrg
2844202a189Smrgvoid
2854642e01fSmrgmiSetZeroLineBias(ScreenPtr pScreen, unsigned int bias)
28605b261ecSmrg{
2874202a189Smrg    if (!dixRegisterPrivateKey(&miZeroLineScreenKeyRec, PRIVATE_SCREEN, 0))
288f7df2e56Smrg        return;
2894202a189Smrg
290f7df2e56Smrg    dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey,
291f7df2e56Smrg                  (unsigned long *) (unsigned long) bias);
29205b261ecSmrg}
293