31 #include <sys/types.h> 40 #include <wayland-client.h> 41 #include <wayland-egl.h> 43 #include <GLES2/gl2.h> 45 #include <EGL/eglext.h> 50 #include <libwindowmanager.h> 53 #include <ilm/ivi-application-client-protocol.h> 54 #include "hmi-debug.h" 69 static const struct wl_interface *
types[] = {
73 &wl_surface_interface,
78 {
"destroy",
"",
types + 0 },
82 {
"configure",
"ii",
types + 0 },
92 {
"surface_create",
"uon",
types + 2 },
101 #include "platform.h" 103 #ifndef EGL_EXT_swap_buffers_with_damage 104 #define EGL_EXT_swap_buffers_with_damage 1 108 #ifndef EGL_EXT_buffer_age 109 #define EGL_EXT_buffer_age 1 110 #define EGL_BUFFER_AGE_EXT 0x313D 151 int fullscreen,
opaque, buffer_size, frame_sync;
155 "uniform mat4 rotation;\n" 156 "attribute vec4 pos;\n" 157 "attribute vec4 color;\n" 158 "varying vec4 v_color;\n" 160 " gl_Position = rotation * pos;\n" 161 " v_color = color;\n" 165 "precision mediump float;\n" 166 "varying vec4 v_color;\n" 168 " gl_FragColor = v_color;\n" 176 static const EGLint context_attribs[] = {
177 EGL_CONTEXT_CLIENT_VERSION, 2,
180 const char *extensions;
182 EGLint config_attribs[] = {
183 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
188 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
192 EGLint major, minor, n, count, i, size;
197 config_attribs[9] = 0;
199 display->
egl.
dpy = weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR, display->
display, NULL);
202 ret = eglInitialize(display->
egl.
dpy, &major, &minor);
203 assert(ret == EGL_TRUE);
204 ret = eglBindAPI(EGL_OPENGL_ES_API);
205 assert(ret == EGL_TRUE);
207 if (!eglGetConfigs(display->
egl.
dpy, NULL, 0, &count) || count < 1)
210 configs = calloc(count,
sizeof *configs);
213 ret = eglChooseConfig(display->
egl.
dpy, config_attribs,
215 assert(ret && n >= 1);
217 for (i = 0; i < n; i++) {
218 eglGetConfigAttrib(display->
egl.
dpy,
219 configs[i], EGL_BUFFER_SIZE, &size);
221 display->
egl.
conf = configs[i];
226 if (display->
egl.
conf == NULL) {
234 EGL_NO_CONTEXT, context_attribs);
238 extensions = eglQueryString(display->
egl.
dpy, EGL_EXTENSIONS);
240 strstr(extensions,
"EGL_EXT_swap_buffers_with_damage") &&
241 strstr(extensions,
"EGL_EXT_buffer_age"))
243 (PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)
244 eglGetProcAddress(
"eglSwapBuffersWithDamageEXT");
254 eglTerminate(display->
egl.
dpy);
264 shader = glCreateShader(shader_type);
267 glShaderSource(shader, 1, (
const char **) &source, NULL);
268 glCompileShader(shader);
270 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
274 glGetShaderInfoLog(shader, 1000, &len, log);
276 shader_type == GL_VERTEX_SHADER ?
"vertex" :
"fragment",
294 program = glCreateProgram();
295 glAttachShader(program, frag);
296 glAttachShader(program, vert);
297 glLinkProgram(program);
299 glGetProgramiv(program, GL_LINK_STATUS, &status);
303 glGetProgramInfoLog(program, 1000, &len, log);
308 glUseProgram(program);
313 glBindAttribLocation(program, window->
gl.
pos,
"pos");
314 glBindAttribLocation(program, window->
gl.
col,
"color");
315 glLinkProgram(program);
318 glGetUniformLocation(program,
"rotation");
345 wl_egl_window_create(window->
surface,
346 window->geometry.width,
347 window->geometry.height);
349 weston_platform_create_egl_surface(display->
egl.
dpy,
362 assert(ret == EGL_TRUE);
365 eglSwapInterval(display->
egl.
dpy, 0);
374 eglMakeCurrent(window->
display->
egl.
dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
378 wl_egl_window_destroy(window->
native);
382 wl_surface_destroy(window->
surface);
385 wl_callback_destroy(window->
callback);
389 redraw(
void *data,
struct wl_callback *callback, uint32_t time)
393 static const GLfloat verts[3][2] = {
399 static const GLfloat colors[3][3] = {
406 GLfloat rotation[4][4] = {
412 static const uint32_t speed_div = 5, benchmark_interval = 5;
413 struct wl_region *region;
415 EGLint buffer_age = 0;
418 assert(window->
callback == callback);
422 wl_callback_destroy(callback);
424 gettimeofday(&tv, NULL);
425 time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
429 if (time - window->
benchmark_time > (benchmark_interval * 1000)) {
433 (
float) window->
frames / benchmark_interval);
438 angle = (time / speed_div) % 360 * M_PI / 180.0;
439 rotation[0][0] = cos(angle);
440 rotation[0][2] = sin(angle);
441 rotation[2][0] = -sin(angle);
442 rotation[2][2] = cos(angle);
448 glViewport(0, 0, window->geometry.width, window->geometry.height);
451 (GLfloat *) rotation);
453 glClearColor(0.0, 0.0, 0.0, 0.5);
454 glClear(GL_COLOR_BUFFER_BIT);
456 glVertexAttribPointer(window->
gl.
pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
457 glVertexAttribPointer(window->
gl.
col, 3, GL_FLOAT, GL_FALSE, 0, colors);
458 glEnableVertexAttribArray(window->
gl.
pos);
459 glEnableVertexAttribArray(window->
gl.
col);
461 glDrawArrays(GL_TRIANGLES, 0, 3);
463 glDisableVertexAttribArray(window->
gl.
pos);
464 glDisableVertexAttribArray(window->
gl.
col);
468 wl_region_add(region, 0, 0,
469 window->geometry.width,
470 window->geometry.height);
471 wl_surface_set_opaque_region(window->
surface, region);
472 wl_region_destroy(region);
474 wl_surface_set_opaque_region(window->
surface, NULL);
478 rect[0] = window->geometry.width / 4 - 1;
479 rect[1] = window->geometry.height / 4 - 1;
480 rect[2] = window->geometry.width / 2 + 2;
481 rect[3] = window->geometry.height / 2 + 2;
494 uint32_t name,
const char *interface, uint32_t version)
498 if (strcmp(interface,
"wl_compositor") == 0) {
500 wl_registry_bind(registry, name,
501 &wl_compositor_interface, 1);
502 }
else if (strcmp(interface,
"ivi_application") == 0) {
504 wl_registry_bind(registry, name,
544 wmh.on_visible = [](
const char* role,
bool visible){
548 wmh.on_sync_draw = [
wm, window](
const char* role,
const char* area, Rect rect) {
550 HMI_DEBUG(
log_prefix,
"Surface %s got syncDraw! Area: %s. w:%d, h:%d", role, area, rect.width(), rect.height());
552 wl_egl_window_resize(window->
native, rect.width(), rect.height(), 0, 0);
553 window->geometry.width = rect.width();
554 window->geometry.height = rect.height();
559 wm->setEventHandler(wmh);
575 struct json_object *param_obj = json_object_object_get(
object, hs->
_keyParameter);
576 const char *area = json_object_get_string(
577 json_object_object_get(param_obj, hs->
_keyArea));
591 struct sigaction sigint;
592 struct window window = { 0 };
593 struct display display = { 0 };
597 window.geometry.width = 1080;
598 window.geometry.height = 1488;
604 port = strtol(argv[1], NULL, 10);
610 display.
display = wl_display_connect(NULL);
614 wl_registry_add_listener(display.
registry,
617 wl_display_roundtrip(display.
display);
621 wm =
new LibWindowmanager();
628 wl_registry_destroy(display.
registry);
629 wl_display_flush(display.
display);
640 wl_registry_destroy(display.
registry);
641 wl_display_flush(display.
display);
650 sigemptyset(&sigint.sa_mask);
651 sigint.sa_flags = SA_RESETHAND;
652 sigaction(SIGINT, &sigint, NULL);
663 wl_display_dispatch_pending(display.
display);
678 wl_registry_destroy(display.
registry);
679 wl_display_flush(display.
display);
680 wl_display_disconnect(display.
display);
static const struct wl_message ivi_surface_events[]
static void registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
static void init_gl(struct window *window)
int init_wm(LibWindowmanager *wm, struct window *window)
const struct wl_interface ivi_surface_interface
typedef EGLBoolean(EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)(EGLDisplay dpy
EGLSurface EGLint * rects
static const struct wl_interface * types[]
static const struct wl_message ivi_application_requests[]
const char * _keyParameter
static GLuint create_shader(struct window *window, const char *source, GLenum shader_type)
#define EGL_BUFFER_AGE_EXT
static void signal_int(int signum)
static const char * frag_shader_text
static void create_surface(struct window *window)
static void redraw(void *data, struct wl_callback *callback, uint32_t time)
struct wl_egl_window * native
EGLSurface EGLint EGLint n_rects
struct wl_surface * surface
static const char * vert_shader_text
struct ivi_application * ivi_application
struct wl_callback * callback
PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage
const struct wl_interface ivi_application_interface
struct wl_registry * registry
static const struct wl_registry_listener registry_listener
static void create_ivi_surface(struct window *window, struct display *display)
struct ivi_surface * ivi_surface
struct geometry geometry window_size
int init(const int port, const std::string &token)
struct wl_display * display
static void fini_egl(struct display *display)
#define HMI_ERROR(prefix, args,...)
static void init_egl(struct display *display, struct window *window)
#define HMI_DEBUG(prefix, args,...)
static void registry_handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
int main(int argc, char **argv)
struct wl_compositor * compositor
static void destroy_surface(struct window *window)
int init_hs(LibHomeScreen *hs)
static const struct wl_message ivi_surface_requests[]
void set_event_handler(enum EventType et, handler_func f)