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 ROSEN_RENDER_SERVICE_BASE_RS_UIEXTENSION_DATA_H
17 #define ROSEN_RENDER_SERVICE_BASE_RS_UIEXTENSION_DATA_H
18 
19 #include <map>
20 #include <parcel.h>
21 #include <vector>
22 
23 #include "common/rs_common_def.h"
24 #include "common/rs_macros.h"
25 #include "common/rs_rect.h"
26 #include "common/rs_vector2.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 
31 struct SecRectInfo {
32     RectI relativeCoords = RectI();
33     Vector2f scale = {1.f, 1.f};
34     Vector2f anchor = {0.f, 0.f};
35 };
36 
37 struct SecSurfaceInfo {
38     SecRectInfo uiExtensionRectInfo;
39     pid_t hostPid = 0;
40     pid_t uiExtensionPid = 0;
41     uint64_t hostNodeId = INVALID_NODEID;
42     uint64_t uiExtensionNodeId = INVALID_NODEID;
43     std::vector<SecRectInfo> upperNodes = {};
44 };
45 
46 using UIExtensionCallbackData = std::map<NodeId, std::vector<SecSurfaceInfo>>;
47 class RSB_EXPORT RSUIExtensionData : public Parcelable {
48 public:
49     RSUIExtensionData() = default;
RSUIExtensionData(UIExtensionCallbackData & data)50     RSUIExtensionData(UIExtensionCallbackData& data)
51     {
52         for (UIExtensionCallbackData::iterator iter = data.begin(); iter != data.end(); ++iter) {
53             secData_.insert(std::make_pair(iter->first, iter->second));
54         }
55     }
RSUIExtensionData(RSUIExtensionData && other)56     RSUIExtensionData(RSUIExtensionData&& other) : secData_(std::move(other.secData_)) {}
57     virtual ~RSUIExtensionData() noexcept = default;
58 
GetSecData()59     const UIExtensionCallbackData& GetSecData() const
60     {
61         return secData_;
62     }
63     [[nodiscard]] static RSUIExtensionData* Unmarshalling(Parcel& parcel);
64     bool Marshalling(Parcel& parcel) const override;
65 
66 private:
67     static bool MarshallingRectInfo(const SecRectInfo& rectInfo, Parcel& parcel);
68     static void UnmarshallingRectInfo(SecRectInfo& rectInfo, Parcel& parcel);
69     UIExtensionCallbackData secData_;
70 };
71 } // namespace Rosen
72 } // namespace OHOS
73 
74 #endif