mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
comp: Use u_logging in some EGL code.
This commit is contained in:
parent
a6b6ab8e2c
commit
bf37b9d999
|
@ -21,6 +21,8 @@
|
|||
#include "client/comp_gl_memobj_swapchain.h"
|
||||
#include "client/comp_gl_eglimage_swapchain.h"
|
||||
#include "util/u_misc.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "util/u_debug.h"
|
||||
#include "xrt/xrt_gfx_egl.h"
|
||||
#include "xrt/xrt_handles.h"
|
||||
|
||||
|
@ -29,6 +31,16 @@
|
|||
#error "This file shouldn't be compiled without EGL"
|
||||
#endif
|
||||
|
||||
static enum u_logging_level ll;
|
||||
|
||||
#define EGL_TRACE(...) U_LOG_IFL_T(ll, __VA_ARGS__)
|
||||
#define EGL_DEBUG(...) U_LOG_IFL_D(ll, __VA_ARGS__)
|
||||
#define EGL_INFO(...) U_LOG_IFL_I(ll, __VA_ARGS__)
|
||||
#define EGL_WARN(...) U_LOG_IFL_W(ll, __VA_ARGS__)
|
||||
#define EGL_ERROR(...) U_LOG_IFL_E(ll, __VA_ARGS__)
|
||||
|
||||
DEBUG_GET_ONCE_LOG_OPTION(egl_log, "EGL_LOG", U_LOGGING_WARN)
|
||||
|
||||
// Not forward declared by mesa
|
||||
typedef EGLBoolean EGLAPIENTRY (*PFNEGLMAKECURRENTPROC)(EGLDisplay dpy,
|
||||
EGLSurface draw,
|
||||
|
@ -51,10 +63,11 @@ xrt_gfx_provider_create_gl_egl(struct xrt_compositor_native *xcn,
|
|||
EGLContext context,
|
||||
PFNEGLGETPROCADDRESSPROC get_gl_procaddr)
|
||||
{
|
||||
ll = debug_get_log_option_egl_log();
|
||||
|
||||
gladLoadEGL(display, get_gl_procaddr);
|
||||
if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context)) {
|
||||
fprintf(stderr, "Failed to make EGL context current\n");
|
||||
EGL_ERROR("Failed to make EGL context current");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -70,8 +83,7 @@ xrt_gfx_provider_create_gl_egl(struct xrt_compositor_native *xcn,
|
|||
gladLoadGL(get_gl_procaddr);
|
||||
break;
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"OpenGL support not including in this runtime build\n");
|
||||
EGL_ERROR("OpenGL support not including in this runtime build");
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
|
@ -81,33 +93,49 @@ xrt_gfx_provider_create_gl_egl(struct xrt_compositor_native *xcn,
|
|||
gladLoadGLES2(get_gl_procaddr);
|
||||
break;
|
||||
#else
|
||||
fprintf(
|
||||
stderr,
|
||||
"OpenGL|ES support not including in this runtime build\n");
|
||||
EGL_ERROR(
|
||||
"OpenGL|ES support not including in this runtime build");
|
||||
return NULL;
|
||||
#endif
|
||||
default: EGL_ERROR("Unsupported EGL client type"); return NULL;
|
||||
}
|
||||
struct client_gl_compositor *c =
|
||||
U_TYPED_CALLOC(struct client_gl_compositor);
|
||||
|
||||
client_gl_swapchain_create_func sc_create = NULL;
|
||||
|
||||
EGL_INFO("Extension availability:");
|
||||
#define DUMP_EXTENSION_STATUS(EXT) \
|
||||
EGL_INFO(" - " #EXT ": %s", GLAD_##EXT ? "true" : "false")
|
||||
|
||||
DUMP_EXTENSION_STATUS(GL_EXT_memory_object);
|
||||
DUMP_EXTENSION_STATUS(GL_EXT_memory_object_fd);
|
||||
DUMP_EXTENSION_STATUS(GL_EXT_memory_object_win32);
|
||||
DUMP_EXTENSION_STATUS(EGL_EXT_image_dma_buf_import);
|
||||
DUMP_EXTENSION_STATUS(GL_OES_EGL_image_external);
|
||||
DUMP_EXTENSION_STATUS(EGL_KHR_image);
|
||||
// DUMP_EXTENSION_STATUS(EGL_KHR_image_base);
|
||||
|
||||
#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
|
||||
if (GLAD_GL_EXT_memory_object && GLAD_GL_EXT_memory_object_fd) {
|
||||
EGL_INFO("Using GL memory object swapchain implementation");
|
||||
sc_create = client_gl_memobj_swapchain_create;
|
||||
}
|
||||
if (sc_create == NULL && GLAD_EGL_EXT_image_dma_buf_import) {
|
||||
EGL_INFO("Using EGL_Image swapchain implementation");
|
||||
sc_create = client_gl_eglimage_swapchain_create;
|
||||
}
|
||||
if (sc_create == NULL) {
|
||||
free(c);
|
||||
fprintf(stderr,
|
||||
"Could not find a required extension: need either "
|
||||
"EGL_EXT_image_dma_buf_import or "
|
||||
"GL_EXT_memory_object_fd\n");
|
||||
EGL_ERROR(
|
||||
"Could not find a required extension: need either "
|
||||
"EGL_EXT_image_dma_buf_import or "
|
||||
"GL_EXT_memory_object_fd");
|
||||
return NULL;
|
||||
}
|
||||
#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
|
||||
EGL_INFO(
|
||||
"Using EGL_Image swapchain implementation with AHardwareBuffer");
|
||||
sc_create = client_gl_eglimage_swapchain_create;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -15,23 +15,35 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "util/u_misc.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "util/u_debug.h"
|
||||
|
||||
#include <xrt/xrt_config_have.h>
|
||||
#include <xrt/xrt_config_os.h>
|
||||
#include <xrt/xrt_handles.h>
|
||||
|
||||
#if defined(XRT_HAVE_EGL)
|
||||
#include "ogl/egl_api.h"
|
||||
#endif
|
||||
#if defined(XRT_HAVE_OPENGL) || defined(XRT_HAVE_OPENGLES)
|
||||
#include "ogl/ogl_api.h"
|
||||
#endif
|
||||
|
||||
#include "client/comp_gl_client.h"
|
||||
#include "client/comp_gl_eglimage_swapchain.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
static enum u_logging_level ll;
|
||||
|
||||
#define EGL_SC_TRACE(...) U_LOG_IFL_T(ll, __VA_ARGS__)
|
||||
#define EGL_SC_DEBUG(...) U_LOG_IFL_D(ll, __VA_ARGS__)
|
||||
#define EGL_SC_INFO(...) U_LOG_IFL_I(ll, __VA_ARGS__)
|
||||
#define EGL_SC_WARN(...) U_LOG_IFL_W(ll, __VA_ARGS__)
|
||||
#define EGL_SC_ERROR(...) U_LOG_IFL_E(ll, __VA_ARGS__)
|
||||
|
||||
DEBUG_GET_ONCE_LOG_OPTION(egl_swapchain_log,
|
||||
"EGL_SWAPCHAIN_LOG",
|
||||
U_LOGGING_WARN)
|
||||
|
||||
|
||||
/*!
|
||||
* Down-cast helper.
|
||||
* @private @memberof client_gl_eglimage_swapchain
|
||||
|
@ -111,9 +123,9 @@ gl_format_to_drm_fourcc(uint64_t format)
|
|||
case GL_RGBA16F:
|
||||
#endif
|
||||
default:
|
||||
printf("Cannot convert VK format 0x%016" PRIx64
|
||||
" to DRM FOURCC format!\n",
|
||||
format);
|
||||
EGL_SC_ERROR("Cannot convert GL format 0x%08" PRIx64
|
||||
" to DRM FOURCC format!",
|
||||
format);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -130,9 +142,9 @@ gl_format_to_bpp(uint64_t format)
|
|||
case GL_RGBA16F:
|
||||
#endif
|
||||
default:
|
||||
printf("Cannot convert VK format 0x%016" PRIx64
|
||||
" to DRM FOURCC format!\n",
|
||||
format);
|
||||
EGL_SC_ERROR("Cannot convert GL format 0x%08" PRIx64
|
||||
" to DRM FOURCC format!",
|
||||
format);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +157,10 @@ client_gl_eglimage_swapchain_create(
|
|||
struct xrt_swapchain_native *xscn,
|
||||
struct client_gl_swapchain **out_sc)
|
||||
{
|
||||
ll = debug_get_log_option_egl_swapchain_log();
|
||||
|
||||
if (xscn == NULL) {
|
||||
EGL_SC_ERROR("Native compositor is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -154,11 +169,18 @@ client_gl_eglimage_swapchain_create(
|
|||
if (format == 0) {
|
||||
return NULL;
|
||||
}
|
||||
uint32_t row_bits = gl_format_to_bpp(info->format) * info->width;
|
||||
uint32_t row_pitch = row_bits / 8;
|
||||
if (row_pitch * 8 < row_bits) {
|
||||
// round up
|
||||
row_pitch += 1;
|
||||
uint32_t row_pitch = 0;
|
||||
{
|
||||
uint32_t bpp = gl_format_to_bpp(info->format);
|
||||
uint32_t row_bits = bpp * info->width;
|
||||
row_pitch = row_bits / 8;
|
||||
if (row_pitch * 8 < row_bits) {
|
||||
// round up
|
||||
row_pitch += 1;
|
||||
}
|
||||
EGL_SC_INFO("Computed row pitch is %" PRIu32 " bytes: %" PRIu32
|
||||
" bpp, %" PRIu32 " pixels wide",
|
||||
row_pitch, bpp, info->width);
|
||||
}
|
||||
#endif // defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
|
||||
|
||||
|
@ -178,7 +200,6 @@ client_gl_eglimage_swapchain_create(
|
|||
glGenTextures(native_xsc->num_images, xscgl->images);
|
||||
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < native_xsc->num_images; i++) {
|
||||
#ifdef XRT_OS_ANDROID
|
||||
glBindTexture(GL_TEXTURE_EXTERNAL_OES, xscgl->images[i]);
|
||||
|
@ -195,6 +216,7 @@ client_gl_eglimage_swapchain_create(
|
|||
eglGetNativeClientBufferANDROID(xscn->images[i].handle);
|
||||
|
||||
if (NULL == native_buffer) {
|
||||
EGL_SC_ERROR("eglGetNativeClientBufferANDROID failed");
|
||||
client_gl_eglimage_swapchain_teardown_storage(sc);
|
||||
free(sc);
|
||||
return NULL;
|
||||
|
@ -222,6 +244,7 @@ client_gl_eglimage_swapchain_create(
|
|||
sc->egl_images[i] = eglCreateImageKHR(
|
||||
sc->display, EGL_NO_CONTEXT, target, native_buffer, attrs);
|
||||
if (NULL == sc->egl_images[i]) {
|
||||
EGL_SC_ERROR("eglCreateImageKHR failed");
|
||||
client_gl_eglimage_swapchain_teardown_storage(sc);
|
||||
free(sc);
|
||||
return NULL;
|
||||
|
@ -230,6 +253,7 @@ client_gl_eglimage_swapchain_create(
|
|||
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
|
||||
sc->egl_images[i]);
|
||||
#else
|
||||
//! @todo this should be glTexImage2D I think.
|
||||
glEGLImageTargetTexture2DOES(
|
||||
info->array_size == 1 ? GL_TEXTURE_2D : GL_TEXTURE_2D_ARRAY,
|
||||
sc->egl_images[i]);
|
||||
|
|
Loading…
Reference in a new issue