• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_IMAGE_OBJECT_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_IMAGE_OBJECT_NG_H
18 
19 #include "base/utils/noncopyable.h"
20 #include "core/components_ng/image_provider/image_data.h"
21 #include "core/components_ng/image_provider/image_provider.h"
22 #include "core/components_ng/image_provider/svg_dom_base.h"
23 #include "core/components_ng/render/canvas_image.h"
24 #include "core/image/image_source_info.h"
25 
26 namespace OHOS::Ace::NG {
27 
28 class ImageObject : public virtual AceType {
29     DECLARE_ACE_TYPE(ImageObject, AceType);
30 
31 public:
32     ImageObject() = delete;
ImageObject(const ImageSourceInfo & sourceInfo,const SizeF & imageSize,const RefPtr<ImageData> & data)33     ImageObject(const ImageSourceInfo& sourceInfo, const SizeF& imageSize, const RefPtr<ImageData>& data)
34         : src_(sourceInfo), imageSize_(imageSize), data_(data)
35     {}
36     ~ImageObject() override = default;
37 
38     const SizeF& GetImageSize() const;
39     const ImageSourceInfo& GetSourceInfo() const;
40     const RefPtr<ImageData>& GetData() const;
41     int32_t GetFrameCount() const;
42 
43     void SetData(const RefPtr<ImageData>& data);
44     void SetImageSize(const SizeF& imageSize);
45     virtual void ClearData();
46     void SetFrameCount(int32_t frameCount);
47 
GetSVGDom()48     virtual RefPtr<SvgDomBase> GetSVGDom() const
49     {
50         return nullptr;
51     }
52 
53     virtual RefPtr<ImageObject> Clone() = 0;
GetDumpInfo()54     virtual std::string GetDumpInfo() { return ""; }
IsSupportCache()55     bool IsSupportCache() const
56     {
57         return src_.SupportObjCache();
58     }
59 
60     virtual void MakeCanvasImage(const RefPtr<ImageLoadingContext>& ctx, const SizeF& resizeTarget, bool forceResize,
61         bool syncLoad, bool loadInVipChannel = false) = 0;
62 
63 protected:
64     const ImageSourceInfo src_;
65     SizeF imageSize_ { -1.0, -1.0 };
66     // no longer needed after making canvas image
67     RefPtr<ImageData> data_;
68     int32_t frameCount_ = 1;
69 
70     ACE_DISALLOW_COPY_AND_MOVE(ImageObject);
71 };
72 } // namespace OHOS::Ace::NG
73 
74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_IMAGE_OBJECT_NG_H
75