diff options
Diffstat (limited to 'src/graphics.cc')
| -rw-r--r-- | src/graphics.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/graphics.cc b/src/graphics.cc index 0e34213..9027400 100644 --- a/src/graphics.cc +++ b/src/graphics.cc @@ -3,6 +3,8 @@ #include <EGL/egl.h> #include <EGL/eglplatform.h> +#include <cstring> + #include "utils.h" #include "wlstate.h" @@ -44,6 +46,7 @@ enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics, struct wlstate_s* state) { wayc_notnull(graphics); wayc_notnull(state); + memset(graphics, 0, sizeof(*graphics)); EGLDisplay display = eglGetDisplay(state->display); if (display == EGL_NO_DISPLAY) return GRAPHICS_ERROR_ACQUIRE_DISPLAY; @@ -90,3 +93,49 @@ void wayc_graphics_deinit(struct graphics_s* graphics) { graphics->display = nullptr; graphics->context = nullptr; } + +enum renderer_error_e wayc_renderer_init(struct renderer_s* renderer, + struct window_s* window, + struct graphics_s* graphics, i32 width, + i32 height) { + wayc_notnull(renderer); + wayc_notnull(window); + wayc_notnull(graphics); + memset(renderer, 0, sizeof(*renderer)); + + wl_egl_window_t ewindow = + wl_egl_window_create(window->surface, width, height); + if (ewindow == nullptr) return RENDERER_ERROR_WINDOW_CREATION; + + EGLNativeWindowType nwindow = (EGLNativeWindowType)ewindow; + + EGLSurface esurface = eglCreateWindowSurface( + graphics->display, graphics->config, nwindow, nullptr); + if (esurface == EGL_NO_SURFACE) { + wl_egl_window_destroy(ewindow); + return RENDERER_ERROR_SURFACE_CREATION; + } + + renderer->graphics = graphics; + renderer->ewindow = ewindow; + renderer->esurface = esurface; + renderer->width = width; + renderer->height = height; + + return RENDERER_ERROR_NONE; +} + +void wayc_renderer_deinit(struct renderer_s* renderer) { + wayc_notnull(renderer); + + if (renderer->graphics == nullptr || renderer->esurface == nullptr || + renderer->ewindow == nullptr) + return; + + eglDestroySurface(renderer->graphics->display, renderer->esurface); + wl_egl_window_destroy(renderer->ewindow); + + renderer->graphics = nullptr; + renderer->esurface = nullptr; + renderer->ewindow = nullptr; +} |
