1 /*
2  * Copyright (C) 2021 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 INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_MANAGER_H
17 #define INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_MANAGER_H
18 
19 #include "pixel_map.h"
20 
21 namespace OHOS {
22 namespace Media {
23 class PixelMapManager {
24 public:
PixelMapManager(PixelMap * pixelMap)25     explicit PixelMapManager(PixelMap *pixelMap) : pixelMap_(pixelMap)
26     {}
27 
FreePixels()28     void FreePixels()
29     {
30         pixelMap_.clear();
31     }
32 
Invalid()33     bool Invalid()
34     {
35         return pixelMap_ == nullptr;
36     }
37 
GetPixelMap()38     PixelMap &GetPixelMap()
39     {
40         return *pixelMap_;
41     }
42 
GetByteCount()43     int32_t GetByteCount()
44     {
45         if (pixelMap_ == nullptr) {
46             return 0;
47         }
48         return pixelMap_->GetByteCount();
49     }
50 
Ref()51     void Ref()
52     {
53         if (pixelMap_ == nullptr) {
54             return;
55         }
56         pixelMap_->IncStrongRef(nullptr);
57     }
58 
UnRef()59     void UnRef()
60     {
61         if (pixelMap_ == nullptr) {
62             return;
63         }
64         pixelMap_->DecStrongRef(nullptr);
65     }
66 
~PixelMapManager()67     ~PixelMapManager()
68     {}
69 
70 private:
71     ::OHOS::sptr<PixelMap> pixelMap_ = nullptr;
72 };
73 } // namespace Media
74 } // namespace OHOS
75 #endif // INTERFACES_INNERKITS_INCLUDE_PIXEL_MAP_MANAGER_H
76