Arm-2D  
2D Image Processing Library for Cortex-M Processors
arm_2d_helper_scene.h
1/*
2 * Copyright (C) 2022 Arm Limited or its affiliates. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* ----------------------------------------------------------------------
20 * Project: Arm-2D Library
21 * Title: #include "arm_2d_helper_scene.h"
22 * Description: Public header file for the scene service
23 *
24 * $Date: 23. March 2023
25 * $Revision: V.1.3.12
26 *
27 * Target Processor: Cortex-M cores
28 * -------------------------------------------------------------------- */
29
30#ifndef __ARM_2D_HELPER_SCENE_H__
31#define __ARM_2D_HELPER_SCENE_H__
32
33/*============================ INCLUDES ======================================*/
34#include "arm_2d_helper_pfb.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#if defined(__clang__)
41# pragma clang diagnostic push
42# pragma clang diagnostic ignored "-Wunknown-warning-option"
43# pragma clang diagnostic ignored "-Wreserved-identifier"
44# pragma clang diagnostic ignored "-Wdeclaration-after-statement"
45# pragma clang diagnostic ignored "-Wpadded"
46# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
47#endif
48
49/*!
50 * \addtogroup gHelper 7 Helper Services
51 * @{
52 */
53
54
55/*============================ MACROS ========================================*/
56/*============================ MACROFIED FUNCTIONS ===========================*/
57
58/*!
59 * \brief register / update the evtOnDrawNavigation event handler. You can use
60 * this event to draw an ALWAY-TOP navigation bar or title during switching
61 * period.
62 *
63 * \param[in] __DISP_ADAPTER_PTR the target scene player
64 * \param[in] __DRAW_HANDLER the event handler to draw the navigation bar and/or
65 * titles
66 * \param[in] __USER_TARGET_PTR the address of an user specified object. If it
67 * is NULL, ptThis will be used instead.
68 * \param[in] ... an optional dirty region list for the navigation layer. If
69 * ommited, NULL is used.
70 * \note if the optional dirty region list is omitted and the normal scene
71 * doesn't cover the region of the content in the navigation layer,
72 * you won't see the content.
73 * \return arm_2d_err_t the operation result
74 */
75#define arm_2d_scene_player_register_on_draw_navigation_event_handler( \
76 __SCENE_PLAYER_PTR, \
77 __DRAW_HANDLER, \
78 __USER_TARGET_PTR, \
79 ...) \
80 __arm_2d_scene_player_register_on_draw_navigation_event_handler( \
81 (__SCENE_PLAYER_PTR), \
82 (__DRAW_HANDLER), \
83 (__USER_TARGET_PTR), \
84 (NULL,##__VA_ARGS__))
85
86/*!
87 * \brief configure the scene switching mode
88 *
89 * \param[in] __DISP_ADAPTER_PTR the target scene player
90 * \param[in] __SWITCH_MODE a switching mode object
91 * \param[in] ... an optional configurations for the switching
92 */
93#define arm_2d_scene_player_set_switching_mode(__SCENE_PLAYER_PTR, \
94 __SWITCH_MODE, \
95 ...) \
96 __arm_2d_scene_player_set_switching_mode((__SCENE_PLAYER_PTR), \
97 &(__SWITCH_MODE), \
98 (0,##__VA_ARGS__))
99
100/*!
101 * \brief register / update the evtBeforeSwitching event handler. You can use
102 * this event to prepare next scenes.
103 *
104 * \param[in] ptThis the target scene player
105 * \param[in] fnHandler the event handler
106 * \param[in] ... optional, the address of an user specified object.
107 * \return arm_2d_err_t the operation result
108 */
109#define arm_2d_scene_player_register_before_switching_event_handler( \
110 __SCENE_PLAYER_PTR, \
111 __HANDLER, \
112 ...) \
113 __arm_2d_scene_player_register_before_switching_event_handler( \
114 (__SCENE_PLAYER_PTR), \
115 (__HANDLER), \
116 (NULL,##__VA_ARGS__))
117
118
119/*============================ TYPES =========================================*/
120
121/*!
122 * \brief scene switching mode
123 */
124typedef enum {
125
126 /* valid switching visual effects begin */
127 ARM_2D_SCENE_SWITCH_CFG_NONE = 0, //!< no switching visual effect
128 ARM_2D_SCENE_SWITCH_CFG_USER = 1, //!< user defined switching visual effect
129 ARM_2D_SCENE_SWITCH_CFG_FADE_WHITE = 2, //!< fade in fade out (white)
130 ARM_2D_SCENE_SWITCH_CFG_FADE_BLACK = 3, //!< fade in fade out (black)
135 ARM_2D_SCENE_SWITCH_CFG_ERASE_LEFT = 8, //!< erase to the right
137 ARM_2D_SCENE_SWITCH_CFG_ERASE_UP, //!< erase to the top
138 ARM_2D_SCENE_SWITCH_CFG_ERASE_DOWN, //!< erase to the bottom
139
140 /* valid switching visual effects end */
141 __ARM_2D_SCENE_SWITCH_CFG_VALID, //!< For internal user only
142
143 ARM_2D_SCENE_SWITCH_CFG_IGNORE_OLD_BG = _BV(8), //!< ignore the background of the old scene
144 ARM_2D_SCENE_SWITCH_CFG_IGNORE_OLD_SCEBE = _BV(9), //!< ignore the old scene
145 ARM_2D_SCENE_SWITCH_CFG_IGNORE_NEW_BG = _BV(10), //!< ignore the background of the new scene
146 ARM_2D_SCENE_SWITCH_CFG_IGNORE_NEW_SCEBE = _BV(11), //!< ignore the new scene
147
148 ARM_2D_SCENE_SWITCH_CFG_DEFAULT_BG_WHITE = 0 << 12, //!< use white as default background
149 ARM_2D_SCENE_SWITCH_CFG_DEFAULT_BG_BLACK = 1 << 12, //!< use black as default background
150 ARM_2D_SCENE_SWITCH_CFG_DEFAULT_BG_USER = 2 << 12, //!< use user defined default background
151
152 __ARM_2D_SCENE_SWTICH_CFG_IGNORE_msk = 0x0F << 8, //!< For internal user only
153 __ARM_2D_SCENE_SWTICH_CFG_IGNORE_pos = 8, //!< For internal user only
154 __ARM_2D_SCENE_SWTICH_CFG_DEFAULT_BG_msk = 3 << 12, //!< For internal user only
155 __ARM_2D_SCENE_SWTICH_CFG_DEFAULT_BG_pos = 12, //!< For internal user only
156
158
159
160
161/*!
162 * \brief an internal data structure for scene switching
163 *
164 * \note Please do not use it.
165 */
167
168 struct {
169 uint8_t chMode; //!< the switch visual effect
170 uint8_t bIgnoreOldSceneBG : 1; //!< when set, ignore the background of the old scene
171 uint8_t bIgnoreOldScene : 1; //!< when set, ignore the old scene
172 uint8_t bIgnoreNewSceneBG : 1; //!< when set, ignore the background of the new scene
173 uint8_t bIgnoreNewScene : 1; //!< when set, ignore the new scene
174 uint8_t u2DefaultBG : 2; //!< the default background
175 uint8_t : 2;
176 } Feature;
177 uint16_t hwSetting; //!< the setting value
178
180
181
182/*!
183 * \brief scene switching mode descriptor
184 */
185typedef const struct {
186 uint8_t chEffects; //!< switching effects
187 arm_2d_helper_draw_handler_t *fnSwitchDrawer; //!< switching algorithm
189
190
192
193/*!
194 * \brief a class for describing scenes which are the combination of a
195 * background and a foreground with a dirty-region-list support
196 *
197 */
198typedef struct arm_2d_scene_t arm_2d_scene_t;
200 arm_2d_scene_t *ptNext; //!< next scene
201 arm_2d_scene_player_t *ptPlayer; //!< points to the host scene player
202 arm_2d_region_list_item_t *ptDirtyRegion; //!< dirty region list for the foreground
203 arm_2d_helper_draw_handler_t *fnBackground; //!< the function pointer for the background
204 arm_2d_helper_draw_handler_t *fnScene; //!< the function pointer for the foreground
205 void (*fnOnBGStart)(arm_2d_scene_t *ptThis); //!< on-start-drawing-background event handler
206 void (*fnOnBGComplete)(arm_2d_scene_t *ptThis); //!< on-complete-drawing-background event handler
207 void (*fnOnFrameStart)(arm_2d_scene_t *ptThis); //!< on-frame-start event handler
208 void (*fnOnFrameCPL)(arm_2d_scene_t *ptThis); //!< on-frame-complete event handler
209
210 /*!
211 * \note We can use this event to initialize/generate the new(next) scene
212 */
213 void (*fnBeforeSwitchOut)(arm_2d_scene_t *ptThis); //!< before-scene-switch-out event handler
214
215 /*!
216 * \note We use fnDepose to free the resources
217 */
218 void (*fnDepose)(arm_2d_scene_t *ptThis); //!< on-scene-depose event handler
219 struct {
220 uint8_t bOnSwitchingIgnoreBG : 1; //!< ignore background during switching period
221 uint8_t bOnSwitchingIgnoreScene : 1; //!< ignore forground during switching period
222 };
223};
224
225
226/*!
227 * \brief the scene player event handler
228 *
229 * \param[in] pTarget a user attached target address
230 * \param[in] ptPlayer the scene player
231 * \param[in] ptScene the old scene that is to be switched out
232 */
234 void *pTarget,
235 arm_2d_scene_player_t *ptPlayer,
236 arm_2d_scene_t *ptScene);
237
238/*!
239 * \brief on low level render event
240 */
243 void *pTarget; //!< user attached target
245
246/*!
247 * \brief a class to manage scenes
248 *
249 */
251 inherit(arm_2d_helper_pfb_t); //!< inherit from arm_2d_helper_pfb_t
252
253 ARM_PRIVATE(
254 struct {
255 arm_2d_scene_t *ptHead; //!< points to the head of the FIFO
256 arm_2d_scene_t *ptTail; //!< points to the tail of the FIFO
257 } SceneFIFO; //!< Scene FIFO
258
259 struct {
260 uint8_t bNextSceneReq : 1; //!< a flag to request switching-to-the next-scene
261 uint8_t bSwitchCPL : 1; //!< indication of scene switching completion
262 uint8_t bUpdateBG : 1; //!< update the background of the current scene
263 uint8_t : 5;
264 uint8_t chState; //!< the state of the FSM used by runtime.
265 } Runtime; //!< scene player runtime
266
267 struct {
268 arm_2d_scene_switch_mode_t *ptMode; //!< the switching mode
269 union {
270 uint8_t chState; //!< FSM state
271 struct {
272 uint8_t chState; //!< FSM state
273 uint8_t chOpacity; //!< opacity of the cover
274 bool bIsFadeBlack; //!< the colour of the cover
275 }Fade;
276 struct {
277 uint8_t chState; //!< FSM state
278 arm_2d_tile_t tSceneWindow; //!< scene window
279 arm_2d_tile_t tTemp; //!< a temp tile
280 int16_t iOffset; //!< erase offset
281 }Erase;
282 struct {
283 uint8_t chState; //!< FSM state
284 arm_2d_tile_t tSceneWindow; //!< scene window
285 int16_t iOffset; //!< slide offset
286 }Slide;
287 };
288 __arm_2d_helper_scene_switch_t tConfig; //!< the switching configuration
289 uint16_t hwPeriod; //!< the switching should finish in specified millisecond
290 int64_t lTimeStamp;
291 }Switch;
292
293 struct {
294 /*!
295 * \note We can use this event to initialize/generate the new(next) scene
296 */
297 arm_2d_scene_before_scene_switching_evt_t evtBeforeSwitching; //!< before-scene-switch-out event handler
298 } Events;
300};
301
302/*============================ GLOBAL VARIABLES ==============================*/
303
304extern
305arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_NONE;
306
307extern
308arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_USER;
309
310extern
311arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_FADE_WHITE;
312
313extern
314arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_FADE_BLACK;
315
316extern
317arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_SLIDE_LEFT;
318
319extern
320arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_SLIDE_RIGHT;
321
322extern
323arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_SLIDE_UP;
324
325extern
326arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_SLIDE_DOWN;
327
328extern
329arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_ERASE_LEFT;
330
331extern
332arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_ERASE_RIGHT;
333
334extern
335arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_ERASE_UP;
336
337extern
338arm_2d_scene_switch_mode_t ARM_2D_SCENE_SWITCH_MODE_ERASE_DOWN;
339
340/*============================ LOCAL VARIABLES ===============================*/
341/*============================ PROTOTYPES ====================================*/
342
343/*!
344 * \brief flush the scene FIFO
345 *
346 * \param[in] ptThis the target scene player
347 */
348extern
349ARM_NONNULL(1)
351
352/*!
353 * \brief append a set of scenes to a scene player
354 *
355 * \param[in] ptThis the target scene player
356 * \param[in] ptScenes a scene array
357 * \param[in] hwCount the number of scenes in the array
358 */
359extern
360ARM_NONNULL(1)
362 arm_2d_scene_t *ptScenes,
363 int_fast16_t hwCount);
364
365/*!
366 * \brief request updating the background of the current scene
367 * \param[in] ptThis the target scene player
368 */
369ARM_NONNULL(1)
371
372/*!
373 * \brief request switching to the next scene safely
374 *
375 * \param[in] ptThis the target scene player
376 *
377 * \note Once received a request, the scene player will only switch to the
378 * next scene at the end of a frame.
379 */
380extern
381ARM_NONNULL(1)
383
384/*!
385 * \brief configure the scene switching mode
386 *
387 * \param[in] ptThis the target scene player
388 * \param[in] ptMode a switching mode object
389 * \param[in] hwSettings configurations for the switching
390 */
391extern
392ARM_NONNULL(1)
395 uint16_t hwSettings);
396
397/*!
398 * \brief read the current scene switching mode
399 *
400 * \param[in] ptThis the target scene player
401 * \return uint16_t the current setting value for the scene switching mode
402 */
403extern
404ARM_NONNULL(1)
406
407/*!
408 * \brief configure the scene switching period
409 *
410 * \param[in] ptThis the target scene player
411 * \param[in] hwMS period in millisecond
412 */
413extern
414ARM_NONNULL(1)
416 uint_fast16_t hwMS);
417
418
419/*!
420 * \brief register / update the evtOnDrawNavigation event handler. You can use
421 * this event to draw an ALWAY-TOP navigation bar or title during switching
422 * period.
423 *
424 * \param[in] ptThis the target scene player
425 * \param[in] fnHandler the event handler to draw the navigation bar and/or titles
426 * \param[in] pTarget the address of an user specified object. If it is NULL,
427 * ptThis will be used instead.
428 * \param[in] ptDirtyRegions a dirty region list for the navigation layer.
429 * \note if ptDirtyRegions is NULL and the normal scene doesn't cover the region
430 * of the content in the navigation layer, you won't see the content.
431 * \return arm_2d_err_t the operation result
432 */
433extern
434ARM_NONNULL(1)
436 arm_2d_scene_player_t *ptThis,
437 arm_2d_helper_draw_handler_t *fnHandler,
438 void *pTarget,
439 arm_2d_region_list_item_t *ptDirtyRegions);
440
441/*!
442 * \brief register / update the evtBeforeSwitching event handler. You can use
443 * this event to prepare next scenes.
444 *
445 * \param[in] ptThis the target scene player
446 * \param[in] fnHandler the event handler
447 * \param[in] pTarget the address of an user specified object.
448 * \return arm_2d_err_t the operation result
449 */
450extern
451ARM_NONNULL(1)
453 arm_2d_scene_player_t *ptThis,
455 void *pTarget
456 );
457
458/*!
459 * \brief the scene player task function
460 *
461 * \param[in] ptThis the target scene player
462 *
463 * \note the event sequence of a scene:
464 * 1. when fnBackground is valid
465 * - invoke fnOnBGStart when it is valid
466 * - invoke fnBackground
467 * - invoke fnOnBGComplete when it is valid
468 * 2. invoke fnOnFrameStart when it is valid
469 * 3. invoke fnScene
470 * 4. invoke fnOnFrameCPL when it is valid
471 * 5. Check bNextSceneReq
472 * - false (0), go back to step 2
473 * - true, invoke fnDepose when it is valid and switch to the next scene
474 *
475 */
476extern
477ARM_NONNULL(1)
479
480/*! @} */
481
482#if defined(__clang__)
483# pragma clang diagnostic pop
484#endif
485
486#ifdef __cplusplus
487}
488#endif
489
490#endif