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