X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fstage-impl.cpp;h=905cfba4b678ce9fd05f73d24f791add9ae7f799;hb=35ae944cd226dd2594260c4e36b83a06773250da;hp=775c31941124403b9e94a1e8ce63d168a3bc0e6f;hpb=c72d83ab9ed29f43e69aa6959a2248e63bd1bcf8;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/stage-impl.cpp b/dali/internal/event/common/stage-impl.cpp index 775c319..905cfba 100644 --- a/dali/internal/event/common/stage-impl.cpp +++ b/dali/internal/event/common/stage-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,13 @@ // EXTERNAL INCLUDES #include #include +#include // for strcmp // INTERNAL INCLUDES #include #include #include #include -#include #include #include #include @@ -36,18 +36,19 @@ #include #include #include +#include #include #include -#ifdef DYNAMICS_SUPPORT -#include -#include -#include -#include -#endif - using Dali::Internal::SceneGraph::Node; +namespace +{ +#if defined(DEBUG_ENABLED) +Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_DEPTH_TIMER" ); +#endif +} + namespace Dali { @@ -61,21 +62,27 @@ const float DEFAULT_STEREO_BASE( 65.0f ); // Signals -const char* const SIGNAL_KEY_EVENT = "key-event"; -const char* const SIGNAL_EVENT_PROCESSING_FINISHED = "event-processing-finished"; +const char* const SIGNAL_KEY_EVENT = "keyEvent"; +const char* const SIGNAL_KEY_EVENT_GENERATED = "keyEventGenerated"; +const char* const SIGNAL_EVENT_PROCESSING_FINISHED = "eventProcessingFinished"; const char* const SIGNAL_TOUCHED = "touched"; -const char* const SIGNAL_CONTEXT_LOST = "context-lost"; -const char* const SIGNAL_CONTEXT_REGAINED = "context-regained"; -const char* const SIGNAL_SCENE_CREATED = "scene-created"; +const char* const SIGNAL_TOUCH = "touch"; +const char* const SIGNAL_WHEEL_EVENT = "wheelEvent"; +const char* const SIGNAL_CONTEXT_LOST = "contextLost"; +const char* const SIGNAL_CONTEXT_REGAINED = "contextRegained"; +const char* const SIGNAL_SCENE_CREATED = "sceneCreated"; TypeRegistration mType( typeid(Dali::Stage), typeid(Dali::BaseHandle), NULL ); SignalConnectorType signalConnector1( mType, SIGNAL_KEY_EVENT, &Stage::DoConnectSignal ); SignalConnectorType signalConnector2( mType, SIGNAL_EVENT_PROCESSING_FINISHED, &Stage::DoConnectSignal ); SignalConnectorType signalConnector3( mType, SIGNAL_TOUCHED, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector4( mType, SIGNAL_CONTEXT_LOST, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector5( mType, SIGNAL_CONTEXT_REGAINED, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector6( mType, SIGNAL_SCENE_CREATED, &Stage::DoConnectSignal ); +SignalConnectorType signalConnector4( mType, SIGNAL_WHEEL_EVENT, &Stage::DoConnectSignal ); +SignalConnectorType signalConnector5( mType, SIGNAL_CONTEXT_LOST, &Stage::DoConnectSignal ); +SignalConnectorType signalConnector6( mType, SIGNAL_CONTEXT_REGAINED, &Stage::DoConnectSignal ); +SignalConnectorType signalConnector7( mType, SIGNAL_SCENE_CREATED, &Stage::DoConnectSignal ); +SignalConnectorType signalConnector8( mType, SIGNAL_KEY_EVENT_GENERATED, &Stage::DoConnectSignal ); +SignalConnectorType signalConnector9( mType, SIGNAL_TOUCH, &Stage::DoConnectSignal ); } // unnamed namespace @@ -97,7 +104,10 @@ void Stage::Initialize() // The stage owns the default layer mRootLayer = Layer::NewRoot( *mLayerList, mUpdateManager, false/*not system-level*/ ); mRootLayer->SetName("RootLayer"); - mRootLayer->SetRelayoutEnabled( false ); // Exclude from size negotiation + // The root layer needs to have a fixed resize policy (as opposed to the default USE_NATURAL_SIZE). + // This stops actors parented to the stage having their relayout requests propagating + // up to the root layer, and down through other children unnecessarily. + mRootLayer->SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); // Create the default camera actor first; this is needed by the RenderTaskList CreateDefaultCameraActor(); @@ -117,7 +127,9 @@ void Stage::Uninitialize() if( mDefaultCamera ) { - Remove(*(mDefaultCamera.Get())); + // its enough to release the handle so the object is released + // don't need to remove it from root actor as root actor will delete the object + mDefaultCamera.Reset(); } if( mRootLayer ) @@ -185,25 +197,44 @@ void Stage::Remove( Actor& actor ) mRootLayer->Remove( actor ); } -void Stage::SetSize(float width, float height) +void Stage::SurfaceResized(float width, float height) { + mSurfaceSize.width = width; + mSurfaceSize.height = height; + // Internally we want to report the actual size of the stage. - mSize.width = width; - mSize.height = height; + mSize.width = width; + mSize.height = height - mTopMargin; // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position. - mDefaultCamera->SetPerspectiveProjection( mSize ); + mDefaultCamera->SetPerspectiveProjection( mSurfaceSize ); + + // Adjust the camera height to allow for top-margin + SetDefaultCameraPosition(); - // The depth of the stage gets set to the maximun of these values - mRootLayer->SetSize( mSize ); + mRootLayer->SetSize( mSize.width, mSize.height ); // Repeat for SystemOverlay actors if( mSystemOverlay ) { - mSystemOverlay->GetImpl()->SetSize( mSize.width, mSize.height ); + // Note that the SystemOverlay has a separate camera, configured for the full surface-size. + // This will remain unaffected by changes in SetDefaultCameraPosition() + mSystemOverlay->GetImpl()->SetSize( width, height ); } SetDefaultSurfaceRectMessage( mUpdateManager, Rect( 0, 0, width, height ) ); + + // if single render task to screen then set its viewport parameters + if( 1 == mRenderTaskList->GetTaskCount() ) + { + Dali::RenderTask mDefaultRenderTask = mRenderTaskList->GetTask(0); + + if(!mDefaultRenderTask.GetTargetFrameBuffer()) + { + mDefaultRenderTask.SetViewport( Viewport(0, 0, width, height) ); + } + } + } Vector2 Stage::GetSize() const @@ -211,6 +242,23 @@ Vector2 Stage::GetSize() const return mSize; } +void Stage::SetTopMargin( unsigned int margin ) +{ + if (mTopMargin == margin) + { + return; + } + mTopMargin = margin; + + mSize.width = mSurfaceSize.width; + mSize.height = mSurfaceSize.height - mTopMargin; + + // Adjust the camera height to allow for top-margin + SetDefaultCameraPosition(); + + mRootLayer->SetSize( mSize.width, mSize.height ); +} + RenderTaskList& Stage::GetRenderTaskList() const { return *mRenderTaskList; @@ -226,6 +274,11 @@ void Stage::CreateDefaultCameraActor() Add(*(mDefaultCamera.Get())); } +void Stage::SetDefaultCameraPosition() +{ + mDefaultCamera->SetY( -(static_cast(mTopMargin) * 0.5f) ); +} + Actor& Stage::GetDefaultRootActor() { return *mRootLayer; @@ -290,7 +343,7 @@ void Stage::SetViewMode( ViewMode viewMode ) if( mViewMode == MONO ) { - mDefaultCamera->SetOrientation( Degree( 180.0f ), Vector3::YAXIS ); + mDefaultCamera->SetOrientation( Dali::ANGLE_180, Vector3::YAXIS ); mRenderTaskList->GetTask(0).SetSourceActor( Dali::Actor() ); //Create camera and RenderTask for left eye @@ -328,8 +381,7 @@ void Stage::SetViewMode( ViewMode viewMode ) mDefaultCamera->Remove( *mRightCamera.Get() ); mRightRenderTask.Reset(); mRightCamera.Reset(); - - mDefaultCamera->SetOrientation( Degree( 0.0f ), Vector3::YAXIS ); + mDefaultCamera->SetOrientation( Dali::ANGLE_0, Vector3::YAXIS ); mDefaultCamera->SetType( Dali::Camera::LOOK_AT_TARGET ); mRenderTaskList->GetTask(0).SetSourceActor( Dali::Layer(mRootLayer.Get()) ); @@ -348,13 +400,14 @@ void Stage::SetViewMode( ViewMode viewMode ) mLeftCamera->SetPerspectiveProjection( mSize, Vector2( 0.0f,stereoBase) ); mLeftCamera->SetAspectRatio( aspect ); - mLeftCamera->SetOrientation( Degree(-90.0f), Vector3::ZAXIS ); + + mLeftCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) ); mLeftRenderTask.SetViewport( Viewport(0, mSize.height * 0.5f, mSize.width, mSize.height * 0.5f) ); mRightCamera->SetPerspectiveProjection( mSize, Vector2( 0.0, -stereoBase) ); mRightCamera->SetAspectRatio( aspect ); - mRightCamera->SetOrientation( Degree(-90.0f), Vector3::ZAXIS ); + mRightCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) ); mRightRenderTask.SetViewport( Viewport(0, 0, mSize.width, mSize.height * 0.5f ) ); @@ -370,13 +423,13 @@ void Stage::SetViewMode( ViewMode viewMode ) mLeftCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(stereoBase,0.0f) ); mLeftCamera->SetFieldOfView( fov ); - mLeftCamera->SetOrientation( Degree(0.0f), Vector3::ZAXIS ); + mLeftCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS ); mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) ); mLeftRenderTask.SetViewport( Viewport(0, 0, mSize.width * 0.5f, mSize.height ) ); mRightCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(-stereoBase,0.0f) ); mRightCamera->SetFieldOfView( fov ); - mRightCamera->SetOrientation( Degree(0.0f), Vector3::ZAXIS ); + mRightCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS ); mRightCamera->SetPosition( Vector3( -stereoBase, 0.0f, 0.0f ) ); mRightRenderTask.SetViewport( Viewport(mSize.width * 0.5f, 0, mSize.width * 0.5f, mSize.height ) ); @@ -399,7 +452,7 @@ void Stage::SetStereoBase( float stereoBase ) { if( ! Equals( mStereoBase, stereoBase ) ) { - DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "old( %.2f) new(%.2f)", mStereoBase, stereoBase ); + DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "old( %.2f) new(%.2f)\n", mStereoBase, stereoBase ); mStereoBase = stereoBase; switch( mViewMode ) @@ -469,47 +522,6 @@ void Stage::SetDpi(Vector2 dpi) mDpi = dpi; } -#ifdef DYNAMICS_SUPPORT - -DynamicsNotifier& Stage::GetDynamicsNotifier() -{ - return mDynamicsNotifier; -} - -DynamicsWorldPtr Stage::InitializeDynamics(DynamicsWorldConfigPtr config) -{ - if( !mDynamicsFactory ) - { - mDynamicsFactory = ThreadLocalStorage::Get().GetPlatformAbstraction().GetDynamicsFactory(); - } - - if( mDynamicsFactory && !mDynamicsWorld ) - { - if( mDynamicsFactory->InitializeDynamics( *(config->GetSettings()) ) ) - { - mDynamicsWorld = DynamicsWorld::New(); - mDynamicsWorld->Initialize( *this, *mDynamicsFactory, config ); - } - } - return mDynamicsWorld; -} - -DynamicsWorldPtr Stage::GetDynamicsWorld() -{ - return mDynamicsWorld; -} - -void Stage::TerminateDynamics() -{ - if( mDynamicsWorld ) - { - mDynamicsWorld->Terminate(*this); - mDynamicsWorld = NULL; - } -} - -#endif // DYNAMICS_SUPPORT - void Stage::KeepRendering( float durationSeconds ) { // Send message to keep rendering @@ -519,12 +531,16 @@ void Stage::KeepRendering( float durationSeconds ) bool Stage::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { bool connected( true ); - Stage* stage = dynamic_cast(object); + Stage* stage = static_cast< Stage* >(object); // TypeRegistry guarantees that this is the correct type. if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) ) { stage->KeyEventSignal().Connect( tracker, functor ); } + else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT_GENERATED ) ) + { + stage->KeyEventGeneratedSignal().Connect( tracker, functor ); + } else if( 0 == strcmp( signalName.c_str(), SIGNAL_EVENT_PROCESSING_FINISHED ) ) { stage->EventProcessingFinishedSignal().Connect( tracker, functor ); @@ -533,6 +549,14 @@ bool Stage::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra { stage->TouchedSignal().Connect( tracker, functor ); } + else if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCH ) ) + { + stage->TouchSignal().Connect( tracker, functor ); + } + else if( 0 == strcmp( signalName.c_str(), SIGNAL_WHEEL_EVENT ) ) + { + stage->WheelEventSignal().Connect( tracker, functor ); + } else if( 0 == strcmp( signalName.c_str(), SIGNAL_CONTEXT_LOST ) ) { stage->ContextLostSignal().Connect( tracker, functor ); @@ -561,16 +585,30 @@ void Stage::EmitKeyEventSignal(const KeyEvent& event) mKeyEventSignal.Emit( event ); } +bool Stage::EmitKeyEventGeneratedSignal(const KeyEvent& event) +{ + // Emit the KeyEventGenerated signal when KeyEvent is generated + + return mKeyEventGeneratedSignal.Emit( event ); +} + void Stage::EmitEventProcessingFinishedSignal() { mEventProcessingFinishedSignal.Emit(); } -void Stage::EmitTouchedSignal( const TouchEvent& touch ) +void Stage::EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch ) { - mTouchedSignal.Emit( touch ); + mTouchedSignal.Emit( touchEvent ); + mTouchSignal.Emit( touch ); } +void Stage::EmitWheelEventSignal(const WheelEvent& event) +{ + // Emit the wheel event signal when no actor in the stage has gained the wheel input focus + + mWheelEventSignal.Emit( event ); +} void Stage::EmitSceneCreatedSignal() { @@ -582,6 +620,11 @@ Dali::Stage::KeyEventSignalType& Stage::KeyEventSignal() return mKeyEventSignal; } +Dali::DevelStage::KeyEventGeneratedSignalType& Stage::KeyEventGeneratedSignal() +{ + return mKeyEventGeneratedSignal; +} + Dali::Stage::EventProcessingFinishedSignalType& Stage::EventProcessingFinishedSignal() { return mEventProcessingFinishedSignal; @@ -589,9 +632,20 @@ Dali::Stage::EventProcessingFinishedSignalType& Stage::EventProcessingFinishedSi Dali::Stage::TouchedSignalType& Stage::TouchedSignal() { + DALI_LOG_WARNING( "Deprecated. Use TouchSignal() instead.\n" ); return mTouchedSignal; } +Dali::Stage::TouchSignalType& Stage::TouchSignal() +{ + return mTouchSignal; +} + +Dali::Stage::WheelEventSignalType& Stage::WheelEventSignal() +{ + return mWheelEventSignal; +} + Dali::Stage::ContextStatusSignal& Stage::ContextLostSignal() { return mContextLostSignal; @@ -617,6 +671,27 @@ void Stage::NotifyContextRegained() mContextRegainedSignal.Emit(); } + +void Stage::RequestRebuildDepthTree() +{ + DALI_LOG_INFO(gLogFilter, Debug::General, "RequestRebuildDepthTree()\n"); + mDepthTreeDirty = true; +} + +void Stage::RebuildDepthTree() +{ + // If the depth tree needs rebuilding, do it in this frame only. + if( mDepthTreeDirty ) + { + DALI_LOG_INFO(gLogFilter, Debug::Concise, "RebuildDepthTree() dirty:T\n"); + + ActorPtr actor( mRootLayer.Get() ); + actor->RebuildDepthTree(); + mDepthTreeDirty = false; + } +} + + Stage::Stage( AnimationPlaylist& playlist, PropertyNotificationManager& propertyNotificationManager, SceneGraph::UpdateManager& updateManager, @@ -629,9 +704,7 @@ Stage::Stage( AnimationPlaylist& playlist, mBackgroundColor(Dali::Stage::DEFAULT_BACKGROUND_COLOR), mViewMode( MONO ), mStereoBase( DEFAULT_STEREO_BASE ), -#ifdef DYNAMICS_SUPPORT - mDynamicsFactory(NULL), -#endif + mTopMargin( 0 ), mSystemOverlay(NULL) { }