{
gResourceReadySignalCounter++;
- if( gResourceReadySignalCounter == 1 )
+ if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
{
- // Set image twice
- ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
- ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
+ if( gResourceReadySignalCounter == 1 )
+ {
+ // Set image twice
+ // It makes the first new visual be deleted immediately
+ ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
+ ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
+ }
+ }
+ else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
+ {
+ // Make the resource ready immediately
+ control[ImageView::Property::IMAGE] = TEST_RESOURCE_DIR "/svg1.svg";
}
}
DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
+ // Reset count
+ gResourceReadySignalCounter = 0;
+
+ imageView[ImageView::Property::IMAGE] = "invalid.jpg";
+
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ // Run idle callback
+ application.RunIdles();
+
+ DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
+
END_TEST;
}
#include <dali/devel-api/scripting/scripting.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <cstring>
#include <limits>
mDownFocusableActorId( -1 ),
mStyleName(""),
mBackgroundColor(Color::TRANSPARENT),
- mStartingPinchScale( NULL ),
+ mStartingPinchScale(nullptr),
mMargin( 0, 0, 0, 0 ),
mPadding( 0, 0, 0, 0 ),
mKeyEventSignal(),
mLongPressGestureDetector(),
mTooltip( NULL ),
mInputMethodContext(),
+ mIdleCallback(nullptr),
mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
mIsKeyboardNavigationSupported( false ),
- mIsKeyboardFocusGroup( false )
+ mIsKeyboardFocusGroup( false ),
+ mIsEmittingResourceReadySignal(false),
+ mNeedToEmitResourceReady(false)
{
}
{
// All gesture detectors will be destroyed so no need to disconnect.
delete mStartingPinchScale;
+
+ if(mIdleCallback && Adaptor::IsAvailable())
+ {
+ // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
+ Adaptor::Get().RemoveIdle(mIdleCallback);
+ }
}
Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
// Emit signal if all enabled visuals registered by the control are ready.
if( IsResourceReady() )
{
- Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
- mResourceReadySignal.Emit( handle );
+ // Reset the flag
+ mNeedToEmitResourceReady = false;
+
+ EmitResourceReadySignal();
}
}
mControlImpl.RelayoutRequest();
}
+void Control::Impl::EmitResourceReadySignal()
+{
+ if(!mIsEmittingResourceReadySignal)
+ {
+ // Guard against calls to emit the signal during the callback
+ mIsEmittingResourceReadySignal = true;
+
+ // If the signal handler changes visual, it may become ready during this call & therefore this method will
+ // get called again recursively. If so, mNeedToEmitResourceReady is set below, and we act on it after that secondary
+ // invocation has completed by notifying in an Idle callback to prevent further recursion.
+ Dali::Toolkit::Control handle(mControlImpl.GetOwner());
+ mResourceReadySignal.Emit(handle);
+
+ if(mNeedToEmitResourceReady)
+ {
+ // Add idler to emit the signal again
+ if(!mIdleCallback)
+ {
+ // The callback manager takes the ownership of the callback object.
+ mIdleCallback = MakeCallback( this, &Control::Impl::OnIdleCallback);
+ Adaptor::Get().AddIdle(mIdleCallback, false);
+ }
+ }
+
+ mIsEmittingResourceReadySignal = false;
+ }
+ else
+ {
+ mNeedToEmitResourceReady = true;
+ }
+}
+
+void Control::Impl::OnIdleCallback()
+{
+ if(mNeedToEmitResourceReady)
+ {
+ // Reset the flag
+ mNeedToEmitResourceReady = false;
+
+ // A visual is ready so control may need relayouting if staged
+ if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
+ {
+ mControlImpl.RelayoutRequest();
+ }
+
+ EmitResourceReadySignal();
+ }
+
+ // Set the pointer to null as the callback manager deletes the callback after execute it.
+ mIdleCallback = nullptr;
+}
+
} // namespace Internal
} // namespace Toolkit
*/
void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
+ /**
+ * @brief Emits the resource ready signal.
+ */
+ void EmitResourceReadySignal();
+
+ /**
+ * @brief Callbacks called on idle.
+ */
+ void OnIdleCallback();
+
public:
Control& mControlImpl;
TooltipPtr mTooltip;
InputMethodContext mInputMethodContext;
+ CallbackBase* mIdleCallback; ///< The idle callback to emit the resource ready signal.
ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
+ bool mIsEmittingResourceReadySignal :1; ///< True during ResourceReady().
+ bool mNeedToEmitResourceReady :1; ///< True if need to emit the resource ready signal again.
RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready