mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
WindowServer: Spawn a secondary thread to decode wallpapers.
The threading API's are not very mature, so this code looks a bit crufty but it does take the load off the WindowServer main thread when changing wallpapers. :^)
This commit is contained in:
parent
cff3685a4c
commit
6614746ca8
3 changed files with 39 additions and 11 deletions
|
@ -188,16 +188,42 @@ void WSWindowManager::tick_clock()
|
|||
invalidate(menubar_rect());
|
||||
}
|
||||
|
||||
bool WSWindowManager::set_wallpaper(const String& path)
|
||||
bool WSWindowManager::set_wallpaper(const String& path, Function<void(bool)>&& callback)
|
||||
{
|
||||
auto bitmap = load_png(path);
|
||||
if (!bitmap)
|
||||
return false;
|
||||
struct Context {
|
||||
String path;
|
||||
RetainPtr<GraphicsBitmap> bitmap;
|
||||
Function<void(bool)> callback;
|
||||
};
|
||||
auto context = make<Context>();
|
||||
context->path = path;
|
||||
context->callback = move(callback);
|
||||
|
||||
int rc = create_thread([] (void* ctx) -> int {
|
||||
OwnPtr<Context> context((Context*)ctx);
|
||||
context->bitmap = load_png(context->path);
|
||||
if (!context->bitmap) {
|
||||
context->callback(false);
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
}
|
||||
the().deferred_invoke([context = move(context)] (auto&) {
|
||||
the().finish_setting_wallpaper(context->path, *context->bitmap);
|
||||
context->callback(true);
|
||||
});
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
}, context.leak_ptr());
|
||||
ASSERT(rc == 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WSWindowManager::finish_setting_wallpaper(const String& path, Retained<GraphicsBitmap>&& bitmap)
|
||||
{
|
||||
m_wallpaper_path = path;
|
||||
m_wallpaper = move(bitmap);
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
void WSWindowManager::set_resolution(int width, int height)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue