Make rendering stats thread safe [Core feature] (#4059)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Adrian Cojocaru <adrian.cojocaru92@yahoo.com>
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
Alex Cristici
2026-01-21 02:49:45 +02:00
committed by GitHub
parent 4fab83669a
commit a8622a3a4f
5 changed files with 65 additions and 34 deletions

View File

@@ -13,6 +13,8 @@
#include <memory>
#include <string>
#include <mutex>
#include <shared_mutex>
namespace mbgl {
@@ -93,6 +95,16 @@ public:
gfx::RenderingStats& renderingStats() { return stats; }
const gfx::RenderingStats& renderingStats() const { return stats; }
void threadSafeAccessRenderingStats(const std::function<void(RenderingStats&)>& function) {
std::scoped_lock lock(renderingStatsMutex);
function(stats);
}
RenderingStats threadSafeCopyRenderingStats() {
std::shared_lock lock(renderingStatsMutex);
return stats;
}
#ifndef NDEBUG
virtual void visualizeStencilBuffer() = 0;
virtual void visualizeDepthBuffer(float depthRangeSize) = 0;
@@ -174,6 +186,7 @@ protected:
virtual std::unique_ptr<RenderbufferResource> createRenderbufferResource(RenderbufferPixelType, Size) = 0;
virtual std::unique_ptr<DrawScopeResource> createDrawScopeResource() = 0;
std::shared_mutex renderingStatsMutex;
gfx::RenderingStats stats;
ContextObserver* observer;
};