2019-04-04 10:26:44 +02:00
|
|
|
unit uCEFFMXBufferPanel;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF MSWINDOWS}
|
2020-03-05 11:15:47 +01:00
|
|
|
Winapi.Windows, FMX.Platform.Win,
|
2018-01-25 21:34:04 +01:00
|
|
|
{$ELSE}
|
|
|
|
System.SyncObjs,
|
|
|
|
{$ENDIF}
|
|
|
|
System.Classes, System.UIConsts, System.Types, System.UITypes,
|
2021-12-08 17:45:03 +01:00
|
|
|
{$IFDEF DELPHI19_UP}
|
2018-01-25 21:34:04 +01:00
|
|
|
FMX.Graphics,
|
|
|
|
{$ENDIF}
|
2020-03-05 11:15:47 +01:00
|
|
|
FMX.Types, FMX.Controls, FMX.Forms,
|
2022-10-14 16:35:50 +02:00
|
|
|
uCEFTypes, uCEFConstants;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
type
|
|
|
|
TDialogKeyEvent = procedure(Sender: TObject; var Key: Word; Shift: TShiftState) of object;
|
|
|
|
|
2022-10-14 16:35:50 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pfidWindows or pfidOSX or pfidLinux)]{$ENDIF}{$ENDIF}
|
2023-08-08 20:19:19 +02:00
|
|
|
/// <summary>
|
|
|
|
/// TBufferPanel is used by FMX applications with browsers in OSR mode
|
|
|
|
/// to draw the browser contents. See the FMXExternalPumpBrowser demo for more details.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
TFMXBufferPanel = class(TControl)
|
|
|
|
protected
|
|
|
|
{$IFDEF MSWINDOWS}
|
2020-12-20 12:28:56 +01:00
|
|
|
FMutex : THandle;
|
2018-01-25 21:34:04 +01:00
|
|
|
{$ELSE}
|
2020-12-20 12:28:56 +01:00
|
|
|
FBufferCS : TCriticalSection;
|
2018-01-25 21:34:04 +01:00
|
|
|
{$ENDIF}
|
2020-12-20 12:28:56 +01:00
|
|
|
FBuffer : TBitmap;
|
|
|
|
FScanlineSize : integer;
|
|
|
|
FColor : TAlphaColor;
|
|
|
|
FHighSpeedDrawing : boolean;
|
|
|
|
FOnDialogKey : TDialogKeyEvent;
|
|
|
|
FForcedDeviceScaleFactor : single;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
procedure CreateSyncObj;
|
|
|
|
|
|
|
|
procedure DestroySyncObj;
|
|
|
|
procedure DestroyBuffer;
|
|
|
|
|
2020-12-20 12:28:56 +01:00
|
|
|
function GetScreenScale : single; virtual;
|
2018-01-25 21:34:04 +01:00
|
|
|
function GetBufferWidth : integer;
|
|
|
|
function GetBufferHeight : integer;
|
2020-03-05 11:15:47 +01:00
|
|
|
function GetParentForm : TCustomForm;
|
|
|
|
function GetParentFormHandle : TCefWindowHandle;
|
2020-12-20 12:28:56 +01:00
|
|
|
function GetRealScreenScale(var aResultScale : single) : boolean; virtual;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
function CopyBuffer : boolean;
|
|
|
|
function SaveBufferToFile(const aFilename : string) : boolean;
|
|
|
|
|
|
|
|
procedure Paint; override;
|
|
|
|
procedure DialogKey(var Key: Word; Shift: TShiftState); override;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure AfterConstruction; override;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Save the visible web contents as a bitmap file.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
function SaveToFile(const aFilename : string) : boolean;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Invalidate this panel.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure InvalidatePanel;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Acquires the synchronization object before drawing into the background bitmap.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
function BeginBufferDraw : boolean;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Releases the synchronization object after drawing into the background bitmap.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure EndBufferDraw;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Draws a part of aBitmap into the background bitmap buffer at the specified rectangle.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="aBitmap">Bitmap that will be drawn into the background bitmap.</param>
|
|
|
|
/// <param name="aSrcRect">Rectangle that defines the area of aBitmap that will be drawn into the background bitmap.</param>
|
|
|
|
/// <param name="aDstRect">Rectangle that defines the area of the background bitmap where aBitmap will be drawn.</param>
|
2020-03-18 18:37:55 +01:00
|
|
|
procedure BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRectF);
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Update the background bitmap size.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
function UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Check if the background image buffers have the same dimensions as this panel. Returns true if they have the same size.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
function BufferIsResized(aUseMutex : boolean = True) : boolean;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Convert a point from the screen coordinate system to the client coordinate system.
|
|
|
|
/// </summary>
|
2020-03-05 11:15:47 +01:00
|
|
|
function ScreenToClient(aPoint : TPoint) : TPoint; overload;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Convert a point from the screen coordinate system to the client coordinate system.
|
|
|
|
/// </summary>
|
2020-03-05 11:15:47 +01:00
|
|
|
function ScreenToClient(aPoint : TPointF) : TPointF; overload;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Convert a point from the client coordinate system to the screen coordinate system.
|
|
|
|
/// </summary>
|
2020-03-05 11:15:47 +01:00
|
|
|
function ClientToScreen(aPoint : TPoint) : TPoint; overload;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Convert a point from the client coordinate system to the screen coordinate system.
|
|
|
|
/// </summary>
|
2020-03-05 11:15:47 +01:00
|
|
|
function ClientToScreen(aPoint : TPointF) : TPointF; overload;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Background bitmap.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property Buffer : TBitmap read FBuffer;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the scanline size.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ScanlineSize : integer read FScanlineSize;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image width.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property BufferWidth : integer read GetBufferWidth;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image height.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property BufferHeight : integer read GetBufferHeight;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the screen scale.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ScreenScale : single read GetScreenScale;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Screen scale value used instead of the real one.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ForcedDeviceScaleFactor : single read FForcedDeviceScaleFactor write FForcedDeviceScaleFactor;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
published
|
|
|
|
property Align;
|
|
|
|
property Anchors;
|
|
|
|
property Visible;
|
|
|
|
property Enabled;
|
|
|
|
property TabOrder;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Color used to clear the panel canvas in the Paint method.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
property Color : TAlphaColor read FColor write FColor default claWhite;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Set HighSpeedDrawing to True to draw the buffer to the canvas using a high speed interpolation mode.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
property HighSpeedDrawing : boolean read FHighSpeedDrawing write FHighSpeedDrawing default True;
|
|
|
|
|
|
|
|
{$IFDEF DELPHI17_UP}
|
|
|
|
property CanFocus;
|
|
|
|
property CanParentFocus;
|
|
|
|
property Height;
|
|
|
|
property Width;
|
|
|
|
property Padding;
|
|
|
|
property Opacity;
|
|
|
|
property Margins;
|
|
|
|
property Position;
|
|
|
|
property RotationAngle;
|
|
|
|
property RotationCenter;
|
|
|
|
property Scale;
|
2021-12-08 17:45:03 +01:00
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF DELPHI18_UP}
|
|
|
|
property TabStop;
|
2018-01-25 21:34:04 +01:00
|
|
|
property Size;
|
2022-03-06 10:21:37 +01:00
|
|
|
{$ENDIF}
|
2022-03-16 21:39:12 +01:00
|
|
|
{$IFDEF DELPHI25_UP}
|
2021-05-18 16:40:37 +02:00
|
|
|
property OnResized;
|
2018-01-25 21:34:04 +01:00
|
|
|
{$ENDIF}
|
2019-03-15 09:12:09 +01:00
|
|
|
{$IFNDEF DELPHI23_UP}
|
|
|
|
property Hint;
|
|
|
|
property ShowHint;
|
|
|
|
{$ENDIF}
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
property OnEnter;
|
|
|
|
property OnExit;
|
|
|
|
property OnResize;
|
|
|
|
property OnClick;
|
|
|
|
property OnMouseDown;
|
|
|
|
property OnMouseMove;
|
|
|
|
property OnMouseUp;
|
|
|
|
property OnMouseEnter;
|
|
|
|
property OnMouseLeave;
|
|
|
|
property OnMouseWheel;
|
|
|
|
property OnKeyUp;
|
|
|
|
property OnKeyDown;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered before the DialogKey.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
property OnDialogKey : TDialogKeyEvent read FOnDialogKey write FOnDialogKey;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils, System.Math,
|
2021-12-08 17:45:03 +01:00
|
|
|
{$IFDEF MSWINDOWS}{$IFDEF DELPHI24_UP}FMX.Helpers.Win,{$ENDIF}{$ENDIF}
|
2021-06-24 17:47:22 +02:00
|
|
|
FMX.Platform, {$IFDEF MACOS}FMX.Platform.Mac,{$ENDIF}
|
|
|
|
uCEFMiscFunctions, uCEFApplicationCore;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
constructor TFMXBufferPanel.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
FMutex := 0;
|
|
|
|
{$ELSE}
|
|
|
|
FBufferCS := nil;
|
|
|
|
{$ENDIF}
|
|
|
|
FBuffer := nil;
|
|
|
|
FScanlineSize := 0;
|
|
|
|
FColor := claWhite;
|
|
|
|
FOnDialogKey := nil;
|
|
|
|
FHighSpeedDrawing := True;
|
2020-12-20 12:28:56 +01:00
|
|
|
|
|
|
|
if (GlobalCEFApp <> nil) and (GlobalCEFApp.ForcedDeviceScaleFactor <> 0) then
|
|
|
|
FForcedDeviceScaleFactor := GlobalCEFApp.ForcedDeviceScaleFactor
|
|
|
|
else
|
|
|
|
FForcedDeviceScaleFactor := 0;
|
2018-01-25 21:34:04 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TFMXBufferPanel.Destroy;
|
|
|
|
begin
|
|
|
|
DestroyBuffer;
|
|
|
|
DestroySyncObj;
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.AfterConstruction;
|
|
|
|
begin
|
|
|
|
inherited AfterConstruction;
|
|
|
|
|
|
|
|
CreateSyncObj;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.CreateSyncObj;
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
FMutex := CreateMutex(nil, False, nil);
|
|
|
|
{$ELSE}
|
|
|
|
FBufferCS := TCriticalSection.Create;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.DestroySyncObj;
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (FMutex <> 0) then
|
|
|
|
begin
|
|
|
|
CloseHandle(FMutex);
|
|
|
|
FMutex := 0;
|
|
|
|
end;
|
|
|
|
{$ELSE}
|
|
|
|
if (FBufferCS <> nil) then FreeAndNil(FBufferCS);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.DestroyBuffer;
|
|
|
|
begin
|
|
|
|
if BeginBufferDraw then
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
|
|
|
EndBufferDraw;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.SaveBufferToFile(const aFilename : string) : boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
begin
|
|
|
|
FBuffer.SaveToFile(aFilename);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TFMXBufferPanel.SaveBufferToFile', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.SaveToFile(const aFilename : string) : boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
if BeginBufferDraw then
|
|
|
|
begin
|
|
|
|
Result := SaveBufferToFile(aFilename);
|
|
|
|
EndBufferDraw;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.InvalidatePanel;
|
|
|
|
begin
|
|
|
|
InvalidateRect(TRectF.Create(0, 0, Width, Height));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.BeginBufferDraw : boolean;
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
Result := (FMutex <> 0) and (WaitForSingleObject(FMutex, 5000) = WAIT_OBJECT_0);
|
|
|
|
{$ELSE}
|
|
|
|
if (FBufferCS <> nil) then
|
|
|
|
begin
|
|
|
|
FBufferCS.Acquire;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.EndBufferDraw;
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (FMutex <> 0) then ReleaseMutex(FMutex);
|
|
|
|
{$ELSE}
|
|
|
|
if (FBufferCS <> nil) then FBufferCS.Release;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.CopyBuffer : boolean;
|
|
|
|
var
|
2020-02-05 18:52:32 +01:00
|
|
|
TempSrc, TempDst, TempClip : TRectF;
|
|
|
|
TempState : TCanvasSaveState;
|
2020-03-05 11:15:47 +01:00
|
|
|
TempScale : single;
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
2020-03-29 17:31:42 +02:00
|
|
|
Result := False;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
if Canvas.BeginScene then
|
|
|
|
try
|
|
|
|
if BeginBufferDraw then
|
2020-02-05 18:52:32 +01:00
|
|
|
try
|
2018-01-25 21:34:04 +01:00
|
|
|
if (FBuffer <> nil) then
|
|
|
|
begin
|
2020-03-05 11:15:47 +01:00
|
|
|
TempScale := ScreenScale;
|
2020-02-05 18:52:32 +01:00
|
|
|
TempSrc := TRectF.Create(0, 0, FBuffer.Width, FBuffer.Height);
|
2020-03-05 11:15:47 +01:00
|
|
|
TempDst := TRectF.Create(0, 0, FBuffer.Width / TempScale, FBuffer.Height / TempScale);
|
2020-02-05 18:52:32 +01:00
|
|
|
TempClip := TRectF.Create(0, 0, Width, Height);
|
|
|
|
|
|
|
|
TempState := Canvas.SaveState;
|
|
|
|
try
|
2020-02-06 10:37:54 +01:00
|
|
|
Canvas.IntersectClipRect(TempClip);
|
2020-02-05 18:52:32 +01:00
|
|
|
Canvas.DrawBitmap(FBuffer, TempSrc, TempDst, 1, FHighSpeedDrawing);
|
|
|
|
Result := True;
|
|
|
|
finally
|
|
|
|
Canvas.RestoreState(TempState);
|
|
|
|
end;
|
2018-01-25 21:34:04 +01:00
|
|
|
end;
|
2020-02-05 18:52:32 +01:00
|
|
|
finally
|
2018-01-25 21:34:04 +01:00
|
|
|
EndBufferDraw;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Canvas.EndScene;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.DialogKey(var Key: Word; Shift: TShiftState);
|
|
|
|
begin
|
|
|
|
if assigned(FOnDialogKey) then FOnDialogKey(self, Key, Shift);
|
|
|
|
|
|
|
|
inherited DialogKey(Key, Shift);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXBufferPanel.Paint;
|
|
|
|
var
|
|
|
|
TempRect : TRectF;
|
|
|
|
begin
|
|
|
|
if (csDesigning in ComponentState) or not(CopyBuffer) then
|
|
|
|
begin
|
|
|
|
TempRect := TRectF.Create(0, 0, Width, Height);
|
|
|
|
|
|
|
|
if Canvas.BeginScene then
|
|
|
|
try
|
|
|
|
Canvas.ClearRect(TempRect, FColor);
|
|
|
|
finally
|
|
|
|
Canvas.EndScene;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-03-05 11:15:47 +01:00
|
|
|
function TFMXBufferPanel.GetParentForm : TCustomForm;
|
|
|
|
var
|
|
|
|
TempComp : TComponent;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
TempComp := Owner;
|
|
|
|
|
|
|
|
while (TempComp <> nil) do
|
|
|
|
if (TempComp is TCustomForm) then
|
|
|
|
begin
|
|
|
|
Result := TCustomForm(TempComp);
|
|
|
|
exit;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
TempComp := TempComp.owner;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.GetParentFormHandle : TCefWindowHandle;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
var
|
|
|
|
TempForm : TCustomForm;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
2021-02-21 18:41:25 +01:00
|
|
|
InitializeWindowHandle(Result);
|
2020-03-05 11:15:47 +01:00
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
TempForm := GetParentForm;
|
|
|
|
|
|
|
|
if (TempForm <> nil) then
|
|
|
|
Result := FmxHandleToHWND(TempForm.Handle)
|
|
|
|
else
|
|
|
|
if (Application <> nil) and
|
|
|
|
(Application.MainForm <> nil) then
|
|
|
|
Result := FmxHandleToHWND(Application.MainForm.Handle);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2020-12-20 12:28:56 +01:00
|
|
|
function TFMXBufferPanel.GetRealScreenScale(var aResultScale : single) : boolean;
|
2021-01-14 16:03:04 +01:00
|
|
|
{$IFDEF DELPHI24_UP}{$IFDEF MSWINDOWS}
|
2020-03-05 11:15:47 +01:00
|
|
|
var
|
|
|
|
TempHandle : TCefWindowHandle;
|
2021-01-14 16:03:04 +01:00
|
|
|
{$ENDIF}{$ENDIF}
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
2021-06-24 17:47:22 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$IFDEF DELPHI24_UP}
|
2020-03-05 11:15:47 +01:00
|
|
|
TempHandle := GetParentFormHandle;
|
|
|
|
|
|
|
|
if (TempHandle <> 0) then
|
2020-12-20 12:28:56 +01:00
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
aResultScale := GetWndScale(TempHandle);
|
2021-07-03 09:59:24 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
aResultScale := 1;
|
2020-12-20 12:28:56 +01:00
|
|
|
end;
|
2021-07-03 09:59:24 +02:00
|
|
|
{$ELSE}
|
|
|
|
Result := False;
|
|
|
|
aResultScale := 1;
|
2021-06-24 17:47:22 +02:00
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF LINUX}
|
2022-06-26 17:53:54 +02:00
|
|
|
if (Screen.DisplayCount = 1) then
|
|
|
|
aResultScale := Screen.Displays[0].Scale
|
|
|
|
else
|
|
|
|
aResultScale := Screen.DisplayFromForm(GetParentForm).Scale;
|
|
|
|
|
|
|
|
Result := True;
|
2021-06-24 17:47:22 +02:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF MACOS}
|
|
|
|
Result := True;
|
|
|
|
aResultScale := TMacWindowHandle(GetParentForm.Handle).Wnd.backingScaleFactor;
|
|
|
|
{$ENDIF}
|
2020-12-20 12:28:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.GetScreenScale : single;
|
|
|
|
var
|
|
|
|
TempScale : single;
|
|
|
|
begin
|
|
|
|
if (FForcedDeviceScaleFactor <> 0) then
|
|
|
|
Result := FForcedDeviceScaleFactor
|
|
|
|
else
|
|
|
|
if GetRealScreenScale(TempScale) then
|
|
|
|
Result := TempScale
|
2020-03-05 11:15:47 +01:00
|
|
|
else
|
2020-12-20 12:28:56 +01:00
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
Result := GlobalCEFApp.DeviceScaleFactor
|
|
|
|
else
|
|
|
|
Result := 1;
|
2018-01-25 21:34:04 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.GetBufferWidth : integer;
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
Result := FBuffer.Width
|
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.GetBufferHeight : integer;
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
Result := FBuffer.Height
|
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
2020-03-18 18:37:55 +01:00
|
|
|
procedure TFMXBufferPanel.BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRectF);
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then
|
2020-03-18 18:37:55 +01:00
|
|
|
if FBuffer.Canvas.BeginScene then
|
|
|
|
try
|
|
|
|
FBuffer.Canvas.DrawBitmap(aBitmap, aSrcRect, aDstRect, 1, FHighSpeedDrawing);
|
|
|
|
finally
|
|
|
|
FBuffer.Canvas.EndScene;
|
|
|
|
end;
|
2018-01-25 21:34:04 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
2021-12-08 17:45:03 +01:00
|
|
|
{$IFDEF DELPHI18_UP}
|
2020-03-05 11:15:47 +01:00
|
|
|
var
|
|
|
|
TempScale : single;
|
2021-12-08 17:45:03 +01:00
|
|
|
{$ENDIF}
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
2020-03-18 18:37:55 +01:00
|
|
|
Result := False;
|
2021-12-08 17:45:03 +01:00
|
|
|
{$IFDEF DELPHI18_UP}
|
2020-03-05 11:15:47 +01:00
|
|
|
TempScale := ScreenScale;
|
2021-12-08 17:45:03 +01:00
|
|
|
{$ENDIF}
|
2018-01-25 21:34:04 +01:00
|
|
|
|
2020-03-05 11:15:47 +01:00
|
|
|
if ((FBuffer = nil) or
|
2021-12-08 17:45:03 +01:00
|
|
|
{$IFDEF DELPHI18_UP}
|
2020-03-05 11:15:47 +01:00
|
|
|
(FBuffer.BitmapScale <> TempScale) or
|
2021-12-08 17:45:03 +01:00
|
|
|
{$ENDIF}
|
2020-03-05 11:15:47 +01:00
|
|
|
(FBuffer.Width <> aWidth) or
|
|
|
|
(FBuffer.Height <> aHeight)) then
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
|
|
|
|
|
|
|
FBuffer := TBitmap.Create(aWidth, aHeight);
|
2021-12-08 17:45:03 +01:00
|
|
|
{$IFDEF DELPHI18_UP}
|
2020-03-05 11:15:47 +01:00
|
|
|
FBuffer.BitmapScale := TempScale;
|
2018-01-25 21:34:04 +01:00
|
|
|
FScanlineSize := FBuffer.BytesPerLine;
|
|
|
|
{$ELSE}
|
|
|
|
FScanlineSize := aWidth * SizeOf(TRGBQuad);
|
|
|
|
{$ENDIF}
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.BufferIsResized(aUseMutex : boolean) : boolean;
|
|
|
|
var
|
|
|
|
TempWidth, TempHeight : integer;
|
2020-03-05 11:15:47 +01:00
|
|
|
TempScale : single;
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
if not(aUseMutex) or BeginBufferDraw then
|
|
|
|
begin
|
2020-03-05 11:15:47 +01:00
|
|
|
TempScale := ScreenScale;
|
|
|
|
TempWidth := round(Width * TempScale);
|
|
|
|
TempHeight := round(Height * TempScale);
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
Result := (FBuffer <> nil) and
|
2021-12-08 17:45:03 +01:00
|
|
|
{$IFDEF DELPHI18_UP}
|
2020-03-05 11:15:47 +01:00
|
|
|
(FBuffer.BitmapScale = TempScale) and
|
2021-12-08 17:45:03 +01:00
|
|
|
{$ENDIF}
|
2020-03-05 11:15:47 +01:00
|
|
|
(FBuffer.Width = TempWidth) and
|
|
|
|
(FBuffer.Height = TempHeight);
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
if aUseMutex then EndBufferDraw;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.ScreenToClient(aPoint : TPoint) : TPoint;
|
|
|
|
var
|
|
|
|
TempPoint : TPointF;
|
|
|
|
begin
|
|
|
|
TempPoint.x := aPoint.x;
|
|
|
|
TempPoint.y := aPoint.y;
|
|
|
|
TempPoint := ScreenToLocal(TempPoint);
|
|
|
|
Result.x := round(TempPoint.x);
|
|
|
|
Result.y := round(TempPoint.y);
|
|
|
|
end;
|
|
|
|
|
2020-03-05 11:15:47 +01:00
|
|
|
function TFMXBufferPanel.ScreenToClient(aPoint : TPointF) : TPointF;
|
|
|
|
begin
|
|
|
|
Result := ScreenToLocal(aPoint);
|
|
|
|
end;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
function TFMXBufferPanel.ClientToScreen(aPoint : TPoint) : TPoint;
|
|
|
|
var
|
|
|
|
TempPoint : TPointF;
|
|
|
|
begin
|
|
|
|
TempPoint.x := aPoint.x;
|
|
|
|
TempPoint.y := aPoint.y;
|
|
|
|
TempPoint := LocalToScreen(TempPoint);
|
|
|
|
Result.x := round(TempPoint.x);
|
|
|
|
Result.y := round(TempPoint.y);
|
|
|
|
end;
|
|
|
|
|
2020-03-05 11:15:47 +01:00
|
|
|
function TFMXBufferPanel.ClientToScreen(aPoint : TPointF) : TPointF;
|
|
|
|
begin
|
|
|
|
Result := LocalToScreen(aPoint);
|
|
|
|
end;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
end.
|