Skip to content

Commit 1c1d144

Browse files
committed
vdisp/gl: more simplifications
1 parent f34ce2e commit 1c1d144

File tree

1 file changed

+54
-44
lines changed

1 file changed

+54
-44
lines changed

src/video_display/gl.cpp

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ using std::cout;
103103
using std::lock_guard;
104104
using std::mutex;
105105
using std::queue;
106-
using std::stof;
107-
using std::stoi;
108-
using std::stol;
109106
using std::string;
110107
using std::swap;
111108
using std::unique_lock;
@@ -417,6 +414,10 @@ static void upload_texture(struct state_gl *s, char *data);
417414
static bool check_rpi_pbo_quirks();
418415
static void set_gamma(struct state_gl *s);
419416

417+
enum show_cursor { SC_AUTOHIDE, SC_TRUE, SC_FALSE };
418+
enum deint { DEINT_OFF, DEINT_ON, DEINT_FORCE };
419+
enum modeset { MODESET = -2, MODESET_SIZE_ONLY = GLFW_DONT_CARE, NOMODESET = 0 };
420+
420421
struct state_gl {
421422
GLuint PHandles[VC_COUNT] = {};
422423
GLuint PHandle_deint = 0;
@@ -435,7 +436,7 @@ struct state_gl {
435436
GLFWwindow *window = nullptr;
436437

437438
bool fs = false;
438-
enum class deint { off, on, force } deinterlace = deint::off;
439+
enum deint deinterlace = DEINT_OFF;
439440

440441
struct video_frame *current_frame = nullptr;
441442

@@ -456,7 +457,7 @@ struct state_gl {
456457
int vsync = 1;
457458
bool noresizable = false;
458459
volatile bool paused = false;
459-
enum show_cursor_t { SC_TRUE, SC_FALSE, SC_AUTOHIDE } show_cursor = SC_AUTOHIDE;
460+
enum show_cursor show_cursor = SC_AUTOHIDE;
460461
time_ns_t cursor_shown_from{}; ///< indicates time point from which is cursor show if show_cursor == SC_AUTOHIDE, timepoint() means cursor is not currently shown
461462
string syphon_spout_srv_name;
462463

@@ -472,7 +473,7 @@ struct state_gl {
472473
int pos_x = INT_MIN;
473474
int pos_y = INT_MIN;
474475

475-
enum modeset_t { MODESET = -2, MODESET_SIZE_ONLY = GLFW_DONT_CARE, NOMODESET = 0 } modeset = NOMODESET; ///< positive vals force framerate
476+
enum modeset modeset = NOMODESET; ///< positive vals force framerate
476477
struct dictionary *window_hints;
477478
int use_pbo = -1;
478479
int req_monitor_idx = -1;
@@ -482,16 +483,22 @@ struct state_gl {
482483
bool vdp_interop = false;
483484
void* scratchpad{}; ///< scratchpad sized WxHx8
484485

485-
static const char *deint_to_string(state_gl::deint val) {
486-
switch (val) {
487-
case state_gl::deint::off: return "OFF";
488-
case state_gl::deint::on: return "ON";
489-
case state_gl::deint::force: return "FORCE";
490-
}
491-
return NULL;
492-
}
493486
};
494487

488+
static const char *
489+
deint_to_string(enum deint val)
490+
{
491+
switch (val) {
492+
case DEINT_OFF:
493+
return "OFF";
494+
case DEINT_ON:
495+
return "ON";
496+
case DEINT_FORCE:
497+
return "FORCE";
498+
}
499+
return nullptr;
500+
}
501+
495502
static void gl_print_monitors(bool fullhelp) {
496503
printf("\nmonitors:\n");
497504
int count = 0;
@@ -823,19 +830,22 @@ display_gl_parse_fmt(struct state_gl *s, char *ptr)
823830
return false;
824831
}
825832
if (!strcmp(tok, "d") || !strcmp(tok, "dforce")) {
826-
s->deinterlace = !strcmp(tok, "d") ? state_gl::deint::on : state_gl::deint::force;
833+
s->deinterlace = !strcmp(tok, "d") ? DEINT_ON : DEINT_FORCE;
827834
} else if(!strncmp(tok, "fs", 2)) {
828835
s->fs = true;
829-
if (char *val = strchr(tok, '=')) {
830-
s->req_monitor_idx = stoi(val + 1);
836+
const char *val = strchr(tok, '=');
837+
if (val != nullptr) {
838+
s->req_monitor_idx =
839+
(int) strtol(val + 1, nullptr, 0);
831840
}
832841
} else if(strstr(tok, "modeset") != nullptr) {
833842
if (strcmp(tok, "nomodeset") != 0) {
834-
if (char *val = strchr(tok, '=')) {
843+
const char *val = strchr(tok, '=');
844+
if (val != nullptr) {
835845
val += 1;
836-
s->modeset = strcmp(val, "size") == 0 ? state_gl::MODESET_SIZE_ONLY : (enum state_gl::modeset_t) stoi(val);
846+
s->modeset = strcmp(val, "size") == 0 ? MODESET_SIZE_ONLY : (enum modeset) atoi(val);
837847
} else {
838-
s->modeset = state_gl::MODESET;
848+
s->modeset = MODESET;
839849
}
840850
}
841851
} else if(!strncmp(tok, "aspect=", strlen("aspect="))) {
@@ -858,7 +868,7 @@ display_gl_parse_fmt(struct state_gl *s, char *ptr)
858868
s->vsync = atoi(tok + strlen("vsync="));
859869
}
860870
} else if (!strcasecmp(tok, "cursor")) {
861-
s->show_cursor = state_gl::SC_TRUE;
871+
s->show_cursor = SC_TRUE;
862872
} else if (strstr(tok, "syphon") == tok || strstr(tok, "spout") == tok) {
863873
#if defined HAVE_SYPHON || defined HAVE_SPOUT
864874
if (strchr(tok, '=')) {
@@ -871,9 +881,9 @@ display_gl_parse_fmt(struct state_gl *s, char *ptr)
871881
return false;
872882
#endif
873883
} else if (strstr(tok, "gamma=") == tok) {
874-
s->gamma = stof(strchr(tok, '=') + 1);
884+
s->gamma = strtod(strchr(tok, '=') + 1, nullptr);
875885
if (strchr(tok, '/')) {
876-
s->gamma /= stof(strchr(tok, '/') + 1);
886+
s->gamma /= strtod(strchr(tok, '=') + 1, nullptr);
877887
}
878888
} else if (!strcasecmp(tok, "hide-window")) {
879889
dictionary_insert(s->window_hints,
@@ -944,7 +954,7 @@ static void * display_gl_init(struct module *parent, const char *fmt, unsigned i
944954
s->use_pbo = s->use_pbo == -1 ? !check_rpi_pbo_quirks() : s->use_pbo; // don't use PBO for Raspberry Pi (better performance)
945955

946956
log_msg(LOG_LEVEL_INFO,"GL setup: fullscreen: %s, deinterlace: %s\n",
947-
s->fs ? "ON" : "OFF", state_gl::deint_to_string(s->deinterlace));
957+
s->fs ? "ON" : "OFF", deint_to_string(s->deinterlace));
948958

949959
gl_load_splashscreen(s);
950960
for (unsigned i = 0; i < countof(keybindings); i++) {
@@ -1005,7 +1015,7 @@ display_gl_reconfigure(void *state, struct video_desc desc)
10051015
if (get_bits_per_component(desc.color_spec) > 8) {
10061016
LOG(LOG_LEVEL_WARNING) << MOD_NAME "Displaying 10+ bits - performance degradation may occur, consider '--param " GL_DISABLE_10B_OPT_PARAM_NAME "'\n";
10071017
}
1008-
if (desc.interlacing == INTERLACED_MERGED && s->deinterlace == state_gl::deint::off) {
1018+
if (desc.interlacing == INTERLACED_MERGED && s->deinterlace == DEINT_OFF) {
10091019
LOG(LOG_LEVEL_WARNING) << MOD_NAME "Receiving interlaced video but deinterlacing is off - suggesting toggling it on (press 'd' or pass cmdline option)\n";
10101020
}
10111021

@@ -1022,16 +1032,16 @@ static void glfw_print_video_mode(struct state_gl *s) {
10221032
LOG(LOG_LEVEL_NOTICE) << MOD_NAME << "Display mode set to: " << mode->width << "x" << mode->height << "@" << mode->refreshRate << "\n";
10231033
}
10241034

1025-
static int get_refresh_rate(enum state_gl::modeset_t modeset, GLFWmonitor *mon, double video_refresh_rate) {
1035+
static int get_refresh_rate(enum modeset modeset, GLFWmonitor *mon, double video_refresh_rate) {
10261036
if (!mon) {
10271037
return GLFW_DONT_CARE;
10281038
}
10291039
switch (modeset) {
1030-
case state_gl::modeset_t::MODESET:
1040+
case MODESET:
10311041
return round(video_refresh_rate);
1032-
case state_gl::modeset_t::MODESET_SIZE_ONLY:
1042+
case MODESET_SIZE_ONLY:
10331043
return GLFW_DONT_CARE;
1034-
case state_gl::modeset_t::NOMODESET: {
1044+
case NOMODESET: {
10351045
const GLFWvidmode* mode = glfwGetVideoMode(mon);
10361046
return mode->refreshRate;
10371047
}
@@ -1049,7 +1059,7 @@ static void glfw_resize_window(GLFWwindow *win, bool fs, int height, double aspe
10491059
int width = round(height * aspect);
10501060
GLFWmonitor *mon = s->monitor;
10511061
int refresh_rate = get_refresh_rate(s->modeset, mon, fps);
1052-
if (s->modeset == state_gl::modeset_t::NOMODESET) {
1062+
if (s->modeset == NOMODESET) {
10531063
const GLFWvidmode* mode = glfwGetVideoMode(mon);
10541064
width = mode->width;
10551065
height = mode->height;
@@ -1330,7 +1340,7 @@ static void gl_process_frames(struct state_gl *s)
13301340
free_message(msg, r);
13311341
}
13321342

1333-
if (s->show_cursor == state_gl::SC_AUTOHIDE) {
1343+
if (s->show_cursor == SC_AUTOHIDE) {
13341344
if (s->cursor_shown_from != 0) {
13351345
const auto now = get_time_in_ns();
13361346
if (now - s->cursor_shown_from > SEC_TO_NS(2)) {
@@ -1372,7 +1382,7 @@ static void gl_process_frames(struct state_gl *s)
13721382
glBindTexture(GL_TEXTURE_2D, s->texture_display);
13731383

13741384
gl_render(s, frame->tiles[0].data);
1375-
if (s->deinterlace == state_gl::deint::force || (s->deinterlace == state_gl::deint::on && s->current_display_desc.interlacing == INTERLACED_MERGED)) {
1385+
if (s->deinterlace == DEINT_FORCE || (s->deinterlace == DEINT_ON && s->current_display_desc.interlacing == INTERLACED_MERGED)) {
13761386
glUseProgram(s->PHandle_deint);
13771387
}
13781388
gl_draw(s->aspect, (s->dxt_height - s->current_display_desc.height) / (float) s->dxt_height * 2, s->vsync != SINGLE_BUF);
@@ -1441,7 +1451,7 @@ static bool display_gl_process_key(struct state_gl *s, long long int key)
14411451
int width = s->current_display_desc.width;
14421452
int height = s->current_display_desc.height;
14431453
GLFWmonitor *mon = s->fs ? s->monitor : nullptr;
1444-
if (mon && s->modeset == state_gl::modeset_t::NOMODESET) {
1454+
if (mon && s->modeset == NOMODESET) {
14451455
const GLFWvidmode* mode = glfwGetVideoMode(mon);
14461456
width = mode->width;
14471457
height = mode->height;
@@ -1457,9 +1467,9 @@ static bool display_gl_process_key(struct state_gl *s, long long int key)
14571467
exit_uv(0);
14581468
break;
14591469
case K_ALT('d'):
1460-
s->deinterlace = s->deinterlace == state_gl::deint::off ? state_gl::deint::on : state_gl::deint::off;
1470+
s->deinterlace = s->deinterlace == DEINT_OFF ? DEINT_ON : DEINT_OFF;
14611471
MSG(NOTICE, "Deinterlacing: %s\n",
1462-
state_gl::deint_to_string(s->deinterlace));
1472+
deint_to_string(s->deinterlace));
14631473
break;
14641474
case K_ALT('p'):
14651475
s->paused = !s->paused;
@@ -1471,9 +1481,9 @@ static bool display_gl_process_key(struct state_gl *s, long long int key)
14711481
screenshot(s->current_frame);
14721482
break;
14731483
case K_ALT('m'):
1474-
s->show_cursor = (state_gl::show_cursor_t) (((int) s->show_cursor + 1) % 3);
1484+
s->show_cursor = (enum show_cursor) (((int) s->show_cursor + 1) % 3);
14751485
LOG(LOG_LEVEL_NOTICE) << MOD_NAME << "Show cursor (0 - on, 1 - off, 2 - autohide): " << s->show_cursor << "\n";
1476-
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == state_gl::SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
1486+
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
14771487
break;
14781488
case K_CTRL_UP:
14791489
s->window_size_factor *= 1.1;
@@ -1516,7 +1526,7 @@ static void glfw_key_callback(GLFWwindow* win, int key, int /* scancode */, int
15161526
static void glfw_mouse_callback(GLFWwindow *win, double /* x */, double /* y */)
15171527
{
15181528
auto *s = (struct state_gl *) glfwGetWindowUserPointer(win);
1519-
if (s->show_cursor == state_gl::SC_AUTOHIDE) {
1529+
if (s->show_cursor == SC_AUTOHIDE) {
15201530
if (s->cursor_shown_from == 0) {
15211531
glfwSetInputMode(s->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
15221532
}
@@ -1611,18 +1621,18 @@ static void set_mac_color_space(void) {
16111621
if (!col) {
16121622
return;
16131623
}
1614-
glfwWindowHint(GLFW_COCOA_NS_COLOR_SPACE, stoi(col, nullptr, 16));
1624+
glfwWindowHint(GLFW_COCOA_NS_COLOR_SPACE, strtoul(col, nullptr, 16));
16151625
#endif // defined GLFW_COCOA_NS_COLOR_SPACE
16161626
}
16171627

16181628
static GLuint gl_substitute_compile_link(const char *vprogram, const char *fprogram)
16191629
{
16201630
char *fp = strdup(fprogram);
1621-
int index = 1;
1631+
unsigned index = 1;
16221632
const char *col = get_commandline_param("color");
16231633
if (col) {
1624-
int color = stol(col, nullptr, 16) >> 4; // first nibble
1625-
if (color > 0 && color <= 3) {
1634+
unsigned color = strtoul(col, nullptr, 16) >> 4; // first nibble
1635+
if (color <= 3) {
16261636
index = color;
16271637
} else {
16281638
LOG(LOG_LEVEL_WARNING) << MOD_NAME "Wrong chromicities index " << color << "\n";
@@ -1757,7 +1767,7 @@ static bool display_gl_init_opengl(struct state_gl *s)
17571767
if (s->fixed_size && s->fixed_w && s->fixed_h) {
17581768
width = s->fixed_w;
17591769
height = s->fixed_h;
1760-
} else if (mon != nullptr && s->modeset == state_gl::modeset_t::NOMODESET) {
1770+
} else if (mon != nullptr && s->modeset == NOMODESET) {
17611771
const GLFWvidmode* mode = glfwGetVideoMode(mon);
17621772
width = mode->width;
17631773
height = mode->height;
@@ -1781,7 +1791,7 @@ static bool display_gl_init_opengl(struct state_gl *s)
17811791
glfw_print_video_mode(s);
17821792
glfwSetWindowUserPointer(s->window, s);
17831793
set_gamma(s);
1784-
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == state_gl::SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
1794+
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
17851795
glfwMakeContextCurrent(s->window);
17861796
glfwSetKeyCallback(s->window, glfw_key_callback);
17871797
glfwSetCursorPosCallback(s->window, glfw_mouse_callback);

0 commit comments

Comments
 (0)