Skip to content

Commit 4e013a3

Browse files
authored
fix(builtin_scene): use std::async to make each web content rendering run in parallel (#310)
1 parent f918ddf commit 4e013a3

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/client/builtin_scene/web_content_renderer.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cmath>
44
#include <algorithm>
55
#include <cstring>
6+
#include <future>
67

78
#include <skia/include/core/SkCanvas.h>
89
#include <skia/include/core/SkPaint.h>
@@ -331,13 +332,28 @@ namespace builtin_scene::web_renderer
331332
if (list.size() == 0)
332333
return;
333334

335+
vector<future<void>> futures;
336+
futures.reserve(list.size());
337+
338+
// Lambda to render a single WebContent entity
339+
auto renderContent = [this](ecs::EntityId entity, WebContent &content)
340+
{
341+
if (render(entity, content))
342+
content.setSurfaceDirty(true);
343+
};
344+
345+
// Schedule rendering tasks for each dirty WebContent entity
334346
for (auto &item : list)
335347
{
336348
ecs::EntityId entity = item.first;
337349
WebContent &content = *item.second;
338-
if (render(entity, content))
339-
content.setSurfaceDirty(true);
350+
futures.emplace_back(async(launch::async, [&renderContent, entity, &content]()
351+
{ renderContent(entity, content); }));
340352
}
353+
354+
// Wait for all rendering tasks to complete
355+
for (auto &future : futures)
356+
future.wait();
341357
}
342358

343359
// Create a gradient shader based on the computed image and rounded rectangle.

0 commit comments

Comments
 (0)