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;
328 struct ilm_control_context *ctx;
331 struct nativehandle_context {
333 uint32_t nativehandle;
337 struct wayland_context {
338 struct wl_display *display;
339 struct wl_registry *registry;
340 struct wl_event_queue *queue;
341 struct wl_compositor *compositor;
342 struct ivi_controller *controller;
345 struct wl_list list_surface;
346 struct wl_list list_layer;
347 struct wl_list list_screen;
350 struct ilm_control_context {
351 struct wayland_context wl;
354 uint32_t internal_id_layer;
356 struct wl_list list_nativehandle;
359 pthread_mutex_t mutex;
360 uint32_t internal_id_surface;
363 static void roundtrip_done(void *data, struct wl_callback *callback,
372 static struct wl_callback_listener roundtrip_listener = {roundtrip_done};
374 int display_roundtrip_queue(struct wl_display *display,
375 struct wl_event_queue *queue)
379 struct wl_callback *callback = wl_display_sync(display);
380 wl_proxy_set_queue((void *)callback, queue);
381 wl_callback_add_listener(callback, &roundtrip_listener, &done);
383 while (ret != -1 && !done)
385 ret = wl_display_dispatch_queue(display, queue);
388 wl_callback_destroy(callback);
393 static inline void lock_context(struct ilm_control_context *ctx)
395 pthread_mutex_lock(&ctx->mutex);
398 static inline void unlock_context(struct ilm_control_context *ctx)
400 pthread_mutex_unlock(&ctx->mutex);
403 static int init_control(void);
405 static struct ilm_control_context* sync_and_acquire_instance(void);
407 static void release_instance(void);
409 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid);
412 wayland_controller_is_inside_surface_list(struct wl_list *list,
415 struct surface_context *ctx_surf = NULL;
416 wl_list_for_each(ctx_surf, list, link) {
417 if (ctx_surf->id_surface == id_surface) {
426 wayland_controller_is_inside_layer_list(struct wl_list *list,
429 struct layer_context *ctx_layer = NULL;
430 wl_list_for_each(ctx_layer, list, link) {
431 if (ctx_layer->id_layer == id_layer) {
439 static struct layer_context*
440 wayland_controller_get_layer_context(struct wayland_context *ctx,
443 struct layer_context *ctx_layer = NULL;
445 if (ctx->controller == NULL) {
446 fprintf(stderr, "controller is not initialized in ilmControl\n");
450 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
451 if (ctx_layer->id_layer == id_layer) {
456 fprintf(stderr, "failed to get layer context in ilmControl\n");
461 output_listener_geometry(void *data,
462 struct wl_output *output,
465 int32_t physical_width,
466 int32_t physical_height,
482 output_listener_mode(void *data,
483 struct wl_output *output,
496 if (flags & WL_OUTPUT_MODE_CURRENT)
498 struct screen_context *ctx_scrn = data;
499 ctx_scrn->prop.screenWidth = width;
500 ctx_scrn->prop.screenHeight = height;
505 output_listener_done(void *data,
506 struct wl_output *output)
513 output_listener_scale(void *data,
514 struct wl_output *output,
522 static struct wl_output_listener output_listener = {
523 output_listener_geometry,
524 output_listener_mode,
525 output_listener_done,
526 output_listener_scale
529 static struct screen_context*
530 get_screen_context_by_output(struct wayland_context *ctx,
531 struct wl_output *output)
533 struct screen_context *ctx_scrn = NULL;
534 struct wl_proxy *pxy_out = NULL;
535 struct wl_proxy *pxy_out_in_scrn = NULL;
537 uint32_t pxy_id_in_scrn = 0;
539 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
540 pxy_out = (struct wl_proxy*)output;
541 pxy_out_in_scrn = (struct wl_proxy*)ctx_scrn->output;
542 pxy_id = wl_proxy_get_id(pxy_out);
543 pxy_id_in_scrn = wl_proxy_get_id(pxy_out_in_scrn);
544 if (pxy_id == pxy_id_in_scrn) {
551 static struct screen_context*
552 get_screen_context_by_serverid(struct wayland_context *ctx,
555 struct screen_context *ctx_scrn = NULL;
557 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
558 if (ctx_scrn->id_from_server == id_screen) {
566 add_orderlayer_to_screen(struct layer_context *ctx_layer,
567 struct wl_output* output)
569 struct screen_context *ctx_scrn = NULL;
571 ctx_scrn = get_screen_context_by_output(ctx_layer->ctx, output);
572 if (ctx_scrn == NULL) {
573 fprintf(stderr, "failed to add_orderlayer_to_screen\n");
578 struct layer_context *layer_link;
579 wl_list_for_each(layer_link, &ctx_scrn->order.list_layer, order.link) {
580 if (layer_link == ctx_layer) {
587 wl_list_init(&ctx_layer->order.link);
588 wl_list_insert(&ctx_scrn->order.list_layer, &ctx_layer->order.link);
593 remove_orderlayer_from_screen(struct layer_context *ctx_layer)
595 wl_list_remove(&ctx_layer->order.link);
596 wl_list_init(&ctx_layer->order.link);
600 controller_layer_listener_visibility(void *data,
601 struct ivi_controller_layer *controller,
604 struct layer_context *ctx_layer = data;
606 ctx_layer->prop.visibility = (t_ilm_bool)visibility;
608 if (ctx_layer->notification != NULL) {
609 ctx_layer->notification(ctx_layer->id_layer,
611 ILM_NOTIFICATION_VISIBILITY);
616 controller_layer_listener_opacity(void *data,
617 struct ivi_controller_layer *controller,
620 struct layer_context *ctx_layer = data;
622 ctx_layer->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
624 if (ctx_layer->notification != NULL) {
625 ctx_layer->notification(ctx_layer->id_layer,
627 ILM_NOTIFICATION_OPACITY);
632 controller_layer_listener_source_rectangle(void *data,
633 struct ivi_controller_layer *controller,
639 struct layer_context *ctx_layer = data;
641 ctx_layer->prop.sourceX = (t_ilm_uint)x;
642 ctx_layer->prop.sourceY = (t_ilm_uint)y;
643 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
644 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
645 if (ctx_layer->prop.origSourceWidth == 0) {
646 ctx_layer->prop.origSourceWidth = (t_ilm_uint)width;
648 if (ctx_layer->prop.origSourceHeight == 0) {
649 ctx_layer->prop.origSourceHeight = (t_ilm_uint)height;
652 if (ctx_layer->notification != NULL) {
653 ctx_layer->notification(ctx_layer->id_layer,
655 ILM_NOTIFICATION_SOURCE_RECT);
660 controller_layer_listener_destination_rectangle(void *data,
661 struct ivi_controller_layer *controller,
667 struct layer_context *ctx_layer = data;
669 ctx_layer->prop.destX = (t_ilm_uint)x;
670 ctx_layer->prop.destY = (t_ilm_uint)y;
671 ctx_layer->prop.destWidth = (t_ilm_uint)width;
672 ctx_layer->prop.destHeight = (t_ilm_uint)height;
674 if (ctx_layer->notification != NULL) {
675 ctx_layer->notification(ctx_layer->id_layer,
677 ILM_NOTIFICATION_DEST_RECT);
682 controller_layer_listener_configuration(void *data,
683 struct ivi_controller_layer *controller,
687 struct layer_context *ctx_layer = data;
689 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
690 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
694 controller_layer_listener_orientation(void *data,
695 struct ivi_controller_layer *controller,
698 ilmOrientation ilmorientation = ILM_ZERO;
699 struct layer_context *ctx_layer = data;
701 switch(orientation) {
702 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
703 ilmorientation = ILM_ZERO;
705 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
706 ilmorientation = ILM_NINETY;
708 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
709 ilmorientation = ILM_ONEHUNDREDEIGHTY;
711 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
712 ilmorientation = ILM_TWOHUNDREDSEVENTY;
718 ctx_layer->prop.orientation = ilmorientation;
720 if (ctx_layer->notification != NULL) {
721 ctx_layer->notification(ctx_layer->id_layer,
723 ILM_NOTIFICATION_ORIENTATION);
728 controller_layer_listener_screen(void *data,
729 struct ivi_controller_layer *controller,
730 struct wl_output *output)
732 struct layer_context *ctx_layer = data;
734 if (output == NULL) {
735 remove_orderlayer_from_screen(ctx_layer);
737 add_orderlayer_to_screen(ctx_layer, output);
742 controller_layer_listener_destroyed(void *data,
743 struct ivi_controller_layer *controller)
745 struct layer_context *ctx_layer = data;
746 wl_list_remove(&ctx_layer->link);
750 static struct ivi_controller_layer_listener controller_layer_listener =
752 controller_layer_listener_visibility,
753 controller_layer_listener_opacity,
754 controller_layer_listener_source_rectangle,
755 controller_layer_listener_destination_rectangle,
756 controller_layer_listener_configuration,
757 controller_layer_listener_orientation,
758 controller_layer_listener_screen,
759 controller_layer_listener_destroyed
763 add_ordersurface_to_layer(struct surface_context *ctx_surf,
764 struct ivi_controller_layer *layer)
766 struct layer_context *ctx_layer = NULL;
767 struct surface_context *link = NULL;
770 ctx_layer = ivi_controller_layer_get_user_data(layer);
772 wl_list_for_each(link, &ctx_layer->order.list_surface, order.link) {
773 if (link == ctx_surf) {
780 wl_list_init(&ctx_surf->order.link);
781 wl_list_insert(&ctx_layer->order.list_surface, &ctx_surf->order.link);
786 remove_ordersurface_from_layer(struct surface_context *ctx_surf)
788 wl_list_remove(&ctx_surf->order.link);
789 wl_list_init(&ctx_surf->order.link);
793 controller_surface_listener_visibility(void *data,
794 struct ivi_controller_surface *controller,
797 struct surface_context *ctx_surf = data;
799 ctx_surf->prop.visibility = (t_ilm_bool)visibility;
801 if (ctx_surf->notification != NULL) {
802 ctx_surf->notification(ctx_surf->id_surface,
804 ILM_NOTIFICATION_VISIBILITY);
809 controller_surface_listener_opacity(void *data,
810 struct ivi_controller_surface *controller,
813 struct surface_context *ctx_surf = data;
815 ctx_surf->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
817 if (ctx_surf->notification != NULL) {
818 ctx_surf->notification(ctx_surf->id_surface,
820 ILM_NOTIFICATION_OPACITY);
825 controller_surface_listener_configuration(void *data,
826 struct ivi_controller_surface *controller,
830 struct surface_context *ctx_surf = data;
832 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
833 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
837 controller_surface_listener_source_rectangle(void *data,
838 struct ivi_controller_surface *controller,
844 struct surface_context *ctx_surf = data;
846 ctx_surf->prop.sourceX = (t_ilm_uint)x;
847 ctx_surf->prop.sourceY = (t_ilm_uint)y;
848 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
849 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
850 if (ctx_surf->prop.origSourceWidth == 0) {
851 ctx_surf->prop.origSourceWidth = (t_ilm_uint)width;
853 if (ctx_surf->prop.origSourceHeight == 0) {
854 ctx_surf->prop.origSourceHeight = (t_ilm_uint)height;
857 if (ctx_surf->notification != NULL) {
858 ctx_surf->notification(ctx_surf->id_surface,
860 ILM_NOTIFICATION_SOURCE_RECT);
865 controller_surface_listener_destination_rectangle(void *data,
866 struct ivi_controller_surface *controller,
872 struct surface_context *ctx_surf = data;
874 ctx_surf->prop.destX = (t_ilm_uint)x;
875 ctx_surf->prop.destY = (t_ilm_uint)y;
876 ctx_surf->prop.destWidth = (t_ilm_uint)width;
877 ctx_surf->prop.destHeight = (t_ilm_uint)height;
879 if (ctx_surf->notification != NULL) {
880 ctx_surf->notification(ctx_surf->id_surface,
882 ILM_NOTIFICATION_DEST_RECT);
887 controller_surface_listener_orientation(void *data,
888 struct ivi_controller_surface *controller,
891 struct surface_context *ctx_surf = data;
892 ilmOrientation ilmorientation = ILM_ZERO;
894 switch (orientation) {
895 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
896 ilmorientation = ILM_ZERO;
898 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
899 ilmorientation = ILM_NINETY;
901 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
902 ilmorientation = ILM_ONEHUNDREDEIGHTY;
904 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
905 ilmorientation = ILM_TWOHUNDREDSEVENTY;
911 ctx_surf->prop.orientation = ilmorientation;
913 if (ctx_surf->notification != NULL) {
914 ctx_surf->notification(ctx_surf->id_surface,
916 ILM_NOTIFICATION_ORIENTATION);
921 controller_surface_listener_pixelformat(void *data,
922 struct ivi_controller_surface *controller,
925 struct surface_context *ctx_surf = data;
927 ctx_surf->prop.pixelformat = (t_ilm_uint)pixelformat;
931 controller_surface_listener_layer(void *data,
932 struct ivi_controller_surface *controller,
933 struct ivi_controller_layer *layer)
935 struct surface_context *ctx_surf = data;
938 remove_ordersurface_from_layer(ctx_surf);
940 add_ordersurface_to_layer(ctx_surf, layer);
945 controller_surface_listener_stats(void *data,
946 struct ivi_controller_surface *controller,
947 uint32_t redraw_count,
948 uint32_t frame_count,
949 uint32_t update_count,
951 const char *process_name)
953 struct surface_context *ctx_surf = data;
956 ctx_surf->prop.drawCounter = (t_ilm_uint)redraw_count;
957 ctx_surf->prop.frameCounter = (t_ilm_uint)frame_count;
958 ctx_surf->prop.updateCounter = (t_ilm_uint)update_count;
959 ctx_surf->prop.creatorPid = (t_ilm_uint)pid;
963 controller_surface_listener_destroyed(void *data,
964 struct ivi_controller_surface *controller)
966 struct surface_context *ctx_surf = data;
968 wl_list_remove(&ctx_surf->link);
973 controller_surface_listener_content(void *data,
974 struct ivi_controller_surface *controller,
975 int32_t content_state)
977 // if client surface (=content) was removed with ilm_surfaceDestroy()
978 // the expected behavior within ILM API mandates a full removal
979 // of the surface from the scene. We must remove the controller
981 if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED == content_state)
983 struct surface_context *ctx_surf = data;
985 ivi_controller_surface_destroy(controller, 1);
987 wl_list_remove(&ctx_surf->link);
993 controller_surface_listener_input_focus(void *data,
994 struct ivi_controller_surface *controller,
1002 static struct ivi_controller_surface_listener controller_surface_listener=
1004 controller_surface_listener_visibility,
1005 controller_surface_listener_opacity,
1006 controller_surface_listener_source_rectangle,
1007 controller_surface_listener_destination_rectangle,
1008 controller_surface_listener_configuration,
1009 controller_surface_listener_orientation,
1010 controller_surface_listener_pixelformat,
1011 controller_surface_listener_layer,
1012 controller_surface_listener_stats,
1013 controller_surface_listener_destroyed,
1014 controller_surface_listener_content,
1015 controller_surface_listener_input_focus
1019 controller_listener_layer(void *data,
1020 struct ivi_controller *controller,
1023 struct wayland_context *ctx = data;
1025 if (wayland_controller_is_inside_layer_list(&ctx->list_layer, id_layer))
1030 (void) create_controller_layer(ctx, 0, 0, id_layer);
1034 controller_listener_surface(void *data,
1035 struct ivi_controller *controller,
1036 uint32_t id_surface)
1038 struct wayland_context *ctx = data;
1039 struct surface_context *ctx_surf = NULL;
1040 int32_t is_inside = 0;
1042 is_inside = wayland_controller_is_inside_surface_list(
1043 &ctx->list_surface, id_surface);
1045 if (is_inside != 0) {
1046 fprintf(stderr, "invalid id_surface in controller_listener_surface\n");
1050 ctx_surf = calloc(1, sizeof *ctx_surf);
1051 if (ctx_surf == NULL) {
1052 fprintf(stderr, "Failed to allocate memory for surface_context\n");
1056 ctx_surf->controller = ivi_controller_surface_create(
1057 controller, id_surface);
1058 if (ctx_surf->controller == NULL) {
1060 fprintf(stderr, "Failed to create controller surface\n");
1063 ctx_surf->id_surface = id_surface;
1064 ctx_surf->prop.inputDevicesAcceptance = ILM_INPUT_DEVICE_ALL;
1065 ctx_surf->ctx = ctx;
1067 wl_list_init(&ctx_surf->link);
1068 wl_list_insert(&ctx->list_surface, &ctx_surf->link);
1069 wl_list_init(&ctx_surf->order.link);
1070 ivi_controller_surface_add_listener(ctx_surf->controller,
1071 &controller_surface_listener, ctx_surf);
1075 controller_listener_error(void *data,
1076 struct ivi_controller *ivi_controller,
1078 int32_t object_type,
1080 const char *error_text)
1083 (void)ivi_controller;
1091 controller_listener_screen(void *data,
1092 struct ivi_controller *ivi_controller,
1094 struct ivi_controller_screen *controller_screen)
1096 struct wayland_context *ctx = data;
1097 struct screen_context *ctx_screen;
1098 (void)ivi_controller;
1100 ctx_screen = get_screen_context_by_serverid(ctx, id_screen);
1101 if (ctx_screen == NULL) {
1102 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1105 ctx_screen->controller = controller_screen;
1108 static struct ivi_controller_listener controller_listener= {
1109 controller_listener_screen,
1110 controller_listener_layer,
1111 controller_listener_surface,
1112 controller_listener_error
1116 registry_handle_control(void *data,
1117 struct wl_registry *registry,
1118 uint32_t name, const char *interface,
1121 struct wayland_context *ctx = data;
1124 if (strcmp(interface, "ivi_controller") == 0) {
1125 ctx->controller = wl_registry_bind(registry, name,
1126 &ivi_controller_interface, 1);
1127 if (ctx->controller == NULL) {
1128 fprintf(stderr, "Failed to registry bind ivi_controller\n");
1131 if (ivi_controller_add_listener(ctx->controller,
1132 &controller_listener,
1134 fprintf(stderr, "Failed to add ivi_controller listener\n");
1137 } else if (strcmp(interface, "wl_output") == 0) {
1139 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
1140 struct wl_proxy *pxy = NULL;
1142 if (ctx_scrn == NULL) {
1143 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1146 wl_list_init(&ctx_scrn->link);
1147 ctx_scrn->output = wl_registry_bind(registry, name,
1148 &wl_output_interface, 1);
1149 if (ctx_scrn->output == NULL) {
1151 fprintf(stderr, "Failed to registry bind wl_output\n");
1155 if (wl_output_add_listener(ctx_scrn->output,
1159 fprintf(stderr, "Failed to add wl_output listener\n");
1163 pxy = (struct wl_proxy*)ctx_scrn->output;
1164 ctx_scrn->id_from_server = wl_proxy_get_id(pxy);
1165 ctx_scrn->id_screen = ctx->num_screen;
1167 wl_list_init(&ctx_scrn->order.list_layer);
1168 wl_list_init(&ctx_scrn->order.link);
1169 wl_list_insert(&ctx->list_screen, &ctx_scrn->link);
1173 static const struct wl_registry_listener
1174 registry_control_listener= {
1175 registry_handle_control,
1179 static struct ilm_control_context ilm_context = {0};
1182 destroy_control_resources(void)
1184 struct ilm_control_context *ctx = &ilm_context;
1185 struct screen_context *ctx_scrn;
1186 struct screen_context *next;
1188 wl_list_for_each_safe(ctx_scrn, next, &ctx->wl.list_screen, link) {
1189 if (ctx_scrn->output != NULL) {
1190 wl_list_remove(&ctx_scrn->link);
1191 wl_output_destroy(ctx_scrn->output);
1195 if (ctx->wl.controller != NULL) {
1196 ivi_controller_destroy(ctx->wl.controller);
1197 ctx->wl.controller = NULL;
1200 wl_display_flush(ctx->wl.display);
1202 wl_event_queue_destroy(ctx->wl.queue);
1203 ctx->wl.queue = NULL;
1205 if (0 != pthread_mutex_destroy(&ctx->mutex)) {
1206 fprintf(stderr, "failed to destroy pthread_mutex\n");
1211 wayland_destroy(void)
1213 struct ilm_control_context *ctx = &ilm_context;
1214 pthread_cancel(ctx->thread);
1215 if (0 != pthread_join(ctx->thread, NULL)) {
1216 fprintf(stderr, "failed to join control thread\n");
1218 destroy_control_resources();
1219 memset(ctx, 0, sizeof *ctx);
1222 static ilmErrorTypes
1223 wayland_init(t_ilm_nativedisplay nativedisplay)
1225 struct ilm_control_context *ctx = &ilm_context;
1227 if (ctx->initialized)
1229 fprintf(stderr, "Already initialized!\n");
1233 if (nativedisplay == 0) {
1234 return ILM_ERROR_INVALID_ARGUMENTS;
1237 memset(ctx, 0, sizeof *ctx);
1239 ctx->wl.display = (struct wl_display*)nativedisplay;
1241 wl_list_init(&ctx->wl.list_screen);
1242 wl_list_init(&ctx->wl.list_layer);
1243 wl_list_init(&ctx->wl.list_surface);
1246 pthread_mutexattr_t a;
1247 if (pthread_mutexattr_init(&a) != 0)
1252 if (pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE) != 0)
1254 pthread_mutexattr_destroy(&a);
1258 if (pthread_mutex_init(&ctx->mutex, &a) != 0)
1260 pthread_mutexattr_destroy(&a);
1261 fprintf(stderr, "failed to initialize pthread_mutex\n");
1265 pthread_mutexattr_destroy(&a);
1268 return init_control() == 0 ? ILM_SUCCESS : ILM_FAILED;
1271 static void cancel_read(void *d)
1273 wl_display_cancel_read(d);
1277 control_thread(void *p_ret)
1279 struct ilm_control_context *ctx = &ilm_context;
1280 struct wayland_context *wl = &ctx->wl;
1281 struct wl_display *display = wl->display;
1282 struct wl_event_queue *queue = wl->queue;
1283 int fd = wl_display_get_fd(display);
1289 if (wl_display_prepare_read_queue(display, queue) != 0)
1292 wl_display_dispatch_queue_pending(display, queue);
1293 unlock_context(ctx);
1298 if (wl_display_flush(display) == -1)
1306 pfd.events = POLLIN;
1311 pthread_cleanup_push(cancel_read, display);
1312 pollret = poll(&pfd, 1, -1);
1313 pthread_cleanup_pop(0);
1315 if (pollret != -1 && (pfd.revents & POLLIN))
1317 wl_display_read_events(display);
1320 int ret = wl_display_dispatch_queue_pending(display, queue);
1321 unlock_context(ctx);
1330 wl_display_cancel_read(display);
1340 struct ilm_control_context *ctx = &ilm_context;
1341 struct wayland_context *wl = &ctx->wl;
1345 wl_list_init(&ctx->list_nativehandle);
1347 wl->queue = wl_display_create_queue(wl->display);
1349 /* registry_add_listener for request by ivi-controller */
1350 wl->registry = wl_display_get_registry(wl->display);
1351 if (wl->registry == NULL) {
1352 fprintf(stderr, "Failed to get registry\n");
1355 wl_proxy_set_queue((void*)wl->registry, wl->queue);
1357 if (wl_registry_add_listener(wl->registry,
1358 ®istry_control_listener, ctx)) {
1359 fprintf(stderr, "Failed to add registry listener\n");
1363 // first level objects; ivi_controller
1364 display_roundtrip_queue(wl->display, wl->queue);
1365 // second level object: ivi_controller_surfaces/layers
1366 display_roundtrip_queue(wl->display, wl->queue);
1367 // third level objects: ivi_controller_surfaces/layers properties
1368 display_roundtrip_queue(wl->display, wl->queue);
1370 ret = pthread_create(&ctx->thread, NULL, control_thread, NULL);
1373 fprintf(stderr, "Failed to start internal receive thread. returned %d\n", ret);
1377 ctx->initialized = true;
1382 static struct ilm_control_context*
1383 sync_and_acquire_instance(void)
1385 struct ilm_control_context *ctx = &ilm_context;
1387 display_roundtrip_queue(ctx->wl.display, ctx->wl.queue);
1391 static void release_instance(void)
1393 struct ilm_control_context *ctx = &ilm_context;
1394 unlock_context(ctx);
1398 gen_layer_id(struct ilm_control_context *ctx)
1400 struct layer_context *ctx_layer = NULL;
1403 if (wl_list_length(&ctx->wl.list_layer) == 0) {
1404 ctx->internal_id_layer++;
1405 return ctx->internal_id_layer;
1407 wl_list_for_each(ctx_layer, &ctx->wl.list_layer, link) {
1408 if (ctx_layer->id_layer == ctx->internal_id_layer) {
1414 return ctx->internal_id_layer;
1417 ctx->internal_id_layer++;
1421 static struct surface_context*
1422 get_surface_context(struct wayland_context *ctx,
1423 uint32_t id_surface)
1425 struct surface_context *ctx_surf = NULL;
1427 if (ctx->controller == NULL) {
1428 fprintf(stderr, "controller is not initialized in ilmControl\n");
1432 wl_list_for_each(ctx_surf, &ctx->list_surface, link) {
1433 if (ctx_surf->id_surface == id_surface) {
1438 fprintf(stderr, "failed to get surface context in ilmControl\n");
1442 static struct screen_context*
1443 get_screen_context_by_id(struct wayland_context *ctx, uint32_t id_screen)
1445 struct screen_context *ctx_scrn = NULL;
1447 if (ctx->controller == NULL) {
1448 fprintf(stderr, "get_screen_context_by_id: controller is NULL\n");
1452 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
1453 if (ctx_scrn->id_screen == id_screen) {
1460 static ilmErrorTypes
1461 wayland_getPropertiesOfLayer(t_ilm_uint layerID,
1462 struct ilmLayerProperties* pLayerProperties)
1464 ilmErrorTypes returnValue = ILM_FAILED;
1465 struct ilm_control_context *ctx = sync_and_acquire_instance();
1466 struct layer_context *ctx_layer = NULL;
1468 if (pLayerProperties != NULL) {
1470 ctx_layer = (struct layer_context*)
1471 wayland_controller_get_layer_context(
1472 &ctx->wl, (uint32_t)layerID);
1474 if (ctx_layer != NULL) {
1475 *pLayerProperties = ctx_layer->prop;
1476 returnValue = ILM_SUCCESS;
1485 create_layerids(struct screen_context *ctx_screen,
1486 t_ilm_layer **layer_ids, t_ilm_uint *layer_count)
1488 struct layer_context *ctx_layer = NULL;
1489 t_ilm_layer *ids = NULL;
1491 *layer_count = wl_list_length(&ctx_screen->order.list_layer);
1492 if (*layer_count == 0) {
1497 *layer_ids = malloc(*layer_count * sizeof(t_ilm_layer));
1498 if (*layer_ids == NULL) {
1499 fprintf(stderr, "memory insufficient for layerids\n");
1505 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link) {
1506 *ids = (t_ilm_layer)ctx_layer->id_layer;
1511 static ilmErrorTypes
1512 wayland_getPropertiesOfScreen(t_ilm_display screenID,
1513 struct ilmScreenProperties* pScreenProperties)
1515 ilmErrorTypes returnValue = ILM_FAILED;
1517 if (! pScreenProperties)
1519 return ILM_ERROR_INVALID_ARGUMENTS;
1522 struct ilm_control_context *ctx = sync_and_acquire_instance();
1524 struct screen_context *ctx_screen = NULL;
1525 ctx_screen = get_screen_context_by_id(&ctx->wl, (uint32_t)screenID);
1526 if (ctx_screen != NULL) {
1527 *pScreenProperties = ctx_screen->prop;
1528 create_layerids(ctx_screen, &pScreenProperties->layerIds,
1529 &pScreenProperties->layerCount);
1530 returnValue = ILM_SUCCESS;
1537 static ilmErrorTypes
1538 wayland_getNumberOfHardwareLayers(t_ilm_uint screenID,
1539 t_ilm_uint* pNumberOfHardwareLayers)
1543 if (pNumberOfHardwareLayers != NULL) {
1544 *pNumberOfHardwareLayers = 0;
1551 static ilmErrorTypes
1552 wayland_getScreenIDs(t_ilm_uint* pNumberOfIDs, t_ilm_uint** ppIDs)
1554 ilmErrorTypes returnValue = ILM_FAILED;
1555 struct ilm_control_context *ctx = sync_and_acquire_instance();
1557 if ((pNumberOfIDs != NULL) && (ppIDs != NULL)) {
1558 struct screen_context *ctx_scrn = NULL;
1559 t_ilm_uint length = wl_list_length(&ctx->wl.list_screen);
1562 *ppIDs = (t_ilm_uint*)malloc(length * sizeof *ppIDs);
1563 if (*ppIDs != NULL) {
1564 t_ilm_uint* ids = *ppIDs;
1565 wl_list_for_each(ctx_scrn, &ctx->wl.list_screen, link) {
1566 *ids = ctx_scrn->id_screen;
1569 *pNumberOfIDs = length;
1571 returnValue = ILM_SUCCESS;
1579 static ilmErrorTypes
1580 wayland_getLayerIDs(t_ilm_int* pLength, t_ilm_layer** ppArray)
1582 ilmErrorTypes returnValue = ILM_FAILED;
1583 struct ilm_control_context *ctx = sync_and_acquire_instance();
1585 if ((pLength != NULL) && (ppArray != NULL)) {
1586 struct layer_context *ctx_layer = NULL;
1587 t_ilm_uint length = wl_list_length(&ctx->wl.list_layer);
1590 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
1591 if (*ppArray != NULL) {
1592 // compositor sends layers in opposite order
1593 // write ids from back to front to turn them around
1594 t_ilm_layer* ids = *ppArray;
1595 wl_list_for_each_reverse(ctx_layer, &ctx->wl.list_layer, link)
1597 *ids = ctx_layer->id_layer;
1602 returnValue = ILM_SUCCESS;
1610 static ilmErrorTypes
1611 wayland_getLayerIDsOnScreen(t_ilm_uint screenId,
1613 t_ilm_layer** ppArray)
1615 ilmErrorTypes returnValue = ILM_FAILED;
1616 struct ilm_control_context *ctx = sync_and_acquire_instance();
1618 if ((pLength != NULL) && (ppArray != NULL)) {
1619 struct screen_context *ctx_screen = NULL;
1620 ctx_screen = get_screen_context_by_id(&ctx->wl, screenId);
1621 if (ctx_screen != NULL) {
1622 struct layer_context *ctx_layer = NULL;
1623 t_ilm_int length = wl_list_length(&ctx_screen->order.list_layer);
1627 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
1628 if (*ppArray != NULL) {
1629 // compositor sends layers in opposite order
1630 // write ids from back to front to turn them around
1631 t_ilm_layer* ids = *ppArray;
1632 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link)
1634 *ids = ctx_layer->id_layer;
1646 returnValue = ILM_SUCCESS;
1654 static ilmErrorTypes
1655 wayland_getSurfaceIDs(t_ilm_int* pLength, t_ilm_surface** ppArray)
1657 ilmErrorTypes returnValue = ILM_FAILED;
1658 struct ilm_control_context *ctx = sync_and_acquire_instance();
1660 if ((pLength != NULL) && (ppArray != NULL)) {
1661 struct surface_context *ctx_surf = NULL;
1662 t_ilm_uint length = wl_list_length(&ctx->wl.list_surface);
1665 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
1666 if (*ppArray != NULL) {
1667 t_ilm_surface* ids = *ppArray;
1668 wl_list_for_each_reverse(ctx_surf, &ctx->wl.list_surface, link) {
1669 *ids = ctx_surf->id_surface;
1674 returnValue = ILM_SUCCESS;
1682 static ilmErrorTypes
1683 wayland_getSurfaceIDsOnLayer(t_ilm_layer layer,
1685 t_ilm_surface** ppArray)
1687 struct ilm_control_context *ctx = sync_and_acquire_instance();
1688 struct layer_context *ctx_layer = NULL;
1689 struct surface_context *ctx_surf = NULL;
1690 t_ilm_uint length = 0;
1691 t_ilm_surface* ids = NULL;
1693 if ((pLength == NULL) || (ppArray == NULL)) {
1698 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1699 &ctx->wl, (uint32_t)layer);
1701 if (ctx_layer == NULL) {
1706 length = wl_list_length(&ctx_layer->order.list_surface);
1707 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
1708 if (*ppArray == NULL) {
1714 wl_list_for_each_reverse(ctx_surf, &ctx_layer->order.list_surface, order.link) {
1715 *ids = (t_ilm_surface)ctx_surf->id_surface;
1724 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid)
1726 struct layer_context *ctx_layer = calloc(1, sizeof *ctx_layer);
1727 if (ctx_layer == NULL) {
1728 fprintf(stderr, "Failed to allocate memory for layer_context\n");
1732 ctx_layer->controller = ivi_controller_layer_create(
1734 layerid, width, height);
1735 if (ctx_layer->controller == NULL) {
1736 fprintf(stderr, "Failed to create layer\n");
1740 ctx_layer->id_layer = layerid;
1741 ctx_layer->ctx = ctx;
1743 wl_list_init(&ctx_layer->link);
1744 wl_list_insert(&ctx->list_layer, &ctx_layer->link);
1745 wl_list_init(&ctx_layer->order.link);
1746 wl_list_init(&ctx_layer->order.list_surface);
1748 ivi_controller_layer_add_listener(ctx_layer->controller,
1749 &controller_layer_listener, ctx_layer);
1754 static ilmErrorTypes
1755 wayland_layerCreateWithDimension(t_ilm_layer* pLayerId,
1759 ilmErrorTypes returnValue = ILM_FAILED;
1760 struct ilm_control_context *ctx = sync_and_acquire_instance();
1761 uint32_t layerid = 0;
1762 int32_t is_inside = 0;
1765 if (pLayerId == NULL) {
1769 if (*pLayerId != INVALID_ID) {
1770 /* Return failed, if layerid is already inside list_layer */
1771 is_inside = wayland_controller_is_inside_layer_list(
1772 &ctx->wl.list_layer, *pLayerId);
1773 if (0 != is_inside) {
1774 fprintf(stderr, "layerid=%d is already used.\n", *pLayerId);
1777 layerid = *pLayerId;
1780 /* Generate ID, if layerid is INVALID_ID */
1781 layerid = gen_layer_id(ctx);
1782 *pLayerId = layerid;
1785 if (create_controller_layer(&ctx->wl, width, height, layerid) == 0)
1787 returnValue = ILM_SUCCESS;
1795 static ilmErrorTypes
1796 wayland_layerRemove(t_ilm_layer layerId)
1798 ilmErrorTypes returnValue = ILM_FAILED;
1799 struct ilm_control_context *ctx = sync_and_acquire_instance();
1800 struct layer_context *ctx_layer = NULL;
1801 struct layer_context *ctx_next = NULL;
1803 wl_list_for_each_safe(ctx_layer, ctx_next,
1804 &ctx->wl.list_layer, link) {
1805 if (ctx_layer->id_layer == layerId) {
1806 ivi_controller_layer_destroy(ctx_layer->controller, 1);
1808 wl_list_remove(&ctx_layer->link);
1811 returnValue = ILM_SUCCESS;
1820 static ilmErrorTypes
1821 wayland_layerGetType(t_ilm_layer layerId, ilmLayerType* pLayerType)
1825 return ILM_ERROR_INVALID_ARGUMENTS;
1828 struct ilm_control_context *ctx = sync_and_acquire_instance();
1830 *pLayerType = wayland_controller_is_inside_layer_list(&ctx->wl.list_layer, layerId) ?
1831 ILM_LAYERTYPE_SOFTWARE2D :
1832 ILM_LAYERTYPE_UNKNOWN;
1835 return ILM_SUCCESS; // even if non existent?
1838 static ilmErrorTypes
1839 wayland_layerSetVisibility(t_ilm_layer layerId, t_ilm_bool newVisibility)
1841 ilmErrorTypes returnValue = ILM_FAILED;
1842 struct ilm_control_context *ctx = sync_and_acquire_instance();
1843 struct layer_context *ctx_layer = NULL;
1845 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1846 &ctx->wl, (uint32_t)layerId);
1848 if (ctx_layer != NULL) {
1849 uint32_t visibility = 0;
1850 if (newVisibility == ILM_TRUE) {
1853 ivi_controller_layer_set_visibility(ctx_layer->controller,
1855 returnValue = ILM_SUCCESS;
1862 static ilmErrorTypes
1863 wayland_layerGetVisibility(t_ilm_layer layerId, t_ilm_bool *pVisibility)
1865 ilmErrorTypes returnValue = ILM_FAILED;
1866 struct ilm_control_context *ctx = sync_and_acquire_instance();
1868 if (pVisibility != NULL) {
1869 struct layer_context *ctx_layer = NULL;
1871 ctx_layer = (struct layer_context*)
1872 wayland_controller_get_layer_context(
1873 &ctx->wl, (uint32_t)layerId);
1875 if (ctx_layer != NULL) {
1876 *pVisibility = ctx_layer->prop.visibility;
1877 returnValue = ILM_SUCCESS;
1885 static ilmErrorTypes
1886 wayland_layerSetOpacity(t_ilm_layer layerId, t_ilm_float opacity)
1888 ilmErrorTypes returnValue = ILM_FAILED;
1889 struct ilm_control_context *ctx = sync_and_acquire_instance();
1890 struct layer_context *ctx_layer = NULL;
1892 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1893 &ctx->wl, (uint32_t)layerId);
1895 if (ctx_layer != NULL) {
1896 wl_fixed_t opacity_fixed = wl_fixed_from_double((double)opacity);
1897 ivi_controller_layer_set_opacity(ctx_layer->controller,
1899 returnValue = ILM_SUCCESS;
1906 static ilmErrorTypes
1907 wayland_layerGetOpacity(t_ilm_layer layerId, t_ilm_float *pOpacity)
1909 ilmErrorTypes returnValue = ILM_FAILED;
1910 struct ilm_control_context *ctx = sync_and_acquire_instance();
1912 if (pOpacity != NULL) {
1913 struct layer_context *ctx_layer = NULL;
1915 ctx_layer = (struct layer_context*)
1916 wayland_controller_get_layer_context(
1917 &ctx->wl, (uint32_t)layerId);
1919 if (ctx_layer != NULL) {
1920 *pOpacity = ctx_layer->prop.opacity;
1921 returnValue = ILM_SUCCESS;
1929 static ilmErrorTypes
1930 wayland_layerSetSourceRectangle(t_ilm_layer layerId,
1931 t_ilm_uint x, t_ilm_uint y,
1932 t_ilm_uint width, t_ilm_uint height)
1934 ilmErrorTypes returnValue = ILM_FAILED;
1935 struct ilm_control_context *ctx = sync_and_acquire_instance();
1936 struct layer_context *ctx_layer = NULL;
1938 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1939 &ctx->wl, (uint32_t)layerId);
1941 if (ctx_layer != NULL) {
1942 ivi_controller_layer_set_source_rectangle(ctx_layer->controller,
1947 returnValue = ILM_SUCCESS;
1954 static ilmErrorTypes
1955 wayland_layerSetDestinationRectangle(t_ilm_layer layerId,
1956 t_ilm_int x, t_ilm_int y,
1957 t_ilm_int width, t_ilm_int height)
1959 ilmErrorTypes returnValue = ILM_FAILED;
1960 struct ilm_control_context *ctx = sync_and_acquire_instance();
1961 struct layer_context *ctx_layer = NULL;
1963 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1964 &ctx->wl, (uint32_t)layerId);
1965 if (ctx_layer != NULL) {
1966 ivi_controller_layer_set_destination_rectangle(
1967 ctx_layer->controller,
1968 (uint32_t)x, (uint32_t)y,
1971 returnValue = ILM_SUCCESS;
1978 static ilmErrorTypes
1979 wayland_layerGetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
1981 ilmErrorTypes returnValue = ILM_FAILED;
1982 struct ilm_control_context *ctx = sync_and_acquire_instance();
1983 struct layer_context *ctx_layer = NULL;
1985 if (pDimension != NULL) {
1986 ctx_layer = (struct layer_context*)
1987 wayland_controller_get_layer_context(
1988 &ctx->wl, (uint32_t)layerId);
1989 if (ctx_layer != NULL) {
1990 *pDimension = ctx_layer->prop.destWidth;
1991 *(pDimension + 1) = ctx_layer->prop.destHeight;
1992 returnValue = ILM_SUCCESS;
2000 static ilmErrorTypes
2001 wayland_layerSetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
2003 ilmErrorTypes returnValue = ILM_FAILED;
2004 struct ilm_control_context *ctx = sync_and_acquire_instance();
2005 struct layer_context *ctx_layer = NULL;
2007 if (pDimension != NULL) {
2008 ctx_layer = (struct layer_context*)
2009 wayland_controller_get_layer_context(
2010 &ctx->wl, (uint32_t)layerId);
2011 if (ctx_layer != NULL) {
2012 ivi_controller_layer_set_destination_rectangle(
2013 ctx_layer->controller,
2014 ctx_layer->prop.destX, ctx_layer->prop.destY,
2015 (int32_t)*pDimension, (int32_t)*(pDimension + 1));
2016 returnValue = ILM_SUCCESS;
2024 static ilmErrorTypes
2025 wayland_layerGetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2027 ilmErrorTypes returnValue = ILM_FAILED;
2028 struct ilm_control_context *ctx = sync_and_acquire_instance();
2029 struct layer_context *ctx_layer = NULL;
2031 if (pPosition != NULL) {
2032 ctx_layer = (struct layer_context*)
2033 wayland_controller_get_layer_context(
2034 &ctx->wl, (uint32_t)layerId);
2035 if (ctx_layer != NULL) {
2036 *pPosition = ctx_layer->prop.destX;
2037 *(pPosition + 1) = ctx_layer->prop.destY;
2038 returnValue = ILM_SUCCESS;
2046 static ilmErrorTypes
2047 wayland_layerSetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2049 ilmErrorTypes returnValue = ILM_FAILED;
2050 struct ilm_control_context *ctx = sync_and_acquire_instance();
2051 struct layer_context *ctx_layer = NULL;
2053 if (pPosition != NULL) {
2054 ctx_layer = (struct layer_context*)
2055 wayland_controller_get_layer_context(
2056 &ctx->wl, (uint32_t)layerId);
2057 if (ctx_layer != NULL) {
2058 ivi_controller_layer_set_destination_rectangle(
2059 ctx_layer->controller,
2060 (int32_t)*pPosition, (int32_t)*(pPosition + 1),
2061 ctx_layer->prop.destWidth, ctx_layer->prop.destHeight);
2062 returnValue = ILM_SUCCESS;
2070 static ilmErrorTypes
2071 wayland_layerSetOrientation(t_ilm_layer layerId, ilmOrientation orientation)
2073 ilmErrorTypes returnValue = ILM_FAILED;
2074 struct ilm_control_context *ctx = sync_and_acquire_instance();
2075 struct layer_context *ctx_layer = NULL;
2076 int32_t iviorientation = 0;
2079 switch(orientation) {
2081 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2084 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2086 case ILM_ONEHUNDREDEIGHTY:
2087 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2089 case ILM_TWOHUNDREDSEVENTY:
2090 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2093 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2097 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2098 &ctx->wl, (uint32_t)layerId);
2099 if (ctx_layer == NULL) {
2100 returnValue = ILM_FAILED;
2104 ivi_controller_layer_set_orientation(ctx_layer->controller,
2107 returnValue = ILM_SUCCESS;
2114 static ilmErrorTypes
2115 wayland_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrientation)
2117 ilmErrorTypes returnValue = ILM_FAILED;
2118 struct ilm_control_context *ctx = sync_and_acquire_instance();
2119 struct layer_context *ctx_layer = NULL;
2121 if (pOrientation != NULL) {
2122 ctx_layer = (struct layer_context*)
2123 wayland_controller_get_layer_context(
2124 &ctx->wl, (uint32_t)layerId);
2125 if (ctx_layer != NULL) {
2126 *pOrientation = ctx_layer->prop.orientation;
2127 returnValue = ILM_SUCCESS;
2135 static ilmErrorTypes
2136 wayland_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
2144 static ilmErrorTypes
2145 wayland_layerSetRenderOrder(t_ilm_layer layerId,
2146 t_ilm_surface *pSurfaceId,
2149 ilmErrorTypes returnValue = ILM_FAILED;
2150 struct ilm_control_context *ctx = sync_and_acquire_instance();
2151 struct layer_context *ctx_layer = NULL;
2153 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2154 &ctx->wl, (uint32_t)layerId);
2158 struct wl_array ids;
2159 wl_array_init(&ids);
2160 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2162 for (i = 0; i < number; i++) pids[i] = (uint32_t)pSurfaceId[i];
2163 ivi_controller_layer_set_render_order(ctx_layer->controller, &ids);
2164 wl_array_release(&ids);
2165 returnValue = ILM_SUCCESS;
2172 static ilmErrorTypes
2173 wayland_layerGetCapabilities(t_ilm_layer layerId,
2174 t_ilm_layercapabilities *pCapabilities)
2177 (void)pCapabilities;
2182 static ilmErrorTypes
2183 wayland_layerTypeGetCapabilities(ilmLayerType layerType,
2184 t_ilm_layercapabilities *pCapabilities)
2187 (void)pCapabilities;
2192 static ilmErrorTypes
2193 wayland_surfaceSetVisibility(t_ilm_surface surfaceId, t_ilm_bool newVisibility)
2195 ilmErrorTypes returnValue = ILM_FAILED;
2196 struct ilm_control_context *ctx = sync_and_acquire_instance();
2197 struct surface_context *ctx_surf = NULL;
2198 uint32_t visibility = 0;
2200 if (newVisibility == ILM_TRUE) {
2203 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2205 ivi_controller_surface_set_visibility(ctx_surf->controller,
2207 returnValue = ILM_SUCCESS;
2214 static ilmErrorTypes
2215 wayland_surfaceSetOpacity(t_ilm_surface surfaceId, t_ilm_float opacity)
2217 ilmErrorTypes returnValue = ILM_FAILED;
2218 struct ilm_control_context *ctx = sync_and_acquire_instance();
2219 struct surface_context *ctx_surf = NULL;
2220 wl_fixed_t opacity_fixed = 0;
2222 opacity_fixed = wl_fixed_from_double((double)opacity);
2223 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2225 ivi_controller_surface_set_opacity(ctx_surf->controller,
2227 returnValue = ILM_SUCCESS;
2234 static ilmErrorTypes
2235 wayland_surfaceGetOpacity(t_ilm_surface surfaceId, t_ilm_float *pOpacity)
2237 ilmErrorTypes returnValue = ILM_FAILED;
2238 struct ilm_control_context *ctx = sync_and_acquire_instance();
2240 if (pOpacity != NULL) {
2241 struct surface_context *ctx_surf = NULL;
2242 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2244 *pOpacity = ctx_surf->prop.opacity;
2245 returnValue = ILM_SUCCESS;
2253 static ilmErrorTypes
2254 wayland_SetKeyboardFocusOn(t_ilm_surface surfaceId)
2256 ilmErrorTypes returnValue = ILM_FAILED;
2258 returnValue = ILM_SUCCESS;
2262 static ilmErrorTypes
2263 wayland_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
2265 ilmErrorTypes returnValue = ILM_FAILED;
2267 returnValue = ILM_SUCCESS;
2271 static ilmErrorTypes
2272 wayland_surfaceSetDestinationRectangle(t_ilm_surface surfaceId,
2273 t_ilm_int x, t_ilm_int y,
2274 t_ilm_int width, t_ilm_int height)
2276 ilmErrorTypes returnValue = ILM_FAILED;
2277 struct ilm_control_context *ctx = sync_and_acquire_instance();
2278 struct surface_context *ctx_surf = NULL;
2280 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2282 ivi_controller_surface_set_destination_rectangle(
2283 ctx_surf->controller,
2284 x, y, width, height);
2285 returnValue = ILM_SUCCESS;
2292 static ilmErrorTypes
2293 wayland_surfaceSetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
2295 ilmErrorTypes returnValue = ILM_FAILED;
2296 struct ilm_control_context *ctx = sync_and_acquire_instance();
2298 if (pDimension != NULL) {
2299 struct surface_context *ctx_surf = NULL;
2300 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2302 uint32_t width = *pDimension;
2303 uint32_t height = *(pDimension + 1);
2304 ivi_controller_surface_set_destination_rectangle(
2305 ctx_surf->controller,
2306 ctx_surf->prop.destX, ctx_surf->prop.destY, width, height);
2307 returnValue = ILM_SUCCESS;
2315 static ilmErrorTypes
2316 wayland_surfaceGetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2318 ilmErrorTypes returnValue = ILM_FAILED;
2319 struct ilm_control_context *ctx = sync_and_acquire_instance();
2321 if (pPosition != NULL) {
2322 struct surface_context *ctx_surf = NULL;
2323 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2325 *pPosition = ctx_surf->prop.destX;
2326 *(pPosition + 1) = ctx_surf->prop.destY;
2327 returnValue = ILM_SUCCESS;
2335 static ilmErrorTypes
2336 wayland_surfaceSetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2338 ilmErrorTypes returnValue = ILM_FAILED;
2339 struct ilm_control_context *ctx = sync_and_acquire_instance();
2341 if (pPosition != NULL) {
2342 struct surface_context *ctx_surf = NULL;
2343 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2345 int32_t destX = (int32_t)*pPosition;
2346 int32_t destY = (int32_t)*(pPosition + 1);
2347 ivi_controller_surface_set_destination_rectangle(
2348 ctx_surf->controller, destX, destY,
2349 ctx_surf->prop.destWidth, ctx_surf->prop.destHeight);
2350 returnValue = ILM_SUCCESS;
2358 static ilmErrorTypes
2359 wayland_surfaceSetOrientation(t_ilm_surface surfaceId,
2360 ilmOrientation orientation)
2362 ilmErrorTypes returnValue = ILM_FAILED;
2363 struct ilm_control_context *ctx = sync_and_acquire_instance();
2364 struct surface_context *ctx_surf = NULL;
2365 int32_t iviorientation = 0;
2368 switch(orientation) {
2370 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2373 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2375 case ILM_ONEHUNDREDEIGHTY:
2376 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2378 case ILM_TWOHUNDREDSEVENTY:
2379 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2382 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2386 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2387 if (ctx_surf == NULL) {
2388 returnValue = ILM_FAILED;
2392 ivi_controller_surface_set_orientation(ctx_surf->controller,
2395 returnValue = ILM_SUCCESS;
2402 static ilmErrorTypes
2403 wayland_surfaceGetOrientation(t_ilm_surface surfaceId,
2404 ilmOrientation *pOrientation)
2406 ilmErrorTypes returnValue = ILM_FAILED;
2407 struct ilm_control_context *ctx = sync_and_acquire_instance();
2409 if (pOrientation != NULL) {
2410 struct surface_context *ctx_surf = NULL;
2411 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2413 *pOrientation = ctx_surf->prop.orientation;
2414 returnValue = ILM_SUCCESS;
2422 static ilmErrorTypes
2423 wayland_surfaceGetPixelformat(t_ilm_layer surfaceId,
2424 ilmPixelFormat *pPixelformat)
2426 ilmErrorTypes returnValue = ILM_FAILED;
2427 struct ilm_control_context *ctx = sync_and_acquire_instance();
2429 if (pPixelformat != NULL) {
2430 struct surface_context *ctx_surf = NULL;
2431 ctx_surf = get_surface_context(&ctx->wl, surfaceId);
2433 *pPixelformat = ctx_surf->prop.pixelformat;
2434 returnValue = ILM_SUCCESS;
2442 static ilmErrorTypes
2443 wayland_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
2451 static ilmErrorTypes
2452 wayland_displaySetRenderOrder(t_ilm_display display,
2453 t_ilm_layer *pLayerId, const t_ilm_uint number)
2455 ilmErrorTypes returnValue = ILM_FAILED;
2456 struct ilm_control_context *ctx = sync_and_acquire_instance();
2457 struct screen_context *ctx_scrn = NULL;
2459 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)display);
2460 if (ctx_scrn != NULL) {
2461 struct wl_array ids;
2462 wl_array_init(&ids);
2463 uint32_t *pids = wl_array_add(&ids, number * sizeof *pids);
2465 for (i = 0; i < number; i++) pids[i] = (uint32_t)pLayerId[i];
2466 ivi_controller_screen_set_render_order(ctx_scrn->controller, &ids);
2467 wl_array_release(&ids);
2468 returnValue = ILM_SUCCESS;
2475 static ilmErrorTypes
2476 wayland_takeScreenshot(t_ilm_uint screen, t_ilm_const_string filename)
2478 ilmErrorTypes returnValue = ILM_FAILED;
2479 struct ilm_control_context *ctx = sync_and_acquire_instance();
2480 struct screen_context *ctx_scrn = NULL;
2482 ctx_scrn = get_screen_context_by_id(&ctx->wl, (uint32_t)screen);
2483 if (ctx_scrn != NULL) {
2484 ivi_controller_screen_screenshot(ctx_scrn->controller,
2486 wl_display_flush(ctx->wl.display);
2487 returnValue = ILM_SUCCESS;
2494 static ilmErrorTypes
2495 wayland_takeLayerScreenshot(t_ilm_const_string filename, t_ilm_layer layerid)
2497 ilmErrorTypes returnValue = ILM_FAILED;
2498 struct ilm_control_context *ctx = sync_and_acquire_instance();
2499 struct layer_context *ctx_layer = NULL;
2501 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2502 &ctx->wl, (uint32_t)layerid);
2503 if (ctx_layer != NULL) {
2504 ivi_controller_layer_screenshot(ctx_layer->controller,
2506 wl_display_flush(ctx->wl.display);
2507 returnValue = ILM_SUCCESS;
2514 static ilmErrorTypes
2515 wayland_takeSurfaceScreenshot(t_ilm_const_string filename,
2516 t_ilm_surface surfaceid)
2518 ilmErrorTypes returnValue = ILM_FAILED;
2519 struct ilm_control_context *ctx = sync_and_acquire_instance();
2520 struct surface_context *ctx_surf = NULL;
2522 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceid);
2524 ivi_controller_surface_screenshot(ctx_surf->controller,
2526 wl_display_flush(ctx->wl.display);
2527 returnValue = ILM_SUCCESS;
2534 static ilmErrorTypes
2535 wayland_SetOptimizationMode(ilmOptimization id, ilmOptimizationMode mode)
2543 static ilmErrorTypes
2544 wayland_GetOptimizationMode(ilmOptimization id, ilmOptimizationMode* pMode)
2553 static ilmErrorTypes
2554 wayland_layerAddNotification(t_ilm_layer layer,
2555 layerNotificationFunc callback)
2557 ilmErrorTypes returnValue = ILM_FAILED;
2558 struct ilm_control_context *ctx = sync_and_acquire_instance();
2559 struct layer_context *ctx_layer = NULL;
2561 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2562 &ctx->wl, (uint32_t)layer);
2563 if (ctx_layer == NULL) {
2564 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2566 ctx_layer->notification = callback;
2568 returnValue = ILM_SUCCESS;
2576 static ilmErrorTypes
2577 wayland_layerRemoveNotification(t_ilm_layer layer)
2579 return wayland_layerAddNotification(layer, NULL);
2583 static ilmErrorTypes
2584 wayland_surfaceAddNotification(t_ilm_surface surface,
2585 surfaceNotificationFunc callback)
2587 ilmErrorTypes returnValue = ILM_FAILED;
2588 struct ilm_control_context *ctx = sync_and_acquire_instance();
2589 struct surface_context *ctx_surf = NULL;
2591 ctx_surf = (struct surface_context*)get_surface_context(
2592 &ctx->wl, (uint32_t)surface);
2593 if (ctx_surf == NULL) {
2594 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2596 ctx_surf->notification = callback;
2598 returnValue = ILM_SUCCESS;
2606 static ilmErrorTypes
2607 wayland_surfaceRemoveNotification(t_ilm_surface surface)
2609 return wayland_surfaceAddNotification(surface, NULL);
2612 static ilmErrorTypes
2613 wayland_getNativeHandle(t_ilm_uint pid, t_ilm_int *n_handle,
2614 t_ilm_nativehandle **p_handles)
2616 struct ilm_control_context *ctx = sync_and_acquire_instance();
2617 struct nativehandle_context *p_nh_ctx = NULL;
2622 wl_list_for_each(p_nh_ctx, &ctx->list_nativehandle, link)
2624 if (p_nh_ctx->pid == pid)
2628 (t_ilm_nativehandle*)malloc(sizeof(t_ilm_nativehandle));
2629 (*p_handles)[0] = p_nh_ctx->nativehandle;
2635 return (*n_handle > 0) ? ILM_SUCCESS : ILM_FAILED;
2638 static ilmErrorTypes
2639 wayland_getPropertiesOfSurface(t_ilm_uint surfaceID,
2640 struct ilmSurfaceProperties* pSurfaceProperties)
2642 ilmErrorTypes returnValue = ILM_FAILED;
2643 struct ilm_control_context *ctx = sync_and_acquire_instance();
2645 if (pSurfaceProperties != NULL) {
2646 struct surface_context *ctx_surf = NULL;
2648 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceID);
2649 if (ctx_surf != NULL) {
2651 *pSurfaceProperties = ctx_surf->prop;
2652 returnValue = ILM_SUCCESS;
2660 static ilmErrorTypes
2661 wayland_layerAddSurface(t_ilm_layer layerId,
2662 t_ilm_surface surfaceId)
2664 ilmErrorTypes returnValue = ILM_FAILED;
2665 struct ilm_control_context *ctx = sync_and_acquire_instance();
2666 struct layer_context *ctx_layer = NULL;
2667 struct surface_context *ctx_surf = NULL;
2669 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2670 &ctx->wl, (uint32_t)layerId);
2671 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2672 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2673 ivi_controller_layer_add_surface(ctx_layer->controller,
2674 ctx_surf->controller);
2675 returnValue = ILM_SUCCESS;
2682 static ilmErrorTypes
2683 wayland_layerRemoveSurface(t_ilm_layer layerId,
2684 t_ilm_surface surfaceId)
2686 ilmErrorTypes returnValue = ILM_FAILED;
2687 struct ilm_control_context *ctx = sync_and_acquire_instance();
2688 struct layer_context *ctx_layer = NULL;
2689 struct surface_context *ctx_surf = NULL;
2691 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2692 &ctx->wl, (uint32_t)layerId);
2693 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2694 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2695 ivi_controller_layer_remove_surface(ctx_layer->controller,
2696 ctx_surf->controller);
2697 returnValue = ILM_SUCCESS;
2704 static ilmErrorTypes
2705 wayland_surfaceGetDimension(t_ilm_surface surfaceId,
2706 t_ilm_uint *pDimension)
2708 ilmErrorTypes returnValue = ILM_FAILED;
2709 struct ilm_control_context *ctx = sync_and_acquire_instance();
2711 if (pDimension != NULL) {
2712 struct surface_context *ctx_surf = NULL;
2714 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2715 if (ctx_surf != NULL) {
2716 *pDimension = (t_ilm_uint)ctx_surf->prop.destWidth;
2717 *(pDimension + 1) = (t_ilm_uint)ctx_surf->prop.destHeight;
2718 returnValue = ILM_SUCCESS;
2726 static ilmErrorTypes
2727 wayland_surfaceGetVisibility(t_ilm_surface surfaceId,
2728 t_ilm_bool *pVisibility)
2730 ilmErrorTypes returnValue = ILM_FAILED;
2731 struct ilm_control_context *ctx = sync_and_acquire_instance();
2732 struct surface_context *ctx_surf = NULL;
2734 if (pVisibility != NULL) {
2735 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2736 if (ctx_surf != NULL) {
2737 *pVisibility = (t_ilm_bool)ctx_surf->prop.visibility;
2738 returnValue = ILM_SUCCESS;
2746 static ilmErrorTypes
2747 wayland_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
2748 t_ilm_int x, t_ilm_int y,
2749 t_ilm_int width, t_ilm_int height)
2751 ilmErrorTypes returnValue = ILM_FAILED;
2752 struct ilm_control_context *ctx = sync_and_acquire_instance();
2753 struct surface_context *ctx_surf = NULL;
2755 ctx_surf = get_surface_context(&ctx->wl, (uint32_t)surfaceId);
2756 if (ctx_surf != NULL) {
2757 if (ctx_surf->controller != NULL) {
2758 ivi_controller_surface_set_source_rectangle(
2759 ctx_surf->controller,
2760 x, y, width, height);
2761 returnValue = ILM_SUCCESS;
2769 static ilmErrorTypes
2770 wayland_commitChanges(void)
2772 ilmErrorTypes returnValue = ILM_FAILED;
2773 struct ilm_control_context *ctx = sync_and_acquire_instance();
2775 if (ctx->wl.controller != NULL) {
2776 ivi_controller_commit_changes(ctx->wl.controller);
2778 if (display_roundtrip_queue(ctx->wl.display, ctx->wl.queue) != -1)
2780 returnValue = ILM_SUCCESS;