• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FRAMEWORKS_BOOTANIMATION_INCLUDE_UTIL_H
17 #define FRAMEWORKS_BOOTANIMATION_INCLUDE_UTIL_H
18 
19 #include "contrib/minizip/unzip.h"
20 #include "contrib/minizip/zip.h"
21 #include "zlib.h"
22 #include "log.h"
23 
24 #include <cstdint>
25 #include <dirent.h>
26 #include <functional>
27 #include <unistd.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 
31 #include <if_system_ability_manager.h>
32 #include <ipc_skeleton.h>
33 #include <iservice_registry.h>
34 #include <iremote_object.h>
35 #include <include/core/SkImage.h>
36 #include <include/core/SkRefCnt.h>
37 #include <platform/ohos/rs_irender_service.h>
38 #include <system_ability_definition.h>
39 
40 namespace OHOS {
41 static const int READ_SIZE = 8192;
42 static const int MAX_FILE_NAME = 512;
43 static const std::string BOOT_PIC_CONFIGFILE = "config.json";
44 using MemStruct = struct MemStruct {
45 public:
46     char* memBuffer = nullptr;
47     unsigned long bufsize = 0;
48     sk_sp<SkData> skData_ = nullptr;
~MemStructMemStruct49     ~MemStruct()
50     {
51         if (skData_ != nullptr) {
52             skData_ = nullptr;
53         } else {
54             free(memBuffer);
55             memBuffer = nullptr;
56         }
57         LOGI("~MemStruct()");
58     }
setOwnerShipMemStruct59     void setOwnerShip(sk_sp<SkData>& skData)
60     {
61         skData_ = skData;
62     }
SetBufferSizeMemStruct63     void SetBufferSize(unsigned long ibufsize)
64     {
65         if (ibufsize == 0) {
66             LOGE("MemStruct SetBuffer size is invalid!");
67             return;
68         }
69         if (memBuffer == nullptr) {
70             bufsize = ibufsize + 1;
71             memBuffer = static_cast<char *>(malloc(bufsize + 1));
72         }
73     }
74 };
75 using ImageStruct = struct ImageStruct {
76 public:
77     std::string fileName = {};
78     sk_sp<SkImage> imageData = nullptr;
79     MemStruct memPtr;
~ImageStructImageStruct80     ~ImageStruct()
81     {
82         imageData = nullptr;
83         LOGI("~ImageStruct() %{public}s", fileName.c_str());
84     }
85 };
86 using BootAniConfig = struct BootAniConfig {
87 public:
88     int32_t frameRate = 30;
89 };
90 using ImageStructVec = std::vector<std::shared_ptr<ImageStruct>>;
91 int64_t GetNowTime();
92 void PostTask(std::function<void()> func, uint32_t delayTime = 0);
93 bool ReadZipFile(const std::string& srcFilePath, ImageStructVec& outBgImgVec, BootAniConfig& aniconfig);
94 void WaitRenderServiceInit();
95 bool ReadCurrentFile(const unzFile zipfile, const std::string& filename, ImageStructVec& outBgImgVec,
96     BootAniConfig& aniconfig, unsigned long fileSize);
97 bool GenImageData(const std::string& filename, std::shared_ptr<ImageStruct> imagetruct, int32_t bufferlen,
98     ImageStructVec& outBgImgVec);
99 bool ReadJsonConfig(const char* filebuffer, int totalsize, BootAniConfig& aniconfig);
100 void SortZipFile(ImageStructVec& outBgImgVec);
101 } // namespace OHOS
102 
103 #endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_UTIL_H
104