Dali 3D User Interface Engine
Animation: Multi-threading Notes

Multi-threaded Architecture

DALi animations and rendering occur in a dedicated rendering thread. This allows animations to run smoothly, regardless of the time taken to process inputs events etc. in application code.

Internally DALi contains a scene-graph, which mirrors the Actor hierachy. The scene-graph objects perform the actual animation & rendering, whilst Actors provide thread-safe access.

An example actor hierachy is shown below, in which one of the actors is being animated. The objects in green are created by the application code, whilst the private objects in blue are used in the dedicated rendering thread.

multi-threaded-animation.png

Reading an animated value

When a property is animatable, it can only be modified in the rendering thread. The value returned from a getter method, is the value used when the previous frame was rendered.

For example Dali::Actor::GetCurrentPosition returns the position at which the Actor was last rendered. Since Dali::Actor::SetPosition is asynchronous, a call to Dali::Actor::GetCurrentPosition won't immediately return the same value.

// Whilst handling an event...
Actor actor = Actor::New();
Stage::GetCurrent().Add(actor); // initial position is 0,0,0
actor.SetPosition(Vector3(10,10,10));
Vector3 current;
current = actor.GetCurrentPosition();
std::cout << "Current position: " << current.x << ", " << current.y << ", " << current.z << std::endl;
std::cout << "..." << std::endl;
// Whilst handling another event...
current = actor.GetCurrentPosition();
std::cout << "Current position: " << current.x << ", " << current.y << ", " << current.z << std::endl;

The example code above would likely output:

"Current position: 0,0,0"
"..."
"Current position: 10,10,10"

Setting a property during an animation

When a property is being animated, the Animation will override any values set e.g. with Actor::SetPosition()

multi-threaded-animation-2.png

The order of execution in the render thread is:

1) Process message => SetPosition
2) Apply animation => SetPosition
3) Render frame
Dali Docs Home
Read more about Dali