2
{$WARNING this should be in the IPC unit!!!}
10
Constructor TX11Image.Create(display : PDisplay; screen, width, height : Integer; format : TPTCFormat);
19
Destructor TX11Image.Destroy;
25
Constructor TX11NormalImage.Create(display : PDisplay; screen, width, height : Integer; format : TPTCFormat);
28
xpad, xpitch : Integer;
32
{ cerr << "Creating normal image" << endl << flush; }
35
Inherited Create(display, screen, width, height, format);
37
If format.bits = 24 Then
39
xpitch := width * format.bits Div 8;
41
xpitch := xpitch And (Not 3);
42
m_pixels := GetMem(xpitch * height);
43
Pointer(tmp_m_pixels) := Pointer(m_pixels);
44
m_image := XCreateImage(display, DefaultVisual(display, screen),
45
DefaultDepth(display, screen),
46
ZPixmap, 0, tmp_m_pixels,
47
width, height, xpad, 0);
49
Raise TPTCError.Create('cannot create XImage');
52
Destructor TX11NormalImage.Destroy;
55
If m_image <> Nil Then
57
{ Restore XImage's buffer pointer }
59
XDestroyImage(m_image);
61
If m_pixels <> Nil Then
66
Procedure TX11NormalImage.put(w : TWindow; gc : TGC; x, y : Integer);
69
XPutImage(m_disp, w, gc, m_image, 0, 0, x, y, m_width, m_height);
73
Procedure TX11NormalImage.put(w : TWindow; gc : TGC; sx, sy, dx, dy,
74
width, height : Integer);
77
XPutImage(m_disp, w, gc, m_image, sx, sy, dx, dy, width, height);
81
Function TX11NormalImage.lock : Pointer;
87
Function TX11NormalImage.pitch : Integer;
90
pitch := m_image^.bytes_per_line;
93
{$IFDEF HAVE_X11_EXTENSIONS_XSHM}
97
Fshm_oldhandler : Function(disp : PDisplay; xev : PXErrorEvent) : Integer; CDecl;
99
Function Fshm_errorhandler(disp : PDisplay; xev : PXErrorEvent) : Integer; CDecl;
102
If xev^.error_code=BadAccess Then
108
Result := Fshm_oldhandler(disp, xev);
111
Constructor TX11SHMImage.Create(display : PDisplay; screen, width, height : Integer; format : TPTCFormat);
114
{ cerr << "Creating SHM image" << endl << flush; }
116
shminfo.shmaddr := Pointer(-1);
117
FShmAttached := False;
119
Inherited Create(display, screen, width, height, format);
120
m_image := XShmCreateImage(display, DefaultVisual(display, screen),
121
DefaultDepth(display, screen),
122
ZPixmap, Nil, @shminfo, width, height);
123
If m_image = Nil Then
124
Raise TPTCError.Create('cannot create SHM image');
126
shminfo.shmid := shmget(IPC_PRIVATE, m_image^.bytes_per_line * m_image^.height,
128
If shminfo.shmid = -1 Then
129
Raise TPTCError.Create('cannot get shared memory segment');
131
shminfo.shmaddr := shmat(shminfo.shmid, Nil, 0);
132
shminfo.readOnly := False;
133
m_image^.data := shminfo.shmaddr;
135
If Pointer(shminfo.shmaddr) = Pointer(-1) Then
136
Raise TPTCError.Create('cannot allocate shared memory');
138
// Try and attach the segment to the server. Bugfix: Have to catch
139
// bad access errors in case it runs over the net.
141
Fshm_oldhandler := XSetErrorHandler(@Fshm_errorhandler);
143
If XShmAttach(display, @shminfo) = 0 Then
144
Raise TPTCError.Create('cannot attach shared memory segment to display');
146
XSync(display, False);
148
Raise TPTCError.Create('cannot attach shared memory segment to display');
149
FShmAttached := True;
151
XSetErrorHandler(Fshm_oldhandler);
155
Destructor TX11SHMImage.Destroy;
160
XShmDetach(m_disp, @shminfo);
161
XSync(m_disp, False);
163
If m_image <> Nil Then
164
XDestroyImage(m_image);
165
If Pointer(shminfo.shmaddr) <> Pointer(-1) Then
166
shmdt(shminfo.shmaddr);
167
If shminfo.shmid <> -1 Then
168
shmctl(shminfo.shmid, IPC_RMID, Nil);
172
Procedure TX11SHMImage.put(w : TWindow; gc : TGC; x, y : Integer);
175
XShmPutImage(m_disp, w, gc, m_image, 0, 0, x, y, m_width, m_height, False);
176
XSync(m_disp, False);
179
Procedure TX11SHMImage.put(w : TWindow; gc : TGC; sx, sy, dx, dy,
180
width, height : Integer);
183
XShmPutImage(m_disp, w, gc, m_image, sx, sy, dx, dy, width, height, False);
184
XSync(m_disp, False);
187
Function TX11SHMImage.lock : Pointer;
190
lock := Pointer(shminfo.shmaddr);
193
Function TX11SHMImage.pitch : Integer;
196
pitch := m_image^.bytes_per_line;