• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "feature/capture/rs_ui_capture_helper.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 namespace {
21 constexpr const uint64_t INVALID_TIME_STAMP = 0;
22 }
InsertUiCaptureCmdsExecutedFlag(NodeId nodeId,bool flag)23 void RSUiCaptureHelper::InsertUiCaptureCmdsExecutedFlag(NodeId nodeId, bool flag)
24 {
25     std::lock_guard<std::mutex> lock(uiCaptureCmdsExecutedMutex_);
26     if (!flag) {
27         auto iter = uiCaptureCmdsExecutedFlag_.find(nodeId);
28         if (iter == uiCaptureCmdsExecutedFlag_.end()) {
29             uiCaptureCmdsExecutedFlag_[nodeId] = std::make_pair(false, GetCurrentSteadyTimeMs());
30         }
31         return;
32     }
33     uiCaptureCmdsExecutedFlag_[nodeId] = std::make_pair(flag, GetCurrentSteadyTimeMs());
34 }
35 
EraseUiCaptureCmdsExecutedFlag(NodeId nodeId)36 void RSUiCaptureHelper::EraseUiCaptureCmdsExecutedFlag(NodeId nodeId)
37 {
38     std::lock_guard<std::mutex> lock(uiCaptureCmdsExecutedMutex_);
39     uiCaptureCmdsExecutedFlag_.erase(nodeId);
40 }
41 
GetUiCaptureCmdsExecutedFlag(NodeId nodeId)42 std::pair<bool, uint64_t> RSUiCaptureHelper::GetUiCaptureCmdsExecutedFlag(NodeId nodeId)
43 {
44     std::lock_guard<std::mutex> lock(uiCaptureCmdsExecutedMutex_);
45     auto iter = uiCaptureCmdsExecutedFlag_.find(nodeId);
46     if (iter != uiCaptureCmdsExecutedFlag_.end()) {
47         return iter->second;
48     } else {
49         return std::make_pair(true, INVALID_TIME_STAMP);
50     }
51 }
52 
GetCurrentSteadyTimeMs() const53 uint64_t RSUiCaptureHelper::GetCurrentSteadyTimeMs() const
54 {
55     auto curTime = std::chrono::steady_clock::now().time_since_epoch();
56     uint64_t curSteadyTime =
57         static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(curTime).count());
58     return curSteadyTime;
59 }
60 } // namespace Rosen
61 } // namespace OHOS