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
minibrowser: implement HiDPI support #30343
Conversation
e946ea4
to
63e69cd
Compare
1e9f3f6
to
e32ce0e
Compare
63e69cd
to
a27a036
Compare
238baf9
to
b088f81
Compare
f546afd
to
b90e315
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Just a couple comments below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
let's run try build so I do not need to build it myself to test windows @bors-servo try=all |
🤔 Unknown try string 'try=all' |
@bors-servo try |
🔨 Triggering try run (#6174746797) with platform=all and layout=all |
Test results for linux-wpt-layout-2013 from try job (#6174746797): Flaky unexpected result (21)
Stable unexpected results that are known to be intermittent (16)
|
Test results for linux-wpt-layout-2020 from try job (#6174746797): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (15)
|
✨ Try run (#6174746797) succeeded. |
I tested on my windows and something is working, but there is no logging and on mixed-dpi setup there is no change (blurred on hi-dpi monitor). |
Thanks for testing this! It looks like there’s no logging in the Windows try artifacts, because our Windows release builds use the Windows subsystem. With a debug build and
|
winit’s source suggests that it delivers ScaleFactorChanged in response to WM_DPICHANGED, but even with a modified version of Raymond Chen’s scratch program, it looks like Windows isn’t giving us WM_DPICHANGED when I move the window between monitors with different dpi, because I don’t get a MessageBox: // build with: cl scratch.cc
// https://stackoverflow.com/q/27613278
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "ole32.lib")
#pragma comment (lib, "comctl32.lib")
// https://gist.github.com/nanoant/dde75805132561140ed5e38f4048f5c1#file-win32directwrite-cpp-L146
#define HANDLE_WM_DPICHANGED(hwnd, wParam, lParam, fn) ((fn)((hwnd), LOWORD(wParam), HIWORD(wParam), *((RECT*)(lParam))), 0L)
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <ole2.h>
#include <commctrl.h>
#include <shlwapi.h>
HINSTANCE g_hinst;
BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
return TRUE;
}
void
OnDestroy(HWND hwnd)
{
PostQuitMessage(0);
}
void
PaintContent(HWND hwnd, PAINTSTRUCT *pps)
{
}
void
OnPaint(HWND hwnd)
{
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
PaintContent(hwnd, &ps);
EndPaint(hwnd, &ps);
}
void
OnPrintClient(HWND hwnd, HDC hdc)
{
PAINTSTRUCT ps;
ps.hdc = hdc;
GetClientRect(hwnd, &ps.rcPaint);
PaintContent(hwnd, &ps);
}
void
OnDpiChanged(HWND hwnd, WORD x, WORD y, RECT suggested)
{
MessageBoxW(NULL, L"", L"WM_DPICHANGED", 0);
}
/*
* Window procedure
*/
LRESULT CALLBACK
WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg) {
HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
HANDLE_MSG(hwnd, WM_SIZE, OnSize);
HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
HANDLE_MSG(hwnd, WM_DPICHANGED, OnDpiChanged);
case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
}
return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}
BOOL
InitApp(void)
{
WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hinst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("Scratch");
if (!RegisterClass(&wc)) return FALSE;
InitCommonControls(); /* In case we use a common control */
return TRUE;
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
LPSTR lpCmdLine, int nShowCmd)
{
MSG msg;
HWND hwnd;
g_hinst = hinst;
if (!InitApp()) return 0;
if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
hwnd = CreateWindow(
TEXT("Scratch"), /* Class Name */
TEXT("Scratch"), /* Title */
WS_OVERLAPPEDWINDOW, /* Style */
CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
NULL, /* Parent */
NULL, /* No menu */
hinst, /* Instance */
0); /* No special parameters */
ShowWindow(hwnd, nShowCmd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
}
return 0;
} |
Maybe we need to tell windows that we are DPI aware application. |
That did the trick! With d621a90:
|
d621a90
to
110d6d6
Compare
(force push to rebase over #30344) |
This patch makes the minibrowser behave correctly under HiDPI and mixed-dpi environments, by plumbing the servoshell Window’s scale factor into egui during context creation and on ScaleFactorChanged events.
To test this manually:
RUST_LOG=warn,servo::app=info
data:text/html,<body style=margin:0>BODY
and check that:Test results:
./mach build -d
does not report any errors./mach test-tidy
does not report any errors