gl-renderer: bikeshed GL version handling

The main point here is to print "GL ES %d.%d" instead of "GL ES 2"
because GL-renderer can and will use GL ES 3 features when present.
Saying it's GL ES 2 renderer is not quite true.

To print that, I need to extract major, minor from gr->gl_version and
those didn't have ready made macros yet. While writing the extraction,
make all these trivial functions, so that the compiler might warn us if
one passes e.g. negative literal numbers to gr_gl_version(). Explicit
types help keeping the bit operations safe too.

The only purpose for GR_GL_VERSION_INVALID was to fall back to version
2.0. Moving the fallback and logging into get_gl_version() makes that
macro unnecessary.

Finally, just in case GL version string contained garbage, reject
negative version numbers.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 4 years ago
parent fbd4160474
commit d8a0ba893d
  1. 47
      libweston/renderer-gl/gl-renderer.c

@ -58,12 +58,6 @@
#include "shared/timespec-util.h" #include "shared/timespec-util.h"
#include "shared/weston-egl-ext.h" #include "shared/weston-egl-ext.h"
#define GR_GL_VERSION(major, minor) \
(((uint32_t)(major) << 16) | (uint32_t)(minor))
#define GR_GL_VERSION_INVALID \
GR_GL_VERSION(0, 0)
#define BUFFER_DAMAGE_COUNT 2 #define BUFFER_DAMAGE_COUNT 2
enum gl_border_status { enum gl_border_status {
@ -219,6 +213,24 @@ struct timeline_render_point {
struct wl_event_source *event_source; struct wl_event_source *event_source;
}; };
static uint32_t
gr_gl_version(uint16_t major, uint16_t minor)
{
return ((uint32_t)major << 16) | minor;
}
static int
gr_gl_version_major(uint32_t ver)
{
return ver >> 16;
}
static int
gr_gl_version_minor(uint32_t ver)
{
return ver & 0xffff;
}
static inline const char * static inline const char *
dump_format(uint32_t format, char out[4]) dump_format(uint32_t format, char out[4])
{ {
@ -3658,11 +3670,13 @@ get_gl_version(void)
version = (const char *) glGetString(GL_VERSION); version = (const char *) glGetString(GL_VERSION);
if (version && if (version &&
(sscanf(version, "%d.%d", &major, &minor) == 2 || (sscanf(version, "%d.%d", &major, &minor) == 2 ||
sscanf(version, "OpenGL ES %d.%d", &major, &minor) == 2)) { sscanf(version, "OpenGL ES %d.%d", &major, &minor) == 2) &&
return GR_GL_VERSION(major, minor); major > 0 && minor >= 0) {
return gr_gl_version(major, minor);
} }
return GR_GL_VERSION_INVALID; weston_log("warning: failed to detect GLES version, defaulting to 2.0.\n");
return gr_gl_version(2, 0);
} }
static int static int
@ -3737,12 +3751,6 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
} }
gr->gl_version = get_gl_version(); gr->gl_version = get_gl_version();
if (gr->gl_version == GR_GL_VERSION_INVALID) {
weston_log("warning: failed to detect GLES version, "
"defaulting to 2.0.\n");
gr->gl_version = GR_GL_VERSION(2, 0);
}
log_gl_info(); log_gl_info();
gr->image_target_texture_2d = gr->image_target_texture_2d =
@ -3764,13 +3772,13 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
else else
ec->read_format = PIXMAN_a8b8g8r8; ec->read_format = PIXMAN_a8b8g8r8;
if (gr->gl_version < GR_GL_VERSION(3, 0) && if (gr->gl_version < gr_gl_version(3, 0) &&
!weston_check_egl_extension(extensions, "GL_EXT_unpack_subimage")) { !weston_check_egl_extension(extensions, "GL_EXT_unpack_subimage")) {
weston_log("GL_EXT_unpack_subimage not available.\n"); weston_log("GL_EXT_unpack_subimage not available.\n");
return -1; return -1;
} }
if (gr->gl_version >= GR_GL_VERSION(3, 0) || if (gr->gl_version >= gr_gl_version(3, 0) ||
weston_check_egl_extension(extensions, "GL_EXT_texture_rg")) weston_check_egl_extension(extensions, "GL_EXT_texture_rg"))
gr->has_gl_texture_rg = true; gr->has_gl_texture_rg = true;
@ -3795,13 +3803,14 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
wl_signal_add(&ec->output_destroyed_signal, wl_signal_add(&ec->output_destroyed_signal,
&gr->output_destroy_listener); &gr->output_destroy_listener);
weston_log("GL ES 2 renderer features:\n"); weston_log("GL ES %d.%d - renderer features:\n",
gr_gl_version_major(gr->gl_version),
gr_gl_version_minor(gr->gl_version));
weston_log_continue(STAMP_SPACE "read-back format: %s\n", weston_log_continue(STAMP_SPACE "read-back format: %s\n",
ec->read_format == PIXMAN_a8r8g8b8 ? "BGRA" : "RGBA"); ec->read_format == PIXMAN_a8r8g8b8 ? "BGRA" : "RGBA");
weston_log_continue(STAMP_SPACE "EGL Wayland extension: %s\n", weston_log_continue(STAMP_SPACE "EGL Wayland extension: %s\n",
gr->has_bind_display ? "yes" : "no"); gr->has_bind_display ? "yes" : "no");
return 0; return 0;
} }

Loading…
Cancel
Save