From 2ce55266059eb3dfc3b8a90a5a3ca266bb84674a Mon Sep 17 00:00:00 2001 From: Julien Heanley Date: Thu, 22 May 2014 17:10:27 +0100 Subject: [PATCH] ScrollView - Stop Timer running in homescreen idle state [problem] Load analyzer shows homescreen is running in idle state [cause] ScrollView refresh timer is running continuously [solution] Replaced Timer with PropertyNotification, added new API's for ScrollUpdateDistance instead of RefreshInterval Change-Id: Id5a0dfa15752d805703d2d88845f1462d2b07030 Signed-off-by: Julien Heanley Signed-off-by: Adeel Kazmi --- .../scrollable/scroll-view/scroll-view-impl.cpp | 98 ++++++++++++---------- .../scrollable/scroll-view/scroll-view-impl.h | 30 ++++--- .../scrollable/scroll-view/scroll-view.cpp | 10 +++ .../controls/scrollable/scroll-view/scroll-view.h | 19 +++++ 4 files changed, 104 insertions(+), 53 deletions(-) diff --git a/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp index 25d2d77..9cabbf0 100644 --- a/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp @@ -58,6 +58,7 @@ const unsigned long MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET( 150u ); const float DEFAULT_OVERSHOOT_ANIMATION_DURATION = 0.35f; // time in seconds const Vector2 OVERSCROLL_CLAMP(1.0f, 1.0f); // maximum overscroll allowed in pixels when overshoot indicator is being used const float TOUCH_DOWN_TIMER_INTERVAL = 100.0f; +const float DEFAULT_SCROLL_UPDATE_DISTANCE( 30.0f ); ///< Default distance to travel in pixels for scroll update signal // predefined effect values const Vector3 ANGLE_CAROUSEL_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f); @@ -596,7 +597,7 @@ ScrollView::ScrollView() mMinTouchesForPanning(1), mMaxTouchesForPanning(1), mLockAxis(LockPossible), - mRefreshIntervalMilliseconds(DEFAULT_REFRESH_INTERVAL_MILLISECONDS), + mScrollUpdateDistance(DEFAULT_SCROLL_UPDATE_DISTANCE), mOvershootDelay(1.0f), mMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT), mUserMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT), @@ -1113,12 +1114,22 @@ void ScrollView::SetWrapMode(bool enable) int ScrollView::GetRefreshInterval() const { - return mRefreshIntervalMilliseconds; + return mScrollUpdateDistance; } void ScrollView::SetRefreshInterval(int milliseconds) { - mRefreshIntervalMilliseconds = milliseconds; + mScrollUpdateDistance = milliseconds; +} + +int ScrollView::GetScrollUpdateDistance() const +{ + return mScrollUpdateDistance; +} + +void ScrollView::SetScrollUpdateDistance(int distance) +{ + mScrollUpdateDistance = distance; } bool ScrollView::GetAxisAutoLock() const @@ -1275,6 +1286,7 @@ void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, floa Self().SetProperty(mPropertyScrolling, false); mScrolling = false; DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); + SetScrollUpdateNotification(false); mScrollCompletedSignalV2.Emit( currentScrollPosition ); } } @@ -1793,7 +1805,7 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat mScrollPreScale = mScrollPostScale = scale; } } - StartRefreshTimer(); + SetScrollUpdateNotification(true); // Always send a snap event when AnimateTo is called. Toolkit::ScrollView::SnapEvent snapEvent; @@ -1884,8 +1896,7 @@ Vector3 ScrollView::GetPropertyScale() const void ScrollView::HandleStoppedAnimation() { - // Animation has stopped, so stop sending the scroll-update signal. - CancelRefreshTimer(); + SetScrollUpdateNotification(false); } void ScrollView::HandleSnapAnimationFinished() @@ -1910,6 +1921,44 @@ void ScrollView::HandleSnapAnimationFinished() HandleStoppedAnimation(); } +void ScrollView::SetScrollUpdateNotification( bool enabled ) +{ + Actor self = Self(); + if( mScrollXUpdateNotification ) + { + // disconnect now to avoid a notification before removed from update thread + mScrollXUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification); + self.RemovePropertyNotification(mScrollXUpdateNotification); + mScrollXUpdateNotification.Reset(); + } + if( enabled ) + { + mScrollXUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 0, StepCondition(mScrollUpdateDistance, 0.0f)); + mScrollXUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification ); + } + if( mScrollYUpdateNotification ) + { + // disconnect now to avoid a notification before removed from update thread + mScrollYUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification); + self.RemovePropertyNotification(mScrollYUpdateNotification); + mScrollYUpdateNotification.Reset(); + } + if( enabled ) + { + mScrollYUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 1, StepCondition(mScrollUpdateDistance, 0.0f)); + mScrollYUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification ); + } +} + +void ScrollView::OnScrollUpdateNotification(Dali::PropertyNotification& source) +{ + // Guard against destruction during signal emission + Toolkit::ScrollView handle( GetOwner() ); + + Vector3 currentScrollPosition = GetCurrentScrollPosition(); + mScrollUpdatedSignalV2.Emit( currentScrollPosition ); +} + bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { Dali::BaseHandle handle( object ); @@ -2510,6 +2559,7 @@ void ScrollView::FinishTransform() if(!animating) { // if not animating, then this pan has completed right now. + SetScrollUpdateNotification(false); mScrolling = false; Self().SetProperty(mPropertyScrolling, false); Vector3 currentScrollPosition = GetCurrentScrollPosition(); @@ -2798,42 +2848,6 @@ void ScrollView::SetInternalConstraints() ApplyConstraintToBoundActors(constraint); } -void ScrollView::StartRefreshTimer() -{ - if(mRefreshIntervalMilliseconds > 0) - { - if (!mRefreshTimer) - { - mRefreshTimer = Timer::New( mRefreshIntervalMilliseconds ); - mRefreshTimer.TickSignal().Connect( this, &ScrollView::OnRefreshTick ); - } - - if (!mRefreshTimer.IsRunning()) - { - mRefreshTimer.Start(); - } - } -} - -void ScrollView::CancelRefreshTimer() -{ - if (mRefreshTimer) - { - mRefreshTimer.Stop(); - } -} - -bool ScrollView::OnRefreshTick() -{ - // Guard against destruction during signal emission - Toolkit::ScrollView handle( GetOwner() ); - - Vector3 currentScrollPosition = GetCurrentScrollPosition(); - mScrollUpdatedSignalV2.Emit( currentScrollPosition ); - - return true; -} - } // namespace Internal } // namespace Toolkit diff --git a/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h b/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h index 9c1b433..77587b7 100644 --- a/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h +++ b/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h @@ -266,16 +266,28 @@ public: void SetWrapMode(bool enable); /** + * @deprecated * @copydoc Toolkit::ScrollView::GetRefreshInterval */ int GetRefreshInterval() const; /** + * @deprecated * @copydoc Toolkit::ScrollView::SetRefreshInterval */ void SetRefreshInterval(int milliseconds); /** + * @copydoc Toolkit::ScrollView::GetScrollupdateDistance + */ + int GetScrollUpdateDistance() const; + + /** + * @copydoc Toolkit::ScrollView::SetScrollUpdateDistance + */ + void SetScrollUpdateDistance(int distance); + + /** * @copydoc Toolkit::ScrollView::GetAxisAutoLock */ bool GetAxisAutoLock() const; @@ -857,20 +869,15 @@ private: void HandleSnapAnimationFinished(); /** - * Helper to start the refresh timer. + * Checks if the property notifications are active and adds them if not */ - void StartRefreshTimer(); - - /** - * Helper to cancel the refresh timer. - */ - void CancelRefreshTimer(); + void SetScrollUpdateNotification( bool enabled ); /** * Refresh the ScrollView (used when animating to update application developer of changes) * @return True if the refresh timer should be kept running. */ - bool OnRefreshTick(); + void OnScrollUpdateNotification(Dali::PropertyNotification& source); private: @@ -927,9 +934,10 @@ private: LockAxis mLockAxis; Timer mTouchDownTimer; ///< Used to interrupt snap-animation. This cannot be done in OnTouchEvent without breaking fast flick behavior. - Timer mOvershootRefreshTimer; - Timer mRefreshTimer; ///< Refresh timer is used to provide the Application developer with updates as animations run. - int mRefreshIntervalMilliseconds; ///< Refresh timer interval. + + float mScrollUpdateDistance; ///< Distance for scrolling to travel for the scroll update notifications + Dali::PropertyNotification mScrollXUpdateNotification; ///< scroll x position update notification + Dali::PropertyNotification mScrollYUpdateNotification; ///< scroll y position update notification Actor mInternalActor; ///< Internal actor (we keep internal actors in here e.g. scrollbars, so we can ignore it in searches) diff --git a/base/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp b/base/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp index 69db853..ff8fd79 100644 --- a/base/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp +++ b/base/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp @@ -438,6 +438,16 @@ void ScrollView::SetRefreshInterval(int milliseconds) GetImpl(*this).SetRefreshInterval(milliseconds); } +int ScrollView::GetScrollUpdateDistance() const +{ + return GetImpl(*this).GetScrollUpdateDistance(); +} + +void ScrollView::SetScrollUpdateDistance(int distance) +{ + GetImpl(*this).SetScrollUpdateDistance(distance); +} + bool ScrollView::GetAxisAutoLock() const { return GetImpl(*this).GetAxisAutoLock(); diff --git a/capi/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h b/capi/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h index 963955c..6592fd6 100644 --- a/capi/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h +++ b/capi/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h @@ -701,6 +701,7 @@ public: void SetWrapMode(bool enable); /** + * @deprecated * @brief Gets the current refresh interval in milliseconds. * * @return Current refresh interval in milliseconds @@ -708,6 +709,7 @@ public: int GetRefreshInterval() const; /** + * @deprecated * @brief Sets the refresh interval in milliseconds. * * The refresh interval is a notification signal @@ -721,6 +723,23 @@ public: void SetRefreshInterval(int milliseconds); /** + * @brief Gets the current distance needed to scroll for ScrollUpdatedSignal to be emitted + * + * @return Current scroll update distance + */ + int GetScrollUpdateDistance() const; + + /** + * @brief Sets the distance needed to scroll for ScrollUpdatedSignal to be emitted + * + * The scroll update distance tells ScrollView how far to move before ScrollUpdatedSignal the informs application. + * Each time the ScrollView crosses this distance the signal will be emitted + * + * @param[in] distance The distance for ScrollView to move before emitting update signal + */ + void SetScrollUpdateDistance(int distance); + + /** * @brief Returns state of Axis Auto Lock mode. * * @return Whether Axis Auto Lock mode has been enabled or not. -- 2.7.4