Skip to content

Commit

Permalink
Stop all surfaces on SurfaceManager destruction (#48481)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #48481

[Changelog] [Internal] - Stop all surfaces on SurfaceManager destruction

Reviewed By: zeyap

Differential Revision: D67809574

fbshipit-source-id: 150ddd091e6822c3a40f8ea413aa65da50445ede
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Jan 4, 2025
1 parent a6e6f5e commit 6abcca8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@

#include "SurfaceManager.h"

#include <glog/logging.h>
#include <react/renderer/scheduler/Scheduler.h>

namespace facebook::react {

SurfaceManager::SurfaceManager(const Scheduler& scheduler) noexcept
: scheduler_(scheduler) {}

SurfaceManager::~SurfaceManager() noexcept {
LOG(WARNING) << "SurfaceManager::~SurfaceManager() was called (address: "
<< this << ").";
stopAllSurfaces();
}

void SurfaceManager::startSurface(
SurfaceId surfaceId,
const std::string& moduleName,
Expand Down Expand Up @@ -58,6 +65,19 @@ void SurfaceManager::stopSurface(SurfaceId surfaceId) const noexcept {
}
}

void SurfaceManager::stopAllSurfaces() 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);
}
}

Size SurfaceManager::measureSurface(
SurfaceId surfaceId,
const LayoutConstraints& layoutConstraints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace facebook::react {
class SurfaceManager final {
public:
explicit SurfaceManager(const Scheduler& scheduler) noexcept;
~SurfaceManager() noexcept;

#pragma mark - Surface Management

Expand All @@ -44,6 +45,8 @@ class SurfaceManager final {

void stopSurface(SurfaceId surfaceId) const noexcept;

void stopAllSurfaces() const noexcept;

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

0 comments on commit 6abcca8

Please sign in to comment.