• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #include "memory/rs_memory_graphic.h"
16 #include "platform/common/rs_log.h"
17 
18 namespace OHOS {
19 namespace Rosen {
MemoryGraphic(int32_t pid,float cpuMemSize,float gpuMemSize)20 MemoryGraphic::MemoryGraphic(int32_t pid, float cpuMemSize, float gpuMemSize)
21     : pid_(pid), cpuMemSize_(cpuMemSize), gpuMemSize_(gpuMemSize)
22 {}
23 
GetPid() const24 int32_t MemoryGraphic::GetPid() const
25 {
26     return pid_;
27 }
28 
GetCpuMemorySize() const29 float MemoryGraphic::GetCpuMemorySize() const
30 {
31     return cpuMemSize_;
32 }
33 
GetGpuMemorySize() const34 float MemoryGraphic::GetGpuMemorySize() const
35 {
36     return gpuMemSize_;
37 }
38 
GetTotalMemorySize() const39 float MemoryGraphic::GetTotalMemorySize() const
40 {
41     return gpuMemSize_ + cpuMemSize_;
42 }
43 
SetPid(int32_t pid)44 void MemoryGraphic::SetPid(int32_t pid)
45 {
46     pid_ = pid;
47 }
48 
SetCpuMemorySize(float cpuMemSize)49 void MemoryGraphic::SetCpuMemorySize(float cpuMemSize)
50 {
51     cpuMemSize_ = cpuMemSize;
52 }
53 
SetGpuMemorySize(float gpuMemSize)54 void MemoryGraphic::SetGpuMemorySize(float gpuMemSize)
55 {
56     gpuMemSize_ = gpuMemSize;
57 }
58 
Marshalling(Parcel & parcel) const59 bool MemoryGraphic::Marshalling(Parcel& parcel) const
60 {
61     bool flag = parcel.WriteInt32(pid_) && parcel.WriteFloat(cpuMemSize_) &&
62         parcel.WriteFloat(gpuMemSize_);
63     if (!flag) {
64         ROSEN_LOGE("MemoryGraphic::Marshalling failed");
65     }
66     return flag;
67 }
68 
Unmarshalling(Parcel & parcel)69 MemoryGraphic* MemoryGraphic::Unmarshalling(Parcel& parcel)
70 {
71     int32_t pid;
72     float cpuMemSize;
73     float gpuMemSize;
74     if (!(parcel.ReadInt32(pid) && parcel.ReadFloat(cpuMemSize) && parcel.ReadFloat(gpuMemSize))) {
75         ROSEN_LOGE("MemoryGraphic::Unmarshalling failed");
76         return nullptr;
77     }
78 
79     MemoryGraphic* mem = new MemoryGraphic(pid, cpuMemSize, gpuMemSize);
80     return mem;
81 }
82 
operator +=(const MemoryGraphic & other)83 MemoryGraphic& MemoryGraphic::operator+=(const MemoryGraphic& other)
84 {
85     cpuMemSize_ += other.GetCpuMemorySize();
86     gpuMemSize_ += other.GetGpuMemorySize();
87     return *this;
88 }
89 
IncreaseCpuMemory(float cpuMemSize)90 void MemoryGraphic::IncreaseCpuMemory(float cpuMemSize)
91 {
92     cpuMemSize_ += cpuMemSize;
93 }
94 
IncreaseGpuMemory(float gpuMemSize)95 void MemoryGraphic::IncreaseGpuMemory(float gpuMemSize)
96 {
97     gpuMemSize_ += gpuMemSize;
98 }
99 
100 }
101 }