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 RS_HARDWARE_COMPOSE_DISABLED_REASON_COLLECTION_H
17 #define RS_HARDWARE_COMPOSE_DISABLED_REASON_COLLECTION_H
18 
19 #include <mutex>
20 #include <vector>
21 
22 #include "common/rs_common_def.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 static const size_t HWC_DISABLED_REASON_INFO_OFFSET = 4;
27 
28 enum HwcDisabledReasons {
29     DISABLED_BY_FLITER_RECT = 0,
30     DISABLED_BY_TRANSPARENT_CLEAN_FLITER = 1,
31     DISABLED_BY_TRANSPARENT_DIRTY_FLITER = 2,
32     DISABLED_BY_ACCUMULATED_ALPHA = 3,
33     DISABLED_BY_ROTATION = 4,
34     DISABLED_BY_HWC_NODE_ABOVE = 5,
35     DISABLED_BY_BACKGROUND_ALPHA = 6,
36     DISABLED_BY_INVALID_PARAM = 7,
37     DISABLED_BY_PREVALIDATE = 8,
38     DISABLED_BY_SRC_PIXEL = 9,
39     DISABLED_BY_BUFFER_NONMATCH = 10,
40     DISABLED_REASON_LENGTH = 11,
41 };
42 
43 struct HwcDisabledReasonInfo {
44     int32_t disabledReasonStatistics[HwcDisabledReasons::DISABLED_REASON_LENGTH] = {0};
45     int32_t pidOfBelongsApp = 0;
46     std::string nodeName = "";
47 };
48 
49 using HwcDisabledReasonInfos = std::vector<HwcDisabledReasonInfo>;
50 
51 class RSB_EXPORT HwcDisabledReasonCollection {
52 public:
53     static HwcDisabledReasonCollection& GetInstance();
54 
55     void UpdateHwcDisabledReasonForDFX(NodeId id, int32_t disabledReason, const std::string& nodeName);
56     HwcDisabledReasonInfos GetHwcDisabledReasonInfo();
57 
58 private:
59     HwcDisabledReasonCollection();
60     ~HwcDisabledReasonCollection() noexcept;
61     HwcDisabledReasonCollection(const HwcDisabledReasonCollection&) = delete;
62     HwcDisabledReasonCollection(const HwcDisabledReasonCollection&&) = delete;
63     HwcDisabledReasonCollection& operator=(const HwcDisabledReasonCollection&) = delete;
64     HwcDisabledReasonCollection& operator=(const HwcDisabledReasonCollection&&) = delete;
65 
66     std::unordered_map<NodeId, HwcDisabledReasonInfo> hwcDisabledReasonInfoMap_;
67     mutable std::mutex hwcDisabledReasonMtx_;
68 };
69 } // namespace Rosen
70 } // namespace OHOS
71 
72 #endif // RS_HARDWARE_COMPOSE_DISABLED_REASON_COLLECTION_H