Skip to content

Commit 44525aa

Browse files
Add isSurfaceRunning / getRunningSurfaces util functions to SurfaceManager (facebook#48484)
Summary: Pull Request resolved: facebook#48484 [Changelog] [Internal] - Add isSurfaceRunning / getRunningSurfaces util functions to SurfaceManager This exposes convience getter methods to data already stored in SurfaceManager Reviewed By: rshest Differential Revision: D67814092 fbshipit-source-id: af5e9df3b380d5efc0c11627a0d9a56796526639
1 parent 25c673e commit 44525aa

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ void SurfaceManager::startSurface(
4545
}
4646

4747
void SurfaceManager::stopSurface(SurfaceId surfaceId) noexcept {
48+
bool surfaceWasRunning = false;
4849
visit(surfaceId, [&](const SurfaceHandler& surfaceHandler) {
4950
surfaceHandler.stop();
5051
scheduler_.unregisterSurface(surfaceHandler);
52+
surfaceWasRunning = true;
5153
});
54+
if (!surfaceWasRunning) {
55+
LOG(WARNING)
56+
<< "SurfaceManager::stopSurface tried to stop a surface which was not running, surfaceId = "
57+
<< surfaceId;
58+
}
5259

5360
{
5461
std::unique_lock lock(mutex_);
@@ -59,16 +66,27 @@ void SurfaceManager::stopSurface(SurfaceId surfaceId) noexcept {
5966
}
6067

6168
void SurfaceManager::stopAllSurfaces() noexcept {
69+
auto surfaceIds = getRunningSurfaces();
70+
for (const auto& surfaceId : surfaceIds) {
71+
stopSurface(surfaceId);
72+
}
73+
}
74+
75+
bool SurfaceManager::isSurfaceRunning(SurfaceId surfaceId) const noexcept {
76+
std::shared_lock lock(mutex_);
77+
return registry_.contains(surfaceId);
78+
}
79+
80+
std::unordered_set<SurfaceId> SurfaceManager::getRunningSurfaces()
81+
const noexcept {
6282
std::unordered_set<SurfaceId> surfaceIds;
6383
{
6484
std::shared_lock lock(mutex_);
6585
for (const auto& [surfaceId, _] : registry_) {
6686
surfaceIds.insert(surfaceId);
6787
}
6888
}
69-
for (const auto& surfaceId : surfaceIds) {
70-
stopSurface(surfaceId);
71-
}
89+
return surfaceIds;
7290
}
7391

7492
Size SurfaceManager::measureSurface(

packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class SurfaceManager final {
4242

4343
void stopAllSurfaces() noexcept;
4444

45+
bool isSurfaceRunning(SurfaceId surfaceId) const noexcept;
46+
47+
std::unordered_set<SurfaceId> getRunningSurfaces() const noexcept;
48+
4549
Size measureSurface(
4650
SurfaceId surfaceId,
4751
const LayoutConstraints& layoutConstraints,

0 commit comments

Comments
 (0)