Skip to content

Commit

Permalink
PNGLoader: Tag the decoded bitmap with the source PNG path.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Apr 30, 2019
1 parent d55ff47 commit f4b190c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion SharedGraphics/GraphicsBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size)
size_t size_in_bytes = size.area() * sizeof(RGBA32);
m_data = (RGBA32*)mmap(nullptr, size_in_bytes, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
ASSERT(m_data && m_data != (void*)-1);
set_mmap_name(m_data, size_in_bytes, String::format("GraphicsBitmap [%dx%d]", width(), height()).characters());
m_needs_munmap = true;
set_mmap_name(String::format("GraphicsBitmap [%dx%d]", width(), height()).characters());
}

Retained<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Size& size, RGBA32* data)
Expand Down Expand Up @@ -83,3 +83,9 @@ GraphicsBitmap::~GraphicsBitmap()
m_data = nullptr;
}

void GraphicsBitmap::set_mmap_name(const String& name)
{
ASSERT(m_needs_munmap);
size_t size_in_bytes = m_size.area() * sizeof(RGBA32);
::set_mmap_name(m_data, size_in_bytes, name.characters());
}
2 changes: 2 additions & 0 deletions SharedGraphics/GraphicsBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class GraphicsBitmap : public Retainable<GraphicsBitmap> {
bool has_alpha_channel() const { return m_format == Format::RGBA32; }
Format format() const { return m_format; }

void set_mmap_name(const String&);

private:
GraphicsBitmap(Format, const Size&);
GraphicsBitmap(Format, const Size&, RGBA32*);
Expand Down
6 changes: 5 additions & 1 deletion SharedGraphics/PNGLoader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <SharedGraphics/PNGLoader.h>
#include <AK/NetworkOrdered.h>
#include <AK/MappedFile.h>
#include <AK/FileSystemPath.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
Expand Down Expand Up @@ -105,7 +106,10 @@ RetainPtr<GraphicsBitmap> load_png(const String& path)
MappedFile mapped_file(path);
if (!mapped_file.is_valid())
return nullptr;
return load_png_impl((const byte*)mapped_file.pointer(), mapped_file.size());
auto bitmap = load_png_impl((const byte*)mapped_file.pointer(), mapped_file.size());
if (bitmap)
bitmap->set_mmap_name(String::format("GraphicsBitmap [%dx%d] - Decoded PNG: %s", bitmap->width(), bitmap->height(), FileSystemPath(path).string().characters()));
return bitmap;
}

[[gnu::always_inline]] static inline byte paeth_predictor(int a, int b, int c)
Expand Down

0 comments on commit f4b190c

Please sign in to comment.