• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_MEMORY_UTILS_PURGEABLE_PIXELMAP_BUILDER_H
16 #define OHOS_MEMORY_UTILS_PURGEABLE_PIXELMAP_BUILDER_H
17 
18 #include "image_source.h"
19 #include "image_type.h"
20 #include "pixel_map.h"
21 
22 #include "purgeable_ashmem.h"
23 #include "purgeable_mem_builder.h"
24 #include "purgeable_resource_manager.h"
25 
26 #include "memory.h"
27 
28 namespace OHOS {
29 namespace PurgeableBuilder {
30 using namespace OHOS::Media;
31 
32 class PurgeablePixelMapBuilder : public PurgeableMem::PurgeableMemBuilder {
33 public:
34     PurgeablePixelMapBuilder(uint32_t index, std::unique_ptr<ImageSource> &imageSource,
35         DecodeOptions opts);
36 
37     bool Build(void *data, size_t size) override;
38 
~PurgeablePixelMapBuilder()39     ~PurgeablePixelMapBuilder() {}
40 
41 private:
42     uint32_t index_;
43     DecodeOptions opts_;
44     std::unique_ptr<ImageSource> imageSource_;
45 }; // class PurgeablePixelMapBuilder
46 
47 bool GetSysForPurgeable();
48 void SetBuilderToBePurgeable(PixelMap *pixelMap,
49                              std::unique_ptr<PurgeableMem::PurgeableMemBuilder> &builder);
50 void RemoveFromPurgeableResourceMgr(PixelMap *pixelMap);
51 void AddToPurgeableResourceMgr(PixelMap *pixelMap);
52 bool MakePixelMapToBePurgeable(std::unique_ptr<PixelMap> &pixelMap,
53     std::unique_ptr<ImageSource> &backupImgSrc4Rebuild, DecodeOptions &decodeOpts);
54 bool MakePixelMapToBePurgeable(std::unique_ptr<PixelMap> &pixelMap, const int fd,
55     const SourceOptions &opts, DecodeOptions &decodeOpts);
56 bool MakePixelMapToBePurgeableBySrc(PixelMap *pixelMap,
57     std::unique_ptr<ImageSource> &backupImgSrc4Rebuild, DecodeOptions &decodeOpts);
58 bool MakePixelMapToBePurgeableByFd(PixelMap *pixelMap, const int fd, const SourceOptions &opts,
59     DecodeOptions &decodeOpts);
60 bool IfCanBePurgeable(DecodeOptions &decodeOpts);
61 } // namespace PurgeableBuilder
62 } // namespace OHOS
63 #endif /* OHOS_MEMORY_UTILS_PURGEABLE_PIXELMAP_BUILDER_H */