mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 04:00:07 +00:00
Merge branch 'features/HighDpiAgain' of https://github.com/bjarteskogoy/CefSharp
This commit is contained in:
@@ -29,9 +29,6 @@ namespace CefSharp
|
||||
_webBrowserInternal(webBrowserInternal)
|
||||
{
|
||||
_renderWebBrowser = dynamic_cast<IRenderWebBrowser^>(webBrowserInternal);
|
||||
|
||||
_mainBitmapInfo = _renderWebBrowser->CreateBitmapInfo(false);
|
||||
_popupBitmapInfo = _renderWebBrowser->CreateBitmapInfo(true);
|
||||
}
|
||||
|
||||
~RenderClientAdapter()
|
||||
@@ -50,14 +47,18 @@ namespace CefSharp
|
||||
_popupBitmapInfo = nullptr;
|
||||
}
|
||||
|
||||
void CreateBitmapInfo()
|
||||
{
|
||||
_mainBitmapInfo = _renderWebBrowser->CreateBitmapInfo(false);
|
||||
_popupBitmapInfo = _renderWebBrowser->CreateBitmapInfo(true);
|
||||
}
|
||||
|
||||
// CefClient
|
||||
virtual DECL CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE{ return this; };
|
||||
|
||||
// CefRenderHandler
|
||||
virtual DECL bool GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo& screen_info) OVERRIDE
|
||||
{
|
||||
return false;
|
||||
|
||||
if ((IRenderWebBrowser^)_renderWebBrowser == nullptr)
|
||||
{
|
||||
return false;
|
||||
@@ -84,11 +85,10 @@ namespace CefSharp
|
||||
|
||||
auto screenInfo = _renderWebBrowser->GetScreenInfo();
|
||||
|
||||
//auto scaledWidth = screenInfo.Width / screenInfo.ScaleFactor;
|
||||
//auto scaledHeight = screenInfo.Height / screenInfo.ScaleFactor;
|
||||
//rect = CefRect(0, 0, scaledWidth, scaledHeight);
|
||||
auto scaledWidth = screenInfo.Width;
|
||||
auto scaledHeight = screenInfo.Height;
|
||||
rect = CefRect(0, 0, scaledWidth, scaledHeight);
|
||||
|
||||
rect = CefRect(0, 0, screenInfo.Width, screenInfo.Height);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -187,22 +187,25 @@ namespace CefSharp
|
||||
private:
|
||||
void ReleaseBitmapHandlers(BitmapInfo^ bitmapInfo)
|
||||
{
|
||||
auto backBufferHandle = (HANDLE)bitmapInfo->BackBufferHandle;
|
||||
auto fileMappingHandle = (HANDLE)bitmapInfo->FileMappingHandle;
|
||||
if(bitmapInfo)
|
||||
{
|
||||
auto backBufferHandle = (HANDLE)bitmapInfo->BackBufferHandle;
|
||||
auto fileMappingHandle = (HANDLE)bitmapInfo->FileMappingHandle;
|
||||
|
||||
if (backBufferHandle != NULL)
|
||||
{
|
||||
UnmapViewOfFile(backBufferHandle);
|
||||
backBufferHandle = NULL;
|
||||
bitmapInfo->BackBufferHandle = IntPtr::Zero;
|
||||
}
|
||||
if (backBufferHandle != NULL)
|
||||
{
|
||||
UnmapViewOfFile(backBufferHandle);
|
||||
backBufferHandle = NULL;
|
||||
bitmapInfo->BackBufferHandle = IntPtr::Zero;
|
||||
}
|
||||
|
||||
if (fileMappingHandle != NULL)
|
||||
{
|
||||
CloseHandle(fileMappingHandle);
|
||||
fileMappingHandle = NULL;
|
||||
bitmapInfo->FileMappingHandle = IntPtr::Zero;
|
||||
}
|
||||
if (fileMappingHandle != NULL)
|
||||
{
|
||||
CloseHandle(fileMappingHandle);
|
||||
fileMappingHandle = NULL;
|
||||
bitmapInfo->FileMappingHandle = IntPtr::Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_REFCOUNTING(RenderClientAdapter)
|
||||
|
||||
@@ -16,6 +16,10 @@ bool ManagedCefBrowserAdapter::IsDisposed::get()
|
||||
|
||||
void ManagedCefBrowserAdapter::CreateOffscreenBrowser(IntPtr windowHandle, BrowserSettings^ browserSettings, RequestContext^ requestContext, String^ address)
|
||||
{
|
||||
//Create the required BitmapInfo classes before the offscreen browser is initialized
|
||||
auto renderClientAdapter = dynamic_cast<RenderClientAdapter*>(_clientAdapter.get());
|
||||
renderClientAdapter->CreateBitmapInfo();
|
||||
|
||||
auto hwnd = static_cast<HWND>(windowHandle.ToPointer());
|
||||
|
||||
CefWindowInfo window;
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace CefSharp.Wpf
|
||||
public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrowser
|
||||
{
|
||||
private readonly List<IDisposable> disposables = new List<IDisposable>();
|
||||
private readonly ScaleTransform imageTransform;
|
||||
|
||||
private HwndSource source;
|
||||
private HwndSourceHook sourceHook;
|
||||
@@ -144,7 +143,6 @@ namespace CefSharp.Wpf
|
||||
UndoCommand = new DelegateCommand(this.Undo);
|
||||
RedoCommand = new DelegateCommand(this.Redo);
|
||||
|
||||
imageTransform = new ScaleTransform();
|
||||
managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
|
||||
|
||||
disposables.Add(managedCefBrowserAdapter);
|
||||
@@ -233,10 +231,8 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
var screenInfo = new ScreenInfo();
|
||||
|
||||
var point = matrix.Transform(new Point(ActualWidth, ActualHeight));
|
||||
|
||||
screenInfo.Width = (int)point.X;
|
||||
screenInfo.Height = (int)point.Y;
|
||||
screenInfo.Width = (int)ActualWidth;
|
||||
screenInfo.Height = (int)ActualHeight;
|
||||
screenInfo.ScaleFactor = (float)matrix.M11;
|
||||
|
||||
return screenInfo;
|
||||
@@ -248,7 +244,7 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
throw new Exception("BitmapFactory cannot be null");
|
||||
}
|
||||
return BitmapFactory.CreateBitmap(isPopup);
|
||||
return BitmapFactory.CreateBitmap(isPopup, matrix.M11);
|
||||
}
|
||||
|
||||
bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y)
|
||||
@@ -814,13 +810,16 @@ namespace CefSharp.Wpf
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
var notifyDpiChanged = !matrix.Equals(source.CompositionTarget.TransformToDevice);
|
||||
|
||||
matrix = source.CompositionTarget.TransformToDevice;
|
||||
sourceHook = SourceHook;
|
||||
source.AddHook(sourceHook);
|
||||
|
||||
managedCefBrowserAdapter.NotifyScreenInfoChanged();
|
||||
imageTransform.ScaleX = 1 / matrix.M11;
|
||||
imageTransform.ScaleY = 1 / matrix.M22;
|
||||
if (notifyDpiChanged)
|
||||
{
|
||||
managedCefBrowserAdapter.NotifyScreenInfoChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args.OldSource != null)
|
||||
@@ -910,8 +909,6 @@ namespace CefSharp.Wpf
|
||||
img.Stretch = Stretch.None;
|
||||
img.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
img.VerticalAlignment = VerticalAlignment.Top;
|
||||
//Scale Image based on DPI settings
|
||||
img.LayoutTransform = imageTransform;
|
||||
|
||||
return img;
|
||||
}
|
||||
@@ -985,10 +982,10 @@ namespace CefSharp.Wpf
|
||||
|
||||
private void SetPopupSizeAndPositionImpl(int width, int height, int x, int y)
|
||||
{
|
||||
popup.Width = width / matrix.M11;
|
||||
popup.Height = height / matrix.M22;
|
||||
popup.Width = width ;
|
||||
popup.Height = height;
|
||||
|
||||
var popupOffset = new Point(x / matrix.M11, y / matrix.M22);
|
||||
var popupOffset = new Point(x, y);
|
||||
var locationFromScreen = PointToScreen(popupOffset);
|
||||
popup.HorizontalOffset = locationFromScreen.X / matrix.M11;
|
||||
popup.VerticalOffset = locationFromScreen.Y / matrix.M22;
|
||||
@@ -1251,9 +1248,8 @@ namespace CefSharp.Wpf
|
||||
private Point GetPixelPosition(MouseEventArgs e)
|
||||
{
|
||||
var deviceIndependentPosition = e.GetPosition(this);
|
||||
var pixelPosition = matrix.Transform(deviceIndependentPosition);
|
||||
|
||||
return pixelPosition;
|
||||
return deviceIndependentPosition;
|
||||
}
|
||||
|
||||
public IBrowser GetBrowser()
|
||||
|
||||
@@ -8,10 +8,21 @@ namespace CefSharp.Wpf.Rendering
|
||||
{
|
||||
public class BitmapFactory : IBitmapFactory
|
||||
{
|
||||
public BitmapInfo CreateBitmap(bool isPopup)
|
||||
public const int DefaultDpi = 96;
|
||||
|
||||
public BitmapInfo CreateBitmap(bool isPopup, double dpiScale)
|
||||
{
|
||||
//return new WritableBitmapInfo { IsPopup = isPopup };
|
||||
return new InteropBitmapInfo { IsPopup = isPopup };
|
||||
if (dpiScale > 1.0)
|
||||
{
|
||||
return new WritableBitmapInfo(DefaultDpi * dpiScale, DefaultDpi * dpiScale)
|
||||
{
|
||||
IsPopup = isPopup
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new InteropBitmapInfo { IsPopup = isPopup };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,19 @@ namespace CefSharp.Wpf.Rendering
|
||||
private static readonly PixelFormat PixelFormat = PixelFormats.Bgra32;
|
||||
|
||||
public WriteableBitmap Bitmap { get; private set; }
|
||||
public double DpiX { get; private set; }
|
||||
public double DpiY { get; private set; }
|
||||
|
||||
public WritableBitmapInfo()
|
||||
: this(BitmapFactory.DefaultDpi, BitmapFactory.DefaultDpi)
|
||||
{
|
||||
}
|
||||
|
||||
public WritableBitmapInfo(double dpiX, double dpiY)
|
||||
{
|
||||
DpiX = dpiX;
|
||||
DpiY = dpiY;
|
||||
|
||||
BytesPerPixel = PixelFormat.BitsPerPixel / 8;
|
||||
DirtyRectSupport = true;
|
||||
}
|
||||
@@ -48,7 +58,7 @@ namespace CefSharp.Wpf.Rendering
|
||||
|
||||
public override BitmapSource CreateBitmap()
|
||||
{
|
||||
Bitmap = new WriteableBitmap(Width, Height, 96, 96, PixelFormat, null);
|
||||
Bitmap = new WriteableBitmap(Width, Height, DpiX, DpiY, PixelFormat, null);
|
||||
|
||||
return Bitmap;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ namespace CefSharp
|
||||
{
|
||||
public interface IBitmapFactory
|
||||
{
|
||||
BitmapInfo CreateBitmap(bool isPopup);
|
||||
BitmapInfo CreateBitmap(bool isPopup, double dpiScale);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user