Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Optimization Mystery...
Optimization Mystery... [message #11888] Sun, 30 September 2007 10:31 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, I decided it is time to perform low-level check... So I have put together Win98 machine with 400Mhz Celeron and compiled UWord.

Found it running very slow, so I started to investigate.

In couple of minutes I have found that following change in the Image::Data::Paint code mostly fixes the problem:

/*	if(GetKind() == IMAGE_OPAQUE) {
		if(!hbmp) {
			LTIMING("Image Opaque create");
			CreateHBMP(dc, buffer);
		}
		LTIMING("Image Opaque blit");
		HDC dcMem = ::CreateCompatibleDC(dc);
		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);
		PaintOnlyShrink();
		return;
	}*/
	if(GetKind() == IMAGE_MASK || GetKind() == IMAGE_OPAQUE) { // THIS NOW HANDLES BOTH CASES
		HDC dcMem = ::CreateCompatibleDC(dc);
		if(!hmask) {
			LTIMING("Image Mask create");
			Buffer<RGBA> bmp(len);
			hmask = CreateBitMask(buffer, sz, sz, sz, bmp);
			ResCount++;
			if(!hbmp)
				CreateHBMP(dc, bmp);
		}
		LTIMING("Image Mask blt");
		HBITMAP o = (HBITMAP)::SelectObject(dcMem, ::CreateCompatibleBitmap(dc, sz.cx, sz.cy));
		::BitBlt(dcMem, 0, 0, ssz.cx, ssz.cy, dc, x, y, SRCCOPY);
		HDC dcMem2 = ::CreateCompatibleDC(dc);
		::SelectObject(dcMem2, hmask);
		::BitBlt(dcMem, 0, 0, ssz.cx, ssz.cy, dcMem2, sr.left, sr.top, SRCAND);
		if(IsNull(c)) {
			::SelectObject(dcMem2, hbmp);
			::BitBlt(dcMem, 0, 0, ssz.cx, ssz.cy, dcMem2, sr.left, sr.top, SRCPAINT);
		}
		else {
			HBRUSH ho = (HBRUSH) SelectObject(dcMem, CreateSolidBrush(c));
			::BitBlt(dcMem, 0, 0, ssz.cx, ssz.cy, dcMem2, sr.left, sr.top, 0xba0b09);
			::DeleteObject(::SelectObject(dcMem, ho));
		}
		::BitBlt(dc, x, y, ssz.cx, ssz.cy, dcMem, 0, 0, SRCCOPY);
		::DeleteObject(::SelectObject(dcMem, o));
		::DeleteDC(dcMem2);
		::DeleteDC(dcMem);
		PaintOnlyShrink();
		return;
	}


To explain - now commented part was dealing with the "simple" case of completely opaque Image being sent to display, while now used part deals with this opaque image is if it was complex one.

Now this is weirdest thing I have ever met - much more complex GDI code is faster? WTF?!

Any suggestions why it behaves this way?

Mirek

[Updated on: Sun, 30 September 2007 10:32]

Report message to a moderator

Re: Optimization Mystery... [message #11889 is a reply to message #11888] Sun, 30 September 2007 10:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Funny, I believe I have just found the reason....

This behaviour prevailed when the display was in 256 colors mode.

Setting to TrueColor immediately fixes everything.

Looks like poor Win98 was forced to perform the conversion of Image format each time for that particular code.

Mirek
Re: Optimization Mystery... [message #11890 is a reply to message #11889] Sun, 30 September 2007 10:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, fixed Smile
Re: Optimization Mystery... [message #11894 is a reply to message #11888] Sun, 30 September 2007 12:16 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Any chance to try some linux distro too and look if there's anything to optimize? Very Happy
(but I think the KDE or GTK will be too slow on such machine, maybe some lightweight X would make more sense. Than again making sure UPP is fast under GTK and KDE is more important, as those two are major players right now).
Re: Optimization Mystery... [message #11895 is a reply to message #11894] Sun, 30 September 2007 14:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Seriously, this issue was very Win32 specific...

Also GTK != Gnome.

Anyway, does this mean you have found performance problem with U++/X11?

Mirek

[Updated on: Sun, 30 September 2007 14:25]

Report message to a moderator

Re: Optimization Mystery... [message #11897 is a reply to message #11888] Sun, 30 September 2007 14:40 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
not really .. on my old 1GHz Athlon the whole KDE is quite slow (when compared to win2k). U++ performs so far just as good like anything else.
Re: Optimization Mystery... [message #11899 is a reply to message #11897] Sun, 30 September 2007 16:22 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mr_ped wrote on Sun, 30 September 2007 08:40

not really .. on my old 1GHz Athlon the whole KDE is quite slow (when compared to win2k). U++ performs so far just as good like anything else.


BTW, usually the problem is with video drivers...

Mirek
Previous Topic: GDI, and therefore, Draw performance on Vista
Next Topic: ValueMap
Goto Forum:
  


Current Time: Sat Apr 27 22:51:58 CEST 2024

Total time taken to generate the page: 0.04830 seconds