1 /* 2 * Copyright (c) 2021 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_RS_TRANSACTION_PROXY_H 17 #define ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_PROXY_H 18 19 #include <memory> 20 #include <mutex> 21 22 #include "command/rs_command.h" 23 #include "common/rs_singleton.h" 24 #include "transaction/rs_irender_client.h" 25 #include "transaction/rs_transaction_data.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 class RSSyncTask; 30 31 class RSTransactionProxy final { 32 public: 33 static RSTransactionProxy* GetInstance(); 34 void SetRenderThreadClient(std::unique_ptr<RSIRenderClient>& renderThreadClient); 35 void SetRenderServiceClient(const std::shared_ptr<RSIRenderClient>& renderServiceClient); 36 37 void AddCommand(std::unique_ptr<RSCommand>& command, bool isRenderServiceCommand = false); 38 void AddCommandFromRT(std::unique_ptr<RSCommand>& command); 39 40 void FlushImplicitTransaction(); 41 void FlushImplicitTransactionFromRT(); 42 43 void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task, bool isRenderServiceTask = false); 44 private: 45 RSTransactionProxy(); 46 virtual ~RSTransactionProxy(); 47 static void Init(); 48 static void Destory(); 49 50 RSTransactionProxy(const RSTransactionProxy&) = delete; 51 RSTransactionProxy(const RSTransactionProxy&&) = delete; 52 RSTransactionProxy& operator=(const RSTransactionProxy&) = delete; 53 RSTransactionProxy& operator=(const RSTransactionProxy&&) = delete; 54 55 void AddCommonCommand(std::unique_ptr<RSCommand>& command); 56 void AddRemoteCommand(std::unique_ptr<RSCommand>& command); 57 58 // Command Transaction Triggered by UI Thread. 59 std::mutex mutex_; 60 std::unique_ptr<RSTransactionData> implicitCommonTransactionData_{std::make_unique<RSTransactionData>()}; 61 std::unique_ptr<RSTransactionData> implicitRemoteTransactionData_{std::make_unique<RSTransactionData>()}; 62 63 // Command Transaction Triggered by Render Thread which is definitely send to Render Service. 64 std::mutex mutexForRT_; 65 std::unique_ptr<RSTransactionData> implicitTransactionDataFromRT_{std::make_unique<RSTransactionData>()}; 66 67 std::shared_ptr<RSIRenderClient> renderServiceClient_ = RSIRenderClient::CreateRenderServiceClient(); 68 std::unique_ptr<RSIRenderClient> renderThreadClient_ = nullptr; 69 70 static std::once_flag flag_; 71 static RSTransactionProxy* instance_; 72 }; 73 } // namespace Rosen 74 } // namespace OHOS 75 76 #endif // ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_PROXY_H 77