diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-18 20:50:58 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-18 20:50:58 +0100 |
commit | 7cc4b90b169c8134bc1f806f7102370edc36ac5f (patch) | |
tree | 2b6c7343e67f1e033ab5e8d61ddbc9ab1a8d8cf4 | |
parent | 77ae98a9b69802ff6f7c0aacc08352d76dec7439 (diff) | |
download | serenity-7cc4b90b169c8134bc1f806f7102370edc36ac5f.zip |
LibDraw: Create purgeable GraphicsBitmap in the PNG decoder
Also add ImageDecoder APIs for controlling the volatile flag.
-rw-r--r-- | Libraries/LibDraw/ImageDecoder.h | 5 | ||||
-rw-r--r-- | Libraries/LibDraw/PNGLoader.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibDraw/PNGLoader.h | 2 |
3 files changed, 21 insertions, 1 deletions
diff --git a/Libraries/LibDraw/ImageDecoder.h b/Libraries/LibDraw/ImageDecoder.h index 90ba053184..f3397b9aff 100644 --- a/Libraries/LibDraw/ImageDecoder.h +++ b/Libraries/LibDraw/ImageDecoder.h @@ -14,6 +14,9 @@ public: virtual Size size() = 0; virtual RefPtr<GraphicsBitmap> bitmap() = 0; + virtual void set_volatile() = 0; + [[nodiscard]] virtual bool set_nonvolatile() = 0; + protected: ImageDecoderPlugin() {} }; @@ -27,6 +30,8 @@ public: int width() const { return size().width(); } int height() const { return size().height(); } RefPtr<GraphicsBitmap> bitmap() const { return m_plugin->bitmap(); } + void set_volatile() { m_plugin->set_volatile(); } + [[nodiscard]] bool set_nonvolatile() { return m_plugin->set_nonvolatile(); } private: ImageDecoder(const u8*, size_t); diff --git a/Libraries/LibDraw/PNGLoader.cpp b/Libraries/LibDraw/PNGLoader.cpp index 3c157df745..508641f1f0 100644 --- a/Libraries/LibDraw/PNGLoader.cpp +++ b/Libraries/LibDraw/PNGLoader.cpp @@ -515,7 +515,7 @@ static bool decode_png_bitmap(PNGLoadingContext& context) #ifdef PNG_STOPWATCH_DEBUG Stopwatch sw("load_png_impl: create bitmap"); #endif - context.bitmap = GraphicsBitmap::create(context.has_alpha() ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32, { context.width, context.height }); + context.bitmap = GraphicsBitmap::create_purgeable(context.has_alpha() ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32, { context.width, context.height }); } unfilter(context); @@ -701,3 +701,16 @@ RefPtr<GraphicsBitmap> PNGImageDecoderPlugin::bitmap() ASSERT(m_context->bitmap); return m_context->bitmap; } + +void PNGImageDecoderPlugin::set_volatile() +{ + if (m_context->bitmap) + m_context->bitmap->set_volatile(); +} + +bool PNGImageDecoderPlugin::set_nonvolatile() +{ + if (!m_context->bitmap) + return false; + return m_context->bitmap->set_nonvolatile(); +} diff --git a/Libraries/LibDraw/PNGLoader.h b/Libraries/LibDraw/PNGLoader.h index c72dafe350..f148e6ea25 100644 --- a/Libraries/LibDraw/PNGLoader.h +++ b/Libraries/LibDraw/PNGLoader.h @@ -15,6 +15,8 @@ public: virtual Size size() override; virtual RefPtr<GraphicsBitmap> bitmap() override; + virtual void set_volatile() override; + [[nodiscard]] virtual bool set_nonvolatile() override; private: OwnPtr<PNGLoadingContext> m_context; |