1 /* 2 * Copyright (c) 2021-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 ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_H 17 #define ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_H 18 19 #include <parcel.h> 20 #include <refbase.h> 21 22 #include "common/rs_common_def.h" 23 #include "pipeline/rs_context.h" 24 #include "recording/draw_cmd_list.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 29 //Each command HAVE TO have UNIQUE ID in ALL HISTORY 30 //If a command is not used and you want to delete it, 31 //just COMMENT it - and never use this value anymore 32 enum RSCommandType : uint16_t { 33 // node commands 34 BASE_NODE = 0, 35 RS_NODE = 1, // formerly RSPropertyNode 36 CANVAS_NODE = 2, // formerly RSNode 37 SURFACE_NODE = 3, 38 PROXY_NODE = 4, 39 ROOT_NODE = 5, 40 DISPLAY_NODE = 6, // LOGICAL_DISPLAY_NODE 41 EFFECT_NODE = 7, 42 CANVAS_DRAWING_NODE = 8, 43 // animation commands 44 ANIMATION = 9, 45 // read showing properties (deprecated, will be removed later) 46 RS_NODE_SYNCHRONOUS_READ_PROPERTY = 10, 47 RS_NODE_SYNCHRONOUS_GET_VALUE_FRACTION = 11, 48 FRAME_RATE_LINKER = 12, 49 }; 50 51 enum RSCommandPermissionType : uint16_t { 52 PERMISSION_APP, 53 PERMISSION_SYSTEM, 54 }; 55 56 // [attention] 57 // RSCommand object is serializable, when use ADD_COMMAND macro to define a new RSCommand type, 58 // use POD types or type with marshalling & unmarshalling func defined in RSMarshallingHelper for construction 59 // parameters, otherwise you should define marshalling & unmarshalling func for your param type. 60 // Especially, don't use enum class type directly, convert it to int 61 class RSCommand : public Parcelable { 62 public: 63 RSCommand() = default; 64 RSCommand(const RSCommand&) = delete; 65 RSCommand(const RSCommand&&) = delete; 66 RSCommand& operator=(const RSCommand&) = delete; 67 RSCommand& operator=(const RSCommand&&) = delete; 68 ~RSCommand() noexcept override = default; 69 70 virtual void Process(RSContext& context) = 0; 71 GetAccessPermission()72 virtual RSCommandPermissionType GetAccessPermission() const 73 { 74 return RSCommandPermissionType::PERMISSION_SYSTEM; 75 } 76 GetType()77 virtual uint16_t GetType() const 78 { 79 return 0; 80 } 81 GetSubType()82 virtual uint16_t GetSubType() const 83 { 84 return 0; 85 } 86 GetDrawCmdList()87 virtual std::shared_ptr<Drawing::DrawCmdList> GetDrawCmdList() const 88 { 89 return nullptr; 90 } 91 GetUniqueType()92 std::pair<uint16_t, uint16_t> GetUniqueType() const 93 { 94 return std::make_pair(GetType(), GetSubType()); 95 } 96 GetNodeId()97 virtual NodeId GetNodeId() const 98 { 99 return 0; 100 } 101 GetToken()102 virtual uint64_t GetToken() const 103 { 104 return 0; 105 } 106 PrintType()107 std::string PrintType() const 108 { 109 return "commandType:[" + std::to_string(GetType()) + ", " + std::to_string(GetSubType()) + "], "; 110 } 111 SetCallingPidValid(bool isCallingPidValid)112 void SetCallingPidValid(bool isCallingPidValid) 113 { 114 if (isCallingPidValid_.load() != isCallingPidValid) { 115 isCallingPidValid_.store(isCallingPidValid); 116 } 117 } 118 IsCallingPidValid()119 bool IsCallingPidValid() const 120 { 121 return isCallingPidValid_.load(); 122 } 123 124 private: 125 size_t indexVerifier_ = 0; 126 std::atomic_bool isCallingPidValid_ = true; 127 friend class RSTransactionData; 128 #ifdef RS_PROFILER_ENABLED 129 protected: 130 using PatchFunction = NodeId (*)(NodeId); 131 132 private: 133 friend class RSProfiler; Patch(PatchFunction function)134 virtual void Patch(PatchFunction function) {}; 135 #endif 136 }; 137 138 class RSSyncTask : public RSCommand { 139 public: RSSyncTask(uint64_t timeoutNS)140 RSSyncTask(uint64_t timeoutNS) : timeoutNS_(timeoutNS) {} 141 142 virtual bool CheckHeader(Parcel& parcel) const = 0; 143 virtual bool ReadFromParcel(Parcel& parcel) = 0; IsCallingPidValid(pid_t callingPid,const RSRenderNodeMap & nodeMap)144 virtual bool IsCallingPidValid(pid_t callingPid, const RSRenderNodeMap& nodeMap) const 145 { 146 return true; 147 } GetType()148 virtual uint16_t GetType() const override 149 { 150 return 0; 151 } 152 GetTimeout()153 inline uint64_t GetTimeout() const 154 { 155 return timeoutNS_; 156 } IsSuccess()157 inline bool IsSuccess() const 158 { 159 return success_; 160 } 161 162 protected: 163 uint64_t timeoutNS_ = 0; 164 bool success_ = false; 165 }; 166 167 } // namespace Rosen 168 } // namespace OHOS 169 170 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_H 171