2
{$WARNING this belongs to the ipc unit}
5
Constructor TX11Image.Create(ADisplay : PDisplay; AScreen, AWidth, AHeight : Integer; AFormat : TPTCFormat);
13
Constructor TX11NormalImage.Create(ADisplay : PDisplay; AScreen, AWidth, AHeight : Integer; AFormat : TPTCFormat);
16
xpad, xpitch : Integer;
23
If AFormat.Bits = 24 Then
25
xpitch := AWidth * AFormat.Bits Div 8;
27
xpitch := xpitch And (Not 3);
28
FPixels := GetMem(xpitch * AHeight);
29
Pointer(tmp_FPixels) := Pointer(FPixels);
30
FImage := XCreateImage(ADisplay, DefaultVisual(ADisplay, AScreen),
31
DefaultDepth(ADisplay, AScreen),
32
ZPixmap, 0, tmp_FPixels,
33
AWidth, AHeight, xpad, 0);
35
Raise TPTCError.Create('cannot create XImage');
38
Destructor TX11NormalImage.Destroy;
43
{ Restore XImage's buffer pointer }
45
XDestroyImage(FImage);
48
If FPixels <> Nil Then
54
Procedure TX11NormalImage.Put(AWindow : TWindow; AGC : TGC; AX, AY : Integer);
57
XPutImage(FDisplay, AWindow, AGC, FImage, 0, 0, AX, AY, FWidth, FHeight);
58
XSync(FDisplay, False);
61
Procedure TX11NormalImage.Put(AWindow : TWindow; AGC : TGC; ASX, ASY, ADX, ADY,
62
AWidth, AHeight : Integer);
65
XPutImage(FDisplay, AWindow, AGC, FImage, ASX, ASY, ADX, ADY, AWidth, AHeight);
66
XSync(FDisplay, False);
69
Function TX11NormalImage.Lock : Pointer;
75
Function TX11NormalImage.Pitch : Integer;
78
Result := FImage^.bytes_per_line;
81
Function TX11NormalImage.Name : String;
87
{$IFDEF ENABLE_X11_EXTENSION_XSHM}
91
Fshm_oldhandler : Function(disp : PDisplay; xev : PXErrorEvent) : Integer; CDecl;
93
Function Fshm_errorhandler(disp : PDisplay; xev : PXErrorEvent) : Integer; CDecl;
96
If xev^.error_code=BadAccess Then
102
Result := Fshm_oldhandler(disp, xev);
105
Constructor TX11ShmImage.Create(ADisplay : PDisplay; AScreen, AWidth, AHeight : Integer; AFormat : TPTCFormat);
110
FShmInfo.shmid := -1;
111
FShmInfo.shmaddr := Pointer(-1);
112
FImage := XShmCreateImage(ADisplay, DefaultVisual(ADisplay, AScreen),
113
DefaultDepth(ADisplay, AScreen),
114
ZPixmap, Nil, @FShmInfo, AWidth, AHeight);
116
Raise TPTCError.Create('cannot create SHM image');
118
FShmInfo.shmid := shmget(IPC_PRIVATE, FImage^.bytes_per_line * FImage^.height,
120
If FShmInfo.shmid = -1 Then
121
Raise TPTCError.Create('cannot get shared memory segment');
123
FShmInfo.shmaddr := shmat(FShmInfo.shmid, Nil, 0);
124
FShmInfo.readOnly := False;
125
FImage^.data := FShmInfo.shmaddr;
127
If Pointer(FShmInfo.shmaddr) = Pointer(-1) Then
128
Raise TPTCError.Create('cannot allocate shared memory');
130
// Try and attach the segment to the server. Bugfix: Have to catch
131
// bad access errors in case it runs over the net.
133
Fshm_oldhandler := XSetErrorHandler(@Fshm_errorhandler);
135
If XShmAttach(ADisplay, @FShmInfo) = 0 Then
136
Raise TPTCError.Create('cannot attach shared memory segment to display');
138
XSync(ADisplay, False);
140
Raise TPTCError.Create('cannot attach shared memory segment to display');
141
FShmAttached := True;
143
XSetErrorHandler(Fshm_oldhandler);
147
Destructor TX11ShmImage.Destroy;
152
XShmDetach(FDisplay, @FShmInfo);
153
XSync(FDisplay, False);
155
If FImage <> Nil Then
156
XDestroyImage(FImage);
157
If Pointer(FShmInfo.shmaddr) <> Pointer(-1) Then
158
shmdt(FShmInfo.shmaddr);
159
If FShmInfo.shmid <> -1 Then
160
shmctl(FShmInfo.shmid, IPC_RMID, Nil);
165
Procedure TX11ShmImage.Put(AWindow : TWindow; AGC : TGC; AX, AY : Integer);
168
XShmPutImage(FDisplay, AWindow, AGC, FImage, 0, 0, AX, AY, FWidth, FHeight, False);
169
XSync(FDisplay, False);
172
Procedure TX11ShmImage.Put(AWindow : TWindow; AGC : TGC; ASX, ASY, ADX, ADY,
173
AWidth, AHeight : Integer);
176
XShmPutImage(FDisplay, AWindow, AGC, FImage, ASX, ASY, ADX, ADY, FWidth, FHeight, False);
177
XSync(FDisplay, False);
180
Function TX11ShmImage.Lock : Pointer;
183
Result := Pointer(FShmInfo.shmaddr);
186
Function TX11ShmImage.Pitch : Integer;
189
Result := FImage^.bytes_per_line;
192
Function TX11ShmImage.Name : String;
197
{$ENDIF ENABLE_X11_EXTENSION_XSHM}