diff options
author | drewski207 <drewski207@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-22 21:05:38 +0000 |
---|---|---|
committer | drewski207 <drewski207@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-22 21:05:38 +0000 |
commit | 49e51459783e1de062551fe86ae7030582c81aa7 (patch) | |
tree | 3d68f87d9942df98799b8eb28df53c63bba67896 /src/corelib | |
parent | bba6d008d8b9bb7a8129fa23d0edea0bfde2e059 (diff) | |
download | fpGUI-49e51459783e1de062551fe86ae7030582c81aa7.tar.xz |
* Increased double buffer on x11 efficiency
* Fixed a bug on listbox that allowed Item 0 to be selected with the mouse
* Fixed a possible bug for TfpgTimer that possibly could allow
timers to be skipped if timer(s) were destroyed during the callback
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/fpgfx.pas | 20 | ||||
-rw-r--r-- | src/corelib/x11/gfx_x11.pas | 50 |
2 files changed, 61 insertions, 9 deletions
diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas index cb6c0092..3125bef2 100644 --- a/src/corelib/fpgfx.pas +++ b/src/corelib/fpgfx.pas @@ -369,8 +369,17 @@ var ctime: TDateTime; begin ctime := now; - for i := 0 to fpgTimers.Count-1 do - TfpgTimer(fpgTimers[i]).CheckAlarm(ctime); + i := 0; + + while i < fpgTimers.Count do + begin + if fpgTimers[i] = nil then + fpgTimers.Delete(i) + else begin + TfpgTimer(fpgTimers[i]).CheckAlarm(ctime); + Inc(i); + end; + end; end; function fpgClosestTimer(ctime: TDateTime; amaxtime: integer): integer; @@ -387,7 +396,7 @@ begin for i := 0 to fpgTimers.Count-1 do begin t := TfpgTimer(fpgTimers[i]); - if t.Enabled and (t.NextAlarm < dt) then + if (t <> nil) and t.Enabled and (t.NextAlarm < dt) then begin dt := t.NextAlarm; tb := True; @@ -597,7 +606,7 @@ var begin i := fpgTimers.IndexOf(self); if i > -1 then - fpgTimers.Delete(i); + fpgTimers[i] := nil; // we free the item in fpgCheckTimers inherited Destroy; end; @@ -751,7 +760,8 @@ begin fpgCaret.Free; for i := fpgTimers.Count-1 downto 0 do - TfpgTimer(fpgTimers[i]).Free; + if fpgTimers[i] <> nil then + TfpgTimer(fpgTimers[i]).Free; fpgTimers.Free; FDefaultFont.Free; diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index 7fea5804..e505ed1f 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -132,6 +132,8 @@ type end; + { TfpgCanvasImpl } + TfpgCanvasImpl = class(TfpgCanvasBase) private FDrawing: boolean; @@ -147,6 +149,8 @@ type FClipRegion: TRegion; FPixHeight, FPixWidth: Integer; + FBufferFreeTimer: TObject; + procedure BufferFreeTimer(Sender: TObject); procedure TryFreePixmap; protected procedure DoSetFontRes(fntres: TfpgFontResourceBase); override; @@ -1688,6 +1692,7 @@ destructor TfpgCanvasImpl.Destroy; begin if FDrawing then DoEndDraw; + FreeAndNil(FBufferFreeTimer); TryFreePixmap; inherited Destroy; end; @@ -1730,13 +1735,41 @@ begin if buffered then begin - if (FastDoubleBuffer = False) or (FBufferPixmap = 0) or (w <> FPixWidth) or (h <> FPixHeight) then + if (FBufferPixmap = 0) + or (FastDoubleBuffer = False) + or (FastDoubleBuffer and (w > FPixWidth) or (h > FPixHeight)) + or ((FastDoubleBuffer = False) and ((w <> FPixWidth) or (h <> FPixHeight))) + then begin + if FastDoubleBuffer and ((w > FPixWidth) or (h > FPixHeight)) then + begin + FPixHeight := h + 30; + FPixWidth := w + 30; + end + else begin + FPixHeight := h; + FPixWidth := w; + end; TryFreePixmap; - FBufferPixmap := XCreatePixmap(xapplication.display, FDrawWindow.FWinHandle, w, h, xapplication.DisplayDepth); + FBufferPixmap := XCreatePixmap(xapplication.display, FDrawWindow.FWinHandle, FPixWidth, FPixHeight, xapplication.DisplayDepth); + end; + if FastDoubleBuffer then + begin + // Rapid paint events reuse the double buffer which resests a delay + // After the delay the double buffer is freed, letting the OS use video + // memory if needed. + // Things like scrolling and resizing are fast + + // Reset the timers next trigger + if FBufferFreeTimer = nil then + begin + FBufferFreeTimer := TfpgTimer.Create(500); + TfpgTimer(FBufferFreeTimer).OnTimer := @BufferFreeTimer; + end + else + TfpgTimer(FBufferFreeTimer).Enabled := False; + TfpgTimer(FBufferFreeTimer).Enabled := True; end; - FPixHeight := h; - FPixWidth := w; FDrawHandle := FBufferPixmap; end else @@ -1836,6 +1869,15 @@ begin Trunc(64 * a1), Trunc(64 * a2)); end; +procedure TfpgCanvasImpl.BufferFreeTimer(Sender: TObject); +begin + {$IFDEF DEBUG} + WriteLn('fpGFX/X11: Freeing Buffer w=', FPixWidth, ' h=', FPixHeight); + {$ENDIF} + TryFreePixmap; + FreeAndNil(FBufferFreeTimer); +end; + procedure TfpgCanvasImpl.TryFreePixmap; begin if FBufferPixmap > 0 then |