Skip to content

Commit

Permalink
feat(simulator) add glfw3 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
etag4048 committed Nov 7, 2024
1 parent 39735e1 commit 0b9cbce
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)
project(lvgl)

foreach(BACKEND_NAME "SDL" "LINUX_DRM" "LINUX_FBDEV" "X11" "WAYLAND")
foreach(BACKEND_NAME "SDL" "LINUX_DRM" "LINUX_FBDEV" "X11" "WAYLAND" "OPENGLES")
execute_process(COMMAND "scripts/backend_conf.sh" ${BACKEND_NAME} OUTPUT_VARIABLE IS_BACKEND_ENABLED)
set("LV_USE_${BACKEND_NAME}" ${IS_BACKEND_ENABLED})
endforeach()
Expand Down Expand Up @@ -65,6 +65,16 @@ elseif (LV_USE_LINUX_FBDEV)
add_executable(lvglsim ${SIM_SRC} src/backends/fbdev.c)
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg m pthread)

elseif (LV_USE_OPENGLES)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW3 REQUIRED glfw3)
pkg_check_modules(GLEW REQUIRED glew)

add_executable(lvglsim ${SIM_SRC} src/backends/glfw3.c)
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg
m pthread ${GLFW3_LIBRARIES} ${GLEW_LIBRARIES})

endif()

add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/lvglsim DEPENDS lvglsim)
55 changes: 55 additions & 0 deletions src/backends/glfw3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @file glfw3.c
*
* The backend for the glfw3 library
*
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>

#include "lvgl/lvgl.h"
#include "settings.h"
#include "util.h"

void lv_linux_disp_init(void)
{
lv_glfw_texture_t *window_texture;
lv_indev_t *mouse;
lv_display_t *disp_texture;
uint32_t disp_texture_id;
lv_obj_t *cursor_obj;

/* create a window and initialize OpenGL */
lv_glfw_window_t * window = lv_glfw_window_create(window_width, window_height, true);

/* create a display that flushes to a texture */
disp_texture = lv_opengles_texture_create(window_width, window_height);
lv_display_set_default(disp_texture);

/* add the texture to the window */
disp_texture_id = lv_opengles_texture_get_texture_id(disp_texture);
window_texture = lv_glfw_window_add_texture(window, disp_texture_id,
window_width, window_height);

/* get the mouse indev of the window texture */
mouse = lv_glfw_texture_get_mouse_indev(window_texture);

/* add a cursor to the mouse indev */
LV_IMAGE_DECLARE(mouse_cursor_icon);
cursor_obj = lv_image_create(lv_screen_active());
lv_image_set_src(cursor_obj, &mouse_cursor_icon);
lv_indev_set_cursor(mouse, cursor_obj);
}

void lv_linux_run_loop(void)
{
uint32_t idle_time;

/* Handle LVGL tasks */
while (true) {

idle_time = lv_timer_handler(); /* Returns the time to the next timer execution */
usleep(idle_time * 1000);
}
}
1 change: 1 addition & 0 deletions src/backends/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#if LV_USE_SDL == 0 && \
LV_USE_WAYLAND == 0 && \
LV_USE_LINUX_DRM == 0 && \
LV_USE_OPENGLES == 0 && \
LV_USE_LINUX_FBDEV == 0

#error Unsupported configuration - Please select at least one backend in lv_conf.h
Expand Down

0 comments on commit 0b9cbce

Please sign in to comment.