Compare commits

..

1 Commits

Author SHA1 Message Date
Romain Vimont
fa226c94ec 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 also avoids HiDPI scale issues, by computing the scaling manually.

This will also enable to draw items at their expected size on the screen
(unscaled).
2020-05-15 19:19:06 +02:00
3 changed files with 15 additions and 23 deletions

View File

@@ -136,7 +136,7 @@ event_watcher(void *data, SDL_Event *event) {
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
// In practice, it seems to always be called from the same thread in
// that specific case. Anyway, it's just a workaround.
screen_render(&screen, true);
screen_render(&screen);
}
return 0;
}

View File

@@ -157,7 +157,7 @@ get_initial_optimal_size(struct size content_size, uint16_t req_width,
}
static void
screen_update_content_rect(struct screen *screen) {
update_content_rect(struct screen *screen) {
int dw;
int dh;
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
@@ -325,12 +325,7 @@ screen_init_rendering(struct screen *screen, const char *window_title,
return false;
}
// Reset the window size to trigger a SIZE_CHANGED event, to workaround
// HiDPI issues with some SDL renderers when several displays having
// different HiDPI scaling are connected
SDL_SetWindowSize(screen->window, window_size.width, window_size.height);
screen_update_content_rect(screen);
update_content_rect(screen);
return true;
}
@@ -407,7 +402,8 @@ screen_set_rotation(struct screen *screen, unsigned rotation) {
screen->rotation = rotation;
LOGI("Display rotation set to %u", rotation);
screen_render(screen, true);
update_content_rect(screen);
screen_render(screen);
}
// recreate the texture and resize the window if the frame size has changed
@@ -424,7 +420,7 @@ prepare_for_frame(struct screen *screen, struct size new_frame_size) {
get_rotated_size(new_frame_size, screen->rotation);
set_content_size(screen, new_content_size);
screen_update_content_rect(screen);
update_content_rect(screen);
LOGI("New texture: %" PRIu16 "x%" PRIu16,
screen->frame_size.width, screen->frame_size.height);
@@ -466,16 +462,12 @@ screen_update_frame(struct screen *screen, struct video_buffer *vb) {
update_texture(screen, frame);
mutex_unlock(vb->mutex);
screen_render(screen, false);
screen_render(screen);
return true;
}
void
screen_render(struct screen *screen, bool update_content_rect) {
if (update_content_rect) {
screen_update_content_rect(screen);
}
screen_render(struct screen *screen) {
SDL_RenderClear(screen->renderer);
if (screen->rotation == 0) {
SDL_RenderCopy(screen->renderer, screen->texture, NULL, &screen->rect);
@@ -518,7 +510,8 @@ screen_switch_fullscreen(struct screen *screen) {
}
LOGD("Switched to %s mode", screen->fullscreen ? "fullscreen" : "windowed");
screen_render(screen, true);
update_content_rect(screen);
screen_render(screen);
}
void
@@ -556,10 +549,12 @@ screen_handle_window_event(struct screen *screen,
const SDL_WindowEvent *event) {
switch (event->event) {
case SDL_WINDOWEVENT_EXPOSED:
screen_render(screen, true);
update_content_rect(screen);
screen_render(screen);
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
screen_render(screen, true);
update_content_rect(screen);
screen_render(screen);
break;
case SDL_WINDOWEVENT_MAXIMIZED:
screen->maximized = true;

View File

@@ -97,11 +97,8 @@ bool
screen_update_frame(struct screen *screen, struct video_buffer *vb);
// render the texture to the renderer
//
// Set the update_content_rect flag if the window or content size may have
// changed, so that the content rectangle is recomputed
void
screen_render(struct screen *screen, bool update_content_rect);
screen_render(struct screen *screen);
// switch the fullscreen mode
void