• 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 FOUNDATION_ACE_FRAMEWORKS_CORE_IMAGE_FLUTTER_IMAGE_CACHE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_IMAGE_FLUTTER_IMAGE_CACHE_H
18 
19 #include "flutter/fml/memory/ref_counted.h"
20 #include "flutter/lib/ui/painting/image.h"
21 
22 #include "core/image/image_cache.h"
23 #include "core/image/image_object.h"
24 
25 namespace OHOS::Ace {
26 
27 struct CachedImage {
CachedImageCachedImage28     CachedImage(const fml::RefPtr<flutter::CanvasImage>& image) : imagePtr(image) {}
29     fml::RefPtr<flutter::CanvasImage> imagePtr;
30 };
31 
32 struct SkiaCachedImageData : public CachedImageData {
33     DECLARE_ACE_TYPE(SkiaCachedImageData, CachedImageData);
34 public:
SkiaCachedImageDataSkiaCachedImageData35     SkiaCachedImageData(const sk_sp<SkData>& data) : imageData(data) {}
36     ~SkiaCachedImageData() override = default;
37 
GetSizeSkiaCachedImageData38     size_t GetSize() override
39     {
40         return imageData ? imageData->size() : 0;
41     }
42 
GetDataSkiaCachedImageData43     const uint8_t* GetData() override
44     {
45         return imageData ? imageData->bytes() : nullptr;
46     }
47 
48     sk_sp<SkData> imageData;
49 };
50 
51 class FlutterImageCache : public ImageCache {
52     DECLARE_ACE_TYPE(FlutterImageCache, ImageCache);
53 
54 public:
55     FlutterImageCache() = default;
56     ~FlutterImageCache() override = default;
57     void Clear() override;
58     virtual RefPtr<CachedImageData> GetDataFromCacheFile(const std::string& filePath) override;
59 };
60 
61 } // namespace OHOS::Ace
62 
63 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_IMAGE_FLUTTER_IMAGE_CACHE_H
64