Skip to content

Commit

Permalink
Add isSurfaceRunning / getRunningSurfaces util functions to SurfaceMa…
Browse files Browse the repository at this point in the history
…nager (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
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Jan 7, 2025
1 parent 25c673e commit 44525aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ void SurfaceManager::startSurface(
}

void SurfaceManager::stopSurface(SurfaceId surfaceId) noexcept {
bool surfaceWasRunning = false;
visit(surfaceId, [&](const SurfaceHandler& surfaceHandler) {
surfaceHandler.stop();
scheduler_.unregisterSurface(surfaceHandler);
surfaceWasRunning = true;
});
if (!surfaceWasRunning) {
LOG(WARNING)
<< "SurfaceManager::stopSurface tried to stop a surface which was not running, surfaceId = "
<< surfaceId;
}

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

void SurfaceManager::stopAllSurfaces() noexcept {
auto surfaceIds = getRunningSurfaces();
for (const auto& surfaceId : surfaceIds) {
stopSurface(surfaceId);
}
}

bool SurfaceManager::isSurfaceRunning(SurfaceId surfaceId) const noexcept {
std::shared_lock lock(mutex_);
return registry_.contains(surfaceId);
}

std::unordered_set<SurfaceId> SurfaceManager::getRunningSurfaces()
const noexcept {
std::unordered_set<SurfaceId> surfaceIds;
{
std::shared_lock lock(mutex_);
for (const auto& [surfaceId, _] : registry_) {
surfaceIds.insert(surfaceId);
}
}
for (const auto& surfaceId : surfaceIds) {
stopSurface(surfaceId);
}
return surfaceIds;
}

Size SurfaceManager::measureSurface(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class SurfaceManager final {

void stopAllSurfaces() noexcept;

bool isSurfaceRunning(SurfaceId surfaceId) const noexcept;

std::unordered_set<SurfaceId> getRunningSurfaces() const noexcept;

Size measureSurface(
SurfaceId surfaceId,
const LayoutConstraints& layoutConstraints,
Expand Down

0 comments on commit 44525aa

Please sign in to comment.