~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xnest/Pixmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: Pixmap.c,v 1.3 2000/08/17 19:53:28 cpqbld Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1993 by Davor Matic
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software
 
7
and its documentation for any purpose is hereby granted without fee,
 
8
provided that the above copyright notice appear in all copies and that
 
9
both that copyright notice and this permission notice appear in
 
10
supporting documentation.  Davor Matic makes no representations about
 
11
the suitability of this software for any purpose.  It is provided "as
 
12
is" without express or implied warranty.
 
13
 
 
14
*/
 
15
/* $XFree86: xc/programs/Xserver/hw/xnest/Pixmap.c,v 3.7 2003/07/16 01:38:51 dawes Exp $ */
 
16
 
 
17
#ifdef HAVE_XNEST_CONFIG_H
 
18
#include <xnest-config.h>
 
19
#endif
 
20
 
 
21
#include <X11/X.h>
 
22
#include <X11/Xproto.h>
 
23
#include "regionstr.h"
 
24
#include "pixmapstr.h"
 
25
#include "scrnintstr.h"
 
26
#include "regionstr.h"
 
27
#include "gc.h"
 
28
#include "servermd.h"
 
29
#include "mi.h"
 
30
 
 
31
#include "Xnest.h"
 
32
 
 
33
#include "Display.h"
 
34
#include "Screen.h"
 
35
#include "XNPixmap.h"
 
36
 
 
37
#ifdef PIXPRIV
 
38
int xnestPixmapPrivateIndex;        
 
39
#endif
 
40
 
 
41
PixmapPtr
 
42
xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth)
 
43
{
 
44
  PixmapPtr pPixmap;
 
45
 
 
46
  pPixmap = AllocatePixmap(pScreen, sizeof(xnestPrivPixmap));
 
47
  if (!pPixmap)
 
48
    return NullPixmap;
 
49
  pPixmap->drawable.type = DRAWABLE_PIXMAP;
 
50
  pPixmap->drawable.class = 0;
 
51
  pPixmap->drawable.depth = depth;
 
52
  pPixmap->drawable.bitsPerPixel = depth;
 
53
  pPixmap->drawable.id = 0;
 
54
  pPixmap->drawable.x = 0;
 
55
  pPixmap->drawable.y = 0;
 
56
  pPixmap->drawable.width = width;
 
57
  pPixmap->drawable.height = height;
 
58
  pPixmap->drawable.pScreen = pScreen;
 
59
  pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 
60
  pPixmap->refcnt = 1;
 
61
  pPixmap->devKind = PixmapBytePad(width, depth);
 
62
#ifdef PIXPRIV
 
63
  pPixmap->devPrivates[xnestPixmapPrivateIndex].ptr =
 
64
      (pointer)((char *)pPixmap + pScreen->totalPixmapSize);
 
65
#else
 
66
  pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
 
67
#endif
 
68
  if (width && height)
 
69
      xnestPixmapPriv(pPixmap)->pixmap = 
 
70
          XCreatePixmap(xnestDisplay, 
 
71
                        xnestDefaultWindows[pScreen->myNum],
 
72
                        width, height, depth);
 
73
  else
 
74
      xnestPixmapPriv(pPixmap)->pixmap = 0;
 
75
  
 
76
  return pPixmap;
 
77
}
 
78
 
 
79
Bool
 
80
xnestDestroyPixmap(PixmapPtr pPixmap)
 
81
{
 
82
  if(--pPixmap->refcnt)
 
83
    return TRUE;
 
84
  XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
 
85
  xfree(pPixmap);
 
86
  return TRUE;
 
87
}
 
88
 
 
89
RegionPtr
 
90
xnestPixmapToRegion(PixmapPtr pPixmap)
 
91
{
 
92
  XImage *ximage;
 
93
  register RegionPtr pReg, pTmpReg;
 
94
  register int x, y;
 
95
  unsigned long previousPixel, currentPixel;
 
96
  BoxRec Box;
 
97
  Bool overlap;
 
98
  
 
99
  ximage = XGetImage(xnestDisplay, xnestPixmap(pPixmap), 0, 0,
 
100
                     pPixmap->drawable.width, pPixmap->drawable.height,
 
101
                     1, XYPixmap);
 
102
  
 
103
  pReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1);
 
104
  pTmpReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1);
 
105
  if(!pReg || !pTmpReg) return NullRegion;
 
106
  
 
107
  for (y = 0; y < pPixmap->drawable.height; y++) {
 
108
    Box.y1 = y;
 
109
    Box.y2 = y + 1;
 
110
    previousPixel = 0L;
 
111
    for (x = 0; x < pPixmap->drawable.width; x++) {
 
112
      currentPixel = XGetPixel(ximage, x, y);
 
113
      if (previousPixel != currentPixel) {
 
114
        if (previousPixel == 0L) { 
 
115
          /* left edge */
 
116
          Box.x1 = x;
 
117
        }
 
118
        else if (currentPixel == 0L) {
 
119
          /* right edge */
 
120
          Box.x2 = x;
 
121
          REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box);
 
122
          REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg);
 
123
        }
 
124
        previousPixel = currentPixel;
 
125
      }
 
126
    }
 
127
    if (previousPixel != 0L) {
 
128
      /* right edge because of the end of pixmap */
 
129
      Box.x2 = pPixmap->drawable.width;
 
130
      REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box);
 
131
      REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg);
 
132
    }
 
133
  }
 
134
  
 
135
  REGION_DESTROY(pPixmap->drawable.pScreen, pTmpReg);
 
136
  XDestroyImage(ximage);
 
137
 
 
138
  REGION_VALIDATE(pPixmap->drawable.pScreen, pReg, &overlap);
 
139
 
 
140
  return(pReg);
 
141
}