mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:57:44 +00:00
WindowServer+LibGUI: Pass the system theme using Core::AnonymousBuffer
This was the last remaining user of shbufs in WindowServer, and so WindowServer no longer pledges "shared_buffer" :^)
This commit is contained in:
parent
9c6c18d9b6
commit
04f95f9160
13 changed files with 51 additions and 56 deletions
|
@ -31,13 +31,13 @@
|
|||
|
||||
namespace Gfx {
|
||||
|
||||
NonnullRefPtr<PaletteImpl> PaletteImpl::create_with_shared_buffer(SharedBuffer& buffer)
|
||||
NonnullRefPtr<PaletteImpl> PaletteImpl::create_with_anonymous_buffer(Core::AnonymousBuffer buffer)
|
||||
{
|
||||
return adopt(*new PaletteImpl(buffer));
|
||||
return adopt(*new PaletteImpl(move(buffer)));
|
||||
}
|
||||
|
||||
PaletteImpl::PaletteImpl(SharedBuffer& buffer)
|
||||
: m_theme_buffer(buffer)
|
||||
PaletteImpl::PaletteImpl(Core::AnonymousBuffer buffer)
|
||||
: m_theme_buffer(move(buffer))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ Palette::~Palette()
|
|||
|
||||
const SystemTheme& PaletteImpl::theme() const
|
||||
{
|
||||
return *m_theme_buffer->data<SystemTheme>();
|
||||
return *m_theme_buffer.data<SystemTheme>();
|
||||
}
|
||||
|
||||
Color PaletteImpl::color(ColorRole role) const
|
||||
|
@ -75,9 +75,9 @@ String PaletteImpl::path(PathRole role) const
|
|||
|
||||
NonnullRefPtr<PaletteImpl> PaletteImpl::clone() const
|
||||
{
|
||||
auto new_theme_buffer = SharedBuffer::create_with_size(m_theme_buffer->size());
|
||||
memcpy(new_theme_buffer->data<SystemTheme>(), &theme(), m_theme_buffer->size());
|
||||
return adopt(*new PaletteImpl(*new_theme_buffer));
|
||||
auto new_theme_buffer = Core::AnonymousBuffer::create_with_size(m_theme_buffer.size());
|
||||
memcpy(new_theme_buffer.data<SystemTheme>(), &theme(), m_theme_buffer.size());
|
||||
return adopt(*new PaletteImpl(move(new_theme_buffer)));
|
||||
}
|
||||
|
||||
void Palette::set_color(ColorRole role, Color color)
|
||||
|
@ -109,9 +109,9 @@ PaletteImpl::~PaletteImpl()
|
|||
{
|
||||
}
|
||||
|
||||
void PaletteImpl::replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer)
|
||||
void PaletteImpl::replace_internal_buffer(Badge<GUI::Application>, Core::AnonymousBuffer buffer)
|
||||
{
|
||||
m_theme_buffer = buffer;
|
||||
m_theme_buffer = move(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class PaletteImpl : public RefCounted<PaletteImpl> {
|
|||
|
||||
public:
|
||||
~PaletteImpl();
|
||||
static NonnullRefPtr<PaletteImpl> create_with_shared_buffer(SharedBuffer&);
|
||||
static NonnullRefPtr<PaletteImpl> create_with_anonymous_buffer(Core::AnonymousBuffer);
|
||||
NonnullRefPtr<PaletteImpl> clone() const;
|
||||
|
||||
Color color(ColorRole) const;
|
||||
|
@ -49,12 +49,12 @@ public:
|
|||
String path(PathRole) const;
|
||||
const SystemTheme& theme() const;
|
||||
|
||||
void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer);
|
||||
void replace_internal_buffer(Badge<GUI::Application>, Core::AnonymousBuffer buffer);
|
||||
|
||||
private:
|
||||
explicit PaletteImpl(SharedBuffer&);
|
||||
explicit PaletteImpl(Core::AnonymousBuffer);
|
||||
|
||||
RefPtr<SharedBuffer> m_theme_buffer;
|
||||
Core::AnonymousBuffer m_theme_buffer;
|
||||
};
|
||||
|
||||
class Palette {
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace Gfx {
|
|||
|
||||
static SystemTheme dummy_theme;
|
||||
static const SystemTheme* theme_page = &dummy_theme;
|
||||
static RefPtr<SharedBuffer> theme_buffer;
|
||||
static Core::AnonymousBuffer theme_buffer;
|
||||
|
||||
const SystemTheme& current_system_theme()
|
||||
{
|
||||
|
@ -41,24 +41,24 @@ const SystemTheme& current_system_theme()
|
|||
return *theme_page;
|
||||
}
|
||||
|
||||
int current_system_theme_buffer_id()
|
||||
Core::AnonymousBuffer& current_system_theme_buffer()
|
||||
{
|
||||
ASSERT(theme_buffer);
|
||||
return theme_buffer->shbuf_id();
|
||||
ASSERT(theme_buffer.is_valid());
|
||||
return theme_buffer;
|
||||
}
|
||||
|
||||
void set_system_theme(SharedBuffer& buffer)
|
||||
void set_system_theme(Core::AnonymousBuffer buffer)
|
||||
{
|
||||
theme_buffer = buffer;
|
||||
theme_page = theme_buffer->data<SystemTheme>();
|
||||
theme_buffer = move(buffer);
|
||||
theme_page = theme_buffer.data<SystemTheme>();
|
||||
}
|
||||
|
||||
RefPtr<SharedBuffer> load_system_theme(const String& path)
|
||||
Core::AnonymousBuffer load_system_theme(const String& path)
|
||||
{
|
||||
auto file = Core::ConfigFile::open(path);
|
||||
auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme));
|
||||
auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme));
|
||||
|
||||
auto* data = buffer->data<SystemTheme>();
|
||||
auto* data = buffer.data<SystemTheme>();
|
||||
|
||||
auto get_color = [&](auto& name) {
|
||||
auto color_string = file->read_entry("Colors", name);
|
||||
|
@ -121,9 +121,6 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|||
|
||||
DO_PATH(TitleButtonIcons);
|
||||
|
||||
buffer->seal();
|
||||
buffer->share_globally();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Forward.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCore/AnonymousBuffer.h>
|
||||
#include <LibGfx/Color.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
@ -153,9 +154,9 @@ struct SystemTheme {
|
|||
};
|
||||
|
||||
const SystemTheme& current_system_theme();
|
||||
int current_system_theme_buffer_id();
|
||||
void set_system_theme(SharedBuffer&);
|
||||
RefPtr<SharedBuffer> load_system_theme(const String& path);
|
||||
Core::AnonymousBuffer& current_system_theme_buffer();
|
||||
void set_system_theme(Core::AnonymousBuffer);
|
||||
Core::AnonymousBuffer load_system_theme(const String& path);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue