1 /*
2 * Copyright (c) 2021-2023 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 #ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COMMON_DEF_H
16 #define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COMMON_DEF_H
17
18 #include <atomic>
19 #include <cmath>
20 #include <functional>
21 #include <limits.h>
22 #include <limits>
23 #include <memory>
24 #include <string>
25 #include <unordered_map>
26 #include <unordered_set>
27 #include <unistd.h>
28 #include <utils/rect.h>
29 #include <vector>
30
31 #include "common/rs_macros.h"
32 #include "common/rs_anco_type.h"
33 #include "draw/color.h"
34
35 namespace OHOS {
36 class Surface;
37
38 namespace Rosen {
39 using AnimationId = uint64_t;
40 using NodeType = uint8_t;
41 using FrameRateLinkerId = uint64_t;
42 using InteractiveImplictAnimatorId = uint64_t;
43 using LeashPersistentId = uint64_t;
44 using ModifierId = uint64_t;
45 using NodeId = uint64_t;
46 using PropertyId = uint64_t;
47 using SurfaceId = uint64_t;
48
49 constexpr uint32_t UNI_MAIN_THREAD_INDEX = UINT32_MAX;
50 constexpr uint32_t UNI_RENDER_THREAD_INDEX = UNI_MAIN_THREAD_INDEX - 1;
51 constexpr uint64_t INVALID_NODEID = 0;
52 constexpr int32_t INSTANCE_ID_UNDEFINED = -1;
53 constexpr uint32_t RGBA_MAX = 255;
54 constexpr uint64_t INVALID_LEASH_PERSISTENTID = 0;
55 constexpr uint8_t TOP_OCCLUSION_SURFACES_NUM = 3;
56 constexpr uint8_t OCCLUSION_ENABLE_SCENE_NUM = 2;
57 constexpr int16_t DEFAULT_OCCLUSION_SURFACE_ORDER = -1;
58 constexpr int MAX_DIRTY_ALIGNMENT_SIZE = 128;
59
60 /**
61 * Bitmask enumeration for hierarchical type identification
62 * Descendant types must include all ancestor bits following the rules:
63 * childFlags = ParentFlags | AdditionalBits
64 */
65 enum class RSUINodeType : uint32_t {
66 UNKNOW = 0x0000u,
67 RS_NODE = 0x0001u,
68 DISPLAY_NODE = 0x0011u,
69 SURFACE_NODE = 0x0021u,
70 PROXY_NODE = 0x0041u,
71 CANVAS_NODE = 0x0081u,
72 EFFECT_NODE = 0x0101u,
73 ROUND_CORNER_NODE = 0x0201u,
74 ROOT_NODE = 0x1081u,
75 CANVAS_DRAWING_NODE = 0x2081u,
76 };
77
78 enum class FollowType : uint8_t {
79 NONE,
80 FOLLOW_TO_PARENT,
81 FOLLOW_TO_SELF,
82 };
83
84 #define LIKELY(exp) (__builtin_expect((exp) != 0, true))
85 #define UNLIKELY(exp) (__builtin_expect((exp) != 0, false))
86
87 #ifdef CM_FEATURE_ENABLE
88 #define CM_INLINE __attribute__((always_inline))
89 #else
90 #define CM_INLINE
91 #endif
92
93 /**
94 * Bitmask enumeration for hierarchical type identification
95 * Descendant types must include all ancestor bits following the rule:
96 * ChildFlags = ParentFlags | AdditionalBits
97 */
98 enum class RSRenderNodeType : uint32_t {
99 UNKNOW = 0x0000u,
100 RS_NODE = 0x0001u,
101 SCREEN_NODE = 0x0011u,
102 SURFACE_NODE = 0x0021u,
103 PROXY_NODE = 0x0041u,
104 CANVAS_NODE = 0x0081u,
105 EFFECT_NODE = 0x0101u,
106 ROUND_CORNER_NODE = 0x0201u,
107 LOGICAL_DISPLAY_NODE = 0x0401u,
108 ROOT_NODE = 0x1081u,
109 CANVAS_DRAWING_NODE = 0x2081u,
110 };
111
112 // types for Processor
113 enum class RSProcessorType : uint32_t {
114 UNKNOW = 0x0000u,
115 RS_PROCESSOR = 0x0001u,
116 PHYSICAL_SCREEN_PROCESSOR = 0x0011u,
117 VIRTUAL_SCREEN_PROCESSOR = 0x0021u,
118 UNIRENDER_PROCESSOR = 0x0041u,
119 UNIRENDER_VIRTUAL_PROCESSOR = 0x0081u,
120 };
121
122 enum class CompositeType : uint32_t {
123 UNI_RENDER_COMPOSITE = 0,
124 UNI_RENDER_MIRROR_COMPOSITE,
125 UNI_RENDER_EXPAND_COMPOSITE,
126 HARDWARE_COMPOSITE,
127 SOFTWARE_COMPOSITE
128 };
129
130 enum RSRenderParamsDirtyType {
131 NO_DIRTY = 0,
132 MATRIX_DIRTY,
133 LAYER_INFO_DIRTY,
134 BUFFER_INFO_DIRTY,
135 DRAWING_CACHE_TYPE_DIRTY,
136 MAX_DIRTY_TYPE,
137 };
138
139 enum class NodeDirtyType : uint32_t {
140 NOT_DIRTY = 0x0000u,
141 GEOMETRY = 0x0001u,
142 BACKGROUND = 0x0002u,
143 CONTENT = 0x0004u,
144 FOREGROUND = 0x0008u,
145 OVERLAY = 0x0010u,
146 APPEARANCE = 0x0020u,
147 };
148
149 enum class CacheType : uint8_t {
150 NONE = 0,
151 CONTENT,
152 ANIMATE_PROPERTY,
153 };
154
155 enum class DrawableCacheType : uint8_t {
156 NONE = 0,
157 CONTENT,
158 };
159
160 enum RSDrawingCacheType : uint8_t {
161 DISABLED_CACHE = 0,
162 FORCED_CACHE, // must-to-do case
163 TARGETED_CACHE, // suggested case which could be disabled by optimized strategy
164 FOREGROUND_FILTER_CACHE // using cache to draw foreground filter
165 };
166
167 enum class FilterCacheType : uint8_t {
168 NONE = 0,
169 SNAPSHOT = 1,
170 FILTERED_SNAPSHOT = 2,
171 BOTH = SNAPSHOT | FILTERED_SNAPSHOT,
172 };
173
174 // opinc state
175 enum NodeCacheState : uint8_t {
176 STATE_INIT = 0,
177 STATE_CHANGE,
178 STATE_UNCHANGE,
179 STATE_DISABLE,
180 };
181
182 enum NodeChangeType : uint8_t {
183 KEEP_UNCHANGE = 0,
184 SELF_DIRTY,
185 };
186
187 // opinc cache state
188 enum NodeStrategyType : uint8_t {
189 CACHE_NONE = 0,
190 DDGR_OPINC_DYNAMIC,
191 OPINC_AUTOCACHE,
192 NODE_GROUP,
193 CACHE_DISABLE,
194 };
195
196 enum NodeRecordState : uint8_t {
197 RECORD_NONE = 0,
198 RECORD_CALCULATE,
199 RECORD_CACHING,
200 RECORD_CACHED,
201 RECORD_DISABLE,
202 };
203
204 enum DrawAreaEnableState : uint8_t {
205 DRAW_AREA_INIT = 0,
206 DRAW_AREA_ENABLE,
207 DRAW_AREA_DISABLE,
208 };
209
210 // priority for node, higher number means lower priority
211 enum class NodePriorityType : uint8_t {
212 MAIN_PRIORITY = 0, // node must render in main thread
213 SUB_FOCUSNODE_PRIORITY, // node render in sub thread with the highest priority
214 SUB_VIDEO_PRIORITY, // node render in sub thread with the second highest priority
215 SUB_HIGH_PRIORITY, // node render in sub thread with the second priority
216 SUB_LOW_PRIORITY, // node render in sub thread with low priority
217 };
218
219 enum class RSVisibleLevel : uint32_t {
220 RS_ALL_VISIBLE = 0,
221 RS_SEMI_NONDEFAULT_VISIBLE,
222 RS_SEMI_DEFAULT_VISIBLE,
223 RS_INVISIBLE,
224 RS_SYSTEM_ANIMATE_SCENE,
225 RS_UNKNOW_VISIBLE_LEVEL,
226 };
227
228 // status for sub thread node
229 enum class CacheProcessStatus : uint8_t {
230 WAITING = 0, // waiting for process
231 DOING, // processing
232 DONE, // processed
233 SKIPPED, // skip cur process and wait for next new data to process
234 UNKNOWN,
235 };
236
237 // the type of surfaceCapture
238 enum class SurfaceCaptureType : uint8_t {
239 DEFAULT_CAPTURE = 0, // displayNode capture or window capture
240 UICAPTURE = 1, // UI capture
241 SURFACE_CAPTURE_TYPE_BUTT, // a boundary for SurfaceTureCaptureType Security Check
242 };
243
244 #ifdef TP_FEATURE_ENABLE
245 // the type of TpFeatureConfig
246 enum class TpFeatureConfigType : uint8_t {
247 DEFAULT_TP_FEATURE = 0,
248 AFT_TP_FEATURE,
249 };
250 #endif
251
252 // types for RenderNodeDrawable
253 enum class RSRenderNodeDrawableType : uint32_t {
254 UNKNOW = 0,
255 RS_NODE_DRAWABLE,
256 LOGICAL_DISPLAY_NODE_DRAWABLE,
257 SCREEN_NODE_DRAWABLE,
258 SURFACE_NODE_DRAWABLE,
259 CANVAS_NODE_DRAWABLE,
260 EFFECT_NODE_DRAWABLE,
261 ROOT_NODE_DRAWABLE,
262 CANVAS_DRAWING_NODE_DRAWABLE,
263 };
264
265 // zOrder of topLayer
266 enum class TopLayerZOrder : uint32_t {
267 ROUNDED_CORNER_TOP = 9901,
268 ROUNDED_CORNER_BOTTOM = 9900,
269 POINTER_WINDOW = 9800,
270 CHARGE_ACTION_TEXT = 9300,
271 CHARGE_3D_MOTION = 9200,
272 STYLUS = 9100,
273 MINIMUM_VALUE = 9000,
274 };
275
276 struct FocusAppInfo {
277 int32_t pid = -1;
278 int32_t uid = -1;
279 std::string bundleName = "";
280 std::string abilityName = "";
281 uint64_t focusNodeId = 0;
282 };
283
284 struct RSUICaptureInRangeParam {
285 NodeId endNodeId = INVALID_NODEID;
286 bool useBeginNodeSize = true;
287 };
288
289 struct RSSurfaceCaptureConfig {
290 float scaleX = 1.0f;
291 float scaleY = 1.0f;
292 bool useDma = false;
293 bool useCurWindow = true;
294 SurfaceCaptureType captureType = SurfaceCaptureType::DEFAULT_CAPTURE;
295 bool isSync = false;
296 Drawing::Rect mainScreenRect = {};
297 std::vector<NodeId> blackList = {}; // exclude surfacenode in screenshot
298 bool isSoloNodeUiCapture = false;
299 bool isHdrCapture = false;
300 bool needF16WindowCaptureForScRGB = false;
301 RSUICaptureInRangeParam uiCaptureInRangeParam = {};
302 Drawing::Rect specifiedAreaRect = {};
303 uint32_t backGroundColor = Drawing::Color::COLOR_TRANSPARENT;
304 bool operator==(const RSSurfaceCaptureConfig& config) const
305 {
306 return mainScreenRect == config.mainScreenRect &&
307 specifiedAreaRect == config.specifiedAreaRect &&
308 uiCaptureInRangeParam.endNodeId == config.uiCaptureInRangeParam.endNodeId &&
309 uiCaptureInRangeParam.useBeginNodeSize == config.uiCaptureInRangeParam.useBeginNodeSize;
310 }
311 };
312
313 struct RSSurfaceCaptureBlurParam {
314 bool isNeedBlur = false;
315 float blurRadius = 1E-6;
316 };
317
318 struct RSSurfaceCaptureParam {
319 NodeId id = 0;
320 RSSurfaceCaptureConfig config = {};
321 bool isSystemCalling = false;
322 bool isSelfCapture = false;
323 bool isFreeze = false;
324 RSSurfaceCaptureBlurParam blurParam = {};
325 bool secExemption = false;
326 };
327
328 struct RSSurfaceCapturePermissions {
329 bool screenCapturePermission = false;
330 bool isSystemCalling = false;
331 bool selfCapture = false;
332 };
333
334 #define CHECK_FALSE_RETURN(var) \
335 do { \
336 if (!(var)) { \
337 return; \
338 } \
339 } while (0) \
340
341 #define CHECK_FALSE_RETURN_VALUE(var, value) \
342 do { \
343 if (!(var)) { \
344 return value; \
345 } \
346 } while (0)
347
348 #define IS_SCB_WINDOW_TYPE(windowType) \
349 (windowType == SurfaceWindowType::SYSTEM_SCB_WINDOW || windowType == SurfaceWindowType::SCB_DESKTOP || \
350 windowType == SurfaceWindowType::SCB_WALLPAPER || windowType == SurfaceWindowType::SCB_SCREEN_LOCK || \
351 windowType == SurfaceWindowType::SCB_NEGATIVE_SCREEN || windowType == SurfaceWindowType::SCB_DROPDOWN_PANEL || \
352 windowType == SurfaceWindowType::SCB_VOLUME_PANEL || \
353 windowType == SurfaceWindowType::SCB_BANNER_NOTIFICATION || windowType == SurfaceWindowType::SCB_GESTURE_BACK)
354
355 enum class DeviceType : uint8_t {
356 PHONE,
357 PC,
358 TABLET,
359 OTHERS,
360 };
361
362 enum GrallocBufferAttr : uint32_t {
363 // used in set roi region to codec, must be the same as private key in codec
364 GRALLOC_BUFFER_ATTR_BUFFER_ROI_INFO = 2054,
365 };
366
367 // types for PC SystemAnimatedScenes
368 enum class SystemAnimatedScenes : uint32_t {
369 ENTER_MISSION_CENTER, // Enter the mission center
370 EXIT_MISSION_CENTER, // Exit the mission center
371 ENTER_TFS_WINDOW, // Three-finger sliding window recovery
372 EXIT_TFU_WINDOW, // The three-finger up window disappears
373 ENTER_WINDOW_FULL_SCREEN, // Enter the window full screen
374 EXIT_WINDOW_FULL_SCREEN, // Exit the window full screen
375 ENTER_MAX_WINDOW, // Enter the window maximization state
376 EXIT_MAX_WINDOW, // Exit the window maximization state
377 ENTER_SPLIT_SCREEN, // Enter the split screen
378 EXIT_SPLIT_SCREEN, // Exit the split screen
379 ENTER_APP_CENTER, // Enter the app center
380 EXIT_APP_CENTER, // Exit the app center
381 APPEAR_MISSION_CENTER, // A special case scenario that displays the mission center
382 ENTER_WIND_CLEAR, // Enter win+D in clear screen mode
383 ENTER_WIND_RECOVER, // Enter win+D in recover mode
384 ENTER_RECENTS, // Enter recents only for phone, end with EXIT_RECENTS instead of OTHERS
385 EXIT_RECENTS, // Exit recents only for phone
386 LOCKSCREEN_TO_LAUNCHER, // Enter unlock screen for pc scene
387 ENTER_MIN_WINDOW, // Enter the window minimization state
388 RECOVER_MIN_WINDOW, // Recover minimized window
389 SNAPSHOT_ROTATION, // Enter tablet's snapshot rotation scene
390 OTHERS, // 1.Default state 2.The state in which the animation ends
391 };
392
393 // types for RSSurfaceRenderNode
394 enum class RSSurfaceNodeType : uint8_t {
395 DEFAULT,
396 APP_WINDOW_NODE, // surfacenode created as app main window
397 STARTING_WINDOW_NODE, // starting window, surfacenode created by wms
398 SELF_DRAWING_WINDOW_NODE, // create by wms, such as bootanimation
399 LEASH_WINDOW_NODE, // leashwindow
400 ABILITY_COMPONENT_NODE, // surfacenode created as ability component
401 SELF_DRAWING_NODE, // surfacenode created by arkui component (except ability component)
402 SURFACE_TEXTURE_NODE, // create by video
403 FOREGROUND_SURFACE,
404 SCB_SCREEN_NODE, // surfacenode created as sceneboard
405 UI_EXTENSION_COMMON_NODE, // uiextension node
406 UI_EXTENSION_SECURE_NODE, // uiextension node that requires info callback
407 CURSOR_NODE, // cursor node created by MMI
408 ABILITY_MAGNIFICATION_NODE, // local magnification
409 NODE_MAX,
410 };
411
412 enum class MultiThreadCacheType : uint8_t {
413 NONE = 0,
414 LEASH_WINDOW,
415 ARKTS_CARD,
416 NONFOCUS_WINDOW,
417 };
418
419 enum class UiFirstModeType : uint8_t {
420 SINGLE_WINDOW_MODE,
421 MULTI_WINDOW_MODE,
422 };
423
424 //Each command HAVE TO have UNIQUE ID in ALL HISTORY
425 //If a command is not used and you want to delete it,
426 //just COMMENT it - and never use this value anymore
427
428 enum class UiFirstCcmType : uint8_t {
429 SINGLE = 1,
430 MULTI = 2,
431 HYBRID = 3,
432 };
433
434 enum class RSUIFirstSwitch {
435 NONE = 0, // follow RS rules
436 MODAL_WINDOW_CLOSE = 1, // open app with modal window animation, close uifirst
437 FORCE_DISABLE = 2, // force close uifirst
438 FORCE_ENABLE = 3, // force open uifirst
439 FORCE_ENABLE_LIMIT = 4, // force open uifirst, but for limited
440 FORCE_DISABLE_NONFOCUS = 5, // force close uifirst when only in nonfocus window
441 };
442
443 enum class SelfDrawingNodeType : uint8_t {
444 DEFAULT,
445 VIDEO,
446 XCOM,
447 };
448
449 enum class SurfaceWindowType : uint8_t {
450 DEFAULT_WINDOW = 0,
451 SYSTEM_SCB_WINDOW = 1,
452 SCB_DESKTOP = 2,
453 SCB_WALLPAPER = 3,
454 SCB_SCREEN_LOCK = 4,
455 SCB_NEGATIVE_SCREEN = 5,
456 SCB_DROPDOWN_PANEL = 6,
457 SCB_VOLUME_PANEL = 7,
458 SCB_BANNER_NOTIFICATION = 8,
459 SCB_GESTURE_BACK = 9,
460 };
461
462 enum class SurfaceHwcNodeType : uint8_t {
463 DEFAULT_HWC_TYPE = 0,
464 DEFAULT_HWC_VIDEO = 1,
465 DEFAULT_HWC_ROSENWEB = 2,
466 };
467
468 struct RSSurfaceRenderNodeConfig {
469 NodeId id = 0;
470 std::string name = "SurfaceNode";
471 RSSurfaceNodeType nodeType = RSSurfaceNodeType::DEFAULT;
472 void* additionalData = nullptr;
473 bool isTextureExportNode = false;
474 bool isSync = false;
475 enum SurfaceWindowType surfaceWindowType = SurfaceWindowType::DEFAULT_WINDOW;
476 std::string bundleName = "";
477 };
478
479 struct RSAdvancedDirtyConfig {
480 // a threshold, if the number of rectangles is larger than it, we will merge all rectangles to one
481 static const int RECT_NUM_MERGING_ALL = 35;
482 // a threshold, if the number of rectangles is larger than it, we will merge all rectangles by level
483 static const int RECT_NUM_MERGING_BY_LEVEL = 20;
484 // maximal number of dirty rectangles in one surface/display node when advancedDirty is opened
485 static const int MAX_RECT_NUM_EACH_NODE = 10;
486 // number of dirty rectangles in one surface/display node when advancedDirty is closed
487 static const int DISABLED_RECT_NUM_EACH_NODE = 1;
488 // expected number of rectangles after merging
489 static const int EXPECTED_OUTPUT_NUM = 3;
490 // maximal tolerable cost in merging
491 // if the merging cost of two rectangles is larger than it, we will not merge
492 // later it could be set to a quantity related to screen area
493 static const int MAX_TOLERABLE_COST = INT_MAX;
494 };
495
496 static RSAdvancedDirtyConfig advancedDirtyConfig;
497
498 // codes for arkui-x start
499 // types for RSSurfaceExt
500 enum class RSSurfaceExtType : uint8_t {
501 NONE,
502 SURFACE_TEXTURE,
503 SURFACE_PLATFORM_TEXTURE,
504 };
505
506 struct RSSurfaceExtConfig {
507 RSSurfaceExtType type = RSSurfaceExtType::NONE;
508 void* additionalData = nullptr;
509 };
510 using RSSurfaceTextureConfig = RSSurfaceExtConfig;
511 using RSSurfaceTextureAttachCallBack = std::function<void(int64_t textureId, bool attach)>;
512 using RSSurfaceTextureUpdateCallBack = std::function<void(std::vector<float>&)>;
513 using RSSurfaceTextureInitTypeCallBack = std::function<void(int32_t&)>;
514 // codes for arkui-x end
515
516 struct RSDisplayNodeConfig {
517 uint64_t screenId = 0;
518 bool isMirrored = false;
519 NodeId mirrorNodeId = 0;
520 bool isSync = false;
521 };
522
523 // ability state of surface node
524 enum class RSSurfaceNodeAbilityState : uint8_t {
525 BACKGROUND,
526 FOREGROUND,
527 };
528
529 struct SubSurfaceCntUpdateInfo {
530 int updateCnt_ = 0;
531 NodeId preParentId_ = INVALID_NODEID;
532 NodeId curParentId_ = INVALID_NODEID;
533 };
534
535 constexpr int64_t NS_TO_S = 1000000000;
536 constexpr int64_t NS_PER_MS = 1000000;
537 constexpr uint32_t SIZE_UPPER_LIMIT = 1000;
538 constexpr uint32_t PARTICLE_EMMITER_UPPER_LIMIT = 2000;
539 constexpr uint32_t PARTICLE_UPPER_LIMIT = 1000000;
540
541 #if defined(M_PI)
542 constexpr float PI = M_PI;
543 #else
544 static const float PI = std::atanf(1.0) * 4;
545 #endif
546
547 template<typename T>
ROSEN_EQ(const T & x,const T & y)548 inline constexpr bool ROSEN_EQ(const T& x, const T& y)
549 {
550 if constexpr (std::is_floating_point<T>::value) {
551 return (std::abs((x) - (y)) <= (std::numeric_limits<T>::epsilon()));
552 } else {
553 return x == y;
554 }
555 }
556
557 template<typename T>
ROSEN_EQ(T x,T y,T epsilon)558 inline bool ROSEN_EQ(T x, T y, T epsilon)
559 {
560 return (std::abs((x) - (y)) <= (epsilon));
561 }
562
563 template<typename T>
ROSEN_EQ(const std::weak_ptr<T> & x,const std::weak_ptr<T> & y)564 inline bool ROSEN_EQ(const std::weak_ptr<T>& x, const std::weak_ptr<T>& y)
565 {
566 return !(x.owner_before(y) || y.owner_before(x));
567 }
568
569 template<typename T>
ROSEN_NE(const T & x,const T & y)570 inline constexpr bool ROSEN_NE(const T& x, const T& y)
571 {
572 return !ROSEN_EQ(x, y);
573 }
574
ROSEN_LNE(float left,float right)575 inline bool ROSEN_LNE(float left, float right) // less not equal
576 {
577 constexpr float epsilon = -0.001f;
578 return (left - right) < epsilon;
579 }
580
ROSEN_GNE(float left,float right)581 inline bool ROSEN_GNE(float left, float right) // great not equal
582 {
583 constexpr float epsilon = 0.001f;
584 return (left - right) > epsilon;
585 }
586
ROSEN_GE(float left,float right)587 inline bool ROSEN_GE(float left, float right) // great or equal
588 {
589 constexpr float epsilon = -0.001f;
590 return (left - right) > epsilon;
591 }
592
ROSEN_LE(float left,float right)593 inline bool ROSEN_LE(float left, float right) // less or equal
594 {
595 constexpr float epsilon = 0.001f;
596 return (left - right) < epsilon;
597 }
598
599 class MemObject {
600 public:
MemObject(size_t size)601 explicit MemObject(size_t size) : size_(size) {}
602 virtual ~MemObject() = default;
603
604 void* operator new(size_t size);
605 void operator delete(void* ptr);
606
607 void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
608 void operator delete(void* ptr, const std::nothrow_t&) noexcept;
609
610 protected:
611 size_t size_;
612 };
613
ExtractPid(uint64_t id)614 inline constexpr pid_t ExtractPid(uint64_t id)
615 {
616 // extract high 32 bits of nodeid/animationId/propertyId as pid
617 return static_cast<pid_t>(id >> 32);
618 }
619
ExtractTid(uint64_t token)620 inline constexpr int32_t ExtractTid(uint64_t token)
621 {
622 // extract high 32 bits of token as tid
623 return static_cast<int32_t>(token >> 32);
624 }
625
MakeNodeId(pid_t pid,uint32_t uid)626 inline constexpr uint64_t MakeNodeId(pid_t pid, uint32_t uid)
627 {
628 // combine pid and uid to nodeId
629 return (static_cast<uint64_t>(pid) << 32) | uid;
630 }
631
GenerateUniqueNodeIdForRS()632 inline uint64_t GenerateUniqueNodeIdForRS()
633 {
634 static std::atomic<uint32_t> uid { 0 };
635 return MakeNodeId(getpid(), uid.fetch_add(1, std::memory_order_relaxed));
636 }
637
638 template<class Container, class Predicate>
EraseIf(Container & container,Predicate pred)639 inline typename Container::size_type EraseIf(Container& container, Predicate pred)
640 {
641 // erase from container if pred returns true, backport of c++20 std::remove_if
642 typename Container::size_type oldSize = container.size();
643 const typename Container::iterator end = container.end();
644 for (typename Container::iterator iter = container.begin(); iter != end;) {
645 if (pred(*iter)) {
646 iter = container.erase(iter);
647 } else {
648 ++iter;
649 }
650 }
651 return oldSize - container.size();
652 }
653
654 enum class RSInterfaceErrorCode : uint32_t {
655 #undef NO_ERROR
656 NO_ERROR = 0,
657 NONSYSTEM_CALLING,
658 NOT_SELF_CALLING,
659 WRITE_PARCEL_ERROR,
660 UNKNOWN_ERROR,
661 NULLPTR_ERROR,
662 };
663
664 struct VSyncConnParam {
665 uint64_t id = 0;
666 NodeId windowNodeId = 0;
667 bool fromXcomponent = false;
668 };
669
670 enum DrawNodeType : uint32_t {
671 PureContainerType = 0,
672 MergeableType,
673 DrawPropertyType,
674 GeometryPropertyType
675 };
676
677 enum class ComponentEnableSwitch : uint8_t {
678 TEXTBLOB = 0,
679 SVG,
680 HMSYMBOL,
681 CANVAS,
682 MAX_VALUE,
683 };
684 } // namespace Rosen
685 } // namespace OHOS
686 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COMMON_DEF_H
687