fbwindow.c revision 6747b715
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(), 35 fbGetScreenPixmap(pWin->drawable.pScreen)); 36#ifdef FB_SCREEN_PRIVATE 37 if (pWin->drawable.bitsPerPixel == 32) 38 pWin->drawable.bitsPerPixel = fbGetScreenPrivate(pWin->drawable.pScreen)->win32bpp; 39#endif 40 return TRUE; 41} 42 43Bool 44fbDestroyWindow(WindowPtr pWin) 45{ 46 return TRUE; 47} 48 49Bool 50fbMapWindow(WindowPtr pWindow) 51{ 52 return TRUE; 53} 54 55Bool 56fbPositionWindow(WindowPtr pWin, int x, int y) 57{ 58 return TRUE; 59} 60 61Bool 62fbUnmapWindow(WindowPtr pWindow) 63{ 64 return TRUE; 65} 66 67void 68fbCopyWindowProc (DrawablePtr pSrcDrawable, 69 DrawablePtr pDstDrawable, 70 GCPtr pGC, 71 BoxPtr pbox, 72 int nbox, 73 int dx, 74 int dy, 75 Bool reverse, 76 Bool upsidedown, 77 Pixel bitplane, 78 void *closure) 79{ 80 FbBits *src; 81 FbStride srcStride; 82 int srcBpp; 83 int srcXoff, srcYoff; 84 FbBits *dst; 85 FbStride dstStride; 86 int dstBpp; 87 int dstXoff, dstYoff; 88 89 fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff); 90 fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); 91 92 while (nbox--) 93 { 94 fbBlt (src + (pbox->y1 + dy + srcYoff) * srcStride, 95 srcStride, 96 (pbox->x1 + dx + srcXoff) * srcBpp, 97 98 dst + (pbox->y1 + dstYoff) * dstStride, 99 dstStride, 100 (pbox->x1 + dstXoff) * dstBpp, 101 102 (pbox->x2 - pbox->x1) * dstBpp, 103 (pbox->y2 - pbox->y1), 104 105 GXcopy, 106 FB_ALLONES, 107 dstBpp, 108 109 reverse, 110 upsidedown); 111 pbox++; 112 } 113 114 fbFinishAccess (pDstDrawable); 115 fbFinishAccess (pSrcDrawable); 116} 117 118void 119fbCopyWindow(WindowPtr pWin, 120 DDXPointRec ptOldOrg, 121 RegionPtr prgnSrc) 122{ 123 RegionRec rgnDst; 124 int dx, dy; 125 126 PixmapPtr pPixmap = fbGetWindowPixmap (pWin); 127 DrawablePtr pDrawable = &pPixmap->drawable; 128 129 dx = ptOldOrg.x - pWin->drawable.x; 130 dy = ptOldOrg.y - pWin->drawable.y; 131 RegionTranslate(prgnSrc, -dx, -dy); 132 133 RegionNull(&rgnDst); 134 135 RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc); 136 137#ifdef COMPOSITE 138 if (pPixmap->screen_x || pPixmap->screen_y) 139 RegionTranslate(&rgnDst, 140 -pPixmap->screen_x, -pPixmap->screen_y); 141#endif 142 143 miCopyRegion (pDrawable, pDrawable, 144 0, 145 &rgnDst, dx, dy, fbCopyWindowProc, 0, 0); 146 147 RegionUninit(&rgnDst); 148 fbValidateDrawable (&pWin->drawable); 149} 150 151Bool 152fbChangeWindowAttributes(WindowPtr pWin, unsigned long mask) 153{ 154 PixmapPtr pPixmap; 155 156 if (mask & CWBackPixmap) 157 { 158 if (pWin->backgroundState == BackgroundPixmap) 159 { 160 pPixmap = pWin->background.pixmap; 161#ifdef FB_24_32BIT 162 if (pPixmap->drawable.bitsPerPixel != pWin->drawable.bitsPerPixel) 163 { 164 pPixmap = fb24_32ReformatTile (pPixmap, 165 pWin->drawable.bitsPerPixel); 166 if (pPixmap) 167 { 168 (*pWin->drawable.pScreen->DestroyPixmap) (pWin->background.pixmap); 169 pWin->background.pixmap = pPixmap; 170 } 171 } 172#endif 173 if (FbEvenTile (pPixmap->drawable.width * 174 pPixmap->drawable.bitsPerPixel)) 175 fbPadPixmap (pPixmap); 176 } 177 } 178 if (mask & CWBorderPixmap) 179 { 180 if (pWin->borderIsPixel == FALSE) 181 { 182 pPixmap = pWin->border.pixmap; 183#ifdef FB_24_32BIT 184 if (pPixmap->drawable.bitsPerPixel != 185 pWin->drawable.bitsPerPixel) 186 { 187 pPixmap = fb24_32ReformatTile (pPixmap, 188 pWin->drawable.bitsPerPixel); 189 if (pPixmap) 190 { 191 (*pWin->drawable.pScreen->DestroyPixmap) (pWin->border.pixmap); 192 pWin->border.pixmap = pPixmap; 193 } 194 } 195#endif 196 if (FbEvenTile (pPixmap->drawable.width * 197 pPixmap->drawable.bitsPerPixel)) 198 fbPadPixmap (pPixmap); 199 } 200 } 201 return TRUE; 202} 203 204void 205fbFillRegionSolid (DrawablePtr pDrawable, 206 RegionPtr pRegion, 207 FbBits and, 208 FbBits xor) 209{ 210 FbBits *dst; 211 FbStride dstStride; 212 int dstBpp; 213 int dstXoff, dstYoff; 214 int n = RegionNumRects(pRegion); 215 BoxPtr pbox = RegionRects(pRegion); 216 217#ifndef FB_ACCESS_WRAPPER 218 int try_mmx = 0; 219 if (!and) 220 try_mmx = 1; 221#endif 222 223 fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); 224 225 while (n--) 226 { 227#ifndef FB_ACCESS_WRAPPER 228 if (!try_mmx || !pixman_fill ((uint32_t *)dst, dstStride, dstBpp, 229 pbox->x1 + dstXoff, pbox->y1 + dstYoff, 230 (pbox->x2 - pbox->x1), 231 (pbox->y2 - pbox->y1), 232 xor)) 233 { 234#endif 235 fbSolid (dst + (pbox->y1 + dstYoff) * dstStride, 236 dstStride, 237 (pbox->x1 + dstXoff) * dstBpp, 238 dstBpp, 239 (pbox->x2 - pbox->x1) * dstBpp, 240 pbox->y2 - pbox->y1, 241 and, xor); 242#ifndef FB_ACCESS_WRAPPER 243 } 244#endif 245 fbValidateDrawable (pDrawable); 246 pbox++; 247 } 248 249 fbFinishAccess (pDrawable); 250} 251