2018-01-25 22:34:04 +02:00
|
|
|
// ************************************************************************
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
// ************************************************************************
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2018-01-25 22:34:04 +02:00
|
|
|
// browser in Delphi applications.
|
|
|
|
//
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
//
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
//
|
2020-01-01 13:48:10 +02:00
|
|
|
// Copyright � 2020 Salvador Diaz Fau. All rights reserved.
|
2018-01-25 22:34:04 +02:00
|
|
|
//
|
|
|
|
// ************************************************************************
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
// ************************************************************************
|
|
|
|
(*
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
*
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
*
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
* this source code without explicit permission.
|
|
|
|
*
|
|
|
|
*)
|
|
|
|
|
2019-04-04 10:26:44 +02:00
|
|
|
unit uCEFFMXBufferPanel;
|
2018-01-25 22:34:04 +02:00
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF MSWINDOWS}
|
2020-03-05 12:15:47 +02:00
|
|
|
Winapi.Windows, FMX.Platform.Win,
|
2018-01-25 22:34:04 +02:00
|
|
|
{$ELSE}
|
|
|
|
System.SyncObjs,
|
|
|
|
{$ENDIF}
|
|
|
|
System.Classes, System.UIConsts, System.Types, System.UITypes,
|
|
|
|
{$IFDEF DELPHI17_UP}
|
|
|
|
FMX.Graphics,
|
|
|
|
{$ENDIF}
|
2020-03-05 12:15:47 +02:00
|
|
|
FMX.Types, FMX.Controls, FMX.Forms,
|
|
|
|
uCEFTypes;
|
2018-01-25 22:34:04 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
TDialogKeyEvent = procedure(Sender: TObject; var Key: Word; Shift: TShiftState) of object;
|
|
|
|
|
2018-12-09 12:11:59 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pidWin32 or pidWin64)]{$ENDIF}{$ENDIF}
|
2018-01-25 22:34:04 +02:00
|
|
|
TFMXBufferPanel = class(TControl)
|
|
|
|
protected
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
FMutex : THandle;
|
|
|
|
{$ELSE}
|
|
|
|
FBufferCS : TCriticalSection;
|
|
|
|
{$ENDIF}
|
|
|
|
FBuffer : TBitmap;
|
|
|
|
FScanlineSize : integer;
|
|
|
|
FColor : TAlphaColor;
|
|
|
|
FHighSpeedDrawing : boolean;
|
|
|
|
FOnDialogKey : TDialogKeyEvent;
|
|
|
|
|
|
|
|
procedure CreateSyncObj;
|
|
|
|
|
|
|
|
procedure DestroySyncObj;
|
|
|
|
procedure DestroyBuffer;
|
|
|
|
|
|
|
|
function GetScreenScale : Single;
|
|
|
|
function GetBufferWidth : integer;
|
|
|
|
function GetBufferHeight : integer;
|
2020-03-05 12:15:47 +02:00
|
|
|
function GetParentForm : TCustomForm;
|
|
|
|
function GetParentFormHandle : TCefWindowHandle;
|
2018-01-25 22:34:04 +02: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;
|
|
|
|
function SaveToFile(const aFilename : string) : boolean;
|
|
|
|
procedure InvalidatePanel;
|
|
|
|
function BeginBufferDraw : boolean;
|
|
|
|
procedure EndBufferDraw;
|
2020-03-18 19:37:55 +02:00
|
|
|
procedure BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRectF);
|
2018-01-25 22:34:04 +02:00
|
|
|
function UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
|
|
|
function BufferIsResized(aUseMutex : boolean = True) : boolean;
|
2020-03-05 12:15:47 +02:00
|
|
|
function ScreenToClient(aPoint : TPoint) : TPoint; overload;
|
|
|
|
function ScreenToClient(aPoint : TPointF) : TPointF; overload;
|
|
|
|
function ClientToScreen(aPoint : TPoint) : TPoint; overload;
|
|
|
|
function ClientToScreen(aPoint : TPointF) : TPointF; overload;
|
2018-01-25 22:34:04 +02:00
|
|
|
|
|
|
|
property Buffer : TBitmap read FBuffer;
|
|
|
|
property ScanlineSize : integer read FScanlineSize;
|
|
|
|
property BufferWidth : integer read GetBufferWidth;
|
|
|
|
property BufferHeight : integer read GetBufferHeight;
|
|
|
|
property ScreenScale : single read GetScreenScale;
|
|
|
|
|
|
|
|
published
|
|
|
|
property Align;
|
|
|
|
property Anchors;
|
|
|
|
property Visible;
|
|
|
|
property Enabled;
|
|
|
|
property TabOrder;
|
|
|
|
property Color : TAlphaColor read FColor write FColor default claWhite;
|
|
|
|
property HighSpeedDrawing : boolean read FHighSpeedDrawing write FHighSpeedDrawing default True;
|
|
|
|
|
|
|
|
{$IFDEF DELPHI17_UP}
|
|
|
|
property TabStop;
|
|
|
|
property CanFocus;
|
|
|
|
property CanParentFocus;
|
|
|
|
property Height;
|
|
|
|
property Width;
|
|
|
|
property Padding;
|
|
|
|
property Opacity;
|
|
|
|
property Margins;
|
|
|
|
property Position;
|
|
|
|
property RotationAngle;
|
|
|
|
property RotationCenter;
|
|
|
|
property Scale;
|
|
|
|
property Size;
|
|
|
|
{$ENDIF}
|
2019-03-15 10:12:09 +02:00
|
|
|
{$IFNDEF DELPHI23_UP}
|
|
|
|
property Hint;
|
|
|
|
property ShowHint;
|
|
|
|
{$ENDIF}
|
2018-01-25 22:34:04 +02: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;
|
|
|
|
property OnDialogKey : TDialogKeyEvent read FOnDialogKey write FOnDialogKey;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils, System.Math,
|
2020-03-05 12:15:47 +02:00
|
|
|
{$IFDEF MSWINDOWS}FMX.Helpers.Win,{$ENDIF}
|
2019-11-09 00:15:53 +02:00
|
|
|
FMX.Platform, uCEFMiscFunctions, uCEFApplicationCore;
|
2018-01-25 22:34:04 +02: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;
|
|
|
|
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 19:52:32 +02:00
|
|
|
TempSrc, TempDst, TempClip : TRectF;
|
|
|
|
TempState : TCanvasSaveState;
|
2020-03-05 12:15:47 +02:00
|
|
|
TempScale : single;
|
2018-01-25 22:34:04 +02:00
|
|
|
begin
|
2020-03-29 17:31:42 +02:00
|
|
|
Result := False;
|
2018-01-25 22:34:04 +02:00
|
|
|
|
|
|
|
if Canvas.BeginScene then
|
|
|
|
try
|
|
|
|
if BeginBufferDraw then
|
2020-02-05 19:52:32 +02:00
|
|
|
try
|
2018-01-25 22:34:04 +02:00
|
|
|
if (FBuffer <> nil) then
|
|
|
|
begin
|
2020-03-05 12:15:47 +02:00
|
|
|
TempScale := ScreenScale;
|
2020-02-05 19:52:32 +02:00
|
|
|
TempSrc := TRectF.Create(0, 0, FBuffer.Width, FBuffer.Height);
|
2020-03-05 12:15:47 +02:00
|
|
|
TempDst := TRectF.Create(0, 0, FBuffer.Width / TempScale, FBuffer.Height / TempScale);
|
2020-02-05 19:52:32 +02:00
|
|
|
TempClip := TRectF.Create(0, 0, Width, Height);
|
|
|
|
|
|
|
|
TempState := Canvas.SaveState;
|
|
|
|
try
|
2020-02-06 11:37:54 +02:00
|
|
|
Canvas.IntersectClipRect(TempClip);
|
2020-02-05 19:52:32 +02:00
|
|
|
Canvas.DrawBitmap(FBuffer, TempSrc, TempDst, 1, FHighSpeedDrawing);
|
|
|
|
Result := True;
|
|
|
|
finally
|
|
|
|
Canvas.RestoreState(TempState);
|
|
|
|
end;
|
2018-01-25 22:34:04 +02:00
|
|
|
end;
|
2020-02-05 19:52:32 +02:00
|
|
|
finally
|
2018-01-25 22:34:04 +02: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 12:15:47 +02: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
|
|
|
|
Result := 0;
|
|
|
|
|
|
|
|
{$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;
|
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
function TFMXBufferPanel.GetScreenScale : Single;
|
2020-04-03 17:57:52 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-03-05 12:15:47 +02:00
|
|
|
var
|
|
|
|
TempHandle : TCefWindowHandle;
|
2020-04-03 17:57:52 +02:00
|
|
|
{$ENDIF}
|
2018-01-25 22:34:04 +02:00
|
|
|
begin
|
2020-04-03 17:57:52 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-03-05 12:15:47 +02:00
|
|
|
TempHandle := GetParentFormHandle;
|
|
|
|
|
|
|
|
if (TempHandle <> 0) then
|
|
|
|
Result := GetWndScale(TempHandle)
|
2018-01-25 22:34:04 +02:00
|
|
|
else
|
2020-04-03 17:57:52 +02:00
|
|
|
{$ENDIF}
|
2020-03-05 12:15:47 +02:00
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
Result := GlobalCEFApp.DeviceScaleFactor
|
|
|
|
else
|
|
|
|
Result := 1;
|
2018-01-25 22:34:04 +02: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 19:37:55 +02:00
|
|
|
procedure TFMXBufferPanel.BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRectF);
|
2018-01-25 22:34:04 +02:00
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then
|
2020-03-18 19:37:55 +02:00
|
|
|
if FBuffer.Canvas.BeginScene then
|
|
|
|
try
|
|
|
|
FBuffer.Canvas.DrawBitmap(aBitmap, aSrcRect, aDstRect, 1, FHighSpeedDrawing);
|
|
|
|
finally
|
|
|
|
FBuffer.Canvas.EndScene;
|
|
|
|
end;
|
2018-01-25 22:34:04 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TFMXBufferPanel.UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
2020-03-05 12:15:47 +02:00
|
|
|
var
|
|
|
|
TempScale : single;
|
2018-01-25 22:34:04 +02:00
|
|
|
begin
|
2020-03-18 19:37:55 +02:00
|
|
|
Result := False;
|
2020-03-05 12:15:47 +02:00
|
|
|
TempScale := ScreenScale;
|
2018-01-25 22:34:04 +02:00
|
|
|
|
2020-03-05 12:15:47 +02:00
|
|
|
if ((FBuffer = nil) or
|
|
|
|
(FBuffer.BitmapScale <> TempScale) or
|
|
|
|
(FBuffer.Width <> aWidth) or
|
|
|
|
(FBuffer.Height <> aHeight)) then
|
2018-01-25 22:34:04 +02:00
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
|
|
|
|
|
|
|
FBuffer := TBitmap.Create(aWidth, aHeight);
|
|
|
|
{$IFDEF DELPHI17_UP}
|
2020-03-05 12:15:47 +02:00
|
|
|
FBuffer.BitmapScale := TempScale;
|
2018-01-25 22:34:04 +02: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 12:15:47 +02:00
|
|
|
TempScale : single;
|
2018-01-25 22:34:04 +02:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
if not(aUseMutex) or BeginBufferDraw then
|
|
|
|
begin
|
2020-03-05 12:15:47 +02:00
|
|
|
TempScale := ScreenScale;
|
|
|
|
TempWidth := round(Width * TempScale);
|
|
|
|
TempHeight := round(Height * TempScale);
|
2018-01-25 22:34:04 +02:00
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
// Workaround for CEF4Delphi issue #271 (CEF issue #2833)
|
|
|
|
// https://github.com/salvadordf/CEF4Delphi/issues/271
|
|
|
|
// https://bitbucket.org/chromiumembedded/cef/issues/2833/osr-gpu-consume-cpu-and-may-not-draw
|
|
|
|
if GlobalCEFApp.EnableGPU and (TempScale <> 1) then
|
|
|
|
begin
|
|
|
|
while (Frac(TempWidth * TempScale) <> 0) do dec(TempWidth);
|
|
|
|
while (Frac(TempHeight * TempScale) <> 0) do dec(TempHeight);
|
|
|
|
end;
|
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
Result := (FBuffer <> nil) and
|
2020-03-05 12:15:47 +02:00
|
|
|
(FBuffer.BitmapScale = TempScale) and
|
|
|
|
(FBuffer.Width = TempWidth) and
|
|
|
|
(FBuffer.Height = TempHeight);
|
2018-01-25 22:34:04 +02: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 12:15:47 +02:00
|
|
|
function TFMXBufferPanel.ScreenToClient(aPoint : TPointF) : TPointF;
|
|
|
|
begin
|
|
|
|
Result := ScreenToLocal(aPoint);
|
|
|
|
end;
|
|
|
|
|
2018-01-25 22:34:04 +02: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 12:15:47 +02:00
|
|
|
function TFMXBufferPanel.ClientToScreen(aPoint : TPointF) : TPointF;
|
|
|
|
begin
|
|
|
|
Result := LocalToScreen(aPoint);
|
|
|
|
end;
|
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
end.
|