Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 DENSO CORPORATION |
| 3 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 11 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <time.h> |
| 27 | #include <assert.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <stdio.h> |
Lucas Tanure | 9b5fe42 | 2015-09-21 14:10:32 -0300 | [diff] [blame] | 30 | #include <stdbool.h> |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 31 | |
| 32 | #include "ivi-layout-export.h" |
| 33 | #include "ivi-layout-private.h" |
| 34 | |
| 35 | struct ivi_layout_transition; |
| 36 | |
| 37 | typedef void (*ivi_layout_transition_frame_func)( |
| 38 | struct ivi_layout_transition *transition); |
| 39 | typedef void (*ivi_layout_transition_destroy_func)( |
| 40 | struct ivi_layout_transition *transition); |
| 41 | typedef int32_t (*ivi_layout_is_transition_func)(void *private_data, void *id); |
| 42 | |
| 43 | struct ivi_layout_transition { |
| 44 | enum ivi_layout_transition_type type; |
| 45 | void *private_data; |
| 46 | void *user_data; |
| 47 | |
| 48 | uint32_t time_start; |
| 49 | uint32_t time_duration; |
| 50 | uint32_t time_elapsed; |
| 51 | uint32_t is_done; |
| 52 | ivi_layout_is_transition_func is_transition_func; |
| 53 | ivi_layout_transition_frame_func frame_func; |
| 54 | ivi_layout_transition_destroy_func destroy_func; |
| 55 | }; |
| 56 | |
| 57 | struct transition_node { |
| 58 | struct ivi_layout_transition *transition; |
| 59 | struct wl_list link; |
| 60 | }; |
| 61 | |
| 62 | static void layout_transition_destroy(struct ivi_layout_transition *transition); |
| 63 | |
| 64 | static struct ivi_layout_transition * |
| 65 | get_transition_from_type_and_id(enum ivi_layout_transition_type type, |
| 66 | void *id_data) |
| 67 | { |
| 68 | struct ivi_layout *layout = get_instance(); |
| 69 | struct transition_node *node; |
| 70 | struct ivi_layout_transition *tran; |
| 71 | |
| 72 | wl_list_for_each(node, &layout->transitions->transition_list, link) { |
| 73 | tran = node->transition; |
| 74 | |
| 75 | if (tran->type == type && |
| 76 | tran->is_transition_func(tran->private_data, id_data)) |
| 77 | return tran; |
| 78 | } |
| 79 | |
| 80 | return NULL; |
| 81 | } |
| 82 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 83 | int32_t |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 84 | is_surface_transition(struct ivi_layout_surface *surface) |
| 85 | { |
| 86 | struct ivi_layout *layout = get_instance(); |
| 87 | struct transition_node *node; |
| 88 | struct ivi_layout_transition *tran; |
| 89 | |
| 90 | wl_list_for_each(node, &layout->transitions->transition_list, link) { |
| 91 | tran = node->transition; |
| 92 | |
| 93 | if ((tran->type == IVI_LAYOUT_TRANSITION_VIEW_MOVE_RESIZE || |
| 94 | tran->type == IVI_LAYOUT_TRANSITION_VIEW_RESIZE) && |
| 95 | tran->is_transition_func(tran->private_data, surface)) |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Mateusz Polrola | dada6e3 | 2016-03-09 09:13:26 +0000 | [diff] [blame^] | 102 | void |
| 103 | ivi_layout_remove_all_surface_transitions(struct ivi_layout_surface *surface) |
| 104 | { |
| 105 | struct ivi_layout *layout = get_instance(); |
| 106 | struct transition_node *node; |
| 107 | struct transition_node *tmp; |
| 108 | struct ivi_layout_transition *tran; |
| 109 | |
| 110 | wl_list_for_each_safe(node, tmp, &layout->transitions->transition_list, link) { |
| 111 | tran = node->transition; |
| 112 | if (tran->is_transition_func(tran->private_data, surface)) { |
| 113 | layout_transition_destroy(tran); |
| 114 | } |
| 115 | }; |
| 116 | } |
| 117 | |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 118 | static void |
| 119 | tick_transition(struct ivi_layout_transition *transition, uint32_t timestamp) |
| 120 | { |
| 121 | const double t = timestamp - transition->time_start; |
| 122 | |
| 123 | if (transition->time_duration <= t) { |
| 124 | transition->time_elapsed = transition->time_duration; |
| 125 | transition->is_done = 1; |
| 126 | } else { |
| 127 | transition->time_elapsed = t; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static float time_to_nowpos(struct ivi_layout_transition *transition) |
| 132 | { |
| 133 | return sin((float)transition->time_elapsed / |
| 134 | (float)transition->time_duration * M_PI_2); |
| 135 | } |
| 136 | |
| 137 | static void |
| 138 | do_transition_frame(struct ivi_layout_transition *transition, |
| 139 | uint32_t timestamp) |
| 140 | { |
| 141 | if (0 == transition->time_start) |
| 142 | transition->time_start = timestamp; |
| 143 | |
| 144 | tick_transition(transition, timestamp); |
| 145 | transition->frame_func(transition); |
| 146 | |
| 147 | if (transition->is_done) |
| 148 | layout_transition_destroy(transition); |
| 149 | } |
| 150 | |
| 151 | static int32_t |
| 152 | layout_transition_frame(void *data) |
| 153 | { |
| 154 | struct ivi_layout_transition_set *transitions = data; |
| 155 | uint32_t fps = 30; |
| 156 | struct timespec timestamp = {}; |
| 157 | uint32_t msec = 0; |
| 158 | struct transition_node *node = NULL; |
| 159 | struct transition_node *next = NULL; |
| 160 | |
| 161 | if (wl_list_empty(&transitions->transition_list)) { |
| 162 | wl_event_source_timer_update(transitions->event_source, 0); |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | wl_event_source_timer_update(transitions->event_source, 1000 / fps); |
| 167 | |
| 168 | clock_gettime(CLOCK_MONOTONIC, ×tamp);/* FIXME */ |
| 169 | msec = (1e+3 * timestamp.tv_sec + 1e-6 * timestamp.tv_nsec); |
| 170 | |
| 171 | wl_list_for_each_safe(node, next, &transitions->transition_list, link) { |
| 172 | do_transition_frame(node->transition, msec); |
| 173 | } |
| 174 | |
| 175 | ivi_layout_commit_changes(); |
| 176 | return 1; |
| 177 | } |
| 178 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 179 | struct ivi_layout_transition_set * |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 180 | ivi_layout_transition_set_create(struct weston_compositor *ec) |
| 181 | { |
| 182 | struct ivi_layout_transition_set *transitions; |
| 183 | struct wl_event_loop *loop; |
| 184 | |
| 185 | transitions = malloc(sizeof(*transitions)); |
| 186 | if (transitions == NULL) { |
| 187 | weston_log("%s: memory allocation fails\n", __func__); |
| 188 | return NULL; |
| 189 | } |
| 190 | |
| 191 | wl_list_init(&transitions->transition_list); |
| 192 | |
| 193 | loop = wl_display_get_event_loop(ec->wl_display); |
| 194 | transitions->event_source = |
| 195 | wl_event_loop_add_timer(loop, layout_transition_frame, |
| 196 | transitions); |
| 197 | |
| 198 | return transitions; |
| 199 | } |
| 200 | |
Lucas Tanure | 9b5fe42 | 2015-09-21 14:10:32 -0300 | [diff] [blame] | 201 | static bool |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 202 | layout_transition_register(struct ivi_layout_transition *trans) |
| 203 | { |
| 204 | struct ivi_layout *layout = get_instance(); |
| 205 | struct transition_node *node; |
| 206 | |
| 207 | node = malloc(sizeof(*node)); |
| 208 | if (node == NULL) { |
| 209 | weston_log("%s: memory allocation fails\n", __func__); |
Lucas Tanure | 9b5fe42 | 2015-09-21 14:10:32 -0300 | [diff] [blame] | 210 | return false; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | node->transition = trans; |
| 214 | wl_list_insert(&layout->pending_transition_list, &node->link); |
Lucas Tanure | 9b5fe42 | 2015-09-21 14:10:32 -0300 | [diff] [blame] | 215 | return true; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static void |
| 219 | remove_transition(struct ivi_layout *layout, |
| 220 | struct ivi_layout_transition *trans) |
| 221 | { |
| 222 | struct transition_node *node; |
| 223 | struct transition_node *next; |
| 224 | |
| 225 | wl_list_for_each_safe(node, next, |
| 226 | &layout->transitions->transition_list, link) { |
| 227 | if (node->transition == trans) { |
| 228 | wl_list_remove(&node->link); |
| 229 | free(node); |
| 230 | return; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | wl_list_for_each_safe(node, next, |
| 235 | &layout->pending_transition_list, link) { |
| 236 | if (node->transition == trans) { |
| 237 | wl_list_remove(&node->link); |
| 238 | free(node); |
| 239 | return; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | static void |
| 245 | layout_transition_destroy(struct ivi_layout_transition *transition) |
| 246 | { |
| 247 | struct ivi_layout *layout = get_instance(); |
| 248 | |
| 249 | remove_transition(layout, transition); |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 250 | if (transition->destroy_func) |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 251 | transition->destroy_func(transition); |
| 252 | free(transition); |
| 253 | } |
| 254 | |
| 255 | static struct ivi_layout_transition * |
| 256 | create_layout_transition(void) |
| 257 | { |
| 258 | struct ivi_layout_transition *transition = malloc(sizeof(*transition)); |
| 259 | |
| 260 | if (transition == NULL) { |
| 261 | weston_log("%s: memory allocation fails\n", __func__); |
| 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | transition->type = IVI_LAYOUT_TRANSITION_MAX; |
| 266 | transition->time_start = 0; |
| 267 | transition->time_duration = 300; /* 300ms */ |
| 268 | transition->time_elapsed = 0; |
| 269 | |
| 270 | transition->is_done = 0; |
| 271 | |
John-John Tedro | 9d7aff0 | 2015-09-20 02:47:37 +0200 | [diff] [blame] | 272 | transition->is_transition_func = NULL; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 273 | transition->private_data = NULL; |
| 274 | transition->user_data = NULL; |
| 275 | |
| 276 | transition->frame_func = NULL; |
| 277 | transition->destroy_func = NULL; |
| 278 | |
| 279 | return transition; |
| 280 | } |
| 281 | |
| 282 | /* move and resize view transition */ |
| 283 | |
| 284 | struct move_resize_view_data { |
| 285 | struct ivi_layout_surface *surface; |
| 286 | int32_t start_x; |
| 287 | int32_t start_y; |
| 288 | int32_t end_x; |
| 289 | int32_t end_y; |
| 290 | int32_t start_width; |
| 291 | int32_t start_height; |
| 292 | int32_t end_width; |
| 293 | int32_t end_height; |
| 294 | }; |
| 295 | |
| 296 | static void |
| 297 | transition_move_resize_view_destroy(struct ivi_layout_transition *transition) |
| 298 | { |
| 299 | struct move_resize_view_data *data = |
| 300 | (struct move_resize_view_data *)transition->private_data; |
| 301 | struct ivi_layout_surface *layout_surface = data->surface; |
| 302 | |
| 303 | wl_signal_emit(&layout_surface->configured, layout_surface); |
| 304 | |
| 305 | if (transition->private_data) { |
| 306 | free(transition->private_data); |
| 307 | transition->private_data = NULL; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | static void |
| 312 | transition_move_resize_view_user_frame(struct ivi_layout_transition *transition) |
| 313 | { |
| 314 | struct move_resize_view_data *mrv = transition->private_data; |
| 315 | const double current = time_to_nowpos(transition); |
| 316 | |
| 317 | const int32_t destx = mrv->start_x + |
| 318 | (mrv->end_x - mrv->start_x) * current; |
| 319 | |
| 320 | const int32_t desty = mrv->start_y + |
| 321 | (mrv->end_y - mrv->start_y) * current; |
| 322 | |
| 323 | const int32_t dest_width = mrv->start_width + |
| 324 | (mrv->end_width - mrv->start_width) * current; |
| 325 | |
| 326 | const int32_t dest_height = mrv->start_height + |
| 327 | (mrv->end_height - mrv->start_height) * current; |
| 328 | |
| 329 | ivi_layout_surface_set_destination_rectangle(mrv->surface, |
| 330 | destx, desty, |
| 331 | dest_width, dest_height); |
| 332 | } |
| 333 | |
| 334 | static int32_t |
| 335 | is_transition_move_resize_view_func(struct move_resize_view_data *data, |
| 336 | struct ivi_layout_surface *view) |
| 337 | { |
| 338 | return data->surface == view; |
| 339 | } |
| 340 | |
| 341 | static struct ivi_layout_transition * |
| 342 | create_move_resize_view_transition( |
| 343 | struct ivi_layout_surface *surface, |
| 344 | int32_t start_x, int32_t start_y, |
| 345 | int32_t end_x, int32_t end_y, |
| 346 | int32_t start_width, int32_t start_height, |
| 347 | int32_t end_width, int32_t end_height, |
| 348 | ivi_layout_transition_frame_func frame_func, |
| 349 | ivi_layout_transition_destroy_func destroy_func, |
| 350 | uint32_t duration) |
| 351 | { |
Carlos Olmedo Escobar | 703f502 | 2015-03-02 13:24:36 +0100 | [diff] [blame] | 352 | struct ivi_layout_transition *transition; |
| 353 | struct move_resize_view_data *data; |
| 354 | |
| 355 | transition = create_layout_transition(); |
Carlos Olmedo Escobar | e82ba53 | 2015-01-17 19:43:02 +0100 | [diff] [blame] | 356 | if (transition == NULL) |
| 357 | return NULL; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 358 | |
Carlos Olmedo Escobar | 703f502 | 2015-03-02 13:24:36 +0100 | [diff] [blame] | 359 | data = malloc(sizeof(*data)); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 360 | if (data == NULL) { |
| 361 | weston_log("%s: memory allocation fails\n", __func__); |
Lucas Tanure | 9af0017 | 2015-09-21 11:24:35 -0300 | [diff] [blame] | 362 | free(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 363 | return NULL; |
| 364 | } |
| 365 | |
| 366 | transition->type = IVI_LAYOUT_TRANSITION_VIEW_MOVE_RESIZE; |
| 367 | transition->is_transition_func = (ivi_layout_is_transition_func)is_transition_move_resize_view_func; |
| 368 | |
| 369 | transition->frame_func = frame_func; |
| 370 | transition->destroy_func = destroy_func; |
| 371 | transition->private_data = data; |
| 372 | |
| 373 | if (duration != 0) |
| 374 | transition->time_duration = duration; |
| 375 | |
| 376 | data->surface = surface; |
| 377 | data->start_x = start_x; |
| 378 | data->start_y = start_y; |
| 379 | data->end_x = end_x; |
| 380 | data->end_y = end_y; |
| 381 | |
| 382 | data->start_width = start_width; |
| 383 | data->start_height = start_height; |
| 384 | data->end_width = end_width; |
| 385 | data->end_height = end_height; |
| 386 | |
| 387 | return transition; |
| 388 | } |
| 389 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 390 | void |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 391 | ivi_layout_transition_move_resize_view(struct ivi_layout_surface *surface, |
| 392 | int32_t dest_x, int32_t dest_y, |
| 393 | int32_t dest_width, int32_t dest_height, |
| 394 | uint32_t duration) |
| 395 | { |
| 396 | struct ivi_layout_transition *transition; |
| 397 | int32_t start_pos[2] = { |
| 398 | surface->pending.prop.start_x, |
| 399 | surface->pending.prop.start_y |
| 400 | }; |
| 401 | |
| 402 | int32_t start_size[2] = { |
| 403 | surface->pending.prop.start_width, |
| 404 | surface->pending.prop.start_height |
| 405 | }; |
| 406 | |
| 407 | transition = get_transition_from_type_and_id( |
| 408 | IVI_LAYOUT_TRANSITION_VIEW_MOVE_RESIZE, |
| 409 | surface); |
| 410 | if (transition) { |
| 411 | struct move_resize_view_data *data = transition->private_data; |
| 412 | transition->time_start = 0; |
| 413 | transition->time_duration = duration; |
| 414 | |
| 415 | data->start_x = start_pos[0]; |
| 416 | data->start_y = start_pos[1]; |
| 417 | data->end_x = dest_x; |
| 418 | data->end_y = dest_y; |
| 419 | |
| 420 | data->start_width = start_size[0]; |
| 421 | data->start_height = start_size[1]; |
| 422 | data->end_width = dest_width; |
| 423 | data->end_height = dest_height; |
| 424 | return; |
| 425 | } |
| 426 | |
| 427 | transition = create_move_resize_view_transition( |
| 428 | surface, |
| 429 | start_pos[0], start_pos[1], |
| 430 | dest_x, dest_y, |
| 431 | start_size[0], start_size[1], |
| 432 | dest_width, dest_height, |
| 433 | transition_move_resize_view_user_frame, |
| 434 | transition_move_resize_view_destroy, |
| 435 | duration); |
| 436 | |
Lucas Tanure | a3377cd | 2015-09-30 09:38:37 -0300 | [diff] [blame] | 437 | if(transition && layout_transition_register(transition)) |
| 438 | return; |
| 439 | layout_transition_destroy(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* fade transition */ |
| 443 | struct fade_view_data { |
| 444 | struct ivi_layout_surface *surface; |
| 445 | double start_alpha; |
| 446 | double end_alpha; |
| 447 | }; |
| 448 | |
| 449 | struct store_alpha{ |
| 450 | double alpha; |
| 451 | }; |
| 452 | |
| 453 | static void |
| 454 | fade_view_user_frame(struct ivi_layout_transition *transition) |
| 455 | { |
| 456 | struct fade_view_data *fade = transition->private_data; |
| 457 | struct ivi_layout_surface *surface = fade->surface; |
| 458 | |
| 459 | const double current = time_to_nowpos(transition); |
| 460 | const double alpha = fade->start_alpha + |
| 461 | (fade->end_alpha - fade->start_alpha) * current; |
| 462 | |
| 463 | ivi_layout_surface_set_opacity(surface, wl_fixed_from_double(alpha)); |
| 464 | ivi_layout_surface_set_visibility(surface, true); |
| 465 | } |
| 466 | |
| 467 | static int32_t |
| 468 | is_transition_fade_view_func(struct fade_view_data *data, |
| 469 | struct ivi_layout_surface *view) |
| 470 | { |
| 471 | return data->surface == view; |
| 472 | } |
| 473 | |
| 474 | static struct ivi_layout_transition * |
| 475 | create_fade_view_transition( |
| 476 | struct ivi_layout_surface *surface, |
| 477 | double start_alpha, double end_alpha, |
| 478 | ivi_layout_transition_frame_func frame_func, |
| 479 | void *user_data, |
| 480 | ivi_layout_transition_destroy_func destroy_func, |
| 481 | uint32_t duration) |
| 482 | { |
Carlos Olmedo Escobar | 703f502 | 2015-03-02 13:24:36 +0100 | [diff] [blame] | 483 | struct ivi_layout_transition *transition; |
| 484 | struct fade_view_data *data; |
| 485 | |
| 486 | transition = create_layout_transition(); |
Carlos Olmedo Escobar | e82ba53 | 2015-01-17 19:43:02 +0100 | [diff] [blame] | 487 | if (transition == NULL) |
| 488 | return NULL; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 489 | |
Carlos Olmedo Escobar | 703f502 | 2015-03-02 13:24:36 +0100 | [diff] [blame] | 490 | data = malloc(sizeof(*data)); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 491 | if (data == NULL) { |
| 492 | weston_log("%s: memory allocation fails\n", __func__); |
Lucas Tanure | 9af0017 | 2015-09-21 11:24:35 -0300 | [diff] [blame] | 493 | free(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 494 | return NULL; |
| 495 | } |
| 496 | |
| 497 | transition->type = IVI_LAYOUT_TRANSITION_VIEW_FADE; |
| 498 | transition->is_transition_func = (ivi_layout_is_transition_func)is_transition_fade_view_func; |
| 499 | |
| 500 | transition->user_data = user_data; |
| 501 | transition->private_data = data; |
| 502 | transition->frame_func = frame_func; |
| 503 | transition->destroy_func = destroy_func; |
| 504 | |
| 505 | if (duration != 0) |
| 506 | transition->time_duration = duration; |
| 507 | |
| 508 | data->surface = surface; |
| 509 | data->start_alpha = start_alpha; |
| 510 | data->end_alpha = end_alpha; |
| 511 | |
| 512 | return transition; |
| 513 | } |
| 514 | |
| 515 | static void |
| 516 | create_visibility_transition(struct ivi_layout_surface *surface, |
| 517 | double start_alpha, |
| 518 | double dest_alpha, |
| 519 | void *user_data, |
| 520 | ivi_layout_transition_destroy_func destroy_func, |
| 521 | uint32_t duration) |
| 522 | { |
| 523 | struct ivi_layout_transition *transition = NULL; |
| 524 | |
| 525 | transition = create_fade_view_transition( |
| 526 | surface, |
| 527 | start_alpha, dest_alpha, |
| 528 | fade_view_user_frame, |
| 529 | user_data, |
| 530 | destroy_func, |
| 531 | duration); |
| 532 | |
Lucas Tanure | a3377cd | 2015-09-30 09:38:37 -0300 | [diff] [blame] | 533 | if (transition && layout_transition_register(transition)) |
| 534 | return; |
| 535 | layout_transition_destroy(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void |
| 539 | visibility_on_transition_destroy(struct ivi_layout_transition *transition) |
| 540 | { |
| 541 | struct fade_view_data *data = transition->private_data; |
| 542 | struct store_alpha *user_data = transition->user_data; |
| 543 | |
| 544 | ivi_layout_surface_set_visibility(data->surface, true); |
| 545 | |
| 546 | free(data); |
| 547 | transition->private_data = NULL; |
| 548 | |
| 549 | free(user_data); |
| 550 | transition->user_data = NULL; |
| 551 | } |
| 552 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 553 | void |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 554 | ivi_layout_transition_visibility_on(struct ivi_layout_surface *surface, |
| 555 | uint32_t duration) |
| 556 | { |
| 557 | struct ivi_layout_transition *transition; |
Ucan, Emre \(ADITG/SW1\) | c6a138c | 2016-03-04 12:50:06 +0000 | [diff] [blame] | 558 | bool is_visible = surface->prop.visibility; |
Ucan, Emre \(ADITG/SW1\) | 995e6fb | 2016-03-04 12:50:12 +0000 | [diff] [blame] | 559 | wl_fixed_t dest_alpha = surface->prop.opacity; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 560 | struct store_alpha *user_data = NULL; |
| 561 | wl_fixed_t start_alpha = 0.0; |
| 562 | struct fade_view_data *data = NULL; |
| 563 | |
| 564 | transition = get_transition_from_type_and_id( |
| 565 | IVI_LAYOUT_TRANSITION_VIEW_FADE, |
| 566 | surface); |
| 567 | if (transition) { |
Ucan, Emre \(ADITG/SW1\) | 995e6fb | 2016-03-04 12:50:12 +0000 | [diff] [blame] | 568 | start_alpha = surface->prop.opacity; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 569 | user_data = transition->user_data; |
| 570 | data = transition->private_data; |
| 571 | |
| 572 | transition->time_start = 0; |
| 573 | transition->time_duration = duration; |
| 574 | transition->destroy_func = visibility_on_transition_destroy; |
| 575 | |
| 576 | data->start_alpha = wl_fixed_to_double(start_alpha); |
| 577 | data->end_alpha = user_data->alpha; |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | if (is_visible) |
| 582 | return; |
| 583 | |
| 584 | user_data = malloc(sizeof(*user_data)); |
| 585 | if (user_data == NULL) { |
| 586 | weston_log("%s: memory allocation fails\n", __func__); |
| 587 | return; |
| 588 | } |
| 589 | |
| 590 | user_data->alpha = wl_fixed_to_double(dest_alpha); |
| 591 | |
| 592 | create_visibility_transition(surface, |
| 593 | 0.0, // start_alpha |
| 594 | wl_fixed_to_double(dest_alpha), |
| 595 | user_data, |
| 596 | visibility_on_transition_destroy, |
| 597 | duration); |
| 598 | } |
| 599 | |
| 600 | static void |
| 601 | visibility_off_transition_destroy(struct ivi_layout_transition *transition) |
| 602 | { |
| 603 | struct fade_view_data *data = transition->private_data; |
| 604 | struct store_alpha *user_data = transition->user_data; |
| 605 | |
| 606 | ivi_layout_surface_set_visibility(data->surface, false); |
| 607 | |
| 608 | ivi_layout_surface_set_opacity(data->surface, |
| 609 | wl_fixed_from_double(user_data->alpha)); |
| 610 | |
| 611 | free(data); |
| 612 | transition->private_data = NULL; |
| 613 | |
| 614 | free(user_data); |
| 615 | transition->user_data= NULL; |
| 616 | } |
| 617 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 618 | void |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 619 | ivi_layout_transition_visibility_off(struct ivi_layout_surface *surface, |
| 620 | uint32_t duration) |
| 621 | { |
| 622 | struct ivi_layout_transition *transition; |
Ucan, Emre \(ADITG/SW1\) | 995e6fb | 2016-03-04 12:50:12 +0000 | [diff] [blame] | 623 | wl_fixed_t start_alpha = surface->prop.opacity; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 624 | struct store_alpha* user_data = NULL; |
| 625 | struct fade_view_data* data = NULL; |
| 626 | |
| 627 | transition = |
| 628 | get_transition_from_type_and_id(IVI_LAYOUT_TRANSITION_VIEW_FADE, |
| 629 | surface); |
| 630 | if (transition) { |
| 631 | data = transition->private_data; |
| 632 | |
| 633 | transition->time_start = 0; |
| 634 | transition->time_duration = duration; |
| 635 | transition->destroy_func = visibility_off_transition_destroy; |
| 636 | |
| 637 | data->start_alpha = wl_fixed_to_double(start_alpha); |
| 638 | data->end_alpha = 0; |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | user_data = malloc(sizeof(*user_data)); |
| 643 | if (user_data == NULL) { |
| 644 | weston_log("%s: memory allocation fails\n", __func__); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | user_data->alpha = wl_fixed_to_double(start_alpha); |
| 649 | |
| 650 | create_visibility_transition(surface, |
| 651 | wl_fixed_to_double(start_alpha), |
| 652 | 0.0, // dest_alpha |
| 653 | user_data, |
| 654 | visibility_off_transition_destroy, |
| 655 | duration); |
| 656 | } |
| 657 | |
| 658 | /* move layer transition */ |
| 659 | |
| 660 | struct move_layer_data { |
| 661 | struct ivi_layout_layer *layer; |
| 662 | int32_t start_x; |
| 663 | int32_t start_y; |
| 664 | int32_t end_x; |
| 665 | int32_t end_y; |
| 666 | ivi_layout_transition_destroy_user_func destroy_func; |
| 667 | }; |
| 668 | |
| 669 | static void |
| 670 | transition_move_layer_user_frame(struct ivi_layout_transition *transition) |
| 671 | { |
| 672 | struct move_layer_data *data = transition->private_data; |
| 673 | struct ivi_layout_layer *layer = data->layer; |
| 674 | |
| 675 | const float current = time_to_nowpos(transition); |
| 676 | |
| 677 | const int32_t dest_x = data->start_x + |
| 678 | (data->end_x - data->start_x) * current; |
| 679 | |
| 680 | const int32_t dest_y = data->start_y + |
| 681 | (data->end_y - data->start_y) * current; |
| 682 | |
Ucan, Emre \(ADITG/SW1\) | e62bfd8 | 2016-03-04 12:50:46 +0000 | [diff] [blame] | 683 | ivi_layout_layer_set_destination_rectangle(layer, dest_x, dest_y, |
| 684 | layer->prop.dest_width, layer->prop.dest_height); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static void |
| 688 | transition_move_layer_destroy(struct ivi_layout_transition *transition) |
| 689 | { |
| 690 | struct move_layer_data *data = transition->private_data; |
| 691 | |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 692 | if (data->destroy_func) |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 693 | data->destroy_func(transition->user_data); |
| 694 | |
| 695 | free(data); |
| 696 | transition->private_data = NULL; |
| 697 | } |
| 698 | |
| 699 | static int32_t |
| 700 | is_transition_move_layer_func(struct move_layer_data *data, |
| 701 | struct ivi_layout_layer *layer) |
| 702 | { |
| 703 | return data->layer == layer; |
| 704 | } |
| 705 | |
| 706 | |
| 707 | static struct ivi_layout_transition * |
| 708 | create_move_layer_transition( |
| 709 | struct ivi_layout_layer *layer, |
| 710 | int32_t start_x, int32_t start_y, |
| 711 | int32_t end_x, int32_t end_y, |
| 712 | void *user_data, |
| 713 | ivi_layout_transition_destroy_user_func destroy_user_func, |
| 714 | uint32_t duration) |
| 715 | { |
Carlos Olmedo Escobar | 703f502 | 2015-03-02 13:24:36 +0100 | [diff] [blame] | 716 | struct ivi_layout_transition *transition; |
| 717 | struct move_layer_data *data; |
| 718 | |
| 719 | transition = create_layout_transition(); |
Carlos Olmedo Escobar | e82ba53 | 2015-01-17 19:43:02 +0100 | [diff] [blame] | 720 | if (transition == NULL) |
| 721 | return NULL; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 722 | |
Carlos Olmedo Escobar | 703f502 | 2015-03-02 13:24:36 +0100 | [diff] [blame] | 723 | data = malloc(sizeof(*data)); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 724 | if (data == NULL) { |
| 725 | weston_log("%s: memory allocation fails\n", __func__); |
Lucas Tanure | 9af0017 | 2015-09-21 11:24:35 -0300 | [diff] [blame] | 726 | free(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 727 | return NULL; |
| 728 | } |
| 729 | |
| 730 | transition->type = IVI_LAYOUT_TRANSITION_LAYER_MOVE; |
| 731 | transition->is_transition_func = (ivi_layout_is_transition_func)is_transition_move_layer_func; |
| 732 | |
| 733 | transition->frame_func = transition_move_layer_user_frame; |
| 734 | transition->destroy_func = transition_move_layer_destroy; |
| 735 | transition->private_data = data; |
| 736 | transition->user_data = user_data; |
| 737 | |
| 738 | if (duration != 0) |
| 739 | transition->time_duration = duration; |
| 740 | |
| 741 | data->layer = layer; |
| 742 | data->start_x = start_x; |
| 743 | data->start_y = start_y; |
| 744 | data->end_x = end_x; |
| 745 | data->end_y = end_y; |
| 746 | data->destroy_func = destroy_user_func; |
| 747 | |
| 748 | return transition; |
| 749 | } |
| 750 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 751 | void |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 752 | ivi_layout_transition_move_layer(struct ivi_layout_layer *layer, |
| 753 | int32_t dest_x, int32_t dest_y, |
| 754 | uint32_t duration) |
| 755 | { |
Ucan, Emre \(ADITG/SW1\) | dfc2d76 | 2016-03-04 12:50:24 +0000 | [diff] [blame] | 756 | int32_t start_pos_x = layer->prop.dest_x; |
| 757 | int32_t start_pos_y = layer->prop.dest_y; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 758 | struct ivi_layout_transition *transition = NULL; |
| 759 | |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 760 | transition = create_move_layer_transition( |
| 761 | layer, |
| 762 | start_pos_x, start_pos_y, |
| 763 | dest_x, dest_y, |
| 764 | NULL, NULL, |
| 765 | duration); |
| 766 | |
Lucas Tanure | c8dcd16 | 2015-09-23 10:33:21 -0300 | [diff] [blame] | 767 | if (transition && layout_transition_register(transition)) |
| 768 | return; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 769 | |
Lucas Tanure | c8dcd16 | 2015-09-23 10:33:21 -0300 | [diff] [blame] | 770 | free(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 771 | } |
| 772 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 773 | void |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 774 | ivi_layout_transition_move_layer_cancel(struct ivi_layout_layer *layer) |
| 775 | { |
| 776 | struct ivi_layout_transition *transition = |
| 777 | get_transition_from_type_and_id( |
| 778 | IVI_LAYOUT_TRANSITION_LAYER_MOVE, |
| 779 | layer); |
| 780 | if (transition) { |
| 781 | layout_transition_destroy(transition); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /* fade layer transition */ |
| 786 | struct fade_layer_data { |
| 787 | struct ivi_layout_layer *layer; |
| 788 | uint32_t is_fade_in; |
| 789 | double start_alpha; |
| 790 | double end_alpha; |
| 791 | ivi_layout_transition_destroy_user_func destroy_func; |
| 792 | }; |
| 793 | |
| 794 | static void |
| 795 | transition_fade_layer_destroy(struct ivi_layout_transition *transition) |
| 796 | { |
| 797 | struct fade_layer_data *data = transition->private_data; |
| 798 | transition->private_data = NULL; |
| 799 | |
| 800 | free(data); |
| 801 | } |
| 802 | |
| 803 | static void |
| 804 | transition_fade_layer_user_frame(struct ivi_layout_transition *transition) |
| 805 | { |
| 806 | double current = time_to_nowpos(transition); |
| 807 | struct fade_layer_data *data = transition->private_data; |
| 808 | double alpha = data->start_alpha + |
| 809 | (data->end_alpha - data->start_alpha) * current; |
| 810 | wl_fixed_t fixed_alpha = wl_fixed_from_double(alpha); |
| 811 | |
| 812 | int32_t is_done = transition->is_done; |
| 813 | bool is_visible = !is_done || data->is_fade_in; |
| 814 | |
| 815 | ivi_layout_layer_set_opacity(data->layer, fixed_alpha); |
| 816 | ivi_layout_layer_set_visibility(data->layer, is_visible); |
| 817 | } |
| 818 | |
| 819 | static int32_t |
| 820 | is_transition_fade_layer_func(struct fade_layer_data *data, |
| 821 | struct ivi_layout_layer *layer) |
| 822 | { |
| 823 | return data->layer == layer; |
| 824 | } |
| 825 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 826 | void |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 827 | ivi_layout_transition_fade_layer( |
| 828 | struct ivi_layout_layer *layer, |
| 829 | uint32_t is_fade_in, |
| 830 | double start_alpha, double end_alpha, |
| 831 | void* user_data, |
| 832 | ivi_layout_transition_destroy_user_func destroy_func, |
| 833 | uint32_t duration) |
| 834 | { |
| 835 | struct ivi_layout_transition *transition; |
| 836 | struct fade_layer_data *data = NULL; |
| 837 | wl_fixed_t fixed_opacity = 0.0; |
| 838 | double now_opacity = 0.0; |
| 839 | double remain = 0.0; |
| 840 | |
| 841 | transition = get_transition_from_type_and_id( |
| 842 | IVI_LAYOUT_TRANSITION_LAYER_FADE, |
| 843 | layer); |
| 844 | if (transition) { |
| 845 | /* transition update */ |
| 846 | data = transition->private_data; |
| 847 | |
| 848 | /* FIXME */ |
Ucan, Emre \(ADITG/SW1\) | c3aee1f | 2016-03-04 12:50:16 +0000 | [diff] [blame] | 849 | fixed_opacity = layer->prop.opacity; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 850 | now_opacity = wl_fixed_to_double(fixed_opacity); |
| 851 | remain = 0.0; |
| 852 | |
| 853 | data->is_fade_in = is_fade_in; |
| 854 | data->start_alpha = now_opacity; |
| 855 | data->end_alpha = end_alpha; |
| 856 | |
| 857 | remain = is_fade_in? 1.0 - now_opacity : now_opacity; |
| 858 | transition->time_start = 0; |
| 859 | transition->time_elapsed = 0; |
| 860 | transition->time_duration = duration * remain; |
| 861 | |
| 862 | return; |
| 863 | } |
| 864 | |
| 865 | transition = create_layout_transition(); |
Carlos Olmedo Escobar | e82ba53 | 2015-01-17 19:43:02 +0100 | [diff] [blame] | 866 | if (transition == NULL) |
| 867 | return; |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 868 | |
Carlos Olmedo Escobar | e82ba53 | 2015-01-17 19:43:02 +0100 | [diff] [blame] | 869 | data = malloc(sizeof(*data)); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 870 | if (data == NULL) { |
| 871 | weston_log("%s: memory allocation fails\n", __func__); |
Lucas Tanure | c8dcd16 | 2015-09-23 10:33:21 -0300 | [diff] [blame] | 872 | free(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 873 | return; |
| 874 | } |
| 875 | |
| 876 | transition->type = IVI_LAYOUT_TRANSITION_LAYER_FADE; |
| 877 | transition->is_transition_func = (ivi_layout_is_transition_func)is_transition_fade_layer_func; |
| 878 | |
| 879 | transition->private_data = data; |
| 880 | transition->user_data = user_data; |
| 881 | |
| 882 | transition->frame_func = transition_fade_layer_user_frame; |
| 883 | transition->destroy_func = transition_fade_layer_destroy; |
| 884 | |
| 885 | if (duration != 0) |
| 886 | transition->time_duration = duration; |
| 887 | |
| 888 | data->layer = layer; |
| 889 | data->is_fade_in = is_fade_in; |
| 890 | data->start_alpha = start_alpha; |
| 891 | data->end_alpha = end_alpha; |
| 892 | data->destroy_func = destroy_func; |
| 893 | |
Lucas Tanure | c8dcd16 | 2015-09-23 10:33:21 -0300 | [diff] [blame] | 894 | if (!layout_transition_register(transition)) |
| 895 | layout_transition_destroy(transition); |
Nobuhiko Tanibata | 6f9df65 | 2014-11-27 13:22:00 +0900 | [diff] [blame] | 896 | |
| 897 | return; |
| 898 | } |
| 899 | |