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,
768 struct surface_context *ctx_surf = data;
770 if (ctx_surf == NULL) {
771 fprintf(stderr, "%s: Invalid surface context\n", __FUNCTION__);
774 if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
775 ctx_surf->prop.hasKeyboardFocus = enabled;
779 static struct ivi_controller_surface_listener controller_surface_listener=
781 controller_surface_listener_visibility,
782 controller_surface_listener_opacity,
783 controller_surface_listener_source_rectangle,
784 controller_surface_listener_destination_rectangle,
785 controller_surface_listener_configuration,
786 controller_surface_listener_orientation,
787 controller_surface_listener_pixelformat,
788 controller_surface_listener_layer,
789 controller_surface_listener_stats,
790 controller_surface_listener_destroyed,
791 controller_surface_listener_content,
792 controller_surface_listener_input_focus
796 controller_listener_layer(void *data,
797 struct ivi_controller *controller,
800 struct wayland_context *ctx = data;
802 if (wayland_controller_is_inside_layer_list(&ctx->list_layer, id_layer))
807 (void) create_controller_layer(ctx, 0, 0, id_layer);
811 controller_listener_surface(void *data,
812 struct ivi_controller *controller,
817 struct wayland_context *ctx = data;
818 struct surface_context *ctx_surf = NULL;
819 int32_t is_inside = 0;
824 ctx_surf = get_surface_context(ctx, id_surface);
825 if (ctx_surf != NULL) {
826 if (!ctx_surf->is_surface_creation_noticed) {
827 if (ctx_surf->notification != NULL) {
828 ctx_surf->notification(ctx_surf->id_surface,
830 ILM_NOTIFICATION_CONTENT_AVAILABLE);
831 ctx_surf->is_surface_creation_noticed = true;
833 ctx_surf->controller = ivi_controller_surface_create(
834 controller, id_surface);
837 fprintf(stderr, "invalid id_surface in controller_listener_surface\n");
842 ctx_surf = calloc(1, sizeof *ctx_surf);
843 if (ctx_surf == NULL) {
844 fprintf(stderr, "Failed to allocate memory for surface_context\n");
848 ctx_surf->controller = ivi_controller_surface_create(
849 controller, id_surface);
850 if (ctx_surf->controller == NULL) {
852 fprintf(stderr, "Failed to create controller surface\n");
855 ctx_surf->id_surface = id_surface;
856 ctx_surf->prop.inputDevicesAcceptance = ILM_INPUT_DEVICE_ALL;
858 ctx_surf->is_surface_creation_noticed = true;
860 wl_list_init(&ctx_surf->link);
861 wl_list_insert(&ctx->list_surface, &ctx_surf->link);
862 wl_list_init(&ctx_surf->order.link);
863 ivi_controller_surface_add_listener(ctx_surf->controller,
864 &controller_surface_listener, ctx_surf);
868 controller_listener_error(void *data,
869 struct ivi_controller *ivi_controller,
873 const char *error_text)
876 (void)ivi_controller;
884 controller_listener_screen(void *data,
885 struct ivi_controller *ivi_controller,
887 struct ivi_controller_screen *controller_screen)
889 struct wayland_context *ctx = data;
890 struct screen_context *ctx_screen;
891 (void)ivi_controller;
893 ctx_screen = get_screen_context_by_serverid(ctx, id_screen);
894 if (ctx_screen == NULL) {
895 fprintf(stderr, "Failed to allocate memory for screen_context\n");
898 ctx_screen->controller = controller_screen;
901 static struct ivi_controller_listener controller_listener= {
902 controller_listener_screen,
903 controller_listener_layer,
904 controller_listener_surface,
905 controller_listener_error
909 registry_handle_control(void *data,
910 struct wl_registry *registry,
911 uint32_t name, const char *interface,
914 struct wayland_context *ctx = data;
917 if (strcmp(interface, "ivi_controller") == 0) {
918 ctx->controller = wl_registry_bind(registry, name,
919 &ivi_controller_interface, 1);
920 if (ctx->controller == NULL) {
921 fprintf(stderr, "Failed to registry bind ivi_controller\n");
924 if (ivi_controller_add_listener(ctx->controller,
925 &controller_listener,
927 fprintf(stderr, "Failed to add ivi_controller listener\n");
930 } else if (strcmp(interface, "wl_output") == 0) {
931 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
932 struct wl_proxy *pxy = NULL;
934 if (ctx_scrn == NULL) {
935 fprintf(stderr, "Failed to allocate memory for screen_context\n");
938 wl_list_init(&ctx_scrn->link);
939 ctx_scrn->output = wl_registry_bind(registry, name,
940 &wl_output_interface, 1);
941 if (ctx_scrn->output == NULL) {
943 fprintf(stderr, "Failed to registry bind wl_output\n");
947 if (wl_output_add_listener(ctx_scrn->output,
951 fprintf(stderr, "Failed to add wl_output listener\n");
955 pxy = (struct wl_proxy*)ctx_scrn->output;
956 ctx_scrn->id_from_server = wl_proxy_get_id(pxy);
957 ctx_scrn->id_screen = ctx->num_screen;
959 wl_list_init(&ctx_scrn->order.list_layer);
960 wl_list_insert(&ctx->list_screen, &ctx_scrn->link);
964 static const struct wl_registry_listener
965 registry_control_listener= {
966 registry_handle_control,
970 static struct ilm_control_context ilm_context;
972 static void destroy_control_resources(void)
974 struct ilm_control_context *ctx = &ilm_context;
976 // free resources of output objects
977 if (! ctx->wl.controller) {
978 struct screen_context *ctx_scrn;
979 struct screen_context *next;
981 wl_list_for_each_safe(ctx_scrn, next, &ctx->wl.list_screen, link) {
982 if (ctx_scrn->output != NULL) {
983 wl_output_destroy(ctx_scrn->output);
986 wl_list_remove(&ctx_scrn->link);
991 if (ctx->wl.controller != NULL) {
993 struct surface_context *l;
994 struct surface_context *n;
995 wl_list_for_each_safe(l, n, &ctx->wl.list_surface, link) {
996 wl_list_remove(&l->link);
997 wl_list_remove(&l->order.link);
998 ivi_controller_surface_destroy(l->controller, 0);
1004 struct layer_context *l;
1005 struct layer_context *n;
1006 wl_list_for_each_safe(l, n, &ctx->wl.list_layer, link) {
1007 wl_list_remove(&l->link);
1008 wl_list_remove(&l->order.link);
1014 struct screen_context *ctx_scrn;
1015 struct screen_context *next;
1017 wl_list_for_each_safe(ctx_scrn, next, &ctx->wl.list_screen, link) {
1018 if (ctx_scrn->output != NULL) {
1019 wl_output_destroy(ctx_scrn->output);
1022 wl_list_remove(&ctx_scrn->link);
1023 ivi_controller_screen_destroy(ctx_scrn->controller);
1028 ivi_controller_destroy(ctx->wl.controller);
1029 ctx->wl.controller = NULL;
1032 if (ctx->wl.display) {
1033 wl_display_flush(ctx->wl.display);
1036 if (ctx->wl.registry) {
1037 wl_registry_destroy(ctx->wl.registry);
1038 ctx->wl.registry = NULL;
1041 if (ctx->wl.queue) {
1042 wl_event_queue_destroy(ctx->wl.queue);
1043 ctx->wl.queue = NULL;
1046 if (0 != pthread_mutex_destroy(&ctx->mutex)) {
1047 fprintf(stderr, "failed to destroy pthread_mutex\n");
1051 static void send_shutdown_event(struct ilm_control_context *ctx)
1054 while (write(ctx->shutdown_fd, &buf, sizeof buf) == -1 && errno == EINTR)
1059 ilmControl_destroy(void)
1061 struct ilm_control_context *ctx = &ilm_context;
1063 send_shutdown_event(ctx);
1065 if (0 != pthread_join(ctx->thread, NULL)) {
1066 fprintf(stderr, "failed to join control thread\n");
1069 destroy_control_resources();
1071 close(ctx->shutdown_fd);
1073 memset(ctx, 0, sizeof *ctx);
1076 ILM_EXPORT ilmErrorTypes
1077 ilmControl_init(t_ilm_nativedisplay nativedisplay)
1079 struct ilm_control_context *ctx = &ilm_context;
1081 if (ctx->initialized)
1083 fprintf(stderr, "Already initialized!\n");
1087 if (nativedisplay == 0) {
1088 return ILM_ERROR_INVALID_ARGUMENTS;
1091 ctx->shutdown_fd = -1;
1093 ctx->wl.display = (struct wl_display*)nativedisplay;
1095 wl_list_init(&ctx->wl.list_screen);
1096 wl_list_init(&ctx->wl.list_layer);
1097 wl_list_init(&ctx->wl.list_surface);
1100 pthread_mutexattr_t a;
1101 if (pthread_mutexattr_init(&a) != 0)
1106 if (pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE) != 0)
1108 pthread_mutexattr_destroy(&a);
1112 if (pthread_mutex_init(&ctx->mutex, &a) != 0)
1114 pthread_mutexattr_destroy(&a);
1115 fprintf(stderr, "failed to initialize pthread_mutex\n");
1119 pthread_mutexattr_destroy(&a);
1122 return init_control() == 0 ? ILM_SUCCESS : ILM_FAILED;
1126 control_thread(void *p_ret)
1128 struct ilm_control_context *const ctx = &ilm_context;
1129 struct wayland_context *const wl = &ctx->wl;
1130 struct wl_display *const display = wl->display;
1131 struct wl_event_queue *const queue = wl->queue;
1132 int const fd = wl_display_get_fd(display);
1133 int const shutdown_fd = ctx->shutdown_fd;
1138 while (wl_display_prepare_read_queue(display, queue) != 0)
1141 wl_display_dispatch_queue_pending(display, queue);
1142 unlock_context(ctx);
1145 if (wl_display_flush(display) == -1)
1150 struct pollfd pfd[2] = {
1151 { .fd = fd, .events = POLLIN },
1152 { .fd = shutdown_fd, .events = POLLIN }
1155 int pollret = poll(pfd, 2, -1);
1156 if (pollret != -1 && (pfd[0].revents & POLLIN))
1158 wl_display_read_events(display);
1161 int ret = wl_display_dispatch_queue_pending(display, queue);
1162 unlock_context(ctx);
1171 wl_display_cancel_read(display);
1173 if (pollret == -1 || (pfd[1].revents & POLLIN))
1186 struct ilm_control_context *ctx = &ilm_context;
1187 struct wayland_context *wl = &ctx->wl;
1191 wl_list_init(&ctx->list_nativehandle);
1193 wl->queue = wl_display_create_queue(wl->display);
1195 fprintf(stderr, "Could not create wayland event queue\n");
1199 /* registry_add_listener for request by ivi-controller */
1200 wl->registry = wl_display_get_registry(wl->display);
1201 if (wl->registry == NULL) {
1202 wl_event_queue_destroy(wl->queue);
1204 fprintf(stderr, "Failed to get registry\n");
1207 wl_proxy_set_queue((void*)wl->registry, wl->queue);
1209 if (wl_registry_add_listener(wl->registry,
1210 ®istry_control_listener, ctx)) {
1211 fprintf(stderr, "Failed to add registry listener\n");
1216 // first level objects; ivi_controller
1217 display_roundtrip_queue(wl->display, wl->queue) == -1 ||
1218 // second level object: ivi_controller_surfaces/layers
1219 display_roundtrip_queue(wl->display, wl->queue) == -1 ||
1220 // third level objects: ivi_controller_surfaces/layers properties
1221 display_roundtrip_queue(wl->display, wl->queue) == -1)
1223 fprintf(stderr, "Failed to initialize wayland connection: %s\n", strerror(errno));
1227 if (! wl->controller)
1229 fprintf(stderr, "ivi_controller not available\n");
1233 ctx->shutdown_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
1235 if (ctx->shutdown_fd == -1)
1237 fprintf(stderr, "Could not setup shutdown-fd: %s\n", strerror(errno));
1241 ret = pthread_create(&ctx->thread, NULL, control_thread, NULL);
1244 fprintf(stderr, "Failed to start internal receive thread. returned %d\n", ret);
1248 ctx->initialized = true;
1253 static ilmErrorTypes impl_sync_and_acquire_instance(struct ilm_control_context *ctx)
1255 if (! ctx->initialized) {
1256 fprintf(stderr, "Not initialized\n");
1262 if (display_roundtrip_queue(ctx->wl.display, ctx->wl.queue) == -1) {
1263 int err = wl_display_get_error(ctx->wl.display);
1264 fprintf(stderr, "Error communicating with wayland: %s\n", strerror(err));
1265 unlock_context(ctx);
1272 #define sync_and_acquire_instance() ({ \
1273 struct ilm_control_context *ctx = &ilm_context; \
1275 ilmErrorTypes status = impl_sync_and_acquire_instance(ctx); \
1276 if (status != ILM_SUCCESS) { \
1283 static void release_instance(void)
1285 struct ilm_control_context *ctx = &ilm_context;
1286 unlock_context(ctx);
1290 gen_layer_id(struct ilm_control_context *ctx)
1292 struct layer_context *ctx_layer = NULL;
1295 if (wl_list_length(&ctx->wl.list_layer) == 0) {
1296 ctx->internal_id_layer++;
1297 return ctx->internal_id_layer;
1299 wl_list_for_each(ctx_layer, &ctx->wl.list_layer, link) {
1300 if (ctx_layer->id_layer == ctx->internal_id_layer) {
1306 return ctx->internal_id_layer;
1309 ctx->internal_id_layer++;
1313 static struct surface_context*
1314 get_surface_context(struct wayland_context *ctx,
1315 uint32_t id_surface)
1317 struct surface_context *ctx_surf = NULL;
1319 if (ctx->controller == NULL) {
1320 fprintf(stderr, "controller is not initialized in ilmControl\n");
1324 wl_list_for_each(ctx_surf, &ctx->list_surface, link) {
1325 if (ctx_surf->id_surface == id_surface) {
1330 fprintf(stderr, "failed to get surface context in ilmControl\n");
1334 static struct screen_context*
1335 get_screen_context_by_id(struct wayland_context *ctx, uint32_t id_screen)
1337 struct screen_context *ctx_scrn = NULL;
1339 if (ctx->controller == NULL) {
1340 fprintf(stderr, "get_screen_context_by_id: controller is NULL\n");
1344 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
1345 if (ctx_scrn->id_screen == id_screen) {
1352 ILM_EXPORT ilmErrorTypes
1353 ilm_getPropertiesOfLayer(t_ilm_uint layerID,
1354 struct ilmLayerProperties* pLayerProperties)
1356 ilmErrorTypes returnValue = ILM_FAILED;
1357 struct ilm_control_context *ctx = sync_and_acquire_instance();
1358 struct layer_context *ctx_layer = NULL;
1360 if (pLayerProperties != NULL) {
1362 ctx_layer = (struct layer_context*)
1363 wayland_controller_get_layer_context(
1364 &ctx->wl, (uint32_t)layerID);
1366 if (ctx_layer != NULL) {
1367 *pLayerProperties = ctx_layer->prop;
1368 returnValue = ILM_SUCCESS;
1377 create_layerids(struct screen_context *ctx_screen,
1378 t_ilm_layer **layer_ids, t_ilm_uint *layer_count)
1380 struct layer_context *ctx_layer = NULL;
1381 t_ilm_layer *ids = NULL;
1383 *layer_count = wl_list_length(&ctx_screen->order.list_layer);
1384 if (*layer_count == 0) {
1389 *layer_ids = malloc(*layer_count * sizeof(t_ilm_layer));
1390 if (*layer_ids == NULL) {
1391 fprintf(stderr, "memory insufficient for layerids\n");
1397 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link) {
1398 *ids = (t_ilm_layer)ctx_layer->id_layer;
1403 ILM_EXPORT ilmErrorTypes
1404 ilm_getPropertiesOfScreen(t_ilm_display screenID,
1405 struct ilmScreenProperties* pScreenProperties)
1407 ilmErrorTypes returnValue = ILM_FAILED;
1409 if (! pScreenProperties)
1411 return ILM_ERROR_INVALID_ARGUMENTS;
1414 struct ilm_control_context *ctx = sync_and_acquire_instance();
1416 struct screen_context *ctx_screen = NULL;
1417 ctx_screen = get_screen_context_by_id(&ctx->wl, (uint32_t)screenID);
1418 if (ctx_screen != NULL) {
1419 *pScreenProperties = ctx_screen->prop;
1420 create_layerids(ctx_screen, &pScreenProperties->layerIds,
1421 &pScreenProperties->layerCount);
1422 returnValue = ILM_SUCCESS;
1429 ILM_EXPORT ilmErrorTypes
1430 ilm_getNumberOfHardwareLayers(t_ilm_uint screenID,
1431 t_ilm_uint* pNumberOfHardwareLayers)
1435 if (pNumberOfHardwareLayers != NULL) {
1436 *pNumberOfHardwareLayers = 0;
1443 ILM_EXPORT ilmErrorTypes
1444 ilm_getScreenIDs(t_ilm_uint* pNumberOfIDs, t_ilm_uint** ppIDs)
1446 ilmErrorTypes returnValue = ILM_FAILED;
1447 struct ilm_control_context *ctx = sync_and_acquire_instance();
1449 if ((pNumberOfIDs != NULL) && (ppIDs != NULL)) {
1450 struct screen_context *ctx_scrn = NULL;
1451 t_ilm_uint length = wl_list_length(&ctx->wl.list_screen);
1454 *ppIDs = (t_ilm_uint*)malloc(length * sizeof **ppIDs);
1455 if (*ppIDs != NULL) {
1456 t_ilm_uint* ids = *ppIDs;
1457 wl_list_for_each(ctx_scrn, &ctx->wl.list_screen, link) {
1458 *ids = ctx_scrn->id_screen;
1461 *pNumberOfIDs = length;
1463 returnValue = ILM_SUCCESS;
1471 ILM_EXPORT ilmErrorTypes
1472 ilm_getLayerIDs(t_ilm_int* pLength, t_ilm_layer** ppArray)
1474 ilmErrorTypes returnValue = ILM_FAILED;
1475 struct ilm_control_context *ctx = sync_and_acquire_instance();
1477 if ((pLength != NULL) && (ppArray != NULL)) {
1478 struct layer_context *ctx_layer = NULL;
1479 t_ilm_uint length = wl_list_length(&ctx->wl.list_layer);
1482 *ppArray = (t_ilm_layer*)malloc(length * sizeof **ppArray);
1483 if (*ppArray != NULL) {
1484 // compositor sends layers in opposite order
1485 // write ids from back to front to turn them around
1486 t_ilm_layer* ids = *ppArray;
1487 wl_list_for_each_reverse(ctx_layer, &ctx->wl.list_layer, link)
1489 *ids = ctx_layer->id_layer;
1494 returnValue = ILM_SUCCESS;
1502 ILM_EXPORT ilmErrorTypes
1503 ilm_getLayerIDsOnScreen(t_ilm_uint screenId,
1505 t_ilm_layer** ppArray)
1507 ilmErrorTypes returnValue = ILM_FAILED;
1508 struct ilm_control_context *ctx = sync_and_acquire_instance();
1510 if ((pLength != NULL) && (ppArray != NULL)) {
1511 struct screen_context *ctx_screen = NULL;
1512 ctx_screen = get_screen_context_by_id(&ctx->wl, screenId);
1513 if (ctx_screen != NULL) {
1514 struct layer_context *ctx_layer = NULL;
1515 t_ilm_int length = wl_list_length(&ctx_screen->order.list_layer);
1519 *ppArray = (t_ilm_layer*)malloc(length * sizeof **ppArray);
1520 if (*ppArray != NULL) {
1521 // compositor sends layers in opposite order
1522 // write ids from back to front to turn them around
1523 t_ilm_layer* ids = *ppArray;
1524 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link)
1526 *ids = ctx_layer->id_layer;
1538 returnValue = ILM_SUCCESS;
1546 ILM_EXPORT ilmErrorTypes
1547 ilm_getSurfaceIDs(t_ilm_int* pLength, t_ilm_surface** ppArray)
1549 ilmErrorTypes returnValue = ILM_FAILED;
1550 struct ilm_control_context *ctx = sync_and_acquire_instance();
1552 if ((pLength != NULL) && (ppArray != NULL)) {
1553 struct surface_context *ctx_surf = NULL;
1554 t_ilm_uint length = wl_list_length(&ctx->wl.list_surface);
1557 *ppArray = (t_ilm_surface*)malloc(length * sizeof **ppArray);
1558 if (*ppArray != NULL) {
1559 t_ilm_surface* ids = *ppArray;
1560 wl_list_for_each_reverse(ctx_surf, &ctx->wl.list_surface, link) {
1561 *ids = ctx_surf->id_surface;
1566 returnValue = ILM_SUCCESS;
1574 ILM_EXPORT ilmErrorTypes
1575 ilm_getSurfaceIDsOnLayer(t_ilm_layer layer,
1577 t_ilm_surface** ppArray)
1579 struct ilm_control_context *ctx = sync_and_acquire_instance();
1580 struct layer_context *ctx_layer = NULL;
1581 struct surface_context *ctx_surf = NULL;
1582 t_ilm_uint length = 0;
1583 t_ilm_surface* ids = NULL;
1585 if ((pLength == NULL) || (ppArray == NULL)) {
1590 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1591 &ctx->wl, (uint32_t)layer);
1593 if (ctx_layer == NULL) {
1598 length = wl_list_length(&ctx_layer->order.list_surface);
1599 *ppArray = (t_ilm_surface*)malloc(length * sizeof **ppArray);
1600 if (*ppArray == NULL) {
1606 wl_list_for_each_reverse(ctx_surf, &ctx_layer->order.list_surface, order.link) {
1607 *ids = (t_ilm_surface)ctx_surf->id_surface;
1616 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid)
1618 struct layer_context *ctx_layer = calloc(1, sizeof *ctx_layer);
1619 if (ctx_layer == NULL) {
1620 fprintf(stderr, "Failed to allocate memory for layer_context\n");
1624 ctx_layer->controller = ivi_controller_layer_create(
1626 layerid, width, height);
1627 if (ctx_layer->controller == NULL) {
1628 fprintf(stderr, "Failed to create layer\n");
1632 ctx_layer->id_layer = layerid;
1633 ctx_layer->ctx = ctx;
1635 wl_list_init(&ctx_layer->link);
1636 wl_list_insert(&ctx->list_layer, &ctx_layer->link);
1637 wl_list_init(&ctx_layer->order.link);
1638 wl_list_init(&ctx_layer->order.list_surface);
1640 ivi_controller_layer_add_listener(ctx_layer->controller,
1641 &controller_layer_listener, ctx_layer);
1646 ILM_EXPORT ilmErrorTypes
1647 ilm_layerCreateWithDimension(t_ilm_layer* pLayerId,
1651 ilmErrorTypes returnValue = ILM_FAILED;
1652 struct ilm_control_context *ctx = sync_and_acquire_instance();
1653 uint32_t layerid = 0;
1654 int32_t is_inside = 0;
1657 if (pLayerId == NULL) {
1661 if (*pLayerId != INVALID_ID) {
1662 /* Return failed, if layerid is already inside list_layer */
1663 is_inside = wayland_controller_is_inside_layer_list(
1664 &ctx->wl.list_layer, *pLayerId);
1665 if (0 != is_inside) {
1666 fprintf(stderr, "layerid=%d is already used.\n", *pLayerId);
1669 layerid = *pLayerId;
1672 /* Generate ID, if layerid is INVALID_ID */
1673 layerid = gen_layer_id(ctx);
1674 *pLayerId = layerid;
1677 if (create_controller_layer(&ctx->wl, width, height, layerid) == 0)
1679 returnValue = ILM_SUCCESS;
1687 ILM_EXPORT ilmErrorTypes
1688 ilm_layerRemove(t_ilm_layer layerId)
1690 ilmErrorTypes returnValue = ILM_FAILED;
1691 struct ilm_control_context *ctx = sync_and_acquire_instance();
1692 struct layer_context *ctx_layer = NULL;
1693 struct layer_context *ctx_next = NULL;
1695 wl_list_for_each_safe(ctx_layer, ctx_next,
1696 &ctx->wl.list_layer, link) {
1697 if (ctx_layer->id_layer == layerId) {
1698 ivi_controller_layer_destroy(ctx_layer->controller, 1);
1700 wl_list_remove(&ctx_layer->link);
1703 returnValue = ILM_SUCCESS;
1712 ILM_EXPORT ilmErrorTypes
1713 ilm_layerGetType(t_ilm_layer layerId, ilmLayerType* pLayerType)
1717 return ILM_ERROR_INVALID_ARGUMENTS;
1720 struct ilm_control_context *ctx = sync_and_acquire_instance();
1722 *pLayerType = wayland_controller_is_inside_layer_list(&ctx->wl.list_layer, layerId) ?
1723 ILM_LAYERTYPE_SOFTWARE2D :
1724 ILM_LAYERTYPE_UNKNOWN;
1727 return ILM_SUCCESS; // even if non existent?
1730 ILM_EXPORT ilmErrorTypes
1731 ilm_layerSetVisibility(t_ilm_layer layerId, t_ilm_bool newVisibility)
1733 ilmErrorTypes returnValue = ILM_FAILED;
1734 struct ilm_control_context *ctx = sync_and_acquire_instance();
1735 struct layer_context *ctx_layer = NULL;
1737 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1738 &ctx->wl, (uint32_t)layerId);
1740 if (ctx_layer != NULL) {
1741 uint32_t visibility = 0;
1742 if (newVisibility == ILM_TRUE) {
1745 ivi_controller_layer_set_visibility(ctx_layer->controller,
1747 returnValue = ILM_SUCCESS;
1754 ILM_EXPORT ilmErrorTypes
1755 ilm_layerGetVisibility(t_ilm_layer layerId, t_ilm_bool *pVisibility)
1757 ilmErrorTypes returnValue = ILM_FAILED;
1758 struct ilm_control_context *ctx = sync_and_acquire_instance();
1760 if (pVisibility != NULL) {
1761 struct layer_context *ctx_layer = NULL;
1763 ctx_layer = (struct layer_context*)
1764 wayland_controller_get_layer_context(
1765 &ctx->wl, (uint32_t)layerId);
1767 if (ctx_layer != NULL) {
1768 *pVisibility = ctx_layer->prop.visibility;
1769 returnValue = ILM_SUCCESS;
1777 ILM_EXPORT ilmErrorTypes
1778 ilm_layerSetOpacity(t_ilm_layer layerId, t_ilm_float opacity)
1780 ilmErrorTypes returnValue = ILM_FAILED;
1781 struct ilm_control_context *ctx = sync_and_acquire_instance();
1782 struct layer_context *ctx_layer = NULL;
1784 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1785 &ctx->wl, (uint32_t)layerId);
1787 if (ctx_layer != NULL) {
1788 wl_fixed_t opacity_fixed = wl_fixed_from_double((double)opacity);
1789 ivi_controller_layer_set_opacity(ctx_layer->controller,
1791 returnValue = ILM_SUCCESS;
1798 ILM_EXPORT ilmErrorTypes
1799 ilm_layerGetOpacity(t_ilm_layer layerId, t_ilm_float *pOpacity)
1801 ilmErrorTypes returnValue = ILM_FAILED;
1802 struct ilm_control_context *ctx = sync_and_acquire_instance();
1804 if (pOpacity != NULL) {
1805 struct layer_context *ctx_layer = NULL;
1807 ctx_layer = (struct layer_context*)
1808 wayland_controller_get_layer_context(
1809 &ctx->wl, (uint32_t)layerId);
1811 if (ctx_layer != NULL) {
1812 *pOpacity = ctx_layer->prop.opacity;
1813 returnValue = ILM_SUCCESS;
1821 ILM_EXPORT ilmErrorTypes
1822 ilm_layerSetSourceRectangle(t_ilm_layer layerId,
1823 t_ilm_uint x, t_ilm_uint y,
1824 t_ilm_uint width, t_ilm_uint height)
1826 ilmErrorTypes returnValue = ILM_FAILED;
1827 struct ilm_control_context *ctx = sync_and_acquire_instance();
1828 struct layer_context *ctx_layer = NULL;
1830 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1831 &ctx->wl, (uint32_t)layerId);
1833 if (ctx_layer != NULL) {
1834 ivi_controller_layer_set_source_rectangle(ctx_layer->controller,
1839 returnValue = ILM_SUCCESS;
1846 ILM_EXPORT ilmErrorTypes
1847 ilm_layerSetDestinationRectangle(t_ilm_layer layerId,
1848 t_ilm_int x, t_ilm_int y,
1849 t_ilm_int width, t_ilm_int height)
1851 ilmErrorTypes returnValue = ILM_FAILED;
1852 struct ilm_control_context *ctx = sync_and_acquire_instance();
1853 struct layer_context *ctx_layer = NULL;
1855 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1856 &ctx->wl, (uint32_t)layerId);
1857 if (ctx_layer != NULL) {
1858 ivi_controller_layer_set_destination_rectangle(
1859 ctx_layer->controller,
1860 (uint32_t)x, (uint32_t)y,
1863 returnValue = ILM_SUCCESS;
1870 ILM_EXPORT ilmErrorTypes
1871 ilm_layerGetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
1873 ilmErrorTypes returnValue = ILM_FAILED;
1874 struct ilm_control_context *ctx = sync_and_acquire_instance();
1875 struct layer_context *ctx_layer = NULL;
1877 if (pDimension != NULL) {
1878 ctx_layer = (struct layer_context*)
1879 wayland_controller_get_layer_context(
1880 &ctx->wl, (uint32_t)layerId);
1881 if (ctx_layer != NULL) {
1882 *pDimension = ctx_layer->prop.destWidth;
1883 *(pDimension + 1) = ctx_layer->prop.destHeight;
1884 returnValue = ILM_SUCCESS;
1892 ILM_EXPORT ilmErrorTypes
1893 ilm_layerSetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
1895 ilmErrorTypes returnValue = ILM_FAILED;
1896 struct ilm_control_context *ctx = sync_and_acquire_instance();
1897 struct layer_context *ctx_layer = NULL;
1899 if (pDimension != NULL) {
1900 ctx_layer = (struct layer_context*)
1901 wayland_controller_get_layer_context(
1902 &ctx->wl, (uint32_t)layerId);
1903 if (ctx_layer != NULL) {
1904 ivi_controller_layer_set_destination_rectangle(
1905 ctx_layer->controller,
1906 ctx_layer->prop.destX, ctx_layer->prop.destY,
1907 (int32_t)*pDimension, (int32_t)*(pDimension + 1));
1908 returnValue = ILM_SUCCESS;
1916 ILM_EXPORT ilmErrorTypes
1917 ilm_layerGetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
1919 ilmErrorTypes returnValue = ILM_FAILED;
1920 struct ilm_control_context *ctx = sync_and_acquire_instance();
1921 struct layer_context *ctx_layer = NULL;
1923 if (pPosition != NULL) {
1924 ctx_layer = (struct layer_context*)
1925 wayland_controller_get_layer_context(
1926 &ctx->wl, (uint32_t)layerId);
1927 if (ctx_layer != NULL) {
1928 *pPosition = ctx_layer->prop.destX;
1929 *(pPosition + 1) = ctx_layer->prop.destY;
1930 returnValue = ILM_SUCCESS;
1938 ILM_EXPORT ilmErrorTypes
1939 ilm_layerSetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
1941 ilmErrorTypes returnValue = ILM_FAILED;
1942 struct ilm_control_context *ctx = sync_and_acquire_instance();
1943 struct layer_context *ctx_layer = NULL;
1945 if (pPosition != NULL) {
1946 ctx_layer = (struct layer_context*)
1947 wayland_controller_get_layer_context(
1948 &ctx->wl, (uint32_t)layerId);
1949 if (ctx_layer != NULL) {
1950 ivi_controller_layer_set_destination_rectangle(
1951 ctx_layer->controller,
1952 (int32_t)*pPosition, (int32_t)*(pPosition + 1),
1953 ctx_layer->prop.destWidth, ctx_layer->prop.destHeight);
1954 returnValue = ILM_SUCCESS;
1962 ILM_EXPORT ilmErrorTypes
1963 ilm_layerSetOrientation(t_ilm_layer layerId, ilmOrientation orientation)
1965 ilmErrorTypes returnValue = ILM_FAILED;
1966 struct ilm_control_context *ctx = sync_and_acquire_instance();
1967 struct layer_context *ctx_layer = NULL;
1968 int32_t iviorientation = 0;
1971 switch(orientation) {
1973 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
1976 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
1978 case ILM_ONEHUNDREDEIGHTY:
1979 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
1981 case ILM_TWOHUNDREDSEVENTY:
1982 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
1985 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
1989 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1990 &ctx->wl, (uint32_t)layerId);
1991 if (ctx_layer == NULL) {
1992 returnValue = ILM_FAILED;
1996 ivi_controller_layer_set_orientation(ctx_layer->controller,
1999 returnValue = ILM_SUCCESS;
2006 ILM_EXPORT ilmErrorTypes
2007 ilm_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrientation)
2009 ilmErrorTypes returnValue = ILM_FAILED;
2010 struct ilm_control_context *ctx = sync_and_acquire_instance();
2011 struct layer_context *ctx_layer = NULL;
2013 if (pOrientation != NULL) {
2014 ctx_layer = (struct layer_context*)
2015 wayland_controller_get_layer_context(
2016 &ctx->wl, (uint32_t)layerId);
2017 if (ctx_layer != NULL) {
2018 *pOrientation = ctx_layer->prop.orientation;
2019 returnValue = ILM_SUCCESS;
2027 ILM_EXPORT ilmErrorTypes
2028 ilm_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
2036 ILM_EXPORT ilmErrorTypes
2037 ilm_layerSetRenderOrder(t_ilm_layer layerId,
2038 t_ilm_surface *pSurfaceId,
2041 ilmErrorTypes returnValue = ILM_FAILED;
2042 struct ilm_control_context *ctx = sync_and_acquire_instance();
2043 struct layer_context *ctx_layer = NULL;
2045 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2046 &ctx->wl, (uint32_t)layerId);
2050 struct wl_array ids;
2051 wl_array_init(&ids);
2052 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2054 for (i = 0; i < number; i++) pids[i] = (uint32_t)pSurfaceId[i];
2055 ivi_controller_layer_set_render_order(ctx_layer->controller, &ids);
2056 wl_array_release(&ids);
2057 returnValue = ILM_SUCCESS;
2064 ILM_EXPORT ilmErrorTypes
2065 ilm_layerGetCapabilities(t_ilm_layer layerId,
2066 t_ilm_layercapabilities *pCapabilities)
2069 (void)pCapabilities;
2074 ILM_EXPORT ilmErrorTypes
2075 ilm_layerTypeGetCapabilities(ilmLayerType layerType,
2076 t_ilm_layercapabilities *pCapabilities)
2079 (void)pCapabilities;
2084 ILM_EXPORT ilmErrorTypes
2085 ilm_surfaceSetVisibility(t_ilm_surface surfaceId, t_ilm_bool newVisibility)
2087 ilmErrorTypes returnValue = ILM_FAILED;
2088 struct ilm_control_context *ctx = sync_and_acquire_instance();
2089 struct surface_context *ctx_surf = NULL;
2090 uint32_t visibility = 0;
2092 if (newVisibility == ILM_TRUE) {
2095 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2097 ivi_controller_surface_set_visibility(ctx_surf->controller,
2099 returnValue = ILM_SUCCESS;
2106 ILM_EXPORT ilmErrorTypes
2107 ilm_surfaceSetOpacity(t_ilm_surface surfaceId, t_ilm_float opacity)
2109 ilmErrorTypes returnValue = ILM_FAILED;
2110 struct ilm_control_context *ctx = sync_and_acquire_instance();
2111 struct surface_context *ctx_surf = NULL;
2112 wl_fixed_t opacity_fixed = 0;
2114 opacity_fixed = wl_fixed_from_double((double)opacity);
2115 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2117 ivi_controller_surface_set_opacity(ctx_surf->controller,
2119 returnValue = ILM_SUCCESS;
2126 ILM_EXPORT ilmErrorTypes
2127 ilm_surfaceGetOpacity(t_ilm_surface surfaceId, t_ilm_float *pOpacity)
2129 ilmErrorTypes returnValue = ILM_FAILED;
2130 struct ilm_control_context *ctx = sync_and_acquire_instance();
2132 if (pOpacity != NULL) {
2133 struct surface_context *ctx_surf = NULL;
2134 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2136 *pOpacity = ctx_surf->prop.opacity;
2137 returnValue = ILM_SUCCESS;
2145 ILM_EXPORT ilmErrorTypes
2146 ilm_SetKeyboardFocusOn(t_ilm_surface surfaceId)
2148 ilmErrorTypes returnValue = ILM_FAILED;
2149 struct ilm_control_context *ctx = sync_and_acquire_instance();
2150 struct surface_context *ctx_surf =
2151 get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2153 if (ctx_surf != NULL
2154 && ctx_surf->prop.inputDevicesAcceptance & ILM_INPUT_DEVICE_KEYBOARD)
2156 ivi_controller_surface_set_input_focus(ctx_surf->controller,
2157 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD, 1);
2158 returnValue = ILM_SUCCESS;
2164 ILM_EXPORT ilmErrorTypes
2165 ilm_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
2167 struct ilm_control_context *ctx = sync_and_acquire_instance();
2168 struct surface_context *ctx_surf = NULL;
2170 wl_list_for_each(ctx_surf, &ctx->wl.list_surface, link) {
2171 if (ctx_surf->prop.hasKeyboardFocus) {
2172 *pSurfaceId = ctx_surf->id_surface;
2181 ILM_EXPORT ilmErrorTypes
2182 ilm_SetKeyboardMultiFocus(t_ilm_surface *pSurfaceIds, t_ilm_int number)
2184 struct ilm_control_context *ctx = sync_and_acquire_instance();
2185 struct surface_context *ctx_surf;
2186 unsigned int i, send_elements = 0;
2187 struct wl_array send_array;
2188 ilmErrorTypes retval = ILM_FAILED;
2191 wl_array_init(&send_array);
2192 wl_array_add(&send_array, sizeof(uint32_t) * number);
2194 data = send_array.data;
2195 for (i = 0; i < number; i++) {
2196 ctx_surf = get_surface_context(&ctx->wl, (uint32_t) pSurfaceIds[i]);
2197 if (ctx_surf->prop.inputDevicesAcceptance & ILM_INPUT_DEVICE_KEYBOARD) {
2198 data[send_elements] = pSurfaceIds[i];
2203 if (send_elements > 0) {
2204 ivi_controller_set_keyboard_focus(ctx->wl.controller, &send_array);
2205 retval = ILM_SUCCESS;
2208 wl_array_release(&send_array);
2213 ILM_EXPORT ilmErrorTypes
2214 ilm_GetKeyboardMultiFocusSurfaceIds(t_ilm_surface *pSurfaceIds, t_ilm_int size,
2217 struct ilm_control_context *ctx = sync_and_acquire_instance();
2218 struct surface_context *ctx_surf;
2221 wl_list_for_each(ctx_surf, &ctx->wl.list_surface, link) {
2222 if (ctx_surf->prop.hasKeyboardFocus) {
2223 if (*pCount >= size) {
2224 fprintf(stderr, "not enough space to store surface IDs\n");
2227 pSurfaceIds[*pCount] = ctx_surf->id_surface;
2237 ILM_EXPORT ilmErrorTypes
2238 ilm_surfaceSetDestinationRectangle(t_ilm_surface surfaceId,
2239 t_ilm_int x, t_ilm_int y,
2240 t_ilm_int width, t_ilm_int height)
2242 ilmErrorTypes returnValue = ILM_FAILED;
2243 struct ilm_control_context *ctx = sync_and_acquire_instance();
2244 struct surface_context *ctx_surf = NULL;
2246 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2248 ivi_controller_surface_set_destination_rectangle(
2249 ctx_surf->controller,
2250 x, y, width, height);
2251 returnValue = ILM_SUCCESS;
2258 ILM_EXPORT ilmErrorTypes
2259 ilm_surfaceSetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
2261 ilmErrorTypes returnValue = ILM_FAILED;
2262 struct ilm_control_context *ctx = sync_and_acquire_instance();
2264 if (pDimension != NULL) {
2265 struct surface_context *ctx_surf = NULL;
2266 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2268 uint32_t width = *pDimension;
2269 uint32_t height = *(pDimension + 1);
2270 ivi_controller_surface_set_destination_rectangle(
2271 ctx_surf->controller,
2272 ctx_surf->prop.destX, ctx_surf->prop.destY, width, height);
2273 returnValue = ILM_SUCCESS;
2281 ILM_EXPORT ilmErrorTypes
2282 ilm_surfaceGetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2284 ilmErrorTypes returnValue = ILM_FAILED;
2285 struct ilm_control_context *ctx = sync_and_acquire_instance();
2287 if (pPosition != NULL) {
2288 struct surface_context *ctx_surf = NULL;
2289 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2291 *pPosition = ctx_surf->prop.destX;
2292 *(pPosition + 1) = ctx_surf->prop.destY;
2293 returnValue = ILM_SUCCESS;
2301 ILM_EXPORT ilmErrorTypes
2302 ilm_surfaceSetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2304 ilmErrorTypes returnValue = ILM_FAILED;
2305 struct ilm_control_context *ctx = sync_and_acquire_instance();
2307 if (pPosition != NULL) {
2308 struct surface_context *ctx_surf = NULL;
2309 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2311 int32_t destX = (int32_t)*pPosition;
2312 int32_t destY = (int32_t)*(pPosition + 1);
2313 ivi_controller_surface_set_destination_rectangle(
2314 ctx_surf->controller, destX, destY,
2315 ctx_surf->prop.destWidth, ctx_surf->prop.destHeight);
2316 returnValue = ILM_SUCCESS;
2324 ILM_EXPORT ilmErrorTypes
2325 ilm_surfaceSetOrientation(t_ilm_surface surfaceId,
2326 ilmOrientation orientation)
2328 ilmErrorTypes returnValue = ILM_FAILED;
2329 struct ilm_control_context *ctx = sync_and_acquire_instance();
2330 struct surface_context *ctx_surf = NULL;
2331 int32_t iviorientation = 0;
2334 switch(orientation) {
2336 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2339 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2341 case ILM_ONEHUNDREDEIGHTY:
2342 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2344 case ILM_TWOHUNDREDSEVENTY:
2345 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2348 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2352 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2353 if (ctx_surf == NULL) {
2354 returnValue = ILM_FAILED;
2358 ivi_controller_surface_set_orientation(ctx_surf->controller,
2361 returnValue = ILM_SUCCESS;
2368 ILM_EXPORT ilmErrorTypes
2369 ilm_surfaceGetOrientation(t_ilm_surface surfaceId,
2370 ilmOrientation *pOrientation)
2372 ilmErrorTypes returnValue = ILM_FAILED;
2373 struct ilm_control_context *ctx = sync_and_acquire_instance();
2375 if (pOrientation != NULL) {
2376 struct surface_context *ctx_surf = NULL;
2377 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2379 *pOrientation = ctx_surf->prop.orientation;
2380 returnValue = ILM_SUCCESS;
2388 ILM_EXPORT ilmErrorTypes
2389 ilm_surfaceGetPixelformat(t_ilm_layer surfaceId,
2390 ilmPixelFormat *pPixelformat)
2392 ilmErrorTypes returnValue = ILM_FAILED;
2393 struct ilm_control_context *ctx = sync_and_acquire_instance();
2395 if (pPixelformat != NULL) {
2396 struct surface_context *ctx_surf = NULL;
2397 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2399 *pPixelformat = ctx_surf->prop.pixelformat;
2400 returnValue = ILM_SUCCESS;
2408 ILM_EXPORT ilmErrorTypes
2409 ilm_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
2417 ILM_EXPORT ilmErrorTypes
2418 ilm_displaySetRenderOrder(t_ilm_display display,
2419 t_ilm_layer *pLayerId, const t_ilm_uint number)
2421 ilmErrorTypes returnValue = ILM_FAILED;
2422 struct ilm_control_context *ctx = sync_and_acquire_instance();
2423 struct screen_context *ctx_scrn = NULL;
2425 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)display);
2426 if (ctx_scrn != NULL) {
2427 struct wl_array ids;
2428 wl_array_init(&ids);
2429 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2431 for (i = 0; i < number; i++) pids[i] = (uint32_t)pLayerId[i];
2432 ivi_controller_screen_set_render_order(ctx_scrn->controller, &ids);
2433 wl_array_release(&ids);
2434 returnValue = ILM_SUCCESS;
2441 ILM_EXPORT ilmErrorTypes
2442 ilm_takeScreenshot(t_ilm_uint screen, t_ilm_const_string filename)
2444 ilmErrorTypes returnValue = ILM_FAILED;
2445 struct ilm_control_context *ctx = sync_and_acquire_instance();
2446 struct screen_context *ctx_scrn = NULL;
2448 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)screen);
2449 if (ctx_scrn != NULL) {
2450 ivi_controller_screen_screenshot(ctx_scrn->controller,
2452 wl_display_flush(ctx->wl.display);
2453 returnValue = ILM_SUCCESS;
2460 ILM_EXPORT ilmErrorTypes
2461 ilm_takeLayerScreenshot(t_ilm_const_string filename, t_ilm_layer layerid)
2463 ilmErrorTypes returnValue = ILM_FAILED;
2464 struct ilm_control_context *ctx = sync_and_acquire_instance();
2465 struct layer_context *ctx_layer = NULL;
2467 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2468 &ctx->wl, (uint32_t)layerid);
2469 if (ctx_layer != NULL) {
2470 ivi_controller_layer_screenshot(ctx_layer->controller,
2472 wl_display_flush(ctx->wl.display);
2473 returnValue = ILM_SUCCESS;
2480 ILM_EXPORT ilmErrorTypes
2481 ilm_takeSurfaceScreenshot(t_ilm_const_string filename,
2482 t_ilm_surface surfaceid)
2484 ilmErrorTypes returnValue = ILM_FAILED;
2485 struct ilm_control_context *ctx = sync_and_acquire_instance();
2486 struct surface_context *ctx_surf = NULL;
2488 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceid);
2490 ivi_controller_surface_screenshot(ctx_surf->controller,
2492 wl_display_flush(ctx->wl.display);
2493 returnValue = ILM_SUCCESS;
2500 ILM_EXPORT ilmErrorTypes
2501 ilm_SetOptimizationMode(ilmOptimization id, ilmOptimizationMode mode)
2509 ILM_EXPORT ilmErrorTypes
2510 ilm_GetOptimizationMode(ilmOptimization id, ilmOptimizationMode* pMode)
2518 ILM_EXPORT ilmErrorTypes
2519 ilm_layerAddNotification(t_ilm_layer layer,
2520 layerNotificationFunc callback)
2522 ilmErrorTypes returnValue = ILM_FAILED;
2523 struct ilm_control_context *ctx = sync_and_acquire_instance();
2524 struct layer_context *ctx_layer = NULL;
2526 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2527 &ctx->wl, (uint32_t)layer);
2528 if (ctx_layer == NULL) {
2529 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2531 ctx_layer->notification = callback;
2533 returnValue = ILM_SUCCESS;
2540 ILM_EXPORT ilmErrorTypes
2541 ilm_layerRemoveNotification(t_ilm_layer layer)
2543 return ilm_layerAddNotification(layer, NULL);
2546 ILM_EXPORT ilmErrorTypes
2547 ilm_surfaceAddNotification(t_ilm_surface surface,
2548 surfaceNotificationFunc callback)
2550 ilmErrorTypes returnValue = ILM_FAILED;
2551 struct ilm_control_context *ctx = sync_and_acquire_instance();
2552 struct surface_context *ctx_surf = NULL;
2554 ctx_surf = (struct surface_context*)get_surface_context(
2555 &ctx->wl, (uint32_t)surface);
2556 if (ctx_surf == NULL) {
2557 if (callback != NULL) {
2558 callback((uint32_t)surface, NULL, ILM_NOTIFICATION_CONTENT_REMOVED);
2559 controller_listener_surface(ctx, ctx->wl.controller, (uint32_t)surface, 0, NULL);
2560 ctx_surf = (struct surface_context*)get_surface_context(
2561 &ctx->wl, (uint32_t)surface);
2562 ctx_surf->is_surface_creation_noticed = false;
2566 if (ctx_surf == NULL) {
2567 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2570 ctx_surf->notification = callback;
2572 returnValue = ILM_SUCCESS;
2579 ILM_EXPORT ilmErrorTypes
2580 ilm_surfaceRemoveNotification(t_ilm_surface surface)
2582 return ilm_surfaceAddNotification(surface, NULL);
2585 ILM_EXPORT ilmErrorTypes
2586 ilm_getNativeHandle(t_ilm_uint pid, t_ilm_int *n_handle,
2587 t_ilm_nativehandle **p_handles)
2589 struct ilm_control_context *ctx = sync_and_acquire_instance();
2590 struct nativehandle_context *p_nh_ctx = NULL;
2595 wl_list_for_each(p_nh_ctx, &ctx->list_nativehandle, link)
2597 if (p_nh_ctx->pid == pid)
2601 (t_ilm_nativehandle*)malloc(sizeof(t_ilm_nativehandle));
2602 (*p_handles)[0] = p_nh_ctx->nativehandle;
2608 return (*n_handle > 0) ? ILM_SUCCESS : ILM_FAILED;
2611 ILM_EXPORT ilmErrorTypes
2612 ilm_getPropertiesOfSurface(t_ilm_uint surfaceID,
2613 struct ilmSurfaceProperties* pSurfaceProperties)
2615 ilmErrorTypes returnValue = ILM_FAILED;
2616 struct ilm_control_context *ctx = sync_and_acquire_instance();
2618 if (pSurfaceProperties != NULL) {
2619 struct surface_context *ctx_surf = NULL;
2621 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceID);
2622 if (ctx_surf != NULL) {
2623 // request statistics for surface
2624 ivi_controller_surface_send_stats(ctx_surf->controller);
2626 int ret = display_roundtrip_queue(ctx->wl.display, ctx->wl.queue);
2628 // If we got an error here, there is really no sense
2629 // in returning the properties as something is fundamentally
2633 *pSurfaceProperties = ctx_surf->prop;
2634 returnValue = ILM_SUCCESS;
2643 ILM_EXPORT ilmErrorTypes
2644 ilm_layerAddSurface(t_ilm_layer layerId,
2645 t_ilm_surface surfaceId)
2647 ilmErrorTypes returnValue = ILM_FAILED;
2648 struct ilm_control_context *ctx = sync_and_acquire_instance();
2649 struct layer_context *ctx_layer = NULL;
2650 struct surface_context *ctx_surf = NULL;
2652 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2653 &ctx->wl, (uint32_t)layerId);
2654 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2655 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2656 ivi_controller_layer_add_surface(ctx_layer->controller,
2657 ctx_surf->controller);
2658 returnValue = ILM_SUCCESS;
2665 ILM_EXPORT ilmErrorTypes
2666 ilm_layerRemoveSurface(t_ilm_layer layerId,
2667 t_ilm_surface surfaceId)
2669 ilmErrorTypes returnValue = ILM_FAILED;
2670 struct ilm_control_context *ctx = sync_and_acquire_instance();
2671 struct layer_context *ctx_layer = NULL;
2672 struct surface_context *ctx_surf = NULL;
2674 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2675 &ctx->wl, (uint32_t)layerId);
2676 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2677 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2678 ivi_controller_layer_remove_surface(ctx_layer->controller,
2679 ctx_surf->controller);
2680 returnValue = ILM_SUCCESS;
2687 ILM_EXPORT ilmErrorTypes
2688 ilm_surfaceGetDimension(t_ilm_surface surfaceId,
2689 t_ilm_uint *pDimension)
2691 ilmErrorTypes returnValue = ILM_FAILED;
2692 struct ilm_control_context *ctx = sync_and_acquire_instance();
2694 if (pDimension != NULL) {
2695 struct surface_context *ctx_surf = NULL;
2697 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2698 if (ctx_surf != NULL) {
2699 *pDimension = (t_ilm_uint)ctx_surf->prop.destWidth;
2700 *(pDimension + 1) = (t_ilm_uint)ctx_surf->prop.destHeight;
2701 returnValue = ILM_SUCCESS;
2709 ILM_EXPORT ilmErrorTypes
2710 ilm_surfaceGetVisibility(t_ilm_surface surfaceId,
2711 t_ilm_bool *pVisibility)
2713 ilmErrorTypes returnValue = ILM_FAILED;
2714 struct ilm_control_context *ctx = sync_and_acquire_instance();
2715 struct surface_context *ctx_surf = NULL;
2717 if (pVisibility != NULL) {
2718 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2719 if (ctx_surf != NULL) {
2720 *pVisibility = (t_ilm_bool)ctx_surf->prop.visibility;
2721 returnValue = ILM_SUCCESS;
2729 ILM_EXPORT ilmErrorTypes
2730 ilm_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
2731 t_ilm_int x, t_ilm_int y,
2732 t_ilm_int width, t_ilm_int height)
2734 ilmErrorTypes returnValue = ILM_FAILED;
2735 struct ilm_control_context *ctx = sync_and_acquire_instance();
2736 struct surface_context *ctx_surf = NULL;
2738 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2739 if (ctx_surf != NULL) {
2740 if (ctx_surf->controller != NULL) {
2741 ivi_controller_surface_set_source_rectangle(
2742 ctx_surf->controller,
2743 x, y, width, height);
2744 returnValue = ILM_SUCCESS;
2752 ILM_EXPORT ilmErrorTypes
2753 ilm_commitChanges(void)
2755 ilmErrorTypes returnValue = ILM_FAILED;
2756 struct ilm_control_context *ctx = sync_and_acquire_instance();
2758 if (ctx->wl.controller != NULL) {
2759 ivi_controller_commit_changes(ctx->wl.controller);
2761 if (display_roundtrip_queue(ctx->wl.display, ctx->wl.queue) != -1)
2763 returnValue = ILM_SUCCESS;