• 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 #include "core/image/flutter_image_cache.h"
17 
18 #include "third_party/skia/include/core/SkGraphics.h"
19 
20 namespace OHOS::Ace {
21 
Create()22 RefPtr<ImageCache> ImageCache::Create()
23 {
24     return MakeRefPtr<FlutterImageCache>();
25 }
26 
Clear()27 void FlutterImageCache::Clear()
28 {
29     std::scoped_lock clearLock(cacheListMutex_, imageCacheMutex_, dataCacheListMutex_, imageDataCacheMutex_);
30     cacheList_.clear();
31     imageCache_.clear();
32     dataCacheList_.clear();
33     imageDataCache_.clear();
34 }
35 
GetDataFromCacheFile(const std::string & filePath)36 RefPtr<CachedImageData> FlutterImageCache::GetDataFromCacheFile(const std::string& filePath)
37 {
38     std::lock_guard<std::mutex> lock(cacheFileInfoMutex_);
39     if (!GetFromCacheFileInner(filePath)) {
40         LOGD("file : %{public}s not cached, return nullptr", filePath.c_str());
41         return nullptr;
42     } else {
43         LOGD("file : %{public}s cached found", filePath.c_str());
44     }
45     auto cacheFileLoader = AceType::MakeRefPtr<FileImageLoader>();
46     auto data = cacheFileLoader->LoadImageData(ImageSourceInfo(std::string("file:/").append(filePath)));
47     return data ? AceType::MakeRefPtr<SkiaCachedImageData>(data) : nullptr;
48 }
49 
Purge()50 void ImageCache::Purge()
51 {
52     SkGraphics::PurgeResourceCache();
53 }
54 
55 } // namespace OHOS::Ace