• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "core/components_ng/image_provider/image_object.h"
21 
22 namespace OHOS::Ace {
23 
Create()24 RefPtr<ImageCache> ImageCache::Create()
25 {
26     return MakeRefPtr<FlutterImageCache>();
27 }
28 
Clear()29 void FlutterImageCache::Clear()
30 {
31     std::scoped_lock clearLock(imageCacheMutex_, dataCacheListMutex_, imageDataCacheMutex_);
32     cacheList_.clear();
33     imageCache_.clear();
34     dataCacheList_.clear();
35     imageDataCache_.clear();
36 }
37 
GetDataFromCacheFile(const std::string & filePath)38 RefPtr<CachedImageData> FlutterImageCache::GetDataFromCacheFile(const std::string& filePath)
39 {
40     std::lock_guard<std::mutex> lock(cacheFileInfoMutex_);
41     if (!GetFromCacheFileInner(filePath)) {
42         LOGD("file not cached, return nullptr");
43         return nullptr;
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