First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xgl / xglshm.c
blob52a8aabb803ab98493a26bed40c1a45e132d3e3f
1 /*
2 * Copyright © 2005 Novell, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Novell, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Novell, Inc. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
15 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: David Reveman <davidr@novell.com>
26 #include "xgl.h"
27 #include "gcstruct.h"
29 #ifdef MITSHM
31 void
32 xglShmPutImage (DrawablePtr pDrawable,
33 GCPtr pGC,
34 int depth,
35 unsigned int format,
36 int w,
37 int h,
38 int sx,
39 int sy,
40 int sw,
41 int sh,
42 int dx,
43 int dy,
44 char *data)
46 ScreenPtr pScreen = pDrawable->pScreen;
47 PixmapPtr pPixmapHeader = NULL;
48 PixmapPtr pPixmap;
49 int saveTarget;
51 XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
53 if ((format == ZPixmap) || (depth == 1))
55 pPixmap = pPixmapHeader =
56 GetScratchPixmapHeader (pScreen, w, h, depth,
57 BitsPerPixel (depth),
58 PixmapBytePad (w, depth),
59 (pointer) data);
61 /* disable any possible acceleration of this pixmap */
62 if (pPixmap)
63 xglSetPixmapVisual (pPixmap, 0);
65 else
67 pPixmap = (*pScreen->CreatePixmap) (pScreen, sw, sh, depth);
68 if (pPixmap)
70 GCPtr pScratchGC;
72 if (!xglAllocatePixmapBits (pPixmap,
73 XGL_PIXMAP_USAGE_HINT_DEFAULT))
75 (*pScreen->DestroyPixmap) (pPixmap);
76 return;
79 xglSetPixmapVisual (pPixmap, 0);
81 pScratchGC = GetScratchGC (depth, pScreen);
82 if (!pScratchGC)
84 (*pScreen->DestroyPixmap) (pPixmap);
85 return;
88 ValidateGC ((DrawablePtr) pPixmap, pScratchGC);
89 (*pGC->ops->PutImage) ((DrawablePtr) pPixmap, pScratchGC, depth,
90 -sx, -sy, w, h, 0,
91 (format == XYPixmap) ? XYPixmap : ZPixmap,
92 data);
94 FreeScratchGC (pScratchGC);
96 sx = sy = 0;
100 if (!pPixmap)
101 return;
103 /* CopyArea should always be done in software */
104 saveTarget = pPixmapPriv->target;
105 pPixmapPriv->target = xglPixmapTargetNo;
107 if (format == XYBitmap)
108 (*pGC->ops->CopyPlane) ((DrawablePtr) pPixmap, pDrawable, pGC,
109 sx, sy, sw, sh, dx, dy, 1L);
110 else
111 (*pGC->ops->CopyArea) ((DrawablePtr) pPixmap, pDrawable, pGC,
112 sx, sy, sw, sh, dx, dy);
114 pPixmapPriv->target = saveTarget;
116 if (pPixmapHeader)
117 FreeScratchPixmapHeader (pPixmapHeader);
118 else
119 (*pScreen->DestroyPixmap) (pPixmap);
122 #endif