1 /**************************************************************************
3 * Copyright (C) 2013 DENSO CORPORATION
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ****************************************************************************/
30 #include <sys/eventfd.h>
32 #include "ilm_common.h"
33 #include "ilm_control_platform.h"
34 #include "wayland-util.h"
35 #include "ivi-controller-client-protocol.h"
38 #if defined(__GNUC__) && __GNUC__ >= 4
39 #define ILM_EXPORT __attribute__ ((visibility("default")))
44 struct surface_context {
47 struct ivi_surface *surface;
48 struct ivi_controller_surface *controller;
50 t_ilm_uint id_surface;
51 struct ilmSurfaceProperties prop;
52 surfaceNotificationFunc notification;
58 struct wayland_context *ctx;
59 bool is_surface_creation_noticed;
62 struct layer_context {
65 struct ivi_controller_layer *controller;
68 struct ilmLayerProperties prop;
69 layerNotificationFunc notification;
72 struct wl_list list_surface;
76 struct wayland_context *ctx;
79 struct screen_context {
82 struct wl_output *output;
83 struct ivi_controller_screen *controller;
84 t_ilm_uint id_from_server;
87 struct ilmScreenProperties prop;
90 struct wl_list list_layer;
93 struct ilm_control_context *ctx;
96 struct nativehandle_context {
98 uint32_t nativehandle;
102 struct wayland_context {
103 struct wl_display *display;
104 struct wl_registry *registry;
105 struct wl_event_queue *queue;
106 struct wl_compositor *compositor;
107 struct ivi_controller *controller;
110 struct wl_list list_surface;
111 struct wl_list list_layer;
112 struct wl_list list_screen;
115 struct ilm_control_context {
116 struct wayland_context wl;
119 uint32_t internal_id_layer;
121 struct wl_list list_nativehandle;
124 pthread_mutex_t mutex;
126 uint32_t internal_id_surface;
129 static void roundtrip_done(void *data, struct wl_callback *callback,
136 wl_callback_destroy(callback);
139 static struct wl_callback_listener roundtrip_listener = {roundtrip_done};
141 int display_roundtrip_queue(struct wl_display *display,
142 struct wl_event_queue *queue)
146 struct wl_callback *callback = wl_display_sync(display);
153 wl_proxy_set_queue((void *)callback, queue);
154 wl_callback_add_listener(callback, &roundtrip_listener, &done);
156 while (ret != -1 && !done)
158 ret = wl_display_dispatch_queue(display, queue);
161 if (ret == -1 && !done)
163 wl_callback_destroy(callback);
169 static inline void lock_context(struct ilm_control_context *ctx)
171 pthread_mutex_lock(&ctx->mutex);
174 static inline void unlock_context(struct ilm_control_context *ctx)
176 pthread_mutex_unlock(&ctx->mutex);
179 static int init_control(void);
181 static ilmErrorTypes impl_sync_and_acquire_instance(struct ilm_control_context *ctx);
183 static struct surface_context* get_surface_context(struct wayland_context *, uint32_t);
185 static void release_instance(void);
187 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid);
190 wayland_controller_is_inside_surface_list(struct wl_list *list,
193 struct surface_context *ctx_surf = NULL;
194 wl_list_for_each(ctx_surf, list, link) {
195 if (ctx_surf->id_surface == id_surface) {
204 wayland_controller_is_inside_layer_list(struct wl_list *list,
207 struct layer_context *ctx_layer = NULL;
208 wl_list_for_each(ctx_layer, list, link) {
209 if (ctx_layer->id_layer == id_layer) {
217 static struct layer_context*
218 wayland_controller_get_layer_context(struct wayland_context *ctx,
221 struct layer_context *ctx_layer = NULL;
223 if (ctx->controller == NULL) {
224 fprintf(stderr, "controller is not initialized in ilmControl\n");
228 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
229 if (ctx_layer->id_layer == id_layer) {
234 fprintf(stderr, "failed to get layer context in ilmControl\n");
239 output_listener_geometry(void *data,
240 struct wl_output *output,
243 int32_t physical_width,
244 int32_t physical_height,
260 output_listener_mode(void *data,
261 struct wl_output *output,
274 if (flags & WL_OUTPUT_MODE_CURRENT)
276 struct screen_context *ctx_scrn = data;
277 ctx_scrn->prop.screenWidth = width;
278 ctx_scrn->prop.screenHeight = height;
283 output_listener_done(void *data,
284 struct wl_output *output)
291 output_listener_scale(void *data,
292 struct wl_output *output,
300 static struct wl_output_listener output_listener = {
301 output_listener_geometry,
302 output_listener_mode,
303 output_listener_done,
304 output_listener_scale
307 static struct screen_context*
308 get_screen_context_by_serverid(struct wayland_context *ctx,
311 struct screen_context *ctx_scrn = NULL;
313 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
314 if (ctx_scrn->id_from_server == id_screen) {
322 add_orderlayer_to_screen(struct layer_context *ctx_layer,
323 struct wl_output* output)
325 struct screen_context *ctx_scrn = wl_output_get_user_data(output);
328 struct layer_context *layer_link;
329 wl_list_for_each(layer_link, &ctx_scrn->order.list_layer, order.link) {
330 if (layer_link == ctx_layer) {
337 wl_list_init(&ctx_layer->order.link);
338 wl_list_insert(&ctx_scrn->order.list_layer, &ctx_layer->order.link);
343 remove_orderlayer_from_screen(struct layer_context *ctx_layer)
345 wl_list_remove(&ctx_layer->order.link);
346 wl_list_init(&ctx_layer->order.link);
350 controller_layer_listener_visibility(void *data,
351 struct ivi_controller_layer *controller,
354 struct layer_context *ctx_layer = data;
356 ctx_layer->prop.visibility = (t_ilm_bool)visibility;
358 if (ctx_layer->notification != NULL) {
359 ctx_layer->notification(ctx_layer->id_layer,
361 ILM_NOTIFICATION_VISIBILITY);
366 controller_layer_listener_opacity(void *data,
367 struct ivi_controller_layer *controller,
370 struct layer_context *ctx_layer = data;
372 ctx_layer->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
374 if (ctx_layer->notification != NULL) {
375 ctx_layer->notification(ctx_layer->id_layer,
377 ILM_NOTIFICATION_OPACITY);
382 controller_layer_listener_source_rectangle(void *data,
383 struct ivi_controller_layer *controller,
389 struct layer_context *ctx_layer = data;
391 ctx_layer->prop.sourceX = (t_ilm_uint)x;
392 ctx_layer->prop.sourceY = (t_ilm_uint)y;
393 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
394 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
395 if (ctx_layer->prop.origSourceWidth == 0) {
396 ctx_layer->prop.origSourceWidth = (t_ilm_uint)width;
398 if (ctx_layer->prop.origSourceHeight == 0) {
399 ctx_layer->prop.origSourceHeight = (t_ilm_uint)height;
402 if (ctx_layer->notification != NULL) {
403 ctx_layer->notification(ctx_layer->id_layer,
405 ILM_NOTIFICATION_SOURCE_RECT);
410 controller_layer_listener_destination_rectangle(void *data,
411 struct ivi_controller_layer *controller,
417 struct layer_context *ctx_layer = data;
419 ctx_layer->prop.destX = (t_ilm_uint)x;
420 ctx_layer->prop.destY = (t_ilm_uint)y;
421 ctx_layer->prop.destWidth = (t_ilm_uint)width;
422 ctx_layer->prop.destHeight = (t_ilm_uint)height;
424 if (ctx_layer->notification != NULL) {
425 ctx_layer->notification(ctx_layer->id_layer,
427 ILM_NOTIFICATION_DEST_RECT);
432 controller_layer_listener_configuration(void *data,
433 struct ivi_controller_layer *controller,
437 struct layer_context *ctx_layer = data;
439 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
440 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
444 controller_layer_listener_orientation(void *data,
445 struct ivi_controller_layer *controller,
448 ilmOrientation ilmorientation = ILM_ZERO;
449 struct layer_context *ctx_layer = data;
451 switch(orientation) {
452 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
453 ilmorientation = ILM_ZERO;
455 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
456 ilmorientation = ILM_NINETY;
458 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
459 ilmorientation = ILM_ONEHUNDREDEIGHTY;
461 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
462 ilmorientation = ILM_TWOHUNDREDSEVENTY;
468 ctx_layer->prop.orientation = ilmorientation;
470 if (ctx_layer->notification != NULL) {
471 ctx_layer->notification(ctx_layer->id_layer,
473 ILM_NOTIFICATION_ORIENTATION);
478 controller_layer_listener_screen(void *data,
479 struct ivi_controller_layer *controller,
480 struct wl_output *output)
482 struct layer_context *ctx_layer = data;
484 if (output == NULL) {
485 remove_orderlayer_from_screen(ctx_layer);
487 add_orderlayer_to_screen(ctx_layer, output);
492 controller_layer_listener_destroyed(void *data,
493 struct ivi_controller_layer *controller)
495 struct layer_context *ctx_layer = data;
496 wl_list_remove(&ctx_layer->link);
500 static struct ivi_controller_layer_listener controller_layer_listener =
502 controller_layer_listener_visibility,
503 controller_layer_listener_opacity,
504 controller_layer_listener_source_rectangle,
505 controller_layer_listener_destination_rectangle,
506 controller_layer_listener_configuration,
507 controller_layer_listener_orientation,
508 controller_layer_listener_screen,
509 controller_layer_listener_destroyed
513 add_ordersurface_to_layer(struct surface_context *ctx_surf,
514 struct ivi_controller_layer *layer)
516 struct layer_context *ctx_layer = NULL;
517 struct surface_context *link = NULL;
520 ctx_layer = ivi_controller_layer_get_user_data(layer);
522 wl_list_for_each(link, &ctx_layer->order.list_surface, order.link) {
523 if (link == ctx_surf) {
530 wl_list_init(&ctx_surf->order.link);
531 wl_list_insert(&ctx_layer->order.list_surface, &ctx_surf->order.link);
536 remove_ordersurface_from_layer(struct surface_context *ctx_surf)
538 wl_list_remove(&ctx_surf->order.link);
539 wl_list_init(&ctx_surf->order.link);
543 controller_surface_listener_visibility(void *data,
544 struct ivi_controller_surface *controller,
547 struct surface_context *ctx_surf = data;
549 ctx_surf->prop.visibility = (t_ilm_bool)visibility;
551 if (ctx_surf->notification != NULL) {
552 ctx_surf->notification(ctx_surf->id_surface,
554 ILM_NOTIFICATION_VISIBILITY);
559 controller_surface_listener_opacity(void *data,
560 struct ivi_controller_surface *controller,
563 struct surface_context *ctx_surf = data;
565 ctx_surf->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
567 if (ctx_surf->notification != NULL) {
568 ctx_surf->notification(ctx_surf->id_surface,
570 ILM_NOTIFICATION_OPACITY);
575 controller_surface_listener_configuration(void *data,
576 struct ivi_controller_surface *controller,
580 struct surface_context *ctx_surf = data;
582 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
583 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
587 controller_surface_listener_source_rectangle(void *data,
588 struct ivi_controller_surface *controller,
594 struct surface_context *ctx_surf = data;
596 ctx_surf->prop.sourceX = (t_ilm_uint)x;
597 ctx_surf->prop.sourceY = (t_ilm_uint)y;
598 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
599 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
600 if (ctx_surf->prop.origSourceWidth == 0) {
601 ctx_surf->prop.origSourceWidth = (t_ilm_uint)width;
603 if (ctx_surf->prop.origSourceHeight == 0) {
604 ctx_surf->prop.origSourceHeight = (t_ilm_uint)height;
607 if (ctx_surf->notification != NULL) {
608 ctx_surf->notification(ctx_surf->id_surface,
610 ILM_NOTIFICATION_SOURCE_RECT);
615 controller_surface_listener_destination_rectangle(void *data,
616 struct ivi_controller_surface *controller,
622 struct surface_context *ctx_surf = data;
624 ctx_surf->prop.destX = (t_ilm_uint)x;
625 ctx_surf->prop.destY = (t_ilm_uint)y;
626 ctx_surf->prop.destWidth = (t_ilm_uint)width;
627 ctx_surf->prop.destHeight = (t_ilm_uint)height;
629 if (ctx_surf->notification != NULL) {
630 ctx_surf->notification(ctx_surf->id_surface,
632 ILM_NOTIFICATION_DEST_RECT);
637 controller_surface_listener_orientation(void *data,
638 struct ivi_controller_surface *controller,
641 struct surface_context *ctx_surf = data;
642 ilmOrientation ilmorientation = ILM_ZERO;
644 switch (orientation) {
645 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
646 ilmorientation = ILM_ZERO;
648 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
649 ilmorientation = ILM_NINETY;
651 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
652 ilmorientation = ILM_ONEHUNDREDEIGHTY;
654 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
655 ilmorientation = ILM_TWOHUNDREDSEVENTY;
661 ctx_surf->prop.orientation = ilmorientation;
663 if (ctx_surf->notification != NULL) {
664 ctx_surf->notification(ctx_surf->id_surface,
666 ILM_NOTIFICATION_ORIENTATION);
671 controller_surface_listener_pixelformat(void *data,
672 struct ivi_controller_surface *controller,
675 struct surface_context *ctx_surf = data;
677 ctx_surf->prop.pixelformat = (t_ilm_uint)pixelformat;
681 controller_surface_listener_layer(void *data,
682 struct ivi_controller_surface *controller,
683 struct ivi_controller_layer *layer)
685 struct surface_context *ctx_surf = data;
688 remove_ordersurface_from_layer(ctx_surf);
690 add_ordersurface_to_layer(ctx_surf, layer);
695 controller_surface_listener_stats(void *data,
696 struct ivi_controller_surface *controller,
697 uint32_t redraw_count,
698 uint32_t frame_count,
699 uint32_t update_count,
701 const char *process_name)
703 struct surface_context *ctx_surf = data;
706 ctx_surf->prop.drawCounter = (t_ilm_uint)redraw_count;
707 ctx_surf->prop.frameCounter = (t_ilm_uint)frame_count;
708 ctx_surf->prop.updateCounter = (t_ilm_uint)update_count;
709 ctx_surf->prop.creatorPid = (t_ilm_uint)pid;
713 controller_surface_listener_destroyed(void *data,
714 struct ivi_controller_surface *controller)
716 struct surface_context *ctx_surf = data;
718 if (ctx_surf->notification != NULL) {
719 ctx_surf->notification(ctx_surf->id_surface,
721 ILM_NOTIFICATION_CONTENT_REMOVED);
724 wl_list_remove(&ctx_surf->link);
729 controller_surface_listener_content(void *data,
730 struct ivi_controller_surface *controller,
731 int32_t content_state)
733 struct surface_context *ctx_surf = data;
735 // if client surface (=content) was removed with ilm_surfaceDestroy()
736 // the expected behavior within ILM API mandates a full removal
737 // of the surface from the scene. We must remove the controller
739 if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED == content_state)
741 if (ctx_surf->notification != NULL) {
742 ctx_surf->notification(ctx_surf->id_surface,
744 ILM_NOTIFICATION_CONTENT_REMOVED);
747 ivi_controller_surface_destroy(controller, 1);
749 wl_list_remove(&ctx_surf->link);
752 else if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_AVAILABLE == content_state)
754 if (ctx_surf->notification != NULL) {
755 ctx_surf->notification(ctx_surf->id_surface,
757 ILM_NOTIFICATION_CONTENT_AVAILABLE);
763 controller_surface_listener_input_focus(void *data,
764 struct ivi_controller_surface *controller,
774 static struct ivi_controller_surface_listener controller_surface_listener=
776 controller_surface_listener_visibility,
777 controller_surface_listener_opacity,
778 controller_surface_listener_source_rectangle,
779 controller_surface_listener_destination_rectangle,
780 controller_surface_listener_configuration,
781 controller_surface_listener_orientation,
782 controller_surface_listener_pixelformat,
783 controller_surface_listener_layer,
784 controller_surface_listener_stats,
785 controller_surface_listener_destroyed,
786 controller_surface_listener_content,
787 controller_surface_listener_input_focus
791 controller_listener_layer(void *data,
792 struct ivi_controller *controller,
795 struct wayland_context *ctx = data;
797 if (wayland_controller_is_inside_layer_list(&ctx->list_layer, id_layer))
802 (void) create_controller_layer(ctx, 0, 0, id_layer);
806 controller_listener_surface(void *data,
807 struct ivi_controller *controller,
810 struct wayland_context *ctx = data;
811 struct surface_context *ctx_surf = NULL;
813 ctx_surf = get_surface_context(ctx, id_surface);
814 if (ctx_surf != NULL) {
815 if (!ctx_surf->is_surface_creation_noticed) {
816 if (ctx_surf->notification != NULL) {
817 ctx_surf->notification(ctx_surf->id_surface,
819 ILM_NOTIFICATION_CONTENT_AVAILABLE);
820 ctx_surf->is_surface_creation_noticed = true;
822 ctx_surf->controller = ivi_controller_surface_create(
823 controller, id_surface);
826 fprintf(stderr, "invalid id_surface in controller_listener_surface\n");
831 ctx_surf = calloc(1, sizeof *ctx_surf);
832 if (ctx_surf == NULL) {
833 fprintf(stderr, "Failed to allocate memory for surface_context\n");
837 ctx_surf->controller = ivi_controller_surface_create(
838 controller, id_surface);
839 if (ctx_surf->controller == NULL) {
841 fprintf(stderr, "Failed to create controller surface\n");
844 ctx_surf->id_surface = id_surface;
845 ctx_surf->prop.inputDevicesAcceptance = ILM_INPUT_DEVICE_ALL;
847 ctx_surf->is_surface_creation_noticed = true;
849 wl_list_init(&ctx_surf->link);
850 wl_list_insert(&ctx->list_surface, &ctx_surf->link);
851 wl_list_init(&ctx_surf->order.link);
852 ivi_controller_surface_add_listener(ctx_surf->controller,
853 &controller_surface_listener, ctx_surf);
857 controller_listener_error(void *data,
858 struct ivi_controller *ivi_controller,
862 const char *error_text)
865 (void)ivi_controller;
873 controller_listener_screen(void *data,
874 struct ivi_controller *ivi_controller,
876 struct ivi_controller_screen *controller_screen)
878 struct wayland_context *ctx = data;
879 struct screen_context *ctx_screen;
880 (void)ivi_controller;
882 ctx_screen = get_screen_context_by_serverid(ctx, id_screen);
883 if (ctx_screen == NULL) {
884 fprintf(stderr, "Failed to allocate memory for screen_context\n");
887 ctx_screen->controller = controller_screen;
890 static struct ivi_controller_listener controller_listener= {
891 controller_listener_screen,
892 controller_listener_layer,
893 controller_listener_surface,
894 controller_listener_error
898 registry_handle_control(void *data,
899 struct wl_registry *registry,
900 uint32_t name, const char *interface,
903 struct wayland_context *ctx = data;
906 if (strcmp(interface, "ivi_controller") == 0) {
907 ctx->controller = wl_registry_bind(registry, name,
908 &ivi_controller_interface, 1);
909 if (ctx->controller == NULL) {
910 fprintf(stderr, "Failed to registry bind ivi_controller\n");
913 if (ivi_controller_add_listener(ctx->controller,
914 &controller_listener,
916 fprintf(stderr, "Failed to add ivi_controller listener\n");
919 } else if (strcmp(interface, "wl_output") == 0) {
920 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
921 struct wl_proxy *pxy = NULL;
923 if (ctx_scrn == NULL) {
924 fprintf(stderr, "Failed to allocate memory for screen_context\n");
927 wl_list_init(&ctx_scrn->link);
928 ctx_scrn->output = wl_registry_bind(registry, name,
929 &wl_output_interface, 1);
930 if (ctx_scrn->output == NULL) {
932 fprintf(stderr, "Failed to registry bind wl_output\n");
936 if (wl_output_add_listener(ctx_scrn->output,
940 fprintf(stderr, "Failed to add wl_output listener\n");
944 pxy = (struct wl_proxy*)ctx_scrn->output;
945 ctx_scrn->id_from_server = wl_proxy_get_id(pxy);
946 ctx_scrn->id_screen = ctx->num_screen;
948 wl_list_init(&ctx_scrn->order.list_layer);
949 wl_list_insert(&ctx->list_screen, &ctx_scrn->link);
953 static const struct wl_registry_listener
954 registry_control_listener= {
955 registry_handle_control,
959 static struct ilm_control_context ilm_context;
961 static void destroy_control_resources(void)
963 struct ilm_control_context *ctx = &ilm_context;
965 // free resources of output objects
966 if (! ctx->wl.controller) {
967 struct screen_context *ctx_scrn;
968 struct screen_context *next;
970 wl_list_for_each_safe(ctx_scrn, next, &ctx->wl.list_screen, link) {
971 if (ctx_scrn->output != NULL) {
972 wl_output_destroy(ctx_scrn->output);
975 wl_list_remove(&ctx_scrn->link);
980 if (ctx->wl.controller != NULL) {
982 struct surface_context *l;
983 struct surface_context *n;
984 wl_list_for_each_safe(l, n, &ctx->wl.list_surface, link) {
985 wl_list_remove(&l->link);
986 wl_list_remove(&l->order.link);
987 ivi_controller_surface_destroy(l->controller, 0);
993 struct layer_context *l;
994 struct layer_context *n;
995 wl_list_for_each_safe(l, n, &ctx->wl.list_layer, link) {
996 wl_list_remove(&l->link);
997 wl_list_remove(&l->order.link);
1003 struct screen_context *ctx_scrn;
1004 struct screen_context *next;
1006 wl_list_for_each_safe(ctx_scrn, next, &ctx->wl.list_screen, link) {
1007 if (ctx_scrn->output != NULL) {
1008 wl_output_destroy(ctx_scrn->output);
1011 wl_list_remove(&ctx_scrn->link);
1012 ivi_controller_screen_destroy(ctx_scrn->controller);
1017 ivi_controller_destroy(ctx->wl.controller);
1018 ctx->wl.controller = NULL;
1021 if (ctx->wl.display) {
1022 wl_display_flush(ctx->wl.display);
1025 if (ctx->wl.registry) {
1026 wl_registry_destroy(ctx->wl.registry);
1027 ctx->wl.registry = NULL;
1030 if (ctx->wl.queue) {
1031 wl_event_queue_destroy(ctx->wl.queue);
1032 ctx->wl.queue = NULL;
1035 if (0 != pthread_mutex_destroy(&ctx->mutex)) {
1036 fprintf(stderr, "failed to destroy pthread_mutex\n");
1040 static void send_shutdown_event(struct ilm_control_context *ctx)
1043 while (write(ctx->shutdown_fd, &buf, sizeof buf) == -1 && errno == EINTR)
1048 ilmControl_destroy(void)
1050 struct ilm_control_context *ctx = &ilm_context;
1052 send_shutdown_event(ctx);
1054 if (0 != pthread_join(ctx->thread, NULL)) {
1055 fprintf(stderr, "failed to join control thread\n");
1058 destroy_control_resources();
1060 close(ctx->shutdown_fd);
1062 memset(ctx, 0, sizeof *ctx);
1065 ILM_EXPORT ilmErrorTypes
1066 ilmControl_init(t_ilm_nativedisplay nativedisplay)
1068 struct ilm_control_context *ctx = &ilm_context;
1070 if (ctx->initialized)
1072 fprintf(stderr, "Already initialized!\n");
1076 if (nativedisplay == 0) {
1077 return ILM_ERROR_INVALID_ARGUMENTS;
1080 ctx->shutdown_fd = -1;
1082 ctx->wl.display = (struct wl_display*)nativedisplay;
1084 wl_list_init(&ctx->wl.list_screen);
1085 wl_list_init(&ctx->wl.list_layer);
1086 wl_list_init(&ctx->wl.list_surface);
1089 pthread_mutexattr_t a;
1090 if (pthread_mutexattr_init(&a) != 0)
1095 if (pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE) != 0)
1097 pthread_mutexattr_destroy(&a);
1101 if (pthread_mutex_init(&ctx->mutex, &a) != 0)
1103 pthread_mutexattr_destroy(&a);
1104 fprintf(stderr, "failed to initialize pthread_mutex\n");
1108 pthread_mutexattr_destroy(&a);
1111 return init_control() == 0 ? ILM_SUCCESS : ILM_FAILED;
1115 control_thread(void *p_ret)
1117 struct ilm_control_context *const ctx = &ilm_context;
1118 struct wayland_context *const wl = &ctx->wl;
1119 struct wl_display *const display = wl->display;
1120 struct wl_event_queue *const queue = wl->queue;
1121 int const fd = wl_display_get_fd(display);
1122 int const shutdown_fd = ctx->shutdown_fd;
1127 while (wl_display_prepare_read_queue(display, queue) != 0)
1130 wl_display_dispatch_queue_pending(display, queue);
1131 unlock_context(ctx);
1134 if (wl_display_flush(display) == -1)
1139 struct pollfd pfd[2] = {
1140 { .fd = fd, .events = POLLIN },
1141 { .fd = shutdown_fd, .events = POLLIN }
1144 int pollret = poll(pfd, 2, -1);
1145 if (pollret != -1 && (pfd[0].revents & POLLIN))
1147 wl_display_read_events(display);
1150 int ret = wl_display_dispatch_queue_pending(display, queue);
1151 unlock_context(ctx);
1160 wl_display_cancel_read(display);
1162 if (pollret == -1 || (pfd[1].revents & POLLIN))
1175 struct ilm_control_context *ctx = &ilm_context;
1176 struct wayland_context *wl = &ctx->wl;
1180 wl_list_init(&ctx->list_nativehandle);
1182 wl->queue = wl_display_create_queue(wl->display);
1184 fprintf(stderr, "Could not create wayland event queue\n");
1188 /* registry_add_listener for request by ivi-controller */
1189 wl->registry = wl_display_get_registry(wl->display);
1190 if (wl->registry == NULL) {
1191 wl_event_queue_destroy(wl->queue);
1193 fprintf(stderr, "Failed to get registry\n");
1196 wl_proxy_set_queue((void*)wl->registry, wl->queue);
1198 if (wl_registry_add_listener(wl->registry,
1199 ®istry_control_listener, ctx)) {
1200 fprintf(stderr, "Failed to add registry listener\n");
1204 // first level objects; ivi_controller
1205 display_roundtrip_queue(wl->display, wl->queue);
1206 // second level object: ivi_controller_surfaces/layers
1207 display_roundtrip_queue(wl->display, wl->queue);
1208 // third level objects: ivi_controller_surfaces/layers properties
1209 display_roundtrip_queue(wl->display, wl->queue);
1211 if (! wl->controller)
1213 fprintf(stderr, "ivi_controller not available\n");
1217 ctx->shutdown_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
1219 if (ctx->shutdown_fd == -1)
1221 fprintf(stderr, "Could not setup shutdown-fd: %s\n", strerror(errno));
1225 ret = pthread_create(&ctx->thread, NULL, control_thread, NULL);
1228 fprintf(stderr, "Failed to start internal receive thread. returned %d\n", ret);
1232 ctx->initialized = true;
1237 static ilmErrorTypes impl_sync_and_acquire_instance(struct ilm_control_context *ctx)
1239 if (! ctx->initialized) {
1240 fprintf(stderr, "Not initialized\n");
1246 if (display_roundtrip_queue(ctx->wl.display, ctx->wl.queue) == -1) {
1247 int err = wl_display_get_error(ctx->wl.display);
1248 fprintf(stderr, "Error communicating with wayland: %s\n", strerror(err));
1249 unlock_context(ctx);
1256 #define sync_and_acquire_instance() ({ \
1257 struct ilm_control_context *ctx = &ilm_context; \
1259 ilmErrorTypes status = impl_sync_and_acquire_instance(ctx); \
1260 if (status != ILM_SUCCESS) { \
1267 static void release_instance(void)
1269 struct ilm_control_context *ctx = &ilm_context;
1270 unlock_context(ctx);
1274 gen_layer_id(struct ilm_control_context *ctx)
1276 struct layer_context *ctx_layer = NULL;
1279 if (wl_list_length(&ctx->wl.list_layer) == 0) {
1280 ctx->internal_id_layer++;
1281 return ctx->internal_id_layer;
1283 wl_list_for_each(ctx_layer, &ctx->wl.list_layer, link) {
1284 if (ctx_layer->id_layer == ctx->internal_id_layer) {
1290 return ctx->internal_id_layer;
1293 ctx->internal_id_layer++;
1297 static struct surface_context*
1298 get_surface_context(struct wayland_context *ctx,
1299 uint32_t id_surface)
1301 struct surface_context *ctx_surf = NULL;
1303 if (ctx->controller == NULL) {
1304 fprintf(stderr, "controller is not initialized in ilmControl\n");
1308 wl_list_for_each(ctx_surf, &ctx->list_surface, link) {
1309 if (ctx_surf->id_surface == id_surface) {
1314 fprintf(stderr, "failed to get surface context in ilmControl\n");
1318 static struct screen_context*
1319 get_screen_context_by_id(struct wayland_context *ctx, uint32_t id_screen)
1321 struct screen_context *ctx_scrn = NULL;
1323 if (ctx->controller == NULL) {
1324 fprintf(stderr, "get_screen_context_by_id: controller is NULL\n");
1328 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
1329 if (ctx_scrn->id_screen == id_screen) {
1336 ILM_EXPORT ilmErrorTypes
1337 ilm_getPropertiesOfLayer(t_ilm_uint layerID,
1338 struct ilmLayerProperties* pLayerProperties)
1340 ilmErrorTypes returnValue = ILM_FAILED;
1341 struct ilm_control_context *ctx = sync_and_acquire_instance();
1342 struct layer_context *ctx_layer = NULL;
1344 if (pLayerProperties != NULL) {
1346 ctx_layer = (struct layer_context*)
1347 wayland_controller_get_layer_context(
1348 &ctx->wl, (uint32_t)layerID);
1350 if (ctx_layer != NULL) {
1351 *pLayerProperties = ctx_layer->prop;
1352 returnValue = ILM_SUCCESS;
1361 create_layerids(struct screen_context *ctx_screen,
1362 t_ilm_layer **layer_ids, t_ilm_uint *layer_count)
1364 struct layer_context *ctx_layer = NULL;
1365 t_ilm_layer *ids = NULL;
1367 *layer_count = wl_list_length(&ctx_screen->order.list_layer);
1368 if (*layer_count == 0) {
1373 *layer_ids = malloc(*layer_count * sizeof(t_ilm_layer));
1374 if (*layer_ids == NULL) {
1375 fprintf(stderr, "memory insufficient for layerids\n");
1381 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link) {
1382 *ids = (t_ilm_layer)ctx_layer->id_layer;
1387 ILM_EXPORT ilmErrorTypes
1388 ilm_getPropertiesOfScreen(t_ilm_display screenID,
1389 struct ilmScreenProperties* pScreenProperties)
1391 ilmErrorTypes returnValue = ILM_FAILED;
1393 if (! pScreenProperties)
1395 return ILM_ERROR_INVALID_ARGUMENTS;
1398 struct ilm_control_context *ctx = sync_and_acquire_instance();
1400 struct screen_context *ctx_screen = NULL;
1401 ctx_screen = get_screen_context_by_id(&ctx->wl, (uint32_t)screenID);
1402 if (ctx_screen != NULL) {
1403 *pScreenProperties = ctx_screen->prop;
1404 create_layerids(ctx_screen, &pScreenProperties->layerIds,
1405 &pScreenProperties->layerCount);
1406 returnValue = ILM_SUCCESS;
1413 ILM_EXPORT ilmErrorTypes
1414 ilm_getNumberOfHardwareLayers(t_ilm_uint screenID,
1415 t_ilm_uint* pNumberOfHardwareLayers)
1419 if (pNumberOfHardwareLayers != NULL) {
1420 *pNumberOfHardwareLayers = 0;
1427 ILM_EXPORT ilmErrorTypes
1428 ilm_getScreenIDs(t_ilm_uint* pNumberOfIDs, t_ilm_uint** ppIDs)
1430 ilmErrorTypes returnValue = ILM_FAILED;
1431 struct ilm_control_context *ctx = sync_and_acquire_instance();
1433 if ((pNumberOfIDs != NULL) && (ppIDs != NULL)) {
1434 struct screen_context *ctx_scrn = NULL;
1435 t_ilm_uint length = wl_list_length(&ctx->wl.list_screen);
1438 *ppIDs = (t_ilm_uint*)malloc(length * sizeof **ppIDs);
1439 if (*ppIDs != NULL) {
1440 t_ilm_uint* ids = *ppIDs;
1441 wl_list_for_each(ctx_scrn, &ctx->wl.list_screen, link) {
1442 *ids = ctx_scrn->id_screen;
1445 *pNumberOfIDs = length;
1447 returnValue = ILM_SUCCESS;
1455 ILM_EXPORT ilmErrorTypes
1456 ilm_getLayerIDs(t_ilm_int* pLength, t_ilm_layer** ppArray)
1458 ilmErrorTypes returnValue = ILM_FAILED;
1459 struct ilm_control_context *ctx = sync_and_acquire_instance();
1461 if ((pLength != NULL) && (ppArray != NULL)) {
1462 struct layer_context *ctx_layer = NULL;
1463 t_ilm_uint length = wl_list_length(&ctx->wl.list_layer);
1466 *ppArray = (t_ilm_layer*)malloc(length * sizeof **ppArray);
1467 if (*ppArray != NULL) {
1468 // compositor sends layers in opposite order
1469 // write ids from back to front to turn them around
1470 t_ilm_layer* ids = *ppArray;
1471 wl_list_for_each_reverse(ctx_layer, &ctx->wl.list_layer, link)
1473 *ids = ctx_layer->id_layer;
1478 returnValue = ILM_SUCCESS;
1486 ILM_EXPORT ilmErrorTypes
1487 ilm_getLayerIDsOnScreen(t_ilm_uint screenId,
1489 t_ilm_layer** ppArray)
1491 ilmErrorTypes returnValue = ILM_FAILED;
1492 struct ilm_control_context *ctx = sync_and_acquire_instance();
1494 if ((pLength != NULL) && (ppArray != NULL)) {
1495 struct screen_context *ctx_screen = NULL;
1496 ctx_screen = get_screen_context_by_id(&ctx->wl, screenId);
1497 if (ctx_screen != NULL) {
1498 struct layer_context *ctx_layer = NULL;
1499 t_ilm_int length = wl_list_length(&ctx_screen->order.list_layer);
1503 *ppArray = (t_ilm_layer*)malloc(length * sizeof **ppArray);
1504 if (*ppArray != NULL) {
1505 // compositor sends layers in opposite order
1506 // write ids from back to front to turn them around
1507 t_ilm_layer* ids = *ppArray;
1508 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link)
1510 *ids = ctx_layer->id_layer;
1522 returnValue = ILM_SUCCESS;
1530 ILM_EXPORT ilmErrorTypes
1531 ilm_getSurfaceIDs(t_ilm_int* pLength, t_ilm_surface** ppArray)
1533 ilmErrorTypes returnValue = ILM_FAILED;
1534 struct ilm_control_context *ctx = sync_and_acquire_instance();
1536 if ((pLength != NULL) && (ppArray != NULL)) {
1537 struct surface_context *ctx_surf = NULL;
1538 t_ilm_uint length = wl_list_length(&ctx->wl.list_surface);
1541 *ppArray = (t_ilm_surface*)malloc(length * sizeof **ppArray);
1542 if (*ppArray != NULL) {
1543 t_ilm_surface* ids = *ppArray;
1544 wl_list_for_each_reverse(ctx_surf, &ctx->wl.list_surface, link) {
1545 *ids = ctx_surf->id_surface;
1550 returnValue = ILM_SUCCESS;
1558 ILM_EXPORT ilmErrorTypes
1559 ilm_getSurfaceIDsOnLayer(t_ilm_layer layer,
1561 t_ilm_surface** ppArray)
1563 struct ilm_control_context *ctx = sync_and_acquire_instance();
1564 struct layer_context *ctx_layer = NULL;
1565 struct surface_context *ctx_surf = NULL;
1566 t_ilm_uint length = 0;
1567 t_ilm_surface* ids = NULL;
1569 if ((pLength == NULL) || (ppArray == NULL)) {
1574 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1575 &ctx->wl, (uint32_t)layer);
1577 if (ctx_layer == NULL) {
1582 length = wl_list_length(&ctx_layer->order.list_surface);
1583 *ppArray = (t_ilm_surface*)malloc(length * sizeof **ppArray);
1584 if (*ppArray == NULL) {
1590 wl_list_for_each_reverse(ctx_surf, &ctx_layer->order.list_surface, order.link) {
1591 *ids = (t_ilm_surface)ctx_surf->id_surface;
1600 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid)
1602 struct layer_context *ctx_layer = calloc(1, sizeof *ctx_layer);
1603 if (ctx_layer == NULL) {
1604 fprintf(stderr, "Failed to allocate memory for layer_context\n");
1608 ctx_layer->controller = ivi_controller_layer_create(
1610 layerid, width, height);
1611 if (ctx_layer->controller == NULL) {
1612 fprintf(stderr, "Failed to create layer\n");
1616 ctx_layer->id_layer = layerid;
1617 ctx_layer->ctx = ctx;
1619 wl_list_init(&ctx_layer->link);
1620 wl_list_insert(&ctx->list_layer, &ctx_layer->link);
1621 wl_list_init(&ctx_layer->order.link);
1622 wl_list_init(&ctx_layer->order.list_surface);
1624 ivi_controller_layer_add_listener(ctx_layer->controller,
1625 &controller_layer_listener, ctx_layer);
1630 ILM_EXPORT ilmErrorTypes
1631 ilm_layerCreateWithDimension(t_ilm_layer* pLayerId,
1635 ilmErrorTypes returnValue = ILM_FAILED;
1636 struct ilm_control_context *ctx = sync_and_acquire_instance();
1637 uint32_t layerid = 0;
1638 int32_t is_inside = 0;
1641 if (pLayerId == NULL) {
1645 if (*pLayerId != INVALID_ID) {
1646 /* Return failed, if layerid is already inside list_layer */
1647 is_inside = wayland_controller_is_inside_layer_list(
1648 &ctx->wl.list_layer, *pLayerId);
1649 if (0 != is_inside) {
1650 fprintf(stderr, "layerid=%d is already used.\n", *pLayerId);
1653 layerid = *pLayerId;
1656 /* Generate ID, if layerid is INVALID_ID */
1657 layerid = gen_layer_id(ctx);
1658 *pLayerId = layerid;
1661 if (create_controller_layer(&ctx->wl, width, height, layerid) == 0)
1663 returnValue = ILM_SUCCESS;
1671 ILM_EXPORT ilmErrorTypes
1672 ilm_layerRemove(t_ilm_layer layerId)
1674 ilmErrorTypes returnValue = ILM_FAILED;
1675 struct ilm_control_context *ctx = sync_and_acquire_instance();
1676 struct layer_context *ctx_layer = NULL;
1677 struct layer_context *ctx_next = NULL;
1679 wl_list_for_each_safe(ctx_layer, ctx_next,
1680 &ctx->wl.list_layer, link) {
1681 if (ctx_layer->id_layer == layerId) {
1682 ivi_controller_layer_destroy(ctx_layer->controller, 1);
1684 wl_list_remove(&ctx_layer->link);
1687 returnValue = ILM_SUCCESS;
1696 ILM_EXPORT ilmErrorTypes
1697 ilm_layerGetType(t_ilm_layer layerId, ilmLayerType* pLayerType)
1701 return ILM_ERROR_INVALID_ARGUMENTS;
1704 struct ilm_control_context *ctx = sync_and_acquire_instance();
1706 *pLayerType = wayland_controller_is_inside_layer_list(&ctx->wl.list_layer, layerId) ?
1707 ILM_LAYERTYPE_SOFTWARE2D :
1708 ILM_LAYERTYPE_UNKNOWN;
1711 return ILM_SUCCESS; // even if non existent?
1714 ILM_EXPORT ilmErrorTypes
1715 ilm_layerSetVisibility(t_ilm_layer layerId, t_ilm_bool newVisibility)
1717 ilmErrorTypes returnValue = ILM_FAILED;
1718 struct ilm_control_context *ctx = sync_and_acquire_instance();
1719 struct layer_context *ctx_layer = NULL;
1721 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1722 &ctx->wl, (uint32_t)layerId);
1724 if (ctx_layer != NULL) {
1725 uint32_t visibility = 0;
1726 if (newVisibility == ILM_TRUE) {
1729 ivi_controller_layer_set_visibility(ctx_layer->controller,
1731 returnValue = ILM_SUCCESS;
1738 ILM_EXPORT ilmErrorTypes
1739 ilm_layerGetVisibility(t_ilm_layer layerId, t_ilm_bool *pVisibility)
1741 ilmErrorTypes returnValue = ILM_FAILED;
1742 struct ilm_control_context *ctx = sync_and_acquire_instance();
1744 if (pVisibility != NULL) {
1745 struct layer_context *ctx_layer = NULL;
1747 ctx_layer = (struct layer_context*)
1748 wayland_controller_get_layer_context(
1749 &ctx->wl, (uint32_t)layerId);
1751 if (ctx_layer != NULL) {
1752 *pVisibility = ctx_layer->prop.visibility;
1753 returnValue = ILM_SUCCESS;
1761 ILM_EXPORT ilmErrorTypes
1762 ilm_layerSetOpacity(t_ilm_layer layerId, t_ilm_float opacity)
1764 ilmErrorTypes returnValue = ILM_FAILED;
1765 struct ilm_control_context *ctx = sync_and_acquire_instance();
1766 struct layer_context *ctx_layer = NULL;
1768 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1769 &ctx->wl, (uint32_t)layerId);
1771 if (ctx_layer != NULL) {
1772 wl_fixed_t opacity_fixed = wl_fixed_from_double((double)opacity);
1773 ivi_controller_layer_set_opacity(ctx_layer->controller,
1775 returnValue = ILM_SUCCESS;
1782 ILM_EXPORT ilmErrorTypes
1783 ilm_layerGetOpacity(t_ilm_layer layerId, t_ilm_float *pOpacity)
1785 ilmErrorTypes returnValue = ILM_FAILED;
1786 struct ilm_control_context *ctx = sync_and_acquire_instance();
1788 if (pOpacity != NULL) {
1789 struct layer_context *ctx_layer = NULL;
1791 ctx_layer = (struct layer_context*)
1792 wayland_controller_get_layer_context(
1793 &ctx->wl, (uint32_t)layerId);
1795 if (ctx_layer != NULL) {
1796 *pOpacity = ctx_layer->prop.opacity;
1797 returnValue = ILM_SUCCESS;
1805 ILM_EXPORT ilmErrorTypes
1806 ilm_layerSetSourceRectangle(t_ilm_layer layerId,
1807 t_ilm_uint x, t_ilm_uint y,
1808 t_ilm_uint width, t_ilm_uint height)
1810 ilmErrorTypes returnValue = ILM_FAILED;
1811 struct ilm_control_context *ctx = sync_and_acquire_instance();
1812 struct layer_context *ctx_layer = NULL;
1814 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1815 &ctx->wl, (uint32_t)layerId);
1817 if (ctx_layer != NULL) {
1818 ivi_controller_layer_set_source_rectangle(ctx_layer->controller,
1823 returnValue = ILM_SUCCESS;
1830 ILM_EXPORT ilmErrorTypes
1831 ilm_layerSetDestinationRectangle(t_ilm_layer layerId,
1832 t_ilm_int x, t_ilm_int y,
1833 t_ilm_int width, t_ilm_int height)
1835 ilmErrorTypes returnValue = ILM_FAILED;
1836 struct ilm_control_context *ctx = sync_and_acquire_instance();
1837 struct layer_context *ctx_layer = NULL;
1839 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1840 &ctx->wl, (uint32_t)layerId);
1841 if (ctx_layer != NULL) {
1842 ivi_controller_layer_set_destination_rectangle(
1843 ctx_layer->controller,
1844 (uint32_t)x, (uint32_t)y,
1847 returnValue = ILM_SUCCESS;
1854 ILM_EXPORT ilmErrorTypes
1855 ilm_layerGetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
1857 ilmErrorTypes returnValue = ILM_FAILED;
1858 struct ilm_control_context *ctx = sync_and_acquire_instance();
1859 struct layer_context *ctx_layer = NULL;
1861 if (pDimension != NULL) {
1862 ctx_layer = (struct layer_context*)
1863 wayland_controller_get_layer_context(
1864 &ctx->wl, (uint32_t)layerId);
1865 if (ctx_layer != NULL) {
1866 *pDimension = ctx_layer->prop.destWidth;
1867 *(pDimension + 1) = ctx_layer->prop.destHeight;
1868 returnValue = ILM_SUCCESS;
1876 ILM_EXPORT ilmErrorTypes
1877 ilm_layerSetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
1879 ilmErrorTypes returnValue = ILM_FAILED;
1880 struct ilm_control_context *ctx = sync_and_acquire_instance();
1881 struct layer_context *ctx_layer = NULL;
1883 if (pDimension != NULL) {
1884 ctx_layer = (struct layer_context*)
1885 wayland_controller_get_layer_context(
1886 &ctx->wl, (uint32_t)layerId);
1887 if (ctx_layer != NULL) {
1888 ivi_controller_layer_set_destination_rectangle(
1889 ctx_layer->controller,
1890 ctx_layer->prop.destX, ctx_layer->prop.destY,
1891 (int32_t)*pDimension, (int32_t)*(pDimension + 1));
1892 returnValue = ILM_SUCCESS;
1900 ILM_EXPORT ilmErrorTypes
1901 ilm_layerGetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
1903 ilmErrorTypes returnValue = ILM_FAILED;
1904 struct ilm_control_context *ctx = sync_and_acquire_instance();
1905 struct layer_context *ctx_layer = NULL;
1907 if (pPosition != NULL) {
1908 ctx_layer = (struct layer_context*)
1909 wayland_controller_get_layer_context(
1910 &ctx->wl, (uint32_t)layerId);
1911 if (ctx_layer != NULL) {
1912 *pPosition = ctx_layer->prop.destX;
1913 *(pPosition + 1) = ctx_layer->prop.destY;
1914 returnValue = ILM_SUCCESS;
1922 ILM_EXPORT ilmErrorTypes
1923 ilm_layerSetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
1925 ilmErrorTypes returnValue = ILM_FAILED;
1926 struct ilm_control_context *ctx = sync_and_acquire_instance();
1927 struct layer_context *ctx_layer = NULL;
1929 if (pPosition != NULL) {
1930 ctx_layer = (struct layer_context*)
1931 wayland_controller_get_layer_context(
1932 &ctx->wl, (uint32_t)layerId);
1933 if (ctx_layer != NULL) {
1934 ivi_controller_layer_set_destination_rectangle(
1935 ctx_layer->controller,
1936 (int32_t)*pPosition, (int32_t)*(pPosition + 1),
1937 ctx_layer->prop.destWidth, ctx_layer->prop.destHeight);
1938 returnValue = ILM_SUCCESS;
1946 ILM_EXPORT ilmErrorTypes
1947 ilm_layerSetOrientation(t_ilm_layer layerId, ilmOrientation orientation)
1949 ilmErrorTypes returnValue = ILM_FAILED;
1950 struct ilm_control_context *ctx = sync_and_acquire_instance();
1951 struct layer_context *ctx_layer = NULL;
1952 int32_t iviorientation = 0;
1955 switch(orientation) {
1957 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
1960 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
1962 case ILM_ONEHUNDREDEIGHTY:
1963 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
1965 case ILM_TWOHUNDREDSEVENTY:
1966 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
1969 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
1973 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1974 &ctx->wl, (uint32_t)layerId);
1975 if (ctx_layer == NULL) {
1976 returnValue = ILM_FAILED;
1980 ivi_controller_layer_set_orientation(ctx_layer->controller,
1983 returnValue = ILM_SUCCESS;
1990 ILM_EXPORT ilmErrorTypes
1991 ilm_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrientation)
1993 ilmErrorTypes returnValue = ILM_FAILED;
1994 struct ilm_control_context *ctx = sync_and_acquire_instance();
1995 struct layer_context *ctx_layer = NULL;
1997 if (pOrientation != NULL) {
1998 ctx_layer = (struct layer_context*)
1999 wayland_controller_get_layer_context(
2000 &ctx->wl, (uint32_t)layerId);
2001 if (ctx_layer != NULL) {
2002 *pOrientation = ctx_layer->prop.orientation;
2003 returnValue = ILM_SUCCESS;
2011 ILM_EXPORT ilmErrorTypes
2012 ilm_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
2020 ILM_EXPORT ilmErrorTypes
2021 ilm_layerSetRenderOrder(t_ilm_layer layerId,
2022 t_ilm_surface *pSurfaceId,
2025 ilmErrorTypes returnValue = ILM_FAILED;
2026 struct ilm_control_context *ctx = sync_and_acquire_instance();
2027 struct layer_context *ctx_layer = NULL;
2029 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2030 &ctx->wl, (uint32_t)layerId);
2034 struct wl_array ids;
2035 wl_array_init(&ids);
2036 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2038 for (i = 0; i < number; i++) pids[i] = (uint32_t)pSurfaceId[i];
2039 ivi_controller_layer_set_render_order(ctx_layer->controller, &ids);
2040 wl_array_release(&ids);
2041 returnValue = ILM_SUCCESS;
2048 ILM_EXPORT ilmErrorTypes
2049 ilm_layerGetCapabilities(t_ilm_layer layerId,
2050 t_ilm_layercapabilities *pCapabilities)
2053 (void)pCapabilities;
2058 ILM_EXPORT ilmErrorTypes
2059 ilm_layerTypeGetCapabilities(ilmLayerType layerType,
2060 t_ilm_layercapabilities *pCapabilities)
2063 (void)pCapabilities;
2068 ILM_EXPORT ilmErrorTypes
2069 ilm_surfaceSetVisibility(t_ilm_surface surfaceId, t_ilm_bool newVisibility)
2071 ilmErrorTypes returnValue = ILM_FAILED;
2072 struct ilm_control_context *ctx = sync_and_acquire_instance();
2073 struct surface_context *ctx_surf = NULL;
2074 uint32_t visibility = 0;
2076 if (newVisibility == ILM_TRUE) {
2079 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2081 ivi_controller_surface_set_visibility(ctx_surf->controller,
2083 returnValue = ILM_SUCCESS;
2090 ILM_EXPORT ilmErrorTypes
2091 ilm_surfaceSetOpacity(t_ilm_surface surfaceId, t_ilm_float opacity)
2093 ilmErrorTypes returnValue = ILM_FAILED;
2094 struct ilm_control_context *ctx = sync_and_acquire_instance();
2095 struct surface_context *ctx_surf = NULL;
2096 wl_fixed_t opacity_fixed = 0;
2098 opacity_fixed = wl_fixed_from_double((double)opacity);
2099 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2101 ivi_controller_surface_set_opacity(ctx_surf->controller,
2103 returnValue = ILM_SUCCESS;
2110 ILM_EXPORT ilmErrorTypes
2111 ilm_surfaceGetOpacity(t_ilm_surface surfaceId, t_ilm_float *pOpacity)
2113 ilmErrorTypes returnValue = ILM_FAILED;
2114 struct ilm_control_context *ctx = sync_and_acquire_instance();
2116 if (pOpacity != NULL) {
2117 struct surface_context *ctx_surf = NULL;
2118 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2120 *pOpacity = ctx_surf->prop.opacity;
2121 returnValue = ILM_SUCCESS;
2129 ILM_EXPORT ilmErrorTypes
2130 ilm_SetKeyboardFocusOn(t_ilm_surface surfaceId)
2132 ilmErrorTypes returnValue = ILM_FAILED;
2134 returnValue = ILM_SUCCESS;
2138 ILM_EXPORT ilmErrorTypes
2139 ilm_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
2141 ilmErrorTypes returnValue = ILM_FAILED;
2143 returnValue = ILM_SUCCESS;
2147 ILM_EXPORT ilmErrorTypes
2148 ilm_surfaceSetDestinationRectangle(t_ilm_surface surfaceId,
2149 t_ilm_int x, t_ilm_int y,
2150 t_ilm_int width, t_ilm_int height)
2152 ilmErrorTypes returnValue = ILM_FAILED;
2153 struct ilm_control_context *ctx = sync_and_acquire_instance();
2154 struct surface_context *ctx_surf = NULL;
2156 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2158 ivi_controller_surface_set_destination_rectangle(
2159 ctx_surf->controller,
2160 x, y, width, height);
2161 returnValue = ILM_SUCCESS;
2168 ILM_EXPORT ilmErrorTypes
2169 ilm_surfaceSetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
2171 ilmErrorTypes returnValue = ILM_FAILED;
2172 struct ilm_control_context *ctx = sync_and_acquire_instance();
2174 if (pDimension != NULL) {
2175 struct surface_context *ctx_surf = NULL;
2176 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2178 uint32_t width = *pDimension;
2179 uint32_t height = *(pDimension + 1);
2180 ivi_controller_surface_set_destination_rectangle(
2181 ctx_surf->controller,
2182 ctx_surf->prop.destX, ctx_surf->prop.destY, width, height);
2183 returnValue = ILM_SUCCESS;
2191 ILM_EXPORT ilmErrorTypes
2192 ilm_surfaceGetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2194 ilmErrorTypes returnValue = ILM_FAILED;
2195 struct ilm_control_context *ctx = sync_and_acquire_instance();
2197 if (pPosition != NULL) {
2198 struct surface_context *ctx_surf = NULL;
2199 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2201 *pPosition = ctx_surf->prop.destX;
2202 *(pPosition + 1) = ctx_surf->prop.destY;
2203 returnValue = ILM_SUCCESS;
2211 ILM_EXPORT ilmErrorTypes
2212 ilm_surfaceSetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2214 ilmErrorTypes returnValue = ILM_FAILED;
2215 struct ilm_control_context *ctx = sync_and_acquire_instance();
2217 if (pPosition != NULL) {
2218 struct surface_context *ctx_surf = NULL;
2219 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2221 int32_t destX = (int32_t)*pPosition;
2222 int32_t destY = (int32_t)*(pPosition + 1);
2223 ivi_controller_surface_set_destination_rectangle(
2224 ctx_surf->controller, destX, destY,
2225 ctx_surf->prop.destWidth, ctx_surf->prop.destHeight);
2226 returnValue = ILM_SUCCESS;
2234 ILM_EXPORT ilmErrorTypes
2235 ilm_surfaceSetOrientation(t_ilm_surface surfaceId,
2236 ilmOrientation orientation)
2238 ilmErrorTypes returnValue = ILM_FAILED;
2239 struct ilm_control_context *ctx = sync_and_acquire_instance();
2240 struct surface_context *ctx_surf = NULL;
2241 int32_t iviorientation = 0;
2244 switch(orientation) {
2246 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2249 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2251 case ILM_ONEHUNDREDEIGHTY:
2252 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2254 case ILM_TWOHUNDREDSEVENTY:
2255 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2258 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2262 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2263 if (ctx_surf == NULL) {
2264 returnValue = ILM_FAILED;
2268 ivi_controller_surface_set_orientation(ctx_surf->controller,
2271 returnValue = ILM_SUCCESS;
2278 ILM_EXPORT ilmErrorTypes
2279 ilm_surfaceGetOrientation(t_ilm_surface surfaceId,
2280 ilmOrientation *pOrientation)
2282 ilmErrorTypes returnValue = ILM_FAILED;
2283 struct ilm_control_context *ctx = sync_and_acquire_instance();
2285 if (pOrientation != NULL) {
2286 struct surface_context *ctx_surf = NULL;
2287 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2289 *pOrientation = ctx_surf->prop.orientation;
2290 returnValue = ILM_SUCCESS;
2298 ILM_EXPORT ilmErrorTypes
2299 ilm_surfaceGetPixelformat(t_ilm_layer surfaceId,
2300 ilmPixelFormat *pPixelformat)
2302 ilmErrorTypes returnValue = ILM_FAILED;
2303 struct ilm_control_context *ctx = sync_and_acquire_instance();
2305 if (pPixelformat != NULL) {
2306 struct surface_context *ctx_surf = NULL;
2307 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2309 *pPixelformat = ctx_surf->prop.pixelformat;
2310 returnValue = ILM_SUCCESS;
2318 ILM_EXPORT ilmErrorTypes
2319 ilm_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
2327 ILM_EXPORT ilmErrorTypes
2328 ilm_displaySetRenderOrder(t_ilm_display display,
2329 t_ilm_layer *pLayerId, const t_ilm_uint number)
2331 ilmErrorTypes returnValue = ILM_FAILED;
2332 struct ilm_control_context *ctx = sync_and_acquire_instance();
2333 struct screen_context *ctx_scrn = NULL;
2335 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)display);
2336 if (ctx_scrn != NULL) {
2337 struct wl_array ids;
2338 wl_array_init(&ids);
2339 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2341 for (i = 0; i < number; i++) pids[i] = (uint32_t)pLayerId[i];
2342 ivi_controller_screen_set_render_order(ctx_scrn->controller, &ids);
2343 wl_array_release(&ids);
2344 returnValue = ILM_SUCCESS;
2351 ILM_EXPORT ilmErrorTypes
2352 ilm_takeScreenshot(t_ilm_uint screen, t_ilm_const_string filename)
2354 ilmErrorTypes returnValue = ILM_FAILED;
2355 struct ilm_control_context *ctx = sync_and_acquire_instance();
2356 struct screen_context *ctx_scrn = NULL;
2358 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)screen);
2359 if (ctx_scrn != NULL) {
2360 ivi_controller_screen_screenshot(ctx_scrn->controller,
2362 wl_display_flush(ctx->wl.display);
2363 returnValue = ILM_SUCCESS;
2370 ILM_EXPORT ilmErrorTypes
2371 ilm_takeLayerScreenshot(t_ilm_const_string filename, t_ilm_layer layerid)
2373 ilmErrorTypes returnValue = ILM_FAILED;
2374 struct ilm_control_context *ctx = sync_and_acquire_instance();
2375 struct layer_context *ctx_layer = NULL;
2377 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2378 &ctx->wl, (uint32_t)layerid);
2379 if (ctx_layer != NULL) {
2380 ivi_controller_layer_screenshot(ctx_layer->controller,
2382 wl_display_flush(ctx->wl.display);
2383 returnValue = ILM_SUCCESS;
2390 ILM_EXPORT ilmErrorTypes
2391 ilm_takeSurfaceScreenshot(t_ilm_const_string filename,
2392 t_ilm_surface surfaceid)
2394 ilmErrorTypes returnValue = ILM_FAILED;
2395 struct ilm_control_context *ctx = sync_and_acquire_instance();
2396 struct surface_context *ctx_surf = NULL;
2398 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceid);
2400 ivi_controller_surface_screenshot(ctx_surf->controller,
2402 wl_display_flush(ctx->wl.display);
2403 returnValue = ILM_SUCCESS;
2410 ILM_EXPORT ilmErrorTypes
2411 ilm_SetOptimizationMode(ilmOptimization id, ilmOptimizationMode mode)
2419 ILM_EXPORT ilmErrorTypes
2420 ilm_GetOptimizationMode(ilmOptimization id, ilmOptimizationMode* pMode)
2428 ILM_EXPORT ilmErrorTypes
2429 ilm_layerAddNotification(t_ilm_layer layer,
2430 layerNotificationFunc callback)
2432 ilmErrorTypes returnValue = ILM_FAILED;
2433 struct ilm_control_context *ctx = sync_and_acquire_instance();
2434 struct layer_context *ctx_layer = NULL;
2436 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2437 &ctx->wl, (uint32_t)layer);
2438 if (ctx_layer == NULL) {
2439 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2441 ctx_layer->notification = callback;
2443 returnValue = ILM_SUCCESS;
2450 ILM_EXPORT ilmErrorTypes
2451 ilm_layerRemoveNotification(t_ilm_layer layer)
2453 return ilm_layerAddNotification(layer, NULL);
2456 ILM_EXPORT ilmErrorTypes
2457 ilm_surfaceAddNotification(t_ilm_surface surface,
2458 surfaceNotificationFunc callback)
2460 ilmErrorTypes returnValue = ILM_FAILED;
2461 struct ilm_control_context *ctx = sync_and_acquire_instance();
2462 struct surface_context *ctx_surf = NULL;
2464 ctx_surf = (struct surface_context*)get_surface_context(
2465 &ctx->wl, (uint32_t)surface);
2466 if (ctx_surf == NULL) {
2467 if (callback != NULL) {
2468 callback((uint32_t)surface, NULL, ILM_NOTIFICATION_CONTENT_REMOVED);
2469 controller_listener_surface(ctx, ctx->wl.controller, (uint32_t)surface);
2470 ctx_surf = (struct surface_context*)get_surface_context(
2471 &ctx->wl, (uint32_t)surface);
2472 ctx_surf->is_surface_creation_noticed = false;
2476 if (ctx_surf == NULL) {
2477 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2480 ctx_surf->notification = callback;
2482 returnValue = ILM_SUCCESS;
2489 ILM_EXPORT ilmErrorTypes
2490 ilm_surfaceRemoveNotification(t_ilm_surface surface)
2492 return ilm_surfaceAddNotification(surface, NULL);
2495 ILM_EXPORT ilmErrorTypes
2496 ilm_getNativeHandle(t_ilm_uint pid, t_ilm_int *n_handle,
2497 t_ilm_nativehandle **p_handles)
2499 struct ilm_control_context *ctx = sync_and_acquire_instance();
2500 struct nativehandle_context *p_nh_ctx = NULL;
2505 wl_list_for_each(p_nh_ctx, &ctx->list_nativehandle, link)
2507 if (p_nh_ctx->pid == pid)
2511 (t_ilm_nativehandle*)malloc(sizeof(t_ilm_nativehandle));
2512 (*p_handles)[0] = p_nh_ctx->nativehandle;
2518 return (*n_handle > 0) ? ILM_SUCCESS : ILM_FAILED;
2521 ILM_EXPORT ilmErrorTypes
2522 ilm_getPropertiesOfSurface(t_ilm_uint surfaceID,
2523 struct ilmSurfaceProperties* pSurfaceProperties)
2525 ilmErrorTypes returnValue = ILM_FAILED;
2526 struct ilm_control_context *ctx = sync_and_acquire_instance();
2528 if (pSurfaceProperties != NULL) {
2529 struct surface_context *ctx_surf = NULL;
2531 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceID);
2532 if (ctx_surf != NULL) {
2534 *pSurfaceProperties = ctx_surf->prop;
2535 returnValue = ILM_SUCCESS;
2543 ILM_EXPORT ilmErrorTypes
2544 ilm_layerAddSurface(t_ilm_layer layerId,
2545 t_ilm_surface surfaceId)
2547 ilmErrorTypes returnValue = ILM_FAILED;
2548 struct ilm_control_context *ctx = sync_and_acquire_instance();
2549 struct layer_context *ctx_layer = NULL;
2550 struct surface_context *ctx_surf = NULL;
2552 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2553 &ctx->wl, (uint32_t)layerId);
2554 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2555 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2556 ivi_controller_layer_add_surface(ctx_layer->controller,
2557 ctx_surf->controller);
2558 returnValue = ILM_SUCCESS;
2565 ILM_EXPORT ilmErrorTypes
2566 ilm_layerRemoveSurface(t_ilm_layer layerId,
2567 t_ilm_surface surfaceId)
2569 ilmErrorTypes returnValue = ILM_FAILED;
2570 struct ilm_control_context *ctx = sync_and_acquire_instance();
2571 struct layer_context *ctx_layer = NULL;
2572 struct surface_context *ctx_surf = NULL;
2574 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2575 &ctx->wl, (uint32_t)layerId);
2576 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2577 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2578 ivi_controller_layer_remove_surface(ctx_layer->controller,
2579 ctx_surf->controller);
2580 returnValue = ILM_SUCCESS;
2587 ILM_EXPORT ilmErrorTypes
2588 ilm_surfaceGetDimension(t_ilm_surface surfaceId,
2589 t_ilm_uint *pDimension)
2591 ilmErrorTypes returnValue = ILM_FAILED;
2592 struct ilm_control_context *ctx = sync_and_acquire_instance();
2594 if (pDimension != NULL) {
2595 struct surface_context *ctx_surf = NULL;
2597 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2598 if (ctx_surf != NULL) {
2599 *pDimension = (t_ilm_uint)ctx_surf->prop.destWidth;
2600 *(pDimension + 1) = (t_ilm_uint)ctx_surf->prop.destHeight;
2601 returnValue = ILM_SUCCESS;
2609 ILM_EXPORT ilmErrorTypes
2610 ilm_surfaceGetVisibility(t_ilm_surface surfaceId,
2611 t_ilm_bool *pVisibility)
2613 ilmErrorTypes returnValue = ILM_FAILED;
2614 struct ilm_control_context *ctx = sync_and_acquire_instance();
2615 struct surface_context *ctx_surf = NULL;
2617 if (pVisibility != NULL) {
2618 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2619 if (ctx_surf != NULL) {
2620 *pVisibility = (t_ilm_bool)ctx_surf->prop.visibility;
2621 returnValue = ILM_SUCCESS;
2629 ILM_EXPORT ilmErrorTypes
2630 ilm_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
2631 t_ilm_int x, t_ilm_int y,
2632 t_ilm_int width, t_ilm_int height)
2634 ilmErrorTypes returnValue = ILM_FAILED;
2635 struct ilm_control_context *ctx = sync_and_acquire_instance();
2636 struct surface_context *ctx_surf = NULL;
2638 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2639 if (ctx_surf != NULL) {
2640 if (ctx_surf->controller != NULL) {
2641 ivi_controller_surface_set_source_rectangle(
2642 ctx_surf->controller,
2643 x, y, width, height);
2644 returnValue = ILM_SUCCESS;
2652 ILM_EXPORT ilmErrorTypes
2653 ilm_commitChanges(void)
2655 ilmErrorTypes returnValue = ILM_FAILED;
2656 struct ilm_control_context *ctx = sync_and_acquire_instance();
2658 if (ctx->wl.controller != NULL) {
2659 ivi_controller_commit_changes(ctx->wl.controller);
2661 if (display_roundtrip_queue(ctx->wl.display, ctx->wl.queue) != -1)
2663 returnValue = ILM_SUCCESS;