unit X11_Pixmaps; interface uses xlib, X11_Objects, X11_Drawables, X11_Shared_Memory, X11, type_fixes, framebuffers; // TODO public properties for Width, Height. // FIXME common base class with X11_XImages. type TPixmap = class(TDrawable, IPixmap, IDrawable, X11_Objects.IObject, IInterface) private fFramebufferInfo : TFramebufferInfo; protected procedure DeleteUnderlyingObject; override; procedure UpdateFramebufferInfo(aWidth, aHeight, aDepth : TCardinal); published constructor Create(aDisplay : PDisplay; aWidth, aHeight, aDepth : TCardinal); constructor CreateSHM(aDisplay : PDisplay; const aSHMSegment : ISHMSegment; aWidth, aHeight, aDepth : TCardinal; const aWindow : IWindow); function FramebufferInfo : TFramebufferInfoP; end; implementation uses xshm; constructor TPixmap.Create(aDisplay : PDisplay; aWidth, aHeight, aDepth : TCardinal); begin inherited Reuse(aDisplay, XCreatePixmap(aDisplay, fHandle, aWidth, aHeight, aDepth), True); UpdateFramebufferInfo(aWidth, aHeight, aDepth); end; { for aWindow, use the screen's root window if in doubt. } constructor TPixmap.CreateSHM(aDisplay : PDisplay; const aSHMSegment : ISHMSegment; aWidth, aHeight, aDepth : TCardinal; const aWindow : IWindow); var VInfo : TXShmSegmentInfo; VWindowHandle : THandle; begin VInfo.shmseg := aSHMSegment.Handle; VInfo.shmaddr := aSHMSegment.SharedMemory.Address; { TODO? add the other stuff? } VInfo.shmid := aSHMSegment.SharedMemory.ID; VInfo.readonly := LongInt(aSHMSegment.BReadOnly); if AWindow <> nil then VWindowHandle := AWindow.Handle else VWindowHandle := RootWindowOfScreen(xlib.DefaultScreenOfDisplay(aDisplay)); // TODO use the root window inherited Reuse(aDisplay, XShmCreatePixmap(aDisplay, VWindowHandle, aSHMSegment.SharedMemory.Address, @VInfo, aWidth, aHeight, aDepth), True); UpdateFramebufferInfo(aWidth, aHeight, aDepth); end; // FIXME call UpdateFramebufferInfo when reusing. // TODO a constructor where you can specify the start address? procedure TPixmap.DeleteUnderlyingObject; begin if fHandle <> 0 then begin XFreePixmap(Display, fHandle); fHandle := 0; end; end; procedure TPixmap.UpdateFramebufferInfo(aWidth, aHeight, aDepth : TCardinal); begin with fFramebufferInfo do begin Init(pbR8G8B8{FIXME}, aWidth, aHeight); assert(PixelSize <= aDepth); PixelSize := aDepth; // FIXME RowStride := ; end; end; function TPixmap.FramebufferInfo : TFramebufferInfoP; begin Result := @fFramebufferInfo; end; end.