diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-30 13:46:03 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-30 13:46:03 +0200 |
commit | f4b190c58b5153c2f52ac610d1932dcce37ff712 (patch) | |
tree | ab98a491d48dabb634511cefc95315aa314b88db | |
parent | d55ff4756a3e9f7bf48dfc86c52580dd7bd1279b (diff) | |
download | serenity-f4b190c58b5153c2f52ac610d1932dcce37ff712.zip |
PNGLoader: Tag the decoded bitmap with the source PNG path.
-rw-r--r-- | SharedGraphics/GraphicsBitmap.cpp | 8 | ||||
-rw-r--r-- | SharedGraphics/GraphicsBitmap.h | 2 | ||||
-rw-r--r-- | SharedGraphics/PNGLoader.cpp | 6 |
3 files changed, 14 insertions, 2 deletions
diff --git a/SharedGraphics/GraphicsBitmap.cpp b/SharedGraphics/GraphicsBitmap.cpp index 16831acc84..160d39762f 100644 --- a/SharedGraphics/GraphicsBitmap.cpp +++ b/SharedGraphics/GraphicsBitmap.cpp @@ -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) @@ -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()); +} diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h index 75b55a0b82..ba7f3fd667 100644 --- a/SharedGraphics/GraphicsBitmap.h +++ b/SharedGraphics/GraphicsBitmap.h @@ -33,6 +33,8 @@ public: 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*); diff --git a/SharedGraphics/PNGLoader.cpp b/SharedGraphics/PNGLoader.cpp index f2b8721808..3238269d08 100644 --- a/SharedGraphics/PNGLoader.cpp +++ b/SharedGraphics/PNGLoader.cpp @@ -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> @@ -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) |