1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:48:14 +00:00

GraphicsBitmap: create_wrapper() should take pitch as a parameter

We shouldn't assume that the pitch of some arbitrary bitmap memory that
we're wrapping is going to be 16-byte aligned. Instead, just take the
pitch as a parameter.

Also update WindowServer to pass the pitch to the framebuffer bitmaps.
This commit is contained in:
Andreas Kling 2019-08-19 13:29:19 +02:00
parent d11d847161
commit 7038935f74
4 changed files with 13 additions and 9 deletions

View file

@ -24,9 +24,9 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size)
m_needs_munmap = true; m_needs_munmap = true;
} }
NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Size& size, RGBA32* data) NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Size& size, size_t pitch, RGBA32* data)
{ {
return adopt(*new GraphicsBitmap(format, size, data)); return adopt(*new GraphicsBitmap(format, size, pitch, data));
} }
RefPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const StringView& path) RefPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const StringView& path)
@ -42,10 +42,10 @@ RefPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(Format format, const Strin
return adopt(*new GraphicsBitmap(format, size, move(mapped_file))); return adopt(*new GraphicsBitmap(format, size, move(mapped_file)));
} }
GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, RGBA32* data) GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, size_t pitch, RGBA32* data)
: m_size(size) : m_size(size)
, m_data(data) , m_data(data)
, m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16)) , m_pitch(pitch)
, m_format(format) , m_format(format)
{ {
ASSERT(format != Format::Indexed8); ASSERT(format != Format::Indexed8);

View file

@ -20,7 +20,7 @@ public:
}; };
static NonnullRefPtr<GraphicsBitmap> create(Format, const Size&); static NonnullRefPtr<GraphicsBitmap> create(Format, const Size&);
static NonnullRefPtr<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*); static NonnullRefPtr<GraphicsBitmap> create_wrapper(Format, const Size&, size_t pitch, RGBA32*);
static RefPtr<GraphicsBitmap> load_from_file(const StringView& path); static RefPtr<GraphicsBitmap> load_from_file(const StringView& path);
static RefPtr<GraphicsBitmap> load_from_file(Format, const StringView& path, const Size&); static RefPtr<GraphicsBitmap> load_from_file(Format, const StringView& path, const Size&);
static NonnullRefPtr<GraphicsBitmap> create_with_shared_buffer(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); static NonnullRefPtr<GraphicsBitmap> create_with_shared_buffer(Format, NonnullRefPtr<SharedBuffer>&&, const Size&);
@ -94,7 +94,7 @@ public:
private: private:
GraphicsBitmap(Format, const Size&); GraphicsBitmap(Format, const Size&);
GraphicsBitmap(Format, const Size&, RGBA32*); GraphicsBitmap(Format, const Size&, size_t pitch, RGBA32*);
GraphicsBitmap(Format, const Size&, MappedFile&&); GraphicsBitmap(Format, const Size&, MappedFile&&);
GraphicsBitmap(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); GraphicsBitmap(Format, NonnullRefPtr<SharedBuffer>&&, const Size&);

View file

@ -60,12 +60,15 @@ WSCompositor::WSCompositor()
void WSCompositor::init_bitmaps() void WSCompositor::init_bitmaps()
{ {
auto size = WSScreen::the().size(); auto& screen = WSScreen::the();
auto size = screen.size();
m_front_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, size, WSScreen::the().scanline(0)); m_front_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, size, screen.pitch(), screen.scanline(0));
ASSERT(m_screen_can_set_buffer);
if (m_screen_can_set_buffer) if (m_screen_can_set_buffer)
m_back_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, size, WSScreen::the().scanline(size.height())); m_back_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, size, screen.pitch(), screen.scanline(size.height()));
else else
m_back_bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGB32, size); m_back_bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGB32, size);

View file

@ -16,6 +16,7 @@ public:
int width() const { return m_width; } int width() const { return m_width; }
int height() const { return m_height; } int height() const { return m_height; }
size_t pitch() const { return m_pitch; }
RGBA32* scanline(int y); RGBA32* scanline(int y);
static WSScreen& the(); static WSScreen& the();