LazMapViewer: Introduce fast FillPixels as new drawingengine method in order to avoid using the blank tile image.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8834 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2023-06-13 11:26:22 +00:00
parent 834d895879
commit d9eb6e9065
6 changed files with 59 additions and 24 deletions

View File

@ -58,6 +58,7 @@ type
UseAlphaChannel: Boolean); override;
procedure DrawLazIntfImage(X, Y: Integer; AImg: TLazIntfImage); override;
procedure Ellipse(X1, Y1, X2, Y2: Integer); override;
procedure FillPixels(X1, Y1, X2, Y2: Integer; AColor: TColor); override;
procedure FillRect(X1, Y1, X2, Y2: Integer); override;
procedure Line(X1, Y1, X2, Y2: Integer); override;
procedure PaintToCanvas(ACanvas: TCanvas); override;
@ -142,6 +143,17 @@ begin
FBuffer.CanvasBGRA.Ellipse(X1, Y1, X2, Y2);
end;
procedure TMvBGRADrawingEngine.FillPixels(X1, Y1, X2, Y2: Integer;
AColor: TColor);
var
savedColor: TColor;
begin
savedColor := FBuffer.CanvasBGRA.Brush.Color;
FBuffer.CanvasBGRA.Brush.Color := AColor;
FillRect(X1, Y1, X2, Y2);
FBuffer.CanvasBGRA.Brush.Color := savedColor;
end;
procedure TMvBGRADrawingEngine.FillRect(X1, Y1, X2, Y2: Integer);
begin
FBuffer.CanvasBGRA.FillRect(X1, Y1, X2, Y2);

View File

@ -58,6 +58,7 @@ type
UseAlphaChannel: Boolean); override;
procedure DrawLazIntfImage(X, Y: Integer; AImg: TLazIntfImage); override;
procedure Ellipse(X1, Y1, X2, Y2: Integer); override;
procedure FillPixels(X1, Y1, X2, Y2: Integer; AColor: TColor); override;
procedure FillRect(X1, Y1, X2, Y2: Integer); override;
procedure Line(X1, Y1, X2, Y2: Integer); override;
procedure PaintToCanvas(ACanvas: TCanvas); override;
@ -152,6 +153,24 @@ begin
FBuffer.Canvas.Ellipse(X1, Y1, X2, Y2);
end;
procedure TMvRGBGraphicsDrawingEngine.FillPixels(X1, Y1, X2, Y2: Integer;
AColor: TColor);
var
x, y: Integer;
begin
if (X1 >= FBuffer.Width) or (X2 < 0) or (Y1 >= FBuffer.Height) or (Y2 < 0) then
exit;
if X1 < 0 then X1 := 0;
if Y1 < 0 then Y1 := 0;
if X2 >= FBuffer.Width then X2 := FBuffer.Width - 1;
if Y2 >= FBuffer.Height then Y2 := FBuffer.Height - 1;
for y := Y1 to Y2 do
for x := X1 to X2 do
FBuffer.Set32Pixel(x, y, AColor);
end;
procedure TMvRGBGraphicsDrawingEngine.FillRect(X1, Y1, X2, Y2: Integer);
begin
FBuffer.Canvas.FillRect(X1, Y1, X2, Y2);

View File

@ -55,6 +55,7 @@ type
UseAlphaChannel: Boolean); override;
procedure DrawLazIntfImage(X, Y: Integer; AImg: TLazIntfImage); override;
procedure Ellipse(X1, Y1, X2, Y2: Integer); override;
procedure FillPixels(X1, Y1, X2, Y2: Integer; AColor: TColor); override;
procedure FillRect(X1, Y1, X2, Y2: Integer); override;
procedure Line(X1, Y1, X2, Y2: Integer); override;
procedure PaintToCanvas(ACanvas: TCanvas); override;
@ -228,6 +229,26 @@ begin
FCanvas.Ellipse(X1,Y1, X2, Y2);
end;
procedure TMvIntfGraphicsDrawingEngine.FillPixels(X1, Y1, X2, Y2: Integer;
AColor: TColor);
var
c: TFPColor;
x, y: Integer;
begin
if (X1 >= FBuffer.Width) or (X2 < 0) or (Y1 >= FBuffer.Height) or (Y2 < 0) then
exit;
if X1 < 0 then X1 := 0;
if Y1 < 0 then Y1 := 0;
if X2 >= FBuffer.Width then X2 := FBuffer.Width - 1;
if Y2 >= FBuffer.Height then Y2 := FBuffer.Height - 1;
c := TColorToFPColor(ColorToRGB(AColor));
for y := Y1 to Y2 do
for x := X1 to X2 do
FBuffer.Colors[x, y] := c;
end;
procedure TMvIntfGraphicsDrawingEngine.FillRect(X1, Y1, X2, Y2: Integer);
begin
if FCanvas <> nil then

View File

@ -44,6 +44,7 @@ type
UseAlphaChannel: Boolean); virtual; abstract;
procedure DrawLazIntfImage(X, Y: Integer; AImg: TLazIntfImage); virtual; abstract;
procedure Ellipse(X1, Y1, X2, Y2: Integer); virtual; abstract;
procedure FillPixels(X1, Y1, X2, Y2: Integer; AColor: TColor); virtual; abstract;
procedure FillRect(X1, Y1, X2, Y2: Integer); virtual; abstract;
procedure Line(X1, Y1, X2, Y2: Integer); virtual; virtual; abstract;
procedure PaintToCanvas(ACanvas: TCanvas); virtual; abstract;

View File

@ -63,7 +63,6 @@ type
FCyclic: Boolean;
FDownloadEngine: TMvCustomDownloadEngine;
FDrawTitleInGuiThread: boolean;
FEmptyTileImg: TLazIntfImage;
FOnCenterMove: TNotifyEvent;
FOnChange: TNotifyEvent;
FOnDrawTile: TDrawTileEvent;
@ -107,7 +106,6 @@ type
function IsCurrentWin(const aWin: TMapWindow) : boolean;
protected
procedure AdjustZoomCenter(var AWin: TMapWindow);
function CreateBlankImg: TLazIntfImage;
procedure ConstraintZoom(var aWin: TMapWindow);
function GetTileName(const Id: TTileId): String;
procedure evDownload(Data: TObject; Job: TJob);
@ -383,7 +381,6 @@ begin
Cache := TPictureCache.Create(self);
lstProvider := TStringList.Create;
FBkColor := colWhite;
FEmptyTileImg := CreateBlankImg;
RegisterProviders;
Queue := TJobQueue.Create(8);
Queue.OnIdle := @Cache.CheckCacheSize;
@ -402,7 +399,6 @@ begin
FreeAndNil(lstProvider);
FreeAndNil(Cache);
FreeAndNil(Queue);
FreeAndNil(FEmptyTileImg);
inherited Destroy;
end;
@ -493,22 +489,6 @@ begin
end;
end;
function TMapViewerEngine.CreateBlankImg: TLazIntfImage;
var
rawImg: TRawImage;
begin
rawImg.Init;
{$IFDEF DARWIN}
rawImg.Description.Init_BPP32_A8R8G8B8_BIO_TTB(TILE_SIZE, TILE_SIZE);
{$ELSE}
rawImg.Description.Init_BPP32_B8G8R8_BIO_TTB(TILE_SIZE, TILE_SIZE);
{$ENDIF}
rawImg.CreateData(True);
Result := TLazIntfImage.Create(rawImg, true);
Result.FillPixels(FBkColor);
end;
{ Returns true when the visible window crosses the date line, i.e. the longitudes
at the left of the window are > 0, and those at the right are < 0. }
function TMapViewerEngine.CrossesDateline: Boolean;
@ -1088,7 +1068,7 @@ begin
begin
py := AWin.Y + Y * TILE_SIZE;
px := AWin.X + X * TILE_SIZE;
DrawTile(Tiles[iTile], px, py, FEmptyTileImg);
DrawTile(Tiles[iTile], px, py, nil);
end;
if IsValidTile(AWin, Tiles[iTile]) then
@ -1279,7 +1259,6 @@ procedure TMapViewerEngine.SetBkColor(AValue: TFPColor);
begin
if FBkColor = AValue then Exit;
FBkColor := AValue;
FEmptyTileImg.FillPixels(FBkColor);
Redraw(MapWin);
end;

View File

@ -830,12 +830,15 @@ begin
if Assigned(TileImg) then begin
DrawingEngine.DrawLazIntfImage(X, Y, TileImg);
end
else begin
else
DrawingEngine.FillPixels(X, Y, X + TILE_SIZE, Y + TILE_SIZE, InactiveColor);
{
DrawingEngine.BrushColor := InactiveColor;
DrawingEngine.BrushStyle := bsSolid;
DrawingEngine.FillRect(X, Y, X + TILE_SIZE, Y + TILE_SIZE);
end;
}
if FDebugTiles then
DoDrawTileInfo(TileID, X, Y);