1 /* 2 * Copyright (c) 2024 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 FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_RENDER_IMAGE_H 17 #define FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_RENDER_IMAGE_H 18 19 #include "ffi_remote_data.h" 20 21 #include "base/memory/referenced.h" 22 #include "core/components/common/properties/paint_state.h" 23 #include "core/components_ng/image_provider/image_loading_context.h" 24 #include "core/components_ng/render/canvas_image.h" 25 namespace OHOS::Ace::Framework { 26 27 class ACE_EXPORT CJRenderImage : public OHOS::FFI::FFIData, public Referenced { 28 public: 29 CJRenderImage(); 30 explicit CJRenderImage(const int32_t unit); 31 ~CJRenderImage() override = default; 32 33 void InitCJRenderImage(const std::string& src); 34 void InitCJRenderImage(const RefPtr<OHOS::Ace::PixelMap>& pixmap); 35 double GetHeight(); 36 double GetWidth(); GetImageData()37 std::shared_ptr<Ace::ImageData> GetImageData() const 38 { 39 return imageData_; 40 } 41 SetImageData(const std::shared_ptr<Ace::ImageData> & imageData)42 void SetImageData(const std::shared_ptr<Ace::ImageData>& imageData) 43 { 44 imageData_ = imageData; 45 } 46 SetUnit(CanvasUnit unit)47 void SetUnit(CanvasUnit unit) 48 { 49 unit_ = unit; 50 } 51 GetUnit()52 CanvasUnit GetUnit() 53 { 54 return unit_; 55 } 56 SetWidth(double width)57 void SetWidth(double width) 58 { 59 width_ = width; 60 } 61 SetHeight(double height)62 void SetHeight(double height) 63 { 64 height_ = height; 65 } 66 SetPixelMapId(int64_t id)67 void SetPixelMapId(int64_t id) 68 { 69 pixelMapId_ = id; 70 } 71 GetPixelMapId()72 int64_t GetPixelMapId() 73 { 74 return pixelMapId_; 75 } 76 GetPixelMap()77 RefPtr<PixelMap> GetPixelMap() const 78 { 79 return pixelMap_; 80 } 81 GetSrc()82 std::string GetSrc() 83 { 84 return src_; 85 } 86 87 double GetDensity(); 88 89 private: 90 void LoadImage(const std::string& src); 91 void LoadImage(const RefPtr<OHOS::Ace::PixelMap>& pixmap); 92 void LoadImage(const ImageSourceInfo& src); 93 void OnImageDataReady(); 94 void OnImageLoadSuccess(); 95 void OnImageLoadFail(const std::string& errorMsg); 96 97 RefPtr<NG::CanvasImage> image_; 98 RefPtr<PixelMap> pixelMap_; 99 RefPtr<NG::ImageLoadingContext> loadingCtx_; 100 std::shared_ptr<Ace::ImageData> imageData_; 101 int64_t pixelMapId_; 102 ImageSourceInfo sourceInfo_; 103 ImageFit imageFit_ = ImageFit::NONE; 104 105 std::string src_; 106 double width_ = 0; 107 double height_ = 0; 108 CanvasUnit unit_ = CanvasUnit::DEFAULT; 109 }; 110 111 } // namespace OHOS::Ace::Framework 112 113 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_RENDER_IMAGE_H 114