mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
LibDraw: Create purgeable GraphicsBitmap in the PNG decoder
Also add ImageDecoder APIs for controlling the volatile flag.
This commit is contained in:
parent
77ae98a9b6
commit
7cc4b90b16
3 changed files with 21 additions and 1 deletions
|
@ -14,6 +14,9 @@ public:
|
||||||
virtual Size size() = 0;
|
virtual Size size() = 0;
|
||||||
virtual RefPtr<GraphicsBitmap> bitmap() = 0;
|
virtual RefPtr<GraphicsBitmap> bitmap() = 0;
|
||||||
|
|
||||||
|
virtual void set_volatile() = 0;
|
||||||
|
[[nodiscard]] virtual bool set_nonvolatile() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ImageDecoderPlugin() {}
|
ImageDecoderPlugin() {}
|
||||||
};
|
};
|
||||||
|
@ -27,6 +30,8 @@ public:
|
||||||
int width() const { return size().width(); }
|
int width() const { return size().width(); }
|
||||||
int height() const { return size().height(); }
|
int height() const { return size().height(); }
|
||||||
RefPtr<GraphicsBitmap> bitmap() const { return m_plugin->bitmap(); }
|
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:
|
private:
|
||||||
ImageDecoder(const u8*, size_t);
|
ImageDecoder(const u8*, size_t);
|
||||||
|
|
|
@ -515,7 +515,7 @@ static bool decode_png_bitmap(PNGLoadingContext& context)
|
||||||
#ifdef PNG_STOPWATCH_DEBUG
|
#ifdef PNG_STOPWATCH_DEBUG
|
||||||
Stopwatch sw("load_png_impl: create bitmap");
|
Stopwatch sw("load_png_impl: create bitmap");
|
||||||
#endif
|
#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);
|
unfilter(context);
|
||||||
|
@ -701,3 +701,16 @@ RefPtr<GraphicsBitmap> PNGImageDecoderPlugin::bitmap()
|
||||||
ASSERT(m_context->bitmap);
|
ASSERT(m_context->bitmap);
|
||||||
return 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();
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ public:
|
||||||
|
|
||||||
virtual Size size() override;
|
virtual Size size() override;
|
||||||
virtual RefPtr<GraphicsBitmap> bitmap() override;
|
virtual RefPtr<GraphicsBitmap> bitmap() override;
|
||||||
|
virtual void set_volatile() override;
|
||||||
|
[[nodiscard]] virtual bool set_nonvolatile() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OwnPtr<PNGLoadingContext> m_context;
|
OwnPtr<PNGLoadingContext> m_context;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue