Skip to content

Commit e32d5cc

Browse files
committed
vdisp/gl: more simplifications
1 parent a738567 commit e32d5cc

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;
@@ -824,19 +831,22 @@ display_gl_parse_fmt(struct state_gl *s, char *ptr)
824831
return false;
825832
}
826833
if (!strcmp(tok, "d") || !strcmp(tok, "dforce")) {
827-
s->deinterlace = !strcmp(tok, "d") ? state_gl::deint::on : state_gl::deint::force;
834+
s->deinterlace = !strcmp(tok, "d") ? DEINT_ON : DEINT_FORCE;
828835
} else if(!strncmp(tok, "fs", 2)) {
829836
s->fs = true;
830-
if (char *val = strchr(tok, '=')) {
831-
s->req_monitor_idx = stoi(val + 1);
837+
const char *val = strchr(tok, '=');
838+
if (val != nullptr) {
839+
s->req_monitor_idx =
840+
(int) strtol(val + 1, nullptr, 0);
832841
}
833842
} else if(strstr(tok, "modeset") != nullptr) {
834843
if (strcmp(tok, "nomodeset") != 0) {
835-
if (char *val = strchr(tok, '=')) {
844+
const char *val = strchr(tok, '=');
845+
if (val != nullptr) {
836846
val += 1;
837-
s->modeset = strcmp(val, "size") == 0 ? state_gl::MODESET_SIZE_ONLY : (enum state_gl::modeset_t) stoi(val);
847+
s->modeset = strcmp(val, "size") == 0 ? MODESET_SIZE_ONLY : (enum modeset) atoi(val);
838848
} else {
839-
s->modeset = state_gl::MODESET;
849+
s->modeset = MODESET;
840850
}
841851
}
842852
} else if(!strncmp(tok, "aspect=", strlen("aspect="))) {
@@ -859,7 +869,7 @@ display_gl_parse_fmt(struct state_gl *s, char *ptr)
859869
s->vsync = atoi(tok + strlen("vsync="));
860870
}
861871
} else if (!strcasecmp(tok, "cursor")) {
862-
s->show_cursor = state_gl::SC_TRUE;
872+
s->show_cursor = SC_TRUE;
863873
} else if (strstr(tok, "syphon") == tok || strstr(tok, "spout") == tok) {
864874
#if defined HAVE_SYPHON || defined HAVE_SPOUT
865875
if (strchr(tok, '=')) {
@@ -872,9 +882,9 @@ display_gl_parse_fmt(struct state_gl *s, char *ptr)
872882
return false;
873883
#endif
874884
} else if (strstr(tok, "gamma=") == tok) {
875-
s->gamma = stof(strchr(tok, '=') + 1);
885+
s->gamma = strtod(strchr(tok, '=') + 1, nullptr);
876886
if (strchr(tok, '/')) {
877-
s->gamma /= stof(strchr(tok, '/') + 1);
887+
s->gamma /= strtod(strchr(tok, '=') + 1, nullptr);
878888
}
879889
} else if (!strcasecmp(tok, "hide-window")) {
880890
dictionary_insert(s->window_hints,
@@ -945,7 +955,7 @@ static void * display_gl_init(struct module *parent, const char *fmt, unsigned i
945955
s->use_pbo = s->use_pbo == -1 ? !check_rpi_pbo_quirks() : s->use_pbo; // don't use PBO for Raspberry Pi (better performance)
946956

947957
log_msg(LOG_LEVEL_INFO,"GL setup: fullscreen: %s, deinterlace: %s\n",
948-
s->fs ? "ON" : "OFF", state_gl::deint_to_string(s->deinterlace));
958+
s->fs ? "ON" : "OFF", deint_to_string(s->deinterlace));
949959

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

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

1026-
static int get_refresh_rate(enum state_gl::modeset_t modeset, GLFWmonitor *mon, double video_refresh_rate) {
1036+
static int get_refresh_rate(enum modeset modeset, GLFWmonitor *mon, double video_refresh_rate) {
10271037
if (!mon) {
10281038
return GLFW_DONT_CARE;
10291039
}
10301040
switch (modeset) {
1031-
case state_gl::modeset_t::MODESET:
1041+
case MODESET:
10321042
return round(video_refresh_rate);
1033-
case state_gl::modeset_t::MODESET_SIZE_ONLY:
1043+
case MODESET_SIZE_ONLY:
10341044
return GLFW_DONT_CARE;
1035-
case state_gl::modeset_t::NOMODESET: {
1045+
case NOMODESET: {
10361046
const GLFWvidmode* mode = glfwGetVideoMode(mon);
10371047
return mode->refreshRate;
10381048
}
@@ -1050,7 +1060,7 @@ static void glfw_resize_window(GLFWwindow *win, bool fs, int height, double aspe
10501060
int width = round(height * aspect);
10511061
GLFWmonitor *mon = s->monitor;
10521062
int refresh_rate = get_refresh_rate(s->modeset, mon, fps);
1053-
if (s->modeset == state_gl::modeset_t::NOMODESET) {
1063+
if (s->modeset == NOMODESET) {
10541064
const GLFWvidmode* mode = glfwGetVideoMode(mon);
10551065
width = mode->width;
10561066
height = mode->height;
@@ -1331,7 +1341,7 @@ static void gl_process_frames(struct state_gl *s)
13311341
free_message(msg, r);
13321342
}
13331343

1334-
if (s->show_cursor == state_gl::SC_AUTOHIDE) {
1344+
if (s->show_cursor == SC_AUTOHIDE) {
13351345
if (s->cursor_shown_from != 0) {
13361346
const auto now = get_time_in_ns();
13371347
if (now - s->cursor_shown_from > SEC_TO_NS(2)) {
@@ -1373,7 +1383,7 @@ static void gl_process_frames(struct state_gl *s)
13731383
glBindTexture(GL_TEXTURE_2D, s->texture_display);
13741384

13751385
gl_render(s, frame->tiles[0].data);
1376-
if (s->deinterlace == state_gl::deint::force || (s->deinterlace == state_gl::deint::on && s->current_display_desc.interlacing == INTERLACED_MERGED)) {
1386+
if (s->deinterlace == DEINT_FORCE || (s->deinterlace == DEINT_ON && s->current_display_desc.interlacing == INTERLACED_MERGED)) {
13771387
glUseProgram(s->PHandle_deint);
13781388
}
13791389
gl_draw(s->aspect, (s->dxt_height - s->current_display_desc.height) / (float) s->dxt_height * 2, s->vsync != SINGLE_BUF);
@@ -1442,7 +1452,7 @@ static bool display_gl_process_key(struct state_gl *s, long long int key)
14421452
int width = s->current_display_desc.width;
14431453
int height = s->current_display_desc.height;
14441454
GLFWmonitor *mon = s->fs ? s->monitor : nullptr;
1445-
if (mon && s->modeset == state_gl::modeset_t::NOMODESET) {
1455+
if (mon && s->modeset == NOMODESET) {
14461456
const GLFWvidmode* mode = glfwGetVideoMode(mon);
14471457
width = mode->width;
14481458
height = mode->height;
@@ -1458,9 +1468,9 @@ static bool display_gl_process_key(struct state_gl *s, long long int key)
14581468
exit_uv(0);
14591469
break;
14601470
case K_ALT('d'):
1461-
s->deinterlace = s->deinterlace == state_gl::deint::off ? state_gl::deint::on : state_gl::deint::off;
1471+
s->deinterlace = s->deinterlace == DEINT_OFF ? DEINT_ON : DEINT_OFF;
14621472
MSG(NOTICE, "Deinterlacing: %s\n",
1463-
state_gl::deint_to_string(s->deinterlace));
1473+
deint_to_string(s->deinterlace));
14641474
break;
14651475
case K_ALT('p'):
14661476
s->paused = !s->paused;
@@ -1472,9 +1482,9 @@ static bool display_gl_process_key(struct state_gl *s, long long int key)
14721482
screenshot(s->current_frame);
14731483
break;
14741484
case K_ALT('m'):
1475-
s->show_cursor = (state_gl::show_cursor_t) (((int) s->show_cursor + 1) % 3);
1485+
s->show_cursor = (enum show_cursor) (((int) s->show_cursor + 1) % 3);
14761486
LOG(LOG_LEVEL_NOTICE) << MOD_NAME << "Show cursor (0 - on, 1 - off, 2 - autohide): " << s->show_cursor << "\n";
1477-
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == state_gl::SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
1487+
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
14781488
break;
14791489
case K_CTRL_UP:
14801490
s->window_size_factor *= 1.1;
@@ -1517,7 +1527,7 @@ static void glfw_key_callback(GLFWwindow* win, int key, int /* scancode */, int
15171527
static void glfw_mouse_callback(GLFWwindow *win, double /* x */, double /* y */)
15181528
{
15191529
auto *s = (struct state_gl *) glfwGetWindowUserPointer(win);
1520-
if (s->show_cursor == state_gl::SC_AUTOHIDE) {
1530+
if (s->show_cursor == SC_AUTOHIDE) {
15211531
if (s->cursor_shown_from == 0) {
15221532
glfwSetInputMode(s->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
15231533
}
@@ -1612,18 +1622,18 @@ static void set_mac_color_space(void) {
16121622
if (!col) {
16131623
return;
16141624
}
1615-
glfwWindowHint(GLFW_COCOA_NS_COLOR_SPACE, stoi(col, nullptr, 16));
1625+
glfwWindowHint(GLFW_COCOA_NS_COLOR_SPACE, strtoul(col, nullptr, 16));
16161626
#endif // defined GLFW_COCOA_NS_COLOR_SPACE
16171627
}
16181628

16191629
static GLuint gl_substitute_compile_link(const char *vprogram, const char *fprogram)
16201630
{
16211631
char *fp = strdup(fprogram);
1622-
int index = 1;
1632+
unsigned index = 1;
16231633
const char *col = get_commandline_param("color");
16241634
if (col) {
1625-
int color = stol(col, nullptr, 16) >> 4; // first nibble
1626-
if (color > 0 && color <= 3) {
1635+
unsigned color = strtoul(col, nullptr, 16) >> 4; // first nibble
1636+
if (color <= 3) {
16271637
index = color;
16281638
} else {
16291639
LOG(LOG_LEVEL_WARNING) << MOD_NAME "Wrong chromicities index " << color << "\n";
@@ -1758,7 +1768,7 @@ static bool display_gl_init_opengl(struct state_gl *s)
17581768
if (s->fixed_size && s->fixed_w && s->fixed_h) {
17591769
width = s->fixed_w;
17601770
height = s->fixed_h;
1761-
} else if (mon != nullptr && s->modeset == state_gl::modeset_t::NOMODESET) {
1771+
} else if (mon != nullptr && s->modeset == NOMODESET) {
17621772
const GLFWvidmode* mode = glfwGetVideoMode(mon);
17631773
width = mode->width;
17641774
height = mode->height;
@@ -1782,7 +1792,7 @@ static bool display_gl_init_opengl(struct state_gl *s)
17821792
glfw_print_video_mode(s);
17831793
glfwSetWindowUserPointer(s->window, s);
17841794
set_gamma(s);
1785-
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == state_gl::SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
1795+
glfwSetInputMode(s->window, GLFW_CURSOR, s->show_cursor == SC_TRUE ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
17861796
glfwMakeContextCurrent(s->window);
17871797
glfwSetKeyCallback(s->window, glfw_key_callback);
17881798
glfwSetCursorPosCallback(s->window, glfw_mouse_callback);

0 commit comments

Comments
 (0)