Changeset 552 for trunk/Packages


Ignore:
Timestamp:
Apr 24, 2024, 10:28:34 AM (3 weeks ago)
Author:
chronos
Message:
  • Modified: Optimized high DPI scaling. Use lookup table for scaled values. Draw only terrain textures with precise scaling.
Location:
trunk/Packages/DpiControls
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/DpiControls/Dpi.Common.pas

    r547 r552  
    1515  XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean;
    1616function BitBltBitmap(Dest: TBitmap; X, Y, Width, Height: Integer; Src: TBitmap;
    17   XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean;
     17  XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY; Precise: Boolean = False): Boolean;
    1818function CreateRectRgn(X1, Y1, X2, Y2: Integer): HRGN;
    1919{$IFDEF WINDOWS}
     
    5656
    5757function BitBltBitmap(Dest: TBitmap; X, Y, Width, Height: Integer;
    58   Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD): Boolean;
     58  Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY;
     59  Precise: Boolean = False): Boolean;
    5960var
    6061  SrcPixel: TPixelPointer;
     
    6566  NewX, NewY: Integer;
    6667begin
    67   if Frac(ScreenInfo.Dpi / 96) = 0 then
    68   begin
     68  if not Precise or (Frac(ScreenInfo.Dpi / 96) = 0) then begin
    6969    // Use faster non-fractional scaling
    7070    Result := BitBlt(Dest.Canvas.Handle, X, Y, Width, Height, Src.Canvas.Handle,
     
    238238function ScaleToNative(Value: Integer): Integer;
    239239begin
    240   // Round function is faster than Ceil and Floor
    241   Result := Round(Value * ScreenInfo.ToNative);
     240  Result := ScreenInfo.Lookup[Value];
     241  // Round and Trunc are fast. Ceil and Floor slow.
     242  // Without lookup table we would use:
     243  // Result := Ceil(Value * ScreenInfo.ToNative);
    242244end;
    243245
     
    249251function ScaleFromNative(Value: Integer): Integer;
    250252begin
    251   Result := Floor(Value * ScreenInfo.FromNative);
     253  Result := Trunc(Value * ScreenInfo.FromNative);
    252254end;
    253255
  • trunk/Packages/DpiControls/Dpi.Graphics.pas

    r548 r552  
    44
    55uses
    6   Classes, SysUtils, Graphics, LCLType, GraphType, Types;
     6  Classes, SysUtils, Math, Graphics, LCLType, GraphType, Types;
    77
    88const
     
    347347    ToNative: Double;
    348348    FromNative: Double;
     349    Lookup: array[-10000..10000] of Integer; // Should be sufficient for 8K screens
    349350    property Dpi: Integer read FDpi write SetDpi;
    350351  end;
     
    13221323
    13231324procedure TScreenInfo.SetDpi(AValue: Integer);
     1325var
     1326  I: Integer;
    13241327begin
    13251328  if FDpi = AValue then Exit;
     
    13271330  ToNative := ScreenInfo.Dpi / 96;
    13281331  FromNative := 96 / ScreenInfo.Dpi;
     1332  for I := -10000 to 10000 do
     1333    Lookup[I] := Ceil(I * ToNative);
    13291334end;
    13301335
Note: See TracChangeset for help on using the changeset viewer.