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_RENDER_ADAPTER_PIXELMAP_IMAGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_PIXELMAP_IMAGE_H 18 19 #include <utility> 20 21 #include "base/utils/noncopyable.h" 22 #include "core/components_ng/render/canvas_image.h" 23 #include "core/components_ng/render/drawing.h" 24 25 namespace OHOS::Ace::NG { 26 27 class PixelMapImage : public virtual CanvasImage { 28 DECLARE_ACE_TYPE(PixelMapImage, CanvasImage) 29 public: 30 PixelMapImage() = default; PixelMapImage(RefPtr<PixelMap> pixelMap)31 explicit PixelMapImage(RefPtr<PixelMap> pixelMap) : pixelMap_(std::move(pixelMap)) {} 32 33 ~PixelMapImage() override = default; 34 35 int32_t GetWidth() const override; 36 int32_t GetHeight() const override; 37 GetPixelMap()38 RefPtr<PixelMap> GetPixelMap() const override 39 { 40 return pixelMap_; 41 } 42 43 void Cache(const std::string& key) override; 44 45 RefPtr<CanvasImage> Clone() override; 46 47 void NotifyDrawCompletion(const std::string& srcInfo, const RefPtr<PixelMap>& pixmap); 48 void DrawToRSCanvas( 49 RSCanvas& canvas, const RSRect& srcRect, const RSRect& dstRect, const BorderRadiusArray& radiusXY) override; 50 void DrawRect(RSCanvas& canvas, const RSRect& srcRect, const RSRect& dstRect) override; 51 void DrawRect(RSCanvas& canvas, const RSRect& dstRect); 52 53 bool CheckIfNeedForStretching( 54 RSCanvas& canvas, const RSRect& srcRect, const RSRect& dstRect, const BorderRadiusArray& radiusXY); 55 bool StretchImageWithSlice( 56 RSCanvas& canvas, const RSRect& srcRect, const RSRect& dstRect, const BorderRadiusArray& radiusXY); 57 bool StretchImageWithLattice( 58 RSCanvas& canvas, const RSRect& srcRect, const RSRect& dstRect, const BorderRadiusArray& radiusXY); 59 60 static RefPtr<CanvasImage> QueryFromCache(const std::string& key); 61 HasData()62 bool HasData() const override 63 { 64 return GetPixelMap(); 65 } 66 static RSMatrix ToDrawingMatrix(const Matrix4& matrix4); 67 68 private: 69 RefPtr<PixelMap> pixelMap_; 70 71 ACE_DISALLOW_COPY_AND_MOVE(PixelMapImage); 72 }; 73 } // namespace OHOS::Ace::NG 74 75 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_PIXELMAP_IMAGE_H 76