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
17 namespace OHOS {
18 namespace Rosen {
MemoryGraphic(int32_t pid,float cpuMemSize,float gpuMemSize)19 MemoryGraphic::MemoryGraphic(int32_t pid, float cpuMemSize, float gpuMemSize)
20 : pid_(pid), cpuMemSize_(cpuMemSize), gpuMemSize_(gpuMemSize)
21 {}
22
GetPid() const23 int32_t MemoryGraphic::GetPid() const
24 {
25 return pid_;
26 }
27
GetCpuMemorySize() const28 float MemoryGraphic::GetCpuMemorySize() const
29 {
30 return cpuMemSize_;
31 }
32
GetGpuMemorySize() const33 float MemoryGraphic::GetGpuMemorySize() const
34 {
35 return gpuMemSize_;
36 }
37
GetTotalMemorySize() const38 float MemoryGraphic::GetTotalMemorySize() const
39 {
40 return gpuMemSize_ + cpuMemSize_;
41 }
42
SetPid(int32_t pid)43 void MemoryGraphic::SetPid(int32_t pid)
44 {
45 pid_ = pid;
46 }
47
SetCpuMemorySize(float cpuMemSize)48 void MemoryGraphic::SetCpuMemorySize(float cpuMemSize)
49 {
50 cpuMemSize_ = cpuMemSize;
51 }
52
SetGpuMemorySize(float gpuMemSize)53 void MemoryGraphic::SetGpuMemorySize(float gpuMemSize)
54 {
55 gpuMemSize_ = gpuMemSize;
56 }
57
Marshalling(Parcel & parcel) const58 bool MemoryGraphic::Marshalling(Parcel& parcel) const
59 {
60 return parcel.WriteInt32(pid_) && parcel.WriteFloat(cpuMemSize_) &&
61 parcel.WriteFloat(gpuMemSize_);
62 }
63
Unmarshalling(Parcel & parcel)64 MemoryGraphic* MemoryGraphic::Unmarshalling(Parcel& parcel)
65 {
66 int32_t pid;
67 float cpuMemSize;
68 float gpuMemSize;
69 if (!(parcel.ReadInt32(pid) && parcel.ReadFloat(cpuMemSize) && parcel.ReadFloat(gpuMemSize))) {
70 return nullptr;
71 }
72
73 MemoryGraphic* mem = new MemoryGraphic(pid, cpuMemSize, gpuMemSize);
74 return mem;
75 }
76
operator +=(const MemoryGraphic & other)77 MemoryGraphic& MemoryGraphic::operator+=(const MemoryGraphic& other)
78 {
79 cpuMemSize_ += other.GetCpuMemorySize();
80 gpuMemSize_ += other.GetGpuMemorySize();
81 return *this;
82 }
83
IncreaseCpuMemory(float cpuMemSize)84 void MemoryGraphic::IncreaseCpuMemory(float cpuMemSize)
85 {
86 cpuMemSize_ += cpuMemSize;
87 }
88
IncreaseGpuMemory(float gpuMemSize)89 void MemoryGraphic::IncreaseGpuMemory(float gpuMemSize)
90 {
91 gpuMemSize_ += gpuMemSize;
92 }
93
94 }
95 }