1 /*
2  * Copyright (c) 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 MEMORY_GRAPHIC
17 #define MEMORY_GRAPHIC
18 
19 #include <cstdint>
20 #include <parcel.h>
21 
22 #include "common/rs_macros.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class RSB_EXPORT MemoryGraphic : public Parcelable {
27 public:
28     MemoryGraphic() = default;
29     MemoryGraphic(int32_t pid, float cpuMemSize, float gpuMemSize);
30     ~MemoryGraphic() noexcept override = default;
31     MemoryGraphic& operator+=(const MemoryGraphic& other);
32     void IncreaseCpuMemory(float glSize);
33     void IncreaseGpuMemory(float graphicSize);
34 
35 
36     bool Marshalling(Parcel &parcel) const override;
37     static MemoryGraphic *Unmarshalling(Parcel &parcel);
38 
39     int32_t GetPid() const;
40     float GetGpuMemorySize() const; // Memory of gpu = SkiaGpu
41     float GetCpuMemorySize() const; // Memory of cpu = RSCpu + SkiaCpu
42     float GetTotalMemorySize() const;
43 
44     void SetPid(int32_t pid);
45     void SetGpuMemorySize(float glSize);
46     void SetCpuMemorySize(float graphicSize);
47 
48 private:
49     int32_t pid_ = 0;
50     float cpuMemSize_ = 0.0f;
51     float gpuMemSize_ = 0.0f;
52 };
53 } // namespace Rosen
54 } // namespace OHOS
55 
56 #endif // MEMORY_GRAPHIC