fbscreen.c revision 1b5d61b8
105b261ecSmrg/*
205b261ecSmrg * Copyright © 1998 Keith Packard
305b261ecSmrg *
405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
605b261ecSmrg * the above copyright notice appear in all copies and that both that
705b261ecSmrg * copyright notice and this permission notice appear in supporting
805b261ecSmrg * documentation, and that the name of Keith Packard not be used in
905b261ecSmrg * advertising or publicity pertaining to distribution of the software without
1005b261ecSmrg * specific, written prior permission.  Keith Packard makes no
1105b261ecSmrg * representations about the suitability of this software for any purpose.  It
1205b261ecSmrg * is provided "as is" without express or implied warranty.
1305b261ecSmrg *
1405b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1605b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE.
2105b261ecSmrg */
2205b261ecSmrg
2305b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
2405b261ecSmrg#include <dix-config.h>
2505b261ecSmrg#endif
2605b261ecSmrg
2705b261ecSmrg#include "fb.h"
2805b261ecSmrg
2905b261ecSmrgBool
3035c4bbdfSmrgfbCloseScreen(ScreenPtr pScreen)
3105b261ecSmrg{
3235c4bbdfSmrg    int d;
3335c4bbdfSmrg    DepthPtr depths = pScreen->allowedDepths;
3405b261ecSmrg
3535c4bbdfSmrg    fbDestroyGlyphCache();
3605b261ecSmrg    for (d = 0; d < pScreen->numDepths; d++)
3735c4bbdfSmrg        free(depths[d].vids);
386747b715Smrg    free(depths);
396747b715Smrg    free(pScreen->visuals);
4035c4bbdfSmrg    if (pScreen->devPrivate)
4135c4bbdfSmrg        FreePixmap((PixmapPtr)pScreen->devPrivate);
4205b261ecSmrg    return TRUE;
4305b261ecSmrg}
4405b261ecSmrg
4505b261ecSmrgBool
4605b261ecSmrgfbRealizeFont(ScreenPtr pScreen, FontPtr pFont)
4705b261ecSmrg{
486747b715Smrg    return TRUE;
4905b261ecSmrg}
5005b261ecSmrg
5105b261ecSmrgBool
5205b261ecSmrgfbUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
5305b261ecSmrg{
546747b715Smrg    return TRUE;
5505b261ecSmrg}
5605b261ecSmrg
5705b261ecSmrgvoid
5835c4bbdfSmrgfbQueryBestSize(int class,
5935c4bbdfSmrg                unsigned short *width, unsigned short *height,
6035c4bbdfSmrg                ScreenPtr pScreen)
6105b261ecSmrg{
6235c4bbdfSmrg    unsigned short w;
6335c4bbdfSmrg
6405b261ecSmrg    switch (class) {
6505b261ecSmrg    case CursorShape:
6635c4bbdfSmrg        if (*width > pScreen->width)
6735c4bbdfSmrg            *width = pScreen->width;
6835c4bbdfSmrg        if (*height > pScreen->height)
6935c4bbdfSmrg            *height = pScreen->height;
7035c4bbdfSmrg        break;
7105b261ecSmrg    case TileShape:
7205b261ecSmrg    case StippleShape:
7335c4bbdfSmrg        w = *width;
7435c4bbdfSmrg        if ((w & (w - 1)) && w < FB_UNIT) {
7535c4bbdfSmrg            for (w = 1; w < *width; w <<= 1);
7635c4bbdfSmrg            *width = w;
7735c4bbdfSmrg        }
7805b261ecSmrg    }
7905b261ecSmrg}
8005b261ecSmrg
8105b261ecSmrgPixmapPtr
8235c4bbdfSmrg_fbGetWindowPixmap(WindowPtr pWindow)
8305b261ecSmrg{
8435c4bbdfSmrg    return fbGetWindowPixmap(pWindow);
8505b261ecSmrg}
8605b261ecSmrg
8705b261ecSmrgvoid
8835c4bbdfSmrg_fbSetWindowPixmap(WindowPtr pWindow, PixmapPtr pPixmap)
8905b261ecSmrg{
9035c4bbdfSmrg    dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(pWindow), pPixmap);
9105b261ecSmrg}
9205b261ecSmrg
9305b261ecSmrgBool
9435c4bbdfSmrgfbSetupScreen(ScreenPtr pScreen, void *pbits, /* pointer to screen bitmap */
9535c4bbdfSmrg              int xsize,        /* in pixels */
9635c4bbdfSmrg              int ysize, int dpix,      /* dots per inch */
9735c4bbdfSmrg              int dpiy, int width,      /* pixel width of frame buffer */
9835c4bbdfSmrg              int bpp)
9935c4bbdfSmrg{                               /* bits per pixel for screen */
10035c4bbdfSmrg    if (!fbAllocatePrivates(pScreen))
10135c4bbdfSmrg        return FALSE;
10205b261ecSmrg    pScreen->defColormap = FakeClientID(0);
10335c4bbdfSmrg    /* let CreateDefColormap do whatever it wants for pixels */
10405b261ecSmrg    pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
10505b261ecSmrg    pScreen->QueryBestSize = fbQueryBestSize;
10605b261ecSmrg    /* SaveScreen */
10705b261ecSmrg    pScreen->GetImage = fbGetImage;
10805b261ecSmrg    pScreen->GetSpans = fbGetSpans;
10905b261ecSmrg    pScreen->CreateWindow = fbCreateWindow;
11005b261ecSmrg    pScreen->DestroyWindow = fbDestroyWindow;
11105b261ecSmrg    pScreen->PositionWindow = fbPositionWindow;
11205b261ecSmrg    pScreen->ChangeWindowAttributes = fbChangeWindowAttributes;
11335c4bbdfSmrg    pScreen->RealizeWindow = fbRealizeWindow;
11435c4bbdfSmrg    pScreen->UnrealizeWindow = fbUnrealizeWindow;
11505b261ecSmrg    pScreen->CopyWindow = fbCopyWindow;
11605b261ecSmrg    pScreen->CreatePixmap = fbCreatePixmap;
11705b261ecSmrg    pScreen->DestroyPixmap = fbDestroyPixmap;
11805b261ecSmrg    pScreen->RealizeFont = fbRealizeFont;
11905b261ecSmrg    pScreen->UnrealizeFont = fbUnrealizeFont;
12005b261ecSmrg    pScreen->CreateGC = fbCreateGC;
12105b261ecSmrg    pScreen->CreateColormap = fbInitializeColormap;
12235c4bbdfSmrg    pScreen->DestroyColormap = (void (*)(ColormapPtr)) NoopDDA;
12305b261ecSmrg    pScreen->InstallColormap = fbInstallColormap;
12405b261ecSmrg    pScreen->UninstallColormap = fbUninstallColormap;
12505b261ecSmrg    pScreen->ListInstalledColormaps = fbListInstalledColormaps;
12635c4bbdfSmrg    pScreen->StoreColors = (void (*)(ColormapPtr, int, xColorItem *)) NoopDDA;
12705b261ecSmrg    pScreen->ResolveColor = fbResolveColor;
12805b261ecSmrg    pScreen->BitmapToRegion = fbPixmapToRegion;
12935c4bbdfSmrg
13005b261ecSmrg    pScreen->GetWindowPixmap = _fbGetWindowPixmap;
13105b261ecSmrg    pScreen->SetWindowPixmap = _fbSetWindowPixmap;
13205b261ecSmrg
13305b261ecSmrg    return TRUE;
13405b261ecSmrg}
13505b261ecSmrg
13605b261ecSmrg#ifdef FB_ACCESS_WRAPPER
13705b261ecSmrgBool
1381b5d61b8SmrgwfbFinishScreenInit(ScreenPtr pScreen, void *pbits, int xsize, int ysize,
1391b5d61b8Smrg                    int dpix, int dpiy, int width, int bpp,
14035c4bbdfSmrg                    SetupWrapProcPtr setupWrap, FinishWrapProcPtr finishWrap)
14105b261ecSmrg#else
14205b261ecSmrgBool
1431b5d61b8SmrgfbFinishScreenInit(ScreenPtr pScreen, void *pbits, int xsize, int ysize,
1441b5d61b8Smrg                   int dpix, int dpiy, int width, int bpp)
14505b261ecSmrg#endif
14605b261ecSmrg{
14735c4bbdfSmrg    VisualPtr visuals;
14835c4bbdfSmrg    DepthPtr depths;
14935c4bbdfSmrg    int nvisuals;
15035c4bbdfSmrg    int ndepths;
15135c4bbdfSmrg    int rootdepth;
15235c4bbdfSmrg    VisualID defaultVisual;
15305b261ecSmrg
15405b261ecSmrg#ifdef FB_DEBUG
15535c4bbdfSmrg    int stride;
15635c4bbdfSmrg
15705b261ecSmrg    ysize -= 2;
15805b261ecSmrg    stride = (width * bpp) / 8;
15935c4bbdfSmrg    fbSetBits((FbStip *) pbits, stride / sizeof(FbStip), FB_HEAD_BITS);
16005b261ecSmrg    pbits = (void *) ((char *) pbits + stride);
16135c4bbdfSmrg    fbSetBits((FbStip *) ((char *) pbits + stride * ysize),
16235c4bbdfSmrg              stride / sizeof(FbStip), FB_TAIL_BITS);
16305b261ecSmrg#endif
1641b5d61b8Smrg    /* fb requires power-of-two bpp */
1651b5d61b8Smrg    if (Ones(bpp) != 1)
1661b5d61b8Smrg        return FALSE;
16705b261ecSmrg#ifdef FB_ACCESS_WRAPPER
16805b261ecSmrg    fbGetScreenPrivate(pScreen)->setupWrap = setupWrap;
16905b261ecSmrg    fbGetScreenPrivate(pScreen)->finishWrap = finishWrap;
17005b261ecSmrg#endif
17105b261ecSmrg    rootdepth = 0;
17235c4bbdfSmrg    if (!fbInitVisuals(&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
1731b5d61b8Smrg                       &defaultVisual, ((unsigned long) 1 << (bpp - 1)),
17435c4bbdfSmrg                       8))
17535c4bbdfSmrg        return FALSE;
17635c4bbdfSmrg    if (!miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
17735c4bbdfSmrg                      rootdepth, ndepths, depths,
17835c4bbdfSmrg                      defaultVisual, nvisuals, visuals))
17935c4bbdfSmrg        return FALSE;
18005b261ecSmrg    /* overwrite miCloseScreen with our own */
18105b261ecSmrg    pScreen->CloseScreen = fbCloseScreen;
18205b261ecSmrg    return TRUE;
18305b261ecSmrg}
18405b261ecSmrg
18505b261ecSmrg/* dts * (inch/dot) * (25.4 mm / inch) = mm */
18605b261ecSmrg#ifdef FB_ACCESS_WRAPPER
18705b261ecSmrgBool
1881b5d61b8SmrgwfbScreenInit(ScreenPtr pScreen, void *pbits, int xsize, int ysize,
1891b5d61b8Smrg              int dpix, int dpiy, int width, int bpp,
1901b5d61b8Smrg              SetupWrapProcPtr setupWrap, FinishWrapProcPtr finishWrap)
19105b261ecSmrg{
19205b261ecSmrg    if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
19335c4bbdfSmrg        return FALSE;
19405b261ecSmrg    if (!wfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
19535c4bbdfSmrg                             width, bpp, setupWrap, finishWrap))
19635c4bbdfSmrg        return FALSE;
19705b261ecSmrg    return TRUE;
19805b261ecSmrg}
19905b261ecSmrg#else
20005b261ecSmrgBool
2011b5d61b8SmrgfbScreenInit(ScreenPtr pScreen, void *pbits, int xsize, int ysize,
2021b5d61b8Smrg             int dpix, int dpiy, int width, int bpp)
20305b261ecSmrg{
20405b261ecSmrg    if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
20535c4bbdfSmrg        return FALSE;
20635c4bbdfSmrg    if (!fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
20735c4bbdfSmrg                            width, bpp))
20835c4bbdfSmrg        return FALSE;
20905b261ecSmrg    return TRUE;
21005b261ecSmrg}
21105b261ecSmrg#endif
212