EndDraw() takes 80 % of working time in Direct2D

1.1k Views Asked by At

I face one critical Performance problem in my Direct2D application. I make use of Direct2D to draw my graph using PathGeometry to get better performance and to achieve the clean rendering in Windows 8.1.

While creating the DeviceResources, i create the PathGeometry using the Factory interface. Then i set the Graph points to draw my graph in the output surface. Finally rendered ImageSource will be used as the source for my Image element in the XAML.

I just followed the below sample link to achieve my scenario.

http://code.msdn.microsoft.com/windowsapps/XAML-SurfaceImageSource-58f7e4d5

The above sample helped me a lot to get the ImageSource output from the Direct2D and finally used across the XAML/C# app.

Lets come to my problem. I use more than 24 graphs in the single Page of my Windows Store application. This graph allows the user to manipulate in Left and Right position and also allows to scale to the particular zoom level.

Hence whenever user tries to manipulate the graph , i just set the Translation and Scaling matrix to the TransformedPathGeometry instead of creating the new one for each and every time.

ID2D1TransformedGeometry *m_pTransformedGeometry;

pFactory->CreateTransformedGeometry(graphgeometry, combinedMatrix, &m_pTransformedGeometry);

Finally i draw the TransformedGeometry using the DrawGeometry method.

I checked my application using the Performance analysis tool in the VisualStudio2013. I could see that in the particular peek level, It takes more than 80% of running time to call the m_d2deviceContext->EndDraw() method. I attached the below screen shot to get more idea in this performance output.

Is there any way to increase this performance considerably ?

enter image description here

Could you please anyone help me in this ?

Regards, David C

2

There are 2 best solutions below

6
On

THere is a difference between slow performance and time spend.

If your draw method does more work than other parts, can mean that this method is slow but it also can mean that your other parts don't need a lot of cpu.

88.2% tells you only that you spend more time drawing that stuff than doing other stuff.

Use an timer to determine if your draw is slow.

0
On

"i just set the Translation and Scaling matrix to the TransformedPathGeometry instead of creating the new one for each and every time."

I hope you use world transform? Else you overwrite the pointer without releasing it before, providing a memory leak. You cannot change the matrix of a geometry directly, you have to recreate it each time, or if you can, you apply the transform to the entire world.