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