Qt: reduce getSysColor() overhead by caching colors.

git-svn-id: trunk@17700 -
This commit is contained in:
zeljko 2008-12-06 13:03:05 +00:00
parent f7e1b1b5ac
commit 738fb1f569
3 changed files with 78 additions and 54 deletions

View File

@ -67,6 +67,8 @@ type
FDockImage: QRubberBandH;
FDragImageList: QWidgetH;
FDragHotSpot: TPoint;
FCachedColors: Array[0..MAX_SYS_COLORS + 1] of PLongWord;
procedure ClearCachedColors;
procedure SetOverrideCursor(const AValue: TObject);
protected
FStockNullBrush: HBRUSH;

View File

@ -29,6 +29,7 @@ begin
App := QApplication_Create(@argc, argv);
InitStockItems;
QtWidgetSet := Self;
ClearCachedColors;
FDockImage := nil;
end;
@ -55,6 +56,8 @@ begin
QtDefaultContext.Free;
QtScreenContext.Free;
ClearCachedColors;
inherited Destroy;
end;
@ -290,6 +293,7 @@ var
begin
Result := False;
case QEvent_type(Event) of
QEventStyleChange: ClearCachedColors;
LCLQt_Destroy:
begin
AObject := TQtObject(Pointer(QLCLMessageEvent_getWParam(QLCLMessageEventH(Event))));
@ -641,4 +645,16 @@ begin
FStockDefaultDC := 0; // app must be initialized
end;
procedure TQtWidgetSet.ClearCachedColors;
var
i: Integer;
begin
for i := 0 to High(FCachedColors) do
begin
if FCachedColors[i] <> nil then
FreeMem(FCachedColors[i]);
FCachedColors[i] := nil;
end;
end;
//------------------------------------------------------------------------

View File

@ -2778,6 +2778,8 @@ begin
exit;
end;
if FCachedColors[nIndex] = nil then
begin
case nIndex of
{$IFDEF USE_QT_44}
COLOR_SCROLLBAR : Result:=GetColor(QPaletteActive, QPaletteButton);
@ -2833,6 +2835,10 @@ begin
else
Result:=0;
end;
FCachedColors[nIndex] := getMem(SizeOf(LongWord));
FCachedColors[nIndex]^ := Result;
end else
Result := FCachedColors[nIndex]^;
end;
{------------------------------------------------------------------------------