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 ****************************************************************************/
29 #include "ilm_common.h"
30 #include "ilm_control_platform.h"
31 #include "wayland-util.h"
32 #include "ivi-controller-client-protocol.h"
34 static ilmErrorTypes wayland_getPropertiesOfLayer(t_ilm_uint layerID,
35 struct ilmLayerProperties* pLayerProperties);
36 static ilmErrorTypes wayland_getPropertiesOfScreen(t_ilm_display screenID,
37 struct ilmScreenProperties* pScreenProperties);
38 static ilmErrorTypes wayland_getNumberOfHardwareLayers(t_ilm_uint screenID,
39 t_ilm_uint* pNumberOfHardwareLayers);
40 static ilmErrorTypes wayland_getScreenIDs(t_ilm_uint* pNumberOfIDs,
42 static ilmErrorTypes wayland_getLayerIDs(t_ilm_int* pLength,
43 t_ilm_layer** ppArray);
44 static ilmErrorTypes wayland_getLayerIDsOnScreen(t_ilm_uint screenId,
45 t_ilm_int* pLength, t_ilm_layer** ppArray);
46 static ilmErrorTypes wayland_getSurfaceIDs(t_ilm_int* pLength,
47 t_ilm_surface** ppArray);
48 static ilmErrorTypes wayland_getSurfaceIDsOnLayer(t_ilm_layer layer,
49 t_ilm_int* pLength, t_ilm_surface** ppArray);
50 static ilmErrorTypes wayland_layerCreateWithDimension(t_ilm_layer* pLayerId,
51 t_ilm_uint width, t_ilm_uint height);
52 static ilmErrorTypes wayland_layerRemove(t_ilm_layer layerId);
53 static ilmErrorTypes wayland_layerGetType(t_ilm_layer layerId,
54 ilmLayerType* pLayerType);
55 static ilmErrorTypes wayland_layerSetVisibility(t_ilm_layer layerId,
56 t_ilm_bool newVisibility);
57 static ilmErrorTypes wayland_layerGetVisibility(t_ilm_layer layerId,
58 t_ilm_bool *pVisibility);
59 static ilmErrorTypes wayland_layerSetOpacity(t_ilm_layer layerId,
61 static ilmErrorTypes wayland_layerGetOpacity(t_ilm_layer layerId,
62 t_ilm_float *pOpacity);
63 static ilmErrorTypes wayland_layerSetSourceRectangle(t_ilm_layer layerId,
64 t_ilm_uint x, t_ilm_uint y,
65 t_ilm_uint width, t_ilm_uint height);
66 static ilmErrorTypes wayland_layerSetDestinationRectangle(t_ilm_layer layerId,
67 t_ilm_int x, t_ilm_int y,
68 t_ilm_int width, t_ilm_int height);
69 static ilmErrorTypes wayland_layerGetDimension(t_ilm_layer layerId,
70 t_ilm_uint *pDimension);
71 static ilmErrorTypes wayland_layerSetDimension(t_ilm_layer layerId,
72 t_ilm_uint *pDimension);
73 static ilmErrorTypes wayland_layerGetPosition(t_ilm_layer layerId,
74 t_ilm_uint *pPosition);
75 static ilmErrorTypes wayland_layerSetPosition(t_ilm_layer layerId,
76 t_ilm_uint *pPosition);
77 static ilmErrorTypes wayland_layerSetOrientation(t_ilm_layer layerId,
78 ilmOrientation orientation);
79 static ilmErrorTypes wayland_layerGetOrientation(t_ilm_layer layerId,
80 ilmOrientation *pOrientation);
81 static ilmErrorTypes wayland_layerSetChromaKey(t_ilm_layer layerId,
83 static ilmErrorTypes wayland_layerSetRenderOrder(t_ilm_layer layerId,
84 t_ilm_layer *pSurfaceId,
86 static ilmErrorTypes wayland_layerGetCapabilities(t_ilm_layer layerId,
87 t_ilm_layercapabilities *pCapabilities);
88 static ilmErrorTypes wayland_layerTypeGetCapabilities(ilmLayerType layerType,
89 t_ilm_layercapabilities *pCapabilities);
90 static ilmErrorTypes wayland_surfaceSetVisibility(t_ilm_surface surfaceId,
91 t_ilm_bool newVisibility);
92 static ilmErrorTypes wayland_surfaceSetOpacity(t_ilm_surface surfaceId,
94 static ilmErrorTypes wayland_surfaceGetOpacity(t_ilm_surface surfaceId,
95 t_ilm_float *pOpacity);
96 static ilmErrorTypes wayland_SetKeyboardFocusOn(t_ilm_surface surfaceId);
97 static ilmErrorTypes wayland_GetKeyboardFocusSurfaceId(
98 t_ilm_surface* pSurfaceId);
99 static ilmErrorTypes wayland_surfaceSetDestinationRectangle(
100 t_ilm_surface surfaceId,
101 t_ilm_int x, t_ilm_int y,
102 t_ilm_int width, t_ilm_int height);
103 static ilmErrorTypes wayland_surfaceSetDimension(t_ilm_surface surfaceId,
104 t_ilm_uint *pDimension);
105 static ilmErrorTypes wayland_surfaceGetPosition(t_ilm_surface surfaceId,
106 t_ilm_uint *pPosition);
107 static ilmErrorTypes wayland_surfaceSetPosition(t_ilm_surface surfaceId,
108 t_ilm_uint *pPosition);
109 static ilmErrorTypes wayland_surfaceSetOrientation(t_ilm_surface surfaceId,
110 ilmOrientation orientation);
111 static ilmErrorTypes wayland_surfaceGetOrientation(t_ilm_surface surfaceId,
112 ilmOrientation *pOrientation);
113 static ilmErrorTypes wayland_surfaceGetPixelformat(t_ilm_layer surfaceId,
114 ilmPixelFormat *pPixelformat);
115 static ilmErrorTypes wayland_surfaceSetChromaKey(t_ilm_surface surfaceId,
117 static ilmErrorTypes wayland_displaySetRenderOrder(t_ilm_display display,
118 t_ilm_layer *pLayerId, const t_ilm_uint number);
119 static ilmErrorTypes wayland_takeScreenshot(t_ilm_uint screen,
120 t_ilm_const_string filename);
121 static ilmErrorTypes wayland_takeLayerScreenshot(t_ilm_const_string filename,
122 t_ilm_layer layerid);
123 static ilmErrorTypes wayland_takeSurfaceScreenshot(t_ilm_const_string filename,
124 t_ilm_surface surfaceid);
125 static ilmErrorTypes wayland_SetOptimizationMode(ilmOptimization id,
126 ilmOptimizationMode mode);
127 static ilmErrorTypes wayland_GetOptimizationMode(ilmOptimization id,
128 ilmOptimizationMode* pMode);
129 static ilmErrorTypes wayland_layerAddNotification(t_ilm_layer layer,
130 layerNotificationFunc callback);
131 static ilmErrorTypes wayland_layerRemoveNotification(t_ilm_layer layer);
132 static ilmErrorTypes wayland_surfaceAddNotification(t_ilm_surface surface,
133 surfaceNotificationFunc callback);
134 static ilmErrorTypes wayland_surfaceRemoveNotification(t_ilm_surface surface);
135 static ilmErrorTypes wayland_init(t_ilm_nativedisplay nativedisplay);
136 static void wayland_destroy(void);
137 static ilmErrorTypes wayland_getNativeHandle(t_ilm_uint pid,
139 t_ilm_nativehandle **p_handles);
140 static ilmErrorTypes wayland_getPropertiesOfSurface(t_ilm_uint surfaceID,
141 struct ilmSurfaceProperties* pSurfaceProperties);
142 static ilmErrorTypes wayland_layerAddSurface(t_ilm_layer layerId,
143 t_ilm_surface surfaceId);
144 static ilmErrorTypes wayland_layerRemoveSurface(t_ilm_layer layerId,
145 t_ilm_surface surfaceId);
146 static ilmErrorTypes wayland_surfaceGetDimension(t_ilm_surface surfaceId,
147 t_ilm_uint *pDimension);
148 static ilmErrorTypes wayland_surfaceGetVisibility(t_ilm_surface surfaceId,
149 t_ilm_bool *pVisibility);
150 static ilmErrorTypes wayland_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
151 t_ilm_int x, t_ilm_int y,
152 t_ilm_int width, t_ilm_int height);
153 static ilmErrorTypes wayland_commitChanges(void);
155 void init_ilmControlPlatformTable(void)
157 gIlmControlPlatformFunc.getPropertiesOfLayer =
158 wayland_getPropertiesOfLayer;
159 gIlmControlPlatformFunc.getPropertiesOfScreen =
160 wayland_getPropertiesOfScreen;
161 gIlmControlPlatformFunc.getNumberOfHardwareLayers =
162 wayland_getNumberOfHardwareLayers;
163 gIlmControlPlatformFunc.getScreenIDs =
164 wayland_getScreenIDs;
165 gIlmControlPlatformFunc.getLayerIDs =
167 gIlmControlPlatformFunc.getLayerIDsOnScreen =
168 wayland_getLayerIDsOnScreen;
169 gIlmControlPlatformFunc.getSurfaceIDs =
170 wayland_getSurfaceIDs;
171 gIlmControlPlatformFunc.getSurfaceIDsOnLayer =
172 wayland_getSurfaceIDsOnLayer;
173 gIlmControlPlatformFunc.layerCreateWithDimension =
174 wayland_layerCreateWithDimension;
175 gIlmControlPlatformFunc.layerRemove =
177 gIlmControlPlatformFunc.layerGetType =
178 wayland_layerGetType;
179 gIlmControlPlatformFunc.layerSetVisibility =
180 wayland_layerSetVisibility;
181 gIlmControlPlatformFunc.layerGetVisibility =
182 wayland_layerGetVisibility;
183 gIlmControlPlatformFunc.layerSetOpacity =
184 wayland_layerSetOpacity;
185 gIlmControlPlatformFunc.layerGetOpacity =
186 wayland_layerGetOpacity;
187 gIlmControlPlatformFunc.layerSetSourceRectangle =
188 wayland_layerSetSourceRectangle;
189 gIlmControlPlatformFunc.layerSetDestinationRectangle =
190 wayland_layerSetDestinationRectangle;
191 gIlmControlPlatformFunc.layerGetDimension =
192 wayland_layerGetDimension;
193 gIlmControlPlatformFunc.layerSetDimension =
194 wayland_layerSetDimension;
195 gIlmControlPlatformFunc.layerGetPosition =
196 wayland_layerGetPosition;
197 gIlmControlPlatformFunc.layerSetPosition =
198 wayland_layerSetPosition;
199 gIlmControlPlatformFunc.layerSetOrientation =
200 wayland_layerSetOrientation;
201 gIlmControlPlatformFunc.layerGetOrientation =
202 wayland_layerGetOrientation;
203 gIlmControlPlatformFunc.layerSetChromaKey =
204 wayland_layerSetChromaKey;
205 gIlmControlPlatformFunc.layerSetRenderOrder =
206 wayland_layerSetRenderOrder;
207 gIlmControlPlatformFunc.layerGetCapabilities =
208 wayland_layerGetCapabilities;
209 gIlmControlPlatformFunc.layerTypeGetCapabilities =
210 wayland_layerTypeGetCapabilities;
211 gIlmControlPlatformFunc.surfaceSetVisibility =
212 wayland_surfaceSetVisibility;
213 gIlmControlPlatformFunc.surfaceSetOpacity =
214 wayland_surfaceSetOpacity;
215 gIlmControlPlatformFunc.surfaceGetOpacity =
216 wayland_surfaceGetOpacity;
217 gIlmControlPlatformFunc.SetKeyboardFocusOn =
218 wayland_SetKeyboardFocusOn;
219 gIlmControlPlatformFunc.GetKeyboardFocusSurfaceId =
220 wayland_GetKeyboardFocusSurfaceId;
221 gIlmControlPlatformFunc.surfaceSetDestinationRectangle =
222 wayland_surfaceSetDestinationRectangle;
223 gIlmControlPlatformFunc.surfaceSetDimension =
224 wayland_surfaceSetDimension;
225 gIlmControlPlatformFunc.surfaceGetPosition =
226 wayland_surfaceGetPosition;
227 gIlmControlPlatformFunc.surfaceSetPosition =
228 wayland_surfaceSetPosition;
229 gIlmControlPlatformFunc.surfaceSetOrientation =
230 wayland_surfaceSetOrientation;
231 gIlmControlPlatformFunc.surfaceGetOrientation =
232 wayland_surfaceGetOrientation;
233 gIlmControlPlatformFunc.surfaceGetPixelformat =
234 wayland_surfaceGetPixelformat;
235 gIlmControlPlatformFunc.surfaceSetChromaKey =
236 wayland_surfaceSetChromaKey;
237 gIlmControlPlatformFunc.displaySetRenderOrder =
238 wayland_displaySetRenderOrder;
239 gIlmControlPlatformFunc.takeScreenshot =
240 wayland_takeScreenshot;
241 gIlmControlPlatformFunc.takeLayerScreenshot =
242 wayland_takeLayerScreenshot;
243 gIlmControlPlatformFunc.takeSurfaceScreenshot =
244 wayland_takeSurfaceScreenshot;
245 gIlmControlPlatformFunc.SetOptimizationMode =
246 wayland_SetOptimizationMode;
247 gIlmControlPlatformFunc.GetOptimizationMode =
248 wayland_GetOptimizationMode;
249 gIlmControlPlatformFunc.layerAddNotification =
250 wayland_layerAddNotification;
251 gIlmControlPlatformFunc.layerRemoveNotification =
252 wayland_layerRemoveNotification;
253 gIlmControlPlatformFunc.surfaceAddNotification =
254 wayland_surfaceAddNotification;
255 gIlmControlPlatformFunc.surfaceRemoveNotification =
256 wayland_surfaceRemoveNotification;
257 gIlmControlPlatformFunc.init =
259 gIlmControlPlatformFunc.destroy =
261 gIlmControlPlatformFunc.getNativeHandle =
262 wayland_getNativeHandle;
263 gIlmControlPlatformFunc.getPropertiesOfSurface =
264 wayland_getPropertiesOfSurface;
265 gIlmControlPlatformFunc.layerAddSurface =
266 wayland_layerAddSurface;
267 gIlmControlPlatformFunc.layerRemoveSurface =
268 wayland_layerRemoveSurface;
269 gIlmControlPlatformFunc.surfaceGetDimension =
270 wayland_surfaceGetDimension;
271 gIlmControlPlatformFunc.surfaceGetVisibility =
272 wayland_surfaceGetVisibility;
273 gIlmControlPlatformFunc.surfaceSetSourceRectangle =
274 wayland_surfaceSetSourceRectangle;
275 gIlmControlPlatformFunc.commitChanges =
276 wayland_commitChanges;
279 struct surface_context {
282 struct ivi_surface *surface;
283 struct ivi_controller_surface *controller;
285 t_ilm_uint id_surface;
286 struct ilmSurfaceProperties prop;
287 surfaceNotificationFunc notification;
293 struct wayland_context *ctx;
296 struct layer_context {
299 struct ivi_controller_layer *controller;
302 struct ilmLayerProperties prop;
303 layerNotificationFunc notification;
306 struct wl_list list_surface;
310 struct wayland_context *ctx;
313 struct screen_context {
316 struct wl_output *output;
317 struct ivi_controller_screen *controller;
318 t_ilm_uint id_from_server;
319 t_ilm_uint id_screen;
321 struct ilmScreenProperties prop;
324 struct wl_list list_layer;
327 struct ilm_control_context *ctx;
330 struct nativehandle_context {
332 uint32_t nativehandle;
336 struct wayland_context {
337 struct wl_display *display;
338 struct wl_registry *registry;
339 struct wl_event_queue *queue;
340 struct wl_compositor *compositor;
341 struct ivi_controller *controller;
344 struct wl_list list_surface;
345 struct wl_list list_layer;
346 struct wl_list list_screen;
349 struct ilm_control_context {
350 struct wayland_context wl;
353 uint32_t internal_id_layer;
355 struct wl_list list_nativehandle;
358 pthread_mutex_t mutex;
359 uint32_t internal_id_surface;
362 static void roundtrip_done(void *data, struct wl_callback *callback,
371 static struct wl_callback_listener roundtrip_listener = {roundtrip_done};
373 int display_roundtrip_queue(struct wl_display *display,
374 struct wl_event_queue *queue)
378 struct wl_callback *callback = wl_display_sync(display);
379 wl_proxy_set_queue((void *)callback, queue);
380 wl_callback_add_listener(callback, &roundtrip_listener, &done);
382 while (ret != -1 && !done)
384 ret = wl_display_dispatch_queue(display, queue);
387 wl_callback_destroy(callback);
392 static inline void lock_context(struct ilm_control_context *ctx)
394 pthread_mutex_lock(&ctx->mutex);
397 static inline void unlock_context(struct ilm_control_context *ctx)
399 pthread_mutex_unlock(&ctx->mutex);
402 static int init_control(void);
404 static struct ilm_control_context* sync_and_acquire_instance(void);
406 static void release_instance(void);
408 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid);
411 wayland_controller_is_inside_surface_list(struct wl_list *list,
414 struct surface_context *ctx_surf = NULL;
415 wl_list_for_each(ctx_surf, list, link) {
416 if (ctx_surf->id_surface == id_surface) {
425 wayland_controller_is_inside_layer_list(struct wl_list *list,
428 struct layer_context *ctx_layer = NULL;
429 wl_list_for_each(ctx_layer, list, link) {
430 if (ctx_layer->id_layer == id_layer) {
438 static struct layer_context*
439 wayland_controller_get_layer_context(struct wayland_context *ctx,
442 struct layer_context *ctx_layer = NULL;
444 if (ctx->controller == NULL) {
445 fprintf(stderr, "controller is not initialized in ilmControl\n");
449 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
450 if (ctx_layer->id_layer == id_layer) {
455 fprintf(stderr, "failed to get layer context in ilmControl\n");
460 output_listener_geometry(void *data,
461 struct wl_output *output,
464 int32_t physical_width,
465 int32_t physical_height,
481 output_listener_mode(void *data,
482 struct wl_output *output,
495 if (flags & WL_OUTPUT_MODE_CURRENT)
497 struct screen_context *ctx_scrn = data;
498 ctx_scrn->prop.screenWidth = width;
499 ctx_scrn->prop.screenHeight = height;
504 output_listener_done(void *data,
505 struct wl_output *output)
512 output_listener_scale(void *data,
513 struct wl_output *output,
521 static struct wl_output_listener output_listener = {
522 output_listener_geometry,
523 output_listener_mode,
524 output_listener_done,
525 output_listener_scale
528 static struct screen_context*
529 get_screen_context_by_output(struct wayland_context *ctx,
530 struct wl_output *output)
532 struct screen_context *ctx_scrn = NULL;
533 struct wl_proxy *pxy_out = NULL;
534 struct wl_proxy *pxy_out_in_scrn = NULL;
536 uint32_t pxy_id_in_scrn = 0;
538 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
539 pxy_out = (struct wl_proxy*)output;
540 pxy_out_in_scrn = (struct wl_proxy*)ctx_scrn->output;
541 pxy_id = wl_proxy_get_id(pxy_out);
542 pxy_id_in_scrn = wl_proxy_get_id(pxy_out_in_scrn);
543 if (pxy_id == pxy_id_in_scrn) {
550 static struct screen_context*
551 get_screen_context_by_serverid(struct wayland_context *ctx,
554 struct screen_context *ctx_scrn = NULL;
556 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
557 if (ctx_scrn->id_from_server == id_screen) {
565 add_orderlayer_to_screen(struct layer_context *ctx_layer,
566 struct wl_output* output)
568 struct screen_context *ctx_scrn = NULL;
570 ctx_scrn = get_screen_context_by_output(ctx_layer->ctx, output);
571 if (ctx_scrn == NULL) {
572 fprintf(stderr, "failed to add_orderlayer_to_screen\n");
577 struct layer_context *layer_link;
578 wl_list_for_each(layer_link, &ctx_scrn->order.list_layer, order.link) {
579 if (layer_link == ctx_layer) {
586 wl_list_init(&ctx_layer->order.link);
587 wl_list_insert(&ctx_scrn->order.list_layer, &ctx_layer->order.link);
592 remove_orderlayer_from_screen(struct layer_context *ctx_layer)
594 wl_list_remove(&ctx_layer->order.link);
595 wl_list_init(&ctx_layer->order.link);
599 controller_layer_listener_visibility(void *data,
600 struct ivi_controller_layer *controller,
603 struct layer_context *ctx_layer = data;
605 ctx_layer->prop.visibility = (t_ilm_bool)visibility;
607 if (ctx_layer->notification != NULL) {
608 ctx_layer->notification(ctx_layer->id_layer,
610 ILM_NOTIFICATION_VISIBILITY);
615 controller_layer_listener_opacity(void *data,
616 struct ivi_controller_layer *controller,
619 struct layer_context *ctx_layer = data;
621 ctx_layer->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
623 if (ctx_layer->notification != NULL) {
624 ctx_layer->notification(ctx_layer->id_layer,
626 ILM_NOTIFICATION_OPACITY);
631 controller_layer_listener_source_rectangle(void *data,
632 struct ivi_controller_layer *controller,
638 struct layer_context *ctx_layer = data;
640 ctx_layer->prop.sourceX = (t_ilm_uint)x;
641 ctx_layer->prop.sourceY = (t_ilm_uint)y;
642 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
643 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
644 if (ctx_layer->prop.origSourceWidth == 0) {
645 ctx_layer->prop.origSourceWidth = (t_ilm_uint)width;
647 if (ctx_layer->prop.origSourceHeight == 0) {
648 ctx_layer->prop.origSourceHeight = (t_ilm_uint)height;
651 if (ctx_layer->notification != NULL) {
652 ctx_layer->notification(ctx_layer->id_layer,
654 ILM_NOTIFICATION_SOURCE_RECT);
659 controller_layer_listener_destination_rectangle(void *data,
660 struct ivi_controller_layer *controller,
666 struct layer_context *ctx_layer = data;
668 ctx_layer->prop.destX = (t_ilm_uint)x;
669 ctx_layer->prop.destY = (t_ilm_uint)y;
670 ctx_layer->prop.destWidth = (t_ilm_uint)width;
671 ctx_layer->prop.destHeight = (t_ilm_uint)height;
673 if (ctx_layer->notification != NULL) {
674 ctx_layer->notification(ctx_layer->id_layer,
676 ILM_NOTIFICATION_DEST_RECT);
681 controller_layer_listener_configuration(void *data,
682 struct ivi_controller_layer *controller,
686 struct layer_context *ctx_layer = data;
688 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
689 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
693 controller_layer_listener_orientation(void *data,
694 struct ivi_controller_layer *controller,
697 ilmOrientation ilmorientation = ILM_ZERO;
698 struct layer_context *ctx_layer = data;
700 switch(orientation) {
701 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
702 ilmorientation = ILM_ZERO;
704 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
705 ilmorientation = ILM_NINETY;
707 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
708 ilmorientation = ILM_ONEHUNDREDEIGHTY;
710 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
711 ilmorientation = ILM_TWOHUNDREDSEVENTY;
717 ctx_layer->prop.orientation = ilmorientation;
719 if (ctx_layer->notification != NULL) {
720 ctx_layer->notification(ctx_layer->id_layer,
722 ILM_NOTIFICATION_ORIENTATION);
727 controller_layer_listener_screen(void *data,
728 struct ivi_controller_layer *controller,
729 struct wl_output *output)
731 struct layer_context *ctx_layer = data;
733 if (output == NULL) {
734 remove_orderlayer_from_screen(ctx_layer);
736 add_orderlayer_to_screen(ctx_layer, output);
741 controller_layer_listener_destroyed(void *data,
742 struct ivi_controller_layer *controller)
744 struct layer_context *ctx_layer = data;
745 wl_list_remove(&ctx_layer->link);
749 static struct ivi_controller_layer_listener controller_layer_listener =
751 controller_layer_listener_visibility,
752 controller_layer_listener_opacity,
753 controller_layer_listener_source_rectangle,
754 controller_layer_listener_destination_rectangle,
755 controller_layer_listener_configuration,
756 controller_layer_listener_orientation,
757 controller_layer_listener_screen,
758 controller_layer_listener_destroyed
762 add_ordersurface_to_layer(struct surface_context *ctx_surf,
763 struct ivi_controller_layer *layer)
765 struct layer_context *ctx_layer = NULL;
766 struct surface_context *link = NULL;
769 ctx_layer = ivi_controller_layer_get_user_data(layer);
771 wl_list_for_each(link, &ctx_layer->order.list_surface, order.link) {
772 if (link == ctx_surf) {
779 wl_list_init(&ctx_surf->order.link);
780 wl_list_insert(&ctx_layer->order.list_surface, &ctx_surf->order.link);
785 remove_ordersurface_from_layer(struct surface_context *ctx_surf)
787 wl_list_remove(&ctx_surf->order.link);
788 wl_list_init(&ctx_surf->order.link);
792 controller_surface_listener_visibility(void *data,
793 struct ivi_controller_surface *controller,
796 struct surface_context *ctx_surf = data;
798 ctx_surf->prop.visibility = (t_ilm_bool)visibility;
800 if (ctx_surf->notification != NULL) {
801 ctx_surf->notification(ctx_surf->id_surface,
803 ILM_NOTIFICATION_VISIBILITY);
808 controller_surface_listener_opacity(void *data,
809 struct ivi_controller_surface *controller,
812 struct surface_context *ctx_surf = data;
814 ctx_surf->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
816 if (ctx_surf->notification != NULL) {
817 ctx_surf->notification(ctx_surf->id_surface,
819 ILM_NOTIFICATION_OPACITY);
824 controller_surface_listener_configuration(void *data,
825 struct ivi_controller_surface *controller,
829 struct surface_context *ctx_surf = data;
831 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
832 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
836 controller_surface_listener_source_rectangle(void *data,
837 struct ivi_controller_surface *controller,
843 struct surface_context *ctx_surf = data;
845 ctx_surf->prop.sourceX = (t_ilm_uint)x;
846 ctx_surf->prop.sourceY = (t_ilm_uint)y;
847 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
848 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
849 if (ctx_surf->prop.origSourceWidth == 0) {
850 ctx_surf->prop.origSourceWidth = (t_ilm_uint)width;
852 if (ctx_surf->prop.origSourceHeight == 0) {
853 ctx_surf->prop.origSourceHeight = (t_ilm_uint)height;
856 if (ctx_surf->notification != NULL) {
857 ctx_surf->notification(ctx_surf->id_surface,
859 ILM_NOTIFICATION_SOURCE_RECT);
864 controller_surface_listener_destination_rectangle(void *data,
865 struct ivi_controller_surface *controller,
871 struct surface_context *ctx_surf = data;
873 ctx_surf->prop.destX = (t_ilm_uint)x;
874 ctx_surf->prop.destY = (t_ilm_uint)y;
875 ctx_surf->prop.destWidth = (t_ilm_uint)width;
876 ctx_surf->prop.destHeight = (t_ilm_uint)height;
878 if (ctx_surf->notification != NULL) {
879 ctx_surf->notification(ctx_surf->id_surface,
881 ILM_NOTIFICATION_DEST_RECT);
886 controller_surface_listener_orientation(void *data,
887 struct ivi_controller_surface *controller,
890 struct surface_context *ctx_surf = data;
891 ilmOrientation ilmorientation = ILM_ZERO;
893 switch (orientation) {
894 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
895 ilmorientation = ILM_ZERO;
897 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
898 ilmorientation = ILM_NINETY;
900 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
901 ilmorientation = ILM_ONEHUNDREDEIGHTY;
903 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
904 ilmorientation = ILM_TWOHUNDREDSEVENTY;
910 ctx_surf->prop.orientation = ilmorientation;
912 if (ctx_surf->notification != NULL) {
913 ctx_surf->notification(ctx_surf->id_surface,
915 ILM_NOTIFICATION_ORIENTATION);
920 controller_surface_listener_pixelformat(void *data,
921 struct ivi_controller_surface *controller,
924 struct surface_context *ctx_surf = data;
926 ctx_surf->prop.pixelformat = (t_ilm_uint)pixelformat;
930 controller_surface_listener_layer(void *data,
931 struct ivi_controller_surface *controller,
932 struct ivi_controller_layer *layer)
934 struct surface_context *ctx_surf = data;
937 remove_ordersurface_from_layer(ctx_surf);
939 add_ordersurface_to_layer(ctx_surf, layer);
944 controller_surface_listener_stats(void *data,
945 struct ivi_controller_surface *controller,
946 uint32_t redraw_count,
947 uint32_t frame_count,
948 uint32_t update_count,
950 const char *process_name)
952 struct surface_context *ctx_surf = data;
955 ctx_surf->prop.drawCounter = (t_ilm_uint)redraw_count;
956 ctx_surf->prop.frameCounter = (t_ilm_uint)frame_count;
957 ctx_surf->prop.updateCounter = (t_ilm_uint)update_count;
958 ctx_surf->prop.creatorPid = (t_ilm_uint)pid;
962 controller_surface_listener_destroyed(void *data,
963 struct ivi_controller_surface *controller)
965 struct surface_context *ctx_surf = data;
967 wl_list_remove(&ctx_surf->link);
972 controller_surface_listener_content(void *data,
973 struct ivi_controller_surface *controller,
974 int32_t content_state)
976 // if client surface (=content) was removed with ilm_surfaceDestroy()
977 // the expected behavior within ILM API mandates a full removal
978 // of the surface from the scene. We must remove the controller
980 if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED == content_state)
982 struct surface_context *ctx_surf = data;
984 ivi_controller_surface_destroy(controller, 1);
986 wl_list_remove(&ctx_surf->link);
992 controller_surface_listener_input_focus(void *data,
993 struct ivi_controller_surface *controller,
1001 static struct ivi_controller_surface_listener controller_surface_listener=
1003 controller_surface_listener_visibility,
1004 controller_surface_listener_opacity,
1005 controller_surface_listener_source_rectangle,
1006 controller_surface_listener_destination_rectangle,
1007 controller_surface_listener_configuration,
1008 controller_surface_listener_orientation,
1009 controller_surface_listener_pixelformat,
1010 controller_surface_listener_layer,
1011 controller_surface_listener_stats,
1012 controller_surface_listener_destroyed,
1013 controller_surface_listener_content,
1014 controller_surface_listener_input_focus
1018 controller_listener_layer(void *data,
1019 struct ivi_controller *controller,
1022 struct wayland_context *ctx = data;
1024 if (wayland_controller_is_inside_layer_list(&ctx->list_layer, id_layer))
1029 (void) create_controller_layer(ctx, 0, 0, id_layer);
1033 controller_listener_surface(void *data,
1034 struct ivi_controller *controller,
1035 uint32_t id_surface)
1037 struct wayland_context *ctx = data;
1038 struct surface_context *ctx_surf = NULL;
1039 int32_t is_inside = 0;
1041 is_inside = wayland_controller_is_inside_surface_list(
1042 &ctx->list_surface, id_surface);
1044 if (is_inside != 0) {
1045 fprintf(stderr, "invalid id_surface in controller_listener_surface\n");
1049 ctx_surf = calloc(1, sizeof *ctx_surf);
1050 if (ctx_surf == NULL) {
1051 fprintf(stderr, "Failed to allocate memory for surface_context\n");
1055 ctx_surf->controller = ivi_controller_surface_create(
1056 controller, id_surface);
1057 if (ctx_surf->controller == NULL) {
1059 fprintf(stderr, "Failed to create controller surface\n");
1062 ctx_surf->id_surface = id_surface;
1063 ctx_surf->prop.inputDevicesAcceptance = ILM_INPUT_DEVICE_ALL;
1064 ctx_surf->ctx = ctx;
1066 wl_list_init(&ctx_surf->link);
1067 wl_list_insert(&ctx->list_surface, &ctx_surf->link);
1068 wl_list_init(&ctx_surf->order.link);
1069 ivi_controller_surface_add_listener(ctx_surf->controller,
1070 &controller_surface_listener, ctx_surf);
1074 controller_listener_error(void *data,
1075 struct ivi_controller *ivi_controller,
1077 int32_t object_type,
1079 const char *error_text)
1082 (void)ivi_controller;
1090 controller_listener_screen(void *data,
1091 struct ivi_controller *ivi_controller,
1093 struct ivi_controller_screen *controller_screen)
1095 struct wayland_context *ctx = data;
1096 struct screen_context *ctx_screen;
1097 (void)ivi_controller;
1099 ctx_screen = get_screen_context_by_serverid(ctx, id_screen);
1100 if (ctx_screen == NULL) {
1101 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1104 ctx_screen->controller = controller_screen;
1107 static struct ivi_controller_listener controller_listener= {
1108 controller_listener_screen,
1109 controller_listener_layer,
1110 controller_listener_surface,
1111 controller_listener_error
1115 registry_handle_control(void *data,
1116 struct wl_registry *registry,
1117 uint32_t name, const char *interface,
1120 struct wayland_context *ctx = data;
1123 if (strcmp(interface, "ivi_controller") == 0) {
1124 ctx->controller = wl_registry_bind(registry, name,
1125 &ivi_controller_interface, 1);
1126 if (ctx->controller == NULL) {
1127 fprintf(stderr, "Failed to registry bind ivi_controller\n");
1130 if (ivi_controller_add_listener(ctx->controller,
1131 &controller_listener,
1133 fprintf(stderr, "Failed to add ivi_controller listener\n");
1136 } else if (strcmp(interface, "wl_output") == 0) {
1138 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
1139 struct wl_proxy *pxy = NULL;
1141 if (ctx_scrn == NULL) {
1142 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1145 wl_list_init(&ctx_scrn->link);
1146 ctx_scrn->output = wl_registry_bind(registry, name,
1147 &wl_output_interface, 1);
1148 if (ctx_scrn->output == NULL) {
1150 fprintf(stderr, "Failed to registry bind wl_output\n");
1154 if (wl_output_add_listener(ctx_scrn->output,
1158 fprintf(stderr, "Failed to add wl_output listener\n");
1162 pxy = (struct wl_proxy*)ctx_scrn->output;
1163 ctx_scrn->id_from_server = wl_proxy_get_id(pxy);
1164 ctx_scrn->id_screen = ctx->num_screen;
1166 wl_list_init(&ctx_scrn->order.list_layer);
1167 wl_list_insert(&ctx->list_screen, &ctx_scrn->link);
1171 static const struct wl_registry_listener
1172 registry_control_listener= {
1173 registry_handle_control,
1177 static struct ilm_control_context ilm_context;
1179 static void destroy_control_resources(void)
1181 struct ilm_control_context *ctx = &ilm_context;
1183 if (ctx->wl.controller != NULL) {
1185 struct surface_context *l;
1186 struct surface_context *n;
1187 wl_list_for_each_safe(l, n, &ctx->wl.list_surface, link) {
1188 wl_list_remove(&l->link);
1189 wl_list_remove(&l->order.link);
1190 ivi_controller_surface_destroy(l->controller, 0);
1196 struct layer_context *l;
1197 struct layer_context *n;
1198 wl_list_for_each_safe(l, n, &ctx->wl.list_layer, link) {
1199 wl_list_remove(&l->link);
1200 wl_list_remove(&l->order.link);
1201 ivi_controller_layer_destroy(l->controller, 0);
1207 struct screen_context *ctx_scrn;
1208 struct screen_context *next;
1210 wl_list_for_each_safe(ctx_scrn, next, &ctx->wl.list_screen, link) {
1211 if (ctx_scrn->output != NULL) {
1212 wl_output_destroy(ctx_scrn->output);
1215 wl_list_remove(&ctx_scrn->link);
1216 ivi_controller_screen_destroy(ctx_scrn->controller);
1221 ivi_controller_destroy(ctx->wl.controller);
1222 ctx->wl.controller = NULL;
1225 wl_display_flush(ctx->wl.display);
1227 wl_event_queue_destroy(ctx->wl.queue);
1228 ctx->wl.queue = NULL;
1230 wl_registry_destroy(ctx->wl.registry);
1231 ctx->wl.registry = NULL;
1233 if (0 != pthread_mutex_destroy(&ctx->mutex)) {
1234 fprintf(stderr, "failed to destroy pthread_mutex\n");
1239 wayland_destroy(void)
1241 struct ilm_control_context *ctx = &ilm_context;
1242 pthread_cancel(ctx->thread);
1243 if (0 != pthread_join(ctx->thread, NULL)) {
1244 fprintf(stderr, "failed to join control thread\n");
1246 destroy_control_resources();
1247 memset(ctx, 0, sizeof *ctx);
1250 static ilmErrorTypes
1251 wayland_init(t_ilm_nativedisplay nativedisplay)
1253 struct ilm_control_context *ctx = &ilm_context;
1255 if (ctx->initialized)
1257 fprintf(stderr, "Already initialized!\n");
1261 if (nativedisplay == 0) {
1262 return ILM_ERROR_INVALID_ARGUMENTS;
1265 memset(ctx, 0, sizeof *ctx);
1267 ctx->wl.display = (struct wl_display*)nativedisplay;
1269 wl_list_init(&ctx->wl.list_screen);
1270 wl_list_init(&ctx->wl.list_layer);
1271 wl_list_init(&ctx->wl.list_surface);
1274 pthread_mutexattr_t a;
1275 if (pthread_mutexattr_init(&a) != 0)
1280 if (pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE) != 0)
1282 pthread_mutexattr_destroy(&a);
1286 if (pthread_mutex_init(&ctx->mutex, &a) != 0)
1288 pthread_mutexattr_destroy(&a);
1289 fprintf(stderr, "failed to initialize pthread_mutex\n");
1293 pthread_mutexattr_destroy(&a);
1296 return init_control() == 0 ? ILM_SUCCESS : ILM_FAILED;
1299 static void cancel_read(void *d)
1301 wl_display_cancel_read(d);
1305 control_thread(void *p_ret)
1307 struct ilm_control_context *ctx = &ilm_context;
1308 struct wayland_context *wl = &ctx->wl;
1309 struct wl_display *display = wl->display;
1310 struct wl_event_queue *queue = wl->queue;
1311 int fd = wl_display_get_fd(display);
1317 if (wl_display_prepare_read_queue(display, queue) != 0)
1320 wl_display_dispatch_queue_pending(display, queue);
1321 unlock_context(ctx);
1326 if (wl_display_flush(display) == -1)
1334 pfd.events = POLLIN;
1339 pthread_cleanup_push(cancel_read, display);
1340 pollret = poll(&pfd, 1, -1);
1341 pthread_cleanup_pop(0);
1343 if (pollret != -1 && (pfd.revents & POLLIN))
1345 wl_display_read_events(display);
1348 int ret = wl_display_dispatch_queue_pending(display, queue);
1349 unlock_context(ctx);
1358 wl_display_cancel_read(display);
1368 struct ilm_control_context *ctx = &ilm_context;
1369 struct wayland_context *wl = &ctx->wl;
1373 wl_list_init(&ctx->list_nativehandle);
1375 wl->queue = wl_display_create_queue(wl->display);
1377 /* registry_add_listener for request by ivi-controller */
1378 wl->registry = wl_display_get_registry(wl->display);
1379 if (wl->registry == NULL) {
1380 wl_event_queue_destroy(wl->queue);
1382 fprintf(stderr, "Failed to get registry\n");
1385 wl_proxy_set_queue((void*)wl->registry, wl->queue);
1387 if (wl_registry_add_listener(wl->registry,
1388 ®istry_control_listener, ctx)) {
1389 fprintf(stderr, "Failed to add registry listener\n");
1393 // first level objects; ivi_controller
1394 display_roundtrip_queue(wl->display, wl->queue);
1395 // second level object: ivi_controller_surfaces/layers
1396 display_roundtrip_queue(wl->display, wl->queue);
1397 // third level objects: ivi_controller_surfaces/layers properties
1398 display_roundtrip_queue(wl->display, wl->queue);
1400 ret = pthread_create(&ctx->thread, NULL, control_thread, NULL);
1403 fprintf(stderr, "Failed to start internal receive thread. returned %d\n", ret);
1407 ctx->initialized = true;
1412 static struct ilm_control_context*
1413 sync_and_acquire_instance(void)
1415 struct ilm_control_context *ctx = &ilm_context;
1417 display_roundtrip_queue(ctx->wl.display, ctx->wl.queue);
1421 static void release_instance(void)
1423 struct ilm_control_context *ctx = &ilm_context;
1424 unlock_context(ctx);
1428 gen_layer_id(struct ilm_control_context *ctx)
1430 struct layer_context *ctx_layer = NULL;
1433 if (wl_list_length(&ctx->wl.list_layer) == 0) {
1434 ctx->internal_id_layer++;
1435 return ctx->internal_id_layer;
1437 wl_list_for_each(ctx_layer, &ctx->wl.list_layer, link) {
1438 if (ctx_layer->id_layer == ctx->internal_id_layer) {
1444 return ctx->internal_id_layer;
1447 ctx->internal_id_layer++;
1451 static struct surface_context*
1452 get_surface_context(struct wayland_context *ctx,
1453 uint32_t id_surface)
1455 struct surface_context *ctx_surf = NULL;
1457 if (ctx->controller == NULL) {
1458 fprintf(stderr, "controller is not initialized in ilmControl\n");
1462 wl_list_for_each(ctx_surf, &ctx->list_surface, link) {
1463 if (ctx_surf->id_surface == id_surface) {
1468 fprintf(stderr, "failed to get surface context in ilmControl\n");
1472 static struct screen_context*
1473 get_screen_context_by_id(struct wayland_context *ctx, uint32_t id_screen)
1475 struct screen_context *ctx_scrn = NULL;
1477 if (ctx->controller == NULL) {
1478 fprintf(stderr, "get_screen_context_by_id: controller is NULL\n");
1482 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
1483 if (ctx_scrn->id_screen == id_screen) {
1490 static ilmErrorTypes
1491 wayland_getPropertiesOfLayer(t_ilm_uint layerID,
1492 struct ilmLayerProperties* pLayerProperties)
1494 ilmErrorTypes returnValue = ILM_FAILED;
1495 struct ilm_control_context *ctx = sync_and_acquire_instance();
1496 struct layer_context *ctx_layer = NULL;
1498 if (pLayerProperties != NULL) {
1500 ctx_layer = (struct layer_context*)
1501 wayland_controller_get_layer_context(
1502 &ctx->wl, (uint32_t)layerID);
1504 if (ctx_layer != NULL) {
1505 *pLayerProperties = ctx_layer->prop;
1506 returnValue = ILM_SUCCESS;
1515 create_layerids(struct screen_context *ctx_screen,
1516 t_ilm_layer **layer_ids, t_ilm_uint *layer_count)
1518 struct layer_context *ctx_layer = NULL;
1519 t_ilm_layer *ids = NULL;
1521 *layer_count = wl_list_length(&ctx_screen->order.list_layer);
1522 if (*layer_count == 0) {
1527 *layer_ids = malloc(*layer_count * sizeof(t_ilm_layer));
1528 if (*layer_ids == NULL) {
1529 fprintf(stderr, "memory insufficient for layerids\n");
1535 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link) {
1536 *ids = (t_ilm_layer)ctx_layer->id_layer;
1541 static ilmErrorTypes
1542 wayland_getPropertiesOfScreen(t_ilm_display screenID,
1543 struct ilmScreenProperties* pScreenProperties)
1545 ilmErrorTypes returnValue = ILM_FAILED;
1547 if (! pScreenProperties)
1549 return ILM_ERROR_INVALID_ARGUMENTS;
1552 struct ilm_control_context *ctx = sync_and_acquire_instance();
1554 struct screen_context *ctx_screen = NULL;
1555 ctx_screen = get_screen_context_by_id(&ctx->wl, (uint32_t)screenID);
1556 if (ctx_screen != NULL) {
1557 *pScreenProperties = ctx_screen->prop;
1558 create_layerids(ctx_screen, &pScreenProperties->layerIds,
1559 &pScreenProperties->layerCount);
1560 returnValue = ILM_SUCCESS;
1567 static ilmErrorTypes
1568 wayland_getNumberOfHardwareLayers(t_ilm_uint screenID,
1569 t_ilm_uint* pNumberOfHardwareLayers)
1573 if (pNumberOfHardwareLayers != NULL) {
1574 *pNumberOfHardwareLayers = 0;
1581 static ilmErrorTypes
1582 wayland_getScreenIDs(t_ilm_uint* pNumberOfIDs, t_ilm_uint** ppIDs)
1584 ilmErrorTypes returnValue = ILM_FAILED;
1585 struct ilm_control_context *ctx = sync_and_acquire_instance();
1587 if ((pNumberOfIDs != NULL) && (ppIDs != NULL)) {
1588 struct screen_context *ctx_scrn = NULL;
1589 t_ilm_uint length = wl_list_length(&ctx->wl.list_screen);
1592 *ppIDs = (t_ilm_uint*)malloc(length * sizeof *ppIDs);
1593 if (*ppIDs != NULL) {
1594 t_ilm_uint* ids = *ppIDs;
1595 wl_list_for_each(ctx_scrn, &ctx->wl.list_screen, link) {
1596 *ids = ctx_scrn->id_screen;
1599 *pNumberOfIDs = length;
1601 returnValue = ILM_SUCCESS;
1609 static ilmErrorTypes
1610 wayland_getLayerIDs(t_ilm_int* pLength, t_ilm_layer** ppArray)
1612 ilmErrorTypes returnValue = ILM_FAILED;
1613 struct ilm_control_context *ctx = sync_and_acquire_instance();
1615 if ((pLength != NULL) && (ppArray != NULL)) {
1616 struct layer_context *ctx_layer = NULL;
1617 t_ilm_uint length = wl_list_length(&ctx->wl.list_layer);
1620 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
1621 if (*ppArray != NULL) {
1622 // compositor sends layers in opposite order
1623 // write ids from back to front to turn them around
1624 t_ilm_layer* ids = *ppArray;
1625 wl_list_for_each_reverse(ctx_layer, &ctx->wl.list_layer, link)
1627 *ids = ctx_layer->id_layer;
1632 returnValue = ILM_SUCCESS;
1640 static ilmErrorTypes
1641 wayland_getLayerIDsOnScreen(t_ilm_uint screenId,
1643 t_ilm_layer** ppArray)
1645 ilmErrorTypes returnValue = ILM_FAILED;
1646 struct ilm_control_context *ctx = sync_and_acquire_instance();
1648 if ((pLength != NULL) && (ppArray != NULL)) {
1649 struct screen_context *ctx_screen = NULL;
1650 ctx_screen = get_screen_context_by_id(&ctx->wl, screenId);
1651 if (ctx_screen != NULL) {
1652 struct layer_context *ctx_layer = NULL;
1653 t_ilm_int length = wl_list_length(&ctx_screen->order.list_layer);
1657 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
1658 if (*ppArray != NULL) {
1659 // compositor sends layers in opposite order
1660 // write ids from back to front to turn them around
1661 t_ilm_layer* ids = *ppArray;
1662 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link)
1664 *ids = ctx_layer->id_layer;
1676 returnValue = ILM_SUCCESS;
1684 static ilmErrorTypes
1685 wayland_getSurfaceIDs(t_ilm_int* pLength, t_ilm_surface** ppArray)
1687 ilmErrorTypes returnValue = ILM_FAILED;
1688 struct ilm_control_context *ctx = sync_and_acquire_instance();
1690 if ((pLength != NULL) && (ppArray != NULL)) {
1691 struct surface_context *ctx_surf = NULL;
1692 t_ilm_uint length = wl_list_length(&ctx->wl.list_surface);
1695 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
1696 if (*ppArray != NULL) {
1697 t_ilm_surface* ids = *ppArray;
1698 wl_list_for_each_reverse(ctx_surf, &ctx->wl.list_surface, link) {
1699 *ids = ctx_surf->id_surface;
1704 returnValue = ILM_SUCCESS;
1712 static ilmErrorTypes
1713 wayland_getSurfaceIDsOnLayer(t_ilm_layer layer,
1715 t_ilm_surface** ppArray)
1717 struct ilm_control_context *ctx = sync_and_acquire_instance();
1718 struct layer_context *ctx_layer = NULL;
1719 struct surface_context *ctx_surf = NULL;
1720 t_ilm_uint length = 0;
1721 t_ilm_surface* ids = NULL;
1723 if ((pLength == NULL) || (ppArray == NULL)) {
1728 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1729 &ctx->wl, (uint32_t)layer);
1731 if (ctx_layer == NULL) {
1736 length = wl_list_length(&ctx_layer->order.list_surface);
1737 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
1738 if (*ppArray == NULL) {
1744 wl_list_for_each_reverse(ctx_surf, &ctx_layer->order.list_surface, order.link) {
1745 *ids = (t_ilm_surface)ctx_surf->id_surface;
1754 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid)
1756 struct layer_context *ctx_layer = calloc(1, sizeof *ctx_layer);
1757 if (ctx_layer == NULL) {
1758 fprintf(stderr, "Failed to allocate memory for layer_context\n");
1762 ctx_layer->controller = ivi_controller_layer_create(
1764 layerid, width, height);
1765 if (ctx_layer->controller == NULL) {
1766 fprintf(stderr, "Failed to create layer\n");
1770 ctx_layer->id_layer = layerid;
1771 ctx_layer->ctx = ctx;
1773 wl_list_init(&ctx_layer->link);
1774 wl_list_insert(&ctx->list_layer, &ctx_layer->link);
1775 wl_list_init(&ctx_layer->order.link);
1776 wl_list_init(&ctx_layer->order.list_surface);
1778 ivi_controller_layer_add_listener(ctx_layer->controller,
1779 &controller_layer_listener, ctx_layer);
1784 static ilmErrorTypes
1785 wayland_layerCreateWithDimension(t_ilm_layer* pLayerId,
1789 ilmErrorTypes returnValue = ILM_FAILED;
1790 struct ilm_control_context *ctx = sync_and_acquire_instance();
1791 uint32_t layerid = 0;
1792 int32_t is_inside = 0;
1795 if (pLayerId == NULL) {
1799 if (*pLayerId != INVALID_ID) {
1800 /* Return failed, if layerid is already inside list_layer */
1801 is_inside = wayland_controller_is_inside_layer_list(
1802 &ctx->wl.list_layer, *pLayerId);
1803 if (0 != is_inside) {
1804 fprintf(stderr, "layerid=%d is already used.\n", *pLayerId);
1807 layerid = *pLayerId;
1810 /* Generate ID, if layerid is INVALID_ID */
1811 layerid = gen_layer_id(ctx);
1812 *pLayerId = layerid;
1815 if (create_controller_layer(&ctx->wl, width, height, layerid) == 0)
1817 returnValue = ILM_SUCCESS;
1825 static ilmErrorTypes
1826 wayland_layerRemove(t_ilm_layer layerId)
1828 ilmErrorTypes returnValue = ILM_FAILED;
1829 struct ilm_control_context *ctx = sync_and_acquire_instance();
1830 struct layer_context *ctx_layer = NULL;
1831 struct layer_context *ctx_next = NULL;
1833 wl_list_for_each_safe(ctx_layer, ctx_next,
1834 &ctx->wl.list_layer, link) {
1835 if (ctx_layer->id_layer == layerId) {
1836 ivi_controller_layer_destroy(ctx_layer->controller, 1);
1838 wl_list_remove(&ctx_layer->link);
1841 returnValue = ILM_SUCCESS;
1850 static ilmErrorTypes
1851 wayland_layerGetType(t_ilm_layer layerId, ilmLayerType* pLayerType)
1855 return ILM_ERROR_INVALID_ARGUMENTS;
1858 struct ilm_control_context *ctx = sync_and_acquire_instance();
1860 *pLayerType = wayland_controller_is_inside_layer_list(&ctx->wl.list_layer, layerId) ?
1861 ILM_LAYERTYPE_SOFTWARE2D :
1862 ILM_LAYERTYPE_UNKNOWN;
1865 return ILM_SUCCESS; // even if non existent?
1868 static ilmErrorTypes
1869 wayland_layerSetVisibility(t_ilm_layer layerId, t_ilm_bool newVisibility)
1871 ilmErrorTypes returnValue = ILM_FAILED;
1872 struct ilm_control_context *ctx = sync_and_acquire_instance();
1873 struct layer_context *ctx_layer = NULL;
1875 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1876 &ctx->wl, (uint32_t)layerId);
1878 if (ctx_layer != NULL) {
1879 uint32_t visibility = 0;
1880 if (newVisibility == ILM_TRUE) {
1883 ivi_controller_layer_set_visibility(ctx_layer->controller,
1885 returnValue = ILM_SUCCESS;
1892 static ilmErrorTypes
1893 wayland_layerGetVisibility(t_ilm_layer layerId, t_ilm_bool *pVisibility)
1895 ilmErrorTypes returnValue = ILM_FAILED;
1896 struct ilm_control_context *ctx = sync_and_acquire_instance();
1898 if (pVisibility != NULL) {
1899 struct layer_context *ctx_layer = NULL;
1901 ctx_layer = (struct layer_context*)
1902 wayland_controller_get_layer_context(
1903 &ctx->wl, (uint32_t)layerId);
1905 if (ctx_layer != NULL) {
1906 *pVisibility = ctx_layer->prop.visibility;
1907 returnValue = ILM_SUCCESS;
1915 static ilmErrorTypes
1916 wayland_layerSetOpacity(t_ilm_layer layerId, t_ilm_float opacity)
1918 ilmErrorTypes returnValue = ILM_FAILED;
1919 struct ilm_control_context *ctx = sync_and_acquire_instance();
1920 struct layer_context *ctx_layer = NULL;
1922 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1923 &ctx->wl, (uint32_t)layerId);
1925 if (ctx_layer != NULL) {
1926 wl_fixed_t opacity_fixed = wl_fixed_from_double((double)opacity);
1927 ivi_controller_layer_set_opacity(ctx_layer->controller,
1929 returnValue = ILM_SUCCESS;
1936 static ilmErrorTypes
1937 wayland_layerGetOpacity(t_ilm_layer layerId, t_ilm_float *pOpacity)
1939 ilmErrorTypes returnValue = ILM_FAILED;
1940 struct ilm_control_context *ctx = sync_and_acquire_instance();
1942 if (pOpacity != NULL) {
1943 struct layer_context *ctx_layer = NULL;
1945 ctx_layer = (struct layer_context*)
1946 wayland_controller_get_layer_context(
1947 &ctx->wl, (uint32_t)layerId);
1949 if (ctx_layer != NULL) {
1950 *pOpacity = ctx_layer->prop.opacity;
1951 returnValue = ILM_SUCCESS;
1959 static ilmErrorTypes
1960 wayland_layerSetSourceRectangle(t_ilm_layer layerId,
1961 t_ilm_uint x, t_ilm_uint y,
1962 t_ilm_uint width, t_ilm_uint height)
1964 ilmErrorTypes returnValue = ILM_FAILED;
1965 struct ilm_control_context *ctx = sync_and_acquire_instance();
1966 struct layer_context *ctx_layer = NULL;
1968 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1969 &ctx->wl, (uint32_t)layerId);
1971 if (ctx_layer != NULL) {
1972 ivi_controller_layer_set_source_rectangle(ctx_layer->controller,
1977 returnValue = ILM_SUCCESS;
1984 static ilmErrorTypes
1985 wayland_layerSetDestinationRectangle(t_ilm_layer layerId,
1986 t_ilm_int x, t_ilm_int y,
1987 t_ilm_int width, t_ilm_int height)
1989 ilmErrorTypes returnValue = ILM_FAILED;
1990 struct ilm_control_context *ctx = sync_and_acquire_instance();
1991 struct layer_context *ctx_layer = NULL;
1993 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1994 &ctx->wl, (uint32_t)layerId);
1995 if (ctx_layer != NULL) {
1996 ivi_controller_layer_set_destination_rectangle(
1997 ctx_layer->controller,
1998 (uint32_t)x, (uint32_t)y,
2001 returnValue = ILM_SUCCESS;
2008 static ilmErrorTypes
2009 wayland_layerGetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
2011 ilmErrorTypes returnValue = ILM_FAILED;
2012 struct ilm_control_context *ctx = sync_and_acquire_instance();
2013 struct layer_context *ctx_layer = NULL;
2015 if (pDimension != NULL) {
2016 ctx_layer = (struct layer_context*)
2017 wayland_controller_get_layer_context(
2018 &ctx->wl, (uint32_t)layerId);
2019 if (ctx_layer != NULL) {
2020 *pDimension = ctx_layer->prop.destWidth;
2021 *(pDimension + 1) = ctx_layer->prop.destHeight;
2022 returnValue = ILM_SUCCESS;
2030 static ilmErrorTypes
2031 wayland_layerSetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
2033 ilmErrorTypes returnValue = ILM_FAILED;
2034 struct ilm_control_context *ctx = sync_and_acquire_instance();
2035 struct layer_context *ctx_layer = NULL;
2037 if (pDimension != NULL) {
2038 ctx_layer = (struct layer_context*)
2039 wayland_controller_get_layer_context(
2040 &ctx->wl, (uint32_t)layerId);
2041 if (ctx_layer != NULL) {
2042 ivi_controller_layer_set_destination_rectangle(
2043 ctx_layer->controller,
2044 ctx_layer->prop.destX, ctx_layer->prop.destY,
2045 (int32_t)*pDimension, (int32_t)*(pDimension + 1));
2046 returnValue = ILM_SUCCESS;
2054 static ilmErrorTypes
2055 wayland_layerGetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2057 ilmErrorTypes returnValue = ILM_FAILED;
2058 struct ilm_control_context *ctx = sync_and_acquire_instance();
2059 struct layer_context *ctx_layer = NULL;
2061 if (pPosition != NULL) {
2062 ctx_layer = (struct layer_context*)
2063 wayland_controller_get_layer_context(
2064 &ctx->wl, (uint32_t)layerId);
2065 if (ctx_layer != NULL) {
2066 *pPosition = ctx_layer->prop.destX;
2067 *(pPosition + 1) = ctx_layer->prop.destY;
2068 returnValue = ILM_SUCCESS;
2076 static ilmErrorTypes
2077 wayland_layerSetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2079 ilmErrorTypes returnValue = ILM_FAILED;
2080 struct ilm_control_context *ctx = sync_and_acquire_instance();
2081 struct layer_context *ctx_layer = NULL;
2083 if (pPosition != NULL) {
2084 ctx_layer = (struct layer_context*)
2085 wayland_controller_get_layer_context(
2086 &ctx->wl, (uint32_t)layerId);
2087 if (ctx_layer != NULL) {
2088 ivi_controller_layer_set_destination_rectangle(
2089 ctx_layer->controller,
2090 (int32_t)*pPosition, (int32_t)*(pPosition + 1),
2091 ctx_layer->prop.destWidth, ctx_layer->prop.destHeight);
2092 returnValue = ILM_SUCCESS;
2100 static ilmErrorTypes
2101 wayland_layerSetOrientation(t_ilm_layer layerId, ilmOrientation orientation)
2103 ilmErrorTypes returnValue = ILM_FAILED;
2104 struct ilm_control_context *ctx = sync_and_acquire_instance();
2105 struct layer_context *ctx_layer = NULL;
2106 int32_t iviorientation = 0;
2109 switch(orientation) {
2111 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2114 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2116 case ILM_ONEHUNDREDEIGHTY:
2117 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2119 case ILM_TWOHUNDREDSEVENTY:
2120 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2123 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2127 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2128 &ctx->wl, (uint32_t)layerId);
2129 if (ctx_layer == NULL) {
2130 returnValue = ILM_FAILED;
2134 ivi_controller_layer_set_orientation(ctx_layer->controller,
2137 returnValue = ILM_SUCCESS;
2144 static ilmErrorTypes
2145 wayland_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrientation)
2147 ilmErrorTypes returnValue = ILM_FAILED;
2148 struct ilm_control_context *ctx = sync_and_acquire_instance();
2149 struct layer_context *ctx_layer = NULL;
2151 if (pOrientation != NULL) {
2152 ctx_layer = (struct layer_context*)
2153 wayland_controller_get_layer_context(
2154 &ctx->wl, (uint32_t)layerId);
2155 if (ctx_layer != NULL) {
2156 *pOrientation = ctx_layer->prop.orientation;
2157 returnValue = ILM_SUCCESS;
2165 static ilmErrorTypes
2166 wayland_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
2174 static ilmErrorTypes
2175 wayland_layerSetRenderOrder(t_ilm_layer layerId,
2176 t_ilm_surface *pSurfaceId,
2179 ilmErrorTypes returnValue = ILM_FAILED;
2180 struct ilm_control_context *ctx = sync_and_acquire_instance();
2181 struct layer_context *ctx_layer = NULL;
2183 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2184 &ctx->wl, (uint32_t)layerId);
2188 struct wl_array ids;
2189 wl_array_init(&ids);
2190 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2192 for (i = 0; i < number; i++) pids[i] = (uint32_t)pSurfaceId[i];
2193 ivi_controller_layer_set_render_order(ctx_layer->controller, &ids);
2194 wl_array_release(&ids);
2195 returnValue = ILM_SUCCESS;
2202 static ilmErrorTypes
2203 wayland_layerGetCapabilities(t_ilm_layer layerId,
2204 t_ilm_layercapabilities *pCapabilities)
2207 (void)pCapabilities;
2212 static ilmErrorTypes
2213 wayland_layerTypeGetCapabilities(ilmLayerType layerType,
2214 t_ilm_layercapabilities *pCapabilities)
2217 (void)pCapabilities;
2222 static ilmErrorTypes
2223 wayland_surfaceSetVisibility(t_ilm_surface surfaceId, t_ilm_bool newVisibility)
2225 ilmErrorTypes returnValue = ILM_FAILED;
2226 struct ilm_control_context *ctx = sync_and_acquire_instance();
2227 struct surface_context *ctx_surf = NULL;
2228 uint32_t visibility = 0;
2230 if (newVisibility == ILM_TRUE) {
2233 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2235 ivi_controller_surface_set_visibility(ctx_surf->controller,
2237 returnValue = ILM_SUCCESS;
2244 static ilmErrorTypes
2245 wayland_surfaceSetOpacity(t_ilm_surface surfaceId, t_ilm_float opacity)
2247 ilmErrorTypes returnValue = ILM_FAILED;
2248 struct ilm_control_context *ctx = sync_and_acquire_instance();
2249 struct surface_context *ctx_surf = NULL;
2250 wl_fixed_t opacity_fixed = 0;
2252 opacity_fixed = wl_fixed_from_double((double)opacity);
2253 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2255 ivi_controller_surface_set_opacity(ctx_surf->controller,
2257 returnValue = ILM_SUCCESS;
2264 static ilmErrorTypes
2265 wayland_surfaceGetOpacity(t_ilm_surface surfaceId, t_ilm_float *pOpacity)
2267 ilmErrorTypes returnValue = ILM_FAILED;
2268 struct ilm_control_context *ctx = sync_and_acquire_instance();
2270 if (pOpacity != NULL) {
2271 struct surface_context *ctx_surf = NULL;
2272 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2274 *pOpacity = ctx_surf->prop.opacity;
2275 returnValue = ILM_SUCCESS;
2283 static ilmErrorTypes
2284 wayland_SetKeyboardFocusOn(t_ilm_surface surfaceId)
2286 ilmErrorTypes returnValue = ILM_FAILED;
2288 returnValue = ILM_SUCCESS;
2292 static ilmErrorTypes
2293 wayland_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
2295 ilmErrorTypes returnValue = ILM_FAILED;
2297 returnValue = ILM_SUCCESS;
2301 static ilmErrorTypes
2302 wayland_surfaceSetDestinationRectangle(t_ilm_surface surfaceId,
2303 t_ilm_int x, t_ilm_int y,
2304 t_ilm_int width, t_ilm_int height)
2306 ilmErrorTypes returnValue = ILM_FAILED;
2307 struct ilm_control_context *ctx = sync_and_acquire_instance();
2308 struct surface_context *ctx_surf = NULL;
2310 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2312 ivi_controller_surface_set_destination_rectangle(
2313 ctx_surf->controller,
2314 x, y, width, height);
2315 returnValue = ILM_SUCCESS;
2322 static ilmErrorTypes
2323 wayland_surfaceSetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
2325 ilmErrorTypes returnValue = ILM_FAILED;
2326 struct ilm_control_context *ctx = sync_and_acquire_instance();
2328 if (pDimension != NULL) {
2329 struct surface_context *ctx_surf = NULL;
2330 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2332 uint32_t width = *pDimension;
2333 uint32_t height = *(pDimension + 1);
2334 ivi_controller_surface_set_destination_rectangle(
2335 ctx_surf->controller,
2336 ctx_surf->prop.destX, ctx_surf->prop.destY, width, height);
2337 returnValue = ILM_SUCCESS;
2345 static ilmErrorTypes
2346 wayland_surfaceGetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2348 ilmErrorTypes returnValue = ILM_FAILED;
2349 struct ilm_control_context *ctx = sync_and_acquire_instance();
2351 if (pPosition != NULL) {
2352 struct surface_context *ctx_surf = NULL;
2353 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2355 *pPosition = ctx_surf->prop.destX;
2356 *(pPosition + 1) = ctx_surf->prop.destY;
2357 returnValue = ILM_SUCCESS;
2365 static ilmErrorTypes
2366 wayland_surfaceSetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2368 ilmErrorTypes returnValue = ILM_FAILED;
2369 struct ilm_control_context *ctx = sync_and_acquire_instance();
2371 if (pPosition != NULL) {
2372 struct surface_context *ctx_surf = NULL;
2373 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2375 int32_t destX = (int32_t)*pPosition;
2376 int32_t destY = (int32_t)*(pPosition + 1);
2377 ivi_controller_surface_set_destination_rectangle(
2378 ctx_surf->controller, destX, destY,
2379 ctx_surf->prop.destWidth, ctx_surf->prop.destHeight);
2380 returnValue = ILM_SUCCESS;
2388 static ilmErrorTypes
2389 wayland_surfaceSetOrientation(t_ilm_surface surfaceId,
2390 ilmOrientation orientation)
2392 ilmErrorTypes returnValue = ILM_FAILED;
2393 struct ilm_control_context *ctx = sync_and_acquire_instance();
2394 struct surface_context *ctx_surf = NULL;
2395 int32_t iviorientation = 0;
2398 switch(orientation) {
2400 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2403 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2405 case ILM_ONEHUNDREDEIGHTY:
2406 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2408 case ILM_TWOHUNDREDSEVENTY:
2409 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2412 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2416 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2417 if (ctx_surf == NULL) {
2418 returnValue = ILM_FAILED;
2422 ivi_controller_surface_set_orientation(ctx_surf->controller,
2425 returnValue = ILM_SUCCESS;
2432 static ilmErrorTypes
2433 wayland_surfaceGetOrientation(t_ilm_surface surfaceId,
2434 ilmOrientation *pOrientation)
2436 ilmErrorTypes returnValue = ILM_FAILED;
2437 struct ilm_control_context *ctx = sync_and_acquire_instance();
2439 if (pOrientation != NULL) {
2440 struct surface_context *ctx_surf = NULL;
2441 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2443 *pOrientation = ctx_surf->prop.orientation;
2444 returnValue = ILM_SUCCESS;
2452 static ilmErrorTypes
2453 wayland_surfaceGetPixelformat(t_ilm_layer surfaceId,
2454 ilmPixelFormat *pPixelformat)
2456 ilmErrorTypes returnValue = ILM_FAILED;
2457 struct ilm_control_context *ctx = sync_and_acquire_instance();
2459 if (pPixelformat != NULL) {
2460 struct surface_context *ctx_surf = NULL;
2461 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2463 *pPixelformat = ctx_surf->prop.pixelformat;
2464 returnValue = ILM_SUCCESS;
2472 static ilmErrorTypes
2473 wayland_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
2481 static ilmErrorTypes
2482 wayland_displaySetRenderOrder(t_ilm_display display,
2483 t_ilm_layer *pLayerId, const t_ilm_uint number)
2485 ilmErrorTypes returnValue = ILM_FAILED;
2486 struct ilm_control_context *ctx = sync_and_acquire_instance();
2487 struct screen_context *ctx_scrn = NULL;
2489 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)display);
2490 if (ctx_scrn != NULL) {
2491 struct wl_array ids;
2492 wl_array_init(&ids);
2493 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2495 for (i = 0; i < number; i++) pids[i] = (uint32_t)pLayerId[i];
2496 ivi_controller_screen_set_render_order(ctx_scrn->controller, &ids);
2497 wl_array_release(&ids);
2498 returnValue = ILM_SUCCESS;
2505 static ilmErrorTypes
2506 wayland_takeScreenshot(t_ilm_uint screen, t_ilm_const_string filename)
2508 ilmErrorTypes returnValue = ILM_FAILED;
2509 struct ilm_control_context *ctx = sync_and_acquire_instance();
2510 struct screen_context *ctx_scrn = NULL;
2512 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)screen);
2513 if (ctx_scrn != NULL) {
2514 ivi_controller_screen_screenshot(ctx_scrn->controller,
2516 wl_display_flush(ctx->wl.display);
2517 returnValue = ILM_SUCCESS;
2524 static ilmErrorTypes
2525 wayland_takeLayerScreenshot(t_ilm_const_string filename, t_ilm_layer layerid)
2527 ilmErrorTypes returnValue = ILM_FAILED;
2528 struct ilm_control_context *ctx = sync_and_acquire_instance();
2529 struct layer_context *ctx_layer = NULL;
2531 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2532 &ctx->wl, (uint32_t)layerid);
2533 if (ctx_layer != NULL) {
2534 ivi_controller_layer_screenshot(ctx_layer->controller,
2536 wl_display_flush(ctx->wl.display);
2537 returnValue = ILM_SUCCESS;
2544 static ilmErrorTypes
2545 wayland_takeSurfaceScreenshot(t_ilm_const_string filename,
2546 t_ilm_surface surfaceid)
2548 ilmErrorTypes returnValue = ILM_FAILED;
2549 struct ilm_control_context *ctx = sync_and_acquire_instance();
2550 struct surface_context *ctx_surf = NULL;
2552 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceid);
2554 ivi_controller_surface_screenshot(ctx_surf->controller,
2556 wl_display_flush(ctx->wl.display);
2557 returnValue = ILM_SUCCESS;
2564 static ilmErrorTypes
2565 wayland_SetOptimizationMode(ilmOptimization id, ilmOptimizationMode mode)
2573 static ilmErrorTypes
2574 wayland_GetOptimizationMode(ilmOptimization id, ilmOptimizationMode* pMode)
2583 static ilmErrorTypes
2584 wayland_layerAddNotification(t_ilm_layer layer,
2585 layerNotificationFunc callback)
2587 ilmErrorTypes returnValue = ILM_FAILED;
2588 struct ilm_control_context *ctx = sync_and_acquire_instance();
2589 struct layer_context *ctx_layer = NULL;
2591 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2592 &ctx->wl, (uint32_t)layer);
2593 if (ctx_layer == NULL) {
2594 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2596 ctx_layer->notification = callback;
2598 returnValue = ILM_SUCCESS;
2606 static ilmErrorTypes
2607 wayland_layerRemoveNotification(t_ilm_layer layer)
2609 return wayland_layerAddNotification(layer, NULL);
2613 static ilmErrorTypes
2614 wayland_surfaceAddNotification(t_ilm_surface surface,
2615 surfaceNotificationFunc callback)
2617 ilmErrorTypes returnValue = ILM_FAILED;
2618 struct ilm_control_context *ctx = sync_and_acquire_instance();
2619 struct surface_context *ctx_surf = NULL;
2621 ctx_surf = (struct surface_context*)get_surface_context(
2622 &ctx->wl, (uint32_t)surface);
2623 if (ctx_surf == NULL) {
2624 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2626 ctx_surf->notification = callback;
2628 returnValue = ILM_SUCCESS;
2636 static ilmErrorTypes
2637 wayland_surfaceRemoveNotification(t_ilm_surface surface)
2639 return wayland_surfaceAddNotification(surface, NULL);
2642 static ilmErrorTypes
2643 wayland_getNativeHandle(t_ilm_uint pid, t_ilm_int *n_handle,
2644 t_ilm_nativehandle **p_handles)
2646 struct ilm_control_context *ctx = sync_and_acquire_instance();
2647 struct nativehandle_context *p_nh_ctx = NULL;
2652 wl_list_for_each(p_nh_ctx, &ctx->list_nativehandle, link)
2654 if (p_nh_ctx->pid == pid)
2658 (t_ilm_nativehandle*)malloc(sizeof(t_ilm_nativehandle));
2659 (*p_handles)[0] = p_nh_ctx->nativehandle;
2665 return (*n_handle > 0) ? ILM_SUCCESS : ILM_FAILED;
2668 static ilmErrorTypes
2669 wayland_getPropertiesOfSurface(t_ilm_uint surfaceID,
2670 struct ilmSurfaceProperties* pSurfaceProperties)
2672 ilmErrorTypes returnValue = ILM_FAILED;
2673 struct ilm_control_context *ctx = sync_and_acquire_instance();
2675 if (pSurfaceProperties != NULL) {
2676 struct surface_context *ctx_surf = NULL;
2678 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceID);
2679 if (ctx_surf != NULL) {
2681 *pSurfaceProperties = ctx_surf->prop;
2682 returnValue = ILM_SUCCESS;
2690 static ilmErrorTypes
2691 wayland_layerAddSurface(t_ilm_layer layerId,
2692 t_ilm_surface surfaceId)
2694 ilmErrorTypes returnValue = ILM_FAILED;
2695 struct ilm_control_context *ctx = sync_and_acquire_instance();
2696 struct layer_context *ctx_layer = NULL;
2697 struct surface_context *ctx_surf = NULL;
2699 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2700 &ctx->wl, (uint32_t)layerId);
2701 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2702 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2703 ivi_controller_layer_add_surface(ctx_layer->controller,
2704 ctx_surf->controller);
2705 returnValue = ILM_SUCCESS;
2712 static ilmErrorTypes
2713 wayland_layerRemoveSurface(t_ilm_layer layerId,
2714 t_ilm_surface surfaceId)
2716 ilmErrorTypes returnValue = ILM_FAILED;
2717 struct ilm_control_context *ctx = sync_and_acquire_instance();
2718 struct layer_context *ctx_layer = NULL;
2719 struct surface_context *ctx_surf = NULL;
2721 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2722 &ctx->wl, (uint32_t)layerId);
2723 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2724 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2725 ivi_controller_layer_remove_surface(ctx_layer->controller,
2726 ctx_surf->controller);
2727 returnValue = ILM_SUCCESS;
2734 static ilmErrorTypes
2735 wayland_surfaceGetDimension(t_ilm_surface surfaceId,
2736 t_ilm_uint *pDimension)
2738 ilmErrorTypes returnValue = ILM_FAILED;
2739 struct ilm_control_context *ctx = sync_and_acquire_instance();
2741 if (pDimension != NULL) {
2742 struct surface_context *ctx_surf = NULL;
2744 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2745 if (ctx_surf != NULL) {
2746 *pDimension = (t_ilm_uint)ctx_surf->prop.destWidth;
2747 *(pDimension + 1) = (t_ilm_uint)ctx_surf->prop.destHeight;
2748 returnValue = ILM_SUCCESS;
2756 static ilmErrorTypes
2757 wayland_surfaceGetVisibility(t_ilm_surface surfaceId,
2758 t_ilm_bool *pVisibility)
2760 ilmErrorTypes returnValue = ILM_FAILED;
2761 struct ilm_control_context *ctx = sync_and_acquire_instance();
2762 struct surface_context *ctx_surf = NULL;
2764 if (pVisibility != NULL) {
2765 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2766 if (ctx_surf != NULL) {
2767 *pVisibility = (t_ilm_bool)ctx_surf->prop.visibility;
2768 returnValue = ILM_SUCCESS;
2776 static ilmErrorTypes
2777 wayland_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
2778 t_ilm_int x, t_ilm_int y,
2779 t_ilm_int width, t_ilm_int height)
2781 ilmErrorTypes returnValue = ILM_FAILED;
2782 struct ilm_control_context *ctx = sync_and_acquire_instance();
2783 struct surface_context *ctx_surf = NULL;
2785 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2786 if (ctx_surf != NULL) {
2787 if (ctx_surf->controller != NULL) {
2788 ivi_controller_surface_set_source_rectangle(
2789 ctx_surf->controller,
2790 x, y, width, height);
2791 returnValue = ILM_SUCCESS;
2799 static ilmErrorTypes
2800 wayland_commitChanges(void)
2802 ilmErrorTypes returnValue = ILM_FAILED;
2803 struct ilm_control_context *ctx = sync_and_acquire_instance();
2805 if (ctx->wl.controller != NULL) {
2806 ivi_controller_commit_changes(ctx->wl.controller);
2808 if (display_roundtrip_queue(ctx->wl.display, ctx->wl.queue) != -1)
2810 returnValue = ILM_SUCCESS;