Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use device scale factor to support higher DPI on WPF #842

Merged
merged 4 commits into from
Feb 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CefSharp.Core/Internals/RenderClientAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ namespace CefSharp
// CefClient
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE{ return this; };

// CefRenderHandler
virtual DECL bool GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo& screen_info) OVERRIDE
{
if ((IRenderWebBrowser^)_renderWebBrowser == nullptr)
{
return false;
}

auto scaleFactor = _renderWebBrowser->GetScreenInfoScaleFactor();

if (screen_info.device_scale_factor == scaleFactor)
{
return false;
}

screen_info.device_scale_factor = scaleFactor;
return true;
}

// CefRenderHandler
virtual DECL bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) OVERRIDE
{
Expand Down
10 changes: 10 additions & 0 deletions CefSharp.Core/ManagedCefBrowserAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@ namespace CefSharp
}
}

void NotifyScreenInfoChanged()
{
auto browser = _clientAdapter->GetCefBrowser();

if (browser != nullptr)
{
browser->GetHost()->NotifyScreenInfoChanged();
}
}

void RegisterJsObject(String^ name, Object^ object)
{
_javaScriptObjectRepository->Register(name, object);
Expand Down
5 changes: 5 additions & 0 deletions CefSharp.OffScreen/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ public BitmapInfo CreateBitmapInfo(bool isPopup)
return new GdiBitmapInfo { IsPopup = isPopup, BitmapLock = bitmapLock };
}

float IRenderWebBrowser.GetScreenInfoScaleFactor()
{
return 1F;
}

void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo)
{
lock (bitmapLock)
Expand Down
16 changes: 15 additions & 1 deletion CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrow
private bool ignoreUriChange;
private bool browserCreated;
private Matrix matrix;
private float deviceScaleFactor;
private ScaleTransform imageTransform;

private Image image;
private Image popupImage;
Expand Down Expand Up @@ -494,6 +496,8 @@ public ChromiumWebBrowser()
UndoCommand = new DelegateCommand(Undo);
RedoCommand = new DelegateCommand(Redo);

deviceScaleFactor = 1.0F;
imageTransform = new ScaleTransform();
managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);

disposables.Add(managedCefBrowserAdapter);
Expand Down Expand Up @@ -655,8 +659,13 @@ private void PresentationSourceChangedHandler(object sender, SourceChangedEventA
if (source != null)
{
matrix = source.CompositionTarget.TransformToDevice;
deviceScaleFactor = (float)matrix.M11;
sourceHook = SourceHook;
source.AddHook(sourceHook);

managedCefBrowserAdapter.NotifyScreenInfoChanged();
imageTransform.ScaleX = 1 / matrix.M11;
imageTransform.ScaleY = 1 / matrix.M22;
}
}
else if (args.OldSource != null)
Expand Down Expand Up @@ -743,7 +752,7 @@ private Image CreateImage()
img.HorizontalAlignment = HorizontalAlignment.Left;
img.VerticalAlignment = VerticalAlignment.Top;
//Scale Image based on DPI settings
img.LayoutTransform = new ScaleTransform(1 / matrix.M11, 1 / matrix.M22);
img.LayoutTransform = imageTransform;

return img;
}
Expand Down Expand Up @@ -811,6 +820,11 @@ public BitmapInfo CreateBitmapInfo(bool isPopup)
return BitmapFactory.CreateBitmap(isPopup);
}

float IRenderWebBrowser.GetScreenInfoScaleFactor()
{
return deviceScaleFactor;
}

void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo)
{
UiThreadRunAsync(delegate
Expand Down
2 changes: 2 additions & 0 deletions CefSharp/Internals/IRenderWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface IRenderWebBrowser : IWebBrowserInternal
int Width { get; }
int Height { get; }

float GetScreenInfoScaleFactor();

BitmapInfo CreateBitmapInfo(bool isPopup);
void InvokeRenderAsync(BitmapInfo bitmapInfo);

Expand Down