Page 1 of 1

thread safety of IRenderer

Posted: 14 Aug 2021, 15:57
by Naphtalene
Hi,
I need a way to block input events that are over a GUI View. i've seen that thread :
viewtopic.php?t=698

my question is, is it safe to operate on IRenderer on the main thread:
Ptr<IView> current_view;
IRenderer* uiRenderer = current_view->GetRenderer();

Visual* root = VisualTreeHelper::GetRoot(uiRenderer->GetContent());
HitTestResult hit = VisualTreeHelper::HitTest(root, Point(mousePosX, mousePosY));
if (hit.visualHit != 0)
{
    // block event
}
while render thread is operating on the same IRenderer in this way :
  
current_view->GetRenderer()->UpdateRenderTree();
current_view->GetRenderer()->RenderOffscreen();
...
current_view->GetRenderer()->Render();

Re: thread safety of IRenderer

Posted: 16 Aug 2021, 18:11
by sfernandez
That post is quite old and the API changed a bit in newer versions. The IView provides access to the Content so you don't need to interact with the IRenderer object for that:
Ptr<IView> current_view;
Visual* root = VisualTreeHelper::GetRoot(current_view->GetContent());
HitTestResult hit = VisualTreeHelper::HitTest(root, Point(mousePosX, mousePosY));
if (hit.visualHit != 0)
{
    // block event
}

Re: thread safety of IRenderer

Posted: 16 Aug 2021, 18:40
by Naphtalene
Alright i will do it this way, Thank you very much !

Re: thread safety of IRenderer

Posted: 16 Aug 2021, 18:59
by Naphtalene
Turns out
Ptr<IView> current_view;
current_view->GetContent(); // returns a FrameworkElement*
and
VisualTreeHelper::GetRoot(const Visual* ) //takes a Visual* 

Re: thread safety of IRenderer

Posted: 16 Aug 2021, 19:06
by sfernandez
Yes, a FrameworkElement inherits from Visual, so you can pass the element to the GetRoot() function.
If you have compiler errors make sure to include <NsGui/FrameworkElement.h> in your code (or just the NoesisPCH.h we provide in our SDK if you are using precompiled headers).

Re: thread safety of IRenderer

Posted: 16 Aug 2021, 19:08
by Naphtalene
alright thanks again !

Re: thread safety of IRenderer

Posted: 17 Aug 2021, 12:03
by jsantos
Just a clarification for future readers: all functions in the interface IRenderer must always be invoked from the render thread (in case you are using a separate thread for rendering)