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();
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();
152 void init_ilmControlPlatformTable()
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 ilm_control_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 ilm_control_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_compositor *compositor;
338 struct ivi_controller *controller;
341 struct wl_list list_surface;
342 struct wl_list list_layer;
343 struct wl_list list_screen;
346 struct ilm_control_context {
347 struct wayland_context main_ctx;
348 struct wayland_context child_ctx;
353 uint32_t internal_id_layer;
355 struct wl_list list_nativehandle;
358 pthread_mutex_t mutex;
359 uint32_t internal_id_surface;
363 wayland_controller_is_inside_surface_list(struct wl_list *list,
366 struct surface_context *ctx_surf = NULL;
367 wl_list_for_each(ctx_surf, list, link) {
368 if (ctx_surf->id_surface == id_surface) {
377 wayland_controller_is_inside_layer_list(struct wl_list *list,
380 struct layer_context *ctx_layer = NULL;
381 wl_list_for_each(ctx_layer, list, link) {
382 if (ctx_layer->id_layer == id_layer) {
390 static struct layer_context*
391 wayland_controller_get_layer_context(struct wayland_context *ctx,
394 struct layer_context *ctx_layer = NULL;
396 if (ctx->controller == NULL) {
397 fprintf(stderr, "controller is not initialized in ilmControl\n");
401 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
402 if (ctx_layer->id_layer == id_layer) {
407 fprintf(stderr, "failed to get layer context in ilmControl\n");
411 static struct ilm_control_context* get_instance();
414 output_listener_geometry(void *data,
415 struct wl_output *output,
418 int32_t physical_width,
419 int32_t physical_height,
425 struct screen_context *ctx_scrn = data;
434 ctx_scrn->prop.screenWidth = physical_width;
435 ctx_scrn->prop.screenHeight = physical_height;
439 output_listener_mode(void *data,
440 struct wl_output *output,
455 output_listener_done(void *data,
456 struct wl_output *output)
463 output_listener_scale(void *data,
464 struct wl_output *output,
472 static struct wl_output_listener output_listener = {
473 output_listener_geometry,
474 output_listener_mode,
475 output_listener_done,
476 output_listener_scale
479 static struct screen_context*
480 get_screen_context_by_output(struct wayland_context *ctx,
481 struct wl_output *output)
483 struct screen_context *ctx_scrn = NULL;
484 struct wl_proxy *pxy_out = NULL;
485 struct wl_proxy *pxy_out_in_scrn = NULL;
487 uint32_t pxy_id_in_scrn = 0;
489 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
490 pxy_out = (struct wl_proxy*)output;
491 pxy_out_in_scrn = (struct wl_proxy*)ctx_scrn->output;
492 pxy_id = wl_proxy_get_id(pxy_out);
493 pxy_id_in_scrn = wl_proxy_get_id(pxy_out_in_scrn);
494 if (pxy_id == pxy_id_in_scrn) {
501 static struct screen_context*
502 get_screen_context_by_serverid(struct wayland_context *ctx,
505 struct screen_context *ctx_scrn = NULL;
507 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
508 if (ctx_scrn->id_from_server == id_screen) {
516 add_orderlayer_to_screen(struct wayland_context *ctx,
517 struct layer_context *ctx_layer,
518 struct wl_output* output)
520 struct screen_context *ctx_scrn = NULL;
522 ctx_scrn = get_screen_context_by_output(ctx, output);
523 if (ctx_scrn == NULL) {
524 fprintf(stderr, "failed to add_orderlayer_to_screen\n");
529 struct layer_context *layer_link;
530 wl_list_for_each(layer_link, &ctx_scrn->order.list_layer, order.link) {
531 if (layer_link == ctx_layer) {
538 wl_list_init(&ctx_layer->order.link);
539 wl_list_insert(&ctx_scrn->order.list_layer, &ctx_layer->order.link);
544 remove_orderlayer_from_screen(struct wayland_context *ctx,
545 struct layer_context *ctx_layer)
547 struct screen_context *ctx_scrn = NULL;
548 struct layer_context *ctx_orderlayer = NULL;
549 struct layer_context *next = NULL;
550 struct wl_proxy *pxy_layer = NULL;
551 struct wl_proxy *pxy_orderlayer = NULL;
552 uint32_t id_layer = 0;
553 uint32_t id_orderlayer = 0;
555 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
556 wl_list_for_each_safe(ctx_orderlayer, next,
557 &ctx_scrn->order.list_layer,
559 pxy_layer = (struct wl_proxy*)ctx_layer->controller;
560 pxy_orderlayer = (struct wl_proxy*)ctx_orderlayer->controller;
561 id_layer = wl_proxy_get_id(pxy_layer);
562 id_orderlayer = wl_proxy_get_id(pxy_orderlayer);
563 if (id_layer == id_orderlayer) {
564 wl_list_remove(&ctx_orderlayer->order.link);
571 static struct layer_context*
572 get_layer_context_by_controller(struct wayland_context *ctx,
573 struct ivi_controller_layer *controller)
575 struct layer_context *ctx_layer = NULL;
576 struct wl_proxy *pxy_layer = NULL;
577 struct wl_proxy *pxy_addlayer = NULL;
578 uint32_t id_layer = 0;
579 uint32_t id_addlayer = 0;
581 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
582 pxy_layer = (struct wl_proxy*)ctx_layer->controller;
583 pxy_addlayer = (struct wl_proxy*)controller;
584 id_layer = wl_proxy_get_id(pxy_layer);
585 id_addlayer = wl_proxy_get_id(pxy_addlayer);
586 if (id_layer == id_addlayer) {
594 controller_layer_listener_visibility_child(void *data,
595 struct ivi_controller_layer *controller,
598 struct ilm_control_context *ctx = data;
599 struct layer_context *ctx_layer = NULL;
601 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
602 if (ctx_layer == NULL) {
603 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
607 ctx_layer->prop.visibility = (t_ilm_bool)visibility;
609 if (ctx_layer->notification != NULL) {
610 ctx_layer->notification(ctx_layer->id_layer,
612 ILM_NOTIFICATION_VISIBILITY);
617 controller_layer_listener_opacity_child(void *data,
618 struct ivi_controller_layer *controller,
621 struct ilm_control_context *ctx = data;
622 struct layer_context *ctx_layer = NULL;
624 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
625 if (ctx_layer == NULL) {
626 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
630 ctx_layer->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
632 if (ctx_layer->notification != NULL) {
633 ctx_layer->notification(ctx_layer->id_layer,
635 ILM_NOTIFICATION_OPACITY);
640 controller_layer_listener_source_rectangle_child(void *data,
641 struct ivi_controller_layer *controller,
647 struct ilm_control_context *ctx = data;
648 struct layer_context *ctx_layer = NULL;
650 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
651 if (ctx_layer == NULL) {
652 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
656 ctx_layer->prop.sourceX = (t_ilm_uint)x;
657 ctx_layer->prop.sourceY = (t_ilm_uint)y;
658 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
659 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
660 if (ctx_layer->prop.origSourceWidth == 0) {
661 ctx_layer->prop.origSourceWidth = (t_ilm_uint)width;
663 if (ctx_layer->prop.origSourceHeight == 0) {
664 ctx_layer->prop.origSourceHeight = (t_ilm_uint)height;
667 if (ctx_layer->notification != NULL) {
668 ctx_layer->notification(ctx_layer->id_layer,
670 ILM_NOTIFICATION_SOURCE_RECT);
675 controller_layer_listener_destination_rectangle_child(void *data,
676 struct ivi_controller_layer *controller,
682 struct ilm_control_context *ctx = data;
683 struct layer_context *ctx_layer = NULL;
685 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
686 if (ctx_layer == NULL) {
687 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
691 ctx_layer->prop.destX = (t_ilm_uint)x;
692 ctx_layer->prop.destY = (t_ilm_uint)y;
693 ctx_layer->prop.destWidth = (t_ilm_uint)width;
694 ctx_layer->prop.destHeight = (t_ilm_uint)height;
696 if (ctx_layer->notification != NULL) {
697 ctx_layer->notification(ctx_layer->id_layer,
699 ILM_NOTIFICATION_DEST_RECT);
704 controller_layer_listener_configuration_child(void *data,
705 struct ivi_controller_layer *controller,
709 struct ilm_control_context *ctx = data;
710 struct layer_context *ctx_layer = NULL;
712 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
713 if (ctx_layer == NULL) {
714 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
718 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
719 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
723 controller_layer_listener_orientation_child(void *data,
724 struct ivi_controller_layer *controller,
727 ilmOrientation ilmorientation = ILM_ZERO;
728 struct ilm_control_context *ctx = data;
729 struct layer_context *ctx_layer = NULL;
731 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
732 if (ctx_layer == NULL) {
733 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
737 switch(orientation) {
738 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
739 ilmorientation = ILM_ZERO;
741 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
742 ilmorientation = ILM_NINETY;
744 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
745 ilmorientation = ILM_ONEHUNDREDEIGHTY;
747 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
748 ilmorientation = ILM_TWOHUNDREDSEVENTY;
754 ctx_layer->prop.orientation = ilmorientation;
756 if (ctx_layer->notification != NULL) {
757 ctx_layer->notification(ctx_layer->id_layer,
759 ILM_NOTIFICATION_ORIENTATION);
764 controller_layer_listener_screen_child(void *data,
765 struct ivi_controller_layer *controller,
766 struct wl_output *output)
768 struct ilm_control_context *ctx = data;
769 struct layer_context *ctx_layer = NULL;
771 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
772 if (ctx_layer == NULL) {
773 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
777 if (output == NULL) {
778 remove_orderlayer_from_screen(&ctx->child_ctx, ctx_layer);
780 add_orderlayer_to_screen(&ctx->child_ctx, ctx_layer, output);
785 controller_layer_listener_destroyed_child(void *data,
786 struct ivi_controller_layer *controller)
788 struct ilm_control_context *ctx = data;
789 struct layer_context *ctx_layer = NULL;
791 ctx_layer = get_layer_context_by_controller(&ctx->child_ctx, controller);
792 if (ctx_layer == NULL) {
793 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
797 wl_list_remove(&ctx_layer->link);
801 static struct ivi_controller_layer_listener controller_layer_listener_child =
803 controller_layer_listener_visibility_child,
804 controller_layer_listener_opacity_child,
805 controller_layer_listener_source_rectangle_child,
806 controller_layer_listener_destination_rectangle_child,
807 controller_layer_listener_configuration_child,
808 controller_layer_listener_orientation_child,
809 controller_layer_listener_screen_child,
810 controller_layer_listener_destroyed_child
814 controller_layer_listener_visibility_main(void *data,
815 struct ivi_controller_layer *controller,
818 struct ilm_control_context *ctx = data;
819 struct layer_context *ctx_layer = NULL;
821 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
822 if (ctx_layer == NULL) {
823 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
827 ctx_layer->prop.visibility = (t_ilm_bool)visibility;
831 controller_layer_listener_opacity_main(void *data,
832 struct ivi_controller_layer *controller,
835 struct ilm_control_context *ctx = data;
836 struct layer_context *ctx_layer = NULL;
838 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
839 if (ctx_layer == NULL) {
840 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
844 ctx_layer->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
848 controller_layer_listener_source_rectangle_main(void *data,
849 struct ivi_controller_layer *controller,
855 struct ilm_control_context *ctx = data;
856 struct layer_context *ctx_layer = NULL;
858 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
859 if (ctx_layer == NULL) {
860 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
864 ctx_layer->prop.sourceX = (t_ilm_uint)x;
865 ctx_layer->prop.sourceY = (t_ilm_uint)y;
866 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
867 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
868 if (ctx_layer->prop.origSourceWidth == 0) {
869 ctx_layer->prop.origSourceWidth = (t_ilm_uint)width;
871 if (ctx_layer->prop.origSourceHeight == 0) {
872 ctx_layer->prop.origSourceHeight = (t_ilm_uint)height;
877 controller_layer_listener_destination_rectangle_main(void *data,
878 struct ivi_controller_layer *controller,
884 struct ilm_control_context *ctx = data;
885 struct layer_context *ctx_layer = NULL;
887 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
888 if (ctx_layer == NULL) {
889 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
893 ctx_layer->prop.destX = (t_ilm_uint)x;
894 ctx_layer->prop.destY = (t_ilm_uint)y;
895 ctx_layer->prop.destWidth = (t_ilm_uint)width;
896 ctx_layer->prop.destHeight = (t_ilm_uint)height;
900 controller_layer_listener_configuration_main(void *data,
901 struct ivi_controller_layer *controller,
905 struct ilm_control_context *ctx = data;
906 struct layer_context *ctx_layer = NULL;
908 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
909 if (ctx_layer == NULL) {
910 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
914 ctx_layer->prop.sourceWidth = (t_ilm_uint)width;
915 ctx_layer->prop.sourceHeight = (t_ilm_uint)height;
919 controller_layer_listener_orientation_main(void *data,
920 struct ivi_controller_layer *controller,
923 ilmOrientation ilmorientation = ILM_ZERO;
924 struct ilm_control_context *ctx = data;
925 struct layer_context *ctx_layer = NULL;
927 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
928 if (ctx_layer == NULL) {
929 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
933 switch(orientation) {
934 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
935 ilmorientation = ILM_ZERO;
937 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
938 ilmorientation = ILM_NINETY;
940 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
941 ilmorientation = ILM_ONEHUNDREDEIGHTY;
943 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
944 ilmorientation = ILM_TWOHUNDREDSEVENTY;
950 ctx_layer->prop.orientation = ilmorientation;
954 controller_layer_listener_screen_main(void *data,
955 struct ivi_controller_layer *controller,
956 struct wl_output *output)
958 struct ilm_control_context *ctx = data;
959 struct layer_context *ctx_layer = NULL;
961 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
962 if (ctx_layer == NULL) {
963 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
967 if (output == NULL) {
968 remove_orderlayer_from_screen(&ctx->main_ctx, ctx_layer);
970 add_orderlayer_to_screen(&ctx->main_ctx, ctx_layer, output);
975 controller_layer_listener_destroyed_main(void *data,
976 struct ivi_controller_layer *controller)
978 struct ilm_control_context *ctx = data;
979 struct layer_context *ctx_layer = NULL;
981 ctx_layer = get_layer_context_by_controller(&ctx->main_ctx, controller);
982 if (ctx_layer == NULL) {
983 fprintf(stderr, "Invalid controller_layer in %s\n", __FUNCTION__);
987 wl_list_remove(&ctx_layer->link);
991 static struct ivi_controller_layer_listener controller_layer_listener_main =
993 controller_layer_listener_visibility_main,
994 controller_layer_listener_opacity_main,
995 controller_layer_listener_source_rectangle_main,
996 controller_layer_listener_destination_rectangle_main,
997 controller_layer_listener_configuration_main,
998 controller_layer_listener_orientation_main,
999 controller_layer_listener_screen_main,
1000 controller_layer_listener_destroyed_main
1004 static struct layer_context*
1005 get_layer_context(struct wayland_context *ctx,
1006 struct ivi_controller_layer *ivi_layer)
1008 struct layer_context *ctx_layer = NULL;
1009 struct wl_proxy *pxy_layer = NULL;
1010 struct wl_proxy *pxy_addlayer = NULL;
1011 uint32_t id_layer = 0;
1012 uint32_t id_addlayer = 0;
1014 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
1015 pxy_layer = (struct wl_proxy*)ctx_layer->controller;
1016 pxy_addlayer = (struct wl_proxy*)ivi_layer;
1017 id_layer = wl_proxy_get_id(pxy_layer);
1018 id_addlayer = wl_proxy_get_id(pxy_addlayer);
1019 if (id_layer == id_addlayer) {
1027 add_ordersurface_to_layer(struct wayland_context *ctx,
1028 struct surface_context *ctx_surf,
1029 struct ivi_controller_layer *layer)
1031 struct layer_context *ctx_layer = NULL;
1032 struct surface_context *link = NULL;
1035 ctx_layer = get_layer_context(ctx, layer);
1036 if (ctx_layer == NULL) {
1037 fprintf(stderr, "failed to add_ordersurface_to_layer\n");
1041 wl_list_for_each(link, &ctx_layer->order.list_surface, order.link) {
1042 if (link == ctx_surf) {
1049 wl_list_init(&ctx_surf->order.link);
1050 wl_list_insert(&ctx_layer->order.list_surface, &ctx_surf->order.link);
1055 remove_ordersurface_from_layer(struct wayland_context *ctx,
1056 struct surface_context *ctx_surf)
1058 struct layer_context *ctx_layer = NULL;
1059 struct surface_context *ctx_ordersurf = NULL;
1060 struct surface_context *next = NULL;
1061 struct wl_proxy *pxy_surf = NULL;
1062 struct wl_proxy *pxy_ordersurf = NULL;
1063 uint32_t id_surf = 0;
1064 uint32_t id_ordersurf = 0;
1066 wl_list_for_each(ctx_layer, &ctx->list_layer, link) {
1067 wl_list_for_each_safe(ctx_ordersurf, next,
1068 &ctx_layer->order.list_surface,
1070 pxy_surf = (struct wl_proxy*)ctx_surf->surface;
1071 pxy_ordersurf = (struct wl_proxy*)ctx_ordersurf->surface;
1072 id_surf = wl_proxy_get_id(pxy_surf);
1073 id_ordersurf = wl_proxy_get_id(pxy_ordersurf);
1074 if (id_surf == id_ordersurf) {
1075 wl_list_remove(&ctx_ordersurf->order.link);
1081 static struct surface_context*
1082 get_surface_context_by_controller(struct wayland_context *ctx,
1083 struct ivi_controller_surface *controller)
1085 struct surface_context *ctx_surf = NULL;
1086 wl_list_for_each(ctx_surf, &ctx->list_surface, link) {
1087 if (ctx_surf->controller == controller) {
1092 fprintf(stderr, "failed to get surface context in %s\n", __FUNCTION__);
1097 controller_surface_listener_visibility_child(void *data,
1098 struct ivi_controller_surface *controller,
1101 struct wayland_context *ctx = data;
1102 struct surface_context *ctx_surf = NULL;
1104 ctx_surf = get_surface_context_by_controller(ctx, controller);
1105 if (ctx_surf == NULL) {
1106 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1110 ctx_surf->prop.visibility = (t_ilm_bool)visibility;
1112 if (ctx_surf->notification != NULL) {
1113 ctx_surf->notification(ctx_surf->id_surface,
1115 ILM_NOTIFICATION_VISIBILITY);
1120 controller_surface_listener_opacity_child(void *data,
1121 struct ivi_controller_surface *controller,
1124 struct wayland_context *ctx = data;
1125 struct surface_context *ctx_surf = NULL;
1127 ctx_surf = get_surface_context_by_controller(ctx, controller);
1128 if (ctx_surf == NULL) {
1129 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1133 ctx_surf->prop.opacity = (t_ilm_float)wl_fixed_to_double(opacity);
1135 if (ctx_surf->notification != NULL) {
1136 ctx_surf->notification(ctx_surf->id_surface,
1138 ILM_NOTIFICATION_OPACITY);
1143 controller_surface_listener_configuration_child(void *data,
1144 struct ivi_controller_surface *controller,
1148 struct wayland_context *ctx = data;
1149 struct surface_context *ctx_surf = NULL;
1151 ctx_surf = get_surface_context_by_controller(ctx, controller);
1152 if (ctx_surf == NULL) {
1153 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1157 if (ctx_surf != NULL) {
1158 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
1159 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
1164 controller_surface_listener_source_rectangle_child(void *data,
1165 struct ivi_controller_surface *controller,
1171 struct wayland_context *ctx = data;
1172 struct surface_context *ctx_surf = NULL;
1174 ctx_surf = get_surface_context_by_controller(ctx, controller);
1175 if (ctx_surf == NULL) {
1176 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1180 ctx_surf->prop.sourceX = (t_ilm_uint)x;
1181 ctx_surf->prop.sourceY = (t_ilm_uint)y;
1182 ctx_surf->prop.sourceWidth = (t_ilm_uint)width;
1183 ctx_surf->prop.sourceHeight = (t_ilm_uint)height;
1184 if (ctx_surf->prop.origSourceWidth == 0) {
1185 ctx_surf->prop.origSourceWidth = (t_ilm_uint)width;
1187 if (ctx_surf->prop.origSourceHeight == 0) {
1188 ctx_surf->prop.origSourceHeight = (t_ilm_uint)height;
1191 if (ctx_surf->notification != NULL) {
1192 ctx_surf->notification(ctx_surf->id_surface,
1194 ILM_NOTIFICATION_SOURCE_RECT);
1199 controller_surface_listener_destination_rectangle_child(void *data,
1200 struct ivi_controller_surface *controller,
1206 struct wayland_context *ctx = data;
1207 struct surface_context *ctx_surf = NULL;
1209 ctx_surf = get_surface_context_by_controller(ctx, controller);
1210 if (ctx_surf == NULL) {
1211 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1215 ctx_surf->prop.destX = (t_ilm_uint)x;
1216 ctx_surf->prop.destY = (t_ilm_uint)y;
1217 ctx_surf->prop.destWidth = (t_ilm_uint)width;
1218 ctx_surf->prop.destHeight = (t_ilm_uint)height;
1220 if (ctx_surf->notification != NULL) {
1221 ctx_surf->notification(ctx_surf->id_surface,
1223 ILM_NOTIFICATION_DEST_RECT);
1228 controller_surface_listener_orientation_child(void *data,
1229 struct ivi_controller_surface *controller,
1230 int32_t orientation)
1232 struct wayland_context *ctx = data;
1233 struct surface_context *ctx_surf = NULL;
1234 ilmOrientation ilmorientation = ILM_ZERO;
1236 ctx_surf = get_surface_context_by_controller(ctx, controller);
1237 if (ctx_surf == NULL) {
1238 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1242 switch (orientation) {
1243 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
1244 ilmorientation = ILM_ZERO;
1246 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
1247 ilmorientation = ILM_NINETY;
1249 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
1250 ilmorientation = ILM_ONEHUNDREDEIGHTY;
1252 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
1253 ilmorientation = ILM_TWOHUNDREDSEVENTY;
1259 ctx_surf->prop.orientation = ilmorientation;
1261 if (ctx_surf->notification != NULL) {
1262 ctx_surf->notification(ctx_surf->id_surface,
1264 ILM_NOTIFICATION_ORIENTATION);
1269 controller_surface_listener_pixelformat_child(void *data,
1270 struct ivi_controller_surface *controller,
1271 int32_t pixelformat)
1273 struct wayland_context *ctx = data;
1274 struct surface_context *ctx_surf = NULL;
1276 ctx_surf = get_surface_context_by_controller(ctx, controller);
1277 if (ctx_surf == NULL) {
1278 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1282 if (ctx_surf != NULL) {
1283 ctx_surf->prop.pixelformat = (t_ilm_uint)pixelformat;
1288 controller_surface_listener_layer_child(void *data,
1289 struct ivi_controller_surface *controller,
1290 struct ivi_controller_layer *layer)
1292 struct wayland_context *ctx = data;
1293 struct surface_context *ctx_surf = NULL;
1295 ctx_surf = get_surface_context_by_controller(ctx, controller);
1296 if (ctx_surf == NULL) {
1297 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1301 if (layer == NULL) {
1302 remove_ordersurface_from_layer(ctx, ctx_surf);
1304 add_ordersurface_to_layer(ctx, ctx_surf, layer);
1309 controller_surface_listener_stats_child(void *data,
1310 struct ivi_controller_surface *controller,
1311 uint32_t redraw_count,
1312 uint32_t frame_count,
1313 uint32_t update_count,
1315 const char *process_name)
1317 struct wayland_context *ctx = data;
1318 struct surface_context *ctx_surf = NULL;
1321 ctx_surf = get_surface_context_by_controller(ctx, controller);
1322 if (ctx_surf == NULL) {
1323 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1327 if (ctx_surf != NULL) {
1328 ctx_surf->prop.drawCounter = (t_ilm_uint)redraw_count;
1329 ctx_surf->prop.frameCounter = (t_ilm_uint)frame_count;
1330 ctx_surf->prop.updateCounter = (t_ilm_uint)update_count;
1331 ctx_surf->prop.creatorPid = (t_ilm_uint)pid;
1336 controller_surface_listener_destroyed_child(void *data,
1337 struct ivi_controller_surface *controller)
1339 struct wayland_context *ctx = data;
1340 struct surface_context *ctx_surf = NULL;
1342 ctx_surf = get_surface_context_by_controller(ctx, controller);
1343 if (ctx_surf == NULL) {
1344 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1348 wl_list_remove(&ctx_surf->link);
1353 controller_surface_listener_content_child(void *data,
1354 struct ivi_controller_surface *controller,
1355 int32_t content_state)
1357 // if client surface (=content) was removed with ilm_surfaceDestroy()
1358 // the expected behavior within ILM API mandates a full removal
1359 // of the surface from the scene. We must remove the controller
1361 if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED == content_state)
1363 struct wayland_context *ctx = data;
1364 struct surface_context *ctx_surf = NULL;
1366 ctx_surf = get_surface_context_by_controller(ctx, controller);
1367 if (ctx_surf == NULL) {
1368 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1372 ivi_controller_surface_destroy(controller, IVI_CONTROLLER_OBJECT_TYPE_SURFACE);
1374 wl_list_remove(&ctx_surf->link);
1380 controller_surface_listener_input_focus_child(void *data,
1381 struct ivi_controller_surface *controller,
1389 static struct ivi_controller_surface_listener controller_surface_listener_child =
1391 controller_surface_listener_visibility_child,
1392 controller_surface_listener_opacity_child,
1393 controller_surface_listener_source_rectangle_child,
1394 controller_surface_listener_destination_rectangle_child,
1395 controller_surface_listener_configuration_child,
1396 controller_surface_listener_orientation_child,
1397 controller_surface_listener_pixelformat_child,
1398 controller_surface_listener_layer_child,
1399 controller_surface_listener_stats_child,
1400 controller_surface_listener_destroyed_child,
1401 controller_surface_listener_content_child,
1402 controller_surface_listener_input_focus_child
1406 controller_surface_listener_visibility_main(void *data,
1407 struct ivi_controller_surface *controller,
1416 controller_surface_listener_opacity_main(void *data,
1417 struct ivi_controller_surface *controller,
1426 controller_surface_listener_source_rectangle_main(void *data,
1427 struct ivi_controller_surface *controller,
1442 controller_surface_listener_destination_rectangle_main(void *data,
1443 struct ivi_controller_surface *controller,
1458 controller_surface_listener_configuration_main(void *data,
1459 struct ivi_controller_surface *controller,
1470 controller_surface_listener_orientation_main(void *data,
1471 struct ivi_controller_surface *controller,
1472 int32_t orientation)
1480 controller_surface_listener_pixelformat_main(void *data,
1481 struct ivi_controller_surface *controller,
1482 int32_t pixelformat)
1490 controller_surface_listener_layer_main(void *data,
1491 struct ivi_controller_surface *controller,
1492 struct ivi_controller_layer *layer)
1494 struct wayland_context *ctx = data;
1495 struct surface_context *ctx_surf = NULL;
1497 ctx_surf = get_surface_context_by_controller(ctx, controller);
1498 if (ctx_surf == NULL) {
1499 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1503 if (layer == NULL) {
1504 remove_ordersurface_from_layer(ctx, ctx_surf);
1506 add_ordersurface_to_layer(ctx, ctx_surf, layer);
1511 controller_surface_listener_stats_main(void *data,
1512 struct ivi_controller_surface *controller,
1513 uint32_t redraw_count,
1514 uint32_t frame_count,
1515 uint32_t update_count,
1517 const char *process_name)
1529 controller_surface_listener_destroyed_main(void *data,
1530 struct ivi_controller_surface *controller)
1532 struct wayland_context *ctx = data;
1533 struct surface_context *ctx_surf = NULL;
1535 ctx_surf = get_surface_context_by_controller(ctx, controller);
1536 if (ctx_surf == NULL) {
1537 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1541 wl_list_remove(&ctx_surf->link);
1546 controller_surface_listener_content_main(void *data,
1547 struct ivi_controller_surface *controller,
1548 int32_t content_state)
1550 // if client surface (=content) was removed with ilm_surfaceDestroy()
1551 // the expected behavior within ILM API mandates a full removal
1552 // of the surface from the scene. We must remove the controller
1554 if (IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED == content_state)
1556 struct wayland_context *ctx = data;
1557 struct surface_context *ctx_surf = NULL;
1559 ctx_surf = get_surface_context_by_controller(ctx, controller);
1560 if (ctx_surf == NULL) {
1561 fprintf(stderr, "Invalid controller_surface in %s\n", __FUNCTION__);
1565 ivi_controller_surface_destroy(controller, IVI_CONTROLLER_OBJECT_TYPE_SURFACE);
1567 wl_list_remove(&ctx_surf->link);
1573 controller_surface_listener_input_focus_main(void *data,
1574 struct ivi_controller_surface *controller,
1582 static struct ivi_controller_surface_listener controller_surface_listener_main =
1584 controller_surface_listener_visibility_main,
1585 controller_surface_listener_opacity_main,
1586 controller_surface_listener_source_rectangle_main,
1587 controller_surface_listener_destination_rectangle_main,
1588 controller_surface_listener_configuration_main,
1589 controller_surface_listener_orientation_main,
1590 controller_surface_listener_pixelformat_main,
1591 controller_surface_listener_layer_main,
1592 controller_surface_listener_stats_main,
1593 controller_surface_listener_destroyed_main,
1594 controller_surface_listener_content_main,
1595 controller_surface_listener_input_focus_main
1599 controller_listener_screen_for_child(void *data,
1600 struct ivi_controller *ivi_controller,
1602 struct ivi_controller_screen *controller_screen)
1605 (void)ivi_controller;
1607 (void)controller_screen;
1611 controller_listener_layer_for_child(void *data,
1612 struct ivi_controller *controller,
1621 controller_listener_surface_for_child(void *data,
1622 struct ivi_controller *controller,
1623 uint32_t id_surface)
1625 struct wayland_context *ctx = data;
1626 struct surface_context *ctx_surf = NULL;
1627 int32_t is_inside = 0;
1629 is_inside = wayland_controller_is_inside_surface_list(
1630 &ctx->list_surface, id_surface);
1632 if (is_inside != 0) {
1633 fprintf(stderr, "invalid id_surface in controller_listener_surface\n");
1637 ctx_surf = calloc(1, sizeof *ctx_surf);
1638 if (ctx_surf == NULL) {
1639 fprintf(stderr, "Failed to allocate memory for surface_context\n");
1643 ctx_surf->controller = ivi_controller_surface_create(
1644 controller, id_surface);
1645 if (ctx_surf->controller == NULL) {
1646 fprintf(stderr, "Failed to create controller surface\n");
1649 ctx_surf->id_surface = id_surface;
1650 ctx_surf->prop.inputDevicesAcceptance = ILM_INPUT_DEVICE_ALL;
1652 wl_list_init(&ctx_surf->link);
1653 wl_list_insert(&ctx->list_surface, &ctx_surf->link);
1654 ivi_controller_surface_add_listener(ctx_surf->controller,
1655 &controller_surface_listener_child, ctx);
1656 wl_display_roundtrip(ctx->display);
1660 controller_listener_error_for_child(void *data,
1661 struct ivi_controller *ivi_controller,
1663 int32_t object_type,
1665 const char *error_text)
1668 (void)ivi_controller;
1675 static struct ivi_controller_listener controller_listener_for_child = {
1676 controller_listener_screen_for_child,
1677 controller_listener_layer_for_child,
1678 controller_listener_surface_for_child,
1679 controller_listener_error_for_child
1683 controller_listener_screen_for_main(void *data,
1684 struct ivi_controller *ivi_controller,
1686 struct ivi_controller_screen *controller_screen)
1688 struct ilm_control_context *ctx = data;
1689 struct screen_context *ctx_screen;
1690 (void)ivi_controller;
1692 ctx_screen = get_screen_context_by_serverid(&ctx->main_ctx, id_screen);
1693 if (ctx_screen == NULL) {
1694 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1697 ctx_screen->controller = controller_screen;
1701 controller_listener_layer_for_main(void *data,
1702 struct ivi_controller *controller,
1711 controller_listener_surface_for_main(void *data,
1712 struct ivi_controller *controller,
1713 uint32_t id_surface)
1715 struct ilm_control_context *ctx = data;
1716 struct surface_context *ctx_surf = NULL;
1717 int32_t is_inside = 0;
1719 is_inside = wayland_controller_is_inside_surface_list(
1720 &ctx->main_ctx.list_surface, id_surface);
1722 if (is_inside != 0) {
1723 fprintf(stderr, "invalid id_surface in controller_listener_surface\n");
1727 ctx_surf = calloc(1, sizeof *ctx_surf);
1728 if (ctx_surf == NULL) {
1729 fprintf(stderr, "Failed to allocate memory for surface_context\n");
1733 ctx_surf->controller = ivi_controller_surface_create(
1734 controller, id_surface);
1735 if (ctx_surf->controller == NULL) {
1736 fprintf(stderr, "Failed to create controller surface\n");
1739 ctx_surf->id_surface = id_surface;
1740 ctx_surf->prop.inputDevicesAcceptance = ILM_INPUT_DEVICE_ALL;
1742 wl_list_init(&ctx_surf->link);
1743 wl_list_insert(&ctx->main_ctx.list_surface, &ctx_surf->link);
1744 ivi_controller_surface_add_listener(ctx_surf->controller,
1745 &controller_surface_listener_main, ctx);
1749 controller_listener_error_for_main(void *data,
1750 struct ivi_controller *ivi_controller,
1752 int32_t object_type,
1754 const char *error_text)
1757 (void)ivi_controller;
1764 static struct ivi_controller_listener controller_listener_for_main = {
1765 controller_listener_screen_for_main,
1766 controller_listener_layer_for_main,
1767 controller_listener_surface_for_main,
1768 controller_listener_error_for_main
1772 registry_handle_control_for_child(void *data,
1773 struct wl_registry *registry,
1774 uint32_t name, const char *interface,
1777 struct wayland_context *ctx = data;
1780 if (strcmp(interface, "ivi_controller") == 0) {
1781 ctx->controller = wl_registry_bind(registry, name,
1782 &ivi_controller_interface, 1);
1783 if (ctx->controller == NULL) {
1784 fprintf(stderr, "Failed to registry bind ivi_controller\n");
1787 if (ivi_controller_add_listener(ctx->controller,
1788 &controller_listener_for_child,
1790 fprintf(stderr, "Failed to add ivi_controller listener\n");
1793 } else if (strcmp(interface, "wl_output") == 0) {
1794 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
1795 if (ctx_scrn == NULL) {
1796 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1799 wl_list_init(&ctx_scrn->link);
1800 ctx_scrn->output = wl_registry_bind(registry, name,
1801 &wl_output_interface, 1);
1802 if (ctx_scrn->output == NULL) {
1804 fprintf(stderr, "Failed to registry bind wl_output\n");
1808 if (wl_output_add_listener(ctx_scrn->output,
1812 fprintf(stderr, "Failed to add wl_output listener\n");
1816 ctx_scrn->id_screen = ctx->num_screen;
1818 wl_list_init(&ctx_scrn->order.list_layer);
1819 wl_list_insert(&ctx->list_screen, &ctx_scrn->link);
1823 static const struct wl_registry_listener
1824 registry_control_listener_for_child = {
1825 registry_handle_control_for_child,
1830 registry_handle_control_for_main(void *data,
1831 struct wl_registry *registry,
1832 uint32_t name, const char *interface,
1835 struct ilm_control_context *ctx = data;
1838 if (strcmp(interface, "ivi_controller") == 0) {
1839 ctx->main_ctx.controller = wl_registry_bind(registry, name,
1840 &ivi_controller_interface, 1);
1841 if (ctx->main_ctx.controller == NULL) {
1842 fprintf(stderr, "Failed to registry bind ivi_controller\n");
1845 if (ivi_controller_add_listener(ctx->main_ctx.controller,
1846 &controller_listener_for_main,
1848 fprintf(stderr, "Failed to add ivi_controller listener\n");
1851 } else if (strcmp(interface, "wl_output") == 0) {
1853 struct screen_context *ctx_scrn = calloc(1, sizeof *ctx_scrn);
1854 struct wl_proxy *pxy = NULL;
1856 if (ctx_scrn == NULL) {
1857 fprintf(stderr, "Failed to allocate memory for screen_context\n");
1860 wl_list_init(&ctx_scrn->link);
1861 ctx_scrn->output = wl_registry_bind(registry, name,
1862 &wl_output_interface, 1);
1863 if (ctx_scrn->output == NULL) {
1865 fprintf(stderr, "Failed to registry bind wl_output\n");
1869 if (wl_output_add_listener(ctx_scrn->output,
1873 fprintf(stderr, "Failed to add wl_output listener\n");
1877 pxy = (struct wl_proxy*)ctx_scrn->output;
1878 ctx_scrn->id_from_server = wl_proxy_get_id(pxy);
1879 ctx_scrn->id_screen = ctx->num_screen;
1881 ctx_scrn->controller = NULL;
1882 ctx_scrn->prop.layerCount = 0;
1883 ctx_scrn->prop.layerIds = NULL;
1884 ctx_scrn->prop.harwareLayerCount = 0;
1885 ctx_scrn->prop.screenWidth = 0;
1886 ctx_scrn->prop.screenHeight = 0;
1887 wl_list_init(&ctx_scrn->order.list_layer);
1888 wl_list_insert(&ctx->main_ctx.list_screen, &ctx_scrn->link);
1892 static const struct wl_registry_listener
1893 registry_control_listener_for_main = {
1894 registry_handle_control_for_main,
1898 static struct ilm_control_context ilm_context = {0};
1903 struct ilm_control_context *ctx = &ilm_context;
1905 void* threadRetVal = NULL;
1906 pthread_cancel(ctx->thread);
1907 if (0 != pthread_join(ctx->thread, &threadRetVal)) {
1908 fprintf(stderr, "failed to join control thread\n");
1913 destroy_control_resources()
1915 struct ilm_control_context *ctx = &ilm_context;
1916 struct screen_context *ctx_scrn;
1917 struct screen_context *next;
1919 wl_list_for_each_safe(ctx_scrn, next, &ctx->child_ctx.list_screen, link) {
1920 if (ctx_scrn->output != NULL) {
1921 wl_list_remove(&ctx_scrn->link);
1922 wl_output_destroy(ctx_scrn->output);
1926 if (ctx->child_ctx.controller != NULL) {
1927 ivi_controller_destroy(ctx->child_ctx.controller);
1928 ctx->child_ctx.controller = NULL;
1931 wl_display_flush(ctx->child_ctx.display);
1933 if (ctx->child_ctx.display != NULL) {
1934 wl_display_disconnect(ctx->child_ctx.display);
1935 ctx->child_ctx.display = NULL;
1938 if (0 != pthread_mutex_destroy(&ctx->mutex)) {
1939 fprintf(stderr, "failed to destroy pthread_mutex\n");
1944 wayland_context_init(struct wayland_context *ctx)
1946 wl_list_init(&ctx->list_screen);
1947 wl_list_init(&ctx->list_layer);
1948 wl_list_init(&ctx->list_surface);
1951 static ilmErrorTypes
1952 wayland_init(t_ilm_nativedisplay nativedisplay)
1954 struct ilm_control_context *ctx = &ilm_context;
1956 if (nativedisplay == 0) {
1957 return ILM_ERROR_INVALID_ARGUMENTS;
1960 memset(ctx, 0, sizeof *ctx);
1962 ctx->main_ctx.display = (struct wl_display*)nativedisplay;
1965 ans = pthread_mutex_init(&ctx->mutex, NULL);
1967 fprintf(stderr, "failed to initialize pthread_mutex\n");
1970 ctx->internal_id_surface = 0;
1971 ctx->num_screen = 0;
1973 wayland_context_init(&ctx->main_ctx);
1974 wayland_context_init(&ctx->child_ctx);
1980 control_thread(void *p_ret)
1982 struct ilm_control_context *ctx = &ilm_context;
1983 struct wayland_context *child_ctx = &ctx->child_ctx;
1986 ctx->num_screen = 0;
1987 wl_list_init(&child_ctx->list_screen);
1988 wl_list_init(&child_ctx->list_layer);
1989 wl_list_init(&child_ctx->list_surface);
1991 child_ctx->display = wl_display_connect(NULL);
1992 if (child_ctx->display == NULL) {
1993 fprintf(stderr, "Failed to connect display in libilmCommon\n");
1997 child_ctx->registry = wl_display_get_registry(child_ctx->display);
1998 if (child_ctx->registry == NULL) {
1999 fprintf(stderr, "Failed to get registry\n");
2002 if (wl_registry_add_listener(child_ctx->registry,
2003 ®istry_control_listener_for_child, &ctx->child_ctx)) {
2004 fprintf(stderr, "Failed to add registry listener\n");
2008 wl_display_dispatch(child_ctx->display);
2009 wl_display_roundtrip(child_ctx->display);
2012 while (0 < ctx->valid)
2014 wl_display_dispatch(child_ctx->display);
2017 destroy_control_resources();
2025 struct ilm_control_context *ctx = &ilm_context;
2026 struct wayland_context *main_ctx = &ctx->main_ctx;
2029 pthread_attr_t thread_attrs;
2031 wl_list_init(&ctx->list_nativehandle);
2033 pthread_attr_init(&thread_attrs);
2034 pthread_attr_setdetachstate(&thread_attrs, PTHREAD_CREATE_JOINABLE);
2035 ret = pthread_create(&ctx->thread, &thread_attrs,
2036 control_thread, NULL);
2038 fprintf(stderr, "Failed to start internal receive \
2039 thread. returned %d\n", ret);
2043 /* registry_add_listener for request by ivi-controller */
2044 main_ctx->registry = wl_display_get_registry(main_ctx->display);
2045 if (main_ctx->registry == NULL) {
2046 fprintf(stderr, "Failed to get registry\n");
2049 if (wl_registry_add_listener(main_ctx->registry,
2050 ®istry_control_listener_for_main, ctx)) {
2051 fprintf(stderr, "Failed to add registry listener\n");
2055 wl_display_dispatch(main_ctx->display);
2056 wl_display_roundtrip(main_ctx->display);
2060 /* Wait for bind to wayland interface */
2062 if (ctx->child_ctx.controller != NULL) {
2066 } while (++wait_count <= 1000); /* wait until 10sec */
2068 if ((ctx->child_ctx.display == NULL) || (ctx->child_ctx.controller == NULL)) {
2069 fprintf(stderr, "Failed to connect display\n");
2074 static struct ilm_control_context*
2077 struct ilm_control_context *ctx = &ilm_context;
2078 if (ctx->valid == 0) {
2082 if (ctx->valid < 0) {
2087 wl_display_roundtrip(ctx->main_ctx.display);
2092 gen_layer_id(struct ilm_control_context *ctx)
2094 struct layer_context *ctx_layer = NULL;
2097 if (wl_list_length(&ctx->main_ctx.list_layer) == 0) {
2098 ctx->internal_id_layer++;
2099 return ctx->internal_id_layer;
2101 wl_list_for_each(ctx_layer, &ctx->main_ctx.list_layer, link) {
2102 if (ctx_layer->id_layer == ctx->internal_id_layer) {
2108 return ctx->internal_id_layer;
2111 ctx->internal_id_layer++;
2115 static struct surface_context*
2116 get_surface_context(struct wayland_context *ctx,
2117 uint32_t id_surface)
2119 struct surface_context *ctx_surf = NULL;
2121 if (ctx->controller == NULL) {
2122 fprintf(stderr, "controller is not initialized in ilmControl\n");
2126 wl_list_for_each(ctx_surf, &ctx->list_surface, link) {
2127 if (ctx_surf->id_surface == id_surface) {
2132 fprintf(stderr, "failed to get surface context in ilmControl\n");
2136 static struct screen_context*
2137 get_screen_context_by_id(struct wayland_context *ctx, uint32_t id_screen)
2139 struct screen_context *ctx_scrn = NULL;
2141 if (ctx->controller == NULL) {
2142 fprintf(stderr, "get_screen_context_by_id: controller is NULL\n");
2146 wl_list_for_each(ctx_scrn, &ctx->list_screen, link) {
2147 if (ctx_scrn->id_screen == id_screen) {
2154 static ilmErrorTypes
2155 wayland_getPropertiesOfLayer(t_ilm_uint layerID,
2156 struct ilmLayerProperties* pLayerProperties)
2158 ilmErrorTypes returnValue = ILM_FAILED;
2159 struct ilm_control_context *ctx = get_instance();
2160 struct layer_context *ctx_layer = NULL;
2162 if (pLayerProperties != NULL) {
2164 ctx_layer = (struct layer_context*)
2165 wayland_controller_get_layer_context(
2166 &ctx->main_ctx, (uint32_t)layerID);
2168 if (ctx_layer != NULL) {
2169 *pLayerProperties = ctx_layer->prop;
2170 returnValue = ILM_SUCCESS;
2178 create_layerids(struct screen_context *ctx_screen,
2179 t_ilm_layer **layer_ids, t_ilm_uint *layer_count)
2181 struct layer_context *ctx_layer = NULL;
2182 t_ilm_layer *ids = NULL;
2184 *layer_count = wl_list_length(&ctx_screen->order.list_layer);
2185 if (*layer_count == 0) {
2190 *layer_ids = malloc(*layer_count * sizeof(t_ilm_layer));
2191 if (*layer_ids == NULL) {
2192 fprintf(stderr, "memory insufficient for layerids\n");
2198 wl_list_for_each(ctx_layer, &ctx_screen->order.list_layer, order.link) {
2199 *ids = (t_ilm_layer)ctx_layer->id_layer;
2204 static ilmErrorTypes
2205 wayland_getPropertiesOfScreen(t_ilm_display screenID,
2206 struct ilmScreenProperties* pScreenProperties)
2208 ilmErrorTypes returnValue = ILM_FAILED;
2209 struct ilm_control_context *ctx = get_instance();
2211 if (pScreenProperties != NULL) {
2212 struct screen_context *ctx_screen = NULL;
2213 ctx_screen = get_screen_context_by_id(&ctx->main_ctx, (uint32_t)screenID);
2214 if (ctx_screen != NULL) {
2215 *pScreenProperties = ctx_screen->prop;
2216 create_layerids(ctx_screen, &pScreenProperties->layerIds,
2217 &pScreenProperties->layerCount);
2218 returnValue = ILM_SUCCESS;
2222 pScreenProperties->layerCount = 0;
2223 pScreenProperties->harwareLayerCount = 0;
2224 pScreenProperties->layerIds = NULL;
2225 pScreenProperties->screenWidth = 0;
2226 pScreenProperties->screenHeight = 0;
2232 static ilmErrorTypes
2233 wayland_getNumberOfHardwareLayers(t_ilm_uint screenID,
2234 t_ilm_uint* pNumberOfHardwareLayers)
2238 if (pNumberOfHardwareLayers != NULL) {
2239 *pNumberOfHardwareLayers = 0;
2246 static ilmErrorTypes
2247 wayland_getScreenIDs(t_ilm_uint* pNumberOfIDs, t_ilm_uint** ppIDs)
2249 ilmErrorTypes returnValue = ILM_FAILED;
2250 struct ilm_control_context *ctx = get_instance();
2252 if ((pNumberOfIDs != NULL) && (ppIDs != NULL)) {
2253 struct screen_context *ctx_scrn = NULL;
2254 t_ilm_uint length = wl_list_length(&ctx->main_ctx.list_screen);
2257 *ppIDs = (t_ilm_uint*)malloc(length * sizeof *ppIDs);
2258 if (*ppIDs != NULL) {
2259 t_ilm_uint* ids = *ppIDs;
2260 wl_list_for_each(ctx_scrn, &ctx->main_ctx.list_screen, link) {
2261 *ids = ctx_scrn->id_screen;
2264 *pNumberOfIDs = length;
2266 returnValue = ILM_SUCCESS;
2273 static ilmErrorTypes
2274 wayland_getLayerIDs(t_ilm_int* pLength, t_ilm_layer** ppArray)
2276 ilmErrorTypes returnValue = ILM_FAILED;
2277 struct ilm_control_context *ctx = get_instance();
2279 if ((pLength != NULL) && (ppArray != NULL)) {
2280 struct layer_context *ctx_layer = NULL;
2281 t_ilm_uint length = wl_list_length(&ctx->main_ctx.list_layer);
2284 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
2285 if (*ppArray != NULL) {
2286 // compositor sends layers in opposite order
2287 // write ids from back to front to turn them around
2288 t_ilm_layer* ids = &((*ppArray)[length - 1]);
2289 wl_list_for_each(ctx_layer, &ctx->main_ctx.list_layer, link)
2291 *ids = ctx_layer->id_layer;
2296 returnValue = ILM_SUCCESS;
2303 static ilmErrorTypes
2304 wayland_getLayerIDsOnScreen(t_ilm_uint screenId,
2306 t_ilm_layer** ppArray)
2308 ilmErrorTypes returnValue = ILM_FAILED;
2309 struct ilm_control_context *ctx = get_instance();
2311 if ((pLength != NULL) && (ppArray != NULL)) {
2312 struct screen_context *ctx_screen = NULL;
2313 ctx_screen = get_screen_context_by_id(&ctx->main_ctx, screenId);
2314 if (ctx_screen != NULL) {
2315 struct layer_context *ctx_layer = NULL;
2316 t_ilm_int length = wl_list_length(&ctx_screen->order.list_layer);
2320 *ppArray = (t_ilm_layer*)malloc(length * sizeof *ppArray);
2321 if (*ppArray != NULL) {
2322 // compositor sends layers in opposite order
2323 // write ids from back to front to turn them around
2324 t_ilm_layer* ids = &((*ppArray)[length - 1]);
2325 wl_list_for_each(ctx_layer, &ctx->main_ctx.list_layer, link)
2327 *ids = ctx_layer->id_layer;
2339 returnValue = ILM_SUCCESS;
2346 static ilmErrorTypes
2347 wayland_getSurfaceIDs(t_ilm_int* pLength, t_ilm_surface** ppArray)
2349 ilmErrorTypes returnValue = ILM_FAILED;
2350 struct ilm_control_context *ctx = get_instance();
2352 if ((pLength != NULL) && (ppArray != NULL)) {
2353 struct surface_context *ctx_surf = NULL;
2354 t_ilm_uint length = wl_list_length(&ctx->main_ctx.list_surface);
2357 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
2358 if (*ppArray != NULL) {
2359 t_ilm_surface* ids = *ppArray;
2360 wl_list_for_each(ctx_surf, &ctx->main_ctx.list_surface, link) {
2361 *ids = ctx_surf->id_surface;
2366 returnValue = ILM_SUCCESS;
2373 static ilmErrorTypes
2374 wayland_getSurfaceIDsOnLayer(t_ilm_layer layer,
2376 t_ilm_surface** ppArray)
2378 struct ilm_control_context *ctx = get_instance();
2379 struct layer_context *ctx_layer = NULL;
2380 struct surface_context *ctx_surf = NULL;
2381 t_ilm_uint length = 0;
2382 t_ilm_surface* ids = NULL;
2384 if ((pLength == NULL) || (ppArray == NULL)) {
2388 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2389 &ctx->main_ctx, (uint32_t)layer);
2391 if (ctx_layer == NULL) {
2395 length = wl_list_length(&ctx_layer->order.list_surface);
2396 *ppArray = (t_ilm_surface*)malloc(length * sizeof *ppArray);
2397 if (*ppArray == NULL) {
2402 wl_list_for_each(ctx_surf, &ctx_layer->order.list_surface, order.link) {
2403 *ids = (t_ilm_surface)ctx_surf->id_surface;
2411 static ilmErrorTypes
2412 wayland_layerCreateWithDimension(t_ilm_layer* pLayerId,
2416 ilmErrorTypes returnValue = ILM_FAILED;
2417 struct ilm_control_context *ctx = get_instance();
2418 uint32_t layerid = 0;
2419 struct layer_context *ctx_layer_main = NULL;
2420 struct layer_context *ctx_layer_child = NULL;
2421 int32_t is_inside = 0;
2424 if (pLayerId == NULL) {
2428 if (*pLayerId != INVALID_ID) {
2429 /* Return failed, if layerid is already inside list_layer */
2430 is_inside = wayland_controller_is_inside_layer_list(
2431 &ctx->main_ctx.list_layer, *pLayerId);
2432 if (0 != is_inside) {
2433 fprintf(stderr, "layerid=%d is already used.\n", *pLayerId);
2436 layerid = *pLayerId;
2439 /* Generate ID, if layerid is INVALID_ID */
2440 layerid = gen_layer_id(ctx);
2441 *pLayerId = layerid;
2445 ctx_layer_main = calloc(1, sizeof *ctx_layer_main);
2446 if (ctx_layer_main == NULL) {
2447 fprintf(stderr, "Failed to allocate memory for layer_context\n");
2451 ctx_layer_main->controller = ivi_controller_layer_create(
2452 ctx->main_ctx.controller,
2453 layerid, width, height);
2454 if (ctx_layer_main->controller == NULL) {
2455 fprintf(stderr, "Failed to create layer\n");
2456 free(ctx_layer_main);
2459 ctx_layer_main->id_layer = layerid;
2461 wl_list_init(&ctx_layer_main->link);
2462 wl_list_insert(&ctx->main_ctx.list_layer, &ctx_layer_main->link);
2463 wl_list_init(&ctx_layer_main->order.link);
2464 wl_list_init(&ctx_layer_main->order.list_surface);
2466 ivi_controller_layer_add_listener(ctx_layer_main->controller,
2467 &controller_layer_listener_main, ctx);
2469 // For child context
2470 ctx_layer_child = calloc(1, sizeof *ctx_layer_child);
2471 if (ctx_layer_child == NULL) {
2472 fprintf(stderr, "Failed to allocate memory for layer_context\n");
2476 ctx_layer_child->controller = ivi_controller_layer_create(
2477 ctx->child_ctx.controller,
2478 layerid, width, height);
2479 if (ctx_layer_child->controller == NULL) {
2480 fprintf(stderr, "Failed to create layer\n");
2481 free(ctx_layer_child);
2484 ctx_layer_child->id_layer = layerid;
2486 wl_list_init(&ctx_layer_child->link);
2487 wl_list_insert(&ctx->child_ctx.list_layer, &ctx_layer_child->link);
2488 wl_list_init(&ctx_layer_child->order.link);
2489 wl_list_init(&ctx_layer_child->order.list_surface);
2491 ivi_controller_layer_add_listener(ctx_layer_child->controller,
2492 &controller_layer_listener_child, ctx);
2494 returnValue = ILM_SUCCESS;
2500 static ilmErrorTypes
2501 wayland_layerRemove(t_ilm_layer layerId)
2503 ilmErrorTypes returnValue = ILM_FAILED;
2504 struct ilm_control_context *ctx = get_instance();
2505 struct layer_context *ctx_layer = NULL;
2506 struct layer_context *ctx_next = NULL;
2508 wl_list_for_each_safe(ctx_layer, ctx_next,
2509 &ctx->main_ctx.list_layer, link) {
2510 if (ctx_layer->id_layer == layerId) {
2511 ivi_controller_layer_destroy(ctx_layer->controller,
2512 IVI_CONTROLLER_OBJECT_TYPE_LAYER);
2514 wl_list_remove(&ctx_layer->link);
2517 returnValue = ILM_SUCCESS;
2525 static ilmErrorTypes
2526 wayland_layerGetType(t_ilm_layer layerId, ilmLayerType* pLayerType)
2530 if (pLayerType != NULL) {
2531 *pLayerType = ILM_LAYERTYPE_SOFTWARE2D;
2536 static ilmErrorTypes
2537 wayland_layerSetVisibility(t_ilm_layer layerId, t_ilm_bool newVisibility)
2539 ilmErrorTypes returnValue = ILM_FAILED;
2540 struct ilm_control_context *ctx = get_instance();
2541 struct layer_context *ctx_layer = NULL;
2543 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2544 &ctx->main_ctx, (uint32_t)layerId);
2546 if (ctx_layer != NULL) {
2547 uint32_t visibility = 0;
2548 if (newVisibility == ILM_TRUE) {
2551 ivi_controller_layer_set_visibility(ctx_layer->controller,
2553 returnValue = ILM_SUCCESS;
2559 static ilmErrorTypes
2560 wayland_layerGetVisibility(t_ilm_layer layerId, t_ilm_bool *pVisibility)
2562 ilmErrorTypes returnValue = ILM_FAILED;
2563 struct ilm_control_context *ctx = get_instance();
2565 if (pVisibility != NULL) {
2566 struct layer_context *ctx_layer = NULL;
2568 ctx_layer = (struct layer_context*)
2569 wayland_controller_get_layer_context(
2570 &ctx->main_ctx, (uint32_t)layerId);
2572 if (ctx_layer != NULL) {
2573 *pVisibility = ctx_layer->prop.visibility;
2574 returnValue = ILM_SUCCESS;
2581 static ilmErrorTypes
2582 wayland_layerSetOpacity(t_ilm_layer layerId, t_ilm_float opacity)
2584 ilmErrorTypes returnValue = ILM_FAILED;
2585 struct ilm_control_context *ctx = get_instance();
2586 struct layer_context *ctx_layer = NULL;
2588 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2589 &ctx->main_ctx, (uint32_t)layerId);
2591 if (ctx_layer != NULL) {
2592 wl_fixed_t opacity_fixed = wl_fixed_from_double((double)opacity);
2593 ivi_controller_layer_set_opacity(ctx_layer->controller,
2595 returnValue = ILM_SUCCESS;
2601 static ilmErrorTypes
2602 wayland_layerGetOpacity(t_ilm_layer layerId, t_ilm_float *pOpacity)
2604 ilmErrorTypes returnValue = ILM_FAILED;
2605 struct ilm_control_context *ctx = get_instance();
2607 if (pOpacity != NULL) {
2608 struct layer_context *ctx_layer = NULL;
2610 ctx_layer = (struct layer_context*)
2611 wayland_controller_get_layer_context(
2612 &ctx->main_ctx, (uint32_t)layerId);
2614 if (ctx_layer != NULL) {
2615 *pOpacity = ctx_layer->prop.opacity;
2616 returnValue = ILM_SUCCESS;
2623 static ilmErrorTypes
2624 wayland_layerSetSourceRectangle(t_ilm_layer layerId,
2625 t_ilm_uint x, t_ilm_uint y,
2626 t_ilm_uint width, t_ilm_uint height)
2628 ilmErrorTypes returnValue = ILM_FAILED;
2629 struct ilm_control_context *ctx = get_instance();
2630 struct layer_context *ctx_layer = NULL;
2632 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2633 &ctx->main_ctx, (uint32_t)layerId);
2635 if (ctx_layer != NULL) {
2636 ivi_controller_layer_set_source_rectangle(ctx_layer->controller,
2641 returnValue = ILM_SUCCESS;
2647 static ilmErrorTypes
2648 wayland_layerSetDestinationRectangle(t_ilm_layer layerId,
2649 t_ilm_int x, t_ilm_int y,
2650 t_ilm_int width, t_ilm_int height)
2652 ilmErrorTypes returnValue = ILM_FAILED;
2653 struct ilm_control_context *ctx = get_instance();
2654 struct layer_context *ctx_layer = NULL;
2656 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2657 &ctx->main_ctx, (uint32_t)layerId);
2658 if (ctx_layer != NULL) {
2659 ivi_controller_layer_set_destination_rectangle(
2660 ctx_layer->controller,
2661 (uint32_t)x, (uint32_t)y,
2664 returnValue = ILM_SUCCESS;
2670 static ilmErrorTypes
2671 wayland_layerGetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
2673 ilmErrorTypes returnValue = ILM_FAILED;
2674 struct ilm_control_context *ctx = get_instance();
2675 struct layer_context *ctx_layer = NULL;
2677 if (pDimension != NULL) {
2678 ctx_layer = (struct layer_context*)
2679 wayland_controller_get_layer_context(
2680 &ctx->main_ctx, (uint32_t)layerId);
2681 if (ctx_layer != NULL) {
2682 *pDimension = ctx_layer->prop.destWidth;
2683 *(pDimension + 1) = ctx_layer->prop.destHeight;
2684 returnValue = ILM_SUCCESS;
2691 static ilmErrorTypes
2692 wayland_layerSetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
2694 ilmErrorTypes returnValue = ILM_FAILED;
2695 struct ilm_control_context *ctx = get_instance();
2696 struct layer_context *ctx_layer = NULL;
2698 if (pDimension != NULL) {
2699 ctx_layer = (struct layer_context*)
2700 wayland_controller_get_layer_context(
2701 &ctx->main_ctx, (uint32_t)layerId);
2702 if (ctx_layer != NULL) {
2703 ivi_controller_layer_set_destination_rectangle(
2704 ctx_layer->controller,
2705 ctx_layer->prop.destX, ctx_layer->prop.destY,
2706 (int32_t)*pDimension, (int32_t)*(pDimension + 1));
2707 returnValue = ILM_SUCCESS;
2714 static ilmErrorTypes
2715 wayland_layerGetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2717 ilmErrorTypes returnValue = ILM_FAILED;
2718 struct ilm_control_context *ctx = get_instance();
2719 struct layer_context *ctx_layer = NULL;
2721 if (pPosition != NULL) {
2722 ctx_layer = (struct layer_context*)
2723 wayland_controller_get_layer_context(
2724 &ctx->main_ctx, (uint32_t)layerId);
2725 if (ctx_layer != NULL) {
2726 *pPosition = ctx_layer->prop.destX;
2727 *(pPosition + 1) = ctx_layer->prop.destY;
2728 returnValue = ILM_SUCCESS;
2735 static ilmErrorTypes
2736 wayland_layerSetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
2738 ilmErrorTypes returnValue = ILM_FAILED;
2739 struct ilm_control_context *ctx = get_instance();
2740 struct layer_context *ctx_layer = NULL;
2742 if (pPosition != NULL) {
2743 ctx_layer = (struct layer_context*)
2744 wayland_controller_get_layer_context(
2745 &ctx->main_ctx, (uint32_t)layerId);
2746 if (ctx_layer != NULL) {
2747 ivi_controller_layer_set_destination_rectangle(
2748 ctx_layer->controller,
2749 (int32_t)*pPosition, (int32_t)*(pPosition + 1),
2750 ctx_layer->prop.destWidth, ctx_layer->prop.destHeight);
2751 returnValue = ILM_SUCCESS;
2758 static ilmErrorTypes
2759 wayland_layerSetOrientation(t_ilm_layer layerId, ilmOrientation orientation)
2761 ilmErrorTypes returnValue = ILM_FAILED;
2762 struct ilm_control_context *ctx = get_instance();
2763 struct layer_context *ctx_layer = NULL;
2764 int32_t iviorientation = 0;
2767 switch(orientation) {
2769 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
2772 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
2774 case ILM_ONEHUNDREDEIGHTY:
2775 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
2777 case ILM_TWOHUNDREDSEVENTY:
2778 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
2781 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
2785 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2786 &ctx->main_ctx, (uint32_t)layerId);
2787 if (ctx_layer == NULL) {
2788 returnValue = ILM_FAILED;
2792 ivi_controller_layer_set_orientation(ctx_layer->controller,
2795 returnValue = ILM_SUCCESS;
2801 static ilmErrorTypes
2802 wayland_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrientation)
2804 ilmErrorTypes returnValue = ILM_FAILED;
2805 struct ilm_control_context *ctx = get_instance();
2806 struct layer_context *ctx_layer = NULL;
2808 if (pOrientation != NULL) {
2809 ctx_layer = (struct layer_context*)
2810 wayland_controller_get_layer_context(
2811 &ctx->main_ctx, (uint32_t)layerId);
2812 if (ctx_layer != NULL) {
2813 *pOrientation = ctx_layer->prop.orientation;
2814 returnValue = ILM_SUCCESS;
2821 static ilmErrorTypes
2822 wayland_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
2830 static ilmErrorTypes
2831 wayland_layerSetRenderOrder(t_ilm_layer layerId,
2832 t_ilm_surface *pSurfaceId,
2835 ilmErrorTypes returnValue = ILM_FAILED;
2836 struct ilm_control_context *ctx = get_instance();
2837 struct layer_context *ctx_layer = NULL;
2839 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
2840 &ctx->main_ctx, (uint32_t)layerId);
2844 struct surface_context *ctx_surf = NULL;
2845 ivi_controller_layer_clear_surfaces(ctx_layer->controller);
2847 for (cnt = 0; cnt < number; cnt++) {
2848 id = (uint32_t)*(pSurfaceId + cnt);
2849 ctx_surf = get_surface_context(&ctx->main_ctx, id);
2851 if (ctx_surf == NULL) {
2852 fprintf(stderr, "invalud argument \
2853 in ilm_layerSetRenderOrder\n");
2856 ivi_controller_layer_add_surface(ctx_layer->controller,
2857 ctx_surf->controller);
2860 returnValue = ILM_SUCCESS;
2866 static ilmErrorTypes
2867 wayland_layerGetCapabilities(t_ilm_layer layerId,
2868 t_ilm_layercapabilities *pCapabilities)
2871 (void)pCapabilities;
2876 static ilmErrorTypes
2877 wayland_layerTypeGetCapabilities(ilmLayerType layerType,
2878 t_ilm_layercapabilities *pCapabilities)
2881 (void)pCapabilities;
2886 static ilmErrorTypes
2887 wayland_surfaceSetVisibility(t_ilm_surface surfaceId, t_ilm_bool newVisibility)
2889 ilmErrorTypes returnValue = ILM_FAILED;
2890 struct ilm_control_context *ctx = get_instance();
2891 struct surface_context *ctx_surf = NULL;
2892 uint32_t visibility = 0;
2894 if (newVisibility == ILM_TRUE) {
2897 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2899 ivi_controller_surface_set_visibility(ctx_surf->controller,
2901 returnValue = ILM_SUCCESS;
2907 static ilmErrorTypes
2908 wayland_surfaceSetOpacity(t_ilm_surface surfaceId, t_ilm_float opacity)
2910 ilmErrorTypes returnValue = ILM_FAILED;
2911 struct ilm_control_context *ctx = get_instance();
2912 struct surface_context *ctx_surf = NULL;
2913 wl_fixed_t opacity_fixed = 0;
2915 opacity_fixed = wl_fixed_from_double((double)opacity);
2916 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2918 ivi_controller_surface_set_opacity(ctx_surf->controller,
2920 returnValue = ILM_SUCCESS;
2926 static ilmErrorTypes
2927 wayland_surfaceGetOpacity(t_ilm_surface surfaceId, t_ilm_float *pOpacity)
2929 ilmErrorTypes returnValue = ILM_FAILED;
2930 struct ilm_control_context *ctx = get_instance();
2932 if (pOpacity != NULL) {
2933 struct surface_context *ctx_surf = NULL;
2934 ctx_surf = get_surface_context(&ctx->child_ctx, surfaceId);
2936 *pOpacity = ctx_surf->prop.opacity;
2937 returnValue = ILM_SUCCESS;
2944 static ilmErrorTypes
2945 wayland_SetKeyboardFocusOn(t_ilm_surface surfaceId)
2947 ilmErrorTypes returnValue = ILM_FAILED;
2949 returnValue = ILM_SUCCESS;
2953 static ilmErrorTypes
2954 wayland_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
2956 ilmErrorTypes returnValue = ILM_FAILED;
2958 returnValue = ILM_SUCCESS;
2962 static ilmErrorTypes
2963 wayland_surfaceSetDestinationRectangle(t_ilm_surface surfaceId,
2964 t_ilm_int x, t_ilm_int y,
2965 t_ilm_int width, t_ilm_int height)
2967 ilmErrorTypes returnValue = ILM_FAILED;
2968 struct ilm_control_context *ctx = get_instance();
2969 struct surface_context *ctx_surf = NULL;
2971 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2973 ivi_controller_surface_set_destination_rectangle(
2974 ctx_surf->controller,
2975 x, y, width, height);
2976 returnValue = ILM_SUCCESS;
2982 static ilmErrorTypes
2983 wayland_surfaceSetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
2985 ilmErrorTypes returnValue = ILM_FAILED;
2986 struct ilm_control_context *ctx = get_instance();
2988 if (pDimension != NULL) {
2989 struct surface_context *ctx_surf = NULL;
2990 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
2992 uint32_t width = *pDimension;
2993 uint32_t height = *(pDimension + 1);
2994 ivi_controller_surface_set_destination_rectangle(
2995 ctx_surf->controller,
2996 ctx_surf->prop.destX, ctx_surf->prop.destY, width, height);
2997 returnValue = ILM_SUCCESS;
3004 static ilmErrorTypes
3005 wayland_surfaceGetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
3007 ilmErrorTypes returnValue = ILM_FAILED;
3008 struct ilm_control_context *ctx = get_instance();
3010 if (pPosition != NULL) {
3011 struct surface_context *ctx_surf = NULL;
3012 ctx_surf = get_surface_context(&ctx->child_ctx, surfaceId);
3014 *pPosition = ctx_surf->prop.destX;
3015 *(pPosition + 1) = ctx_surf->prop.destY;
3016 returnValue = ILM_SUCCESS;
3023 static ilmErrorTypes
3024 wayland_surfaceSetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
3026 ilmErrorTypes returnValue = ILM_FAILED;
3027 struct ilm_control_context *ctx = get_instance();
3029 if (pPosition != NULL) {
3030 struct surface_context *ctx_surf = NULL;
3031 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
3033 int32_t destX = (int32_t)*pPosition;
3034 int32_t destY = (int32_t)*(pPosition + 1);
3035 ivi_controller_surface_set_destination_rectangle(
3036 ctx_surf->controller, destX, destY,
3037 ctx_surf->prop.destWidth, ctx_surf->prop.destHeight);
3038 returnValue = ILM_SUCCESS;
3045 static ilmErrorTypes
3046 wayland_surfaceSetOrientation(t_ilm_surface surfaceId,
3047 ilmOrientation orientation)
3049 ilmErrorTypes returnValue = ILM_FAILED;
3050 struct ilm_control_context *ctx = get_instance();
3051 struct surface_context *ctx_surf = NULL;
3052 int32_t iviorientation = 0;
3055 switch(orientation) {
3057 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES;
3060 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES;
3062 case ILM_ONEHUNDREDEIGHTY:
3063 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES;
3065 case ILM_TWOHUNDREDSEVENTY:
3066 iviorientation = IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES;
3069 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
3073 ctx_surf = get_surface_context(&ctx->main_ctx, surfaceId);
3074 if (ctx_surf == NULL) {
3075 returnValue = ILM_FAILED;
3079 ivi_controller_surface_set_orientation(ctx_surf->controller,
3082 returnValue = ILM_SUCCESS;
3088 static ilmErrorTypes
3089 wayland_surfaceGetOrientation(t_ilm_surface surfaceId,
3090 ilmOrientation *pOrientation)
3092 ilmErrorTypes returnValue = ILM_FAILED;
3093 struct ilm_control_context *ctx = get_instance();
3095 if (pOrientation != NULL) {
3096 struct surface_context *ctx_surf = NULL;
3097 ctx_surf = get_surface_context(&ctx->child_ctx, surfaceId);
3099 *pOrientation = ctx_surf->prop.orientation;
3100 returnValue = ILM_SUCCESS;
3107 static ilmErrorTypes
3108 wayland_surfaceGetPixelformat(t_ilm_layer surfaceId,
3109 ilmPixelFormat *pPixelformat)
3111 ilmErrorTypes returnValue = ILM_FAILED;
3112 struct ilm_control_context *ctx = get_instance();
3114 if (pPixelformat != NULL) {
3115 struct surface_context *ctx_surf = NULL;
3116 ctx_surf = get_surface_context(&ctx->child_ctx, surfaceId);
3118 *pPixelformat = ctx_surf->prop.pixelformat;
3119 returnValue = ILM_SUCCESS;
3126 static ilmErrorTypes
3127 wayland_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
3135 static ilmErrorTypes
3136 wayland_displaySetRenderOrder(t_ilm_display display,
3137 t_ilm_layer *pLayerId, const t_ilm_uint number)
3139 ilmErrorTypes returnValue = ILM_FAILED;
3140 struct ilm_control_context *ctx = get_instance();
3141 struct screen_context *ctx_scrn = NULL;
3143 ctx_scrn = get_screen_context_by_id(&ctx->main_ctx, (uint32_t)display);
3144 if (ctx_scrn != NULL) {
3147 struct layer_context *ctx_layer = NULL;
3149 ivi_controller_screen_clear(ctx_scrn->controller);
3151 for (cnt = 0; cnt < (int)number; cnt++) {
3152 id = (uint32_t)*(pLayerId + cnt);
3154 (struct layer_context*)wayland_controller_get_layer_context(
3155 &ctx->main_ctx, id);
3156 if (ctx_layer != NULL) {
3157 ivi_controller_screen_add_layer(ctx_scrn->controller,
3158 ctx_layer->controller);
3162 returnValue = ILM_SUCCESS;
3168 static ilmErrorTypes
3169 wayland_takeScreenshot(t_ilm_uint screen, t_ilm_const_string filename)
3171 ilmErrorTypes returnValue = ILM_FAILED;
3172 struct ilm_control_context *ctx = get_instance();
3173 struct screen_context *ctx_scrn = NULL;
3175 ctx_scrn = get_screen_context_by_id(&ctx->main_ctx, (uint32_t)screen);
3176 if (ctx_scrn != NULL) {
3177 ivi_controller_screen_screenshot(ctx_scrn->controller,
3179 wl_display_flush(ctx->main_ctx.display);
3180 returnValue = ILM_SUCCESS;
3186 static ilmErrorTypes
3187 wayland_takeLayerScreenshot(t_ilm_const_string filename, t_ilm_layer layerid)
3189 ilmErrorTypes returnValue = ILM_FAILED;
3190 struct ilm_control_context *ctx = get_instance();
3191 struct layer_context *ctx_layer = NULL;
3193 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
3194 &ctx->main_ctx, (uint32_t)layerid);
3195 if (ctx_layer != NULL) {
3196 ivi_controller_layer_screenshot(ctx_layer->controller,
3198 returnValue = ILM_SUCCESS;
3204 static ilmErrorTypes
3205 wayland_takeSurfaceScreenshot(t_ilm_const_string filename,
3206 t_ilm_surface surfaceid)
3208 ilmErrorTypes returnValue = ILM_FAILED;
3209 struct ilm_control_context *ctx = get_instance();
3210 struct surface_context *ctx_surf = NULL;
3212 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceid);
3214 ivi_controller_surface_screenshot(ctx_surf->controller,
3216 wl_display_flush(ctx->main_ctx.display);
3217 returnValue = ILM_SUCCESS;
3223 static ilmErrorTypes
3224 wayland_SetOptimizationMode(ilmOptimization id, ilmOptimizationMode mode)
3232 static ilmErrorTypes
3233 wayland_GetOptimizationMode(ilmOptimization id, ilmOptimizationMode* pMode)
3242 static ilmErrorTypes
3243 wayland_layerAddNotification(t_ilm_layer layer,
3244 layerNotificationFunc callback)
3246 ilmErrorTypes returnValue = ILM_FAILED;
3247 struct ilm_control_context *ctx = get_instance();
3248 struct layer_context *ctx_layer = NULL;
3250 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
3251 &ctx->child_ctx, (uint32_t)layer);
3252 if (ctx_layer == NULL) {
3253 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
3255 ctx_layer->notification = callback;
3257 returnValue = ILM_SUCCESS;
3264 static ilmErrorTypes
3265 wayland_layerRemoveNotification(t_ilm_layer layer)
3267 ilmErrorTypes returnValue = ILM_FAILED;
3268 struct ilm_control_context *ctx = get_instance();
3269 struct layer_context *ctx_layer = NULL;
3271 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
3272 &ctx->child_ctx, (uint32_t)layer);
3273 if (ctx_layer == NULL) {
3274 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
3276 ctx_layer->notification = NULL;
3278 returnValue = ILM_SUCCESS;
3285 static ilmErrorTypes
3286 wayland_surfaceAddNotification(t_ilm_surface surface,
3287 surfaceNotificationFunc callback)
3289 ilmErrorTypes returnValue = ILM_FAILED;
3290 struct ilm_control_context *ctx = get_instance();
3291 struct surface_context *ctx_surf = NULL;
3293 ctx_surf = (struct surface_context*)get_surface_context(
3294 &ctx->child_ctx, (uint32_t)surface);
3295 if (ctx_surf == NULL) {
3296 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
3298 ctx_surf->notification = callback;
3300 returnValue = ILM_SUCCESS;
3307 static ilmErrorTypes
3308 wayland_surfaceRemoveNotification(t_ilm_surface surface)
3310 ilmErrorTypes returnValue = ILM_FAILED;
3311 struct ilm_control_context *ctx = get_instance();
3312 struct surface_context *ctx_surf = NULL;
3314 ctx_surf = (struct surface_context*)get_surface_context(
3315 &ctx->child_ctx, (uint32_t)surface);
3316 if (ctx_surf == NULL) {
3317 returnValue = ILM_ERROR_INVALID_ARGUMENTS;
3319 ctx_surf->notification = NULL;
3321 returnValue = ILM_SUCCESS;
3327 static ilmErrorTypes
3328 wayland_getNativeHandle(t_ilm_uint pid, t_ilm_int *n_handle,
3329 t_ilm_nativehandle **p_handles)
3331 struct ilm_control_context *ctx = get_instance();
3332 struct nativehandle_context *p_nh_ctx = NULL;
3337 wl_list_for_each(p_nh_ctx, &ctx->list_nativehandle, link)
3339 if (p_nh_ctx->pid == pid)
3343 (t_ilm_nativehandle*)malloc(sizeof(t_ilm_nativehandle));
3344 (*p_handles)[0] = p_nh_ctx->nativehandle;
3349 return (*n_handle > 0) ? ILM_SUCCESS : ILM_FAILED;
3352 static ilmErrorTypes
3353 wayland_getPropertiesOfSurface(t_ilm_uint surfaceID,
3354 struct ilmSurfaceProperties* pSurfaceProperties)
3356 ilmErrorTypes returnValue = ILM_FAILED;
3357 struct ilm_control_context *ctx = get_instance();
3359 if (pSurfaceProperties != NULL) {
3360 struct surface_context *ctx_surf = NULL;
3362 ctx_surf = get_surface_context(&ctx->child_ctx, (uint32_t)surfaceID);
3363 if (ctx_surf != NULL) {
3365 *pSurfaceProperties = ctx_surf->prop;
3366 returnValue = ILM_SUCCESS;
3373 static ilmErrorTypes
3374 wayland_layerAddSurface(t_ilm_layer layerId,
3375 t_ilm_surface surfaceId)
3377 ilmErrorTypes returnValue = ILM_FAILED;
3378 struct ilm_control_context *ctx = get_instance();
3379 struct layer_context *ctx_layer = NULL;
3380 struct surface_context *ctx_surf = NULL;
3382 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
3383 &ctx->main_ctx, (uint32_t)layerId);
3384 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
3385 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
3386 ivi_controller_layer_add_surface(ctx_layer->controller,
3387 ctx_surf->controller);
3388 returnValue = ILM_SUCCESS;
3394 static ilmErrorTypes
3395 wayland_layerRemoveSurface(t_ilm_layer layerId,
3396 t_ilm_surface surfaceId)
3398 ilmErrorTypes returnValue = ILM_FAILED;
3399 struct ilm_control_context *ctx = get_instance();
3400 struct layer_context *ctx_layer = NULL;
3401 struct surface_context *ctx_surf = NULL;
3403 ctx_layer = (struct layer_context*)wayland_controller_get_layer_context(
3404 &ctx->main_ctx, (uint32_t)layerId);
3405 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
3406 if ((ctx_layer != NULL) && (ctx_surf != NULL)) {
3407 ivi_controller_layer_remove_surface(ctx_layer->controller,
3408 ctx_surf->controller);
3409 returnValue = ILM_SUCCESS;
3415 static ilmErrorTypes
3416 wayland_surfaceGetDimension(t_ilm_surface surfaceId,
3417 t_ilm_uint *pDimension)
3419 ilmErrorTypes returnValue = ILM_FAILED;
3420 struct ilm_control_context *ctx = get_instance();
3422 if (pDimension != NULL) {
3423 struct surface_context *ctx_surf = NULL;
3425 ctx_surf = get_surface_context(&ctx->child_ctx, (uint32_t)surfaceId);
3426 if (ctx_surf != NULL) {
3427 *pDimension = (t_ilm_uint)ctx_surf->prop.destWidth;
3428 *(pDimension + 1) = (t_ilm_uint)ctx_surf->prop.destHeight;
3429 returnValue = ILM_SUCCESS;
3436 static ilmErrorTypes
3437 wayland_surfaceGetVisibility(t_ilm_surface surfaceId,
3438 t_ilm_bool *pVisibility)
3440 ilmErrorTypes returnValue = ILM_FAILED;
3441 struct ilm_control_context *ctx = get_instance();
3442 struct surface_context *ctx_surf = NULL;
3444 if (pVisibility != NULL) {
3445 ctx_surf = get_surface_context(&ctx->child_ctx, (uint32_t)surfaceId);
3446 if (ctx_surf != NULL) {
3447 *pVisibility = (t_ilm_bool)ctx_surf->prop.visibility;
3448 returnValue = ILM_SUCCESS;
3455 static ilmErrorTypes
3456 wayland_surfaceSetSourceRectangle(t_ilm_surface surfaceId,
3457 t_ilm_int x, t_ilm_int y,
3458 t_ilm_int width, t_ilm_int height)
3460 ilmErrorTypes returnValue = ILM_FAILED;
3461 struct ilm_control_context *ctx = get_instance();
3462 struct surface_context *ctx_surf = NULL;
3464 ctx_surf = get_surface_context(&ctx->main_ctx, (uint32_t)surfaceId);
3465 if (ctx_surf != NULL) {
3466 if (ctx_surf->controller != NULL) {
3467 ivi_controller_surface_set_source_rectangle(
3468 ctx_surf->controller,
3469 x, y, width, height);
3470 returnValue = ILM_SUCCESS;
3477 static ilmErrorTypes
3478 wayland_commitChanges()
3480 ilmErrorTypes returnValue = ILM_FAILED;
3481 struct ilm_control_context *ctx = get_instance();
3483 if (ctx->main_ctx.controller != NULL) {
3484 ivi_controller_commit_changes(ctx->main_ctx.controller);
3486 wl_display_roundtrip(ctx->main_ctx.display);
3487 returnValue = ILM_SUCCESS;