mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Support hidpi
This commit is contained in:
parent
5bf00c07c2
commit
10f86935b8
6 changed files with 19 additions and 45 deletions
|
@ -191,36 +191,7 @@ void OpenGLES::Reset() {
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: simplify this. Duplicating code with CreateSurface(SwapChainPanel)
|
EGLSurface OpenGLES::CreateSurface(SwapChainPanel const &panel, float dpi) {
|
||||||
EGLSurface
|
|
||||||
OpenGLES::CreateSurface(winrt::Windows::UI::Core::CoreWindow const &cwin) {
|
|
||||||
EGLSurface surface = EGL_NO_SURFACE;
|
|
||||||
|
|
||||||
const EGLint surfaceAttributes[] = {EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER,
|
|
||||||
EGL_TRUE, EGL_NONE};
|
|
||||||
|
|
||||||
PropertySet surfaceCreationProperties;
|
|
||||||
|
|
||||||
surfaceCreationProperties.Insert(EGLNativeWindowTypeProperty, cwin);
|
|
||||||
// How to set size and or scale:
|
|
||||||
// Insert(EGLRenderSurfaceSizeProperty),
|
|
||||||
// PropertyValue::CreateSize(*renderSurfaceSize));
|
|
||||||
// Insert(EGLRenderResolutionScaleProperty),
|
|
||||||
// PropertyValue::CreateSingle(*resolutionScale));
|
|
||||||
|
|
||||||
EGLNativeWindowType win = static_cast<EGLNativeWindowType>(
|
|
||||||
winrt::get_abi(surfaceCreationProperties));
|
|
||||||
surface =
|
|
||||||
eglCreateWindowSurface(mEglDisplay, mEglConfig, win, surfaceAttributes);
|
|
||||||
|
|
||||||
if (surface == EGL_NO_SURFACE) {
|
|
||||||
throw winrt::hresult_error(E_FAIL, L"Failed to create EGL surface");
|
|
||||||
}
|
|
||||||
|
|
||||||
return surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLSurface OpenGLES::CreateSurface(SwapChainPanel const &panel) {
|
|
||||||
EGLSurface surface = EGL_NO_SURFACE;
|
EGLSurface surface = EGL_NO_SURFACE;
|
||||||
|
|
||||||
const EGLint surfaceAttributes[] = {EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER,
|
const EGLint surfaceAttributes[] = {EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER,
|
||||||
|
@ -232,8 +203,8 @@ EGLSurface OpenGLES::CreateSurface(SwapChainPanel const &panel) {
|
||||||
// How to set size and or scale:
|
// How to set size and or scale:
|
||||||
// Insert(EGLRenderSurfaceSizeProperty),
|
// Insert(EGLRenderSurfaceSizeProperty),
|
||||||
// PropertyValue::CreateSize(*renderSurfaceSize));
|
// PropertyValue::CreateSize(*renderSurfaceSize));
|
||||||
// Insert(EGLRenderResolutionScaleProperty),
|
surfaceCreationProperties.Insert(EGLRenderResolutionScaleProperty,
|
||||||
// PropertyValue::CreateSingle(*resolutionScale));
|
PropertyValue::CreateSingle(dpi));
|
||||||
|
|
||||||
EGLNativeWindowType win = static_cast<EGLNativeWindowType>(
|
EGLNativeWindowType win = static_cast<EGLNativeWindowType>(
|
||||||
winrt::get_abi(surfaceCreationProperties));
|
winrt::get_abi(surfaceCreationProperties));
|
||||||
|
|
|
@ -10,8 +10,8 @@ public:
|
||||||
~OpenGLES();
|
~OpenGLES();
|
||||||
|
|
||||||
EGLSurface
|
EGLSurface
|
||||||
CreateSurface(winrt::Windows::UI::Xaml::Controls::SwapChainPanel const &);
|
CreateSurface(winrt::Windows::UI::Xaml::Controls::SwapChainPanel const &,
|
||||||
EGLSurface CreateSurface(winrt::Windows::UI::Core::CoreWindow const &);
|
float dpi);
|
||||||
|
|
||||||
void GetSurfaceDimensions(const EGLSurface surface, EGLint *width,
|
void GetSurfaceDimensions(const EGLSurface surface, EGLint *width,
|
||||||
EGLint *height);
|
EGLint *height);
|
||||||
|
|
|
@ -56,7 +56,7 @@ const char* get_clipboard_contents() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Servo::Servo(hstring url, GLsizei width, GLsizei height,
|
Servo::Servo(hstring url, GLsizei width, GLsizei height, float dpi,
|
||||||
ServoDelegate &aDelegate)
|
ServoDelegate &aDelegate)
|
||||||
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
|
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ Servo::Servo(hstring url, GLsizei width, GLsizei height,
|
||||||
o.url = *hstring2char(url);
|
o.url = *hstring2char(url);
|
||||||
o.width = mWindowWidth;
|
o.width = mWindowWidth;
|
||||||
o.height = mWindowHeight;
|
o.height = mWindowHeight;
|
||||||
o.density = 1.0;
|
o.density = dpi;
|
||||||
o.enable_subpixel_text_antialiasing = false;
|
o.enable_subpixel_text_antialiasing = false;
|
||||||
o.vr_pointer = NULL;
|
o.vr_pointer = NULL;
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ protected:
|
||||||
|
|
||||||
class Servo {
|
class Servo {
|
||||||
public:
|
public:
|
||||||
Servo(hstring, GLsizei, GLsizei, ServoDelegate &);
|
Servo(hstring, GLsizei, GLsizei, float, ServoDelegate &);
|
||||||
~Servo();
|
~Servo();
|
||||||
ServoDelegate &Delegate() { return mDelegate; }
|
ServoDelegate &Delegate() { return mDelegate; }
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
using namespace winrt::Windows::Graphics::Display;
|
||||||
using namespace winrt::Windows::UI::Xaml;
|
using namespace winrt::Windows::UI::Xaml;
|
||||||
using namespace winrt::Windows::UI::Core;
|
using namespace winrt::Windows::UI::Core;
|
||||||
using namespace winrt::Windows::Foundation;
|
using namespace winrt::Windows::Foundation;
|
||||||
|
@ -13,6 +14,7 @@ using namespace winrt::servo;
|
||||||
namespace winrt::ServoApp::implementation {
|
namespace winrt::ServoApp::implementation {
|
||||||
|
|
||||||
ServoControl::ServoControl() {
|
ServoControl::ServoControl() {
|
||||||
|
mDPI = (float)DisplayInformation::GetForCurrentView().ResolutionScale() / 100;
|
||||||
DefaultStyleKey(winrt::box_value(L"ServoApp.ServoControl"));
|
DefaultStyleKey(winrt::box_value(L"ServoApp.ServoControl"));
|
||||||
Loaded(std::bind(&ServoControl::OnLoaded, this, _1, _2));
|
Loaded(std::bind(&ServoControl::OnLoaded, this, _1, _2));
|
||||||
}
|
}
|
||||||
|
@ -62,7 +64,7 @@ Controls::SwapChainPanel ServoControl::Panel() {
|
||||||
|
|
||||||
void ServoControl::CreateRenderSurface() {
|
void ServoControl::CreateRenderSurface() {
|
||||||
if (mRenderSurface == EGL_NO_SURFACE) {
|
if (mRenderSurface == EGL_NO_SURFACE) {
|
||||||
mRenderSurface = mOpenGLES.CreateSurface(Panel());
|
mRenderSurface = mOpenGLES.CreateSurface(Panel(), mDPI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,10 +83,10 @@ void ServoControl::RecoverFromLostDevice() {
|
||||||
|
|
||||||
void ServoControl::OnSurfaceManipulationDelta(
|
void ServoControl::OnSurfaceManipulationDelta(
|
||||||
IInspectable const &, Input::ManipulationDeltaRoutedEventArgs const &e) {
|
IInspectable const &, Input::ManipulationDeltaRoutedEventArgs const &e) {
|
||||||
auto x = e.Position().X;
|
auto x = e.Position().X * mDPI;
|
||||||
auto y = e.Position().Y;
|
auto y = e.Position().Y * mDPI;
|
||||||
auto dx = e.Delta().Translation.X;
|
auto dx = e.Delta().Translation.X * mDPI;
|
||||||
auto dy = e.Delta().Translation.Y;
|
auto dy = e.Delta().Translation.Y * mDPI;
|
||||||
RunOnGLThread([=] { mServo->Scroll(dx, dy, x, y); });
|
RunOnGLThread([=] { mServo->Scroll(dx, dy, x, y); });
|
||||||
e.Handled(true);
|
e.Handled(true);
|
||||||
}
|
}
|
||||||
|
@ -92,8 +94,8 @@ void ServoControl::OnSurfaceManipulationDelta(
|
||||||
void ServoControl::OnSurfaceClicked(IInspectable const &,
|
void ServoControl::OnSurfaceClicked(IInspectable const &,
|
||||||
Input::PointerRoutedEventArgs const &e) {
|
Input::PointerRoutedEventArgs const &e) {
|
||||||
auto coords = e.GetCurrentPoint(Panel());
|
auto coords = e.GetCurrentPoint(Panel());
|
||||||
auto x = coords.Position().X;
|
auto x = coords.Position().X * mDPI;
|
||||||
auto y = coords.Position().Y;
|
auto y = coords.Position().Y * mDPI;
|
||||||
RunOnGLThread([=] { mServo->Click(x, y); });
|
RunOnGLThread([=] { mServo->Click(x, y); });
|
||||||
e.Handled(true);
|
e.Handled(true);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +155,7 @@ void ServoControl::Loop() {
|
||||||
if (mServo == nullptr) {
|
if (mServo == nullptr) {
|
||||||
log("Entering loop");
|
log("Entering loop");
|
||||||
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
|
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
|
||||||
mServo = std::make_unique<Servo>(mInitialURL, panelWidth, panelHeight, *sd);
|
mServo = std::make_unique<Servo>(mInitialURL, panelWidth, panelHeight, mDPI, *sd);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: this will fail since create_task didn't pick the thread
|
// FIXME: this will fail since create_task didn't pick the thread
|
||||||
// where Servo was running initially.
|
// where Servo was running initially.
|
||||||
|
|
|
@ -92,6 +92,7 @@ private:
|
||||||
winrt::event<EventDelegate> mOnCaptureGesturesStartedEvent;
|
winrt::event<EventDelegate> mOnCaptureGesturesStartedEvent;
|
||||||
winrt::event<EventDelegate> mOnCaptureGesturesEndedEvent;
|
winrt::event<EventDelegate> mOnCaptureGesturesEndedEvent;
|
||||||
|
|
||||||
|
float mDPI = 1;
|
||||||
hstring mInitialURL = L"https://servo.org";
|
hstring mInitialURL = L"https://servo.org";
|
||||||
|
|
||||||
Windows::UI::Xaml::Controls::SwapChainPanel ServoControl::Panel();
|
Windows::UI::Xaml::Controls::SwapChainPanel ServoControl::Panel();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue