1 /* 2 * Copyright (c) 2021 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_SURFACE_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H 17 18 #include <string> 19 20 #include <parcel.h> 21 #include <refbase.h> 22 #include "surface.h" 23 24 #include <transaction/rs_transaction_proxy.h> 25 #include "platform/drawing/rs_surface.h" 26 #include "ui/rs_node.h" 27 #include "surface_type.h" 28 29 class SkCanvas; 30 31 namespace OHOS { 32 namespace Rosen { 33 34 struct RSSurfaceNodeConfig { 35 std::string SurfaceNodeName = "SurfaceNode"; 36 }; 37 38 class RS_EXPORT RSSurfaceNode : public RSNode, public Parcelable { 39 public: 40 using WeakPtr = std::weak_ptr<RSSurfaceNode>; 41 using SharedPtr = std::shared_ptr<RSSurfaceNode>; 42 static inline constexpr RSUINodeType Type = RSUINodeType::SURFACE_NODE; 43 44 virtual ~RSSurfaceNode(); 45 46 static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, bool isWindow = true); 47 48 void SetBounds(const Vector4f& bounds) override; 49 void SetBounds(float positionX, float positionY, float width, float height) override; 50 void SetBoundsSize(const Vector2f& size) override; 51 void SetBoundsSize(float width, float height) override; 52 void SetBoundsWidth(float width) override; 53 void SetBoundsHeight(float height) override; 54 void SetColorSpace(SurfaceColorGamut colorSpace); 55 void SetSecurityLayer(bool isSecurityLayer); 56 bool GetSecurityLayer() const; 57 58 bool Marshalling(Parcel& parcel) const override; 59 static RSSurfaceNode* Unmarshalling(Parcel& parcel); 60 sptr<OHOS::Surface> GetSurface() const; GetType()61 RSUINodeType GetType() const override 62 { 63 return RSUINodeType::SURFACE_NODE; 64 } GetColorSpace()65 SurfaceColorGamut GetColorSpace() 66 { 67 return colorSpace_; 68 } 69 protected: 70 bool NeedForcedSendToRemote() const override; 71 explicit RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode); 72 RSSurfaceNode(const RSSurfaceNode&) = delete; 73 RSSurfaceNode(const RSSurfaceNode&&) = delete; 74 RSSurfaceNode& operator=(const RSSurfaceNode&) = delete; 75 RSSurfaceNode& operator=(const RSSurfaceNode&&) = delete; 76 77 private: 78 bool CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config); 79 void UpdateSurfaceDefaultSize(float width, float height); 80 std::shared_ptr<RSSurface> surface_; 81 std::string name_; 82 SurfaceColorGamut colorSpace_ = SurfaceColorGamut::COLOR_GAMUT_SRGB; 83 bool isSecurityLayer_ = false; 84 85 friend class RSUIDirector; 86 friend class RSAnimation; 87 friend class RSPathAnimation; 88 template<typename T> 89 friend class RSPropertyAnimation; 90 friend class RSSurfaceExtractor; 91 }; 92 } // namespace Rosen 93 } // namespace OHOS 94 95 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H 96