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 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H 16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H 17 18 #include <memory> 19 #include "common/rs_macros.h" 20 #ifndef USE_ROSEN_DRAWING 21 #include "include/core/SkPaint.h" 22 #include "include/core/SkPath.h" 23 #include "include/core/SkPicture.h" 24 #else 25 #include "draw/brush.h" 26 #include "draw/path.h" 27 #include "image/picture.h" 28 #endif 29 #if defined(NEW_SKIA) 30 #include "modules/svg/include/SkSVGDOM.h" 31 #else 32 #include "experimental/svg/model/SkSVGDOM.h" 33 #endif 34 #include "transaction/rs_marshalling_helper.h" 35 36 namespace OHOS { 37 namespace Rosen { 38 enum class MaskType { 39 NONE = 0, 40 SVG, 41 GRADIENT, 42 PATH, 43 }; 44 45 class RSB_EXPORT RSMask : public std::enable_shared_from_this<RSMask> { 46 public: 47 RSMask(); 48 virtual ~RSMask(); 49 #ifndef USE_ROSEN_DRAWING 50 static std::shared_ptr<RSMask> CreateGradientMask(const SkPaint& maskPaint); 51 static std::shared_ptr<RSMask> CreatePathMask(const SkPath& maskPath, const SkPaint& maskPaint); 52 #else 53 static std::shared_ptr<RSMask> CreateGradientMask(const Drawing::Brush& maskBrush); 54 static std::shared_ptr<RSMask> CreatePathMask(const Drawing::Path& maskPath, const Drawing::Brush& maskBrush); 55 #endif 56 static std::shared_ptr<RSMask> CreateSVGMask(double x, double y, double scaleX, double scaleY, 57 const sk_sp<SkSVGDOM>& svgDom); 58 59 void SetSvgX(double x); 60 double GetSvgX() const; 61 void SetSvgY(double y); 62 double GetSvgY() const; 63 void SetScaleX(double scaleX); 64 double GetScaleX() const; 65 void SetScaleY(double scaleY); 66 double GetScaleY() const; 67 #ifndef USE_ROSEN_DRAWING 68 void SetMaskPath(const SkPath& path); 69 SkPath GetMaskPath() const; 70 void SetMaskPaint(const SkPaint& paint); 71 SkPaint GetMaskPaint() const; 72 #else 73 void SetMaskPath(const Drawing::Path& path); 74 Drawing::Path GetMaskPath() const; 75 void SetMaskBrush(const Drawing::Brush& brush); 76 Drawing::Brush GetMaskBrush() const; 77 #endif 78 void SetSvgDom(const sk_sp<SkSVGDOM>& svgDom); 79 sk_sp<SkSVGDOM> GetSvgDom() const; 80 #ifndef USE_ROSEN_DRAWING 81 sk_sp<SkPicture> GetSvgPicture() const; 82 #else 83 std::shared_ptr<Drawing::Picture> GetSvgPicture() const; 84 #endif 85 void SetMaskType(MaskType type); 86 bool IsSvgMask() const; 87 bool IsGradientMask() const; 88 bool IsPathMask() const; 89 90 #ifdef ROSEN_OHOS 91 bool Marshalling(Parcel& parcel) const; 92 [[nodiscard]] static RSMask* Unmarshalling(Parcel& parcel); 93 #endif 94 95 protected: 96 RSMask(const RSMask&) = delete; 97 RSMask(const RSMask&&) = delete; 98 RSMask& operator=(const RSMask&) = delete; 99 RSMask& operator=(const RSMask&&) = delete; 100 101 private: 102 MaskType type_ = MaskType::NONE; 103 double svgX_ = 0.0f; 104 double svgY_ = 0.0f; 105 double scaleX_ = 1.0f; 106 double scaleY_ = 1.0f; 107 sk_sp<SkSVGDOM> svgDom_; 108 #ifndef USE_ROSEN_DRAWING 109 sk_sp<SkPicture> svgPicture_; 110 SkPaint maskPaint_; 111 SkPath maskPath_; 112 #else 113 std::shared_ptr<Drawing::Picture> svgPicture_; 114 Drawing::Brush maskBrush_; 115 Drawing::Path maskPath_; 116 #endif 117 118 }; 119 } // namespace Rosen 120 } // namespace OHOS 121 122 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H