• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_NODE_SHOWING_COMMAND_H
17 #define ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_NODE_SHOWING_COMMAND_H
18 
19 #include <map>
20 
21 #include "command/rs_command.h"
22 #include "command/rs_command_factory.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class RSRenderPropertyBase;
27 
28 enum RSNodeShowingCommandType : uint16_t {
29     GET_RENDER_PROPERTY,
30     GET_RENDER_PROPERTIES,
31     GET_VALUE_FRACTION,
32 };
33 
34 class RSB_EXPORT RSNodeGetShowingPropertyAndCancelAnimation : public RSSyncTask {
35     constexpr static uint16_t commandType = RS_NODE_SYNCHRONOUS_READ_PROPERTY;
36     constexpr static uint16_t commandSubType = GET_RENDER_PROPERTY;
37 
38 public:
39     explicit RSNodeGetShowingPropertyAndCancelAnimation(
40         NodeId targetId, std::shared_ptr<RSRenderPropertyBase> property, uint64_t timeoutNS = 1e8)
RSSyncTask(timeoutNS)41         : RSSyncTask(timeoutNS), targetId_(targetId), property_(property)
42     {}
43     ~RSNodeGetShowingPropertyAndCancelAnimation() override = default;
44 
45     bool Marshalling(Parcel& parcel) const override;
46     static RSCommand* Unmarshalling(Parcel& parcel);
47 
48     bool CheckHeader(Parcel& parcel) const override;
49     bool ReadFromParcel(Parcel& parcel) override;
50 
51     void Process(RSContext& context) override;
52     bool IsCallingPidValid(pid_t callingPid, const RSRenderNodeMap& nodeMap) const override;
GetProperty()53     std::shared_ptr<RSRenderPropertyBase> GetProperty() const
54     {
55         return property_;
56     }
IsTimeout()57     bool IsTimeout() const
58     {
59         return isTimeout_;
60     }
GetType()61     uint16_t GetType() const override
62     {
63         return commandType;
64     }
65 
66 private:
67     NodeId targetId_ = 0;
68     std::shared_ptr<RSRenderPropertyBase> property_;
69     bool isTimeout_ = true;
70     using Registrar = RSCommandRegister<commandType, commandSubType, Unmarshalling>;
71     static Registrar instance_;
72 };
73 
74 class RSB_EXPORT RSNodeGetShowingPropertiesAndCancelAnimation : public RSSyncTask {
75     constexpr static uint16_t commandType = RS_NODE_SYNCHRONOUS_READ_PROPERTY;
76     constexpr static uint16_t commandSubType = GET_RENDER_PROPERTIES;
77 
78 public:
79     using PropertiesMap = std::map<std::pair<NodeId, PropertyId>,
80         std::pair<std::shared_ptr<RSRenderPropertyBase>, std::vector<AnimationId>>>;
RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS,PropertiesMap && map)81     explicit RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS, PropertiesMap&& map)
82         : RSSyncTask(timeoutNS), propertiesMap_(std::move(map))
83     {}
84     ~RSNodeGetShowingPropertiesAndCancelAnimation() override = default;
85 
86     bool Marshalling(Parcel& parcel) const override;
87     static RSCommand* Unmarshalling(Parcel& parcel);
88 
89     bool CheckHeader(Parcel& parcel) const override;
90     bool ReadFromParcel(Parcel& parcel) override;
91 
92     void Process(RSContext& context) override;
93     bool IsCallingPidValid(pid_t callingPid, const RSRenderNodeMap& nodeMap) const override;
94 
GetProperties()95     const PropertiesMap& GetProperties() const
96     {
97         return this->propertiesMap_;
98     }
99 
GetType()100     uint16_t GetType() const override
101     {
102         return commandType;
103     }
104 
105 private:
RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS)106     RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS): RSSyncTask(timeoutNS) {}
107     PropertiesMap propertiesMap_;
108     using Registrar = RSCommandRegister<commandType, commandSubType, Unmarshalling>;
109     static Registrar instance_;
110 };
111 
112 class RSB_EXPORT RSNodeGetAnimationsValueFraction: public RSSyncTask {
113     constexpr static uint16_t commandType = RS_NODE_SYNCHRONOUS_GET_VALUE_FRACTION;
114     constexpr static uint16_t commandSubType = GET_VALUE_FRACTION;
115 
116 public:
RSNodeGetAnimationsValueFraction(uint64_t timeoutNS,NodeId nodeId,AnimationId animationId)117     explicit RSNodeGetAnimationsValueFraction(uint64_t timeoutNS, NodeId nodeId, AnimationId animationId)
118         : RSSyncTask(timeoutNS), nodeId_(nodeId), animationId_(animationId)
119     {}
120     ~RSNodeGetAnimationsValueFraction() override = default;
121 
122     bool Marshalling(Parcel& parcel) const override;
123     static RSCommand* Unmarshalling(Parcel& parcel);
124 
125     bool CheckHeader(Parcel& parcel) const override;
126     bool ReadFromParcel(Parcel& parcel) override;
127 
128     void Process(RSContext& context) override;
129     bool IsCallingPidValid(pid_t callingPid, const RSRenderNodeMap& nodeMap) const override;
130 
GetFraction()131     float GetFraction() const
132     {
133         return fraction_;
134     }
135 
GetType()136     uint16_t GetType() const override
137     {
138         return commandType;
139     }
140 
141 private:
RSNodeGetAnimationsValueFraction(uint64_t timeoutNS)142     RSNodeGetAnimationsValueFraction(uint64_t timeoutNS): RSSyncTask(timeoutNS) {}
143     NodeId nodeId_;
144     AnimationId animationId_;
145     float fraction_ { 0.0f };
146     static inline RSCommandRegister<commandType, commandSubType, Unmarshalling> registry;
147 };
148 } // namespace Rosen
149 } // namespace OHOS
150 
151 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_NODE_SHOWING_COMMAND_H