已合并
dms test #18331
已合并
wulong158创建于 3月5日
29 个文件变更+5076-0
@@ -0,0 +1,211 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef RECT_H
17+#define RECT_H
18+ 
19+#include <cmath>
20+#include <string>
21+ 
22+typedef float scalar;
23+ 
24+namespace OHOS {
25+namespace Rosen {
26+namespace Drawing {
27+class RectF;
28+ 
29+typedef RectF Rect;
30+ 
31+#define DRAWING_MAX_S32_FITS_IN_FLOAT 2147483520
32+#define DRAWING_MIN_S32_FITS_IN_FLOAT (-DRAWING_MAX_S32_FITS_IN_FLOAT)
33+ 
34+class RectI {
35+public:
36+ inline RectI() noexcept;
37+ inline RectI(const RectI& r) noexcept;
38+ inline RectI(const int32_t l, const int32_t t, const int32_t r, const int32_t b) noexcept;
39+ 
40+ ~RectI() {}
41+ 
42+ inline int32_t GetLeft() const
43+ {
44+ return left_;
45+ }
46+ inline int32_t GetTop() const
47+ {
48+ return top_;
49+ }
50+ inline int32_t GetRight() const
51+ {
52+ return right_;
53+ }
54+ inline int32_t GetBottom() const
55+ {
56+ return bottom_;
57+ }
58+ 
59+ int32_t left_;
60+ int32_t top_;
61+ int32_t right_;
62+ int32_t bottom_;
63+};
64+ 
65+inline RectI::RectI() noexcept : left_(0), top_(0), right_(0), bottom_(0) {}
66+ 
67+inline RectI::RectI(const RectI& r) noexcept
68+{
69+ // Tell the compiler there is no alias and to select wider load/store instructions.
70+ int32_t left = r.GetLeft();
71+ int32_t top = r.GetTop();
72+ int32_t right = r.GetRight();
73+ int32_t bottom = r.GetBottom();
74+ left_ = left;
75+ top_ = top;
76+ right_ = right;
77+ bottom_ = bottom;
78+}
79+ 
80+inline RectI::RectI(const int l, const int t, const int r, const int b) noexcept
81+ : left_(l), top_(t), right_(r), bottom_(b)
82+{}
83+ 
84+class RectF {
85+public:
86+ inline RectF() noexcept;
87+ inline RectF(const RectF& r) noexcept;
88+ inline RectF(const RectI& r) noexcept;
89+ inline RectF(const scalar l, const scalar t, const scalar r, const scalar b) noexcept;
90+ 
91+ ~RectF() {}
92+ 
93+ inline bool IsValid() const;
94+ inline bool IsEmpty() const;
95+ 
96+ inline scalar GetLeft() const;
97+ inline scalar GetTop() const;
98+ inline scalar GetRight() const;
99+ inline scalar GetBottom() const;
100+ 
101+ inline scalar GetWidth() const;
102+ inline scalar GetHeight() const;
103+ 
104+ inline void SetLeft(scalar pos);
105+ inline void SetTop(scalar pos);
106+ inline void SetRight(scalar pos);
107+ inline void SetBottom(scalar pos);
108+ 
109+ scalar left_;
110+ scalar top_;
111+ scalar right_;
112+ scalar bottom_;
113+};
114+ 
115+inline RectF::RectF() noexcept : left_(0.0), top_(0.0), right_(0.0), bottom_(0.0) {}
116+ 
117+inline RectF::RectF(const RectF& r) noexcept
118+{
119+ // Tell the compiler there is no alias and to select wider load/store instructions.
120+ scalar left = r.GetLeft();
121+ scalar top = r.GetTop();
122+ scalar right = r.GetRight();
123+ scalar bottom = r.GetBottom();
124+ left_ = left;
125+ top_ = top;
126+ right_ = right;
127+ bottom_ = bottom;
128+}
129+ 
130+inline RectF::RectF(const RectI& r) noexcept
131+{
132+ // Tell the compiler there is no alias and to select wider load/store instructions.
133+ scalar left = r.GetLeft();
134+ scalar top = r.GetTop();
135+ scalar right = r.GetRight();
136+ scalar bottom = r.GetBottom();
137+ left_ = left;
138+ top_ = top;
139+ right_ = right;
140+ bottom_ = bottom;
141+}
142+ 
143+inline RectF::RectF(const scalar l, const scalar t, const scalar r, const scalar b) noexcept
144+ : left_(l), top_(t), right_(r), bottom_(b)
145+{}
146+ 
147+inline bool RectF::IsValid() const
148+{
149+ return left_ < right_ && top_ < bottom_;
150+}
151+ 
152+inline bool RectF::IsEmpty() const
153+{
154+ return !(left_ < right_ && top_ < bottom_);
155+}
156+ 
157+inline scalar RectF::GetLeft() const
158+{
159+ return left_;
160+}
161+ 
162+inline scalar RectF::GetTop() const
163+{
164+ return top_;
165+}
166+ 
167+inline scalar RectF::GetRight() const
168+{
169+ return right_;
170+}
171+ 
172+inline scalar RectF::GetBottom() const
173+{
174+ return bottom_;
175+}
176+ 
177+inline scalar RectF::GetWidth() const
178+{
179+ return right_ - left_;
180+}
181+ 
182+inline scalar RectF::GetHeight() const
183+{
184+ return bottom_ - top_;
185+}
186+ 
187+inline void RectF::SetLeft(scalar pos)
188+{
189+ left_ = pos;
190+}
191+ 
192+inline void RectF::SetTop(scalar pos)
193+{
194+ top_ = pos;
195+}
196+ 
197+inline void RectF::SetRight(scalar pos)
198+{
199+ right_ = pos;
200+}
201+ 
202+inline void RectF::SetBottom(scalar pos)
203+{
204+ bottom_ = pos;
205+}
206+ 
207+ 
208+} // namespace Drawing
209+} // namespace Rosen
210+} // namespace OHOS
211+#endif
@@ -0,0 +1,741 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COMMON_DEF_H
17+#define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COMMON_DEF_H
18+ 
19+#include <atomic>
20+#include <cmath>
21+#include <functional>
22+#include <limits.h>
23+#include <limits>
24+#include <memory>
25+#include <string>
26+#include <unordered_map>
27+#include <unordered_set>
28+#include <unistd.h>
29+#include <vector>
30+ 
31+#include "common/rs_rect.h"
32+ 
33+#ifndef FLT_EPSILON
34+#define FLT_EPSILON 0x1.0p-23f
35+#endif
36+ 
37+namespace OHOS {
38+class Surface;
39+ 
40+namespace Rosen {
41+ 
42+enum class Gravity : int32_t {
43+ CENTER = 0,
44+ TOP,
45+ BOTTOM,
46+ LEFT,
47+ RIGHT,
48+ TOP_LEFT,
49+ TOP_RIGHT,
50+ BOTTOM_LEFT,
51+ BOTTOM_RIGHT,
52+ RESIZE,
53+ RESIZE_ASPECT,
54+ RESIZE_ASPECT_TOP_LEFT,
55+ RESIZE_ASPECT_BOTTOM_RIGHT,
56+ RESIZE_ASPECT_FILL,
57+ RESIZE_ASPECT_FILL_TOP_LEFT,
58+ RESIZE_ASPECT_FILL_BOTTOM_RIGHT,
59+ 
60+ DEFAULT = TOP_LEFT
61+};
62+ 
63+using AnimationId = uint64_t;
64+using NodeType = uint8_t;
65+using FrameRateLinkerId = uint64_t;
66+using InteractiveImplictAnimatorId = uint64_t;
67+using LeashPersistentId = uint64_t;
68+using ModifierId = uint64_t;
69+using NodeId = uint64_t;
70+using PropertyId = uint64_t;
71+using SurfaceId = uint64_t;
72+ 
73+constexpr uint32_t UNI_MAIN_THREAD_INDEX = UINT32_MAX;
74+constexpr uint32_t UNI_RENDER_THREAD_INDEX = UNI_MAIN_THREAD_INDEX - 1;
75+constexpr uint64_t INVALID_NODEID = 0;
76+constexpr int32_t INSTANCE_ID_UNDEFINED = -1;
77+constexpr uint32_t RGBA_MAX = 255;
78+constexpr uint64_t INVALID_LEASH_PERSISTENTID = 0;
79+constexpr uint8_t TOP_OCCLUSION_SURFACES_NUM = 3;
80+constexpr uint8_t OCCLUSION_ENABLE_SCENE_NUM = 2;
81+constexpr int16_t DEFAULT_OCCLUSION_SURFACE_ORDER = -1;
82+constexpr int MAX_DIRTY_ALIGNMENT_SIZE = 128;
83+static const std::string CAPTURE_WINDOW_NAME = "CapsuleWindow";
84+constexpr uint32_t DEFAULT_DYNAMIC_RANGE_MODE_STANDARD = 2;
85+constexpr uint32_t DYNAMIC_RANGE_MODE_HIGH = 0;
86+constexpr uint32_t DYNAMIC_RANGE_MODE_CONSTRAINT = 1;
87+constexpr int32_t UI_PiPLINE_NUM_UNDEFINED = -1;
88+ 
89+/**
90+ * Bitmask enumeration for hierarchical type identification
91+ * Descendant types must include all ancestor bits following the rule:
92+ * ChildFlags = ParentFlags | AdditionalBits
93+ */
94+enum class RSUINodeType : uint32_t {
95+ UNKNOW = 0x0000u,
96+ RS_NODE = 0x0001u,
97+ DISPLAY_NODE = 0x0011u,
98+ SURFACE_NODE = 0x0021u,
99+ PROXY_NODE = 0x0041u,
100+ CANVAS_NODE = 0x0081u,
101+ EFFECT_NODE = 0x0101u,
102+ WINDOW_KEYFRAME_NODE = 0x0801u,
103+ ROOT_NODE = 0x1081u,
104+ CANVAS_DRAWING_NODE = 0x2081u,
105+ UNION_NODE = 0x4081u,
106+};
107+ 
108+enum class FollowType : uint8_t {
109+ NONE,
110+ FOLLOW_TO_PARENT,
111+ FOLLOW_TO_SELF,
112+};
113+ 
114+enum class RSSurfaceFrameType : uint8_t {
115+ NONE = 0,
116+ RS_SURFACE_FRAME = 1,
117+ RS_SURFACE_FRAME_DARWIN = 2,
118+ RS_SURFACE_FRAME_OHOS = 3,
119+ RS_SURFACE_FRAME_WINDOWS = 4,
120+ RS_SURFACE_FRAME_OHOS_GL = 5,
121+ RS_SURFACE_FRAME_OHOS_RASTER = 6,
122+ RS_SURFACE_FRAME_OHOS_VULKAN = 7,
123+};
124+ 
125+#ifdef CM_FEATURE_ENABLE
126+#define CM_INLINE __attribute__((always_inline))
127+#else
128+#define CM_INLINE
129+#endif
130+ 
131+/**
132+ * Bitmask enumeration for hierarchical type identification
133+ * Descendant types must include all ancestor bits following the rule:
134+ * ChildFlags = ParentFlags | AdditionalBits
135+ */
136+enum class RSRenderNodeType : uint32_t {
137+ UNKNOW = 0x0000u,
138+ RS_NODE = 0x0001u,
139+ SCREEN_NODE = 0x0011u,
140+ SURFACE_NODE = 0x0021u,
141+ PROXY_NODE = 0x0041u,
142+ CANVAS_NODE = 0x0081u,
143+ EFFECT_NODE = 0x0101u,
144+ LOGICAL_DISPLAY_NODE = 0x0201u,
145+ WINDOW_KEYFRAME_NODE = 0x0801u,
146+ ROOT_NODE = 0x1081u,
147+ CANVAS_DRAWING_NODE = 0x2081u,
148+ UNION_NODE = 0x4081u,
149+};
150+ 
151+// types for Processor
152+enum class RSProcessorType : uint32_t {
153+ UNKNOW = 0x0000u,
154+ RS_PROCESSOR = 0x0001u,
155+ PHYSICAL_SCREEN_PROCESSOR = 0x0011u,
156+ VIRTUAL_SCREEN_PROCESSOR = 0x0021u,
157+ UNIRENDER_PROCESSOR = 0x0041u,
158+ UNIRENDER_VIRTUAL_PROCESSOR = 0x0081u,
159+};
160+ 
161+enum class CompositeType : uint32_t {
162+ UNI_RENDER_COMPOSITE = 0,
163+ UNI_RENDER_MIRROR_COMPOSITE,
164+ UNI_RENDER_EXPAND_COMPOSITE,
165+ HARDWARE_COMPOSITE,
166+ SOFTWARE_COMPOSITE
167+};
168+ 
169+enum RSRenderParamsDirtyType {
170+ NO_DIRTY = 0,
171+ MATRIX_DIRTY,
172+ LAYER_INFO_DIRTY,
173+ BUFFER_INFO_DIRTY,
174+ DRAWING_CACHE_TYPE_DIRTY,
175+ MAX_DIRTY_TYPE,
176+};
177+ 
178+enum class NodeDirtyType : uint32_t {
179+ NOT_DIRTY = 0x0000u,
180+ GEOMETRY = 0x0001u,
181+ BACKGROUND = 0x0002u,
182+ CONTENT = 0x0004u,
183+ FOREGROUND = 0x0008u,
184+ OVERLAY = 0x0010u,
185+ APPEARANCE = 0x0020u,
186+};
187+ 
188+enum class CacheType : uint8_t {
189+ NONE = 0,
190+ CONTENT,
191+ ANIMATE_PROPERTY,
192+};
193+ 
194+enum class DrawableCacheType : uint8_t {
195+ NONE = 0,
196+ CONTENT,
197+};
198+ 
199+enum RSDrawingCacheType : uint8_t {
200+ DISABLED_CACHE = 0,
201+ FORCED_CACHE, // must-to-do case
202+ TARGETED_CACHE, // suggested case which could be disabled by optimized strategy
203+ FOREGROUND_FILTER_CACHE // using cache to draw foreground filter
204+};
205+ 
206+enum class FilterCacheType : uint8_t {
207+ NONE = 0,
208+ SNAPSHOT = 1,
209+ FILTERED_SNAPSHOT = 2,
210+ BOTH = SNAPSHOT | FILTERED_SNAPSHOT,
211+};
212+ 
213+// opinc state
214+enum NodeCacheState : uint8_t {
215+ STATE_INIT = 0,
216+ STATE_CHANGE,
217+ STATE_UNCHANGE,
218+ STATE_DISABLE,
219+};
220+ 
221+enum NodeChangeType : uint8_t {
222+ KEEP_UNCHANGE = 0,
223+ SELF_DIRTY,
224+};
225+ 
226+// opinc cache state
227+enum NodeStrategyType : uint8_t {
228+ CACHE_NONE = 0,
229+ DDGR_OPINC_DYNAMIC,
230+ OPINC_AUTOCACHE,
231+ NODE_GROUP,
232+ CACHE_DISABLE,
233+};
234+ 
235+enum NodeRecordState : uint8_t {
236+ RECORD_NONE = 0,
237+ RECORD_CALCULATE,
238+ RECORD_CACHING,
239+ RECORD_CACHED,
240+ RECORD_DISABLE,
241+};
242+ 
243+enum DrawAreaEnableState : uint8_t {
244+ DRAW_AREA_INIT = 0,
245+ DRAW_AREA_ENABLE,
246+ DRAW_AREA_DISABLE,
247+};
248+ 
249+// priority for node, higher number means lower priority
250+enum class NodePriorityType : uint8_t {
251+ MAIN_PRIORITY = 0, // node must render in main thread
252+ SUB_FOCUSNODE_PRIORITY, // node render in sub thread with the highest priority
253+ SUB_VIDEO_PRIORITY, // node render in sub thread with the second highest priority
254+ SUB_HIGH_PRIORITY, // node render in sub thread with the second priority
255+ SUB_LOW_PRIORITY, // node render in sub thread with low priority
256+};
257+ 
258+enum class RSVisibleLevel : uint32_t {
259+ RS_ALL_VISIBLE = 0,
260+ RS_SEMI_NONDEFAULT_VISIBLE,
261+ RS_SEMI_DEFAULT_VISIBLE,
262+ RS_INVISIBLE,
263+ RS_SYSTEM_ANIMATE_SCENE,
264+ RS_UNKNOW_VISIBLE_LEVEL,
265+};
266+ 
267+// status for sub thread node
268+enum class CacheProcessStatus : uint8_t {
269+ WAITING = 0, // waiting for process
270+ DOING, // processing
271+ DONE, // processed
272+ SKIPPED, // skip and wait for next new data to process
273+ UNKNOWN,
274+};
275+ 
276+// the type of surfaceCapture
277+enum class SurfaceCaptureType : uint8_t {
278+ DEFAULT_CAPTURE = 0, // displayNode capture or window capture
279+ UICAPTURE = 1, // UI capture
280+ SURFACE_CAPTURE_TYPE_BUTT, // a boundary for SurfaceTureCaptureType Security Check
281+};
282+ 
283+// the type of TpFeatureConfig
284+enum class TpFeatureConfigType : uint8_t {
285+ DEFAULT_TP_FEATURE = 0,
286+ AFT_TP_FEATURE,
287+};
288+ 
289+// types for RenderNodeDrawable
290+enum class RSRenderNodeDrawableType : uint32_t {
291+ UNKNOW = 0,
292+ RS_NODE_DRAWABLE,
293+ LOGICAL_DISPLAY_NODE_DRAWABLE,
294+ SCREEN_NODE_DRAWABLE,
295+ SURFACE_NODE_DRAWABLE,
296+ CANVAS_NODE_DRAWABLE,
297+ EFFECT_NODE_DRAWABLE,
298+ ROOT_NODE_DRAWABLE,
299+ CANVAS_DRAWING_NODE_DRAWABLE,
300+ UNION_NODE_DRAWABLE,
301+ WINDOW_KEYFRAME_NODE_DRAWABLE,
302+};
303+ 
304+// zOrder of topLayer
305+enum class TopLayerZOrder : uint32_t {
306+ ROUNDED_CORNER_TOP = 9901,
307+ ROUNDED_CORNER_BOTTOM = 9900,
308+ POINTER_WINDOW = 9800,
309+ CHARGE_ACTION_TEXT = 9300,
310+ CHARGE_3D_MOTION = 9200,
311+ STYLUS = 9100,
312+ MINIMUM_VALUE = 9000,
313+};
314+ 
315+struct RSUICaptureInRangeParam {
316+ NodeId endNodeId = INVALID_NODEID;
317+ bool useBeginNodeSize = true;
318+};
319+ 
320+// error code for capture callback
321+enum class CaptureError : uint8_t {
322+ CAPTURE_OK = 0,
323+ CAPTURE_NO_PERMISSION,
324+ CAPTURE_NO_NODE,
325+ CAPTURE_CONFIG_WRONG,
326+ CAPTURE_PIXELMAP_NULL,
327+ CAPTURE_PIXELMAP_COPY_ERROR,
328+ CAPTURE_NULL_FAIL,
329+ HDR_SET_FAIL,
330+ CAPTURE_RENDER_FAIL,
331+ AUTO_NOT_SUPPORT,
332+ COLOR_SPACE_NOT_SUPPORT,
333+ DYNAMIC_RANGE_NOT_SUPPORT,
334+ CAPTURE_NO_SECURE_PERMISSION,
335+ // please add new enum before this comment
336+ CAPTURE_ERROR_BOUNDARY_BUTT, // a boundary for SurfaceTureCaptureType Security Check
337+};
338+ 
339+struct RSSurfaceCaptureConfig {
340+ float scaleX = 1.0f;
341+ float scaleY = 1.0f;
342+ bool useDma = false;
343+ bool useCurWindow = true;
344+ SurfaceCaptureType captureType = SurfaceCaptureType::DEFAULT_CAPTURE;
345+ bool isSync = false;
346+ Drawing::Rect mainScreenRect = {};
347+ std::vector<NodeId> blackList = {}; // exclude surfacenode in screenshot
348+ bool isSoloNodeUiCapture = false;
349+ bool isHdrCapture = false;
350+ bool needF16WindowCaptureForScRGB = false;
351+ bool needErrorCode = false;
352+ RSUICaptureInRangeParam uiCaptureInRangeParam = {};
353+ Drawing::Rect specifiedAreaRect = {};
354+ uint32_t backGroundColor = 0;
355+ // {colorspace, isAutoAjust}
356+ std::pair<uint32_t, bool> colorSpace = {0, false};
357+ // {dynamicRangeMode, isAutoAjust}
358+ std::pair<uint32_t, bool> dynamicRangeMode = {DEFAULT_DYNAMIC_RANGE_MODE_STANDARD, false};
359+};
360+ 
361+struct RSSurfaceCaptureBlurParam {
362+ bool isNeedBlur = false;
363+ float blurRadius = 1E-6;
364+};
365+ 
366+struct RSSurfaceCaptureParam {
367+ NodeId id = 0;
368+ RSSurfaceCaptureConfig config = {};
369+ bool isSystemCalling = false;
370+ bool isSelfCapture = false;
371+ bool isFreeze = false;
372+ RSSurfaceCaptureBlurParam blurParam = {};
373+ bool needCaptureSpecialLayer = false;
374+};
375+ 
376+struct RSSurfaceCapturePermissions {
377+ bool screenCapturePermission = false;
378+ bool isSystemCalling = false;
379+ bool selfCapture = false;
380+};
381+ 
382+enum GrallocBufferAttr : uint32_t {
383+ // used in set roi region to codec, must be the same as private key in codec
384+ GRALLOC_BUFFER_ATTR_BUFFER_ROI_INFO = 2054,
385+};
386+ 
387+// types for PC SystemAnimatedScenes
388+enum class SystemAnimatedScenes : uint32_t {
389+ ENTER_MISSION_CENTER, // Enter the mission center
390+ EXIT_MISSION_CENTER, // Exit the mission center
391+ ENTER_TFS_WINDOW, // Three-finger sliding window recovery
392+ EXIT_TFU_WINDOW, // The three-finger up window disappears
393+ ENTER_WINDOW_FULL_SCREEN, // Enter the window full screen
394+ EXIT_WINDOW_FULL_SCREEN, // Exit the window full screen
395+ ENTER_MAX_WINDOW, // Enter the window maximization state
396+ EXIT_MAX_WINDOW, // Exit the window maximization state
397+ ENTER_SPLIT_SCREEN, // Enter the split screen
398+ EXIT_SPLIT_SCREEN, // Exit the split screen
399+ ENTER_APP_CENTER, // Enter the app center
400+ EXIT_APP_CENTER, // Exit the app center
401+ APPEAR_MISSION_CENTER, // A special case scenario that displays the mission center
402+ ENTER_WIND_CLEAR, // Enter win+D in clear screen mode
403+ ENTER_WIND_RECOVER, // Enter win+D in recover mode
404+ ENTER_RECENTS, // Enter recents only for phone, end with EXIT_RECENTS instead of OTHERS
405+ EXIT_RECENTS, // Exit recents only for phone
406+ LOCKSCREEN_TO_LAUNCHER, // Enter unlock screen for pc scene
407+ ENTER_MIN_WINDOW, // Enter the window minimization state
408+ RECOVER_MIN_WINDOW, // Recover minimized window
409+ SNAPSHOT_ROTATION, // Enter tablet's snapshot rotation scene
410+ DRAG_WINDOW, // Enter scale window scene
411+ OTHERS, // 1.Default state 2.The state in which the animation ends
412+};
413+ 
414+// types for RSSurfaceRenderNode
415+enum class RSSurfaceNodeType : uint8_t {
416+ DEFAULT,
417+ APP_WINDOW_NODE, // surfacenode created as app main window
418+ STARTING_WINDOW_NODE, // starting window, surfacenode created by wms
419+ SELF_DRAWING_WINDOW_NODE, // create by wms, such as bootanimation
420+ LEASH_WINDOW_NODE, // leashwindow
421+ ABILITY_COMPONENT_NODE, // surfacenode created as ability component
422+ SELF_DRAWING_NODE, // surfacenode created by arkui component (except ability component)
423+ FOREGROUND_SURFACE,
424+ SCB_SCREEN_NODE, // surfacenode created as sceneboard
425+ UI_EXTENSION_COMMON_NODE, // uiextension node
426+ UI_EXTENSION_SECURE_NODE, // uiextension node that requires info callback
427+ CURSOR_NODE, // cursor node created by MMI
428+ ABILITY_MAGNIFICATION_NODE, // local magnification
429+ NODE_MAX,
430+};
431+ 
432+enum class MultiThreadCacheType : uint8_t {
433+ NONE = 0,
434+ LEASH_WINDOW,
435+ ARKTS_CARD,
436+ NONFOCUS_WINDOW,
437+};
438+ 
439+enum class UiFirstModeType : uint8_t {
440+ SINGLE_WINDOW_MODE,
441+ MULTI_WINDOW_MODE,
442+};
443+ 
444+ 
445+//Each command HAVE TO have UNIQUE ID in ALL HISTORY
446+//If a command is not used and you want to delete it,
447+//just COMMENT it - and never use this value anymore
448+ 
449+enum class UiFirstCcmType : uint8_t {
450+ SINGLE = 1,
451+ MULTI = 2,
452+ HYBRID = 3,
453+};
454+ 
455+enum class RSUIFirstSwitch {
456+ NONE = 0, // follow RS rules
457+ MODAL_WINDOW_CLOSE = 1, // open app with modal window animation, close uifirst
458+ FORCE_DISABLE = 2, // force close uifirst
459+ FORCE_ENABLE = 3, // force open uifirst
460+ FORCE_ENABLE_LIMIT = 4, // force open uifirst, but is limited by system specifications(filter, rotation..).
461+ FORCE_DISABLE_NONFOCUS = 5, // force close uifirst when only in nonfocus window
462+ FORCE_DISABLE_CARD = 6, // force close uifirst on card
463+};
464+ 
465+enum class SelfDrawingNodeType : uint8_t {
466+ DEFAULT,
467+ VIDEO,
468+ XCOM,
469+};
470+ 
471+enum class SurfaceWindowType : uint8_t {
472+ DEFAULT_WINDOW = 0,
473+ SYSTEM_SCB_WINDOW = 1,
474+ SCB_DESKTOP = 2,
475+ SCB_WALLPAPER = 3,
476+ SCB_SCREEN_LOCK = 4,
477+ SCB_NEGATIVE_SCREEN = 5,
478+ SCB_DROPDOWN_PANEL = 6,
479+ SCB_VOLUME_PANEL = 7,
480+ SCB_BANNER_NOTIFICATION = 8,
481+ SCB_GESTURE_BACK = 9,
482+ SCB_WINDOW_TYPE_BUTT = SCB_GESTURE_BACK + 1,
483+};
484+ 
485+struct RSSurfaceRenderNodeConfig {
486+ NodeId id = 0;
487+ std::string name = "SurfaceNode";
488+ RSSurfaceNodeType nodeType = RSSurfaceNodeType::DEFAULT;
489+ void* additionalData = nullptr;
490+ bool isTextureExportNode = false;
491+ bool isSync = false;
492+ enum SurfaceWindowType surfaceWindowType = SurfaceWindowType::DEFAULT_WINDOW;
493+ std::string bundleName = "";
494+};
495+ 
496+struct RSAdvancedDirtyConfig {
497+ // a threshold, if the number of rectangles is larger than it, we will merge all rectangles to one
498+ static const int RECT_NUM_MERGING_ALL = 35;
499+ // a threshold, if the number of rectangles is larger than it, we will merge all rectangles by level
500+ static const int RECT_NUM_MERGING_BY_LEVEL = 20;
501+ // maximal number of dirty rectangles in one surface/display node when advancedDirty is opened
502+ static const int MAX_RECT_NUM_EACH_NODE = 10;
503+ // number of dirty rectangles in one surface/display node when advancedDirty is closed
504+ static const int DISABLED_RECT_NUM_EACH_NODE = 1;
505+ // expected number of rectangles after merging
506+ static const int EXPECTED_OUTPUT_NUM = 3;
507+ // maximal tolerable cost in merging
508+ // if the merging cost of two rectangles is larger than it, we will not merge
509+ // later it could be set to a quantity related to screen area
510+ static const int MAX_TOLERABLE_COST = INT_MAX;
511+};
512+ 
513+static RSAdvancedDirtyConfig advancedDirtyConfig;
514+ 
515+// codes for arkui-x start
516+// types for RSSurfaceExt
517+enum class RSSurfaceExtType : uint8_t {
518+ NONE,
519+ SURFACE_TEXTURE,
520+ SURFACE_PLATFORM_TEXTURE,
521+};
522+ 
523+struct RSSurfaceExtConfig {
524+ RSSurfaceExtType type = RSSurfaceExtType::NONE;
525+ void* additionalData = nullptr;
526+};
527+struct FocusAppInfo {
528+ int32_t pid = -1;
529+ int32_t uid = -1;
530+ std::string bundleName = "";
531+ std::string abilityName = "";
532+ uint64_t focusNodeId = 0;
533+};
534+ 
535+using RSSurfaceTextureConfig = RSSurfaceExtConfig;
536+using RSSurfaceTextureAttachCallBack = std::function<void(int64_t textureId, bool attach)>;
537+using RSSurfaceTextureUpdateCallBack = std::function<void(std::vector<float>&)>;
538+using RSSurfaceTextureInitTypeCallBack = std::function<void(int32_t&)>;
539+// codes for arkui-x end
540+ 
541+struct RSDisplayNodeConfig {
542+ uint64_t screenId = 0;
543+ bool isMirrored = false;
544+ NodeId mirrorNodeId = 0;
545+ bool isSync = false;
546+ uint32_t mirrorSourceRotation = 4; // default INVALID_SCREEN_ROTATION
547+};
548+ 
549+// ability state of surface node
550+enum class RSSurfaceNodeAbilityState : uint8_t {
551+ BACKGROUND,
552+ FOREGROUND,
553+};
554+ 
555+struct SubSurfaceCntUpdateInfo {
556+ int updateCnt_ = 0;
557+ NodeId preParentId_ = INVALID_NODEID;
558+ NodeId curParentId_ = INVALID_NODEID;
559+};
560+ 
561+constexpr int64_t NS_TO_S = 1000000000;
562+constexpr int64_t NS_PER_MS = 1000000;
563+constexpr uint32_t SIZE_UPPER_LIMIT = 1000;
564+constexpr uint32_t PARTICLE_EMMITER_UPPER_LIMIT = 2000;
565+constexpr uint32_t PARTICLE_UPPER_LIMIT = 1000000;
566+ 
567+#if defined(M_PI)
568+constexpr float PI = M_PI;
569+#else
570+static const float PI = std::atanf(1.0) * 4;
571+#endif
572+ 
573+template<typename T>
574+inline constexpr bool ROSEN_EQ(const T& x, const T& y)
575+{
576+ if constexpr (std::is_floating_point<T>::value) {
577+ return (std::abs((x) - (y)) <= (std::numeric_limits<T>::epsilon()));
578+ } else {
579+ return x == y;
580+ }
581+}
582+ 
583+template<typename T>
584+inline bool ROSEN_EQ(T x, T y, T epsilon)
585+{
586+ return (std::abs((x) - (y)) <= (epsilon));
587+}
588+ 
589+template<typename T>
590+inline bool ROSEN_EQ(const std::weak_ptr<T>& x, const std::weak_ptr<T>& y)
591+{
592+ return !(x.owner_before(y) || y.owner_before(x));
593+}
594+ 
595+template<typename T>
596+inline constexpr bool ROSEN_NE(const T& x, const T& y)
597+{
598+ return !ROSEN_EQ(x, y);
599+}
600+ 
601+inline bool ROSEN_LNE(float left, float right) // less not equal
602+{
603+ constexpr float epsilon = -0.001f;
604+ return (left - right) < epsilon;
605+}
606+ 
607+inline bool ROSEN_GNE(float left, float right) //great not equal
608+{
609+ constexpr float epsilon = 0.001f;
610+ return (left - right) > epsilon;
611+}
612+ 
613+inline bool ROSEN_GE(float left, float right) //great or equal
614+{
615+ constexpr float epsilon = -0.001f;
616+ return (left - right) > epsilon;
617+}
618+ 
619+inline bool ROSEN_LE(float left, float right) //less or equal
620+{
621+ constexpr float epsilon = 0.001f;
622+ return (left - right) < epsilon;
623+}
624+ 
625+class MemObject {
626+public:
627+ explicit MemObject(size_t size) : size_(size) {}
628+ virtual ~MemObject() = default;
629+ 
630+ void* operator new(size_t size);
631+ void operator delete(void* ptr);
632+ 
633+ void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
634+ void operator delete(void* ptr, const std::nothrow_t&) noexcept;
635+ 
636+protected:
637+ size_t size_;
638+};
639+ 
640+inline constexpr pid_t ExtractPid(uint64_t id)
641+{
642+ // extract high 32 bits of nodeid/animationId/propertyId as pid
643+ return static_cast<pid_t>(id >> 32);
644+}
645+ 
646+inline constexpr int32_t ExtractTid(uint64_t token)
647+{
648+ // extract high 32 bits of token as tid
649+ return static_cast<int32_t>(token >> 32);
650+}
651+ 
652+inline constexpr uint64_t MakeNodeId(pid_t pid, uint32_t uid)
653+{
654+ // combine pid and uid to nodeid
655+ return (static_cast<uint64_t>(pid) << 32) | uid;
656+}
657+ 
658+/**
659+ * @brief Generate the unique nodeid for the node created on the server side.
660+ * @return uint64_t The generated nodeid.
661+ */
662+inline uint64_t GenerateUniqueNodeIdForRS()
663+{
664+ static std::atomic<uint32_t> uid { 0 };
665+ return MakeNodeId(getpid(), uid.fetch_add(1, std::memory_order_relaxed));
666+}
667+ 
668+template<class Container, class Predicate>
669+inline typename Container::size_type EraseIf(Container& container, Predicate pred)
670+{
671+ // erase from container if pred returns true, backport of c++20 std::remove_if
672+ typename Container::size_type oldSize = container.size();
673+ const typename Container::iterator end = container.end();
674+ for (typename Container::iterator iter = container.begin(); iter != end;) {
675+ if (pred(*iter)) {
676+ iter = container.erase(iter);
677+ } else {
678+ ++iter;
679+ }
680+ }
681+ return oldSize - container.size();
682+}
683+ 
684+enum class RSInterfaceErrorCode : uint32_t {
685+#undef NO_ERROR
686+ NO_ERROR = 0,
687+ NONSYSTEM_CALLING,
688+ NOT_SELF_CALLING,
689+ WRITE_PARCEL_ERROR,
690+ UNKNOWN_ERROR,
691+ NULLPTR_ERROR,
692+};
693+ 
694+enum DrawNodeType : uint32_t {
695+ PureContainerType = 0,
696+ MergeableType,
697+ DrawPropertyType,
698+ GeometryPropertyType
699+};
700+ 
701+enum class ComponentEnableSwitch : uint8_t {
702+ TEXTBLOB = 0,
703+ SVG,
704+ HMSYMBOL,
705+ CANVAS,
706+ MAX_VALUE,
707+};
708+typedef enum : uint32_t {
709+ SA_WATER_MARK_DEFAULT_SIZE = 0, // 512KB
710+ SA_WATER_MARK_MIDDLE_SIZE = 1, // 6M
711+ SA_WATER_MARK_BOTTOM = 2,
712+} SaSurfaceWatermarkMaxSize;
713+ 
714+typedef enum : uint32_t {
715+ WATER_MARK_SUCCESS = 0,
716+ WATER_MARK_NAME_ERROR = (1U << 1),
717+ WATER_MARK_RS_CONNECTION_ERROR = (1U << 2),
718+ WATER_MARK_IMG_ASTC_ERROR = (1U << 3),
719+ WATER_MARK_NOT_SUPPORT_ERROR = (1U << 4),
720+ WATER_MARK_RENDER_SERVICE_NULL = (1U << 5),
721+ WATER_MARK_WRITE_PARCEL_ERR = (1U << 6),
722+ WATER_MARK_IPC_ERROR = (1U << 7),
723+ WATER_MARK_READ_PARCEL_ERR = (1U << 8),
724+ WATER_MARK_RS_NOT_FIND_NODE = (1U << 9),
725+ WATER_MARK_PERMISSION_ERROR = (1U << 10),
726+ WATER_MARK_IMG_SIZE_ERROR = (1U << 11),
727+ WATER_MARK_NODE_NOT_SCREEN = (1U << 12),
728+ WATER_MARK_PIXELMAP_INVALID = (1U << 13),
729+ WATER_MARK_NOT_SURFACE_NODE_ERROR = (1U << 14),
730+ WATER_MARK_INVALID_WATERMARK_TYPE = (1U << 15),
731+} SurfaceWatermarkStatusCode;
732+ 
733+typedef enum : uint8_t {
734+ CUSTOM_WATER_MARK = 0,
735+ SYSTEM_WATER_MARK = 1,
736+ INVALID_WATER_MARK = 2,
737+} SurfaceWatermarkType;
738+ 
739+} // namespace Rosen
740+} // namespace OHOS
741+#endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COMMON_DEF_H
@@ -0,0 +1,552 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_RECT_H
17+#define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_RECT_H
18+#include <cmath>
19+#include <unordered_set>
20+#include <cinttypes>
21+#include "rs_vector2_mock.h"
22+#include "rs_vector4_mock.h"
23+#include "common/rect.h"
24+#include "transaction/rs_marshalling_helper.h"
25+ 
26+namespace OHOS {
27+namespace Rosen {
28+ 
29+namespace {
30+ constexpr uint32_t SIZE_FOUR = 4;
31+}
32+ 
33+template<typename T>
34+inline constexpr bool ROSEN_EQ_RECT(const T& x, const T& y)
35+{
36+ if constexpr (std::is_floating_point<T>::value) {
37+ return (std::abs((x) - (y)) <= (std::numeric_limits<T>::epsilon()));
38+ } else {
39+ return x == y;
40+ }
41+}
42+ 
43+template<typename T>
44+inline bool ROSEN_EQ_RECT(T x, T y, T epsilon)
45+{
46+ return (std::abs((x) - (y)) <= (epsilon));
47+}
48+ 
49+template<typename T>
50+inline bool ROSEN_EQ_RECT(const std::weak_ptr<T>& x, const std::weak_ptr<T>& y)
51+{
52+ return !(x.owner_before(y) || y.owner_before(x));
53+}
54+ 
55+template<typename T>
56+class RectT {
57+public:
58+ union {
59+ struct {
60+ T left_;
61+ T top_;
62+ T width_;
63+ T height_;
64+ };
65+ T data_[SIZE_FOUR]; // 4 is size of data or structure
66+ };
67+ 
68+ RectT()
69+ {
70+ data_[0] = 0;
71+ data_[1] = 0;
72+ data_[INDEX_TWO] = 0;
73+ data_[INDEX_THREE] = 0;
74+ }
75+ RectT(T left, T top, T width, T height)
76+ {
77+ data_[0] = left;
78+ data_[1] = top;
79+ data_[INDEX_TWO] = width;
80+ data_[INDEX_THREE] = height;
81+ }
82+ RectT(Vector4<T> vector)
83+ {
84+ // Tell the compiler there is no alias and to select wider load/store
85+ // instructions.
86+ T data0 = vector[0];
87+ T data1 = vector[1];
88+ T data2 = vector[INDEX_TWO];
89+ T data3 = vector[INDEX_THREE];
90+ data_[0] = data0;
91+ data_[1] = data1;
92+ data_[INDEX_TWO] = data2;
93+ data_[INDEX_THREE] = data3;
94+ }
95+ explicit RectT(const T* v)
96+ {
97+ // Tell the compiler there is no alias and to select wider load/store
98+ // instructions.
99+ T data0 = v[0];
100+ T data1 = v[1];
101+ T data2 = v[INDEX_TWO];
102+ T data3 = v[INDEX_THREE];
103+ data_[0] = data0;
104+ data_[1] = data1;
105+ data_[INDEX_TWO] = data2;
106+ data_[INDEX_THREE] = data3;
107+ }
108+ ~RectT() = default;
109+ 
110+ inline bool operator==(const RectT<T>& rect) const
111+ {
112+ return ROSEN_EQ_RECT<T>(left_, rect.left_) && ROSEN_EQ_RECT<T>(top_, rect.top_) &&
113+ ROSEN_EQ_RECT<T>(width_, rect.width_) && ROSEN_EQ_RECT<T>(height_, rect.height_);
114+ }
115+ 
116+ inline bool operator!=(const RectT<T>& rect) const
117+ {
118+ return !operator==(rect);
119+ }
120+ 
121+ inline bool IsNearEqual(const RectT<T>& rect, T threshold = std::numeric_limits<T>::epsilon()) const
122+ {
123+ return ROSEN_EQ_RECT<T>(left_, rect.left_, threshold) && ROSEN_EQ_RECT<T>(top_, rect.top_, threshold) &&
124+ ROSEN_EQ_RECT<T>(width_, rect.width_, threshold) && ROSEN_EQ_RECT<T>(height_, rect.height_, threshold);
125+ }
126+ 
127+ inline RectT& operator=(const RectT& other)
128+ {
129+ // Tell the compiler there is no alias and to select wider load/store
130+ // instructions.
131+ const T* oData = other.data_;
132+ T data0 = oData[0];
133+ T data1 = oData[1];
134+ T data2 = oData[INDEX_TWO];
135+ T data3 = oData[INDEX_THREE];
136+ data_[0] = data0;
137+ data_[1] = data1;
138+ data_[INDEX_TWO] = data2;
139+ data_[INDEX_THREE] = data3;
140+ return *this;
141+ }
142+ void SetAll(T left, T top, T width, T height)
143+ {
144+ data_[0] = left;
145+ data_[1] = top;
146+ data_[INDEX_TWO] = width;
147+ data_[INDEX_THREE] = height;
148+ }
149+ T GetRight() const
150+ {
151+ return left_ + width_;
152+ }
153+ T GetLeft() const
154+ {
155+ return left_;
156+ }
157+ T GetBottom() const
158+ {
159+ return top_ + height_;
160+ }
161+ T GetTop() const
162+ {
163+ return top_;
164+ }
165+ T GetWidth() const
166+ {
167+ return width_;
168+ }
169+ T GetHeight() const
170+ {
171+ return height_;
172+ }
173+ void SetRight(T right)
174+ {
175+ width_ = right - left_;
176+ }
177+ void SetBottom(T bottom)
178+ {
179+ height_ = bottom - top_;
180+ }
181+ void Move(T x, T y)
182+ {
183+ left_ += x;
184+ top_ += y;
185+ }
186+ void Clear()
187+ {
188+ left_ = 0;
189+ top_ = 0;
190+ width_ = 0;
191+ height_ = 0;
192+ }
193+ bool IsEmpty() const
194+ {
195+ return width_ <= 0 || height_ <= 0;
196+ }
197+ bool Intersect(T x, T y) const
198+ {
199+ return (x >= left_) && (x < GetRight()) && (y >= top_) && (y < GetBottom());
200+ }
201+ bool IsInsideOf(const RectT<T>& rect) const
202+ {
203+ return (top_ >= rect.top_ && left_ >= rect.left_ &&
204+ GetBottom() <= rect.GetBottom() && GetRight() <= rect.GetRight());
205+ }
206+ bool Intersect(const RectT<T>& other) const
207+ {
208+ return !IsEmpty() && !other.IsEmpty() && (left_ <= other.left_ + other.width_) &&
209+ (other.left_ <= left_ + width_) && (top_ <= other.top_ + other.height_) &&
210+ (other.top_ <= top_ + height_);
211+ }
212+ RectT<T> IntersectRect(const RectT<T>& rect) const
213+ {
214+ T left = std::max(left_, rect.left_);
215+ T top = std::max(top_, rect.top_);
216+ T width = std::min(GetRight(), rect.GetRight()) - left;
217+ T height = std::min(GetBottom(), rect.GetBottom()) - top;
218+ return ((width <= 0) || (height <= 0)) ? RectT<T>() : RectT<T>(left, top, width, height);
219+ }
220+ RectT<T> JoinRect(const RectT<T>& rect) const
221+ {
222+ if (rect.IsEmpty()) {
223+ return RectT<T>(left_, top_, width_, height_);
224+ }
225+ if (IsEmpty()) {
226+ return rect;
227+ }
228+ T left = std::min(left_, rect.left_);
229+ T top = std::min(top_, rect.top_);
230+ T width = std::max(GetRight(), rect.GetRight()) - left;
231+ T height = std::max(GetBottom(), rect.GetBottom()) - top;
232+ return ((width <= 0) || (height <= 0)) ? RectT<T>() : RectT<T>(left, top, width, height);
233+ }
234+ RectT<T> Offset(const T x, const T y) const
235+ {
236+ return RectT<T>(left_ + x, top_ + y, width_, height_);
237+ }
238+ template<typename P>
239+ RectT<P> ConvertTo() const
240+ {
241+ return RectT<P>(static_cast<P>(left_), static_cast<P>(top_), static_cast<P>(width_), static_cast<P>(height_));
242+ }
243+ std::string ToString() const
244+ {
245+ return std::string("[") + std::to_string(left_) + ", " + std::to_string(top_) + ", " +
246+ std::to_string(width_) + ", " + std::to_string(height_) + "]";
247+ }
248+ 
249+ // outset: left, top, right, bottom
250+ RectT<T> MakeOutset(Vector4<T> outset) const
251+ {
252+ return RectT(left_ - outset.x_,
253+ top_ - outset.y_,
254+ width_ + outset.x_ + outset.z_,
255+ height_ + outset.y_ + outset.w_);
256+ }
257+ 
258+ #ifdef ROSEN_OHOS
259+ bool Marshalling(Parcel& parcel) const
260+ {
261+ if (!(RSMarshallingHelper::Marshalling(parcel, left_) &&
262+ RSMarshallingHelper::Marshalling(parcel, top_) &&
263+ RSMarshallingHelper::Marshalling(parcel, width_) &&
264+ RSMarshallingHelper::Marshalling(parcel, height_))) {
265+ return false;
266+ }
267+ return true;
268+ }
269+ 
270+ [[nodiscard]] static RectT<T>* Unmarshalling(Parcel& parcel)
271+ {
272+ auto rect = std::make_unique<RectT<T>>();
273+ if (!(RSMarshallingHelper::Unmarshalling(parcel, rect->left_) &&
274+ RSMarshallingHelper::Unmarshalling(parcel, rect->top_) &&
275+ RSMarshallingHelper::Unmarshalling(parcel, rect->width_) &&
276+ RSMarshallingHelper::Unmarshalling(parcel, rect->height_))) {
277+ return nullptr;
278+ }
279+ return rect.release();
280+ }
281+ #endif
282+ 
283+ bool IsInfinite() const
284+ {
285+ return std::isinf(data_[0]) || std::isinf(data_[1]) ||
286+ std::isinf(data_[INDEX_TWO]) || std::isinf(data_[INDEX_THREE]);
287+ }
288+ 
289+ bool IsNaN() const
290+ {
291+ return std::isnan(data_[0]) || std::isnan(data_[1]) ||
292+ std::isnan(data_[INDEX_TWO]) || std::isnan(data_[INDEX_THREE]);
293+ }
294+ 
295+ bool IsValid() const
296+ {
297+ return !IsInfinite() && !IsNaN();
298+ }
299+};
300+ 
301+typedef RectT<int> RectI;
302+typedef RectT<float> RectF;
303+ 
304+/*
305+ RectIComparator: Used for comparing rects
306+ RectI_Hash_Func: provide hash value for rect comparing
307+*/
308+struct RectIComparator {
309+ bool operator()(const std::pair<uint64_t, RectI>& p1, const std::pair<uint64_t, RectI>& p2) const
310+ {
311+ return p2.second.IsInsideOf(p1.second);
312+ }
313+};
314+ 
315+struct RectI_Hash_Func {
316+ size_t operator()(const std::pair<uint64_t, RectI>& p) const
317+ {
318+ // this is set for all rects can be compared
319+ int hash_value = 0;
320+ return std::hash<int>()(hash_value);
321+ }
322+};
323+ 
324+typedef std::unordered_set<std::pair<uint64_t, RectI>, RectI_Hash_Func, RectIComparator> OcclusionRectISet;
325+
326+struct FilterRectIComparator {
327+ bool operator()(const std::pair<uint64_t, RectI>& p1, const std::pair<uint64_t, RectI>& p2) const
328+ {
329+ return p1.second == p2.second;
330+ }
331+};
332+ 
333+struct Filter_RectI_Hash_Func {
334+ size_t operator()(const std::pair<uint64_t, RectI>& p) const
335+ {
336+ return std::hash<uint64_t>()(p.first);
337+ }
338+};
339+typedef std::unordered_set<std::pair<uint64_t, RectI>, Filter_RectI_Hash_Func, FilterRectIComparator> FilterRectISet;
340+ 
341+template<typename T>
342+class RRectT {
343+public:
344+ RectT<T> rect_ = RectT<T>();
345+ Vector2f radius_[SIZE_FOUR] = { { 0, 0 } };
346+ 
347+ RRectT() {}
348+ ~RRectT() = default;
349+ 
350+ RRectT(RectT<T> rect, float rx, float ry)
351+ {
352+ rect_ = rect;
353+ Vector2f vec = Vector2f(rx, ry);
354+ radius_[0] = vec;
355+ radius_[1] = vec;
356+ radius_[INDEX_TWO] = vec;
357+ radius_[INDEX_THREE] = vec;
358+ }
359+ RRectT(RectT<T> rect, const Vector2f* radius)
360+ {
361+ rect_ = rect;
362+ radius_[0] = radius[0];
363+ radius_[1] = radius[1];
364+ radius_[INDEX_TWO] = radius[INDEX_TWO];
365+ radius_[INDEX_THREE] = radius[INDEX_THREE];
366+ }
367+ RRectT(RectT<T> rect, const Vector4f& radius)
368+ {
369+ rect_ = rect;
370+ radius_[0] = { radius[0], radius[0] };
371+ radius_[1] = { radius[1], radius[1] };
372+ radius_[INDEX_TWO] = { radius[INDEX_TWO], radius[INDEX_TWO] };
373+ radius_[INDEX_THREE] = { radius[INDEX_THREE], radius[INDEX_THREE] };
374+ }
375+ 
376+ void SetValues(RectT<T> rect, const Vector2f* radius)
377+ {
378+ rect_ = rect;
379+ radius_[0] = radius[0];
380+ radius_[1] = radius[1];
381+ radius_[INDEX_TWO] = radius[INDEX_TWO];
382+ radius_[INDEX_THREE] = radius[INDEX_THREE];
383+ }
384+ 
385+ std::string ToString() const
386+ {
387+ return std::string("rect [") +
388+ std::to_string(rect_.left_) + ", " +
389+ std::to_string(rect_.top_) + ", " +
390+ std::to_string(rect_.width_) + ", " +
391+ std::to_string(rect_.height_) +
392+ "] radius: [" +
393+ "(" + std::to_string(radius_[0].x_) + "," + std::to_string(radius_[0].y_) + ")," +
394+ "(" + std::to_string(radius_[1].x_) + "," + std::to_string(radius_[1].y_) + ")," +
395+ "(" + std::to_string(radius_[INDEX_TWO].x_) + "," + std::to_string(radius_[INDEX_TWO].y_) + ")," +
396+ "(" + std::to_string(radius_[INDEX_THREE].x_) + "," + std::to_string(radius_[INDEX_THREE].y_) + ")]";
397+ }
398+ 
399+ RRectT Inset(const Vector4<T> radius) const;
400+ RRectT operator-(const RRectT<T>& other) const;
401+ RRectT operator+(const RRectT<T>& other) const;
402+ RRectT operator/(float scale) const;
403+ RRectT operator*(float scale) const;
404+ RRectT& operator-=(const RRectT<T>& other);
405+ RRectT& operator+=(const RRectT<T>& other);
406+ RRectT& operator*=(float scale);
407+ RRectT& operator=(const RRectT<T>& other);
408+ bool operator==(const RRectT& other) const;
409+ bool operator!=(const RRectT& other) const;
410+ bool IsNearEqual(const RRectT& other, T threshold = std::numeric_limits<T>::epsilon()) const;
411+};
412+ 
413+typedef RRectT<float> RRect;
414+ 
415+template<typename T>
416+RRectT<T> RRectT<T>::Inset(const Vector4<T> width) const
417+{
418+ RRectT<T> rrect;
419+ rrect.rect_.SetAll(rect_.GetLeft() + width.x_, rect_.GetTop() + width.y_,
420+ rect_.GetWidth() - (width.x_ + width.z_),
421+ rect_.GetHeight() - (width.y_ + width.w_));
422+
423+ rrect.radius_[0] = radius_[0] - Vector2(width.x_, width.y_); // 0: topLeft Corner
424+ rrect.radius_[1] = radius_[1] - Vector2(width.z_, width.y_); // 1: topRight Corner
425+ rrect.radius_[INDEX_TWO] = radius_[INDEX_TWO] - Vector2(width.z_, width.w_); // 2: bottomRight Corner
426+ rrect.radius_[INDEX_THREE] = radius_[INDEX_THREE] - Vector2(width.x_, width.w_); // 3: bottomLeft Corner
427+ return rrect;
428+}
429+ 
430+template<typename T>
431+RRectT<T> RRectT<T>::operator-(const RRectT<T>& other) const
432+{
433+ RRectT<T> rrect;
434+ rrect.rect_.SetAll(rect_.GetLeft() - other.rect_.GetLeft(), rect_.GetTop() - other.rect_.GetTop(),
435+ rect_.GetWidth() - other.rect_.GetWidth(), rect_.GetHeight() - other.rect_.GetHeight());
436+ for (int index = 0; index < SIZE_FOUR; index++) {
437+ rrect.radius_[index] = radius_[index] - other.radius_[index];
438+ }
439+ return rrect;
440+}
441+ 
442+template<typename T>
443+RRectT<T> RRectT<T>::operator+(const RRectT<T>& other) const
444+{
445+ RRectT<T> rrect;
446+ rrect.rect_.SetAll(rect_.GetLeft() + other.rect_.GetLeft(), rect_.GetTop() + other.rect_.GetTop(),
447+ rect_.GetWidth() + other.rect_.GetWidth(), rect_.GetHeight() + other.rect_.GetHeight());
448+ for (int index = 0; index < SIZE_FOUR; index++) {
449+ rrect.radius_[index] = radius_[index] + other.radius_[index];
450+ }
451+ return rrect;
452+}
453+ 
454+template<typename T>
455+RRectT<T> RRectT<T>::operator/(float scale) const
456+{
457+ if (scale == 0) {
458+ return *this;
459+ }
460+ if (ROSEN_EQ_RECT<float>(scale, 0)) {
461+ return *this;
462+ }
463+ RRectT<T> rrect;
464+ rrect.rect_.SetAll(rect_.GetLeft() / scale, rect_.GetTop() / scale,
465+ rect_.GetWidth() / scale, rect_.GetHeight() / scale);
466+ for (int index = 0; index < SIZE_FOUR; index++) {
467+ rrect.radius_[index] = radius_[index] / scale;
468+ }
469+ return rrect;
470+}
471+ 
472+template<typename T>
473+RRectT<T> RRectT<T>::operator*(float scale) const
474+{
475+ RRectT<T> rrect;
476+ rrect.rect_.SetAll(rect_.GetLeft() * scale, rect_.GetTop() * scale,
477+ rect_.GetWidth() * scale, rect_.GetHeight() * scale);
478+ for (int index = 0; index < SIZE_FOUR; index++) {
479+ rrect.radius_[index] = radius_[index] * scale;
480+ }
481+ return rrect;
482+}
483+ 
484+template<typename T>
485+RRectT<T>& RRectT<T>::operator-=(const RRectT<T>& other)
486+{
487+ rect_.SetAll(rect_.GetLeft() - other.rect_.GetLeft(), rect_.GetTop() - other.rect_.GetTop(),
488+ rect_.GetWidth() - other.rect_.GetWidth(), rect_.GetHeight() - other.rect_.GetHeight());
489+ for (int index = 0; index < SIZE_FOUR; index++) {
490+ radius_[index] = radius_[index] - other.radius_[index];
491+ }
492+ return *this;
493+}
494+ 
495+template<typename T>
496+RRectT<T>& RRectT<T>::operator+=(const RRectT<T>& other)
497+{
498+ rect_.SetAll(rect_.GetLeft() + other.rect_.GetLeft(), rect_.GetTop() + other.rect_.GetTop(),
499+ rect_.GetWidth() + other.rect_.GetWidth(), rect_.GetHeight() + other.rect_.GetHeight());
500+ for (int index = 0; index < SIZE_FOUR; index++) {
501+ radius_[index] = radius_[index] + other.radius_[index];
502+ }
503+ return *this;
504+}
505+ 
506+template<typename T>
507+RRectT<T>& RRectT<T>::operator*=(float scale)
508+{
509+ rect_.SetAll(rect_.GetLeft() * scale, rect_.GetTop() * scale,
510+ rect_.GetWidth() * scale, rect_.GetHeight() * scale);
511+ for (int index = 0; index < SIZE_FOUR; index++) {
512+ radius_[index] = radius_[index] * scale;
513+ }
514+ return *this;
515+}
516+ 
517+template<typename T>
518+RRectT<T>& RRectT<T>::operator=(const RRectT<T>& other)
519+{
520+ rect_ = other.rect_;
521+ for (int index = 0; index < SIZE_FOUR; index++) {
522+ radius_[index] = other.radius_[index];
523+ }
524+ return *this;
525+}
526+ 
527+template<typename T>
528+inline bool RRectT<T>::operator==(const RRectT& other) const
529+{
530+ return (rect_ == other.rect_) && (radius_[0] == other.radius_[0]) &&
531+ (radius_[1] == other.radius_[1]) && (radius_[INDEX_TWO] == other.radius_[INDEX_TWO]) &&
532+ (radius_[INDEX_THREE] == other.radius_[INDEX_THREE]);
533+}
534+ 
535+template<typename T>
536+inline bool RRectT<T>::operator!=(const RRectT& other) const
537+{
538+ return !operator==(other);
539+}
540+ 
541+template<typename T>
542+inline bool RRectT<T>::IsNearEqual(const RRectT& rrectT, T threshold) const
543+{
544+ return (rect_.IsNearEqual(rrectT.rect_, threshold)) && (radius_[0].IsNearEqual(rrectT.radius_[0], threshold)) &&
545+ (radius_[1].IsNearEqual(rrectT.radius_[1], threshold)) &&
546+ (radius_[INDEX_TWO].IsNearEqual(rrectT.radius_[INDEX_TWO], threshold)) &&
547+ (radius_[INDEX_THREE].IsNearEqual(rrectT.radius_[INDEX_THREE], threshold));
548+}
549+ 
550+} // namespace Rosen
551+} // namespace OHOS
552+#endif
@@ -0,0 +1,187 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_
17+#define INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_
18+ 
19+#include <cinttypes>
20+ 
21+namespace OHOS {
22+namespace Media {
23+#ifdef _WIN32
24+#define NATIVEEXPORT __declspec(dllexport)
25+#else
26+#define NATIVEEXPORT
27+#endif
28+ 
29+enum class AllocatorType : int32_t {
30+ // keep same with java AllocatorType
31+ DEFAULT = 0,
32+ HEAP_ALLOC = 1,
33+ SHARE_MEM_ALLOC = 2,
34+ CUSTOM_ALLOC = 3, // external
35+ DMA_ALLOC = 4, // SurfaceBuffer
36+};
37+ 
38+enum class ColorSpace : int32_t {
39+ // unknown color space.
40+ UNKNOWN = 0,
41+ 
42+ // based on SMPTE RP 431-2-2007 & IEC 61966-2.1:1999.
43+ DISPLAY_P3 = 1,
44+ 
45+ // standard Red Green Blue based on IEC 61966-2.1:1999.
46+ SRGB = 2,
47+ 
48+ // SRGB with a linear transfer function based on IEC 61966-2.1:1999.
49+ LINEAR_SRGB = 3,
50+ 
51+ // based on IEC 61966-2-2:2003.
52+ EXTENDED_SRGB = 4,
53+ 
54+ // based on IEC 61966-2-2:2003.
55+ LINEAR_EXTENDED_SRGB = 5,
56+ 
57+ // based on standard illuminant D50 as the white point.
58+ GENERIC_XYZ = 6,
59+ 
60+ // based on CIE XYZ D50 as the profile conversion space.
61+ GENERIC_LAB = 7,
62+ 
63+ // based on SMPTE ST 2065-1:2012.
64+ ACES = 8,
65+ 
66+ // based on Academy S-2014-004.
67+ ACES_CG = 9,
68+ 
69+ // based on Adobe RGB (1998).
70+ ADOBE_RGB_1998 = 10,
71+ 
72+ // based on SMPTE RP 431-2-2007.
73+ DCI_P3 = 11,
74+ 
75+ // based on Rec. ITU-R BT.709-5.
76+ ITU_709 = 12,
77+ 
78+ // based on Rec. ITU-R BT.2020-1.
79+ ITU_2020 = 13,
80+ 
81+ // based on ROMM RGB ISO 22028-2:2013.
82+ ROMM_RGB = 14,
83+ 
84+ // based on 1953 standard.
85+ NTSC_1953 = 15,
86+ 
87+ // based on SMPTE C.
88+ SMPTE_C = 16,
89+};
90+ 
91+enum class EncodedFormat : int32_t {
92+ UNKNOWN = 0,
93+ JPEG = 1,
94+ PNG = 2,
95+ GIF = 3,
96+ HEIF = 4,
97+};
98+ 
99+enum class PixelFormat : int32_t {
100+ UNKNOWN = 0,
101+ ARGB_8888 = 1, // Each pixel is stored on 4 bytes.
102+ RGB_565 = 2, // Each pixel is stored on 2 bytes
103+ RGBA_8888 = 3,
104+ BGRA_8888 = 4,
105+ RGB_888 = 5,
106+ ALPHA_8 = 6,
107+ RGBA_F16 = 7,
108+ NV21 = 8, // Each pixel is sorted on 3/2 bytes.
109+ NV12 = 9,
110+ CMYK = 10,
111+ YCBCR_P010 = 11,
112+ YCRCB_P010 = 12,
113+ RGBA_1010102 = 14,
114+};
115+ 
116+enum class AlphaType : int32_t {
117+ IMAGE_ALPHA_TYPE_UNKNOWN = 0,
118+ IMAGE_ALPHA_TYPE_OPAQUE = 1, // image pixels are stored as opaque.
119+ IMAGE_ALPHA_TYPE_PREMUL = 2, // image have alpha component, and all pixels have premultiplied by alpha value.
120+ IMAGE_ALPHA_TYPE_UNPREMUL = 3, // image have alpha component, and all pixels stored without premultiply alpha value.
121+};
122+ 
123+enum class MemoryUsagePreference : int32_t {
124+ DEFAULT = 0,
125+ LOW_RAM = 1, // low memory
126+};
127+ 
128+enum class FinalOutputStep : int32_t {
129+ NO_CHANGE = 0,
130+ CONVERT_CHANGE = 1,
131+ ROTATE_CHANGE = 2,
132+ SIZE_CHANGE = 3,
133+ DENSITY_CHANGE = 4
134+};
135+ 
136+struct Position {
137+ int32_t x = 0;
138+ int32_t y = 0;
139+};
140+ 
141+struct Rect {
142+ int32_t left = 0;
143+ int32_t top = 0;
144+ int32_t width = 0;
145+ int32_t height = 0;
146+};
147+ 
148+struct Size {
149+ int32_t width = 0;
150+ int32_t height = 0;
151+};
152+ 
153+struct ImageInfo {
154+ Size size;
155+ PixelFormat pixelFormat = PixelFormat::UNKNOWN;
156+ ColorSpace colorSpace = ColorSpace::SRGB;
157+ AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
158+ int32_t baseDensity = 0;
159+};
160+ 
161+struct DecodeOptions {
162+ int32_t fitDensity = 0;
163+ Rect CropRect;
164+ Size desiredSize;
165+ Rect desiredRegion;
166+ float rotateDegrees = 0;
167+ uint32_t rotateNewDegrees = 0;
168+ static constexpr uint32_t DEFAULT_SAMPLE_SIZE = 1;
169+ uint32_t sampleSize = DEFAULT_SAMPLE_SIZE;
170+ PixelFormat desiredPixelFormat = PixelFormat::UNKNOWN;
171+ AllocatorType allocatorType = AllocatorType::HEAP_ALLOC;
172+ ColorSpace desiredColorSpace = ColorSpace::SRGB;
173+ bool allowPartialImage = true;
174+ bool editable = false;
175+ MemoryUsagePreference preference = MemoryUsagePreference::DEFAULT;
176+};
177+ 
178+enum class ScaleMode : int32_t {
179+ FIT_TARGET_SIZE = 0,
180+ CENTER_CROP = 1,
181+};
182+ 
183+enum class IncrementalMode { FULL_DATA = 0, INCREMENTAL_DATA = 1 };
184+} // namespace Media
185+} // namespace OHOS
186+ 
187+#endif // INTERFACES_INNERKITS_INCLUDE_IMAGE_TYPE_H_
@@ -0,0 +1,42 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_NODE_MAP_H
17+#define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_NODE_MAP_H
18+ 
19+#include <mutex>
20+#include <unordered_map>
21+#include "ui/rs_node.h"
22+ 
23+namespace OHOS {
24+namespace Rosen {
25+ 
26+class RSNodeMap final {
27+public:
28+ static const RSNodeMap& Instance()
29+ {
30+ static RSNodeMap instance_;
31+ return instance_;
32+ }
33+ 
34+ std::shared_ptr<RSBaseNode> GetNode(NodeId id) const
35+ {
36+ return nullptr;
37+ }
38+};
39+} // namespace Rosen
40+} // namespace OHOS
41+ 
42+#endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_NODE_MAP_H
@@ -0,0 +1,42 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_H_
17+#define INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_H_
18+ 
19+#include "parcel.h"
20+#include "image_type.h"
21+ 
22+namespace OHOS {
23+namespace Media {
24+class PixelMap : public Parcelable {
25+public:
26+ int32_t GetWidth()
27+ {
28+ return 0;
29+ }
30+ 
31+ int32_t GetHeight()
32+ {
33+ return 0;
34+ }
35+ static PixelMap* Unmarshalling(Parcel& parcel)
36+ {
37+ return nullptr;
38+ }
39+};
40+}
41+}
42+#endif // INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_H_
@@ -0,0 +1,125 @@
1+/*
2+ * Copyright (c) 2025 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+#include "rs_mock_impl.h"
17+ 
18+namespace OHOS {
19+namespace Rosen {
20+std::shared_ptr<RsMockImpl> RsMockImpl::instance_ = nullptr;
21+std::mutex RsMockImpl::mutex_;
22+ 
23+RsMockImpl& RsMockImpl::GetInstance()
24+{
25+ if (instance_ != nullptr) {
26+ return *instance_;
27+ }
28+ std::unique_lock<std::mutex> lock(mutex_);
29+ if (instance_ != nullptr) {
30+ return *instance_;
31+ }
32+ instance_ = std::make_shared<RsMockImpl>();
33+ return *instance_;
34+}
35+ 
36+void RsMockImpl::Rest()
37+{
38+ std::unique_lock<std::mutex> lock(mutex_);
39+ instance_ == nullptr;
40+}
41+ 
42+void RsMockImpl::Init(const ProductConfigMock& data)
43+{
44+ productConfig_ = data;
45+}
46+ 
47+int32_t RsMockImpl::SetScreenChangeCallback(const ScreenChangeCallback& callback)
48+{
49+ screenChangeCallback_ = callback;
50+ return 0;
51+}
52+ 
53+void RsMockImpl::TriggerScreenChange(ScreenId screenId, ScreenEvent screenEvent, ScreenChangeReason reason)
54+{
55+ if (screenChangeCallback_ != nullptr) {
56+ screenChangeCallback_(screenId, screenEvent, reason);
57+ }
58+}
59+ 
60+RSScreenModeInfo RsMockImpl::GetScreenActiveMode(ScreenId id)
61+{
62+ auto modelIdIt = productConfig_.screenActiveModeId_.find(id);
63+ if (modelIdIt == productConfig_.screenActiveModeId_.end()) {
64+ return RSScreenModeInfo();
65+ }
66+ 
67+ auto modelInfoIt = productConfig_.screenModeInfo_.find(id);
68+ if (modelInfoIt != productConfig_.screenModeInfo_.end() && modelInfoIt->second.size() > modelIdIt->second) {
69+ return modelInfoIt->second[modelIdIt->second];
70+ }
71+ return RSScreenModeInfo();
72+}
73+ 
74+RSScreenCapability RsMockImpl::GetScreenCapability(ScreenId id)
75+{
76+ auto capIt = productConfig_.screenCapability_.find(id);
77+ if (capIt == productConfig_.screenCapability_.end()) {
78+ return RSScreenCapability();
79+ }
80+ return capIt->second;
81+}
82+ 
83+int32_t RsMockImpl::SetScreenCorrection(ScreenId id, ScreenRotation screenRotation)
84+{
85+ screenCorrectionMap_[id] = screenRotation;
86+ return 0;
87+}
88+ 
89+std::vector<RSScreenModeInfo> RsMockImpl::GetScreenSupportedModes(ScreenId id)
90+{
91+ auto modelInfoIt = productConfig_.screenModeInfo_.find(id);
92+ if (modelInfoIt != productConfig_.screenModeInfo_.end()) {
93+ return modelInfoIt->second;
94+ }
95+ return std::vector<RSScreenModeInfo>();
96+}
97+ 
98+int32_t RsMockImpl::GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats)
99+{
100+ auto it = productConfig_.screenHdrFormat_.find(id);
101+ if (it != productConfig_.screenHdrFormat_.end()) {
102+ hdrFormats = it->second;
103+ }
104+ 
105+ return 0;
106+}
107+ 
108+int32_t RsMockImpl::GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces)
109+{
110+ auto it = productConfig_.screenColorSpace_.find(id);
111+ if (it != productConfig_.screenColorSpace_.end()) {
112+ colorSpaces = it->second;
113+ }
114+ 
115+ return 0;
116+}
117+ 
118+int32_t RsMockImpl::RegisterHgmRefreshRateUpdateCallback(const HgmRefreshRateUpdateCallback& callback)
119+{
120+ hgmRefreshRateUpdateCallback_ = callback;
121+ return 0;
122+}
123+ 
124+} // namespace Rosen
125+} // namespace OHOS
@@ -0,0 +1,58 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef OHOS_ROSEN_DMS_RS_MOCK_IMPL_H
18+#define OHOS_ROSEN_DMS_RS_MOCK_IMPL_H
19+ 
20+#include <mutex>
21+#include "transaction/rs_interfaces.h"
22+#include "product_config_mock.h"
23+ 
24+namespace OHOS {
25+namespace Rosen {
26+class RsMockImpl {
27+public:
28+ static RsMockImpl& GetInstance();
29+ static void Rest();
30+ RsMockImpl() = default;
31+ virtual ~RsMockImpl() = default;
32+ 
33+ virtual int32_t SetScreenChangeCallback(const ScreenChangeCallback& callback);
34+ virtual RSScreenModeInfo GetScreenActiveMode(ScreenId id);
35+ virtual RSScreenCapability GetScreenCapability(ScreenId id);
36+ virtual int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation);
37+ virtual std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);
38+ virtual int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats);
39+ virtual int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
40+ virtual int32_t RegisterHgmRefreshRateUpdateCallback(const HgmRefreshRateUpdateCallback& callback);
41+ 
42+ // event trigger
43+ void TriggerScreenChange(ScreenId screenId, ScreenEvent screenEvent, ScreenChangeReason reason);
44+ 
45+ void Init(const ProductConfigMock& data);
46+ 
47+private:
48+ static std::shared_ptr<RsMockImpl> instance_;
49+ static std::mutex mutex_;
50+ ScreenChangeCallback screenChangeCallback_;
51+ HgmRefreshRateUpdateCallback hgmRefreshRateUpdateCallback_;
52+ 
53+ ProductConfigMock productConfig_;
54+ std::map<ScreenId, ScreenRotation> screenCorrectionMap_;
55+};
56+} // namespace Rosen
57+} // namespace OHOS
58+#endif
@@ -0,0 +1,191 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef RS_SCREEN_CAPABILITY
17+#define RS_SCREEN_CAPABILITY
18+ 
19+#include <cstdint>
20+#include <parcel.h>
21+#include <refbase.h>
22+#include <string>
23+#include <vector>
24+ 
25+#include "screen_manager/screen_types.h"
26+ 
27+namespace OHOS {
28+namespace Rosen {
29+class RSScreenProps : public Parcelable {
30+public:
31+ RSScreenProps() = default;
32+ RSScreenProps(std::string propName, uint32_t propId, uint64_t value)
33+ : propName_(propName),
34+ propId_(propId),
35+ value_(value)
36+ {
37+ }
38+ ~RSScreenProps() = default;
39+ [[nodiscard]] static RSScreenProps* Unmarshalling(Parcel& parcel)
40+ {
41+ return nullptr;
42+ }
43+ bool Marshalling(Parcel& parcel) const override
44+ {
45+ return true;
46+ }
47+ 
48+ void SetPropertyName(const std::string& propName)
49+ {
50+ propName_ = propName;
51+ }
52+ 
53+ void SetPropId(uint32_t propId)
54+ {
55+ propId_ = propId;
56+ }
57+ 
58+ void SetValue(uint64_t value)
59+ {
60+ value_ = value;
61+ }
62+ 
63+ const std::string& GetPropertyName() const
64+ {
65+ return propName_;
66+ }
67+ 
68+ uint32_t GetPropId() const
69+ {
70+ return propId_;
71+ }
72+ 
73+ uint64_t GetValue() const
74+ {
75+ return value_;
76+ }
77+ 
78+private:
79+ std::string propName_;
80+ uint32_t propId_;
81+ uint64_t value_;
82+};
83+ 
84+class RSScreenCapability : public Parcelable {
85+public:
86+ RSScreenCapability() = default;
87+ ~RSScreenCapability() = default;
88+ [[nodiscard]] static RSScreenCapability* Unmarshalling(Parcel& parcel)
89+ {
90+ return nullptr;
91+ }
92+ bool Marshalling(Parcel& parcel) const override
93+ {
94+ return true;
95+ }
96+ 
97+ void SetName(const std::string& name)
98+ {
99+ name_ = name;
100+ }
101+ 
102+ void SetType(ScreenInterfaceType type)
103+ {
104+ type_ = type;
105+ }
106+ 
107+ void SetPhyWidth(uint32_t phyWidth)
108+ {
109+ phyWidth_ = phyWidth;
110+ }
111+ 
112+ void SetPhyHeight(uint32_t phyHeight)
113+ {
114+ phyHeight_ = phyHeight;
115+ }
116+ 
117+ void SetSupportLayers(uint32_t supportLayers)
118+ {
119+ supportLayers_ = supportLayers;
120+ }
121+ 
122+ void SetVirtualDispCount(uint32_t virtualDispCount)
123+ {
124+ virtualDispCount_ = virtualDispCount;
125+ }
126+ 
127+ void SetSupportWriteBack(bool supportWriteBack)
128+ {
129+ supportWriteBack_ = supportWriteBack;
130+ }
131+ 
132+ void SetProps(std::vector<RSScreenProps> props)
133+ {
134+ props_ = std::move(props);
135+ }
136+ 
137+ const std::string& GetName() const
138+ {
139+ return name_;
140+ }
141+ 
142+ ScreenInterfaceType GetType() const
143+ {
144+ return type_;
145+ }
146+ 
147+ uint32_t GetPhyWidth() const
148+ {
149+ return phyWidth_;
150+ }
151+ 
152+ uint32_t GetPhyHeight() const
153+ {
154+ return phyHeight_;
155+ }
156+ 
157+ uint32_t GetSupportLayers() const
158+ {
159+ return supportLayers_;
160+ }
161+ 
162+ uint32_t GetVirtualDispCount() const
163+ {
164+ return virtualDispCount_;
165+ }
166+ 
167+ bool GetSupportWriteBack() const
168+ {
169+ return supportWriteBack_;
170+ }
171+ 
172+ const std::vector<RSScreenProps>& GetProps() const
173+ {
174+ return props_;
175+ }
176+ 
177+private:
178+ std::string name_;
179+ ScreenInterfaceType type_ = DISP_INVALID;
180+ uint32_t phyWidth_ = 0;
181+ uint32_t phyHeight_ = 0;
182+ uint32_t supportLayers_ = 0;
183+ uint32_t virtualDispCount_ = 0;
184+ bool supportWriteBack_ = false;
185+ std::vector<RSScreenProps> props_;
186+};
187+ 
188+} // namespace Rosen
189+} // namespace OHOS
190+ 
191+#endif // RS_SCREEN_CAPABILITY
@@ -0,0 +1,313 @@
1+/*
2+ * Copyright (c) 2025 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+#ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_VECTOR2_H
17+#define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_VECTOR2_H
18+#include <cmath>
19+ 
20+namespace OHOS {
21+namespace Rosen {
22+template<typename T>
23+inline constexpr bool ROSEN_EQ2(const T& x, const T& y)
24+{
25+ if constexpr (std::is_floating_point<T>::value) {
26+ return (std::abs((x) - (y)) <= (std::numeric_limits<T>::epsilon()));
27+ } else {
28+ return x == y;
29+ }
30+}
31+ 
32+template<typename T>
33+class Vector2 {
34+public:
35+ static constexpr uint32_t V2SIZE = 2;
36+ static constexpr size_t DATA_SIZE = sizeof(T) * V2SIZE;
37+ union {
38+ struct {
39+ T x_;
40+ T y_;
41+ };
42+ T data_[2];
43+ };
44+ 
45+ Vector2();
46+ Vector2(T x, T y);
47+ explicit Vector2(const T* v);
48+ virtual ~Vector2();
49+ 
50+ Vector2 Normalized() const;
51+ T Dot(const Vector2<T>& other) const;
52+ T Cross(const Vector2<T>& other) const;
53+ Vector2 operator-() const;
54+ Vector2 operator-(const Vector2<T>& other) const;
55+ Vector2 operator+(const Vector2<T>& other) const;
56+ Vector2 operator/(T scale) const;
57+ Vector2 operator*(T scale) const;
58+ Vector2 operator*(const Vector2<T>& other) const;
59+ Vector2& operator*=(const Vector2<T>& other);
60+ Vector2& operator+=(const Vector2<T>& other);
61+ Vector2& operator-=(const Vector2<T>& other);
62+ Vector2& operator=(const Vector2& other);
63+ T operator[](int index) const;
64+ T& operator[](int index);
65+ bool operator==(const Vector2& other) const;
66+ bool operator!=(const Vector2& other) const;
67+ bool IsNearEqual(const Vector2& other, T threshold = std::numeric_limits<T>::epsilon()) const;
68+ 
69+ T* GetData();
70+ 
71+ T GetLength() const;
72+ T GetSqrLength() const;
73+ T Normalize();
74+ bool IsInfinite() const;
75+ bool IsNaN() const;
76+ bool IsValid() const;
77+};
78+ 
79+typedef Vector2<int> UIPoint;
80+typedef Vector2<float> Vector2f;
81+typedef Vector2<double> Vector2d;
82+template<typename T>
83+Vector2<T>::Vector2()
84+{
85+ data_[0] = 0;
86+ data_[1] = 0;
87+}
88+ 
89+template<typename T>
90+Vector2<T>::Vector2(T x, T y)
91+{
92+ data_[0] = x;
93+ data_[1] = y;
94+}
95+ 
96+template<typename T>
97+Vector2<T>::Vector2(const T* v)
98+{
99+ data_[0] = v[0];
100+ data_[1] = v[1];
101+}
102+ 
103+template<typename T>
104+Vector2<T>::~Vector2()
105+{}
106+ 
107+template<typename T>
108+Vector2<T> Vector2<T>::Normalized() const
109+{
110+ Vector2<T> rNormalize(*this);
111+ rNormalize.Normalize();
112+ return rNormalize;
113+}
114+ 
115+template<typename T>
116+T Vector2<T>::Dot(const Vector2<T>& other) const
117+{
118+ const T* oData = other.data_;
119+ T sum = data_[0] * oData[0];
120+ sum += data_[1] * oData[1];
121+ return sum;
122+}
123+ 
124+template<typename T>
125+T Vector2<T>::Cross(const Vector2<T>& other) const
126+{
127+ const T* oData = other.data_;
128+ 
129+ return data_[0] * oData[1] - data_[1] * oData[0];
130+}
131+ 
132+template<typename T>
133+Vector2<T> Vector2<T>::operator-() const
134+{
135+ Vector2<T> rNeg;
136+ T* rData = rNeg.data_;
137+ rData[0] = -data_[0];
138+ rData[1] = -data_[1];
139+ return rNeg;
140+}
141+ 
142+template<typename T>
143+Vector2<T> Vector2<T>::operator-(const Vector2<T>& other) const
144+{
145+ Vector2<T> rSub(*this);
146+ T* rData = rSub.data_;
147+ const T* oData = other.data_;
148+ rData[0] -= oData[0];
149+ rData[1] -= oData[1];
150+ return rSub;
151+}
152+ 
153+template<typename T>
154+Vector2<T> Vector2<T>::operator+(const Vector2<T>& other) const
155+{
156+ Vector2<T> rAdd(*this);
157+ return rAdd += other;
158+}
159+ 
160+template<typename T>
161+Vector2<T> Vector2<T>::operator/(T scale) const
162+{
163+ if (ROSEN_EQ2<T>(scale, 0)) {
164+ return *this;
165+ }
166+ const T invScale = 1.0f / scale;
167+ return (*this) * invScale;
168+}
169+ 
170+template<typename T>
171+Vector2<T> Vector2<T>::operator*(T scale) const
172+{
173+ Vector2<T> rMult(*this);
174+ T* rData = rMult.data_;
175+ 
176+ rData[0] *= scale;
177+ rData[1] *= scale;
178+ return rMult;
179+}
180+ 
181+template<typename T>
182+Vector2<T> Vector2<T>::operator*(const Vector2<T>& other) const
183+{
184+ Vector2<T> rMult(*this);
185+ return rMult *= other;
186+}
187+ 
188+template<typename T>
189+Vector2<T>& Vector2<T>::operator*=(const Vector2<T>& other)
190+{
191+ const T* oData = other.data_;
192+ data_[0] *= oData[0];
193+ data_[1] *= oData[1];
194+ return *this;
195+}
196+ 
197+template<typename T>
198+Vector2<T>& Vector2<T>::operator+=(const Vector2<T>& other)
199+{
200+ data_[0] += other.data_[0];
201+ data_[1] += other.data_[1];
202+ return *this;
203+}
204+ 
205+template<typename T>
206+Vector2<T>& Vector2<T>::operator-=(const Vector2<T>& other)
207+{
208+ data_[0] -= other.data_[0];
209+ data_[1] -= other.data_[1];
210+ return *this;
211+}
212+ 
213+template<typename T>
214+Vector2<T>& Vector2<T>::operator=(const Vector2<T>& other)
215+{
216+ const T* oData = other.data_;
217+ data_[0] = oData[0];
218+ data_[1] = oData[1];
219+ return *this;
220+}
221+ 
222+template<typename T>
223+T Vector2<T>::operator[](int index) const
224+{
225+ return data_[index];
226+}
227+ 
228+template<typename T>
229+inline T& Vector2<T>::operator[](int index)
230+{
231+ return data_[index];
232+}
233+ 
234+template<typename T>
235+inline bool Vector2<T>::operator==(const Vector2& other) const
236+{
237+ const T* oData = other.data_;
238+ 
239+ return (ROSEN_EQ2<T>(data_[0], oData[0])) && (ROSEN_EQ2<T>(data_[1], oData[1]));
240+}
241+ 
242+template<typename T>
243+inline bool Vector2<T>::operator!=(const Vector2& other) const
244+{
245+ const T* oData = other.data_;
246+ 
247+ return (!ROSEN_EQ2<T>(data_[0], oData[0])) || (!ROSEN_EQ2<T>(data_[1], oData[1]));
248+}
249+ 
250+template<typename T>
251+bool Vector2<T>::IsNearEqual(const Vector2& other, T threshold) const
252+{
253+ const T* otherData = other.data_;
254+ 
255+ return (ROSEN_EQ2<T>(data_[0], otherData[0], threshold)) && (ROSEN_EQ2<T>(data_[1], otherData[1], threshold));
256+}
257+ 
258+template<typename T>
259+inline T* Vector2<T>::GetData()
260+{
261+ return data_;
262+}
263+ 
264+template<typename T>
265+T Vector2<T>::GetLength() const
266+{
267+ return sqrt(GetSqrLength());
268+}
269+ 
270+template<typename T>
271+T Vector2<T>::GetSqrLength() const
272+{
273+ T sum = data_[0] * data_[0];
274+ sum += data_[1] * data_[1];
275+ return sum;
276+}
277+ 
278+template<typename T>
279+T Vector2<T>::Normalize()
280+{
281+ T l = GetLength();
282+ if (ROSEN_EQ2<T>(l, 0.0)) {
283+ return 0.0f;
284+ }
285+ 
286+ const T invLen = 1.0f / l;
287+ 
288+ data_[0] *= invLen;
289+ data_[1] *= invLen;
290+ return l;
291+}
292+ 
293+template<typename T>
294+bool Vector2<T>::IsInfinite() const
295+{
296+ return std::isinf(data_[0]) || std::isinf(data_[1]);
297+}
298+ 
299+template<typename T>
300+bool Vector2<T>::IsNaN() const
301+{
302+ return std::isnan(data_[0]) || std::isnan(data_[1]);
303+}
304+ 
305+template<typename T>
306+bool Vector2<T>::IsValid() const
307+{
308+ return !IsInfinite() && !IsNaN();
309+}
310+ 
311+} // namespace Rosen
312+} // namespace OHOS
313+#endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_VECTOR2_H