• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_DFX_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_DFX_H
18 #include <string>
19 
20 #include "base/image/pixel_map.h"
21 namespace OHOS::Ace::NG {
22 struct ImageNodeId {
ImageNodeIdImageNodeId23     ImageNodeId(int32_t nodeId, int64_t accessibilityId, uint64_t canvasNodeId)
24         : nodeId_(nodeId), accessibilityId_(accessibilityId), canvasNodeId_(canvasNodeId)
25     {}
26     ImageNodeId() = default;
27     int32_t nodeId_ = -1;
28     int64_t accessibilityId_ = -1;
29     uint64_t canvasNodeId_ = -1;
30 };
31 class ImageDfxConfig {
32 public:
33     ImageDfxConfig(
34         const ImageNodeId& nodeInfo, int32_t srcType, std::string imageSrc, bool isTrimMemRecycle = false)
nodeInfo_(nodeInfo)35         : nodeInfo_(nodeInfo), srcType_(srcType), imageSrc_(imageSrc), isTrimMemRecycle_(isTrimMemRecycle)
36     {
37         InitToStringWithoutSrc();
38         InitToStringWithSrc();
39     }
40     ImageDfxConfig() = default;
41     // Used in tracing functions, does not include image source information (sensitive data)
ToStringWithoutSrc()42     std::string ToStringWithoutSrc() const
43     {
44         return withoutSrcInfo_;
45     }
46 
47     // Includes image source, but as the image source may be sensitive, use with caution
ToStringWithSrc()48     std::string ToStringWithSrc() const
49     {
50         return withSrcInfo_;
51     }
52 
GetIsTrimMemRecycle()53     bool GetIsTrimMemRecycle() const
54     {
55         return isTrimMemRecycle_;
56     }
57 
GetNodeId()58     int32_t GetNodeId() const
59     {
60         return nodeInfo_.nodeId_;
61     }
62 
GetAccessibilityId()63     int64_t GetAccessibilityId() const
64     {
65         return nodeInfo_.accessibilityId_;
66     }
67 
GetImageSrc()68     std::string GetImageSrc() const
69     {
70         return imageSrc_;
71     }
72 
SetFrameSize(float width,float height)73     void SetFrameSize(float width, float height)
74     {
75         frameSizeWidth_ = width;
76         frameSizeHeight_ = height;
77     }
78 
GetFrameSizeWidth()79     float GetFrameSizeWidth() const
80     {
81         return frameSizeWidth_;
82     }
83 
GetFrameSizeHeight()84     float GetFrameSizeHeight() const
85     {
86         return frameSizeHeight_;
87     }
88 
89 private:
90     ImageNodeId nodeInfo_ = ImageNodeId();
91     int32_t srcType_ = -1;
92     std::string imageSrc_;
93     bool isTrimMemRecycle_ = false;
94     std::string withoutSrcInfo_ = "";
95     std::string withSrcInfo_ = "";
96     float frameSizeWidth_ = 0.0f;
97     float frameSizeHeight_ = 0.0f;
98 
InitToStringWithoutSrc()99     void InitToStringWithoutSrc()
100     {
101         withoutSrcInfo_ = std::string("[")
102                               .append(std::to_string(nodeInfo_.nodeId_))
103                               .append("-")
104                               .append(std::to_string(nodeInfo_.accessibilityId_))
105                               .append("-")
106                               .append(std::to_string(nodeInfo_.canvasNodeId_))
107                               .append("-")
108                               .append(std::to_string(srcType_))
109                               .append("]");
110     }
111 
InitToStringWithSrc()112     void InitToStringWithSrc()
113     {
114         withSrcInfo_ = std::string("[")
115                            .append(std::to_string(nodeInfo_.nodeId_))
116                            .append("-")
117                            .append(std::to_string(nodeInfo_.accessibilityId_))
118                            .append("-")
119                            .append(std::to_string(nodeInfo_.canvasNodeId_))
120                            .append("-")
121                            .append(std::to_string(srcType_))
122                            .append("]-[")
123                            .append(imageSrc_)
124                            .append("]");
125     }
126 };
127 
128 struct RenderedImageInfo {
129     // Indicates whether the rendering has been successfully displayed.
130     bool renderSuccess = false;
131     // PixelMap info
132     int32_t width = 0;
133     int32_t height = 0;
134     int32_t rowStride = 0;
135     int32_t rowBytes = 0;
136     int32_t byteCount = 0;
137     bool isHdr = false;
138     AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
139     PixelFormat pixelFormat = PixelFormat::UNKNOWN;
140     AllocatorType allocatorType = AllocatorType::DEFAULT;
141     std::string pixelMapId;
142     std::string srcInfo;
143 
ToStringRenderedImageInfo144     std::string ToString() const
145     {
146         if (!renderSuccess) {
147             return "RenderedImageInfo: { RenderStatus: NotRender }";
148         }
149         std::string result;
150         result.append("RenderedImageInfo: {")
151             .append("RenderStatus: Success")
152             .append(", Width: ")
153             .append(std::to_string(width))
154             .append(", Height: ")
155             .append(std::to_string(height))
156             .append(", Row Stride: ")
157             .append(std::to_string(rowStride))
158             .append(", Row Bytes: ")
159             .append(std::to_string(rowBytes))
160             .append(", Byte Count: ")
161             .append(std::to_string(byteCount))
162             .append(", Is HDR: ")
163             .append(isHdr ? "true" : "false")
164             .append(", Alpha Type: ")
165             .append(std::to_string(static_cast<int>(alphaType)))
166             .append(", Pixel Format: ")
167             .append(std::to_string(static_cast<int>(pixelFormat)))
168             .append(", Allocator Type: ")
169             .append(std::to_string(static_cast<int>(allocatorType)))
170             .append(", Pixel Map ID: ")
171             .append(pixelMapId)
172             .append(" }");
173         return result;
174     }
175 };
176 } // namespace OHOS::Ace::NG
177 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_DFX_H
178