1 /* 2 * Copyright (c) 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_RENDER_ADAPTER_ROSEN_DRAWING_IMAGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_ROSEN_DRAWING_IMAGE_H 18 19 #include <stdint.h> 20 21 #include "core/components_ng/render/canvas_image.h" 22 #include "core/components_ng/render/drawing.h" 23 24 namespace OHOS::Ace::NG { 25 class DrawingImage : public virtual CanvasImage { DECLARE_ACE_TYPE(DrawingImage,CanvasImage)26 DECLARE_ACE_TYPE(DrawingImage, CanvasImage) 27 public: 28 explicit DrawingImage(const std::shared_ptr<RSImage>& image) : image_(image) {} 29 DrawingImage() = default; 30 ~DrawingImage() override = default; 31 GetImage()32 virtual std::shared_ptr<RSImage> GetImage() const 33 { 34 return image_; 35 } 36 GetCompressData()37 virtual std::shared_ptr<RSData> GetCompressData() const 38 { 39 return compressData_; 40 } 41 SetCompressData(std::shared_ptr<RSData> data,int32_t w,int32_t h)42 void SetCompressData(std::shared_ptr<RSData> data, int32_t w, int32_t h) 43 { 44 compressData_ = data; 45 compressWidth_ = w; 46 compressHeight_ = h; 47 uniqueId_ = image_->GetUniqueID(); 48 } 49 SetRawCompressData(void * dataPtr,int32_t w,int32_t h)50 void SetRawCompressData(void* dataPtr, int32_t w, int32_t h) override 51 { 52 auto* rsData = reinterpret_cast<std::shared_ptr<RSData>*>(dataPtr); 53 SetCompressData(*rsData, w, h); 54 } 55 GetCompressWidth()56 virtual int32_t GetCompressWidth() const 57 { 58 return compressWidth_; 59 } 60 GetCompressHeight()61 virtual int32_t GetCompressHeight() const 62 { 63 return compressHeight_; 64 } 65 GetUniqueID()66 virtual uint32_t GetUniqueID() const 67 { 68 return uniqueId_; 69 } 70 SetUniqueID(uint32_t id)71 virtual void SetUniqueID(uint32_t id) 72 { 73 uniqueId_ = id; 74 } 75 76 RefPtr<CanvasImage> Clone() override; 77 78 void Cache(const std::string& key) override; 79 80 RefPtr<PixelMap> GetPixelMap() const override; 81 82 void ReplaceRSImage(std::shared_ptr<RSImage> image); 83 int32_t GetWidth() const override; 84 int32_t GetHeight() const override; 85 86 void DrawToRSCanvas( 87 RSCanvas& canvas, const RSRect& srcRect, const RSRect& dstRect, const BorderRadiusArray& radiusXY) override; 88 89 static RefPtr<CanvasImage> QueryFromCache(const std::string& key); 90 91 static std::shared_ptr<RSImage> MakeRSImageFromPixmap(const RefPtr<PixelMap>& pixmap); 92 static std::shared_ptr<RSColorSpace> ColorSpaceToRSColorSpace(const RefPtr<PixelMap>& pixmap); 93 static RSAlphaType AlphaTypeToRSAlphaType(const RefPtr<PixelMap>& pixmap); 94 static RSColorType PixelFormatToRSColorType(const RefPtr<PixelMap>& pixmap); 95 96 private: 97 void ClipRRect(RSCanvas& canvas, const RSRect& dstRect, const BorderRadiusArray& radiusXY); 98 bool DrawWithRecordingCanvas(RSCanvas& canvas, const BorderRadiusArray& radiusXY); 99 100 uint32_t uniqueId_ = 0; 101 std::shared_ptr<RSImage> image_; 102 std::shared_ptr<RSData> compressData_; 103 int32_t compressWidth_ = 0; 104 int32_t compressHeight_ = 0; 105 }; 106 } // namespace OHOS::Ace::NG 107 108 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_ROSEN_DRAWING_IMAGE_H 109