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 <stdlib.h>
2805b261ecSmrg
2905b261ecSmrg#include "fb.h"
3005b261ecSmrg
3105b261ecSmrgBool
3205b261ecSmrgfbCreateWindow(WindowPtr pWin)
3305b261ecSmrg{
3435c4bbdfSmrg    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(pWin),
3535c4bbdfSmrg                  fbGetScreenPixmap(pWin->drawable.pScreen));
3605b261ecSmrg    return TRUE;
3705b261ecSmrg}
3805b261ecSmrg
3905b261ecSmrgBool
4005b261ecSmrgfbDestroyWindow(WindowPtr pWin)
4105b261ecSmrg{
4205b261ecSmrg    return TRUE;
4305b261ecSmrg}
4405b261ecSmrg
4505b261ecSmrgBool
4635c4bbdfSmrgfbRealizeWindow(WindowPtr pWindow)
4705b261ecSmrg{
4805b261ecSmrg    return TRUE;
4905b261ecSmrg}
5005b261ecSmrg
5105b261ecSmrgBool
5205b261ecSmrgfbPositionWindow(WindowPtr pWin, int x, int y)
5305b261ecSmrg{
5405b261ecSmrg    return TRUE;
5505b261ecSmrg}
5605b261ecSmrg
5705b261ecSmrgBool
5835c4bbdfSmrgfbUnrealizeWindow(WindowPtr pWindow)
5905b261ecSmrg{
6005b261ecSmrg    return TRUE;
6105b261ecSmrg}
6205b261ecSmrg
6305b261ecSmrgvoid
6435c4bbdfSmrgfbCopyWindowProc(DrawablePtr pSrcDrawable,
6535c4bbdfSmrg                 DrawablePtr pDstDrawable,
6635c4bbdfSmrg                 GCPtr pGC,
6735c4bbdfSmrg                 BoxPtr pbox,
6835c4bbdfSmrg                 int nbox,
6935c4bbdfSmrg                 int dx,
7035c4bbdfSmrg                 int dy,
7135c4bbdfSmrg                 Bool reverse, Bool upsidedown, Pixel bitplane, void *closure)
7205b261ecSmrg{
7335c4bbdfSmrg    FbBits *src;
7435c4bbdfSmrg    FbStride srcStride;
7535c4bbdfSmrg    int srcBpp;
7635c4bbdfSmrg    int srcXoff, srcYoff;
7735c4bbdfSmrg    FbBits *dst;
7835c4bbdfSmrg    FbStride dstStride;
7935c4bbdfSmrg    int dstBpp;
8035c4bbdfSmrg    int dstXoff, dstYoff;
8135c4bbdfSmrg
8235c4bbdfSmrg    fbGetDrawable(pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
8335c4bbdfSmrg    fbGetDrawable(pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
8435c4bbdfSmrg
8535c4bbdfSmrg    while (nbox--) {
8635c4bbdfSmrg        fbBlt(src + (pbox->y1 + dy + srcYoff) * srcStride,
8735c4bbdfSmrg              srcStride,
8835c4bbdfSmrg              (pbox->x1 + dx + srcXoff) * srcBpp,
8935c4bbdfSmrg              dst + (pbox->y1 + dstYoff) * dstStride,
9035c4bbdfSmrg              dstStride,
9135c4bbdfSmrg              (pbox->x1 + dstXoff) * dstBpp,
9235c4bbdfSmrg              (pbox->x2 - pbox->x1) * dstBpp,
9335c4bbdfSmrg              (pbox->y2 - pbox->y1),
9435c4bbdfSmrg              GXcopy, FB_ALLONES, dstBpp, reverse, upsidedown);
9535c4bbdfSmrg        pbox++;
9605b261ecSmrg    }
9705b261ecSmrg
9835c4bbdfSmrg    fbFinishAccess(pDstDrawable);
9935c4bbdfSmrg    fbFinishAccess(pSrcDrawable);
10005b261ecSmrg}
10105b261ecSmrg
1026747b715Smrgvoid
10335c4bbdfSmrgfbCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
10405b261ecSmrg{
10535c4bbdfSmrg    RegionRec rgnDst;
10635c4bbdfSmrg    int dx, dy;
10705b261ecSmrg
10835c4bbdfSmrg    PixmapPtr pPixmap = fbGetWindowPixmap(pWin);
10935c4bbdfSmrg    DrawablePtr pDrawable = &pPixmap->drawable;
11005b261ecSmrg
11105b261ecSmrg    dx = ptOldOrg.x - pWin->drawable.x;
11205b261ecSmrg    dy = ptOldOrg.y - pWin->drawable.y;
1136747b715Smrg    RegionTranslate(prgnSrc, -dx, -dy);
11405b261ecSmrg
1156747b715Smrg    RegionNull(&rgnDst);
11635c4bbdfSmrg
1176747b715Smrg    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
11805b261ecSmrg
11905b261ecSmrg#ifdef COMPOSITE
12005b261ecSmrg    if (pPixmap->screen_x || pPixmap->screen_y)
12135c4bbdfSmrg        RegionTranslate(&rgnDst, -pPixmap->screen_x, -pPixmap->screen_y);
12205b261ecSmrg#endif
12305b261ecSmrg
12435c4bbdfSmrg    miCopyRegion(pDrawable, pDrawable,
12535c4bbdfSmrg                 0, &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
12635c4bbdfSmrg
1276747b715Smrg    RegionUninit(&rgnDst);
12835c4bbdfSmrg    fbValidateDrawable(&pWin->drawable);
12935c4bbdfSmrg}
13035c4bbdfSmrg
13135c4bbdfSmrgstatic void
13235c4bbdfSmrgfbFixupWindowPixmap(DrawablePtr pDrawable, PixmapPtr *ppPixmap)
13335c4bbdfSmrg{
13435c4bbdfSmrg    PixmapPtr pPixmap = *ppPixmap;
13535c4bbdfSmrg
13635c4bbdfSmrg    if (FbEvenTile(pPixmap->drawable.width * pPixmap->drawable.bitsPerPixel))
13735c4bbdfSmrg        fbPadPixmap(pPixmap);
13805b261ecSmrg}
13905b261ecSmrg
14005b261ecSmrgBool
14105b261ecSmrgfbChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
14205b261ecSmrg{
14335c4bbdfSmrg    if (mask & CWBackPixmap) {
14435c4bbdfSmrg        if (pWin->backgroundState == BackgroundPixmap)
14535c4bbdfSmrg            fbFixupWindowPixmap(&pWin->drawable, &pWin->background.pixmap);
14605b261ecSmrg    }
14735c4bbdfSmrg    if (mask & CWBorderPixmap) {
14835c4bbdfSmrg        if (pWin->borderIsPixel == FALSE)
14935c4bbdfSmrg            fbFixupWindowPixmap(&pWin->drawable, &pWin->border.pixmap);
15005b261ecSmrg    }
15105b261ecSmrg    return TRUE;
15205b261ecSmrg}
15305b261ecSmrg
15405b261ecSmrgvoid
15535c4bbdfSmrgfbFillRegionSolid(DrawablePtr pDrawable,
15635c4bbdfSmrg                  RegionPtr pRegion, FbBits and, FbBits xor)
15705b261ecSmrg{
15835c4bbdfSmrg    FbBits *dst;
15935c4bbdfSmrg    FbStride dstStride;
16035c4bbdfSmrg    int dstBpp;
16135c4bbdfSmrg    int dstXoff, dstYoff;
16235c4bbdfSmrg    int n = RegionNumRects(pRegion);
16335c4bbdfSmrg    BoxPtr pbox = RegionRects(pRegion);
16405b261ecSmrg
16505b261ecSmrg#ifndef FB_ACCESS_WRAPPER
16605b261ecSmrg    int try_mmx = 0;
16735c4bbdfSmrg
16805b261ecSmrg    if (!and)
16905b261ecSmrg        try_mmx = 1;
17005b261ecSmrg#endif
17105b261ecSmrg
17235c4bbdfSmrg    fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
17335c4bbdfSmrg
17435c4bbdfSmrg    while (n--) {
17505b261ecSmrg#ifndef FB_ACCESS_WRAPPER
17635c4bbdfSmrg        if (!try_mmx || !pixman_fill((uint32_t *) dst, dstStride, dstBpp,
17735c4bbdfSmrg                                     pbox->x1 + dstXoff, pbox->y1 + dstYoff,
17835c4bbdfSmrg                                     (pbox->x2 - pbox->x1),
17935c4bbdfSmrg                                     (pbox->y2 - pbox->y1), xor)) {
18005b261ecSmrg#endif
18135c4bbdfSmrg            fbSolid(dst + (pbox->y1 + dstYoff) * dstStride,
18235c4bbdfSmrg                    dstStride,
18335c4bbdfSmrg                    (pbox->x1 + dstXoff) * dstBpp,
18435c4bbdfSmrg                    dstBpp,
18535c4bbdfSmrg                    (pbox->x2 - pbox->x1) * dstBpp,
18635c4bbdfSmrg                    pbox->y2 - pbox->y1, and, xor);
18705b261ecSmrg#ifndef FB_ACCESS_WRAPPER
18835c4bbdfSmrg        }
18905b261ecSmrg#endif
19035c4bbdfSmrg        fbValidateDrawable(pDrawable);
19135c4bbdfSmrg        pbox++;
19205b261ecSmrg    }
19335c4bbdfSmrg
19435c4bbdfSmrg    fbFinishAccess(pDrawable);
19505b261ecSmrg}
196