1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Graphic 18 * @{ 19 * 20 * @brief Defines a lightweight graphics system that provides basic UI and container views, 21 * including buttons, images, labels, lists, animators, scroll views, swipe views, and layouts. 22 * This system also provides the Design for X (DFX) capability to implement features such as 23 * view rendering, animation, and input event distribution. 24 * 25 * @since 1.0 26 * @version 1.0 27 */ 28 29 /** 30 * @file graphic_config.h 31 * 32 * @brief Provides configuration items required for graphics. 33 * 34 * @since 1.0 35 * @version 1.0 36 */ 37 38 #ifndef GRAPHIC_LITE_GRAPHIC_CONFIG_H 39 #define GRAPHIC_LITE_GRAPHIC_CONFIG_H 40 41 #if (ENABLE_OHOS_GRAPHIC_UTILS_PRODUCT_CONFIG == 1) 42 #include "product_graphic_lite_config.h" 43 #endif 44 45 #include "gfx_utils/graphic_types.h" 46 47 namespace OHOS { 48 /** 49 * Defines three graphics library versions: lightweight, standard, and extended versions. 50 * The three versions have different requirements on the memory and hardware. 51 * The standard version is enabled by default. 52 * 53 * The macros of the versions are defined as follows: 54 * Name | Version Description 55 * ------------------- | ---------- 56 * VERSION_LITE | Lightweight version 57 * VERSION_STANDARD | Standard version 58 * VERSION_EXTENDED | Extended version 59 */ 60 #ifdef __LITEOS_M__ 61 #define VERSION_LITE 62 #elif defined _WIN32 || defined __APPLE__ 63 #define VERSION_LITE 64 #else 65 #define VERSION_STANDARD 66 #endif 67 68 /* Defines some configurations and their default values on LiteOS and other system platforms. */ 69 #ifndef ENABLE_FIXED_POINT 70 #define ENABLE_FIXED_POINT 1 71 #endif 72 73 #ifdef __LITEOS_M__ 74 /** 75 * @brief Font shaping, which is disabled by default on LiteOS. 76 * Cannot take effect without ENABLE_ICU. 77 */ 78 #ifndef ENABLE_SHAPING 79 #define ENABLE_SHAPING 0 80 #endif 81 /** 82 * @brief Advanced algorithm for line breaks, which is disabled by default on LiteOS. 83 */ 84 #ifndef ENABLE_ICU 85 #define ENABLE_ICU 0 86 #endif 87 /** 88 * @brief Multi-Font type, which is disabled by default on LiteOS. 89 */ 90 #ifndef ENABLE_MULTI_FONT 91 #define ENABLE_MULTI_FONT 0 92 #endif 93 /** 94 * @brief Multi-window, which does not take effect on LiteOS. 95 */ 96 #ifndef ENABLE_WINDOW 97 #define ENABLE_WINDOW 0 98 #endif 99 /** 100 * @brief Display buffer for rendering data refresh, which is disabled by default on LiteOS. 101 */ 102 #ifndef ENABLE_FRAME_BUFFER 103 #define ENABLE_FRAME_BUFFER 1 104 #endif 105 /** 106 * @brief Vector type font, which is enabled by default on LiteOS. 107 */ 108 #ifndef ENABLE_VECTOR_FONT 109 #define ENABLE_VECTOR_FONT 1 110 #endif 111 /** 112 * @brief Bitmap type font, which is disabled by default on LiteOS. 113 */ 114 #ifndef ENABLE_BITMAP_FONT 115 #define ENABLE_BITMAP_FONT 0 116 #endif 117 /** 118 * @brief Static Bitmap type font, which is disabled by default on LiteOS. 119 */ 120 #ifndef ENABLE_STATIC_FONT 121 #define ENABLE_STATIC_FONT 0 122 #endif 123 124 /** 125 * @brief JPEG and PNG, which is disabled by default on LiteOS. 126 */ 127 #ifndef ENABLE_JPEG_AND_PNG 128 #define ENABLE_JPEG_AND_PNG 0 129 #endif 130 131 /** 132 * @brief GIF, which is disabled by default on LiteOS. 133 */ 134 #ifndef ENABLE_GIF 135 #define ENABLE_GIF 0 136 #endif 137 138 /** 139 * @brief Fully rectangle render everytime, which is disabled by default on LiteOS. 140 */ 141 #ifndef FULLY_RENDER 142 #define FULLY_RENDER 0 143 #endif 144 /** 145 * @brief Graphics rendering hardware acceleration, which is enabled by default on LiteOS. 146 */ 147 #ifndef ENABLE_HARDWARE_ACCELERATION 148 #define ENABLE_HARDWARE_ACCELERATION 1 149 #endif 150 /** 151 * @brief Graphics rendering hardware acceleration for text, which is disabled by default on LiteOS. 152 */ 153 #ifndef ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 154 #define ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 0 155 #endif 156 /** 157 * @brief Graphics rendering accelerated by gfx_engines, which is disabled by default on LiteOS. 158 */ 159 #ifndef ENABLE_GFX_ENGINES 160 #define ENABLE_GFX_ENGINES 0 161 #endif 162 /** 163 * @brief ARM NEON ability, which is disabled by default on LiteOS. 164 */ 165 #ifndef ENABLE_ARM_NEON 166 #define ENABLE_ARM_NEON 0 167 #endif 168 #elif defined _WIN32 || defined __APPLE__ 169 /** 170 * @brief Multi-window, which is disabled by default on WIN32. 171 */ 172 #ifndef ENABLE_WINDOW 173 #define ENABLE_WINDOW 0 174 #endif 175 /** 176 * @brief Display buffer for rendering data refresh, which is disabled by default on WIN32. 177 */ 178 #ifndef ENABLE_FRAME_BUFFER 179 #define ENABLE_FRAME_BUFFER 0 180 #endif 181 182 #ifndef ENABLE_JPEG_AND_PNG 183 #define ENABLE_JPEG_AND_PNG 1 184 #endif 185 /** 186 * @brief ARM NEON ability, which is disabled by default on WIN32. 187 */ 188 #ifndef ENABLE_ARM_NEON 189 #define ENABLE_ARM_NEON 0 190 #endif 191 /** 192 * @brief Graphics rendering hardware acceleration, which is disabled by default on WIN32. 193 */ 194 #ifndef ENABLE_HARDWARE_ACCELERATION 195 #define ENABLE_HARDWARE_ACCELERATION 0 196 #endif 197 /** 198 * @brief Graphics rendering hardware acceleration for text, which is disabled by default on WIN32. 199 */ 200 #ifndef ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 201 #define ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 0 202 #endif 203 /** 204 * @brief Graphics rendering accelerated by gfx_engines, which is disabled by default on WIN32. 205 */ 206 #ifndef ENABLE_GFX_ENGINES 207 #define ENABLE_GFX_ENGINES 0 208 #endif 209 210 #else 211 /** 212 * @brief Multi-window, which is enabled by default on other platforms. 213 */ 214 #ifndef ENABLE_WINDOW 215 #define ENABLE_WINDOW 1 216 #endif 217 /** 218 * @brief Display buffer for rendering data refresh, which is disabled by default on other platforms. 219 */ 220 #ifndef ENABLE_FRAME_BUFFER 221 #define ENABLE_FRAME_BUFFER 0 222 #endif 223 224 #ifndef ENABLE_JPEG_AND_PNG 225 #define ENABLE_JPEG_AND_PNG 1 226 #endif 227 /** 228 * @brief ARM NEON ability, which is enabled by default on other platforms. 229 */ 230 #ifndef ENABLE_ARM_NEON 231 #define ENABLE_ARM_NEON 1 232 #endif 233 /** 234 * @brief Graphics rendering hardware acceleration, which is disabled by default on other platforms. 235 */ 236 #ifndef ENABLE_HARDWARE_ACCELERATION 237 #define ENABLE_HARDWARE_ACCELERATION 0 238 #endif 239 /** 240 * @brief Graphics rendering hardware acceleration for text, which is disabled by default on other platforms. 241 */ 242 #ifndef ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 243 #define ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 0 244 #endif 245 /** 246 * @brief Graphics rendering accelerated by gfx_engines, which is enabled by default on other platforms. 247 */ 248 #ifndef ENABLE_GFX_ENGINES 249 #define ENABLE_GFX_ENGINES 1 250 #endif // ENABLE_GFX_ENGINES 251 #endif 252 253 #ifndef ENABLE_ROTATE_INPUT 254 #define ENABLE_ROTATE_INPUT 1 255 #endif 256 257 #ifndef ENABLE_VIBRATOR 258 #define ENABLE_VIBRATOR 1 259 #endif 260 261 #ifndef ENABLE_FOCUS_MANAGER 262 #define ENABLE_FOCUS_MANAGER 1 263 #endif 264 265 /** 266 * @brief Graphics local rendering, which is disabled by default. 267 */ 268 #ifndef LOCAL_RENDER 269 #define LOCAL_RENDER 0 270 #endif 271 272 /** 273 * @brief Actually use ARM NEON optimization. 274 * __ARM_NEON__ and __ARM_NEON are set by the compiler according to the compilation option -mfpu=neon 275 */ 276 #if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && ENABLE_ARM_NEON == 1 277 #define ARM_NEON_OPT 278 #endif 279 280 /** 281 * @brief Graphics bottom-layer RGBA, which is enabled by default. 282 */ 283 #ifndef ENABLE_BUFFER_RGBA 284 #define ENABLE_BUFFER_RGBA 1 285 #endif 286 /** 287 * @brief Debug mode, which is disabled by default. 288 */ 289 #ifndef ENABLE_DEBUG 290 #define ENABLE_DEBUG 1 291 #endif 292 /** 293 * @brief Memory hook, which is enabled by default. The system memory allocation is taken over after it is enabled. 294 */ 295 #ifndef ENABLE_MEMORY_HOOKS 296 #define ENABLE_MEMORY_HOOKS 0 297 #endif 298 /** 299 * @brief Function for monitoring the image refresh frame rate, which is disabled by default. 300 */ 301 #ifndef ENABLE_FPS_SUPPORT 302 #define ENABLE_FPS_SUPPORT 0 303 #endif 304 /** 305 * @brief Anti-aliasing, which is enabled by default. 306 */ 307 #ifndef ENABLE_ANTIALIAS 308 #define ENABLE_ANTIALIAS 1 309 #endif 310 /** 311 * @brief Rectangle anti-aliasing, which is disabled by default. 312 */ 313 #ifndef ENABLE_RECT_ANTIALIAS 314 #define ENABLE_RECT_ANTIALIAS 0 315 #endif 316 /** 317 * @brief Font color mode, which is disabled by default. 318 * After it is enabled, the font color mode is set to <b>4</b> to accelerate font rendering. 319 */ 320 #ifndef ENABLE_SPEC_FONT 321 #define ENABLE_SPEC_FONT 0 322 #endif 323 /** 324 * @brief Log function of a graphics subsystem, which is disabled by default 325 */ 326 #ifndef ENABLE_GRAPHIC_LOG 327 #define ENABLE_GRAPHIC_LOG 0 328 #endif 329 /** 330 * @brief Performance tracking for debugging, which is disabled by default. 331 */ 332 #ifndef ENABLE_DEBUG_PERFORMANCE_TRACE 333 #define ENABLE_DEBUG_PERFORMANCE_TRACE 0 334 #endif 335 /** 336 * @brief Function for receiving input events in screen-off mode, which is disabled by default. 337 */ 338 #ifndef ENABLE_AOD 339 #define ENABLE_AOD 0 340 #endif 341 342 /** 343 * @brief Defines the log level. A smaller value indicates a higher priority. 344 * Logs whose priorities are higher than a specified level can be recorded. 345 * Log levels: 346 * NONE: disabling logs 347 * FATAL: fatal level 348 * ERROR: error level 349 * WARN: warning level 350 * INFO: info level 351 * DEBUG: debugging level 352 */ 353 #ifndef GRAPHIC_LOG_LEVEL 354 #define GRAPHIC_LOG_LEVEL 5 355 #endif 356 /** 357 * @brief Defines the color depth of graphics rendering. The default value is <b>32</b> bits. 358 * The value can be <b>16</b> or <b>32</b>. 359 */ 360 #ifndef COLOR_DEPTH 361 #define COLOR_DEPTH 32 362 #endif 363 364 /** 365 * @brief Represents the code number of the layer pixel format. 366 * 0: LAYER_PF_ARGB1555 367 * 1: LAYER_PF_ARGB8888 368 * Other: LAYER_PF_ARGB8888 369 */ 370 #ifndef LAYER_PF_CODE 371 #define LAYER_PF_CODE 1 372 #endif 373 374 #if LAYER_PF_CODE == 0 375 #define LAYER_PF_ARGB1555 376 #elif LAYER_PF_CODE == 1 377 #define LAYER_PF_ARGB8888 378 #else 379 #define LAYER_PF_ARGB8888 380 #endif 381 382 /** 383 * @brief Defines whether the C library math function is supported. 384 * 0: Unsupport 385 * 1: Support 386 */ 387 #ifndef ENABLE_CMATH 388 #define ENABLE_CMATH 1 389 #endif 390 391 /** 392 * @brief Defines the file name of default vector font. 393 */ 394 #if ENABLE_VECTOR_FONT 395 396 #ifndef DEFAULT_VECTOR_FONT_FILENAME 397 #define DEFAULT_VECTOR_FONT_FILENAME "SourceHanSansSC-Regular.otf" 398 #endif // DEFAULT_VECTOR_FONT_FILENAME 399 400 #else // ENABLE_VECTOR_FONT 401 402 #ifndef DEFAULT_VECTOR_FONT_FILENAME 403 #define DEFAULT_VECTOR_FONT_FILENAME "SourceHanSansSC-Regular" 404 #endif // DEFAULT_VECTOR_FONT_FILENAME 405 406 #endif // ENABLE_VECTOR_FONT 407 408 /* Default font size. The default value is <b>18</b>. */ 409 static constexpr uint8_t DEFAULT_VECTOR_FONT_SIZE = 18; 410 411 /* Defines the file name of default line break rule. */ 412 #ifndef DEFAULT_LINE_BREAK_RULE_FILENAME 413 #define DEFAULT_LINE_BREAK_RULE_FILENAME "line_cj.brk" 414 #endif 415 416 /* Defines some configurations and their default values on LiteOS and other system platforms. */ 417 #ifdef __LITEOS_M__ 418 419 /* Resolution width of a graphics display screen. The default value is <b>454</b>. */ 420 #ifndef HORIZONTAL_RESOLUTION 421 #define HORIZONTAL_RESOLUTION 454 422 #endif 423 424 /* Resolution height of a graphics display screen. The default value is <b>454</b>. */ 425 #ifndef VERTICAL_RESOLUTION 426 #define VERTICAL_RESOLUTION 454 427 #endif // VERTICAL_RESOLUTION 428 429 #elif defined _WIN32 || defined __APPLE__ // __LITEOS_M__ 430 431 /* Resolution width of a graphics display screen. The default value is <b>454</b>. */ 432 #ifndef HORIZONTAL_RESOLUTION 433 #define HORIZONTAL_RESOLUTION 960 434 #endif 435 436 /* Resolution height of a graphics display screen. The default value is <b>454</b>. */ 437 #ifndef VERTICAL_RESOLUTION 438 #define VERTICAL_RESOLUTION 480 439 #endif 440 441 #else 442 443 /* Resolution width of a graphics display screen. The default value is <b>960</b>. */ 444 #ifndef HORIZONTAL_RESOLUTION 445 #define HORIZONTAL_RESOLUTION 960 446 #endif 447 448 /* Resolution height of a graphics display screen. The default value is <b>480</b>. */ 449 #ifndef VERTICAL_RESOLUTION 450 #define VERTICAL_RESOLUTION 480 451 #endif 452 453 #endif 454 455 #ifndef VERSION_LITE 456 static constexpr const char* MEDIA_IMAGE_PLAY_CENTER = "/user/data/videoplayer_play_center.png"; 457 static constexpr const char* MEDIA_IMAGE_PLAY = "/user/data/videoplayer_play.png"; 458 static constexpr const char* MEDIA_IMAGE_PAUSE = "/user/data/videoplayer_pause.png"; 459 static constexpr const char* MEDIA_IMAGE_VOLUME = "/user/data/videoplayer_volume.png"; 460 static constexpr const char* MEDIA_IMAGE_MUTE = "/user/data/videoplayer_mute.png"; 461 #endif 462 463 /* Defines some configurations and their default values on LiteOS and other system platforms. */ 464 #if defined QT_COMPILER 465 /* Default file path for DOM tree logs */ 466 static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = ".\\dump_dom_tree.json"; 467 468 /* Default file path for font */ 469 #ifndef VECTOR_FONT_DIR 470 #define VECTOR_FONT_DIR "..\\..\\simulator\\font\\" 471 #endif 472 473 #elif defined _WIN32 // QT_COMPILER 474 475 /* Default file path for DOM tree logs */ 476 static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = ".\\dump_dom_tree.json"; 477 /* Default file path for font */ 478 #ifndef VECTOR_FONT_DIR 479 #define VECTOR_FONT_DIR "..\\..\\tools\\font\\font_tool\\font_tool\\font\\" 480 #endif 481 482 #elif defined __LITEOS_M__ // QT_COMPILER 483 484 /* Default file path for screenshots */ 485 static constexpr const char* DEFAULT_SCREENSHOT_PATH = "user/log/screenshot.bin"; 486 /* Default file path for DOM tree logs */ 487 static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = "user/log/dump_dom_tree.json"; 488 /* Default file path for font */ 489 #ifndef VECTOR_FONT_DIR 490 #define VECTOR_FONT_DIR "/user/data/" 491 #endif 492 493 #else // QT_COMPILER 494 495 /* Default file path for screenshots */ 496 static constexpr const char* DEFAULT_SCREENSHOT_PATH = "/storage/screenshot.bin"; 497 /* Default file path for DOM tree logs */ 498 static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = "/storage/dump_dom_tree.json"; 499 /* Default file path for font */ 500 #ifndef VECTOR_FONT_DIR 501 #define VECTOR_FONT_DIR "/user/data/" 502 #endif 503 504 #endif // QT_COMPILER 505 /* Default task execution period. The default value is <b>16</b> ms. */ 506 static constexpr uint8_t DEFAULT_TASK_PERIOD = 16; 507 /* Window manager execution period. The default value is <b>16</b> ms. */ 508 static constexpr uint8_t WMS_MAIN_TASK_PERIOD = 16; 509 /* Maximum number of cached images. The default value is <b>5</b>. */ 510 #ifndef IMG_CACHE_SIZE 511 #define IMG_CACHE_SIZE 5 512 #endif 513 static constexpr uint8_t INDEV_READ_PERIOD = 10; /* Input event read cycle. The default value is <b>10</b> ms. */ 514 /* Drag distance threshold of a drag event. The default value is <b>10px</b>. */ 515 static constexpr uint8_t INDEV_DRAG_LIMIT = 10; 516 /* Maximum depth of view nesting. The default value is <b>64</b>. */ 517 static constexpr uint8_t COMPONENT_NESTING_DEPTH = 64; 518 /* Long-press event threshold. The default value is <b>1000</b> ms. */ 519 static constexpr uint16_t INDEV_LONG_PRESS_TIME = 1000; 520 /* Delay for reporting a press event on a draggable object. The default value is <b>100</b> ms. */ 521 static constexpr uint16_t INDEV_PRESS_TIME_IN_DRAG = 100; 522 /* Maximum number of bytes in a text that can be continuously displayed. The default value is <b>4096</b> bytes. */ 523 static constexpr uint16_t MAX_TEXT_LENGTH = 4096; 524 /* Maximum value of the graphic display range. The default value is <b>16383px</b>. */ 525 static constexpr int32_t COORD_MAX = 16383; 526 /* Minimum value of the graphic display range. The default value is <b>-16384px</b>. */ 527 static constexpr int32_t COORD_MIN = -16384; 528 static constexpr uint32_t HARFBUZ_CACHE_LENGTH = 0x19000; // 100K 529 static constexpr uint16_t MAX_LINE_WIDTH = 128; 530 /* Maximum length of a QR code string. The default value is <b>2048</b>. */ 531 static constexpr uint32_t QRCODE_VAL_MAX = 2048; 532 533 /* Rotate sensitivity factor. The default value is <b>1.0<b> time. */ 534 static constexpr float ROTATE_SENSITIVITY = 1.0; 535 /* Rotate sensitivity factor of UISwipeView. The default value is <b>2.8<b> time. */ 536 static constexpr float DEFAULT_SWIPE_VIEW_ROTATE_FACTOR = 2.8; 537 /* Rotate sensitivity factor of UIList. The default value is <b>1.2<b> time. */ 538 static constexpr float DEFAULT_LIST_ROTATE_FACTOR = 1.2; 539 /* Rotate sensitivity factor of UIPicker. The default value is <b>1.2<b> time. */ 540 static constexpr float DEFAULT_PICKER_ROTATE_FACTOR = 1.2; 541 /* Rotate sensitivity factor of UIScrollView. The default value is <b>2.0<b> time. */ 542 static constexpr float DEFAULT_SCROLL_VIEW_ROTATE_FACTOR = 2.0; 543 #ifdef _WIN32 544 /* Rotate sensitivity factor of UISlider. The default value is <b>-1<b> time. */ 545 static constexpr float DEFAULT_SLIDER_ROTATE_FACTOR = -1; 546 #else 547 /* Rotate sensitivity factor of UISlider. The default value is <b>-0.05<b> time. */ 548 static constexpr float DEFAULT_SLIDER_ROTATE_FACTOR = -0.05; 549 #endif 550 /* When rotating the crown, a vibration is triggered every 30 pixels. */ 551 static constexpr uint8_t DEFAULT_SCROLL_VIEW_VIBRATION_LEN = 30; 552 /* calculate drag throw distance when rotating, last rotate distance * ROTATE_DISTANCE_COEFFICIENT */ 553 static constexpr uint8_t ABSTRACT_ROTATE_DISTANCE_COEFF = 20; 554 static constexpr uint8_t SCROLLVIEW_ROTATE_DISTANCE_COEFF = 20; 555 static constexpr uint8_t PICKERVIEW_ROTATE_DISTANCE_COEFF = 20; 556 static constexpr uint8_t LIST_ROTATE_DISTANCE_COEFF = 20; 557 /* calculate rotate throw threshold when rotating the crown, width or height / DEFAULT_ROTATE_THROW_THRESHOLD */ 558 static constexpr uint8_t ABSTRACT_ROTATE_THROW_THRESHOLD = 4; 559 static constexpr uint8_t SCROLLVIEW_ROTATE_THROW_THRESHOLD = 4; 560 static constexpr uint8_t PICKERVIEW_ROTATE_THROW_THRESHOLD = 4; 561 static constexpr uint8_t LIST_ROTATE_THROW_THRESHOLD = 4; 562 } // namespace OHOS 563 #endif // GRAPHIC_LITE_GRAPHIC_CONFIG_H 564