Compare commits

..

3 Commits

Author SHA1 Message Date
30113e5ed3 fix hidpi? 2020-04-19 12:54:58 +02:00
3f8b135ddd Stabilize auto-resize
The window dimensions are integers, so resizing to fit the content may
not be exact.

When computing the optimal size, it could cause to reduce the width and
height alternatively by few pixels, making the "optimal size" unstable.

For the same reason, during rendering, the content size could be
different from the optimal window size, leading to black borders
(supposed to be removed in optimal size).

To avoid this problem, always choose the same dimension if the choice to
resize the width or the height is in the error range.
2020-04-19 12:54:58 +02:00
38941744f4 Manually position and scale the content
Position and scale the content "manually" instead of relying on the
renderer "logical size".

This avoids possible rounding differences between the computed window
size and the content size, causing one row or column of black pixels on
the bottom or on the right.

This will also enable to draw items at their expected size on the screen
(unscaled).
2020-04-19 12:54:58 +02:00

View File

@ -342,6 +342,8 @@ screen_init_rendering(struct screen *screen, const char *window_title,
return false;
}
update_content_rect(screen);
screen->windowed_window_size = window_size;
return true;
@ -417,6 +419,7 @@ prepare_for_frame(struct screen *screen, struct size new_frame_size) {
screen->frame_size = new_frame_size;
screen->content_size = new_content_size;
update_content_rect(screen);
LOGI("New texture: %" PRIu16 "x%" PRIu16,
screen->frame_size.width, screen->frame_size.height);
@ -455,7 +458,6 @@ screen_update_frame(struct screen *screen, struct video_buffer *vb) {
mutex_unlock(vb->mutex);
return false;
}
update_content_rect(screen);
update_texture(screen, frame);
mutex_unlock(vb->mutex);
@ -599,9 +601,14 @@ screen_convert_to_frame_coords(struct screen *screen, int32_t x, int32_t y) {
int32_t w = screen->content_size.width;
int32_t h = screen->content_size.height;
// scale
x = (x - screen->rect.x) * w / screen->rect.w;
y = (y - screen->rect.y) * h / screen->rect.h;
// take the HiDPI scaling (dw/ww and dh/wh) into account
int ww, wh, dw, dh;
SDL_GetWindowSize(screen->window, &ww, &wh);
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
// scale (64 bits for intermediate multiplications)
x = (int64_t) (x - screen->rect.x) * w * dw / (screen->rect.w * ww);
y = (int64_t) (y - screen->rect.y) * h * dh / (screen->rect.h * wh);
// rotate
struct point result;