Skip to main content
Marco.R
Senior
November 20, 2019
Question

Long rendering time when moving two images

  • November 20, 2019
  • 14 replies
  • 2538 views

Hi @Martin KJELDSEN​ 

On a screen I want to move two large images (one has transparency). I've implemented it like in your birdgame example (with the moveto(x,y) method.

Now I recognized that the animation is very slow and the rendering time is very long (>30ms). I don't know why this take so long. I measured it with the RENDER_TIME GPIO and also in SW. I see that the TouchGFX Library is active for more than 30ms.

Do you have any idea where the issue come from? Below you will find the implementation

Thank you

Best regards

Marco

#include <gui/containers/container_moving_waves.hpp>
#include <BitmapDatabase.hpp>
#include <touchgfx/Color.hpp>
 
container_moving_waves::container_moving_waves(): m_waveForeground(), 
 m_waveBackground(), 
 m_animationState(AnimationState::AnimationRunning),
 m_tickCounter(0U),
 m_tickinterval(1U) {}
 
void container_moving_waves::initialize()
{
 container_moving_wavesBase::initialize();
 initializeLayer(m_waveBackground, BITMAP_WAVE_BACKGROUND_ID, 255U, 1U, -1);
 initializeLayer(m_waveForeground, BITMAP_WAVE_FOREGROUND_ID, 204U, 1U, 1);
 
 m_boxWave.setPosition(0, 217, 800, 33);
 m_boxWave.setColor(touchgfx::Color::getColorFrom24BitRGB(112, 148, 197));
 
 add(m_boxWave);
}
 
void container_moving_waves::startAnimation() {
 m_animationState = AnimationState::AnimationRunning;
}
 
void container_moving_waves::stopAnimation() {
 m_animationState = AnimationState::NoAnimation;
}
 
void container_moving_waves::handleTickEvent() {
 m_tickCounter++;
 
 if ((m_tickCounter % m_tickinterval) != 0U) {
 return;
 }
 
 if (m_animationState == AnimationState::AnimationRunning) {
 moveLayer(m_waveForeground, m_tickCounter);
 moveLayer(m_waveBackground, m_tickCounter);
 }
}
 
void container_moving_waves::initializeLayer(Layer& layer, const BitmapId bmp, uint8_t alpha, const uint32_t animationUpdateSpeed, const int32_t animationWidth)
{
 layer.image0.setBitmap(Bitmap(bmp));
 layer.image1.setBitmap(Bitmap(bmp));
 
 layer.image0.setXY(0, 0U);
 if (animationWidth < 0) {
 layer.image1.setXY(layer.image0.getRect().right(), 0U);
 }
 else {
 layer.image1.setXY(layer.image0.getRect().x - layer.image1.getWidth(), 0U);
 }
 
 layer.image0.setAlpha(alpha);
 layer.image1.setAlpha(alpha);
 
 add(layer.image0);
 add(layer.image1);
 
 layer.animationUpdateSpeed = animationUpdateSpeed;
 layer.animationWidth = animationWidth;
}
 
void container_moving_waves::moveLayer(Layer& layer, const uint32_t tickCount) {
 if ((tickCount % layer.animationUpdateSpeed) == 0U) {
 layer.image0.moveTo(layer.image0.getX() + layer.animationWidth, layer.image0.getY());
 layer.image1.moveTo(layer.image1.getX() + layer.animationWidth, layer.image1.getY());
 
 if (layer.animationWidth < 0) {
 //when moving left
 if (layer.image0.getRect().right() < 0) {
 layer.image0.moveTo(layer.image1.getRect().right(), layer.image0.getY());
 }
 
 if (layer.image1.getRect().right() < 0) {
 layer.image1.moveTo(layer.image0.getRect().right(), layer.image1.getY());
 }
 }
 else {
 //when moving right
 if (layer.image0.getRect().x > layer.image0.getWidth()) {
 layer.image0.moveTo(layer.image1.getRect().x - layer.image0.getWidth(), layer.image0.getY());
 }
 
 if (layer.image1.getRect().x > layer.image1.getWidth()) {
 layer.image1.moveTo(layer.image0.getRect().x - layer.image1.getWidth(), layer.image1.getY());
 }
 }
 }
}

This topic has been closed for replies.

14 replies

Martin KJELDSEN
Principal III
November 25, 2019

Hi guys,

I'll try to get to your L8 questions tomorrow. The standard HAL does not support L8, correct.

/Martin