#include <EGL/egl.h>
#include <EGL/eglext.h>
-#include "libwindowmanager.h"
+#include <unistd.h>
+#include <time.h>
+
+#include <libwindowmanager.h>
#include <libhomescreen.hpp>
#include <ilm/ivi-application-client-protocol.h>
-using namespace std;
+#include "hmi-debug.h"
+using namespace std;
+const char* log_prefix = "simple-egl";
uint32_t g_id_ivisurf = 9009;
long port = 1700;
string token = string("wm");
-bool enable_debug = false;
string app_name = string("Navigation");
+const char* main_role = "navigation";
LibHomeScreen* hs;
LibWindowmanager *wm;
static int running = 1;
-static void debug_out(const char* str, ...)
-{
- if(!enable_debug)
- return;
- char *out;
- va_list arg_ptr;
- va_start(arg_ptr, str);
- vasprintf(&out, str, arg_ptr);
- cout << out;
- va_end(arg_ptr);
- // cout << endl;
-}
-
static void
init_egl(struct display *display, struct window *window)
{
if (window->opaque || window->buffer_size == 16)
config_attribs[9] = 0;
-
+
display->egl.dpy = weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR, display->display, NULL);
assert(display->egl.dpy);
}
free(configs);
if (display->egl.conf == NULL) {
- debug_out("did not find config with buffer size %d\n",
+ HMI_ERROR(log_prefix,"did not find config with buffer size %d",
window->buffer_size);
exit(EXIT_FAILURE);
}
eglGetProcAddress("eglSwapBuffersWithDamageEXT");
if (display->swap_buffers_with_damage)
- debug_out("has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage\n");
+ HMI_DEBUG(log_prefix,"has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage");
}
char log[1000];
GLsizei len;
glGetShaderInfoLog(shader, 1000, &len, log);
- debug_out("Error: compiling %s: %*s\n",
+ HMI_ERROR(log_prefix,"Error: compiling %s: %*s",
shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
len, log);
exit(1);
char log[1000];
GLsizei len;
glGetProgramInfoLog(program, 1000, &len, log);
- debug_out("Error: linking:\n%*s\n", len, log);
+ HMI_ERROR(log_prefix,"Error: linking:%*s", len, log);
exit(1);
}
glGetUniformLocation(program, "rotation");
}
-static void
-handle_ivi_surface_configure(void *data, struct ivi_surface *ivi_surface,
- int32_t width, int32_t height)
-{
- struct window *window = data;
-
- wl_egl_window_resize(window->native, width, height, 0, 0);
-
- window->geometry.width = width;
- window->geometry.height = height;
-
- if (!window->fullscreen)
- window->window_size = window->geometry;
-}
-
-static const struct ivi_surface_listener ivi_surface_listener = {
- handle_ivi_surface_configure,
-};
-
static void
create_ivi_surface(struct window *window, struct display *display)
{
id_ivisurf, window->surface);
if (window->ivi_surface == NULL) {
- debug_out("Failed to create ivi_client_surface\n");
+ HMI_ERROR(log_prefix,"Failed to create ivi_client_surface");
abort();
}
- ivi_surface_add_listener(window->ivi_surface,
- &ivi_surface_listener, window);
}
static void
{ 0, 0.5 }
};
- static const GLfloat colors_H[3][3] = {
- { 1, 1, 1 },
- { 1, 1, 1 },
- { 1, 1, 1 }
- };
-
- static const GLfloat colors_N[3][3] = {
+ static const GLfloat colors[3][3] = {
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 }
time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
if (window->frames == 0)
window->benchmark_time = time;
+
if (time - window->benchmark_time > (benchmark_interval * 1000)) {
- debug_out("%d frames in %d seconds: %f fps\n",
+ HMI_DEBUG(log_prefix,"%d frames in %d seconds: %f fps",
window->frames,
benchmark_interval,
(float) window->frames / benchmark_interval);
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
- if(app_name == string("HVAC")){
- glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors_H);
- }
- else{
- glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors_N);
- }
+ glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);
glEnableVertexAttribArray(window->gl.pos);
glEnableVertexAttribArray(window->gl.col);
} else {
eglSwapBuffers(display->egl.dpy, window->egl_surface);
}
-
+
window->frames++;
}
}
int
-init_wm(LibWindowmanager *wm)
+init_wm(LibWindowmanager *wm, struct window *window)
{
- char* surfaceIdStr;
+ HMI_DEBUG(log_prefix,"called");
- if (wm->init(port, token.c_str()) != 0) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] wm init failed. \n");
- return -1;
+ if (wm->init(port, token) != 0) {
+ HMI_ERROR(log_prefix,"wm init failed. ");
+ return -1;
}
- if (wm->requestSurface(app_name.c_str()) != 0) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] wm request surface failed \n");
+ g_id_ivisurf = wm->requestSurface(main_role);
+ if (g_id_ivisurf < 0) {
+ HMI_ERROR(log_prefix,"wm request surface failed ");
return -1;
}
+ HMI_DEBUG(log_prefix,"IVI_SURFACE_ID: %d ", g_id_ivisurf);
- wm->set_event_handler(LibWindowmanager::Event_Active, [](char const *label) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got activated! \n", label);
- });
-
- wm->set_event_handler(LibWindowmanager::Event_Inactive, [](char const *label) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got inactivated!\n", label);
- });
-
- wm->set_event_handler(LibWindowmanager::Event_Visible, [wm](char const *label) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got visibled!\n", label);
- });
+ WMHandler wmh;
+ wmh.on_visible = [](const char* role, bool visible){
+ // Sample code if user uses visible event
+ HMI_DEBUG(log_prefix, "role: %s, visible: %s", role, visible ? "true" : "false");
+ };
+ wmh.on_sync_draw = [wm, window](const char* role, const char* area, Rect rect) {
- wm->set_event_handler(LibWindowmanager::Event_Invisible, [](char const *label) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got invisibled!\n", label);
- });
+ HMI_DEBUG(log_prefix,"Surface %s got syncDraw! Area: %s. w:%d, h:%d", role, area, rect.width(), rect.height());
- wm->set_event_handler(LibWindowmanager::Event_SyncDraw, [wm](char const *label) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got syncdraw!\n", label);
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] try to endDraw %s \n", app_name.c_str());
- wm->endDraw(app_name.c_str());
- });
+ wl_egl_window_resize(window->native, rect.width(), rect.height(), 0, 0);
+ window->geometry.width = rect.width();
+ window->geometry.height = rect.height();
- wm->set_event_handler(LibWindowmanager::Event_FlushDraw, [](char const *label) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got flushdraw! \n", label);
- });
+ wm->endDraw(role);
+ };
- do
- {
- surfaceIdStr = getenv("QT_IVI_SURFACE_ID");
- } while (surfaceIdStr == NULL);
-
- g_id_ivisurf = atoi(surfaceIdStr);
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] IVI_SURFACE_ID: %d \n", g_id_ivisurf);
+ wm->setEventHandler(wmh);
return 0;
}
init_hs(LibHomeScreen* hs){
if(hs->init(port, token)!=0)
{
- debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] homescreen init failed. \n");
+ HMI_ERROR(log_prefix,"homescreen init failed. ");
return -1;
}
- hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](const char* application_name){
- debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] Event_TapShortcut application_name = %s \n", application_name);
- if(strcmp(application_name, app_name.c_str()) == 0)
- {
- debug_out("************** [SIMPLE EGL] [HS SIMPLE] try to activesurface %s \n", app_name.c_str());
- wm->activateSurface(app_name.c_str());
- }
- });
-
- hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [](const char* display_message){
- debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] Event_OnScreenMessage display_message = %s \n", display_message);
+ hs->set_event_handler(LibHomeScreen::Event_ShowWindow, [hs](json_object *object){
+ HMI_DEBUG("simple-egl","try to activeWindow %s ", app_name.c_str());
+
+ struct json_object *param_obj = json_object_object_get(object, "parameter");
+ const char *area = json_object_get_string(
+ json_object_object_get(param_obj, "area"));
+ // Application should call LibWindowmanager::activateWindow() in showWindow handler
+ if(area == nullptr)
+ wm->activateWindow(main_role, "normal.full");
+ else
+ wm->activateWindow(main_role, area);
});
return 0;
main(int argc, char **argv)
{
struct sigaction sigint;
- struct window window = { 0 };
+ struct window window = { 0 };
struct display display = { 0 };
- if(getenv("ENABLE_DEMO_DEBUG"))
- {
- enable_debug = true;
- }
-
window.display = &display;
display.window = &window;
window.geometry.width = 1080;
window.buffer_size = 32;
window.frame_sync = 1;
- if(argc > 2)
- {
- if(string(argv[0]).find("hvac") != string::npos)
- app_name = string("HVAC");
+ if(argc > 2){
port = strtol(argv[1], NULL, 10);
token = argv[2];
}
- debug_out("************** [SIMPLE EGL] [MAIN] app_name: %s, port: %d, token: %s. \n", app_name.c_str(), port, token.c_str());
+ HMI_DEBUG(log_prefix,"main_role: %s, port: %d, token: %s. ", main_role, port, token.c_str());
display.display = wl_display_connect(NULL);
assert(display.display);
init_egl(&display, &window);
wm = new LibWindowmanager();
- hs = new LibHomeScreen();
-
- if(init_wm(wm)!=0){
+ if(init_wm(wm, &window)!=0){
fini_egl(&display);
if (display.ivi_application)
ivi_application_destroy(display.ivi_application);
return -1;
}
+ hs = new LibHomeScreen();
if(init_hs(hs)!=0){
fini_egl(&display);
if (display.ivi_application)
create_surface(&window);
init_gl(&window);
-
+
//Ctrl+C
sigint.sa_handler = signal_int;
sigemptyset(&sigint.sa_mask);
sigint.sa_flags = SA_RESETHAND;
sigaction(SIGINT, &sigint, NULL);
- eglSwapBuffers(display.egl.dpy, window.egl_surface);
- wm->activateSurface(app_name.c_str());
-
+ eglSwapBuffers(window.display->egl.dpy, window.egl_surface);
+
+ // wm->activateWindow(main_role);
+ hs->publishSubscription();
+
/* The mainloop here is a little subtle. Redrawing will cause
* EGL to read events so we can just call
* wl_display_dispatch_pending() to handle any events that got
redraw(&window, NULL, 0);
}
- debug_out("************** [SIMPLE EGL] [MAIN] simple-egl exiting! \n");
+ HMI_DEBUG(log_prefix,"simple-egl exiting! ");
destroy_surface(&window);
fini_egl(&display);