From 2033ca876d0553f147c8f87114191f27041a24d4 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Tue, 22 Nov 2011 16:36:41 +0000 Subject: [PATCH] customdrawnws: Switches to using XShm and now things are getting really faster git-svn-id: trunk@33698 - --- .../customdrawn/customdrawndefines.inc | 1 + .../customdrawn/customdrawnwsforms.pp | 7 +++- .../customdrawn/customdrawnwsforms_x11.inc | 42 ++++++------------- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/lcl/interfaces/customdrawn/customdrawndefines.inc b/lcl/interfaces/customdrawn/customdrawndefines.inc index 4df8f84e28..e69dbba909 100644 --- a/lcl/interfaces/customdrawn/customdrawndefines.inc +++ b/lcl/interfaces/customdrawn/customdrawndefines.inc @@ -15,6 +15,7 @@ {$define CD_Cocoa} {$else} {$define CD_X11} + {$define CD_X11_USE_XSHM} {$endif} {$endif} {$endif} diff --git a/lcl/interfaces/customdrawn/customdrawnwsforms.pp b/lcl/interfaces/customdrawn/customdrawnwsforms.pp index 0ae27be5de..f9f8bf3203 100644 --- a/lcl/interfaces/customdrawn/customdrawnwsforms.pp +++ b/lcl/interfaces/customdrawn/customdrawnwsforms.pp @@ -34,7 +34,12 @@ uses SysUtils, Classes, types, ctypes, {$ifdef CD_Windows}Windows, WinProc,{$endif} {$ifdef CD_Cocoa}MacOSAll, CocoaAll, CocoaPrivate, CocoaUtils,{$endif} - {$ifdef CD_X11}X, XLib, XUtil, XAtom, x11proc,{unitxft, Xft font support}{$endif} + {$ifdef CD_X11} + {$ifdef CD_X11_USE_XSHM} + XShm, + {$endif} + X, XLib, XUtil, XAtom, x11proc,{unitxft, Xft font support} + {$endif} // LazUtils lazutf8sysutils, // LCL diff --git a/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc b/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc index 85e50ee0ee..86e54b1ea7 100644 --- a/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc +++ b/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc @@ -248,11 +248,8 @@ begin {$IFDEF VerboseCDPaintProfiler} lTimeStart := NowUTC(); {$ENDIF} -(* {$IFDEF VerboseFPGUI} - WriteLn('>: DoDrawImageRect'); - {$ENDIF}*) - // !!!: Add support for XF86 4 and XShm etc. to speed this up! + // Create a native Image Image := XCreateImage(CDWidgetSet.FDisplay, ADestWindowInfo.Attr.Visual, ADestWindowInfo.ColorDepth, XYPixmap, 0, PChar(ARawImage.Data), ADestWidth, ADestHeight, 32, (ADestWindowInfo.Canvas.Width*ADestWindowInfo.ColorDepth) div 8); @@ -262,35 +259,20 @@ begin [PtrInt(Image), PtrInt(ARawImage.Data)])); {$ENDIF} -(* { Here its necessary to alloc an extra byte, otherwise it will fail on 32-bits - machines, but still work on 64-bits machines. The cause of this is unknown. } - Image^.data := GetMem(Image^.bytes_per_line * (ASourceRect.Bottom - ASourceRect.Top) + 1); - - if (AImage.PixelFormat.FormatType = ftMono) and - Self.InheritsFrom(TX11MonoPixmapCanvas) then - // mirror the bits within all image data bytes...: - FlipMonoImageBits(ASourceRect, TX11Bitmap(AImage).Data, - TX11Bitmap(AImage).Stride, 0, 0, Image^.data, Image^.bytes_per_line) - else - begin - ConvertFormat := PixelFormat; - - { !!!: The following is a workaround: At least the XFree86 X server for - ATI graphics adapters uses 32 bit padding per pixel for 24 bpp - images...?!? To be checked: Is this always the case or only for ATI? } - if ConvertFormat.FormatType = ftRGB24 then - ConvertFormat.FormatType := ftRGB32; - - ConvertImage(ASourceRect, AImage.PixelFormat, AImage.Palette, - TX11Bitmap(AImage).Data, TX11Bitmap(AImage).Stride, - 0, 0, ConvertFormat, Image^.data, Image^.bytes_per_line); - end;*) + {$ifdef CD_X11_USE_XSHM} + // Draw the image in the window + XShmPutImage(CDWidgetSet.FDisplay, ADestWindowInfo.Window, ADestWindowInfo.GC, + Image, 0, 0, ADestX, ADestY, ADestWidth, ADestHeight, False); + {$else} + // XPutImage is ridiculously slow, really unusable. XPutImage(CDWidgetSet.FDisplay, ADestWindowInfo.Window, ADestWindowInfo.GC, Image, 0, 0, ADestX, ADestY, ADestWidth, ADestHeight); + {$endif} + + // Free the native image + Image^.data := nil; + XDestroyImage(Image); -// FreeMem(Image^.data); -// Image^.data := nil; -// XDestroyImage(Image); {$IFDEF VerboseCDPaintProfiler} DebugLn(Format('[TCDWSCustomForm.DrawRawImageToGC] Paint duration: %d ms', [DateTimeToMilliseconds(NowUTC() - lTimeStart)])); {$ENDIF}