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 FRAME_RATE_LINKER, 44 }; 45 46 // [attention] 47 // RSCommand object is serializable, when use ADD_COMMAND macro to define a new RSCommand type, 48 // use POD types or type with marshalling & unmarshalling func defined in RSMarshallingHelper for construction 49 // parameters, otherwise you should define marshalling & unmarshalling func for your param type. 50 // Especially, don't use enum class type directly, convert it to int 51 class RSCommand : public Parcelable { 52 public: 53 RSCommand() = default; 54 RSCommand(const RSCommand&) = delete; 55 RSCommand(const RSCommand&&) = delete; 56 RSCommand& operator=(const RSCommand&) = delete; 57 RSCommand& operator=(const RSCommand&&) = delete; 58 ~RSCommand() noexcept override = default; 59 60 virtual void Process(RSContext& context) = 0; 61 GetType()62 virtual uint16_t GetType() const 63 { 64 return 0; 65 } 66 GetSubType()67 virtual uint16_t GetSubType() const 68 { 69 return 0; 70 } 71 GetNodeId()72 virtual NodeId GetNodeId() const 73 { 74 return 0; 75 } 76 PrintType()77 std::string PrintType() const 78 { 79 return "commandType:[" + std::to_string(GetType()) + ", " + std::to_string(GetSubType()) + "], "; 80 } 81 }; 82 83 class RSSyncTask : public RSCommand { 84 public: RSSyncTask(uint64_t timeoutNS)85 RSSyncTask(uint64_t timeoutNS) : timeoutNS_(timeoutNS) {} 86 87 virtual bool CheckHeader(Parcel& parcel) const = 0; 88 virtual bool ReadFromParcel(Parcel& parcel) = 0; 89 GetTimeout()90 inline uint64_t GetTimeout() const 91 { 92 return timeoutNS_; 93 } IsSuccess()94 inline bool IsSuccess() const 95 { 96 return success_; 97 } 98 99 protected: 100 uint64_t timeoutNS_ = 0; 101 bool success_ = false; 102 }; 103 104 } // namespace Rosen 105 } // namespace OHOS 106 107 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_H 108