Ticket #7525: mythui_pulse_optimize.patch

File mythui_pulse_optimize.patch, 9.3 KB (added by Jim Stichnoth <stichnot@…>, 10 years ago)
  • libs/libmythui/mythuitype.h

     
    115115
    116116    bool ContainsPoint(const QPoint &point) const;
    117117
     118    enum AnimationType {
     119        animMovement=0,
     120        animAlpha,
     121        animPulse,
     122        animNUMTYPES
     123    };
     124    void SetNextPulse(AnimationType type, bool flag); // true=asap, false=never
     125    void SetNextPulse(bool flag); // true=asap, false=never
     126    void FixupNextChildPulse(bool recomputeChildren=true);
     127
    118128  protected:
    119129    virtual void customEvent(QEvent *);
    120130
     
    181191    QPoint m_XYDestination;
    182192    QPoint m_XYSpeed;
    183193
     194    unsigned m_NextPulse;
     195    unsigned m_NextChildPulse;
     196
    184197    FontMap *m_Fonts;
    185198
    186199    MythUIType *m_Parent;
  • libs/libmythui/mythuitype.cpp

     
    4444    m_XYSpeed = QPoint(0, 0);
    4545    m_deferload = false;
    4646
     47    m_NextPulse = (1 << animNUMTYPES) - 1; // all bits set
     48    m_NextChildPulse = 0;
     49
    4750    m_Parent = NULL;
    4851    if (parent)
    4952    {
     
    6972 */
    7073void MythUIType::Reset()
    7174{
     75    SetNextPulse(true);
    7276    // Reset all children
    7377    QMutableListIterator<MythUIType *> it(m_ChildrenList);
    7478    while (it.hasNext())
     
    8892        return;
    8993
    9094    m_ChildrenList.push_back(child);
     95    FixupNextChildPulse();
    9196}
    9297
    9398static QObject *qChildHelper(const char *objName, const char *inheritsClass,
     
    149154        {
    150155            type->deleteLater();
    151156            it.remove();
     157            FixupNextChildPulse();
    152158            return;
    153159        }
    154160    }
     
    171177        {
    172178            type->deleteLater();
    173179            it.remove();
     180            FixupNextChildPulse();
    174181            child = NULL;
    175182            return;
    176183        }
     
    191198    }
    192199
    193200    m_ChildrenList.clear();
     201    FixupNextChildPulse();
    194202}
    195203
    196204/** \brief Return the first MythUIType which accepts focus found at the given
     
    307315void MythUIType::HandleMovementPulse(void)
    308316{
    309317    if (!GetMythPainter()->SupportsAnimation())
     318    {
     319        SetNextPulse(animMovement, false);
    310320        return;
     321    }
    311322
    312323    if (!m_Moving)
     324    {
     325        SetNextPulse(animMovement, false);
    313326        return;
     327    }
    314328
    315329    QPoint curXY = m_Area.topLeft().toQPoint();
    316330    m_DirtyRegion = m_Area.toQRect();
     
    344358    }
    345359
    346360    m_Area.moveTopLeft(curXY);
     361    SetNextPulse(animMovement, m_Moving);
    347362}
    348363
    349364void MythUIType::HandleAlphaPulse(void)
    350365{
    351366    if (!GetMythPainter()->SupportsAlpha() ||
    352367        !GetMythPainter()->SupportsAnimation())
     368    {
     369        SetNextPulse(animAlpha, false);
    353370        return;
     371    }
    354372
    355373    if (m_AlphaChangeMode == 0)
     374    {
     375        SetNextPulse(animAlpha, false);
    356376        return;
     377    }
    357378
    358379    m_Alpha += m_AlphaChange;
    359380
     
    377398    }
    378399
    379400    SetRedraw();
     401    SetNextPulse(animAlpha, (m_AlphaChangeMode != 0));
    380402}
    381403
    382404void MythUIType::Pulse(void)
     
    384406    if (!m_Visible)
    385407        return;
    386408
    387     HandleMovementPulse();
    388     HandleAlphaPulse();
     409    if (m_NextPulse & (1 << animMovement))
     410        HandleMovementPulse();
     411    if (m_NextPulse & (1 << animAlpha))
     412        HandleAlphaPulse();
    389413
    390     QList<MythUIType *>::Iterator it;
    391     for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it)
    392         (*it)->Pulse();
     414    if (m_NextChildPulse & (1 << animPulse))
     415    {
     416        QList<MythUIType *>::Iterator it;
     417        for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it)
     418            (*it)->Pulse();
     419    }
     420    SetNextPulse(animPulse, false);
    393421}
    394422
    395423int MythUIType::CalcAlpha(int alphamod)
     
    532560                             int maxalpha)
    533561{
    534562    if (!GetMythPainter()->SupportsAlpha())
     563    {
     564        SetNextPulse(animAlpha, false);
    535565        return;
     566    }
    536567
    537568    m_AlphaChangeMode = mode;
    538569    m_AlphaChange = alphachange;
     
    543574        m_Alpha = m_AlphaMax;
    544575    if (m_Alpha < m_AlphaMin)
    545576        m_Alpha = m_AlphaMin;
     577    SetNextPulse(animAlpha, (m_AlphaChangeMode != 0));
    546578}
    547579
    548580void MythUIType::SetAlpha(int newalpha)
     
    615647        emit Showing();
    616648    else
    617649        emit Hiding();
     650    FixupNextChildPulse();
    618651}
    619652
    620653void MythUIType::SetEnabled(bool enable)
     
    677710    m_XYSpeed = base->m_XYSpeed;
    678711    m_deferload = base->m_deferload;
    679712
     713    m_NextPulse = m_Visible ? (1 << animNUMTYPES) - 1 : 0;
     714    FixupNextChildPulse();
     715
    680716    QList<MythUIType *>::Iterator it;
    681717    for (it = base->m_ChildrenList.begin(); it != base->m_ChildrenList.end();
    682718         ++it)
     
    840876    return false;
    841877}
    842878
     879// Recompute m_NextChildPulse, and if anything has changed, continue
     880// up the tree.
     881void MythUIType::FixupNextChildPulse(bool recomputeChildren)
     882{
     883    for (MythUIType *current=this; current; current=current->m_Parent)
     884    {
     885        unsigned oldNextPulse = current->m_NextPulse;
     886        unsigned oldNextChildPulse = current->m_NextChildPulse;
     887
     888        if (current->m_Visible)
     889        {
     890            // If necessary, recompute m_NextChildPulse as the min of
     891            // m_NextPulse and m_NextChildPulse across all children.
     892            if (recomputeChildren)
     893            {
     894                current->m_NextChildPulse = 0;
     895                QList<MythUIType*>::iterator it;
     896                for (it = current->m_ChildrenList.begin(); it != current->m_ChildrenList.end(); ++it)
     897                {
     898                    current->m_NextChildPulse |= (*it)->m_NextPulse;
     899                    current->m_NextChildPulse |= (*it)->m_NextChildPulse;
     900                }
     901            }
     902
     903        } else {
     904            current->m_NextPulse = 0;
     905            current->m_NextChildPulse = 0;
     906        }
     907
     908        // If anything changed, continue up the tree.  Also continue
     909        // if current=this, since the method might have been called as
     910        // a result of m_NextPulse changing.
     911        unsigned oldmin = oldNextPulse | oldNextChildPulse;
     912        unsigned newmin = current->m_NextPulse | current->m_NextChildPulse;
     913        if (oldmin == newmin && current != this)
     914            break;
     915        recomputeChildren = true;
     916    }
     917}
     918
     919void MythUIType::SetNextPulse(AnimationType type, bool flag)
     920{
     921    unsigned oldMask = m_NextPulse;
     922    if (flag)
     923        m_NextPulse |= (1 << type);
     924    else
     925        m_NextPulse &= ~(1 << type);
     926    if (m_NextPulse != oldMask)
     927        FixupNextChildPulse(false);
     928}
     929
     930void MythUIType::SetNextPulse(bool flag)
     931{
     932    for (unsigned i=0; i<animNUMTYPES; i++)
     933        SetNextPulse((AnimationType)i, flag);
     934}
  • libs/libmythui/mythuiimage.cpp

     
    280280    m_Delay = delayms;
    281281    m_LastDisplay = QTime::currentTime();
    282282    m_CurPos = 0;
     283    SetNextPulse(animPulse, (m_Delay > 0));
    283284}
    284285
    285286/**
     
    298299    m_Filename = img->GetFileName();
    299300    Clear();
    300301    m_Delay = -1;
     302    SetNextPulse(animPulse, false);
    301303
    302304    img->UpRef();
    303305
     
    839841    }
    840842
    841843    MythUIType::Pulse();
     844    SetNextPulse(animPulse, (m_Delay > 0));
    842845}
    843846
    844847/**
     
    982985    else if (element.tagName() == "crop")
    983986        m_cropRect = parseRect(element);
    984987    else if (element.tagName() == "delay")
     988    {
    985989        m_Delay = getFirstText(element).toInt();
     990        SetNextPulse(animPulse, (m_Delay > 0));
     991    }
    986992    else if (element.tagName() == "reflection")
    987993    {
    988994        m_isReflected = true;
  • libs/libmythui/mythuitext.cpp

     
    315315    //
    316316
    317317    MythUIType::Pulse();
     318    SetNextPulse(animPulse, (m_colorCycling || m_scrolling));
    318319
    319320    if (m_colorCycling)
    320321    {
  • libs/libmythui/mythuiwebbrowser.cpp

     
    534534    }
    535535
    536536    MythUIType::Pulse();
     537    SetNextPulse(animPulse, (m_updateInterval != 0));
    537538}
    538539
    539540void MythUIWebBrowser::DrawSelf(MythPainter *p, int xoffset, int yoffset,
  • libs/libmythui/mythuitextedit.cpp

     
    7373void MythUITextEdit::Pulse(void)
    7474{
    7575    if (!m_cursorImage)
     76    {
     77        SetNextPulse(animPulse, false);
    7678        return;
     79    }
    7780
    7881    if (m_HasFocus)
    7982    {
     
    9295        m_cursorImage->SetVisible(false);
    9396
    9497    MythUIType::Pulse();
     98    SetNextPulse(animPulse, true);
    9599}
    96100
    97101bool MythUITextEdit::ParseElement(QDomElement &element)
  • libs/libmythui/mythuiclock.cpp

     
    6464    }
    6565
    6666    MythUIText::Pulse();
     67    SetNextPulse(animPulse, true);
    6768}
    6869
    6970bool MythUIClock::ParseElement(QDomElement &element)