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 ****************************************************************************/
26 #include "ilm_common.h"
27 #include "ilm_control_platform.h"
28 #include "wayland-util.h"
29 #include "ivi-controller-client-protocol.h"
31 static ilmErrorTypes wayland_getPropertiesOfLayer(t_ilm_uint layerID,
32 struct ilmLayerProperties* pLayerProperties);
33 static ilmErrorTypes wayland_getPropertiesOfScreen(t_ilm_display screenID,
34 struct ilmScreenProperties* pScreenProperties);
35 static ilmErrorTypes wayland_getNumberOfHardwareLayers(t_ilm_uint screenID,
36 t_ilm_uint* pNumberOfHardwareLayers);
37 static ilmErrorTypes wayland_getScreenIDs(t_ilm_uint* pNumberOfIDs,
39 static ilmErrorTypes wayland_getLayerIDs(t_ilm_int* pLength,
40 t_ilm_layer** ppArray);
41 static ilmErrorTypes wayland_getLayerIDsOnScreen(t_ilm_uint screenId,
42 t_ilm_int* pLength, t_ilm_layer** ppArray);
43 static ilmErrorTypes wayland_getSurfaceIDs(t_ilm_int* pLength,
44 t_ilm_surface** ppArray);
45 static ilmErrorTypes wayland_getSurfaceIDsOnLayer(t_ilm_layer layer,
46 t_ilm_int* pLength, t_ilm_surface** ppArray);
47 static ilmErrorTypes wayland_layerCreateWithDimension(t_ilm_layer* pLayerId,
48 t_ilm_uint width, t_ilm_uint height);
49 static ilmErrorTypes wayland_layerRemove(t_ilm_layer layerId);
50 static ilmErrorTypes wayland_layerGetType(t_ilm_layer layerId,
51 ilmLayerType* pLayerType);
52 static ilmErrorTypes wayland_layerSetVisibility(t_ilm_layer layerId,
53 t_ilm_bool newVisibility);
54 static ilmErrorTypes wayland_layerGetVisibility(t_ilm_layer layerId,
55 t_ilm_bool *pVisibility);
56 static ilmErrorTypes wayland_layerSetOpacity(t_ilm_layer layerId,
58 static ilmErrorTypes wayland_layerGetOpacity(t_ilm_layer layerId,
59 t_ilm_float *pOpacity);
60 static ilmErrorTypes wayland_layerSetSourceRectangle(t_ilm_layer layerId,
61 t_ilm_uint x, t_ilm_uint y,
62 t_ilm_uint width, t_ilm_uint height);
63 static ilmErrorTypes wayland_layerSetDestinationRectangle(t_ilm_layer layerId,
64 t_ilm_int x, t_ilm_int y,
65 t_ilm_int width, t_ilm_int height);
66 static ilmErrorTypes wayland_layerGetDimension(t_ilm_layer layerId,
67 t_ilm_uint *pDimension);
68 static ilmErrorTypes wayland_layerSetDimension(t_ilm_layer layerId,
69 t_ilm_uint *pDimension);
70 static ilmErrorTypes wayland_layerGetPosition(t_ilm_layer layerId,
71 t_ilm_uint *pPosition);
72 static ilmErrorTypes wayland_layerSetPosition(t_ilm_layer layerId,
73 t_ilm_uint *pPosition);
74 static ilmErrorTypes wayland_layerSetOrientation(t_ilm_layer layerId,
75 ilmOrientation orientation);
76 static ilmErrorTypes wayland_layerGetOrientation(t_ilm_layer layerId,
77 ilmOrientation *pOrientation);
78 static ilmErrorTypes wayland_layerSetChromaKey(t_ilm_layer layerId,
80 static ilmErrorTypes wayland_layerSetRenderOrder(t_ilm_layer layerId,
81 t_ilm_layer *pSurfaceId,
83 static ilmErrorTypes wayland_layerGetCapabilities(t_ilm_layer layerId,
84 t_ilm_layercapabilities *pCapabilities);
85 static ilmErrorTypes wayland_layerTypeGetCapabilities(ilmLayerType layerType,
86 t_ilm_layercapabilities *pCapabilities);
87 static ilmErrorTypes wayland_surfaceSetVisibility(t_ilm_surface surfaceId,
88 t_ilm_bool newVisibility);
89 static ilmErrorTypes wayland_surfaceSetOpacity(t_ilm_surface surfaceId,
91 static ilmErrorTypes wayland_surfaceGetOpacity(t_ilm_surface surfaceId,
92 t_ilm_float *pOpacity);
93 static ilmErrorTypes wayland_SetKeyboardFocusOn(t_ilm_surface surfaceId);
94 static ilmErrorTypes wayland_GetKeyboardFocusSurfaceId(
95 t_ilm_surface* pSurfaceId);
96 static ilmErrorTypes wayland_surfaceSetDestinationRectangle(
97 t_ilm_surface surfaceId,
98 t_ilm_int x, t_ilm_int y,
99 t_ilm_int width, t_ilm_int height);
100 static ilmErrorTypes wayland_surfaceSetDimension(t_ilm_surface surfaceId,
101 t_ilm_uint *pDimension);
102 static ilmErrorTypes wayland_surfaceGetPosition(t_ilm_surface surfaceId,
103 t_ilm_uint *pPosition);
104 static ilmErrorTypes wayland_surfaceSetPosition(t_ilm_surface surfaceId,
105 t_ilm_uint *pPosition);
106 static ilmErrorTypes wayland_surfaceSetOrientation(t_ilm_surface surfaceId,
107 ilmOrientation orientation);
108 static ilmErrorTypes wayland_surfaceGetOrientation(t_ilm_surface surfaceId,
109 ilmOrientation *pOrientation);
110 static ilmErrorTypes wayland_surfaceGetPixelformat(t_ilm_layer surfaceId,
111 ilmPixelFormat *pPixelformat);
112 static ilmErrorTypes wayland_surfaceSetChromaKey(t_ilm_surface surfaceId,
114 static ilmErrorTypes wayland_displaySetRenderOrder(t_ilm_display display,
115 t_ilm_layer *pLayerId, const t_ilm_uint number);
116 static ilmErrorTypes wayland_takeScreenshot(t_ilm_uint screen,
117 t_ilm_const_string filename);
118 static ilmErrorTypes wayland_takeLayerScreenshot(t_ilm_const_string filename,
119 t_ilm_layer layerid);
120 static ilmErrorTypes wayland_takeSurfaceScreenshot(t_ilm_const_string filename,
121 t_ilm_surface surfaceid);
122 static ilmErrorTypes wayland_SetOptimizationMode(ilmOptimization id,
123 ilmOptimizationMode mode);
124 static ilmErrorTypes wayland_GetOptimizationMode(ilmOptimization id,
125 ilmOptimizationMode* pMode);
126 static ilmErrorTypes wayland_layerAddNotification(t_ilm_layer layer,
127 layerNotificationFunc callback);
128 static ilmErrorTypes wayland_layerRemoveNotification(t_ilm_layer layer);
129 static ilmErrorTypes wayland_surfaceAddNotification(t_ilm_surface surface,
130 surfaceNotificationFunc callback);
131 static ilmErrorTypes wayland_surfaceRemoveNotification(t_ilm_surface surface);
132 static ilmErrorTypes wayland_init(t_ilm_nativedisplay nativedisplay);
133 static void wayland_destroy(void);
134 static ilmErrorTypes wayland_getNativeHandle(t_ilm_uint pid,
136 t_ilm_nativehandle **p_handles);
137 static ilmErrorTypes wayland_getPropertiesOfSurface(t_ilm_uint surfaceID,
138 struct ilmSurfaceProperties* pSurfaceProperties);
139 static ilmErrorTypes wayland_layerAddSurface(t_ilm_layer layerId,
140 t_ilm_surface surfaceId);
141 static ilmErrorTypes wayland_layerRemoveSurface(t_ilm_layer layerId,
142 t_ilm_surface surfaceId);
143 static ilmErrorTypes wayland_surfaceGetDimension(t_ilm_surface surfaceId,
144 t_ilm_uint *pDimension);
145 static ilmErrorTypes wayland_surfaceGetVisibility(t_ilm_surface surfaceId,
146 t_ilm_bool *pVisibility);
147 static ilmErrorTypes wayland_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
148 t_ilm_int x, t_ilm_int y,
149 t_ilm_int width, t_ilm_int height);
150 static ilmErrorTypes wayland_commitChanges(void);
152 void init_ilmControlPlatformTable(void)
154 gIlmControlPlatformFunc.getPropertiesOfLayer =
155 wayland_getPropertiesOfLayer;
156 gIlmControlPlatformFunc.getPropertiesOfScreen =
157 wayland_getPropertiesOfScreen;
158 gIlmControlPlatformFunc.getNumberOfHardwareLayers =
159 wayland_getNumberOfHardwareLayers;
160 gIlmControlPlatformFunc.getScreenIDs =
161 wayland_getScreenIDs;
162 gIlmControlPlatformFunc.getLayerIDs =
164 gIlmControlPlatformFunc.getLayerIDsOnScreen =
165 wayland_getLayerIDsOnScreen;
166 gIlmControlPlatformFunc.getSurfaceIDs =
167 wayland_getSurfaceIDs;
168 gIlmControlPlatformFunc.getSurfaceIDsOnLayer =
169 wayland_getSurfaceIDsOnLayer;
170 gIlmControlPlatformFunc.layerCreateWithDimension =
171 wayland_layerCreateWithDimension;
172 gIlmControlPlatformFunc.layerRemove =
174 gIlmControlPlatformFunc.layerGetType =
175 wayland_layerGetType;
176 gIlmControlPlatformFunc.layerSetVisibility =
177 wayland_layerSetVisibility;
178 gIlmControlPlatformFunc.layerGetVisibility =
179 wayland_layerGetVisibility;
180 gIlmControlPlatformFunc.layerSetOpacity =
181 wayland_layerSetOpacity;
182 gIlmControlPlatformFunc.layerGetOpacity =
183 wayland_layerGetOpacity;
184 gIlmControlPlatformFunc.layerSetSourceRectangle =
185 wayland_layerSetSourceRectangle;
186 gIlmControlPlatformFunc.layerSetDestinationRectangle =
187 wayland_layerSetDestinationRectangle;
188 gIlmControlPlatformFunc.layerGetDimension =
189 wayland_layerGetDimension;
190 gIlmControlPlatformFunc.layerSetDimension =
191 wayland_layerSetDimension;
192 gIlmControlPlatformFunc.layerGetPosition =
193 wayland_layerGetPosition;
194 gIlmControlPlatformFunc.layerSetPosition =
195 wayland_layerSetPosition;
196 gIlmControlPlatformFunc.layerSetOrientation =
197 wayland_layerSetOrientation;
198 gIlmControlPlatformFunc.layerGetOrientation =
199 wayland_layerGetOrientation;
200 gIlmControlPlatformFunc.layerSetChromaKey =
201 wayland_layerSetChromaKey;
202 gIlmControlPlatformFunc.layerSetRenderOrder =
203 wayland_layerSetRenderOrder;
204 gIlmControlPlatformFunc.layerGetCapabilities =
205 wayland_layerGetCapabilities;
206 gIlmControlPlatformFunc.layerTypeGetCapabilities =
207 wayland_layerTypeGetCapabilities;
208 gIlmControlPlatformFunc.surfaceSetVisibility =
209 wayland_surfaceSetVisibility;
210 gIlmControlPlatformFunc.surfaceSetOpacity =
211 wayland_surfaceSetOpacity;
212 gIlmControlPlatformFunc.surfaceGetOpacity =
213 wayland_surfaceGetOpacity;
214 gIlmControlPlatformFunc.SetKeyboardFocusOn =
215 wayland_SetKeyboardFocusOn;
216 gIlmControlPlatformFunc.GetKeyboardFocusSurfaceId =
217 wayland_GetKeyboardFocusSurfaceId;
218 gIlmControlPlatformFunc.surfaceSetDestinationRectangle =
219 wayland_surfaceSetDestinationRectangle;
220 gIlmControlPlatformFunc.surfaceSetDimension =
221 wayland_surfaceSetDimension;
222 gIlmControlPlatformFunc.surfaceGetPosition =
223 wayland_surfaceGetPosition;
224 gIlmControlPlatformFunc.surfaceSetPosition =
225 wayland_surfaceSetPosition;
226 gIlmControlPlatformFunc.surfaceSetOrientation =
227 wayland_surfaceSetOrientation;
228 gIlmControlPlatformFunc.surfaceGetOrientation =
229 wayland_surfaceGetOrientation;
230 gIlmControlPlatformFunc.surfaceGetPixelformat =
231 wayland_surfaceGetPixelformat;
232 gIlmControlPlatformFunc.surfaceSetChromaKey =
233 wayland_surfaceSetChromaKey;
234 gIlmControlPlatformFunc.displaySetRenderOrder =
235 wayland_displaySetRenderOrder;
236 gIlmControlPlatformFunc.takeScreenshot =
237 wayland_takeScreenshot;
238 gIlmControlPlatformFunc.takeLayerScreenshot =
239 wayland_takeLayerScreenshot;
240 gIlmControlPlatformFunc.takeSurfaceScreenshot =
241 wayland_takeSurfaceScreenshot;
242 gIlmControlPlatformFunc.SetOptimizationMode =
243 wayland_SetOptimizationMode;
244 gIlmControlPlatformFunc.GetOptimizationMode =
245 wayland_GetOptimizationMode;
246 gIlmControlPlatformFunc.layerAddNotification =
247 wayland_layerAddNotification;
248 gIlmControlPlatformFunc.layerRemoveNotification =
249 wayland_layerRemoveNotification;
250 gIlmControlPlatformFunc.surfaceAddNotification =
251 wayland_surfaceAddNotification;
252 gIlmControlPlatformFunc.surfaceRemoveNotification =
253 wayland_surfaceRemoveNotification;
254 gIlmControlPlatformFunc.init =
256 gIlmControlPlatformFunc.destroy =
258 gIlmControlPlatformFunc.getNativeHandle =
259 wayland_getNativeHandle;
260 gIlmControlPlatformFunc.getPropertiesOfSurface =
261 wayland_getPropertiesOfSurface;
262 gIlmControlPlatformFunc.layerAddSurface =
263 wayland_layerAddSurface;
264 gIlmControlPlatformFunc.layerRemoveSurface =
265 wayland_layerRemoveSurface;
266 gIlmControlPlatformFunc.surfaceGetDimension =
267 wayland_surfaceGetDimension;
268 gIlmControlPlatformFunc.surfaceGetVisibility =
269 wayland_surfaceGetVisibility;
270 gIlmControlPlatformFunc.surfaceSetSourceRectangle =
271 wayland_surfaceSetSourceRectangle;
272 gIlmControlPlatformFunc.commitChanges =
273 wayland_commitChanges;
276 struct surface_context {
279 struct ivi_surface *surface;
280 struct ivi_controller_surface *controller;
282 t_ilm_uint id_surface;
283 struct ilmSurfaceProperties prop;
284 surfaceNotificationFunc notification;
290 struct wayland_context *ctx;
293 struct layer_context {
296 struct ivi_controller_layer *controller;
299 struct ilmLayerProperties prop;
300 layerNotificationFunc notification;
303 struct wl_list list_surface;
307 struct wayland_context *ctx;
310 struct screen_context {
313 struct wl_output *output;
314 struct ivi_controller_screen *controller;
315 t_ilm_uint id_from_server;
316 t_ilm_uint id_screen;
318 struct ilmScreenProperties prop;
321 struct wl_list list_layer;
325 struct ilm_control_context *ctx;
328 struct nativehandle_context {
330 uint32_t nativehandle;
334 struct wayland_context {
335 struct wl_display *display;
336 struct wl_registry *registry;
337 struct wl_event_queue *queue;
338 struct wl_compositor *compositor;
339 struct ivi_controller *controller;
342 struct wl_list list_surface;
343 struct wl_list list_layer;
344 struct wl_list list_screen;
347 struct ilm_control_context {
348 struct wayland_context main_ctx;
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* get_instance(void);
406 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid);
409 wayland_controller_is_inside_surface_list(struct wl_list *list,
412 struct surface_context *ctx_surf = NULL;
413 wl_list_for_each(ctx_surf, list, link) {
414 if (ctx_surf->id_surface == id_surface) {
423 wayland_controller_is_inside_layer_list(struct wl_list *list,
426 struct layer_context *ctx_layer = NULL;
427 wl_list_for_each(ctx_layer, list, link) {
428 if (ctx_layer->id_layer == id_layer) {
436 static struct layer_context*
437 wayland_controller_get_layer_context(struct wayland_context *ctx,
440 struct layer_context *ctx_layer = NULL;
442 if (ctx->controller == NULL) {
443 fprintf(stderr, "controller is not initialized in ilmControl\n");
447 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
448 if (ctx_layer->id_layer == id_layer) {
453 fprintf(stderr, "failed to get layer context in ilmControl\n");
458 output_listener_geometry(void *data,
459 struct wl_output *output,
462 int32_t physical_width,
463 int32_t physical_height,
479 output_listener_mode(void *data,
480 struct wl_output *output,
492 struct screen_context *ctx_scrn = data;
493 ctx_scrn->prop.screenWidth = width;
494 ctx_scrn->prop.screenHeight = height;
498 output_listener_done(void *data,
499 struct wl_output *output)
506 output_listener_scale(void *data,
507 struct wl_output *output,
515 static struct wl_output_listener output_listener = {
516 output_listener_geometry,
517 output_listener_mode,
518 output_listener_done,
519 output_listener_scale
522 static struct screen_context*
523 get_screen_context_by_output(struct wayland_context *ctx,
524 struct wl_output *output)
526 struct screen_context *ctx_scrn = NULL;
527 struct wl_proxy *pxy_out = NULL;
528 struct wl_proxy *pxy_out_in_scrn = NULL;
530 uint32_t pxy_id_in_scrn = 0;
532 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
533 pxy_out = (struct wl_proxy*)output;
534 pxy_out_in_scrn = (struct wl_proxy*)ctx_scrn->output;
535 pxy_id = wl_proxy_get_id(pxy_out);
536 pxy_id_in_scrn = wl_proxy_get_id(pxy_out_in_scrn);
537 if (pxy_id == pxy_id_in_scrn) {
544 static struct screen_context*
545 get_screen_context_by_serverid(struct wayland_context *ctx,
548 struct screen_context *ctx_scrn = NULL;
550 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
551 if (ctx_scrn->id_from_server == id_screen) {
559 add_orderlayer_to_screen(struct layer_context *ctx_layer,
560 struct wl_output* output)
562 struct screen_context *ctx_scrn = NULL;
564 ctx_scrn = get_screen_context_by_output(ctx_layer->ctx, output);
565 if (ctx_scrn == NULL) {
566 fprintf(stderr, "failed to add_orderlayer_to_screen\n");
571 struct layer_context *layer_link;
572 wl_list_for_each(layer_link, &ctx_scrn->order.list_layer, order.link) {
573 if (layer_link == ctx_layer) {
580 wl_list_init(&ctx_layer->order.link);
581 wl_list_insert(&ctx_scrn->order.list_layer, &ctx_layer->order.link);
586 remove_orderlayer_from_screen(struct layer_context *ctx_layer)
588 wl_list_remove(&ctx_layer->order.link);
589 wl_list_init(&ctx_layer->order.link);
593 controller_layer_listener_visibility(void *data,
594 struct ivi_controller_layer *controller,
597 struct layer_context *ctx_layer = data;
599 ctx_layer->prop.visibility = (t_ilm_bool)visibility;
601 if (ctx_layer->notification != NULL) {
602 ctx_layer->notification(ctx_layer->id_layer,
604 ILM_NOTIFICATION_VISIBILITY);
609 controller_layer_listener_opacity(void *data,
610 struct ivi_controller_layer *controller,
613 struct layer_context *ctx_layer = data;
615 ctx_layer->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
617 if (ctx_layer->notification != NULL) {
618 ctx_layer->notification(ctx_layer->id_layer,
620 ILM_NOTIFICATION_OPACITY);
625 controller_layer_listener_source_rectangle(void *data,
626 struct ivi_controller_layer *controller,
632 struct layer_context *ctx_layer = data;
634 ctx_layer->prop.sourceX = (t_ilm_uint)x;
635 ctx_layer->prop.sourceY = (t_ilm_uint)y;
636 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
637 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
638 if (ctx_layer->prop.origSourceWidth == 0) {
639 ctx_layer->prop.origSourceWidth = (t_ilm_uint)width;
641 if (ctx_layer->prop.origSourceHeight == 0) {
642 ctx_layer->prop.origSourceHeight = (t_ilm_uint)height;
645 if (ctx_layer->notification != NULL) {
646 ctx_layer->notification(ctx_layer->id_layer,
648 ILM_NOTIFICATION_SOURCE_RECT);
653 controller_layer_listener_destination_rectangle(void *data,
654 struct ivi_controller_layer *controller,
660 struct layer_context *ctx_layer = data;
662 ctx_layer->prop.destX = (t_ilm_uint)x;
663 ctx_layer->prop.destY = (t_ilm_uint)y;
664 ctx_layer->prop.destWidth = (t_ilm_uint)width;
665 ctx_layer->prop.destHeight = (t_ilm_uint)height;
667 if (ctx_layer->notification != NULL) {
668 ctx_layer->notification(ctx_layer->id_layer,
670 ILM_NOTIFICATION_DEST_RECT);
675 controller_layer_listener_configuration(void *data,
676 struct ivi_controller_layer *controller,
680 struct layer_context *ctx_layer = data;
682 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
683 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
687 controller_layer_listener_orientation(void *data,
688 struct ivi_controller_layer *controller,
691 ilmOrientation ilmorientation = ILM_ZERO;
692 struct layer_context *ctx_layer = data;
694 switch(orientation) {
695 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
696 ilmorientation = ILM_ZERO;
698 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
699 ilmorientation = ILM_NINETY;
701 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
702 ilmorientation = ILM_ONEHUNDREDEIGHTY;
704 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
705 ilmorientation = ILM_TWOHUNDREDSEVENTY;
711 ctx_layer->prop.orientation = ilmorientation;
713 if (ctx_layer->notification != NULL) {
714 ctx_layer->notification(ctx_layer->id_layer,
716 ILM_NOTIFICATION_ORIENTATION);
721 controller_layer_listener_screen(void *data,
722 struct ivi_controller_layer *controller,
723 struct wl_output *output)
725 struct layer_context *ctx_layer = data;
727 if (output == NULL) {
728 remove_orderlayer_from_screen(ctx_layer);
730 add_orderlayer_to_screen(ctx_layer, output);
735 controller_layer_listener_destroyed(void *data,
736 struct ivi_controller_layer *controller)
738 struct layer_context *ctx_layer = data;
739 wl_list_remove(&ctx_layer->link);
743 static struct ivi_controller_layer_listener controller_layer_listener =
745 controller_layer_listener_visibility,
746 controller_layer_listener_opacity,
747 controller_layer_listener_source_rectangle,
748 controller_layer_listener_destination_rectangle,
749 controller_layer_listener_configuration,
750 controller_layer_listener_orientation,
751 controller_layer_listener_screen,
752 controller_layer_listener_destroyed
756 add_ordersurface_to_layer(struct surface_context *ctx_surf,
757 struct ivi_controller_layer *layer)
759 struct layer_context *ctx_layer = NULL;
760 struct surface_context *link = NULL;
763 ctx_layer = ivi_controller_layer_get_user_data(layer);
765 wl_list_for_each(link, &ctx_layer->order.list_surface, order.link) {
766 if (link == ctx_surf) {
773 wl_list_init(&ctx_surf->order.link);
774 wl_list_insert(&ctx_layer->order.list_surface, &ctx_surf->order.link);
779 remove_ordersurface_from_layer(struct surface_context *ctx_surf)
781 wl_list_remove(&ctx_surf->order.link);
782 wl_list_init(&ctx_surf->order.link);
786 controller_surface_listener_visibility(void *data,
787 struct ivi_controller_surface *controller,
790 struct surface_context *ctx_surf = data;
792 ctx_surf->prop.visibility = (t_ilm_bool)visibility;
794 if (ctx_surf->notification != NULL) {
795 ctx_surf->notification(ctx_surf->id_surface,
797 ILM_NOTIFICATION_VISIBILITY);
802 controller_surface_listener_opacity(void *data,
803 struct ivi_controller_surface *controller,
806 struct surface_context *ctx_surf = data;
808 ctx_surf->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
810 if (ctx_surf->notification != NULL) {
811 ctx_surf->notification(ctx_surf->id_surface,
813 ILM_NOTIFICATION_OPACITY);
818 controller_surface_listener_configuration(void *data,
819 struct ivi_controller_surface *controller,
823 struct surface_context *ctx_surf = data;
825 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
826 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
830 controller_surface_listener_source_rectangle(void *data,
831 struct ivi_controller_surface *controller,
837 struct surface_context *ctx_surf = data;
839 ctx_surf->prop.sourceX = (t_ilm_uint)x;
840 ctx_surf->prop.sourceY = (t_ilm_uint)y;
841 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
842 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
843 if (ctx_surf->prop.origSourceWidth == 0) {
844 ctx_surf->prop.origSourceWidth = (t_ilm_uint)width;
846 if (ctx_surf->prop.origSourceHeight == 0) {
847 ctx_surf->prop.origSourceHeight = (t_ilm_uint)height;
850 if (ctx_surf->notification != NULL) {
851 ctx_surf->notification(ctx_surf->id_surface,
853 ILM_NOTIFICATION_SOURCE_RECT);
858 controller_surface_listener_destination_rectangle(void *data,
859 struct ivi_controller_surface *controller,
865 struct surface_context *ctx_surf = data;
867 ctx_surf->prop.destX = (t_ilm_uint)x;
868 ctx_surf->prop.destY = (t_ilm_uint)y;
869 ctx_surf->prop.destWidth = (t_ilm_uint)width;
870 ctx_surf->prop.destHeight = (t_ilm_uint)height;
872 if (ctx_surf->notification != NULL) {
873 ctx_surf->notification(ctx_surf->id_surface,
875 ILM_NOTIFICATION_DEST_RECT);
880 controller_surface_listener_orientation(void *data,
881 struct ivi_controller_surface *controller,
884 struct surface_context *ctx_surf = data;
885 ilmOrientation ilmorientation = ILM_ZERO;
887 switch (orientation) {
888 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
889 ilmorientation = ILM_ZERO;
891 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
892 ilmorientation = ILM_NINETY;
894 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
895 ilmorientation = ILM_ONEHUNDREDEIGHTY;
897 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
898 ilmorientation = ILM_TWOHUNDREDSEVENTY;
904 ctx_surf->prop.orientation = ilmorientation;
906 if (ctx_surf->notification != NULL) {
907 ctx_surf->notification(ctx_surf->id_surface,
909 ILM_NOTIFICATION_ORIENTATION);
914 controller_surface_listener_pixelformat(void *data,
915 struct ivi_controller_surface *controller,
918 struct surface_context *ctx_surf = data;
920 ctx_surf->prop.pixelformat = (t_ilm_uint)pixelformat;
924 controller_surface_listener_layer(void *data,
925 struct ivi_controller_surface *controller,
926 struct ivi_controller_layer *layer)
928 struct surface_context *ctx_surf = data;
931 remove_ordersurface_from_layer(ctx_surf);
933 add_ordersurface_to_layer(ctx_surf, layer);
938 controller_surface_listener_stats(void *data,
939 struct ivi_controller_surface *controller,
940 uint32_t redraw_count,
941 uint32_t frame_count,
942 uint32_t update_count,
944 const char *process_name)
946 struct surface_context *ctx_surf = data;
949 ctx_surf->prop.drawCounter = (t_ilm_uint)redraw_count;
950 ctx_surf->prop.frameCounter = (t_ilm_uint)frame_count;
951 ctx_surf->prop.updateCounter = (t_ilm_uint)update_count;
952 ctx_surf->prop.creatorPid = (t_ilm_uint)pid;
956 controller_surface_listener_destroyed(void *data,
957 struct ivi_controller_surface *controller)
959 struct surface_context *ctx_surf = data;
961 wl_list_remove(&ctx_surf->link);
966 controller_surface_listener_content(void *data,
967 struct ivi_controller_surface *controller,
968 int32_t content_state)
970 // if client surface (=content) was removed with ilm_surfaceDestroy()
971 // the expected behavior within ILM API mandates a full removal
972 // of the surface from the scene. We must remove the controller
974 if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED == content_state)
976 struct surface_context *ctx_surf = data;
978 ivi_controller_surface_destroy(controller, 1);
980 wl_list_remove(&ctx_surf->link);
986 controller_surface_listener_input_focus(void *data,
987 struct ivi_controller_surface *controller,
995 static struct ivi_controller_surface_listener controller_surface_listener=
997 controller_surface_listener_visibility,
998 controller_surface_listener_opacity,
999 controller_surface_listener_source_rectangle,
1000 controller_surface_listener_destination_rectangle,
1001 controller_surface_listener_configuration,
1002 controller_surface_listener_orientation,
1003 controller_surface_listener_pixelformat,
1004 controller_surface_listener_layer,
1005 controller_surface_listener_stats,
1006 controller_surface_listener_destroyed,
1007 controller_surface_listener_content,
1008 controller_surface_listener_input_focus
1012 controller_surface_listener_visibility_main(void *data,
1013 struct ivi_controller_surface *controller,
1022 controller_surface_listener_opacity_main(void *data,
1023 struct ivi_controller_surface *controller,
1032 controller_surface_listener_source_rectangle_main(void *data,
1033 struct ivi_controller_surface *controller,
1048 controller_surface_listener_destination_rectangle_main(void *data,
1049 struct ivi_controller_surface *controller,
1064 controller_surface_listener_configuration_main(void *data,
1065 struct ivi_controller_surface *controller,
1076 controller_surface_listener_orientation_main(void *data,
1077 struct ivi_controller_surface *controller,
1078 int32_t orientation)
1086 controller_surface_listener_pixelformat_main(void *data,
1087 struct ivi_controller_surface *controller,
1088 int32_t pixelformat)
1096 controller_surface_listener_layer_main(void *data,
1097 struct ivi_controller_surface *controller,
1098 struct ivi_controller_layer *layer)
1100 struct surface_context *ctx_surf = data;
1102 if (layer == NULL) {
1103 remove_ordersurface_from_layer(ctx_surf);
1105 add_ordersurface_to_layer(ctx_surf, layer);
1110 controller_surface_listener_stats_main(void *data,
1111 struct ivi_controller_surface *controller,
1112 uint32_t redraw_count,
1113 uint32_t frame_count,
1114 uint32_t update_count,
1116 const char *process_name)
1128 controller_surface_listener_destroyed_main(void *data,
1129 struct ivi_controller_surface *controller)
1131 struct surface_context *ctx_surf = data;
1133 wl_list_remove(&ctx_surf->link);
1138 controller_surface_listener_content_main(void *data,
1139 struct ivi_controller_surface *controller,
1140 int32_t content_state)
1142 // if client surface (=content) was removed with ilm_surfaceDestroy()
1143 // the expected behavior within ILM API mandates a full removal
1144 // of the surface from the scene. We must remove the controller
1146 if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED == content_state)
1148 struct surface_context *ctx_surf = data;
1150 ivi_controller_surface_destroy(controller, 1);
1152 wl_list_remove(&ctx_surf->link);
1158 controller_surface_listener_input_focus_main(void *data,
1159 struct ivi_controller_surface *controller,
1167 static struct ivi_controller_surface_listener controller_surface_listener_main =
1169 controller_surface_listener_visibility_main,
1170 controller_surface_listener_opacity_main,
1171 controller_surface_listener_source_rectangle_main,
1172 controller_surface_listener_destination_rectangle_main,
1173 controller_surface_listener_configuration_main,
1174 controller_surface_listener_orientation_main,
1175 controller_surface_listener_pixelformat_main,
1176 controller_surface_listener_layer_main,
1177 controller_surface_listener_stats_main,
1178 controller_surface_listener_destroyed_main,
1179 controller_surface_listener_content_main,
1180 controller_surface_listener_input_focus_main
1184 controller_listener_screen_for_child(void *data,
1185 struct ivi_controller *ivi_controller,
1187 struct ivi_controller_screen *controller_screen)
1190 (void)ivi_controller;
1192 (void)controller_screen;
1196 controller_listener_layer_for_child(void *data,
1197 struct ivi_controller *controller,
1200 struct wayland_context *ctx = data;
1202 if (wayland_controller_is_inside_layer_list(&ctx->list_layer, id_layer))
1207 (void) create_controller_layer(ctx, 0, 0, id_layer);
1211 controller_listener_surface_for_child(void *data,
1212 struct ivi_controller *controller,
1213 uint32_t id_surface)
1215 struct wayland_context *ctx = data;
1216 struct surface_context *ctx_surf = NULL;
1217 int32_t is_inside = 0;
1219 is_inside = wayland_controller_is_inside_surface_list(
1220 &ctx->list_surface, id_surface);
1222 if (is_inside != 0) {
1223 fprintf(stderr, "invalid id_surface in controller_listener_surface\n");
1227 ctx_surf = calloc(1, sizeof *ctx_surf);
1228 if (ctx_surf == NULL) {
1229 fprintf(stderr, "Failed to allocate memory for surface_context\n");
1233 ctx_surf->controller = ivi_controller_surface_create(
1234 controller, id_surface);
1235 if (ctx_surf->controller == NULL) {
1236 fprintf(stderr, "Failed to create controller surface\n");
1239 ctx_surf->id_surface = id_surface;
1240 ctx_surf->prop.inputDevicesAcceptance = ILM_INPUT_DEVICE_ALL;
1241 ctx_surf->ctx = ctx;
1243 wl_list_init(&ctx_surf->link);
1244 wl_list_insert(&ctx->list_surface, &ctx_surf->link);
1245 ivi_controller_surface_add_listener(ctx_surf->controller,
1246 &controller_surface_listener, ctx_surf);
1250 controller_listener_error_for_child(void *data,
1251 struct ivi_controller *ivi_controller,
1253 int32_t object_type,
1255 const char *error_text)
1258 (void)ivi_controller;
1265 static struct ivi_controller_listener controller_listener_for_child = {
1266 controller_listener_screen_for_child,
1267 controller_listener_layer_for_child,
1268 controller_listener_surface_for_child,
1269 controller_listener_error_for_child
1273 controller_listener_screen_for_main(void *data,
1274 struct ivi_controller *ivi_controller,
1276 struct ivi_controller_screen *controller_screen)
1278 struct wayland_context *ctx = data;
1279 struct screen_context *ctx_screen;
1280 (void)ivi_controller;
1282 ctx_screen = get_screen_context_by_serverid(ctx, id_screen);
1283 if (ctx_screen == NULL) {
1284 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1287 ctx_screen->controller = controller_screen;
1290 static struct ivi_controller_listener controller_listener_for_main = {
1291 controller_listener_screen_for_main,
1292 controller_listener_layer_for_child,
1293 controller_listener_surface_for_child,
1294 controller_listener_error_for_child
1298 registry_handle_control_for_child(void *data,
1299 struct wl_registry *registry,
1300 uint32_t name, const char *interface,
1303 struct wayland_context *ctx = data;
1306 if (strcmp(interface, "ivi_controller") == 0) {
1307 ctx->controller = wl_registry_bind(registry, name,
1308 &ivi_controller_interface, 1);
1309 if (ctx->controller == NULL) {
1310 fprintf(stderr, "Failed to registry bind ivi_controller\n");
1313 if (ivi_controller_add_listener(ctx->controller,
1314 &controller_listener_for_child,
1316 fprintf(stderr, "Failed to add ivi_controller listener\n");
1319 } else if (strcmp(interface, "wl_output") == 0) {
1320 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
1321 if (ctx_scrn == NULL) {
1322 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1325 wl_list_init(&ctx_scrn->link);
1326 ctx_scrn->output = wl_registry_bind(registry, name,
1327 &wl_output_interface, 1);
1328 if (ctx_scrn->output == NULL) {
1330 fprintf(stderr, "Failed to registry bind wl_output\n");
1334 if (wl_output_add_listener(ctx_scrn->output,
1338 fprintf(stderr, "Failed to add wl_output listener\n");
1342 ctx_scrn->id_screen = ctx->num_screen;
1344 wl_list_init(&ctx_scrn->order.list_layer);
1345 wl_list_insert(&ctx->list_screen, &ctx_scrn->link);
1349 static const struct wl_registry_listener
1350 registry_control_listener_for_child = {
1351 registry_handle_control_for_child,
1356 registry_handle_control_for_main(void *data,
1357 struct wl_registry *registry,
1358 uint32_t name, const char *interface,
1361 struct ilm_control_context *ctx = data;
1364 if (strcmp(interface, "ivi_controller") == 0) {
1365 ctx->main_ctx.controller = wl_registry_bind(registry, name,
1366 &ivi_controller_interface, 1);
1367 if (ctx->main_ctx.controller == NULL) {
1368 fprintf(stderr, "Failed to registry bind ivi_controller\n");
1371 if (ivi_controller_add_listener(ctx->main_ctx.controller,
1372 &controller_listener_for_main,
1374 fprintf(stderr, "Failed to add ivi_controller listener\n");
1377 } else if (strcmp(interface, "wl_output") == 0) {
1379 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
1380 struct wl_proxy *pxy = NULL;
1382 if (ctx_scrn == NULL) {
1383 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1386 wl_list_init(&ctx_scrn->link);
1387 ctx_scrn->output = wl_registry_bind(registry, name,
1388 &wl_output_interface, 1);
1389 if (ctx_scrn->output == NULL) {
1391 fprintf(stderr, "Failed to registry bind wl_output\n");
1395 if (wl_output_add_listener(ctx_scrn->output,
1399 fprintf(stderr, "Failed to add wl_output listener\n");
1403 pxy = (struct wl_proxy*)ctx_scrn->output;
1404 ctx_scrn->id_from_server = wl_proxy_get_id(pxy);
1405 ctx_scrn->id_screen = ctx->num_screen;
1407 ctx_scrn->controller = NULL;
1408 ctx_scrn->prop.layerCount = 0;
1409 ctx_scrn->prop.layerIds = NULL;
1410 ctx_scrn->prop.harwareLayerCount = 0;
1411 ctx_scrn->prop.screenWidth = 0;
1412 ctx_scrn->prop.screenHeight = 0;
1413 wl_list_init(&ctx_scrn->order.list_layer);
1414 wl_list_insert(&ctx->main_ctx.list_screen, &ctx_scrn->link);
1418 static const struct wl_registry_listener
1419 registry_control_listener_for_main = {
1420 registry_handle_control_for_main,
1424 static struct ilm_control_context ilm_context = {0};
1427 destroy_control_resources(void)
1429 struct ilm_control_context *ctx = &ilm_context;
1430 struct screen_context *ctx_scrn;
1431 struct screen_context *next;
1433 wl_list_for_each_safe(ctx_scrn, next, &ctx->main_ctx.list_screen, link) {
1434 if (ctx_scrn->output != NULL) {
1435 wl_list_remove(&ctx_scrn->link);
1436 wl_output_destroy(ctx_scrn->output);
1440 if (ctx->main_ctx.controller != NULL) {
1441 ivi_controller_destroy(ctx->main_ctx.controller);
1442 ctx->main_ctx.controller = NULL;
1445 wl_display_flush(ctx->main_ctx.display);
1447 wl_event_queue_destroy(ctx->main_ctx.queue);
1448 ctx->main_ctx.queue = NULL;
1450 if (0 != pthread_mutex_destroy(&ctx->mutex)) {
1451 fprintf(stderr, "failed to destroy pthread_mutex\n");
1456 wayland_destroy(void)
1458 struct ilm_control_context *ctx = &ilm_context;
1461 unlock_context(ctx);
1462 void* threadRetVal = NULL;
1463 pthread_cancel(ctx->thread);
1464 if (0 != pthread_join(ctx->thread, &threadRetVal)) {
1465 fprintf(stderr, "failed to join control thread\n");
1467 destroy_control_resources();
1470 static ilmErrorTypes
1471 wayland_init(t_ilm_nativedisplay nativedisplay)
1473 struct ilm_control_context *ctx = &ilm_context;
1475 if (ctx->valid != 0)
1477 fprintf(stderr, "Already initialized!\n");
1481 if (nativedisplay == 0) {
1482 return ILM_ERROR_INVALID_ARGUMENTS;
1485 memset(ctx, 0, sizeof *ctx);
1487 ctx->main_ctx.display = (struct wl_display*)nativedisplay;
1489 wl_list_init(&ctx->main_ctx.list_screen);
1490 wl_list_init(&ctx->main_ctx.list_layer);
1491 wl_list_init(&ctx->main_ctx.list_surface);
1494 pthread_mutexattr_t a;
1495 if (pthread_mutexattr_init(&a) != 0)
1500 if (pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE) != 0)
1502 pthread_mutexattr_destroy(&a);
1506 if (pthread_mutex_init(&ctx->mutex, &a) != 0)
1508 pthread_mutexattr_destroy(&a);
1509 fprintf(stderr, "failed to initialize pthread_mutex\n");
1513 pthread_mutexattr_destroy(&a);
1516 ctx->internal_id_surface = 0;
1517 ctx->num_screen = 0;
1519 return init_control() == 0 ? ILM_SUCCESS : ILM_FAILED;
1523 control_thread(void *p_ret)
1525 struct ilm_control_context *ctx = &ilm_context;
1526 struct wayland_context *main_ctx = &ctx->main_ctx;
1533 int valid = ctx->valid;
1534 unlock_context(ctx);
1542 while (wl_display_prepare_read_queue(main_ctx->display, main_ctx->queue) != 0)
1544 wl_display_dispatch_queue_pending(main_ctx->display, main_ctx->queue);
1546 unlock_context(ctx);
1548 if (wl_display_flush(main_ctx->display) == -1)
1555 pfd.fd = wl_display_get_fd(main_ctx->display);
1556 pfd.events = POLLIN;
1559 if (poll(&pfd, 1, -1) != -1 && (pfd.revents & POLLIN))
1561 wl_display_read_events(main_ctx->display);
1564 int ret = wl_display_dispatch_queue_pending(main_ctx->display, main_ctx->queue);
1565 unlock_context(ctx);
1574 wl_display_cancel_read(main_ctx->display);
1584 struct ilm_control_context *ctx = &ilm_context;
1585 struct wayland_context *main_ctx = &ctx->main_ctx;
1589 wl_list_init(&ctx->list_nativehandle);
1591 main_ctx->queue = wl_display_create_queue(main_ctx->display);
1593 /* registry_add_listener for request by ivi-controller */
1594 main_ctx->registry = wl_display_get_registry(main_ctx->display);
1595 if (main_ctx->registry == NULL) {
1596 fprintf(stderr, "Failed to get registry\n");
1599 wl_proxy_set_queue((void*)main_ctx->registry, main_ctx->queue);
1601 if (wl_registry_add_listener(main_ctx->registry,
1602 ®istry_control_listener_for_main, ctx)) {
1603 fprintf(stderr, "Failed to add registry listener\n");
1607 display_roundtrip_queue(main_ctx->display, main_ctx->queue);
1608 display_roundtrip_queue(main_ctx->display, main_ctx->queue);
1612 ret = pthread_create(&ctx->thread, NULL, control_thread, NULL);
1615 fprintf(stderr, "Failed to start internal receive thread. returned %d\n", ret);
1622 static struct ilm_control_context*
1625 struct ilm_control_context *ctx = &ilm_context;
1627 display_roundtrip_queue(ctx->main_ctx.display, ctx->main_ctx.queue);
1628 unlock_context(ctx);
1633 gen_layer_id(struct ilm_control_context *ctx)
1635 struct layer_context *ctx_layer = NULL;
1638 if (wl_list_length(&ctx->main_ctx.list_layer) == 0) {
1639 ctx->internal_id_layer++;
1640 return ctx->internal_id_layer;
1642 wl_list_for_each(ctx_layer, &ctx->main_ctx.list_layer, link) {
1643 if (ctx_layer->id_layer == ctx->internal_id_layer) {
1649 return ctx->internal_id_layer;
1652 ctx->internal_id_layer++;
1656 static struct surface_context*
1657 get_surface_context(struct wayland_context *ctx,
1658 uint32_t id_surface)
1660 struct surface_context *ctx_surf = NULL;
1662 if (ctx->controller == NULL) {
1663 fprintf(stderr, "controller is not initialized in ilmControl\n");
1667 wl_list_for_each(ctx_surf, &ctx->list_surface, link) {
1668 if (ctx_surf->id_surface == id_surface) {
1673 fprintf(stderr, "failed to get surface context in ilmControl\n");
1677 static struct screen_context*
1678 get_screen_context_by_id(struct wayland_context *ctx, uint32_t id_screen)
1680 struct screen_context *ctx_scrn = NULL;
1682 if (ctx->controller == NULL) {
1683 fprintf(stderr, "get_screen_context_by_id: controller is NULL\n");
1687 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
1688 if (ctx_scrn->id_screen == id_screen) {
1695 static ilmErrorTypes
1696 wayland_getPropertiesOfLayer(t_ilm_uint layerID,
1697 struct ilmLayerProperties* pLayerProperties)
1699 ilmErrorTypes returnValue = ILM_FAILED;
1700 struct ilm_control_context *ctx = get_instance();
1702 struct layer_context *ctx_layer = NULL;
1704 if (pLayerProperties != NULL) {
1706 ctx_layer = (struct layer_context*)
1707 wayland_controller_get_layer_context(
1708 &ctx->main_ctx, (uint32_t)layerID);
1710 if (ctx_layer != NULL) {
1711 *pLayerProperties = ctx_layer->prop;
1712 returnValue = ILM_SUCCESS;
1716 unlock_context(ctx);
1721 create_layerids(struct screen_context *ctx_screen,
1722 t_ilm_layer **layer_ids, t_ilm_uint *layer_count)
1724 struct layer_context *ctx_layer = NULL;
1725 t_ilm_layer *ids = NULL;
1727 *layer_count = wl_list_length(&ctx_screen->order.list_layer);
1728 if (*layer_count == 0) {
1733 *layer_ids = malloc(*layer_count * sizeof(t_ilm_layer));
1734 if (*layer_ids == NULL) {
1735 fprintf(stderr, "memory insufficient for layerids\n");
1741 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link) {
1742 *ids = (t_ilm_layer)ctx_layer->id_layer;
1747 static ilmErrorTypes
1748 wayland_getPropertiesOfScreen(t_ilm_display screenID,
1749 struct ilmScreenProperties* pScreenProperties)
1751 ilmErrorTypes returnValue = ILM_FAILED;
1752 struct ilm_control_context *ctx = get_instance();
1755 if (pScreenProperties != NULL) {
1756 struct screen_context *ctx_screen = NULL;
1757 ctx_screen = get_screen_context_by_id(&ctx->main_ctx, (uint32_t)screenID);
1758 if (ctx_screen != NULL) {
1759 *pScreenProperties = ctx_screen->prop;
1760 create_layerids(ctx_screen, &pScreenProperties->layerIds,
1761 &pScreenProperties->layerCount);
1762 returnValue = ILM_SUCCESS;
1766 pScreenProperties->layerCount = 0;
1767 pScreenProperties->harwareLayerCount = 0;
1768 pScreenProperties->layerIds = NULL;
1769 pScreenProperties->screenWidth = 0;
1770 pScreenProperties->screenHeight = 0;
1773 unlock_context(ctx);
1777 static ilmErrorTypes
1778 wayland_getNumberOfHardwareLayers(t_ilm_uint screenID,
1779 t_ilm_uint* pNumberOfHardwareLayers)
1783 if (pNumberOfHardwareLayers != NULL) {
1784 *pNumberOfHardwareLayers = 0;
1791 static ilmErrorTypes
1792 wayland_getScreenIDs(t_ilm_uint* pNumberOfIDs, t_ilm_uint** ppIDs)
1794 ilmErrorTypes returnValue = ILM_FAILED;
1795 struct ilm_control_context *ctx = get_instance();
1798 if ((pNumberOfIDs != NULL) && (ppIDs != NULL)) {
1799 struct screen_context *ctx_scrn = NULL;
1800 t_ilm_uint length = wl_list_length(&ctx->main_ctx.list_screen);
1803 *ppIDs = (t_ilm_uint*)malloc(length * sizeof *ppIDs);
1804 if (*ppIDs != NULL) {
1805 t_ilm_uint* ids = *ppIDs;
1806 wl_list_for_each(ctx_scrn, &ctx->main_ctx.list_screen, link) {
1807 *ids = ctx_scrn->id_screen;
1810 *pNumberOfIDs = length;
1812 returnValue = ILM_SUCCESS;
1816 unlock_context(ctx);
1820 static ilmErrorTypes
1821 wayland_getLayerIDs(t_ilm_int* pLength, t_ilm_layer** ppArray)
1823 ilmErrorTypes returnValue = ILM_FAILED;
1824 struct ilm_control_context *ctx = get_instance();
1827 if ((pLength != NULL) && (ppArray != NULL)) {
1828 struct layer_context *ctx_layer = NULL;
1829 t_ilm_uint length = wl_list_length(&ctx->main_ctx.list_layer);
1832 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
1833 if (*ppArray != NULL) {
1834 // compositor sends layers in opposite order
1835 // write ids from back to front to turn them around
1836 t_ilm_layer* ids = *ppArray;
1837 wl_list_for_each_reverse(ctx_layer, &ctx->main_ctx.list_layer, link)
1839 *ids = ctx_layer->id_layer;
1844 returnValue = ILM_SUCCESS;
1848 unlock_context(ctx);
1852 static ilmErrorTypes
1853 wayland_getLayerIDsOnScreen(t_ilm_uint screenId,
1855 t_ilm_layer** ppArray)
1857 ilmErrorTypes returnValue = ILM_FAILED;
1858 struct ilm_control_context *ctx = get_instance();
1861 if ((pLength != NULL) && (ppArray != NULL)) {
1862 struct screen_context *ctx_screen = NULL;
1863 ctx_screen = get_screen_context_by_id(&ctx->main_ctx, screenId);
1864 if (ctx_screen != NULL) {
1865 struct layer_context *ctx_layer = NULL;
1866 t_ilm_int length = wl_list_length(&ctx_screen->order.list_layer);
1870 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
1871 if (*ppArray != NULL) {
1872 // compositor sends layers in opposite order
1873 // write ids from back to front to turn them around
1874 t_ilm_layer* ids = *ppArray;
1875 wl_list_for_each_reverse(ctx_layer, &ctx_screen->order.list_layer, order.link)
1877 *ids = ctx_layer->id_layer;
1889 returnValue = ILM_SUCCESS;
1893 unlock_context(ctx);
1897 static ilmErrorTypes
1898 wayland_getSurfaceIDs(t_ilm_int* pLength, t_ilm_surface** ppArray)
1900 ilmErrorTypes returnValue = ILM_FAILED;
1901 struct ilm_control_context *ctx = get_instance();
1904 if ((pLength != NULL) && (ppArray != NULL)) {
1905 struct surface_context *ctx_surf = NULL;
1906 t_ilm_uint length = wl_list_length(&ctx->main_ctx.list_surface);
1909 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
1910 if (*ppArray != NULL) {
1911 t_ilm_surface* ids = *ppArray;
1912 wl_list_for_each_reverse(ctx_surf, &ctx->main_ctx.list_surface, link) {
1913 *ids = ctx_surf->id_surface;
1918 returnValue = ILM_SUCCESS;
1922 unlock_context(ctx);
1926 static ilmErrorTypes
1927 wayland_getSurfaceIDsOnLayer(t_ilm_layer layer,
1929 t_ilm_surface** ppArray)
1931 struct ilm_control_context *ctx = get_instance();
1933 struct layer_context *ctx_layer = NULL;
1934 struct surface_context *ctx_surf = NULL;
1935 t_ilm_uint length = 0;
1936 t_ilm_surface* ids = NULL;
1938 if ((pLength == NULL) || (ppArray == NULL)) {
1939 unlock_context(ctx);
1943 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
1944 &ctx->main_ctx, (uint32_t)layer);
1946 if (ctx_layer == NULL) {
1947 unlock_context(ctx);
1951 length = wl_list_length(&ctx_layer->order.list_surface);
1952 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
1953 if (*ppArray == NULL) {
1954 unlock_context(ctx);
1959 wl_list_for_each_reverse(ctx_surf, &ctx_layer->order.list_surface, order.link) {
1960 *ids = (t_ilm_surface)ctx_surf->id_surface;
1965 unlock_context(ctx);
1969 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid)
1971 struct layer_context *ctx_layer = calloc(1, sizeof *ctx_layer);
1972 if (ctx_layer == NULL) {
1973 fprintf(stderr, "Failed to allocate memory for layer_context\n");
1977 ctx_layer->controller = ivi_controller_layer_create(
1979 layerid, width, height);
1980 if (ctx_layer->controller == NULL) {
1981 fprintf(stderr, "Failed to create layer\n");
1985 ctx_layer->id_layer = layerid;
1986 ctx_layer->ctx = ctx;
1988 wl_list_init(&ctx_layer->link);
1989 wl_list_insert(&ctx->list_layer, &ctx_layer->link);
1990 wl_list_init(&ctx_layer->order.link);
1991 wl_list_init(&ctx_layer->order.list_surface);
1993 ivi_controller_layer_add_listener(ctx_layer->controller,
1994 &controller_layer_listener, ctx_layer);
1999 static ilmErrorTypes
2000 wayland_layerCreateWithDimension(t_ilm_layer* pLayerId,
2004 ilmErrorTypes returnValue = ILM_FAILED;
2005 struct ilm_control_context *ctx = get_instance();
2007 uint32_t layerid = 0;
2008 int32_t is_inside = 0;
2011 if (pLayerId == NULL) {
2015 if (*pLayerId != INVALID_ID) {
2016 /* Return failed, if layerid is already inside list_layer */
2017 is_inside = wayland_controller_is_inside_layer_list(
2018 &ctx->main_ctx.list_layer, *pLayerId);
2019 if (0 != is_inside) {
2020 fprintf(stderr, "layerid=%d is already used.\n", *pLayerId);
2023 layerid = *pLayerId;
2026 /* Generate ID, if layerid is INVALID_ID */
2027 layerid = gen_layer_id(ctx);
2028 *pLayerId = layerid;
2031 if (create_controller_layer(&ctx->main_ctx, width, height, layerid) == 0)
2033 returnValue = ILM_SUCCESS;
2037 unlock_context(ctx);
2041 static ilmErrorTypes
2042 wayland_layerRemove(t_ilm_layer layerId)
2044 ilmErrorTypes returnValue = ILM_FAILED;
2045 struct ilm_control_context *ctx = get_instance();
2047 struct layer_context *ctx_layer = NULL;
2048 struct layer_context *ctx_next = NULL;
2050 wl_list_for_each_safe(ctx_layer, ctx_next,
2051 &ctx->main_ctx.list_layer, link) {
2052 if (ctx_layer->id_layer == layerId) {
2053 ivi_controller_layer_destroy(ctx_layer->controller, 1);
2055 wl_list_remove(&ctx_layer->link);
2058 returnValue = ILM_SUCCESS;
2063 unlock_context(ctx);
2067 static ilmErrorTypes
2068 wayland_layerGetType(t_ilm_layer layerId, ilmLayerType* pLayerType)
2072 return ILM_ERROR_INVALID_ARGUMENTS;
2075 struct ilm_control_context *ctx = get_instance();
2078 *pLayerType = wayland_controller_is_inside_layer_list(&ctx->main_ctx.list_layer, layerId) ?
2079 ILM_LAYERTYPE_SOFTWARE2D :
2080 ILM_LAYERTYPE_UNKNOWN;
2082 unlock_context(ctx);
2083 return ILM_SUCCESS; // even if non existent?
2086 static ilmErrorTypes
2087 wayland_layerSetVisibility(t_ilm_layer layerId, t_ilm_bool newVisibility)
2089 ilmErrorTypes returnValue = ILM_FAILED;
2090 struct ilm_control_context *ctx = get_instance();
2092 struct layer_context *ctx_layer = NULL;
2094 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2095 &ctx->main_ctx, (uint32_t)layerId);
2097 if (ctx_layer != NULL) {
2098 uint32_t visibility = 0;
2099 if (newVisibility == ILM_TRUE) {
2102 ivi_controller_layer_set_visibility(ctx_layer->controller,
2104 returnValue = ILM_SUCCESS;
2107 unlock_context(ctx);
2111 static ilmErrorTypes
2112 wayland_layerGetVisibility(t_ilm_layer layerId, t_ilm_bool *pVisibility)
2114 ilmErrorTypes returnValue = ILM_FAILED;
2115 struct ilm_control_context *ctx = get_instance();
2118 if (pVisibility != NULL) {
2119 struct layer_context *ctx_layer = NULL;
2121 ctx_layer = (struct layer_context*)
2122 wayland_controller_get_layer_context(
2123 &ctx->main_ctx, (uint32_t)layerId);
2125 if (ctx_layer != NULL) {
2126 *pVisibility = ctx_layer->prop.visibility;
2127 returnValue = ILM_SUCCESS;
2131 unlock_context(ctx);
2135 static ilmErrorTypes
2136 wayland_layerSetOpacity(t_ilm_layer layerId, t_ilm_float opacity)
2138 ilmErrorTypes returnValue = ILM_FAILED;
2139 struct ilm_control_context *ctx = get_instance();
2141 struct layer_context *ctx_layer = NULL;
2143 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2144 &ctx->main_ctx, (uint32_t)layerId);
2146 if (ctx_layer != NULL) {
2147 wl_fixed_t opacity_fixed = wl_fixed_from_double((double)opacity);
2148 ivi_controller_layer_set_opacity(ctx_layer->controller,
2150 returnValue = ILM_SUCCESS;
2153 unlock_context(ctx);
2157 static ilmErrorTypes
2158 wayland_layerGetOpacity(t_ilm_layer layerId, t_ilm_float *pOpacity)
2160 ilmErrorTypes returnValue = ILM_FAILED;
2161 struct ilm_control_context *ctx = get_instance();
2164 if (pOpacity != NULL) {
2165 struct layer_context *ctx_layer = NULL;
2167 ctx_layer = (struct layer_context*)
2168 wayland_controller_get_layer_context(
2169 &ctx->main_ctx, (uint32_t)layerId);
2171 if (ctx_layer != NULL) {
2172 *pOpacity = ctx_layer->prop.opacity;
2173 returnValue = ILM_SUCCESS;
2177 unlock_context(ctx);
2181 static ilmErrorTypes
2182 wayland_layerSetSourceRectangle(t_ilm_layer layerId,
2183 t_ilm_uint x, t_ilm_uint y,
2184 t_ilm_uint width, t_ilm_uint height)
2186 ilmErrorTypes returnValue = ILM_FAILED;
2187 struct ilm_control_context *ctx = get_instance();
2189 struct layer_context *ctx_layer = NULL;
2191 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2192 &ctx->main_ctx, (uint32_t)layerId);
2194 if (ctx_layer != NULL) {
2195 ivi_controller_layer_set_source_rectangle(ctx_layer->controller,
2200 returnValue = ILM_SUCCESS;
2203 unlock_context(ctx);
2207 static ilmErrorTypes
2208 wayland_layerSetDestinationRectangle(t_ilm_layer layerId,
2209 t_ilm_int x, t_ilm_int y,
2210 t_ilm_int width, t_ilm_int height)
2212 ilmErrorTypes returnValue = ILM_FAILED;
2213 struct ilm_control_context *ctx = get_instance();
2215 struct layer_context *ctx_layer = NULL;
2217 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2218 &ctx->main_ctx, (uint32_t)layerId);
2219 if (ctx_layer != NULL) {
2220 ivi_controller_layer_set_destination_rectangle(
2221 ctx_layer->controller,
2222 (uint32_t)x, (uint32_t)y,
2225 returnValue = ILM_SUCCESS;
2228 unlock_context(ctx);
2232 static ilmErrorTypes
2233 wayland_layerGetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
2235 ilmErrorTypes returnValue = ILM_FAILED;
2236 struct ilm_control_context *ctx = get_instance();
2238 struct layer_context *ctx_layer = NULL;
2240 if (pDimension != NULL) {
2241 ctx_layer = (struct layer_context*)
2242 wayland_controller_get_layer_context(
2243 &ctx->main_ctx, (uint32_t)layerId);
2244 if (ctx_layer != NULL) {
2245 *pDimension = ctx_layer->prop.destWidth;
2246 *(pDimension + 1) = ctx_layer->prop.destHeight;
2247 returnValue = ILM_SUCCESS;
2251 unlock_context(ctx);
2255 static ilmErrorTypes
2256 wayland_layerSetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
2258 ilmErrorTypes returnValue = ILM_FAILED;
2259 struct ilm_control_context *ctx = get_instance();
2261 struct layer_context *ctx_layer = NULL;
2263 if (pDimension != NULL) {
2264 ctx_layer = (struct layer_context*)
2265 wayland_controller_get_layer_context(
2266 &ctx->main_ctx, (uint32_t)layerId);
2267 if (ctx_layer != NULL) {
2268 ivi_controller_layer_set_destination_rectangle(
2269 ctx_layer->controller,
2270 ctx_layer->prop.destX, ctx_layer->prop.destY,
2271 (int32_t)*pDimension, (int32_t)*(pDimension + 1));
2272 returnValue = ILM_SUCCESS;
2276 unlock_context(ctx);
2280 static ilmErrorTypes
2281 wayland_layerGetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2283 ilmErrorTypes returnValue = ILM_FAILED;
2284 struct ilm_control_context *ctx = get_instance();
2286 struct layer_context *ctx_layer = NULL;
2288 if (pPosition != NULL) {
2289 ctx_layer = (struct layer_context*)
2290 wayland_controller_get_layer_context(
2291 &ctx->main_ctx, (uint32_t)layerId);
2292 if (ctx_layer != NULL) {
2293 *pPosition = ctx_layer->prop.destX;
2294 *(pPosition + 1) = ctx_layer->prop.destY;
2295 returnValue = ILM_SUCCESS;
2299 unlock_context(ctx);
2303 static ilmErrorTypes
2304 wayland_layerSetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2306 ilmErrorTypes returnValue = ILM_FAILED;
2307 struct ilm_control_context *ctx = get_instance();
2309 struct layer_context *ctx_layer = NULL;
2311 if (pPosition != NULL) {
2312 ctx_layer = (struct layer_context*)
2313 wayland_controller_get_layer_context(
2314 &ctx->main_ctx, (uint32_t)layerId);
2315 if (ctx_layer != NULL) {
2316 ivi_controller_layer_set_destination_rectangle(
2317 ctx_layer->controller,
2318 (int32_t)*pPosition, (int32_t)*(pPosition + 1),
2319 ctx_layer->prop.destWidth, ctx_layer->prop.destHeight);
2320 returnValue = ILM_SUCCESS;
2324 unlock_context(ctx);
2328 static ilmErrorTypes
2329 wayland_layerSetOrientation(t_ilm_layer layerId, ilmOrientation orientation)
2331 ilmErrorTypes returnValue = ILM_FAILED;
2332 struct ilm_control_context *ctx = get_instance();
2334 struct layer_context *ctx_layer = NULL;
2335 int32_t iviorientation = 0;
2338 switch(orientation) {
2340 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2343 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2345 case ILM_ONEHUNDREDEIGHTY:
2346 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2348 case ILM_TWOHUNDREDSEVENTY:
2349 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2352 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2356 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2357 &ctx->main_ctx, (uint32_t)layerId);
2358 if (ctx_layer == NULL) {
2359 returnValue = ILM_FAILED;
2363 ivi_controller_layer_set_orientation(ctx_layer->controller,
2366 returnValue = ILM_SUCCESS;
2369 unlock_context(ctx);
2373 static ilmErrorTypes
2374 wayland_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrientation)
2376 ilmErrorTypes returnValue = ILM_FAILED;
2377 struct ilm_control_context *ctx = get_instance();
2379 struct layer_context *ctx_layer = NULL;
2381 if (pOrientation != NULL) {
2382 ctx_layer = (struct layer_context*)
2383 wayland_controller_get_layer_context(
2384 &ctx->main_ctx, (uint32_t)layerId);
2385 if (ctx_layer != NULL) {
2386 *pOrientation = ctx_layer->prop.orientation;
2387 returnValue = ILM_SUCCESS;
2391 unlock_context(ctx);
2395 static ilmErrorTypes
2396 wayland_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
2404 static ilmErrorTypes
2405 wayland_layerSetRenderOrder(t_ilm_layer layerId,
2406 t_ilm_surface *pSurfaceId,
2409 ilmErrorTypes returnValue = ILM_FAILED;
2410 struct ilm_control_context *ctx = get_instance();
2412 struct layer_context *ctx_layer = NULL;
2414 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2415 &ctx->main_ctx, (uint32_t)layerId);
2419 struct surface_context *ctx_surf = NULL;
2420 ivi_controller_layer_clear_surfaces(ctx_layer->controller);
2422 for (cnt = 0; cnt < number; cnt++) {
2423 id = (uint32_t)*(pSurfaceId + cnt);
2424 ctx_surf = get_surface_context(&ctx->main_ctx, id);
2426 if (ctx_surf == NULL) {
2427 fprintf(stderr, "invalud argument \
2428 in ilm_layerSetRenderOrder\n");
2431 ivi_controller_layer_add_surface(ctx_layer->controller,
2432 ctx_surf->controller);
2435 returnValue = ILM_SUCCESS;
2438 unlock_context(ctx);
2442 static ilmErrorTypes
2443 wayland_layerGetCapabilities(t_ilm_layer layerId,
2444 t_ilm_layercapabilities *pCapabilities)
2447 (void)pCapabilities;
2452 static ilmErrorTypes
2453 wayland_layerTypeGetCapabilities(ilmLayerType layerType,
2454 t_ilm_layercapabilities *pCapabilities)
2457 (void)pCapabilities;
2462 static ilmErrorTypes
2463 wayland_surfaceSetVisibility(t_ilm_surface surfaceId, t_ilm_bool newVisibility)
2465 ilmErrorTypes returnValue = ILM_FAILED;
2466 struct ilm_control_context *ctx = get_instance();
2468 struct surface_context *ctx_surf = NULL;
2469 uint32_t visibility = 0;
2471 if (newVisibility == ILM_TRUE) {
2474 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2476 ivi_controller_surface_set_visibility(ctx_surf->controller,
2478 returnValue = ILM_SUCCESS;
2481 unlock_context(ctx);
2485 static ilmErrorTypes
2486 wayland_surfaceSetOpacity(t_ilm_surface surfaceId, t_ilm_float opacity)
2488 ilmErrorTypes returnValue = ILM_FAILED;
2489 struct ilm_control_context *ctx = get_instance();
2491 struct surface_context *ctx_surf = NULL;
2492 wl_fixed_t opacity_fixed = 0;
2494 opacity_fixed = wl_fixed_from_double((double)opacity);
2495 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2497 ivi_controller_surface_set_opacity(ctx_surf->controller,
2499 returnValue = ILM_SUCCESS;
2502 unlock_context(ctx);
2506 static ilmErrorTypes
2507 wayland_surfaceGetOpacity(t_ilm_surface surfaceId, t_ilm_float *pOpacity)
2509 ilmErrorTypes returnValue = ILM_FAILED;
2510 struct ilm_control_context *ctx = get_instance();
2513 if (pOpacity != NULL) {
2514 struct surface_context *ctx_surf = NULL;
2515 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2517 *pOpacity = ctx_surf->prop.opacity;
2518 returnValue = ILM_SUCCESS;
2522 unlock_context(ctx);
2526 static ilmErrorTypes
2527 wayland_SetKeyboardFocusOn(t_ilm_surface surfaceId)
2529 ilmErrorTypes returnValue = ILM_FAILED;
2531 returnValue = ILM_SUCCESS;
2535 static ilmErrorTypes
2536 wayland_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
2538 ilmErrorTypes returnValue = ILM_FAILED;
2540 returnValue = ILM_SUCCESS;
2544 static ilmErrorTypes
2545 wayland_surfaceSetDestinationRectangle(t_ilm_surface surfaceId,
2546 t_ilm_int x, t_ilm_int y,
2547 t_ilm_int width, t_ilm_int height)
2549 ilmErrorTypes returnValue = ILM_FAILED;
2550 struct ilm_control_context *ctx = get_instance();
2552 struct surface_context *ctx_surf = NULL;
2554 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2556 ivi_controller_surface_set_destination_rectangle(
2557 ctx_surf->controller,
2558 x, y, width, height);
2559 returnValue = ILM_SUCCESS;
2562 unlock_context(ctx);
2566 static ilmErrorTypes
2567 wayland_surfaceSetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
2569 ilmErrorTypes returnValue = ILM_FAILED;
2570 struct ilm_control_context *ctx = get_instance();
2573 if (pDimension != NULL) {
2574 struct surface_context *ctx_surf = NULL;
2575 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2577 uint32_t width = *pDimension;
2578 uint32_t height = *(pDimension + 1);
2579 ivi_controller_surface_set_destination_rectangle(
2580 ctx_surf->controller,
2581 ctx_surf->prop.destX, ctx_surf->prop.destY, width, height);
2582 returnValue = ILM_SUCCESS;
2586 unlock_context(ctx);
2590 static ilmErrorTypes
2591 wayland_surfaceGetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2593 ilmErrorTypes returnValue = ILM_FAILED;
2594 struct ilm_control_context *ctx = get_instance();
2597 if (pPosition != NULL) {
2598 struct surface_context *ctx_surf = NULL;
2599 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2601 *pPosition = ctx_surf->prop.destX;
2602 *(pPosition + 1) = ctx_surf->prop.destY;
2603 returnValue = ILM_SUCCESS;
2607 unlock_context(ctx);
2611 static ilmErrorTypes
2612 wayland_surfaceSetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
2614 ilmErrorTypes returnValue = ILM_FAILED;
2615 struct ilm_control_context *ctx = get_instance();
2618 if (pPosition != NULL) {
2619 struct surface_context *ctx_surf = NULL;
2620 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2622 int32_t destX = (int32_t)*pPosition;
2623 int32_t destY = (int32_t)*(pPosition + 1);
2624 ivi_controller_surface_set_destination_rectangle(
2625 ctx_surf->controller, destX, destY,
2626 ctx_surf->prop.destWidth, ctx_surf->prop.destHeight);
2627 returnValue = ILM_SUCCESS;
2631 unlock_context(ctx);
2635 static ilmErrorTypes
2636 wayland_surfaceSetOrientation(t_ilm_surface surfaceId,
2637 ilmOrientation orientation)
2639 ilmErrorTypes returnValue = ILM_FAILED;
2640 struct ilm_control_context *ctx = get_instance();
2642 struct surface_context *ctx_surf = NULL;
2643 int32_t iviorientation = 0;
2646 switch(orientation) {
2648 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2651 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2653 case ILM_ONEHUNDREDEIGHTY:
2654 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2656 case ILM_TWOHUNDREDSEVENTY:
2657 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2660 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2664 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2665 if (ctx_surf == NULL) {
2666 returnValue = ILM_FAILED;
2670 ivi_controller_surface_set_orientation(ctx_surf->controller,
2673 returnValue = ILM_SUCCESS;
2676 unlock_context(ctx);
2680 static ilmErrorTypes
2681 wayland_surfaceGetOrientation(t_ilm_surface surfaceId,
2682 ilmOrientation *pOrientation)
2684 ilmErrorTypes returnValue = ILM_FAILED;
2685 struct ilm_control_context *ctx = get_instance();
2688 if (pOrientation != NULL) {
2689 struct surface_context *ctx_surf = NULL;
2690 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2692 *pOrientation = ctx_surf->prop.orientation;
2693 returnValue = ILM_SUCCESS;
2697 unlock_context(ctx);
2701 static ilmErrorTypes
2702 wayland_surfaceGetPixelformat(t_ilm_layer surfaceId,
2703 ilmPixelFormat *pPixelformat)
2705 ilmErrorTypes returnValue = ILM_FAILED;
2706 struct ilm_control_context *ctx = get_instance();
2709 if (pPixelformat != NULL) {
2710 struct surface_context *ctx_surf = NULL;
2711 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2713 *pPixelformat = ctx_surf->prop.pixelformat;
2714 returnValue = ILM_SUCCESS;
2718 unlock_context(ctx);
2722 static ilmErrorTypes
2723 wayland_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
2731 static ilmErrorTypes
2732 wayland_displaySetRenderOrder(t_ilm_display display,
2733 t_ilm_layer *pLayerId, const t_ilm_uint number)
2735 ilmErrorTypes returnValue = ILM_FAILED;
2736 struct ilm_control_context *ctx = get_instance();
2738 struct screen_context *ctx_scrn = NULL;
2740 ctx_scrn = get_screen_context_by_id(&ctx->main_ctx, (uint32_t)display);
2741 if (ctx_scrn != NULL) {
2744 struct layer_context *ctx_layer = NULL;
2746 ivi_controller_screen_clear(ctx_scrn->controller);
2748 for (cnt = 0; cnt < (int)number; cnt++) {
2749 id = (uint32_t)*(pLayerId + cnt);
2751 (struct layer_context*)wayland_controller_get_layer_context(
2752 &ctx->main_ctx, id);
2753 if (ctx_layer != NULL) {
2754 ivi_controller_screen_add_layer(ctx_scrn->controller,
2755 ctx_layer->controller);
2759 returnValue = ILM_SUCCESS;
2762 unlock_context(ctx);
2766 static ilmErrorTypes
2767 wayland_takeScreenshot(t_ilm_uint screen, t_ilm_const_string filename)
2769 ilmErrorTypes returnValue = ILM_FAILED;
2770 struct ilm_control_context *ctx = get_instance();
2772 struct screen_context *ctx_scrn = NULL;
2774 ctx_scrn = get_screen_context_by_id(&ctx->main_ctx, (uint32_t)screen);
2775 if (ctx_scrn != NULL) {
2776 ivi_controller_screen_screenshot(ctx_scrn->controller,
2778 wl_display_flush(ctx->main_ctx.display);
2779 returnValue = ILM_SUCCESS;
2782 unlock_context(ctx);
2786 static ilmErrorTypes
2787 wayland_takeLayerScreenshot(t_ilm_const_string filename, t_ilm_layer layerid)
2789 ilmErrorTypes returnValue = ILM_FAILED;
2790 struct ilm_control_context *ctx = get_instance();
2792 struct layer_context *ctx_layer = NULL;
2794 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2795 &ctx->main_ctx, (uint32_t)layerid);
2796 if (ctx_layer != NULL) {
2797 ivi_controller_layer_screenshot(ctx_layer->controller,
2799 returnValue = ILM_SUCCESS;
2802 unlock_context(ctx);
2806 static ilmErrorTypes
2807 wayland_takeSurfaceScreenshot(t_ilm_const_string filename,
2808 t_ilm_surface surfaceid)
2810 ilmErrorTypes returnValue = ILM_FAILED;
2811 struct ilm_control_context *ctx = get_instance();
2813 struct surface_context *ctx_surf = NULL;
2815 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceid);
2817 ivi_controller_surface_screenshot(ctx_surf->controller,
2819 wl_display_flush(ctx->main_ctx.display);
2820 returnValue = ILM_SUCCESS;
2823 unlock_context(ctx);
2827 static ilmErrorTypes
2828 wayland_SetOptimizationMode(ilmOptimization id, ilmOptimizationMode mode)
2836 static ilmErrorTypes
2837 wayland_GetOptimizationMode(ilmOptimization id, ilmOptimizationMode* pMode)
2846 static ilmErrorTypes
2847 wayland_layerAddNotification(t_ilm_layer layer,
2848 layerNotificationFunc callback)
2850 ilmErrorTypes returnValue = ILM_FAILED;
2851 struct ilm_control_context *ctx = get_instance();
2853 struct layer_context *ctx_layer = NULL;
2855 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2856 &ctx->main_ctx, (uint32_t)layer);
2857 if (ctx_layer == NULL) {
2858 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2860 ctx_layer->notification = callback;
2862 returnValue = ILM_SUCCESS;
2865 unlock_context(ctx);
2870 static ilmErrorTypes
2871 wayland_layerRemoveNotification(t_ilm_layer layer)
2873 return wayland_layerAddNotification(layer, NULL);
2877 static ilmErrorTypes
2878 wayland_surfaceAddNotification(t_ilm_surface surface,
2879 surfaceNotificationFunc callback)
2881 ilmErrorTypes returnValue = ILM_FAILED;
2882 struct ilm_control_context *ctx = get_instance();
2884 struct surface_context *ctx_surf = NULL;
2886 ctx_surf = (struct surface_context*)get_surface_context(
2887 &ctx->main_ctx, (uint32_t)surface);
2888 if (ctx_surf == NULL) {
2889 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2891 ctx_surf->notification = callback;
2893 returnValue = ILM_SUCCESS;
2896 unlock_context(ctx);
2901 static ilmErrorTypes
2902 wayland_surfaceRemoveNotification(t_ilm_surface surface)
2904 return wayland_surfaceAddNotification(surface, NULL);
2907 static ilmErrorTypes
2908 wayland_getNativeHandle(t_ilm_uint pid, t_ilm_int *n_handle,
2909 t_ilm_nativehandle **p_handles)
2911 struct ilm_control_context *ctx = get_instance();
2913 struct nativehandle_context *p_nh_ctx = NULL;
2918 wl_list_for_each(p_nh_ctx, &ctx->list_nativehandle, link)
2920 if (p_nh_ctx->pid == pid)
2924 (t_ilm_nativehandle*)malloc(sizeof(t_ilm_nativehandle));
2925 (*p_handles)[0] = p_nh_ctx->nativehandle;
2930 unlock_context(ctx);
2931 return (*n_handle > 0) ? ILM_SUCCESS : ILM_FAILED;
2934 static ilmErrorTypes
2935 wayland_getPropertiesOfSurface(t_ilm_uint surfaceID,
2936 struct ilmSurfaceProperties* pSurfaceProperties)
2938 ilmErrorTypes returnValue = ILM_FAILED;
2939 struct ilm_control_context *ctx = get_instance();
2942 if (pSurfaceProperties != NULL) {
2943 struct surface_context *ctx_surf = NULL;
2945 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceID);
2946 if (ctx_surf != NULL) {
2948 *pSurfaceProperties = ctx_surf->prop;
2949 returnValue = ILM_SUCCESS;
2953 unlock_context(ctx);
2957 static ilmErrorTypes
2958 wayland_layerAddSurface(t_ilm_layer layerId,
2959 t_ilm_surface surfaceId)
2961 ilmErrorTypes returnValue = ILM_FAILED;
2962 struct ilm_control_context *ctx = get_instance();
2964 struct layer_context *ctx_layer = NULL;
2965 struct surface_context *ctx_surf = NULL;
2967 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2968 &ctx->main_ctx, (uint32_t)layerId);
2969 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
2970 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2971 ivi_controller_layer_add_surface(ctx_layer->controller,
2972 ctx_surf->controller);
2973 returnValue = ILM_SUCCESS;
2976 unlock_context(ctx);
2980 static ilmErrorTypes
2981 wayland_layerRemoveSurface(t_ilm_layer layerId,
2982 t_ilm_surface surfaceId)
2984 ilmErrorTypes returnValue = ILM_FAILED;
2985 struct ilm_control_context *ctx = get_instance();
2987 struct layer_context *ctx_layer = NULL;
2988 struct surface_context *ctx_surf = NULL;
2990 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2991 &ctx->main_ctx, (uint32_t)layerId);
2992 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
2993 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
2994 ivi_controller_layer_remove_surface(ctx_layer->controller,
2995 ctx_surf->controller);
2996 returnValue = ILM_SUCCESS;
2999 unlock_context(ctx);
3003 static ilmErrorTypes
3004 wayland_surfaceGetDimension(t_ilm_surface surfaceId,
3005 t_ilm_uint *pDimension)
3007 ilmErrorTypes returnValue = ILM_FAILED;
3008 struct ilm_control_context *ctx = get_instance();
3011 if (pDimension != NULL) {
3012 struct surface_context *ctx_surf = NULL;
3014 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
3015 if (ctx_surf != NULL) {
3016 *pDimension = (t_ilm_uint)ctx_surf->prop.destWidth;
3017 *(pDimension + 1) = (t_ilm_uint)ctx_surf->prop.destHeight;
3018 returnValue = ILM_SUCCESS;
3022 unlock_context(ctx);
3026 static ilmErrorTypes
3027 wayland_surfaceGetVisibility(t_ilm_surface surfaceId,
3028 t_ilm_bool *pVisibility)
3030 ilmErrorTypes returnValue = ILM_FAILED;
3031 struct ilm_control_context *ctx = get_instance();
3033 struct surface_context *ctx_surf = NULL;
3035 if (pVisibility != NULL) {
3036 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
3037 if (ctx_surf != NULL) {
3038 *pVisibility = (t_ilm_bool)ctx_surf->prop.visibility;
3039 returnValue = ILM_SUCCESS;
3043 unlock_context(ctx);
3047 static ilmErrorTypes
3048 wayland_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
3049 t_ilm_int x, t_ilm_int y,
3050 t_ilm_int width, t_ilm_int height)
3052 ilmErrorTypes returnValue = ILM_FAILED;
3053 struct ilm_control_context *ctx = get_instance();
3055 struct surface_context *ctx_surf = NULL;
3057 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
3058 if (ctx_surf != NULL) {
3059 if (ctx_surf->controller != NULL) {
3060 ivi_controller_surface_set_source_rectangle(
3061 ctx_surf->controller,
3062 x, y, width, height);
3063 returnValue = ILM_SUCCESS;
3067 unlock_context(ctx);
3071 static ilmErrorTypes
3072 wayland_commitChanges(void)
3074 ilmErrorTypes returnValue = ILM_FAILED;
3075 struct ilm_control_context *ctx = get_instance();
3078 if (ctx->main_ctx.controller != NULL) {
3079 ivi_controller_commit_changes(ctx->main_ctx.controller);
3081 display_roundtrip_queue(ctx->main_ctx.display, ctx->main_ctx.queue);
3082 returnValue = ILM_SUCCESS;
3085 unlock_context(ctx);