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 RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H 17 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H 18 19 #include <event_handler.h> 20 #include <message_parcel.h> 21 #include <mutex> 22 #include <parcel.h> 23 #include <refbase.h> 24 25 #include "common/rs_common_def.h" 26 #include "common/rs_macros.h" 27 #include "transaction/rs_transaction_handler.h" 28 29 namespace OHOS { 30 namespace Rosen { 31 32 class RSC_EXPORT RSTransaction : public Parcelable { 33 public: 34 RSTransaction() = default; 35 RSTransaction(const RSTransaction&) = delete; 36 RSTransaction(const RSTransaction&&) = delete; 37 RSTransaction& operator=(const RSTransaction&) = delete; 38 RSTransaction& operator=(const RSTransaction&&) = delete; 39 ~RSTransaction() override = default; 40 41 static RSTransaction* Unmarshalling(Parcel& parcel); 42 bool Marshalling(Parcel& parcel) const override; 43 44 static void FlushImplicitTransaction(); // planing 45 void OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr); 46 void CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr); 47 48 void Begin(); 49 void Commit(); 50 SetDuration(int32_t duration)51 void SetDuration(int32_t duration) { duration_ = duration; } GetDuration()52 int32_t GetDuration() const { return duration_; } 53 SetParentPid(int32_t parentPid)54 void SetParentPid(int32_t parentPid) 55 { 56 parentPid_ = parentPid; 57 } 58 GetParentPid()59 int32_t GetParentPid() const 60 { 61 return parentPid_; 62 } 63 IsOpenSyncTransaction()64 bool IsOpenSyncTransaction() const 65 { 66 return isOpenSyncTransaction_; 67 } 68 GetSyncId()69 uint64_t GetSyncId() const 70 { 71 return syncId_; 72 } 73 74 private: 75 uint64_t GenerateSyncId(); 76 void ResetSyncTransactionInfo(); 77 bool UnmarshallingParam(Parcel& parcel); 78 SetTransactionHandler(std::shared_ptr<RSTransactionHandler> rsTransactionHandler)79 void SetTransactionHandler(std::shared_ptr<RSTransactionHandler> rsTransactionHandler) 80 { 81 rsTransactionHandler_ = rsTransactionHandler; 82 } 83 uint64_t syncId_ { 0 }; 84 std::mutex mutex_; 85 mutable int32_t transactionCount_ { 0 }; 86 int32_t duration_ = 0; 87 int32_t parentPid_ { -1 }; 88 bool isOpenSyncTransaction_ = false; 89 std::shared_ptr<RSTransactionHandler> rsTransactionHandler_ = nullptr; 90 91 friend class RSSyncTransactionController; 92 friend class RSSyncTransactionHandler; 93 }; 94 95 } // namespace Rosen 96 } // namespace OHOS 97 98 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H 99