rename display to texture

This commit is contained in:
Romain Vimont
2026-01-24 22:39:53 +01:00
parent 82c0ffc69b
commit c2e9aa85e3
5 changed files with 69 additions and 76 deletions

View File

@@ -15,7 +15,6 @@ src = [
'src/delay_buffer.c',
'src/demuxer.c',
'src/device_msg.c',
'src/display.c',
'src/events.c',
'src/icon.c',
'src/file_pusher.c',
@@ -33,6 +32,7 @@ src = [
'src/scrcpy.c',
'src/screen.c',
'src/server.c',
'src/texture.c',
'src/version.c',
'src/hid/hid_gamepad.c',
'src/hid/hid_keyboard.c',

View File

@@ -209,7 +209,7 @@ sc_screen_render(struct sc_screen *screen, bool update_content_rect) {
SDL_FRect *geometry = &screen->rect;
enum sc_orientation orientation = screen->orientation;
SDL_Texture *texture = sc_display_get_current_texture(&screen->display);
SDL_Texture *texture = sc_texture_get_sdl_texture(&screen->tex);
if (!texture) {
return;
}
@@ -418,7 +418,7 @@ sc_screen_init(struct sc_screen *screen,
}
bool mipmaps = params->video;
ok = sc_display_init(&screen->display, screen->renderer, mipmaps);
ok = sc_texture_init(&screen->tex, screen->renderer, mipmaps);
if (!ok) {
goto error_destroy_renderer;
}
@@ -426,7 +426,7 @@ sc_screen_init(struct sc_screen *screen,
ok = SDL_StartTextInput(screen->window);
if (!ok) {
LOGE("Could not enable text input: %s", SDL_GetError());
goto error_destroy_display;
goto error_destroy_texture;
}
SDL_Surface *icon = sc_icon_load_scrcpy();
@@ -440,17 +440,17 @@ sc_screen_init(struct sc_screen *screen,
} else {
// without video, the icon is used as window content, it must be present
LOGE("Could not load icon");
goto error_destroy_display;
goto error_destroy_texture;
}
if (!params->video) {
assert(icon);
screen->content_size.width = icon->w;
screen->content_size.height = icon->h;
ok = sc_display_set_texture_from_surface(&screen->display, icon);
ok = sc_texture_set_from_surface(&screen->tex, icon);
if (!ok) {
sc_icon_destroy(icon);
goto error_destroy_display;
goto error_destroy_texture;
}
}
@@ -461,7 +461,7 @@ sc_screen_init(struct sc_screen *screen,
screen->frame = av_frame_alloc();
if (!screen->frame) {
LOG_OOM();
goto error_destroy_display;
goto error_destroy_texture;
}
struct sc_input_manager_params im_params = {
@@ -517,8 +517,8 @@ sc_screen_init(struct sc_screen *screen,
return true;
error_destroy_display:
sc_display_destroy(&screen->display);
error_destroy_texture:
sc_texture_destroy(&screen->tex);
error_destroy_renderer:
SDL_DestroyRenderer(screen->renderer);
error_destroy_window:
@@ -582,7 +582,7 @@ sc_screen_destroy(struct sc_screen *screen) {
#ifndef NDEBUG
assert(!screen->open);
#endif
sc_display_destroy(&screen->display);
sc_texture_destroy(&screen->tex);
av_frame_free(&screen->frame);
SDL_DestroyRenderer(screen->renderer);
SDL_DestroyWindow(screen->window);
@@ -683,7 +683,7 @@ sc_screen_apply_frame(struct sc_screen *screen) {
}
}
bool ok = sc_display_set_texture_from_frame(&screen->display, frame);
bool ok = sc_texture_set_from_frame(&screen->tex, frame);
if (!ok) {
return false;
}

View File

@@ -12,12 +12,12 @@
#include "controller.h"
#include "coords.h"
#include "display.h"
#include "fps_counter.h"
#include "frame_buffer.h"
#include "input_manager.h"
#include "mouse_capture.h"
#include "options.h"
#include "texture.h"
#include "trait/key_processor.h"
#include "trait/frame_sink.h"
#include "trait/mouse_processor.h"
@@ -32,7 +32,7 @@ struct sc_screen {
bool video;
bool camera;
struct sc_display display;
struct sc_texture tex;
struct sc_input_manager im;
struct sc_mouse_capture mc; // only used in mouse relative mode
struct sc_frame_buffer fb;

View File

@@ -1,4 +1,4 @@
#include "display.h"
#include "texture.h"
#include <assert.h>
#include <inttypes.h>
@@ -8,12 +8,11 @@
#include "util/log.h"
bool
sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
bool mipmaps) {
sc_texture_init(struct sc_texture *tex, SDL_Renderer *renderer, bool mipmaps) {
const char *renderer_name = SDL_GetRendererName(renderer);
LOGI("Renderer: %s", renderer_name ? renderer_name : "(unknown)");
display->mipmaps = false;
tex->mipmaps = false;
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
display->gl_context = NULL;
@@ -40,7 +39,7 @@ sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
}
#endif
struct sc_opengl *gl = &display->gl;
struct sc_opengl *gl = &tex->gl;
sc_opengl_init(gl);
LOGI("OpenGL version: %s", gl->version);
@@ -51,7 +50,7 @@ sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
2, 0 /* OpenGL ES 2.0+ */);
if (supports_mipmaps) {
LOGI("Trilinear filtering enabled");
display->mipmaps = true;
tex->mipmaps = true;
} else {
LOGW("Trilinear filtering disabled "
"(OpenGL 3.0+ or ES 2.0+ required)");
@@ -63,23 +62,23 @@ sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
LOGD("Trilinear filtering disabled (not an OpenGL renderer)");
}
display->renderer = renderer;
display->texture = NULL;
tex->renderer = renderer;
tex->texture = NULL;
return true;
}
void
sc_display_destroy(struct sc_display *display) {
sc_texture_destroy(struct sc_texture *tex) {
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
SDL_GL_DestroyContext(display->gl_context);
SDL_GL_DestroyContext(tex->gl_context);
#endif
if (display->texture) {
SDL_DestroyTexture(display->texture);
if (tex->texture) {
SDL_DestroyTexture(tex->texture);
}
}
static enum SDL_Colorspace
sc_display_to_sdl_color_space(enum AVColorSpace color_space,
sc_texture_to_sdl_color_space(enum AVColorSpace color_space,
enum AVColorRange color_range) {
bool full_range = color_range == AVCOL_RANGE_JPEG;
@@ -102,7 +101,7 @@ sc_display_to_sdl_color_space(enum AVColorSpace color_space,
}
static SDL_Texture *
sc_display_create_frame_texture(struct sc_display *display,
sc_texture_create_frame_texture(struct sc_texture *tex,
struct sc_size size,
enum AVColorSpace color_space,
enum AVColorRange color_range) {
@@ -112,7 +111,7 @@ sc_display_create_frame_texture(struct sc_display *display,
}
enum SDL_Colorspace sdl_color_space =
sc_display_to_sdl_color_space(color_space, color_range);
sc_texture_to_sdl_color_space(color_space, color_range);
bool ok =
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER,
@@ -133,7 +132,7 @@ sc_display_create_frame_texture(struct sc_display *display,
return NULL;
}
SDL_Renderer *renderer = display->renderer;
SDL_Renderer *renderer = tex->renderer;
SDL_Texture *texture = SDL_CreateTextureWithProperties(renderer, props);
SDL_DestroyProperties(props);
if (!texture) {
@@ -141,8 +140,8 @@ sc_display_create_frame_texture(struct sc_display *display,
return NULL;
}
if (display->mipmaps) {
struct sc_opengl *gl = &display->gl;
if (tex->mipmaps) {
struct sc_opengl *gl = &tex->gl;
SDL_PropertiesID props = SDL_GetTextureProperties(texture);
if (!props) {
@@ -151,7 +150,7 @@ sc_display_create_frame_texture(struct sc_display *display,
return NULL;
}
const char *renderer_name = SDL_GetRendererName(display->renderer);
const char *renderer_name = SDL_GetRendererName(tex->renderer);
const char *key = !renderer_name || !strcmp(renderer_name, "opengl")
? SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER
: SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER;
@@ -165,8 +164,8 @@ sc_display_create_frame_texture(struct sc_display *display,
}
assert(!(texture_id & ~0xFFFFFFFF)); // fits in uint32_t
display->texture_id = texture_id;
gl->BindTexture(GL_TEXTURE_2D, display->texture_id);
tex->texture_id = texture_id;
gl->BindTexture(GL_TEXTURE_2D, tex->texture_id);
// Enable trilinear filtering for downscaling
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
@@ -180,41 +179,39 @@ sc_display_create_frame_texture(struct sc_display *display,
}
bool
sc_display_set_texture_from_frame(struct sc_display *display,
const AVFrame *frame) {
sc_texture_set_from_frame(struct sc_texture *tex, const AVFrame *frame) {
struct sc_size size = {frame->width, frame->height};
assert(size.width && size.height);
if (!display->texture
|| display->texture_type != SC_TEXTURE_TYPE_FRAME
|| display->texture_size.width != size.width
|| display->texture_size.height != size.height) {
if (!tex->texture
|| tex->texture_type != SC_TEXTURE_TYPE_FRAME
|| tex->texture_size.width != size.width
|| tex->texture_size.height != size.height) {
// Incompatible texture, recreate it
enum AVColorSpace color_space = frame->colorspace;
enum AVColorRange color_range = frame->color_range;
if (display->texture) {
SDL_DestroyTexture(display->texture);
if (tex->texture) {
SDL_DestroyTexture(tex->texture);
}
display->texture = sc_display_create_frame_texture(display, size,
color_space,
color_range);
if (!display->texture) {
tex->texture = sc_texture_create_frame_texture(tex, size, color_space,
color_range);
if (!tex->texture) {
return false;
}
display->texture_size = size;
display->texture_type = SC_TEXTURE_TYPE_FRAME;
tex->texture_size = size;
tex->texture_type = SC_TEXTURE_TYPE_FRAME;
LOGI("Texture: %" PRIu16 "x%" PRIu16, size.width, size.height);
}
assert(display->texture);
assert(display->texture_type == SC_TEXTURE_TYPE_FRAME);
assert(tex->texture);
assert(tex->texture_type == SC_TEXTURE_TYPE_FRAME);
bool ok = SDL_UpdateYUVTexture(display->texture, NULL,
bool ok = SDL_UpdateYUVTexture(tex->texture, NULL,
frame->data[0], frame->linesize[0],
frame->data[1], frame->linesize[1],
frame->data[2], frame->linesize[2]);
@@ -223,11 +220,11 @@ sc_display_set_texture_from_frame(struct sc_display *display,
return false;
}
if (display->mipmaps) {
assert(display->texture_id);
struct sc_opengl *gl = &display->gl;
if (tex->mipmaps) {
assert(tex->texture_id);
struct sc_opengl *gl = &tex->gl;
gl->BindTexture(GL_TEXTURE_2D, display->texture_id);
gl->BindTexture(GL_TEXTURE_2D, tex->texture_id);
gl->GenerateMipmap(GL_TEXTURE_2D);
gl->BindTexture(GL_TEXTURE_2D, 0);
}
@@ -236,26 +233,25 @@ sc_display_set_texture_from_frame(struct sc_display *display,
}
bool
sc_display_set_texture_from_surface(struct sc_display *display,
SDL_Surface *surface) {
if (display->texture) {
SDL_DestroyTexture(display->texture);
sc_texture_set_from_surface(struct sc_texture *tex, SDL_Surface *surface) {
if (tex->texture) {
SDL_DestroyTexture(tex->texture);
}
display->texture = SDL_CreateTextureFromSurface(display->renderer, surface);
if (!display->texture) {
tex->texture = SDL_CreateTextureFromSurface(tex->renderer, surface);
if (!tex->texture) {
LOGE("Could not create texture: %s", SDL_GetError());
return false;
}
display->texture_size.width = surface->w;
display->texture_size.height = surface->h;
display->texture_type = SC_TEXTURE_TYPE_ICON;
tex->texture_size.width = surface->w;
tex->texture_size.height = surface->h;
tex->texture_type = SC_TEXTURE_TYPE_ICON;
return true;
}
SDL_Texture *
sc_display_get_current_texture(struct sc_display *display) {
return display->texture;
sc_texture_get_sdl_texture(struct sc_texture *tex) {
return tex->texture;
}

View File

@@ -20,7 +20,7 @@ enum sc_texture_type {
SC_TEXTURE_TYPE_ICON,
};
struct sc_display {
struct sc_texture {
SDL_Renderer *renderer; // owned by the caller
SDL_Texture *texture;
// Only valid if texture != NULL
@@ -37,21 +37,18 @@ struct sc_display {
};
bool
sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
bool mipmaps);
sc_texture_init(struct sc_texture *tex, SDL_Renderer *renderer, bool mipmaps);
void
sc_display_destroy(struct sc_display *display);
sc_texture_destroy(struct sc_texture *tex);
bool
sc_display_set_texture_from_frame(struct sc_display *display,
const AVFrame *frame);
sc_texture_set_from_frame(struct sc_texture *tex, const AVFrame *frame);
bool
sc_display_set_texture_from_surface(struct sc_display *display,
SDL_Surface *surface);
sc_texture_set_from_surface(struct sc_texture *tex, SDL_Surface *surface);
SDL_Texture *
sc_display_get_current_texture(struct sc_display *display);
sc_texture_get_sdl_texture(struct sc_texture *tex);
#endif