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