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 25 namespace OHOS { 26 namespace Rosen { 27 28 enum RSCommandType : uint16_t { 29 // node commands 30 BASE_NODE, 31 RS_NODE, // formerly RSPropertyNode 32 CANVAS_NODE, // formerly RSNode 33 SURFACE_NODE, 34 PROXY_NODE, 35 ROOT_NODE, 36 DISPLAY_NODE, 37 EFFECT_NODE, 38 CANVAS_DRAWING_NODE, 39 // animation commands 40 ANIMATION, 41 // read showing properties (deprecated, will be removed later) 42 RS_NODE_SYNCHRONOUS_READ_PROPERTY, 43 }; 44 45 // [attention] 46 // RSCommand object is serializable, when use ADD_COMMAND macro to define a new RSCommand type, 47 // use POD types or type with marshalling & unmarshalling func defined in RSMarshallingHelper for construction 48 // parameters, otherwise you should define marshalling & unmarshalling func for your param type. 49 // Especially, don't use enum class type directly, convert it to int 50 class RSCommand : public Parcelable { 51 public: 52 RSCommand() = default; 53 RSCommand(const RSCommand&) = delete; 54 RSCommand(const RSCommand&&) = delete; 55 RSCommand& operator=(const RSCommand&) = delete; 56 RSCommand& operator=(const RSCommand&&) = delete; 57 ~RSCommand() noexcept override = default; 58 59 virtual void Process(RSContext& context) = 0; 60 GetType()61 virtual uint16_t GetType() const 62 { 63 return 0; 64 } 65 GetSubType()66 virtual uint16_t GetSubType() const 67 { 68 return 0; 69 } 70 GetNodeId()71 virtual NodeId GetNodeId() const 72 { 73 return 0; 74 } 75 PrintType()76 std::string PrintType() const 77 { 78 return "commandType:[" + std::to_string(GetType()) + ", " + std::to_string(GetSubType()) + "], "; 79 } 80 }; 81 82 class RSSyncTask : public RSCommand { 83 public: RSSyncTask(uint64_t timeoutNS)84 RSSyncTask(uint64_t timeoutNS) : timeoutNS_(timeoutNS) {} 85 86 virtual bool CheckHeader(Parcel& parcel) const = 0; 87 virtual bool ReadFromParcel(Parcel& parcel) = 0; 88 GetTimeout()89 inline uint64_t GetTimeout() const 90 { 91 return timeoutNS_; 92 } GetResult()93 inline bool GetResult() const 94 { 95 return result_; 96 } 97 98 protected: 99 uint64_t timeoutNS_ = 0; 100 bool result_ = false; 101 }; 102 103 } // namespace Rosen 104 } // namespace OHOS 105 106 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_H 107