• 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/render/canvas_image.h"
23 #include "core/image/image_source_info.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 class ImageObject : public virtual AceType {
28     DECLARE_ACE_TYPE(ImageObject, AceType);
29 
30 public:
31     ImageObject() = delete;
ImageObject(const ImageSourceInfo & sourceInfo,const SizeF & imageSize,const RefPtr<ImageData> & data)32     ImageObject(const ImageSourceInfo& sourceInfo, const SizeF& imageSize, const RefPtr<ImageData>& data)
33         : src_(sourceInfo), imageSize_(imageSize), data_(data)
34     {}
35     ~ImageObject() override = default;
36 
37     const SizeF& GetImageSize() const;
38     const ImageSourceInfo& GetSourceInfo() const;
39     const RefPtr<ImageData>& GetData() const;
40 
41     void SetData(const RefPtr<ImageData>& data);
42     void SetImageSize(const SizeF& imageSize);
43     virtual void ClearData();
44 
45     virtual RefPtr<ImageObject> Clone() = 0;
46 
IsSupportCache()47     bool IsSupportCache() const
48     {
49         return src_.IsSupportCache();
50     }
51 
52     virtual void MakeCanvasImage(
53         const RefPtr<ImageLoadingContext>& ctx, const SizeF& resizeTarget, bool forceResize, bool syncLoad) = 0;
54 
55 protected:
56     const ImageSourceInfo src_;
57     SizeF imageSize_ { -1.0, -1.0 };
58     // no longer needed after making canvas image
59     RefPtr<ImageData> data_;
60 
61     ACE_DISALLOW_COPY_AND_MOVE(ImageObject);
62 };
63 } // namespace OHOS::Ace::NG
64 
65 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_IMAGE_OBJECT_NG_H
66