CtrlCore: Win32 SystemDraw speed optimized (single additional CompatibleDC)

git-svn-id: svn://ultimatepp.org/upp/trunk@6074 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-05-16 08:43:27 +00:00
parent efd09c8218
commit 2ac1342273
3 changed files with 41 additions and 14 deletions

View file

@ -292,6 +292,7 @@ SystemDraw::SystemDraw() {
actual_offset = Point(0, 0);
Reset();
handle = NULL;
dcMem = NULL;
}
SystemDraw::SystemDraw(HDC hdc) {
@ -318,10 +319,26 @@ void SystemDraw::Unselect() {
Unselect0();
}
void SystemDraw::Attach(HDC ahandle)
{
handle = ahandle;
dcMem = ::CreateCompatibleDC(handle);
Init();
}
HDC SystemDraw::Detach()
{
Unselect();
HDC h = handle;
handle = NULL;
::DeleteDC(dcMem);
dcMem = NULL;
return h;
}
SystemDraw::~SystemDraw() {
GuiLock __;
if(handle)
Unselect();
Detach();
}
HDC SystemDraw::BeginGdi() {
@ -344,6 +361,7 @@ void BackDraw::Create(SystemDraw& w, int cx, int cy) {
size.cy = cy;
hbmp = ::CreateCompatibleBitmap(w.GetHandle(), cx, cy);
handle = ::CreateCompatibleDC(w.GetHandle());
dcMem = ::CreateCompatibleDC(handle);
ASSERT(hbmp);
ASSERT(handle);
#ifndef PLATFORM_WINCE
@ -377,6 +395,8 @@ void BackDraw::Destroy() {
::DeleteDC(handle);
::DeleteObject(hbmp);
handle = NULL;
::DeleteDC(dcMem);
dcMem = NULL;
}
}
@ -457,8 +477,6 @@ PrintDraw::~PrintDraw() {
::AbortDoc(handle);
else
::EndDoc(handle);
DeleteDC(handle);
handle = NULL;
}
#endif

View file

@ -6,8 +6,8 @@
NAMESPACE_UPP
#define LTIMING(x) // RTIMING(x)
#define LLOG(x) // DLOG(x)
#define LTIMING(x) // RTIMING(x)
#define LLOG(x) // DLOG(x)
bool ImageFallBack
// = true
@ -51,6 +51,7 @@ BitmapInfo32__::BitmapInfo32__(int cx, int cy)
HBITMAP CreateBitMask(const RGBA *data, Size sz, Size tsz, Size csz, RGBA *ct)
{
LTIMING("CreateBitMask");
GuiLock __;
memset(ct, 0, tsz.cx * tsz.cy * sizeof(RGBA));
int linelen = (tsz.cx + 15) >> 4 << 1;
@ -81,6 +82,7 @@ HBITMAP CreateBitMask(const RGBA *data, Size sz, Size tsz, Size csz, RGBA *ct)
void SetSurface(HDC dc, const Rect& dest, const RGBA *pixels, Size srcsz, Point srcoff)
{
LTIMING("SetSurface");
GuiLock __;
BitmapInfo32__ bi(srcsz.cx, srcsz.cy);
::SetDIBitsToDevice(dc, dest.left, dest.top, dest.GetWidth(), dest.GetHeight(),
@ -127,6 +129,7 @@ public:
void DrawSurface::Init(SystemDraw& w, int _x, int _y, int cx, int cy)
{
LTIMING("DrawSurface");
GuiLock __;
dc = w.GetHandle();
size = Size(cx, cy);
@ -221,6 +224,7 @@ ImageSysData::~ImageSysData()
void ImageSysData::CreateHBMP(HDC dc, const RGBA *data)
{
LTIMING("CreateHBMP");
LLOG("Creating BMP for " << img.GetSerialId() << ' ' << img.GetSize());
Size sz = img.GetSize();
BitmapInfo32__ bi(sz.cx, sz.cy);
@ -268,14 +272,14 @@ void ImageSysData::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
CreateHBMP(dc, ~img);
}
LTIMING("Image Opaque blit");
HDC dcMem = ::CreateCompatibleDC(dc);
HDC dcMem = w.GetCompatibleDC();
HBITMAP o = (HBITMAP)::SelectObject(dcMem, hbmp);
::BitBlt(dc, x, y, ssz.cx, ssz.cy, dcMem, sr.left, sr.top, SRCCOPY);
::SelectObject(dcMem, o);
::DeleteDC(dcMem);
SysImageRealized(img);
return;
}
#if 0
if(kind == IMAGE_MASK/* || GetKind() == IMAGE_OPAQUE*/) {
HDC dcMem = ::CreateCompatibleDC(dc);
if(!hmask) {
@ -307,6 +311,7 @@ void ImageSysData::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
SysImageRealized(img);
return;
}
#endif
#ifndef PLATFORM_WINCE
if(fnAlphaBlend() && IsNull(c) && !ImageFallBack) {
if(!himg) {
@ -321,10 +326,12 @@ void ImageSysData::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = AC_SRC_ALPHA;
HDC dcMem = ::CreateCompatibleDC(dc);
::SelectObject(dcMem, himg);
// HDC dcMem = ::CreateCompatibleDC(dc);
HDC dcMem = w.GetCompatibleDC();
HBITMAP o = (HBITMAP)::SelectObject(dcMem, himg);
fnAlphaBlend()(dc, x, y, ssz.cx, ssz.cy, dcMem, sr.left, sr.top, ssz.cx, ssz.cy, bf);
::DeleteDC(dcMem);
::SelectObject(dcMem, o);
// ::DeleteDC(dcMem);
SysImageRealized(img);
}
else

View file

@ -95,7 +95,7 @@ private:
protected:
dword style;
HDC handle;
HDC handle, dcMem;
Point actual_offset;
SystemDraw();
@ -134,8 +134,10 @@ public:
HDC GetHandle() { return handle; }
operator HDC() const { return handle; }
void Unselect();
void Attach(HDC ahandle) { handle = ahandle; Init(); }
HDC Detach() { Unselect(); HDC h = handle; handle = NULL; return h; }
void Attach(HDC ahandle);
HDC Detach();
HDC GetCompatibleDC() { return dcMem; }
SystemDraw(HDC hdc);
virtual ~SystemDraw();