fbwindow.c revision 35c4bbdf
1/*
2 * Copyright © 1998 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  Keith Packard makes no
11 * representations about the suitability of this software for any purpose.  It
12 * is provided "as is" without express or implied warranty.
13 *
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#ifdef HAVE_DIX_CONFIG_H
24#include <dix-config.h>
25#endif
26
27#include <stdlib.h>
28
29#include "fb.h"
30
31Bool
32fbCreateWindow(WindowPtr pWin)
33{
34    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(pWin),
35                  fbGetScreenPixmap(pWin->drawable.pScreen));
36    if (pWin->drawable.bitsPerPixel == 32 && pWin->drawable.depth <= 24)
37        pWin->drawable.bitsPerPixel =
38            fbGetScreenPrivate(pWin->drawable.pScreen)->win32bpp;
39    return TRUE;
40}
41
42Bool
43fbDestroyWindow(WindowPtr pWin)
44{
45    return TRUE;
46}
47
48Bool
49fbRealizeWindow(WindowPtr pWindow)
50{
51    return TRUE;
52}
53
54Bool
55fbPositionWindow(WindowPtr pWin, int x, int y)
56{
57    return TRUE;
58}
59
60Bool
61fbUnrealizeWindow(WindowPtr pWindow)
62{
63    return TRUE;
64}
65
66void
67fbCopyWindowProc(DrawablePtr pSrcDrawable,
68                 DrawablePtr pDstDrawable,
69                 GCPtr pGC,
70                 BoxPtr pbox,
71                 int nbox,
72                 int dx,
73                 int dy,
74                 Bool reverse, Bool upsidedown, Pixel bitplane, void *closure)
75{
76    FbBits *src;
77    FbStride srcStride;
78    int srcBpp;
79    int srcXoff, srcYoff;
80    FbBits *dst;
81    FbStride dstStride;
82    int dstBpp;
83    int dstXoff, dstYoff;
84
85    fbGetDrawable(pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
86    fbGetDrawable(pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
87
88    while (nbox--) {
89        fbBlt(src + (pbox->y1 + dy + srcYoff) * srcStride,
90              srcStride,
91              (pbox->x1 + dx + srcXoff) * srcBpp,
92              dst + (pbox->y1 + dstYoff) * dstStride,
93              dstStride,
94              (pbox->x1 + dstXoff) * dstBpp,
95              (pbox->x2 - pbox->x1) * dstBpp,
96              (pbox->y2 - pbox->y1),
97              GXcopy, FB_ALLONES, dstBpp, reverse, upsidedown);
98        pbox++;
99    }
100
101    fbFinishAccess(pDstDrawable);
102    fbFinishAccess(pSrcDrawable);
103}
104
105void
106fbCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
107{
108    RegionRec rgnDst;
109    int dx, dy;
110
111    PixmapPtr pPixmap = fbGetWindowPixmap(pWin);
112    DrawablePtr pDrawable = &pPixmap->drawable;
113
114    dx = ptOldOrg.x - pWin->drawable.x;
115    dy = ptOldOrg.y - pWin->drawable.y;
116    RegionTranslate(prgnSrc, -dx, -dy);
117
118    RegionNull(&rgnDst);
119
120    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
121
122#ifdef COMPOSITE
123    if (pPixmap->screen_x || pPixmap->screen_y)
124        RegionTranslate(&rgnDst, -pPixmap->screen_x, -pPixmap->screen_y);
125#endif
126
127    miCopyRegion(pDrawable, pDrawable,
128                 0, &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
129
130    RegionUninit(&rgnDst);
131    fbValidateDrawable(&pWin->drawable);
132}
133
134static void
135fbFixupWindowPixmap(DrawablePtr pDrawable, PixmapPtr *ppPixmap)
136{
137    PixmapPtr pPixmap = *ppPixmap;
138
139    if (pPixmap->drawable.bitsPerPixel != pDrawable->bitsPerPixel) {
140        pPixmap = fb24_32ReformatTile(pPixmap, pDrawable->bitsPerPixel);
141        if (!pPixmap)
142            return;
143        (*pDrawable->pScreen->DestroyPixmap) (*ppPixmap);
144        *ppPixmap = pPixmap;
145    }
146    if (FbEvenTile(pPixmap->drawable.width * pPixmap->drawable.bitsPerPixel))
147        fbPadPixmap(pPixmap);
148}
149
150Bool
151fbChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
152{
153    if (mask & CWBackPixmap) {
154        if (pWin->backgroundState == BackgroundPixmap)
155            fbFixupWindowPixmap(&pWin->drawable, &pWin->background.pixmap);
156    }
157    if (mask & CWBorderPixmap) {
158        if (pWin->borderIsPixel == FALSE)
159            fbFixupWindowPixmap(&pWin->drawable, &pWin->border.pixmap);
160    }
161    return TRUE;
162}
163
164void
165fbFillRegionSolid(DrawablePtr pDrawable,
166                  RegionPtr pRegion, FbBits and, FbBits xor)
167{
168    FbBits *dst;
169    FbStride dstStride;
170    int dstBpp;
171    int dstXoff, dstYoff;
172    int n = RegionNumRects(pRegion);
173    BoxPtr pbox = RegionRects(pRegion);
174
175#ifndef FB_ACCESS_WRAPPER
176    int try_mmx = 0;
177
178    if (!and)
179        try_mmx = 1;
180#endif
181
182    fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
183
184    while (n--) {
185#ifndef FB_ACCESS_WRAPPER
186        if (!try_mmx || !pixman_fill((uint32_t *) dst, dstStride, dstBpp,
187                                     pbox->x1 + dstXoff, pbox->y1 + dstYoff,
188                                     (pbox->x2 - pbox->x1),
189                                     (pbox->y2 - pbox->y1), xor)) {
190#endif
191            fbSolid(dst + (pbox->y1 + dstYoff) * dstStride,
192                    dstStride,
193                    (pbox->x1 + dstXoff) * dstBpp,
194                    dstBpp,
195                    (pbox->x2 - pbox->x1) * dstBpp,
196                    pbox->y2 - pbox->y1, and, xor);
197#ifndef FB_ACCESS_WRAPPER
198        }
199#endif
200        fbValidateDrawable(pDrawable);
201        pbox++;
202    }
203
204    fbFinishAccess(pDrawable);
205}
206