mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:07:34 +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
|
@ -332,11 +332,12 @@ void WSClientConnection::handle_request(const WSAPISetWindowOpacityRequest& requ
|
||||||
|
|
||||||
void WSClientConnection::handle_request(const WSAPISetWallpaperRequest& request)
|
void WSClientConnection::handle_request(const WSAPISetWallpaperRequest& request)
|
||||||
{
|
{
|
||||||
bool success = WSWindowManager::the().set_wallpaper(request.wallpaper());
|
WSWindowManager::the().set_wallpaper(request.wallpaper(), [&] (bool success) {
|
||||||
WSAPI_ServerMessage response;
|
WSAPI_ServerMessage response;
|
||||||
response.type = WSAPI_ServerMessage::Type::DidSetWallpaper;
|
response.type = WSAPI_ServerMessage::Type::DidSetWallpaper;
|
||||||
response.value = success;
|
response.value = success;
|
||||||
post_message(response);
|
post_message(response);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSClientConnection::handle_request(const WSAPIGetWallpaperRequest&)
|
void WSClientConnection::handle_request(const WSAPIGetWallpaperRequest&)
|
||||||
|
|
|
@ -188,16 +188,42 @@ void WSWindowManager::tick_clock()
|
||||||
invalidate(menubar_rect());
|
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);
|
struct Context {
|
||||||
if (!bitmap)
|
String path;
|
||||||
return false;
|
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_path = path;
|
||||||
m_wallpaper = move(bitmap);
|
m_wallpaper = move(bitmap);
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSWindowManager::set_resolution(int width, int height)
|
void WSWindowManager::set_resolution(int width, int height)
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
|
|
||||||
void set_resolution(int width, int height);
|
void set_resolution(int width, int height);
|
||||||
|
|
||||||
bool set_wallpaper(const String& path);
|
bool set_wallpaper(const String& path, Function<void(bool)>&& callback);
|
||||||
String wallpaper_path() const { return m_wallpaper_path; }
|
String wallpaper_path() const { return m_wallpaper_path; }
|
||||||
|
|
||||||
const WSCursor& active_cursor() const;
|
const WSCursor& active_cursor() const;
|
||||||
|
@ -144,6 +144,7 @@ private:
|
||||||
void tell_wm_listener_about_window_icon(WSWindow& listener, WSWindow&);
|
void tell_wm_listener_about_window_icon(WSWindow& listener, WSWindow&);
|
||||||
void tell_wm_listener_about_window_rect(WSWindow& listener, WSWindow&);
|
void tell_wm_listener_about_window_rect(WSWindow& listener, WSWindow&);
|
||||||
void pick_new_active_window();
|
void pick_new_active_window();
|
||||||
|
void finish_setting_wallpaper(const String& path, Retained<GraphicsBitmap>&&);
|
||||||
|
|
||||||
WSScreen& m_screen;
|
WSScreen& m_screen;
|
||||||
Rect m_screen_rect;
|
Rect m_screen_rect;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue