From 84334c34074dff4d0b3c8ac92a33742146f4ba0d Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 21 Apr 2020 08:37:09 +0000 Subject: [PATCH] CtrlCore: ImageWin32 optimisations git-svn-id: svn://ultimatepp.org/upp/trunk@14343 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Debug.cpp | 2 +- uppsrc/Core/heap.cpp | 2 +- uppsrc/CtrlCore/ImageWin32.cpp | 31 ++++++++++++++++--------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/uppsrc/Core/Debug.cpp b/uppsrc/Core/Debug.cpp index 33c9703ef..18b5f4a93 100644 --- a/uppsrc/Core/Debug.cpp +++ b/uppsrc/Core/Debug.cpp @@ -115,7 +115,7 @@ void HexDumpData(Stream& s, const void *ptr, int size, bool adr, int maxsize) { sprintf(h, "%+6d 0x%08X%08X ", a, (int)(aa >> 32), (int)aa); s.Put(h); #else - sprintf(h, "%+6d 0x%08X ", a, a + dword(ptr)); + sprintf(h, "%+6d 0x%08X ", a, int(a + dword(ptr))); s.Put(h); #endif } diff --git a/uppsrc/Core/heap.cpp b/uppsrc/Core/heap.cpp index 53d53719b..fa85e50bb 100644 --- a/uppsrc/Core/heap.cpp +++ b/uppsrc/Core/heap.cpp @@ -312,7 +312,7 @@ void operator delete[](void *ptr, const std::nothrow_t&) noexcept { UPP::Memory #if defined(PLATFORM_WIN32) && defined(COMPILER_CLANG) // this is temporary fix before llvm-mingw fixes weak references -void __attribute__((__noreturn__)) std::__throw_bad_alloc (void) { throw bad_alloc(); } +// void __attribute__((__noreturn__)) std::__throw_bad_alloc (void) { throw bad_alloc(); } #endif #endif diff --git a/uppsrc/CtrlCore/ImageWin32.cpp b/uppsrc/CtrlCore/ImageWin32.cpp index d14b1739e..e9b085d5c 100644 --- a/uppsrc/CtrlCore/ImageWin32.cpp +++ b/uppsrc/CtrlCore/ImageWin32.cpp @@ -186,7 +186,6 @@ struct ImageSysData { HBITMAP hmask; HBITMAP himg; RGBA *section; - int paintcount; void Init(const Image& img); void CreateHBMP(HDC dc, const RGBA *data); @@ -199,7 +198,6 @@ void ImageSysData::Init(const Image& _img) { img = _img; hbmp = hmask = himg = NULL; - paintcount = 0; LLOG("ImageSysData::Init " << img.GetSerialId() << " " << img.GetSize()); } @@ -254,17 +252,6 @@ void ImageSysData::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c) if(sr.IsEmpty()) return; - int kind = img.GetKindNoScan(); - if(kind == IMAGE_OPAQUE && !IsNull(c)) { - w.DrawRect(x, y, sz.cx, sz.cy, c); - return; - } - if(kind == IMAGE_OPAQUE && (GetDeviceCaps(dc, RASTERCAPS) & RC_DIBTODEV)) { - LTIMING("Image Opaque direct set"); - SetSurface(w, x, y, sz.cx, sz.cy, ~img); - paintcount++; - return; - } if(fnAlphaBlend() && IsNull(c) && !ImageFallBack && !(w.IsPrinter() && (GetDeviceCaps(dc, SHADEBLENDCAPS) & (SB_PIXEL_ALPHA|SB_PREMULT_ALPHA)) != (SB_PIXEL_ALPHA|SB_PREMULT_ALPHA))) { @@ -312,10 +299,24 @@ struct ImageSysDataMaker : LRUCache::Maker { void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color) { + LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << img.GetSize()); + GuiLock __; if(img.GetLength() == 0) return; - LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << img.GetSize()); + + Size sz = img.GetSize(); + int kind = img.GetKindNoScan(); + if(kind == IMAGE_OPAQUE && !IsNull(color)) { + DrawRect(x, y, sz.cx, sz.cy, color); + return; + } + if(kind == IMAGE_OPAQUE && (!IsPrinter() || (GetDeviceCaps(GetHandle(), RASTERCAPS) & RC_DIBTODEV))) { + LTIMING("Image Opaque direct set"); + SetSurface(*this, x, y, sz.cx, sz.cy, ~img); + return; + } + ImageSysDataMaker m; static LRUCache cache; static int Rsz; @@ -325,7 +326,7 @@ void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, cache.Remove([](const ImageSysData& object) { return object.img.GetRefCount() == 1; }); } LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount()); - Size sz = Ctrl::GetPrimaryScreenArea().GetSize(); + sz = Ctrl::GetVirtualScreenArea().GetSize(); m.img = IsPrinter() && GetDeviceCaps(GetHandle(), NUMCOLORS) == 2 ? Dither(img, 360) : img; // If printer does not support color, dither cache.Get(m).Paint(*this, x, y, src, color); cache.Shrink(4 * sz.cx * sz.cy, IsWinNT() ? 1000 : 100);