• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <memory>
17 
18 #include "gfx/fps_info/rs_surface_fps_manager.h"
19 
20 namespace OHOS::Rosen {
GetInstance()21 RSSurfaceFpsManager& RSSurfaceFpsManager::GetInstance()
22 {
23     static RSSurfaceFpsManager instance;
24     return instance;
25 }
26 
RegisterSurfaceFps(NodeId id,const std::string & name)27 bool RSSurfaceFpsManager::RegisterSurfaceFps(NodeId id, const std::string& name)
28 {
29     std::unique_lock<std::shared_mutex> lock(smtx);
30     if (surfaceFpsMap_.find(id) != surfaceFpsMap_.end()) {
31         return false;
32     }
33     surfaceFpsMap_[id] = std::make_shared<RSSurfaceFps>(name);
34     return true;
35 }
36 
UnregisterSurfaceFps(NodeId id)37 bool RSSurfaceFpsManager::UnregisterSurfaceFps(NodeId id)
38 {
39     std::unique_lock<std::shared_mutex> lock(smtx);
40     if (surfaceFpsMap_.find(id) == surfaceFpsMap_.end()) {
41         return false;
42     }
43     surfaceFpsMap_.erase(id);
44     return true;
45 }
46 
GetSurfaceFps(NodeId id)47 std::shared_ptr<RSSurfaceFps> RSSurfaceFpsManager::GetSurfaceFps(NodeId id)
48 {
49     std::shared_lock<std::shared_mutex> lock(smtx);
50     auto iter = surfaceFpsMap_.find(id);
51     if (iter == surfaceFpsMap_.end()) {
52         return nullptr;
53     }
54     return iter->second;
55 }
56 
RecordPresentTime(NodeId id,uint64_t timestamp,uint32_t seqNum)57 bool RSSurfaceFpsManager::RecordPresentTime(NodeId id, uint64_t timestamp, uint32_t seqNum)
58 {
59     const auto& surfaceFps = GetSurfaceFps(id);
60     if (surfaceFps == nullptr) {
61         return false;
62     }
63     return surfaceFps->RecordPresentTime(timestamp, seqNum);
64 }
65 
Dump(std::string & result,NodeId id)66 void RSSurfaceFpsManager::Dump(std::string& result, NodeId id)
67 {
68     const auto& surfaceFps = GetSurfaceFps(id);
69     if (surfaceFps == nullptr) {
70         return ;
71     }
72     result += " surface [" + surfaceFps->GetName() + "]:\n";
73     surfaceFps->Dump(result);
74 }
75 
ClearDump(std::string & result,NodeId id)76 void RSSurfaceFpsManager::ClearDump(std::string& result, NodeId id)
77 {
78     const auto& surfaceFps = GetSurfaceFps(id);
79     if (surfaceFps == nullptr) {
80         return ;
81     }
82     result += " The fps info of surface [" + surfaceFps->GetName() + "] is cleared.\n";
83     surfaceFps->ClearDump();
84 }
85 
GetSurfaceFpsMap() const86 std::unordered_map<NodeId, std::shared_ptr<RSSurfaceFps>> RSSurfaceFpsManager::GetSurfaceFpsMap() const
87 {
88     return surfaceFpsMap_;
89 }
90 }