From 31affcdb468a3f0fb8a01046060a19581a86c374 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 23 Feb 2019 15:28:18 +0000 Subject: [PATCH] CtrlCore: Improved Image cache behaviour in Win32 git-svn-id: svn://ultimatepp.org/upp/trunk@12788 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/ImageWin32.cpp | 6 ++++++ uppsrc/Draw/Image.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/uppsrc/CtrlCore/ImageWin32.cpp b/uppsrc/CtrlCore/ImageWin32.cpp index 20ad00f82..601f63d43 100644 --- a/uppsrc/CtrlCore/ImageWin32.cpp +++ b/uppsrc/CtrlCore/ImageWin32.cpp @@ -339,6 +339,12 @@ void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << img.GetSize()); ImageSysDataMaker m; static LRUCache cache; + static int Rsz; + Rsz += img.GetLength(); + if(Rsz > 200 * 200) { // we do not want to do this for each small image painted... + Rsz = 0; + cache.Remove([](const ImageSysData& object) { return object.img.GetRefCount() == 1; }); + } LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount()); Size sz = Ctrl::GetPrimaryScreenArea().GetSize(); m.img = IsPrinter() && GetDeviceCaps(GetHandle(), NUMCOLORS) == 2 ? Dither(img, 360) : img; // If printer does not support color, dither diff --git a/uppsrc/Draw/Image.h b/uppsrc/Draw/Image.h index a18f57edf..b4150bd3a 100644 --- a/uppsrc/Draw/Image.h +++ b/uppsrc/Draw/Image.h @@ -253,6 +253,10 @@ public: char info[24]; }; explicit Image(const Init& init); + + // required by system image cache managemenent + + int GetRefCount() const { return data->refcount; } }; Image Premultiply(const Image& img);