scroll_effect.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*********************
  7. * INCLUDES
  8. *********************/
  9. #include <math.h>
  10. #include <os_common_api.h>
  11. #include "effects_inner.h"
  12. /*********************
  13. * DEFINES
  14. *********************/
  15. /**
  16. * Camera distance from screen
  17. *
  18. * set 0.0f for orthogonal projection)
  19. */
  20. #define CAMERA_DISTANCE 512.0f
  21. /**
  22. * SCROLL_EFFECT_SCALE.
  23. */
  24. /* can see the cube outside or inside during rotation */
  25. #define CUBE_OUT_ROTATE 0
  26. /* angles between the 2 normal of buffer planes, range (0, 90] */
  27. #if CUBE_OUT_ROTATE
  28. # define CUBE_ANGLE 60
  29. #else
  30. # define CUBE_ANGLE 90
  31. #endif
  32. #define CUBE_ALPHA 0xFF
  33. /**
  34. * SCROLL_EFFECT_FAN.
  35. */
  36. /* angles between the 2 normal of buffers, range (0, 90] */
  37. #define FAN_ANGLE 30
  38. /**
  39. * SCROLL_EFFECT_SCALE.
  40. */
  41. /* minimum scale value, range (0.0, 1.0) */
  42. #define SCALE_MIN 0.5f
  43. /**********************
  44. * TYPEDEFS
  45. **********************/
  46. /**********************
  47. * STATIC PROTOTYPES
  48. **********************/
  49. #ifdef CONFIG_VG_LITE
  50. static void _vglite_scroll_effect_handle(const ui_transform_param_t *param, int *trans_end);
  51. #endif
  52. /**********************
  53. * STATIC VARIABLES
  54. **********************/
  55. __unused static scroll_effect_ctx_t scroll_ctx = {
  56. .type = UI_SCROLL_EFFECT_NONE,
  57. #ifdef CONFIG_VG_LITE
  58. .opt_round_screen_overlapped = false,
  59. .camera_distance = CAMERA_DISTANCE,
  60. .cube = {
  61. .out = CUBE_OUT_ROTATE,
  62. .angle = CUBE_ANGLE,
  63. .alpha = CUBE_ALPHA,
  64. },
  65. .fan = {
  66. .angle = FAN_ANGLE,
  67. },
  68. .scale = {
  69. .min_ratio = SCALE_MIN,
  70. },
  71. #endif
  72. };
  73. /**********************
  74. * GLOBAL FUNCTIONS
  75. **********************/
  76. int ui_scroll_effect_set_type(uint8_t type)
  77. {
  78. if (type >= NUM_UI_SCROLL_EFFECTS)
  79. return -EINVAL;
  80. #ifdef CONFIG_VG_LITE
  81. scroll_ctx.type = type;
  82. if (type != UI_SCROLL_EFFECT_NONE) {
  83. ui_manager_set_transform_scroll_callback(_vglite_scroll_effect_handle);
  84. } else {
  85. ui_manager_set_transform_scroll_callback(NULL);
  86. }
  87. return 0;
  88. #else
  89. return -ENOSYS;
  90. #endif /* CONFIG_VG_LITE */
  91. }
  92. /**********************
  93. * STATIC FUNCTIONS
  94. **********************/
  95. #ifdef CONFIG_VG_LITE
  96. static void _vglite_init_effect_param(const ui_transform_param_t *param)
  97. {
  98. if (!scroll_ctx.param_inited) {
  99. scroll_ctx.param_inited = true;
  100. if (param->rotation == 0 || param->rotation == 180) {
  101. scroll_ctx.fan.radius = (param->dst->height / 2.0f) +
  102. ((param->dst->width / 2.0f) / tan(RAD(scroll_ctx.fan.angle/2.0f)));
  103. } else {
  104. scroll_ctx.fan.radius = (param->dst->width / 2.0f) +
  105. ((param->dst->height / 2.0f) / tan(RAD(scroll_ctx.fan.angle/2.0f)));
  106. }
  107. scroll_ctx.fan.pivot_x = param->dst->width / 2.0f;
  108. scroll_ctx.fan.pivot_y = param->dst->height / 2.0f;
  109. if (param->rotation == 0) {
  110. scroll_ctx.fan.pivot_y += scroll_ctx.fan.radius;
  111. } else if (param->rotation == 90) {
  112. scroll_ctx.fan.pivot_x -= scroll_ctx.fan.radius;
  113. } else if (param->rotation == 180) {
  114. scroll_ctx.fan.pivot_y -= scroll_ctx.fan.radius;
  115. } else /* (param->rotation == 270) */ {
  116. scroll_ctx.fan.pivot_x += scroll_ctx.fan.radius;
  117. }
  118. if (param->rotation == 0 || param->rotation == 180) {
  119. scroll_ctx.cube.radius = (param->dst->width / 2.0f) / tan(RAD(scroll_ctx.cube.angle/2.0f));
  120. } else {
  121. scroll_ctx.cube.radius = (param->dst->height / 2.0f) / tan(RAD(scroll_ctx.cube.angle/2.0f));
  122. }
  123. }
  124. }
  125. static void _vglite_scroll_effect_handle(const ui_transform_param_t *param, int *trans_end)
  126. {
  127. os_strace_u32x2(SYS_TRACE_ID_VIEW_SCROLL_EFFECT, scroll_ctx.type, ui_region_get_width(&param->region_old));
  128. _vglite_init_effect_param(param);
  129. switch (scroll_ctx.type) {
  130. case UI_SCROLL_EFFECT_CUBE:
  131. vglite_scroll_proc_cube_effect(&scroll_ctx, param);
  132. break;
  133. case UI_SCROLL_EFFECT_FAN:
  134. vglite_scroll_proc_fan_effect(&scroll_ctx, param);
  135. break;
  136. case UI_SCROLL_EFFECT_PAGE:
  137. vglite_scroll_proc_page_effect(&scroll_ctx, param);
  138. break;
  139. case UI_SCROLL_EFFECT_SCALE:
  140. vglite_scroll_proc_scale_effect(&scroll_ctx, param);
  141. break;
  142. default:
  143. return;
  144. }
  145. os_strace_end_call(SYS_TRACE_ID_VIEW_SCROLL_EFFECT);
  146. }
  147. #endif /* CONFIG_VG_LITE */