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_ROSEN_MASK_PAINTER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ROSEN_MASK_PAINTER_H 18 19 #include "modules/svg/include/SkSVGDOM.h" 20 21 #include "core/components/box/mask.h" 22 #include "core/image/image_provider.h" 23 #include "core/pipeline/pipeline_context.h" 24 25 namespace OHOS::Rosen { 26 class RSMask; 27 } 28 29 namespace OHOS::Ace { 30 enum class LoadStatus { 31 UNLOADED = 0, 32 LOADING, 33 UPDATING, 34 LOADSUCCESS, 35 LOADFAIL, 36 }; 37 38 class RosenMaskPainter : public Mask { 39 DECLARE_ACE_TYPE(RosenMaskPainter, Mask); 40 41 public: 42 RosenMaskPainter() = default; 43 ~RosenMaskPainter() = default; 44 45 void LoadMask(const WeakPtr<PipelineContext>& context, const RefPtr<RenderNode>& parent) override; 46 bool HasReady() const; 47 #ifndef USE_ROSEN_DRAWING 48 std::shared_ptr<Rosen::RSMask> GetRSMask(const Rect& paintRect, const SkPath& path); 49 #else 50 std::shared_ptr<Rosen::RSMask> GetRSMask(const Rect& paintRect, const RSPath& path); 51 #endif 52 void SetFetchImageObjBackgroundTask(CancelableTask task); 53 54 protected: 55 void LoadSVGImage(const WeakPtr<PipelineContext>& context); 56 void LoadGradient(const WeakPtr<PipelineContext>& context); 57 void LoadPath(const WeakPtr<PipelineContext>& context); 58 void UpdateSVGScale(const Size& boxSize, Size& svgSize); 59 bool UpadteSVGImageDom(double& x, double& y); 60 #ifndef USE_ROSEN_DRAWING 61 bool GetPathPaint(SkPaint& paint); 62 bool GetGradientPaint(const Rect& paintRect, SkPaint& paint); 63 #else 64 bool GetPathPaint(RSBrush& brush); 65 bool GetGradientPaint(const Rect& paintRect, RSBrush& brush); 66 #endif 67 68 RefPtr<RenderNode> parent_; 69 LoadStatus loadStatus_ = LoadStatus::UNLOADED; 70 CancelableTask fetchSvgImageTask_; 71 72 // draw gradient 73 RefPtr<Decoration> decoration_ = nullptr; 74 double dipScale_ = 1.0f; 75 76 // svg image draw object 77 sk_sp<SkSVGDOM> skiaDom_; 78 float scaleX_ = 1.0f; 79 float scaleY_ = 1.0f; 80 }; 81 } // namespace OHOS::Ace 82 83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ROSEN_MASK_PAINTER_H 84