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

Do not allow setting too small or big scale factors #109

Merged
merged 2 commits into from
Jun 1, 2022
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
23 changes: 23 additions & 0 deletions include/wpe/view-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@ WPE_EXPORT
void*
wpe_view_backend_dispatch_get_accessible(struct wpe_view_backend* backend);

/**
* wpe_view_backend_dispatch_set_device_scale_factor:
* @view_backend: (transfer none): The view backend to configure.
* @factor: Scaling factor to apply.
*
* Configure the device scaling factor applied to rendered content.
*
* Set the @factor by which sizes of content rendered to a web view will be
* multiplied by. The typical reason to set a value other than `1.0` (the
* default) is to produce output that will display at the intended physical
* size in displays with a high density of pixels.
*
* Only values from `0.05` up to `5.0` are allowed. Setting a value outside
* this range will be ignored, and in debug builds execution will be aborted.
*
* For example, a display that has a physical resolution of 3840x2160 with
* a scaling factor of `2.0` will make web content behave as if the screen
* had a size of 1920x1080, and content will be rendered at twice the size:
* each “logical” pixel will occupy four “physical” pixels (a 2x2 box) on
* the output.
*
* Since: 1.4
*/
WPE_EXPORT
void
wpe_view_backend_dispatch_set_device_scale_factor(struct wpe_view_backend*, float);
Expand Down
5 changes: 5 additions & 0 deletions src/view-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ wpe_view_backend_dispatch_get_accessible(struct wpe_view_backend* backend)
void
wpe_view_backend_dispatch_set_device_scale_factor(struct wpe_view_backend* backend, float scale)
{
if (scale < 0.05f || scale > 5.0f) {
assert(!"Scale factor not in the [0.05, 5.0] range");
return;
}

if (backend->backend_client && backend->backend_client->set_device_scale_factor)
backend->backend_client->set_device_scale_factor(backend->backend_client_data, scale);
}
Expand Down