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 
16 #ifndef SERVICES_DTBSCHEDMGR_INCLUDE_SNAPSHOT_SNAP_SHOT_H
17 #define SERVICES_DTBSCHEDMGR_INCLUDE_SNAPSHOT_SNAP_SHOT_H
18 
19 #include <memory>
20 
21 #include "dtbschedmgr_log.h"
22 #include "message_parcel.h"
23 #include "pixel_map.h"
24 
25 namespace OHOS {
26 namespace DistributedSchedule {
27 struct Rect;
28 class Snapshot {
29 public:
30     int32_t version_ = 0;
31     int32_t orientation_ = 0;
32     std::unique_ptr<Rect> rect_;
33     bool reducedResolution_ = true;
34     float scale_ = 0.0f;
35     bool isRealSnapshot_ = true;
36     int32_t windowingMode_ = 0;
37     int32_t systemUiVisibility_ = 0;
38     bool isTranslucent_ = true;
39     std::unique_ptr<Rect> windowBounds_;
40     std::u16string appLabel_;
41     std::u16string abilityLabel_;
42     std::vector<uint8_t> icon_;
43     std::u16string secAppLabel_;
44     std::u16string secAbilityLabel_;
45     std::vector<uint8_t> secIcon_;
46     std::u16string sourceDeviceTips_;
47     std::shared_ptr<Media::PixelMap> pixelMap_;
48 
49     ~Snapshot();
50     bool WriteToParcel(MessageParcel& data) const;
51     static std::unique_ptr<Snapshot> Create(const std::vector<uint8_t>& data);
52     bool WriteSnapshotInfo(MessageParcel& data) const;
53     bool WritePixelMap(MessageParcel& data) const;
54     int64_t GetCreatedTime() const;
55     int64_t GetLastAccessTime() const;
56     void UpdateLastAccessTime(int64_t accessTime);
57 private:
58     static std::unique_ptr<Media::PixelMap> CreatePixelMap(const uint8_t* buffer, uint32_t bufferSize);
59     static std::unique_ptr<Snapshot> FillSnapshot(MessageParcel& data);
60 
61     // inner used
62     int64_t createdTime_ = 0;
63     int64_t lastAccessTime_ = 0;
64 };
65 
66 struct Rect : public Parcelable {
RectRect67     Rect(int32_t left, int32_t top, int32_t right, int32_t bottom)
68     {
69         this->left = left;
70         this->top = top;
71         this->right = right;
72         this->bottom = bottom;
73     }
74 
MarshallingRect75     bool Marshalling(Parcel &parcel) const override
76     {
77         if (!parcel.WriteInt32(left) || !parcel.WriteInt32(top) ||
78             !parcel.WriteInt32(right) || !parcel.WriteInt32(bottom)) {
79             return false;
80         }
81         return true;
82     }
83 
UnmarshallingRect84     static Rect* Unmarshalling(Parcel &parcel)
85     {
86         int32_t left = parcel.ReadInt32();
87         int32_t top = parcel.ReadInt32();
88         int32_t right = parcel.ReadInt32();
89         int32_t bottom = parcel.ReadInt32();
90         auto rectPtr = new Rect(left, top, right, bottom);
91         return rectPtr;
92     }
93 
94     int32_t left = 0;
95     int32_t top = 0;
96     int32_t right = 0;
97     int32_t bottom = 0;
98 };
99 } // namespace DistributedSchedule
100 } // namespace OHOS
101 #endif /* SERVICES_DTBSCHEDMGR_INCLUDE_SNAPSHOT_SNAP_SHOT_H */
102