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_BASE_RENDER_UI_RS_MASK_H 16 #define RENDER_SERVICE_BASE_RENDER_UI_RS_MASK_H 17 18 #include <memory> 19 #include "common/rs_macros.h" 20 #include "draw/pen.h" 21 #include "draw/brush.h" 22 #include "draw/path.h" 23 #include "image/picture.h" 24 #include "modules/svg/include/SkSVGDOM.h" 25 #include "transaction/rs_marshalling_helper.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 enum class MaskType { 30 NONE = 0, 31 SVG, 32 GRADIENT, 33 PATH, 34 PIXEL_MAP 35 }; 36 37 class RSB_EXPORT RSMask : public std::enable_shared_from_this<RSMask> { 38 public: 39 RSMask(); 40 virtual ~RSMask(); 41 static std::shared_ptr<RSMask> CreateGradientMask(const Drawing::Brush& maskBrush); 42 static std::shared_ptr<RSMask> CreatePathMask(const Drawing::Path& maskPath, const Drawing::Brush& maskBrush); 43 static std::shared_ptr<RSMask> CreatePathMask( 44 const Drawing::Path& maskPath, const Drawing::Pen& maskPen, const Drawing::Brush& maskBrush); 45 static std::shared_ptr<RSMask> CreateSVGMask(double x, double y, double scaleX, double scaleY, 46 const sk_sp<SkSVGDOM>& svgDom); 47 static std::shared_ptr<RSMask> CreatePixelMapMask(const std::shared_ptr<Media::PixelMap> pixelMap); 48 49 void SetSvgX(double x); 50 double GetSvgX() const; 51 void SetSvgY(double y); 52 double GetSvgY() const; 53 void SetScaleX(double scaleX); 54 double GetScaleX() const; 55 void SetScaleY(double scaleY); 56 double GetScaleY() const; 57 void SetMaskPath(const Drawing::Path& path); 58 std::shared_ptr<Drawing::Path> GetMaskPath() const; 59 void SetMaskPen(const Drawing::Pen& pen); 60 Drawing::Pen GetMaskPen() const; 61 void SetMaskBrush(const Drawing::Brush& brush); 62 Drawing::Brush GetMaskBrush() const; 63 bool MarshallingPathAndBrush(Parcel& parcel) const; 64 void SetSvgDom(const sk_sp<SkSVGDOM>& svgDom); 65 sk_sp<SkSVGDOM> GetSvgDom() const; 66 std::shared_ptr<Drawing::Picture> GetSvgPicture() const; 67 void SetPixelMap(const std::shared_ptr<Media::PixelMap> pixelMap); 68 std::shared_ptr<Media::PixelMap> GetPixelMap() const; 69 std::shared_ptr<Drawing::Image> GetImage() const; 70 void SetMaskType(MaskType type); 71 bool IsSvgMask() const; 72 bool IsGradientMask() const; 73 bool IsPathMask() const; 74 bool IsPixelMapMask() const; 75 void Dump(std::string& out) const; 76 77 #ifdef ROSEN_OHOS 78 bool Marshalling(Parcel& parcel) const; 79 [[nodiscard]] static RSMask* Unmarshalling(Parcel& parcel); 80 #endif 81 82 protected: 83 RSMask(const RSMask&) = delete; 84 RSMask(const RSMask&&) = delete; 85 RSMask& operator=(const RSMask&) = delete; 86 RSMask& operator=(const RSMask&&) = delete; 87 88 private: 89 MaskType type_ = MaskType::NONE; 90 double svgX_ = 0.0f; 91 double svgY_ = 0.0f; 92 double scaleX_ = 1.0f; 93 double scaleY_ = 1.0f; 94 sk_sp<SkSVGDOM> svgDom_; 95 std::shared_ptr<Drawing::Picture> svgPicture_; 96 Drawing::Pen maskPen_; 97 Drawing::Brush maskBrush_; 98 std::shared_ptr<Drawing::Path> maskPath_; 99 std::shared_ptr<Media::PixelMap> pixelMap_; 100 std::shared_ptr<Drawing::Image> image_; 101 102 }; 103 } // namespace Rosen 104 } // namespace OHOS 105 106 #endif // RENDER_SERVICE_BASE_RENDER_UI_RS_MASK_H