summaryrefslogtreecommitdiffstats
path: root/sample/simple-egl
diff options
context:
space:
mode:
Diffstat (limited to 'sample/simple-egl')
-rw-r--r--sample/simple-egl/src/simple-egl.cpp90
1 files changed, 38 insertions, 52 deletions
diff --git a/sample/simple-egl/src/simple-egl.cpp b/sample/simple-egl/src/simple-egl.cpp
index be694d7..799729b 100644
--- a/sample/simple-egl/src/simple-egl.cpp
+++ b/sample/simple-egl/src/simple-egl.cpp
@@ -55,12 +55,13 @@
using namespace std;
-
+const char* log_prefix = "simple-egl";
uint32_t g_id_ivisurf = 9009;
long port = 1700;
string token = string("wm");
string app_name = string("Navigation");
+const char* main_role = "navigation";
LibHomeScreen* hs;
LibWindowmanager *wm;
@@ -194,7 +195,7 @@ 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);
@@ -223,7 +224,7 @@ init_egl(struct display *display, struct window *window)
}
free(configs);
if (display->egl.conf == NULL) {
- HMI_ERROR("simple-egl","did not find config with buffer size %d",
+ HMI_ERROR(log_prefix,"did not find config with buffer size %d",
window->buffer_size);
exit(EXIT_FAILURE);
}
@@ -243,7 +244,7 @@ init_egl(struct display *display, struct window *window)
eglGetProcAddress("eglSwapBuffersWithDamageEXT");
if (display->swap_buffers_with_damage)
- HMI_DEBUG("simple-egl","has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage");
+ HMI_DEBUG(log_prefix,"has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage");
}
@@ -271,7 +272,7 @@ create_shader(struct window *window, const char *source, GLenum shader_type)
char log[1000];
GLsizei len;
glGetShaderInfoLog(shader, 1000, &len, log);
- HMI_ERROR("simple-egl","Error: compiling %s: %*s",
+ HMI_ERROR(log_prefix,"Error: compiling %s: %*s",
shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
len, log);
exit(1);
@@ -300,7 +301,7 @@ init_gl(struct window *window)
char log[1000];
GLsizei len;
glGetProgramInfoLog(program, 1000, &len, log);
- HMI_ERROR("simple-egl","Error: linking:%*s", len, log);
+ HMI_ERROR(log_prefix,"Error: linking:%*s", len, log);
exit(1);
}
@@ -326,7 +327,7 @@ create_ivi_surface(struct window *window, struct display *display)
id_ivisurf, window->surface);
if (window->ivi_surface == NULL) {
- HMI_ERROR("simple-egl","Failed to create ivi_client_surface");
+ HMI_ERROR(log_prefix,"Failed to create ivi_client_surface");
abort();
}
@@ -426,7 +427,7 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
window->benchmark_time = time;
if (time - window->benchmark_time > (benchmark_interval * 1000)) {
- HMI_DEBUG("simple-egl","%d frames in %d seconds: %f fps",
+ HMI_DEBUG(log_prefix,"%d frames in %d seconds: %f fps",
window->frames,
benchmark_interval,
(float) window->frames / benchmark_interval);
@@ -484,7 +485,7 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
} else {
eglSwapBuffers(display->egl.dpy, window->egl_surface);
}
-
+
window->frames++;
}
@@ -525,47 +526,37 @@ signal_int(int signum)
int
init_wm(LibWindowmanager *wm, struct window *window)
{
- HMI_DEBUG("simple-egl","called");
+ HMI_DEBUG(log_prefix,"called");
- if (wm->init(port, token.c_str()) != 0) {
- HMI_ERROR("simple-egl","wm init failed. ");
+ if (wm->init(port, token) != 0) {
+ HMI_ERROR(log_prefix,"wm init failed. ");
return -1;
}
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
- g_id_ivisurf = wm->requestSurface(obj);
+ g_id_ivisurf = wm->requestSurface(main_role);
if (g_id_ivisurf < 0) {
- HMI_ERROR("simple-egl","wm request surface failed ");
+ HMI_ERROR(log_prefix,"wm request surface failed ");
return -1;
}
- HMI_DEBUG("simple-egl","IVI_SURFACE_ID: %d ", g_id_ivisurf);
- wm->set_event_handler(LibWindowmanager::Event_SyncDraw, [wm, window](json_object *object) {
- const char *label = json_object_get_string(
- json_object_object_get(object, wm->kKeyDrawingName));
- const char *area = json_object_get_string(
- json_object_object_get(object, wm->kKeyDrawingArea));
-
- HMI_DEBUG("simple-egl","Surface %s got syncDraw! Area: %s. ", label, area);
- if ((wm->kStrLayoutNormal + "." + wm->kStrAreaFull) == std::string(area)) {
- wl_egl_window_resize(window->native, 1080, 1488, 0, 0);
- window->geometry.width = 1080;
- window->geometry.height = 1488;
- }
- else if ((wm->kStrLayoutSplit + "." + wm->kStrAreaMain) == std::string(area) ||
- (wm->kStrLayoutSplit + "." + wm->kStrAreaSub) == std::string(area)) {
- wl_egl_window_resize(window->native, 1080, 744, 0, 0);
- window->geometry.width = 1080;
- window->geometry.height = 744;
- }
+ HMI_DEBUG(log_prefix,"IVI_SURFACE_ID: %d ", g_id_ivisurf);
- if (!window->fullscreen)
- window->window_size = window->geometry;
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
+ 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->endDraw(obj);
- });
+ HMI_DEBUG(log_prefix,"Surface %s got syncDraw! Area: %s. w:%d, h:%d", role, area, rect.width(), rect.height());
+
+ wl_egl_window_resize(window->native, rect.width(), rect.height(), 0, 0);
+ window->geometry.width = rect.width();
+ window->geometry.height = rect.height();
+
+ wm->endDraw(role);
+ };
+
+ wm->setEventHandler(wmh);
return 0;
}
@@ -574,7 +565,7 @@ int
init_hs(LibHomeScreen* hs){
if(hs->init(port, token)!=0)
{
- HMI_ERROR("simple-egl","homescreen init failed. ");
+ HMI_ERROR(log_prefix,"homescreen init failed. ");
return -1;
}
@@ -585,10 +576,7 @@ init_hs(LibHomeScreen* hs){
if(strcmp(application_name, app_name.c_str()) == 0)
{
HMI_DEBUG("simple-egl","try to activesurface %s ", app_name.c_str());
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
- json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
- wm->activateSurface(obj);
+ wm->activateWindow(main_role);
}
});
@@ -615,7 +603,7 @@ main(int argc, char **argv)
token = argv[2];
}
- HMI_DEBUG("simple-egl","app_name: %s, port: %d, token: %s. ", 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);
@@ -662,10 +650,8 @@ main(int argc, char **argv)
sigaction(SIGINT, &sigint, NULL);
eglSwapBuffers(window.display->egl.dpy, window.egl_surface);
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
- json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
- wm->activateSurface(obj);
+
+ wm->activateWindow(main_role);
/* The mainloop here is a little subtle. Redrawing will cause
* EGL to read events so we can just call
@@ -676,7 +662,7 @@ main(int argc, char **argv)
redraw(&window, NULL, 0);
}
- HMI_DEBUG("simple-egl","simple-egl exiting! ");
+ HMI_DEBUG(log_prefix,"simple-egl exiting! ");
destroy_surface(&window);
fini_egl(&display);