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 » Community » U++ community news and announcements » gtk rendering improvements, BufferPainter::PaintOnceHint
gtk rendering improvements, BufferPainter::PaintOnceHint [message #57172] Thu, 03 June 2021 11:33 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I have found some bottleneck in gtk rendering and possible improvements:

- Paint was called too often (basically, too soon, after each event) due to event processing code, this is now resolved.
- SetSurface was optimized to use cairo_image_surface_create_for_data, which is about 3 times faster than previous code
- With SetSurface fast, when the Image is supposed to be painted just once, SetSurface is the fastest route. To this end I have added PaintOnceHint to ImageBuffer.
- PainterDraw is now using this new hint for much improved performance...

Hopefully this does not break anything...

Mirek
Re: gtk rendering improvements, BufferPainter::PaintOnceHint [message #57173 is a reply to message #57172] Thu, 03 June 2021 16:01 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

Thanks! Sounds interesting. I'll need to take a closer look at this. At first sight it seems to work fine!

Best regards,

Tom
Re: gtk rendering improvements, BufferPainter::PaintOnceHint [message #57175 is a reply to message #57172] Fri, 04 June 2021 13:25 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

I did some testing of SetSurface on Linux/Gtk and noticed that it does not work well when using only a part of a larger image. Offset does not seem to work at all there. On Windows, it works very well and can update a 4k screen at 40-50 FPS with SetSurface and 13 FPS with DrawImage. On Linux I get 11-12 FPS for DrawImage.

Please try this testcase:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class ResponsiveDrag : public TopWindow {
public:
	Image im;
	Point offset;
	
	ResponsiveDrag(){
		Sizeable().MaximizeBox().MinimizeBox();
		Maximize();
		offset=Point(0,0);
		leftdown=false;
	}

	
	virtual void Paint(Draw &w){
		static int64 last;
		int64 now=usecs();
		double fps=1000000/(now-last);
		last=now;
		
		// In Windows SetSurface is about 3x faster than Drawimage on 4k UHD screen
		// However, in Gtk SetSurface fails to display the image correctly
		// and offset is not taken into account at all
		
		SetSurface(w,Rect(GetSize()),~im,im.GetSize(),offset); // Only works on Windows
		// w.DrawImage(Rect(GetSize()),im,Rect(offset,GetSize())); // Works on both Linux and Windows
		
		w.DrawText(10,10,Format("FPS = %.1f",fps));
	}
	
	virtual void Layout(){
		Size sz(GetSize()*3);
		ImageBuffer ib(sz);
		BufferPainter p(ib);
		p.Clear(SColorPaper());
		for(int i=0;i<50;i++){
			p.Move(Random(sz.cx),Random(sz.cy));
			p.Line(Random(sz.cx),Random(sz.cy));
			p.Stroke(3,SColorText());
		}
		im=ib;
		offset=Point(GetSize());
		Refresh();
	}
	
	bool leftdown;
	Point leftdownp;
	
	virtual void LeftDown(Point p, dword keyflags){
		SetCapture();
		leftdown=true;
		leftdownp=p;
	}

	virtual void LeftUp(Point p, dword keyflags){
		ReleaseCapture();
		leftdown=false;
		offset=Point(GetSize());
		Refresh();
	}
	
	virtual void MouseMove(Point p, dword keyflags){
		if(leftdown){
			offset=Point(GetSize())+leftdownp-p;
			Refresh();
		}
	}
};

GUI_APP_MAIN
{
	ResponsiveDrag().Run();
}


Best regards,

Tom

Update: PaintOnceHint() almost doubles the DrawImage() FPS on Linux/Gtk to about 20 FPS. On Windows PaintOnceHint() does not have any effect on DrawImage() performance.

[Updated on: Fri, 04 June 2021 14:01]

Report message to a moderator

Re: gtk rendering improvements, BufferPainter::PaintOnceHint [message #57176 is a reply to message #57175] Fri, 04 June 2021 14:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Fri, 04 June 2021 13:25
Hi Mirek,

I did some testing of SetSurface on Linux/Gtk and noticed that it does not work well when using only a part of a larger image. Offset does not seem to work at all there. On Windows, it works very well and can update a 4k screen at 40-50 FPS with SetSurface and 13 FPS with DrawImage. On Linux I get 11-12 FPS for DrawImage.

Update: PaintOnceHint() almost doubles the DrawImage() FPS on Linux/Gtk to about 20 FPS. On Windows PaintOnceHint() does not have any effect on DrawImage() performance.


Uhm, src and offset is not even really implemented, sorry, that is my mess... Frankly, for the dominant use of SetSurface, it really even is not needed. I think removing that SetSurface variant would be enough; you can always achieve setting subpart with Offset and Clip....

Also PaintOnceHint really is only used with Gtk now. Maybe it could be used to optimize MacOS, but that is todo..

Mirek
Re: gtk rendering improvements, BufferPainter::PaintOnceHint [message #57177 is a reply to message #57176] Fri, 04 June 2021 16:20 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

Please do not remove the SetSurface() variant with src and offset. My scrolling histogram view (on Windows) is absolutely dependent on that as it works on an image buffer which is configured as a larger ring buffer. It is very performance sensitive for fast and smooth scrolling of the view and the current SetSurface() has been the reliable work horse here.

I would certainly like to see it work on Linux too rather than drop out.

Best regards,

Tom
Re: gtk rendering improvements, BufferPainter::PaintOnceHint [message #57178 is a reply to message #57177] Fri, 04 June 2021 17:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Fri, 04 June 2021 16:20
Hi,

Please do not remove the SetSurface() variant with src and offset. My scrolling histogram view (on Windows) is absolutely dependent on that as it works on an image buffer which is configured as a larger ring buffer. It is very performance sensitive for fast and smooth scrolling of the view and the current SetSurface() has been the reliable work horse here.


But it should work exactly the same with Offset and Clip... DrawImage is curretly using this trick already, see Draw/Draw.cpp:134
Re: gtk rendering improvements, BufferPainter::PaintOnceHint [message #57190 is a reply to message #57178] Mon, 07 June 2021 12:27 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
mirek wrote on Fri, 04 June 2021 18:55
Tom1 wrote on Fri, 04 June 2021 16:20
Hi,

Please do not remove the SetSurface() variant with src and offset. My scrolling histogram view (on Windows) is absolutely dependent on that as it works on an image buffer which is configured as a larger ring buffer. It is very performance sensitive for fast and smooth scrolling of the view and the current SetSurface() has been the reliable work horse here.


But it should work exactly the same with Offset and Clip... DrawImage is curretly using this trick already, see Draw/Draw.cpp:134

Hi Mirek,

OK, I see. Did some testing on this. Using Clipoff()+SetSurface() yields similar performance on Windows as SetSurface() with src alone. It just requires a bit more complex code on this side than the original version.

Best regards,

Tom
Re: gtk rendering improvements, BufferPainter::PaintOnceHint [message #57437 is a reply to message #57172] Tue, 10 August 2021 15:56 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
It seems to have improved the problem with screen tearing I was having while scrolling GLCtrls in a container. Cool. Container boundaries are still not obeyed though so the GLCtrl draws on top of everything, but it's a good improvement. Thanks, Mirek!
Previous Topic: git
Next Topic: integer->String conversion optimised
Goto Forum:
  


Current Time: Fri Mar 29 03:11:30 CET 2024

Total time taken to generate the page: 0.01537 seconds