mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
WindowServer: Port threading to LibThread
This commit is contained in:
parent
1ac7fedefe
commit
8d59b10022
5 changed files with 43 additions and 53 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <LibDraw/Font.h>
|
||||
#include <LibDraw/PNGLoader.h>
|
||||
#include <LibDraw/Painter.h>
|
||||
#include <LibThread/BackgroundAction.h>
|
||||
|
||||
// #define COMPOSITOR_DEBUG
|
||||
|
||||
|
@ -265,43 +266,24 @@ void WSCompositor::invalidate(const Rect& a_rect)
|
|||
|
||||
bool WSCompositor::set_wallpaper(const String& path, Function<void(bool)>&& callback)
|
||||
{
|
||||
struct Context {
|
||||
String path;
|
||||
RefPtr<GraphicsBitmap> bitmap;
|
||||
Function<void(bool)> callback;
|
||||
};
|
||||
auto context = make<Context>();
|
||||
context->path = path;
|
||||
context->callback = move(callback);
|
||||
LibThread::BackgroundAction<RefPtr<GraphicsBitmap>>::create(
|
||||
[path] {
|
||||
return load_png(path);
|
||||
},
|
||||
|
||||
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);
|
||||
[this, path, callback = move(callback)](RefPtr<GraphicsBitmap> bitmap) {
|
||||
if (!bitmap) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
m_wallpaper_path = path;
|
||||
m_wallpaper = move(bitmap);
|
||||
invalidate();
|
||||
callback(true);
|
||||
});
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
},
|
||||
context.leak_ptr());
|
||||
ASSERT(rc > 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WSCompositor::finish_setting_wallpaper(const String& path, NonnullRefPtr<GraphicsBitmap>&& bitmap)
|
||||
{
|
||||
m_wallpaper_path = path;
|
||||
m_wallpaper = move(bitmap);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void WSCompositor::flip_buffers()
|
||||
{
|
||||
ASSERT(m_screen_can_set_buffer);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue