2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "ecore-indicator-impl.h"
25 #include <Ecore_Wayland.h>
30 #include <sys/types.h>
36 #include <dali/public-api/images/native-image.h>
37 #include <dali/public-api/events/touch-event.h>
38 #include <dali/public-api/events/touch-point.h>
39 #include <dali/public-api/common/stage.h>
40 #include <dali/public-api/images/buffer-image.h>
42 #include <dali/integration-api/debug.h>
45 #include <adaptor-impl.h>
46 #include <accessibility-adaptor-impl.h>
47 #include <native-image-source.h>
51 #if defined(DEBUG_ENABLED)
52 #define STATE_DEBUG_STRING(state) (state==DISCONNECTED?"DISCONNECTED":state==CONNECTED?"CONNECTED":"UNKNOWN")
58 const float SLIDING_ANIMATION_DURATION( 0.2f ); // 200 milli seconds
59 const float AUTO_INDICATOR_STAY_DURATION(3.0f); // 3 seconds
60 const float SHOWING_DISTANCE_HEIGHT_RATE(0.34f); // 20 pixels
68 const int NUM_GRADIENT_INTERVALS(5); // Number of gradient intervals
69 const float GRADIENT_ALPHA[NUM_GRADIENT_INTERVALS+1] = { 0.6f, 0.38f, 0.20f, 0.08f, 0.0f, 0.0f };
71 #define MAKE_SHADER(A)#A
73 const char* BACKGROUND_VERTEX_SHADER = MAKE_SHADER(
74 attribute mediump vec2 aPosition;
75 attribute mediump float aAlpha;
76 varying mediump float vAlpha;
77 uniform mediump mat4 uMvpMatrix;
78 uniform mediump vec3 uSize;
82 mediump vec4 vertexPosition = vec4( aPosition * uSize.xy, 0.0, 1.0 );
83 vertexPosition = uMvpMatrix * vertexPosition;
86 gl_Position = vertexPosition;
90 const char* BACKGROUND_FRAGMENT_SHADER = MAKE_SHADER(
91 uniform lowp vec4 uColor;
92 varying mediump float vAlpha;
96 gl_FragColor = uColor;
97 gl_FragColor.a *= vAlpha;
101 const char* FOREGROUND_VERTEX_SHADER = DALI_COMPOSE_SHADER(
102 attribute mediump vec2 aPosition;\n
103 varying mediump vec2 vTexCoord;\n
104 uniform mediump mat4 uMvpMatrix;\n
105 uniform mediump vec3 uSize;\n
106 uniform mediump vec4 sTextureRect;\n
110 gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n
111 vTexCoord = aPosition + vec2(0.5);\n
115 const char* FOREGROUND_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
116 varying mediump vec2 vTexCoord;\n
117 uniform sampler2D sTexture;\n
121 gl_FragColor = texture2D( sTexture, vTexCoord );\n // the foreground does not apply actor color
125 Dali::Geometry CreateQuadGeometry()
127 Dali::Property::Map quadVertexFormat;
128 quadVertexFormat["aPosition"] = Dali::Property::VECTOR2;
129 Dali::PropertyBuffer vertexData = Dali::PropertyBuffer::New( quadVertexFormat );
131 const float halfQuadSize = .5f;
132 struct QuadVertex { Dali::Vector2 position; };
133 QuadVertex quadVertexData[4] = {
134 { Dali::Vector2(-halfQuadSize, -halfQuadSize) },
135 { Dali::Vector2(-halfQuadSize, halfQuadSize) },
136 { Dali::Vector2( halfQuadSize, -halfQuadSize) },
137 { Dali::Vector2( halfQuadSize, halfQuadSize) } };
138 vertexData.SetData(quadVertexData, 4);
140 Dali::Geometry quad = Dali::Geometry::New();
141 quad.AddVertexBuffer( vertexData );
142 quad.SetType( Dali::Geometry::TRIANGLE_STRIP );
146 const float OPAQUE_THRESHOLD(0.99f);
147 const float TRANSPARENT_THRESHOLD(0.05f);
149 // indicator service name
150 const char* INDICATOR_SERVICE_NAME("elm_indicator");
152 // Copied from ecore_evas_extn_engine.h
168 OP_PROFILE_CHANGE_REQUEST,
169 OP_PROFILE_CHANGE_DONE,
187 // Copied from elm_conform.c
189 const int MSG_DOMAIN_CONTROL_INDICATOR( 0x10001 );
190 const int MSG_ID_INDICATOR_REPEAT_EVENT( 0x10002 );
191 const int MSG_ID_INDICATOR_ROTATION( 0x10003 );
192 const int MSG_ID_INDICATOR_OPACITY( 0X1004 );
193 const int MSG_ID_INDICATOR_TYPE( 0X1005 );
194 const int MSG_ID_INDICATOR_START_ANIMATION( 0X10006 );
206 struct IpcIndicatorDataAnimation
212 struct IpcDataEvMouseUp
215 Evas_Button_Flags flags;
217 unsigned int timestamp;
218 Evas_Event_Flags event_flags;
220 IpcDataEvMouseUp(unsigned long timestamp)
222 flags(EVAS_BUTTON_NONE),
224 timestamp(static_cast<unsigned int>(timestamp)),
225 event_flags(EVAS_EVENT_FLAG_NONE)
230 struct IpcDataEvMouseDown
233 Evas_Button_Flags flags;
235 unsigned int timestamp;
236 Evas_Event_Flags event_flags;
238 IpcDataEvMouseDown(unsigned long timestamp)
240 flags(EVAS_BUTTON_NONE),
242 timestamp(static_cast<unsigned int>(timestamp)),
243 event_flags(EVAS_EVENT_FLAG_NONE)
248 struct IpcDataEvMouseMove
251 Evas_Button_Flags flags;
253 unsigned int timestamp;
254 Evas_Event_Flags event_flags;
256 IpcDataEvMouseMove(const Dali::TouchPoint& touchPoint, unsigned long timestamp)
257 : x(static_cast<Evas_Coord>(touchPoint.local.x)),
258 y(static_cast<Evas_Coord>(touchPoint.local.y)),
259 flags(EVAS_BUTTON_NONE),
261 timestamp(static_cast<unsigned int>(timestamp)),
262 event_flags(EVAS_EVENT_FLAG_NONE)
267 struct IpcDataEvMouseOut
269 unsigned int timestamp;
271 Evas_Event_Flags event_flags;
273 IpcDataEvMouseOut(unsigned long timestamp)
274 : timestamp(static_cast<unsigned int>(timestamp)),
276 event_flags(EVAS_EVENT_FLAG_NONE)
281 } // anonymous namespace
290 #if defined(DEBUG_ENABLED)
291 Debug::Filter* gIndicatorLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_INDICATOR");
294 // Impl to hide EFL implementation.
296 struct Indicator::Impl
298 enum // operation mode
301 INDICATOR_STAY_WITH_DURATION
307 Impl(Indicator* indicator)
308 : mIndicator(indicator),
309 mEcoreEventHandler(NULL)
311 #if defined(DALI_PROFILE_MOBILE)
313 mEcoreEventHandler = ecore_event_handler_add(ECORE_WL_EVENT_INDICATOR_FLICK, EcoreEventIndicator, this);
315 mEcoreEventHandler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, EcoreEventClientMessage, this);
317 #endif // WAYLAND && DALI_PROFILE_MOBILE
325 if ( mEcoreEventHandler )
327 ecore_event_handler_del(mEcoreEventHandler);
331 static void SetIndicatorVisibility( void* data, int operation )
333 Indicator::Impl* indicatorImpl((Indicator::Impl*)data);
335 if ( indicatorImpl == NULL || indicatorImpl->mIndicator == NULL)
339 if ( operation == INDICATOR_STAY_WITH_DURATION )
341 // if indicator is not showing, INDICATOR_FLICK_DONE is given
342 if( indicatorImpl->mIndicator->mVisible == Dali::Window::AUTO &&
343 !indicatorImpl->mIndicator->mIsShowing )
345 indicatorImpl->mIndicator->ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
348 else if( operation == INDICATOR_HIDE )
350 if( indicatorImpl->mIndicator->mVisible == Dali::Window::AUTO &&
351 indicatorImpl->mIndicator->mIsShowing )
353 indicatorImpl->mIndicator->ShowIndicator( HIDE_NOW );
357 #if defined(DALI_PROFILE_MOBILE)
360 * Called when the Ecore indicator event is received.
362 static Eina_Bool EcoreEventIndicator( void* data, int type, void* event )
364 SetIndicatorVisibility( data, INDICATOR_STAY_WITH_DURATION );
365 return ECORE_CALLBACK_PASS_ON;
369 * Called when the client messages (i.e. quick panel state) are received.
371 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
373 Ecore_X_Event_Client_Message* clientMessageEvent((Ecore_X_Event_Client_Message*)event);
375 if ( clientMessageEvent != NULL )
377 if (clientMessageEvent->message_type == ECORE_X_ATOM_E_INDICATOR_FLICK_DONE)
379 SetIndicatorVisibility( data, INDICATOR_STAY_WITH_DURATION );
381 else if ( clientMessageEvent->message_type == ECORE_X_ATOM_E_MOVE_QUICKPANEL_STATE )
383 SetIndicatorVisibility( data, INDICATOR_HIDE );
386 return ECORE_CALLBACK_PASS_ON;
389 #endif // WAYLAND && DALI_PROFILE_MOBILE
392 Indicator* mIndicator;
393 Ecore_Event_Handler* mEcoreEventHandler;
396 Indicator::LockFile::LockFile(const std::string filename)
397 : mFilename(filename),
400 mFileDescriptor = open(filename.c_str(), O_RDWR);
401 if( mFileDescriptor == -1 )
405 DALI_LOG_ERROR( "### Cannot open %s for indicator lock ###\n", mFilename.c_str() );
409 Indicator::LockFile::~LockFile()
411 // Closing file descriptor also unlocks file.
412 close( mFileDescriptor );
415 bool Indicator::LockFile::Lock()
417 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
420 if( mFileDescriptor > 0 )
422 if( lockf( mFileDescriptor, F_LOCK, 0 ) == 0 ) // Note, operation may block.
430 // file descriptor is no longer valid or not writable
433 DALI_LOG_ERROR( "### Cannot lock indicator: bad file descriptor for %s ###\n", mFilename.c_str() );
441 void Indicator::LockFile::Unlock()
443 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
444 if( lockf( mFileDescriptor, F_ULOCK, 0 ) != 0 )
448 // file descriptor is no longer valid or not writable
451 DALI_LOG_ERROR( "### Cannot unlock indicator: bad file descriptor for %s\n", mFilename.c_str() );
456 bool Indicator::LockFile::RetrieveAndClearErrorStatus()
458 bool error = mErrorThrown;
459 mErrorThrown = false;
463 Indicator::ScopedLock::ScopedLock(LockFile* lockFile)
464 : mLockFile(lockFile),
469 mLocked = mLockFile->Lock();
473 Indicator::ScopedLock::~ScopedLock()
481 bool Indicator::ScopedLock::IsLocked()
486 Indicator::Indicator( Adaptor* adaptor, Dali::Window::WindowOrientation orientation, IndicatorInterface::Observer* observer )
488 mGestureDetected( false ),
490 mOpacityMode( Dali::Window::OPAQUE ),
491 mState( DISCONNECTED ),
493 mServerConnection( NULL ),
494 mObserver( observer ),
495 mOrientation( orientation ),
498 mVisible( Dali::Window::INVISIBLE ),
500 mIsAnimationPlaying( false ),
501 mCurrentSharedFile( 0 ),
502 mSharedBufferType( BUFFER_TYPE_SHM ),
504 mBackgroundVisible( false ),
507 mIndicatorContentActor = Dali::Actor::New();
508 mIndicatorContentActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
509 mIndicatorContentActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
511 // Indicator image handles the touch event including "leave"
512 mIndicatorContentActor.SetLeaveRequired( true );
513 mIndicatorContentActor.TouchedSignal().Connect( this, &Indicator::OnTouched );
514 mIndicatorContentActor.SetColor( Color::BLACK );
516 mIndicatorActor = Dali::Actor::New();
517 mIndicatorActor.Add( mIndicatorContentActor );
519 // Event handler to find out flick down gesture
520 mEventActor = Dali::Actor::New();
521 mEventActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
522 mEventActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
523 mIndicatorActor.Add( mEventActor );
525 // Attach pan gesture to find flick down during hiding.
526 // It can prevent the problem that scrollview gets pan gesture even indicator area is touched,
527 // since it consumes the pan gesture in advance.
528 mPanDetector = Dali::PanGestureDetector::New();
529 mPanDetector.DetectedSignal().Connect( this, &Indicator::OnPan );
530 mPanDetector.Attach( mEventActor );
534 // register indicator to accessibility adaptor
535 Dali::AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
536 if(accessibilityAdaptor)
538 AccessibilityAdaptor::GetImplementation( accessibilityAdaptor ).SetIndicator( this );
540 // hide the indicator by default
541 mIndicatorActor.SetVisible( false );
543 // create impl to handle ecore event
544 mImpl = new Impl(this);
547 Indicator::~Indicator()
557 mEventActor.TouchedSignal().Disconnect( this, &Indicator::OnTouched );
562 void Indicator::SetAdaptor(Adaptor* adaptor)
565 mIndicatorBuffer->SetAdaptor( adaptor );
568 Dali::Actor Indicator::GetActor()
570 return mIndicatorActor;
573 void Indicator::Open( Dali::Window::WindowOrientation orientation )
575 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
577 // Calls from Window should be set up to ensure we are in a
578 // disconnected state before opening a second time.
579 DALI_ASSERT_DEBUG( mState == DISCONNECTED );
581 mOrientation = orientation;
585 // Change background visibility depending on orientation
586 if( mOrientation == Dali::Window::LANDSCAPE || mOrientation == Dali::Window::LANDSCAPE_INVERSE )
588 if( mBackgroundRenderer )
590 mIndicatorContentActor.RemoveRenderer( mBackgroundRenderer );
591 mBackgroundVisible = false;
596 SetOpacityMode( mOpacityMode );
600 void Indicator::Close()
602 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "State: %s", STATE_DEBUG_STRING(mState) );
604 if( mState == CONNECTED )
607 if( mObserver != NULL )
609 mObserver->IndicatorClosed( this );
613 Dali::Texture emptyTexture;
614 SetForegroundImage( emptyTexture );
617 void Indicator::SetOpacityMode( Dali::Window::IndicatorBgOpacity mode )
621 Dali::Geometry geometry = CreateBackgroundGeometry();
624 if( mBackgroundRenderer )
626 if( mBackgroundRenderer.GetGeometry() != geometry )
628 mBackgroundRenderer.SetGeometry( geometry );
633 if( !mBackgroundShader )
635 mBackgroundShader = Dali::Shader::New( BACKGROUND_VERTEX_SHADER, BACKGROUND_FRAGMENT_SHADER, Dali::Shader::Hint::OUTPUT_IS_TRANSPARENT );
638 mBackgroundRenderer = Dali::Renderer::New( geometry, mBackgroundShader );
641 if( !mBackgroundVisible )
643 mIndicatorContentActor.AddRenderer( mBackgroundRenderer );
644 mBackgroundVisible = true;
647 else if( mBackgroundRenderer )
649 mIndicatorContentActor.RemoveRenderer( mBackgroundRenderer );
650 mBackgroundVisible = false;
655 void Indicator::SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate )
657 if ( visibleMode != mVisible || forceUpdate )
659 // If we were previously hidden, then we should update the image data before we display the indicator
660 if ( mVisible == Dali::Window::INVISIBLE )
662 UpdateImageData( mCurrentSharedFile );
665 if ( visibleMode == Dali::Window::INVISIBLE )
667 if (mServerConnection)
669 mServerConnection->SendEvent( OP_HIDE, NULL, 0 );
674 mIndicatorActor.SetVisible( true );
676 if( mServerConnection )
678 mServerConnection->SendEvent( OP_SHOW, NULL, 0 );
682 mVisible = visibleMode;
685 if( mForegroundRenderer && mForegroundRenderer.GetTextures().GetTexture( 0u ) )
687 if( CheckVisibleState() && mVisible == Dali::Window::AUTO )
690 ShowIndicator( AUTO_INDICATOR_STAY_DURATION /* stay n sec */ );
692 else if( CheckVisibleState() && mVisible == Dali::Window::VISIBLE )
695 ShowIndicator( KEEP_SHOWING );
700 ShowIndicator( HIDE_NOW );
710 bool Indicator::IsConnected()
712 return ( mState == CONNECTED );
715 bool Indicator::SendMessage( int messageDomain, int messageId, const void *data, int size )
719 return mServerConnection->SendEvent( OP_MSG, messageDomain, messageId, data, size );
727 bool Indicator::OnTouched(Dali::Actor indicator, const Dali::TouchEvent& touchEvent)
729 if( mServerConnection )
731 const TouchPoint& touchPoint = touchEvent.GetPoint( 0 );
733 // Send touch event to indicator server when indicator is showing
734 if( CheckVisibleState() || mIsShowing )
736 switch( touchPoint.state )
738 case Dali::PointState::DOWN:
740 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
741 IpcDataEvMouseDown ipcDown( touchEvent.time );
742 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
743 mServerConnection->SendEvent( OP_EV_MOUSE_DOWN, &ipcDown, sizeof(ipcDown) );
745 if( mVisible == Dali::Window::AUTO )
747 // Stop hiding indicator
748 ShowIndicator( KEEP_SHOWING );
753 case Dali::PointState::MOTION:
755 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
756 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
760 case Dali::PointState::UP:
761 case Dali::PointState::INTERRUPTED:
763 IpcDataEvMouseUp ipcUp( touchEvent.time );
764 mServerConnection->SendEvent( OP_EV_MOUSE_UP, &ipcUp, sizeof(ipcUp) );
766 if( mVisible == Dali::Window::AUTO )
769 ShowIndicator( 0.5f /* hide after 0.5 sec */ );
774 case Dali::TouchPoint::Leave:
776 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
777 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
778 IpcDataEvMouseUp ipcOut( touchEvent.time );
779 mServerConnection->SendEvent( OP_EV_MOUSE_OUT, &ipcOut, sizeof(ipcOut) );
794 bool Indicator::Connect()
796 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
798 DALI_ASSERT_DEBUG( mState == DISCONNECTED );
800 bool connected = false;
802 mServerConnection = new ServerConnection( INDICATOR_SERVICE_NAME, 0, false, this );
803 if( mServerConnection )
805 connected = mServerConnection->IsConnected();
808 delete mServerConnection;
809 mServerConnection = NULL;
815 StartReconnectionTimer();
825 void Indicator::StartReconnectionTimer()
827 if( ! mReconnectTimer )
829 mReconnectTimer = Dali::Timer::New(1000);
830 mConnection.DisconnectAll();
831 mReconnectTimer.TickSignal().Connect( mConnection, &Indicator::OnReconnectTimer );
833 mReconnectTimer.Start();
836 bool Indicator::OnReconnectTimer()
840 if( mState == DISCONNECTED )
851 void Indicator::Disconnect()
853 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
855 mState = DISCONNECTED;
857 delete mServerConnection;
858 mServerConnection = NULL;
860 ClearSharedFileInfo();
863 void Indicator::Resize( int width, int height )
874 if( mImageWidth != width || mImageHeight != height )
877 mImageHeight = height;
879 mIndicatorContentActor.SetSize( mImageWidth, mImageHeight );
880 mIndicatorActor.SetSize( mImageWidth, mImageHeight );
881 mEventActor.SetSize(mImageWidth, mImageHeight);
886 void Indicator::SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent )
888 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
890 // epcEvent->ref == w
891 // epcEvent->ref_to == h
892 // epcEvent->response == buffer num
893 // epcEvent->data = lockfile + nul byte
895 if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) && (epcEvent->data) &&
896 (((unsigned char *)epcEvent->data)[epcEvent->size - 1] == 0) )
898 int n = epcEvent->response;
900 if( n >= 0 && n < SHARED_FILE_NUMBER )
902 mCurrentSharedFile = n;
904 mSharedFileInfo[n].mImageWidth = epcEvent->ref;
905 mSharedFileInfo[n].mImageHeight = epcEvent->ref_to;
907 mSharedFileInfo[n].mLockFileName.clear();
909 mSharedFileInfo[n].mLockFileName = static_cast< char* >( epcEvent->data );
911 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "SetLockFileInfo: buffer num = %d, w = %d, h = %d, lock = %s\n",
912 n, mSharedFileInfo[n].mImageWidth, mSharedFileInfo[n].mImageHeight, mSharedFileInfo[n].mLockFileName.c_str() );
917 void Indicator::SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent )
919 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
921 // epcEvent->ref == shm id
922 // epcEvent->ref_to == shm num
923 // epcEvent->response == buffer num
924 // epcEvent->data = shm ref string + nul byte
926 if ( (epcEvent->data) &&
927 (epcEvent->size > 0) &&
928 (((unsigned char *)epcEvent->data)[epcEvent->size - 1] == 0) )
930 int n = epcEvent->response;
932 if( n >= 0 && n < SHARED_FILE_NUMBER )
934 mCurrentSharedFile = n;
936 mSharedFileInfo[n].mSharedFileName.clear();
938 mSharedFileInfo[n].mSharedFileName = static_cast< char* >( epcEvent->data );
940 mSharedFileInfo[n].mSharedFileID = epcEvent->ref;
941 mSharedFileInfo[n].mSharedFileNumber = epcEvent->ref_to;
943 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "SetSharedImageInfo: buffer num %d, shared file = %s, id = %d, num = %d\n",
944 n, mSharedFileInfo[n].mSharedFileName.c_str(), mSharedFileInfo[n].mSharedFileID, mSharedFileInfo[n].mSharedFileNumber );
949 void Indicator::LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent )
951 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
953 // epcEvent->ref == alpha
954 // epcEvent->ref_to == sys
955 // epcEvent->response == buffer num
957 if ( mSharedBufferType != BUFFER_TYPE_SHM )
962 int n = epcEvent->response;
964 if( n >= 0 && n < SHARED_FILE_NUMBER )
966 mCurrentSharedFile = n;
968 delete mSharedFileInfo[n].mSharedFile;
969 mSharedFileInfo[n].mSharedFile = NULL;
971 delete mSharedFileInfo[n].mLock;
972 mSharedFileInfo[n].mLock = NULL;
974 std::stringstream sharedFileID;
975 std::stringstream sharedFileNumber;
977 sharedFileID << mSharedFileInfo[n].mSharedFileID;
978 sharedFileNumber << mSharedFileInfo[n].mSharedFileNumber;
980 std::string sharedFilename = "/" + mSharedFileInfo[n].mSharedFileName + "-" + sharedFileID.str() + "." + sharedFileNumber.str();
982 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "LoadSharedImage: file name = %s\n", sharedFilename.c_str() );
984 mSharedFileInfo[n].mSharedFile = SharedFile::New( sharedFilename.c_str(), mSharedFileInfo[n].mImageWidth * mSharedFileInfo[n].mImageWidth * 4, true );
985 if( mSharedFileInfo[n].mSharedFile != NULL )
987 mSharedFileInfo[n].mLock = new Indicator::LockFile( mSharedFileInfo[n].mLockFileName );
988 if( mSharedFileInfo[n].mLock->RetrieveAndClearErrorStatus() )
990 DALI_LOG_ERROR( "### Indicator error: Cannot open lock file %s ###\n", mSharedFileInfo[n].mLockFileName.c_str() );
1001 void Indicator::LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent )
1003 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1005 // epcEvent->ref == pixmap id
1006 // epcEvent->ref_to == type
1007 // epcEvent->response == buffer num
1009 if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) )
1011 mSharedBufferType = (BufferType)(epcEvent->ref_to);
1013 ClearSharedFileInfo();
1015 mPixmap = static_cast<PixmapId>(epcEvent->ref);
1016 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "mPixmap [%x]", mPixmap);
1018 CreateNewPixmapImage();
1023 void Indicator::UpdateTopMargin()
1025 int newMargin = (mVisible == Dali::Window::VISIBLE && mOpacityMode == Dali::Window::OPAQUE) ? mImageHeight : 0;
1026 if (mTopMargin != newMargin)
1028 mTopMargin = newMargin;
1029 mAdaptor->IndicatorSizeChanged( mTopMargin );
1033 void Indicator::UpdateVisibility()
1035 if( CheckVisibleState() )
1037 // set default indicator type (enable the quick panel)
1038 OnIndicatorTypeChanged( INDICATOR_TYPE_1 );
1042 // set default indicator type (disable the quick panel)
1043 OnIndicatorTypeChanged( INDICATOR_TYPE_2 );
1048 mIndicatorContentActor.SetPosition( 0.0f, -mImageHeight, 0.0f );
1051 SetVisible(mVisible, true);
1054 void Indicator::UpdateImageData( int bufferNumber )
1056 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "State: %s mVisible: %s", STATE_DEBUG_STRING(mState), mVisible?"T":"F" );
1058 if( mState == CONNECTED && mVisible )
1062 // in case of shm indicator (not pixmap), not sure we can skip it when mIsShowing is false
1063 CopyToBuffer( bufferNumber );
1069 mAdaptor->RequestUpdateOnce();
1075 bool Indicator::CopyToBuffer( int bufferNumber )
1077 bool success = false;
1079 if( mSharedFileInfo[bufferNumber].mLock )
1081 Indicator::ScopedLock scopedLock(mSharedFileInfo[bufferNumber].mLock);
1082 if( mSharedFileInfo[bufferNumber].mLock->RetrieveAndClearErrorStatus() )
1086 else if( scopedLock.IsLocked() )
1088 unsigned char *src = mSharedFileInfo[bufferNumber].mSharedFile->GetAddress();
1089 size_t size = mSharedFileInfo[bufferNumber].mImageWidth * mSharedFileInfo[bufferNumber].mImageHeight * 4;
1091 if( mIndicatorBuffer->UpdatePixels( src, size ) )
1093 mAdaptor->RequestUpdateOnce();
1102 void Indicator::CreateNewPixmapImage()
1104 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d", mImageWidth, mImageHeight );
1105 Dali::NativeImageSourcePtr nativeImageSource = Dali::NativeImageSource::New( mPixmap );
1107 if( nativeImageSource )
1109 Dali::Texture texture = Dali::Texture::New( *nativeImageSource );
1110 SetForegroundImage( texture );
1111 mIndicatorContentActor.SetSize( mImageWidth, mImageHeight );
1112 mIndicatorActor.SetSize( mImageWidth, mImageHeight );
1113 mEventActor.SetSize( mImageWidth, mImageHeight );
1118 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
1120 if( mObserver != NULL )
1122 mObserver->IndicatorClosed( this );
1124 // Don't do connection in this callback - strange things happen!
1125 StartReconnectionTimer();
1129 void Indicator::CreateNewImage( int bufferNumber )
1131 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d", mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight );
1132 mIndicatorBuffer = new IndicatorBuffer( mAdaptor, mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight, Pixel::BGRA8888 );
1133 bool success = false;
1135 if( CopyToBuffer( bufferNumber ) ) // Only create images if we have valid image buffer
1137 Dali::Texture texture = Dali::Texture::New( mIndicatorBuffer->GetNativeImage() );
1140 SetForegroundImage( texture );
1147 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
1149 if( mObserver != NULL )
1151 mObserver->IndicatorClosed( this );
1153 // Don't do connection in this callback - strange things happen!
1154 StartReconnectionTimer();
1158 Dali::Geometry Indicator::CreateBackgroundGeometry()
1160 switch( mOpacityMode )
1162 case Dali::Window::TRANSLUCENT:
1163 if( !mTranslucentGeometry )
1165 // Construct 5 interval mesh
1179 struct BackgroundVertex
1185 unsigned int numVertices = 2 * ( NUM_GRADIENT_INTERVALS + 1 );
1186 BackgroundVertex vertices[ numVertices ];
1189 float delta = 1.0f / NUM_GRADIENT_INTERVALS;
1190 BackgroundVertex* currentVertex = vertices;
1191 for( int y = 0; y < NUM_GRADIENT_INTERVALS + 1; ++y, d += delta )
1193 currentVertex->mPosition = Vector2( -0.5f, d );
1194 currentVertex->mAlpha = GRADIENT_ALPHA[ y ];
1197 currentVertex->mPosition = Vector2( 0.5f, d );
1198 currentVertex->mAlpha = GRADIENT_ALPHA[ y ];
1203 unsigned int numIndices = 2 * 3 * NUM_GRADIENT_INTERVALS;
1204 unsigned short indices[ numIndices ];
1206 unsigned short* currentIndex = indices;
1207 for( int y = 0; y < NUM_GRADIENT_INTERVALS; ++y )
1209 *currentIndex++ = (2 * y);
1210 *currentIndex++ = (2 * y) + 3;
1211 *currentIndex++ = (2 * y) + 1;
1213 *currentIndex++ = (2 * y);
1214 *currentIndex++ = (2 * y) + 2;
1215 *currentIndex++ = (2 * y) + 3;
1218 Dali::Property::Map vertexFormat;
1219 vertexFormat[ "aPosition" ] = Dali::Property::VECTOR2;
1220 vertexFormat[ "aAlpha" ] = Dali::Property::FLOAT;
1221 Dali::PropertyBuffer vertexPropertyBuffer = Dali::PropertyBuffer::New( vertexFormat );
1222 vertexPropertyBuffer.SetData( vertices, numVertices );
1224 // Create the geometry object
1225 mTranslucentGeometry = Dali::Geometry::New();
1226 mTranslucentGeometry.AddVertexBuffer( vertexPropertyBuffer );
1227 mTranslucentGeometry.SetIndexBuffer( &indices[0], numIndices );
1230 return mTranslucentGeometry;
1231 case Dali::Window::OPAQUE:
1233 if( !mSolidGeometry )
1236 struct BackgroundVertex
1242 BackgroundVertex vertices[ 4 ] = { { Vector2( -0.5f, -0.5f ), 1.0f }, { Vector2( 0.5f, -0.5f ), 1.0f },
1243 { Vector2( -0.5f, 0.5f ), 1.0f }, { Vector2( 0.5f, 0.5f ), 1.0f } };
1246 unsigned short indices[ 6 ] = { 0, 3, 1, 0, 2, 3 };
1248 Dali::Property::Map vertexFormat;
1249 vertexFormat[ "aPosition" ] = Dali::Property::VECTOR2;
1250 vertexFormat[ "aAlpha" ] = Dali::Property::FLOAT;
1251 Dali::PropertyBuffer vertexPropertyBuffer = Dali::PropertyBuffer::New( vertexFormat );
1252 vertexPropertyBuffer.SetData( vertices, 4 );
1255 // Create the geometry object
1256 mSolidGeometry = Dali::Geometry::New();
1257 mSolidGeometry.AddVertexBuffer( vertexPropertyBuffer );
1258 mSolidGeometry.SetIndexBuffer( &indices[0], 6 );
1261 return mSolidGeometry;
1262 case Dali::Window::TRANSPARENT:
1266 return Dali::Geometry();
1269 void Indicator::SetForegroundImage( Dali::Texture texture )
1271 if( !mForegroundRenderer && texture )
1274 Dali::Shader shader = Dali::Shader::New( FOREGROUND_VERTEX_SHADER, FOREGROUND_FRAGMENT_SHADER );
1276 // Create renderer from geometry and material
1277 Dali::Geometry quad = CreateQuadGeometry();
1278 mForegroundRenderer = Dali::Renderer::New( quad, shader );
1279 // Make sure the foreground stays in front of the background
1280 mForegroundRenderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, 1.f );
1282 // Set blend function
1283 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB, Dali::BlendFactor::ONE );
1284 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB, Dali::BlendFactor::ONE_MINUS_SRC_ALPHA );
1285 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA, Dali::BlendFactor::ONE );
1286 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA, Dali::BlendFactor::ONE );
1288 // Create a texture-set and add to renderer
1290 Dali::TextureSet textureSet = Dali::TextureSet::New();
1291 textureSet.SetTexture( 0u, texture );
1292 mForegroundRenderer.SetTextures( textureSet );
1294 mIndicatorContentActor.AddRenderer( mForegroundRenderer );
1296 else if( mForegroundRenderer )
1298 Dali::TextureSet textureSet = mForegroundRenderer.GetTextures();
1299 textureSet.SetTexture( 0u, texture );
1302 if( mImageWidth == 0 && mImageHeight == 0 && texture)
1304 Resize( texture.GetWidth(), texture.GetHeight() );
1308 void Indicator::OnIndicatorTypeChanged( Type indicatorType )
1310 if( mObserver != NULL )
1312 mObserver->IndicatorTypeChanged( indicatorType );
1316 void Indicator::DataReceived( void* event )
1318 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1319 Ecore_Ipc_Event_Server_Data *epcEvent = static_cast<Ecore_Ipc_Event_Server_Data *>( event );
1321 switch( epcEvent->minor )
1325 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE\n" );
1328 mAdaptor->RequestUpdateOnce();
1332 case OP_UPDATE_DONE:
1334 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE_DONE [%d]\n", epcEvent->response );
1335 // epcEvent->response == display buffer #
1336 UpdateImageData( epcEvent->response );
1341 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF0\n" );
1342 SetSharedImageInfo( epcEvent );
1347 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF1\n" );
1348 SetLockFileInfo( epcEvent );
1353 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF2\n" );
1354 LoadSharedImage( epcEvent );
1359 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_PIXMAP_REF\n" );
1360 LoadPixmapImage( epcEvent );
1365 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_RESIZE\n" );
1367 if( (epcEvent->data) && (epcEvent->size >= (int)sizeof(IpcDataResize)) )
1369 IpcDataResize *newSize = static_cast<IpcDataResize*>( epcEvent->data );
1370 Resize( newSize->w, newSize->h );
1376 int msgDomain = epcEvent->ref;
1377 int msgId = epcEvent->ref_to;
1379 void *msgData = NULL;
1380 int msgDataSize = 0;
1381 msgData = epcEvent->data;
1382 msgDataSize = epcEvent->size;
1384 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_MSG_PARENT. msgDomain = %d\n", msgDomain );
1386 if( msgDomain == MSG_DOMAIN_CONTROL_INDICATOR )
1390 case MSG_ID_INDICATOR_TYPE:
1392 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_MSG_PARENT, INDICATOR_TYPE\n" );
1393 Type* indicatorType = static_cast<Type*>( epcEvent->data );
1394 OnIndicatorTypeChanged( *indicatorType );
1398 case MSG_ID_INDICATOR_START_ANIMATION:
1400 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: MSG_ID_INDICATOR_START_ANIMATION\n" );
1402 if (msgDataSize != (int)sizeof(IpcIndicatorDataAnimation))
1404 DALI_LOG_ERROR("Message data is incorrect\n");
1408 IpcIndicatorDataAnimation *animData = static_cast<IpcIndicatorDataAnimation*>(msgData);
1410 if(!CheckVisibleState())
1412 ShowIndicator( animData->duration /* n sec */ );
1423 void Indicator::ConnectionClosed()
1425 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1427 // Will get this callback if the server connection failed to start up.
1428 delete mServerConnection;
1429 mServerConnection = NULL;
1430 mState = DISCONNECTED;
1432 // Attempt to re-connect
1436 bool Indicator::CheckVisibleState()
1438 if( mOrientation == Dali::Window::LANDSCAPE
1439 || mOrientation == Dali::Window::LANDSCAPE_INVERSE
1440 || (mVisible == Dali::Window::INVISIBLE)
1441 || (mVisible == Dali::Window::AUTO && !mIsShowing) )
1449 void Indicator::ClearSharedFileInfo()
1451 for( int i = 0; i < SHARED_FILE_NUMBER; i++ )
1453 delete mSharedFileInfo[i].mLock;
1454 mSharedFileInfo[i].mLock = NULL;
1456 delete mSharedFileInfo[i].mSharedFile;
1457 mSharedFileInfo[i].mSharedFile = NULL;
1459 mSharedFileInfo[i].mLockFileName.clear();
1460 mSharedFileInfo[i].mSharedFileName.clear();
1465 * duration can be this
1469 * KEEP_SHOWING = -1,
1473 void Indicator::ShowIndicator(float duration)
1475 if( !mIndicatorAnimation )
1477 mIndicatorAnimation = Dali::Animation::New(SLIDING_ANIMATION_DURATION);
1478 mIndicatorAnimation.FinishedSignal().Connect(this, &Indicator::OnAnimationFinished);
1481 if(mIsShowing && !EqualsZero(duration))
1483 // If need to show during showing, do nothing.
1484 // In 2nd phase (below) will update timer
1486 else if(!mIsShowing && mIsAnimationPlaying && EqualsZero(duration))
1488 // If need to hide during hiding or hidden already, do nothing
1492 mIndicatorAnimation.Clear();
1494 if( EqualsZero(duration) )
1496 mIndicatorAnimation.AnimateTo( Property( mIndicatorContentActor, Dali::Actor::Property::POSITION ), Vector3(0, -mImageHeight, 0), Dali::AlphaFunction::EASE_OUT );
1500 OnIndicatorTypeChanged( INDICATOR_TYPE_2 ); // un-toucable
1504 mIndicatorAnimation.AnimateTo( Property( mIndicatorContentActor, Dali::Actor::Property::POSITION ), Vector3(0, 0, 0), Dali::AlphaFunction::EASE_OUT );
1508 OnIndicatorTypeChanged( INDICATOR_TYPE_1 ); // touchable
1511 mIndicatorAnimation.Play();
1512 mIsAnimationPlaying = true;
1519 mShowTimer = Dali::Timer::New(1000 * duration);
1520 mShowTimer.TickSignal().Connect(this, &Indicator::OnShowTimer);
1522 mShowTimer.SetInterval(1000* duration);
1525 if( mVisible == Dali::Window::AUTO )
1527 // check the stage touch
1528 Dali::Stage::GetCurrent().TouchedSignal().Connect( this, &Indicator::OnStageTouched );
1533 if(mShowTimer && mShowTimer.IsRunning())
1538 if( mVisible == Dali::Window::AUTO )
1540 // check the stage touch
1541 Dali::Stage::GetCurrent().TouchedSignal().Disconnect( this, &Indicator::OnStageTouched );
1546 bool Indicator::OnShowTimer()
1548 // after time up, hide indicator
1549 ShowIndicator( HIDE_NOW );
1554 void Indicator::OnAnimationFinished(Dali::Animation& animation)
1556 mIsAnimationPlaying = false;
1557 // once animation is finished and indicator is hidden, take it off stage
1558 if( mObserver != NULL )
1560 mObserver->IndicatorVisibilityChanged( mIsShowing ); // is showing?
1564 void Indicator::OnPan( Dali::Actor actor, const Dali::PanGesture& gesture )
1568 if( mServerConnection )
1570 switch( gesture.state )
1572 case Gesture::Started:
1574 mGestureDetected = false;
1576 // The gesture position is the current position after it has moved by the displacement.
1577 // We want to reference the original position.
1578 mGestureDeltaY = gesture.position.y - gesture.displacement.y;
1581 // No break, Fall through
1582 case Gesture::Continuing:
1584 if( mVisible == Dali::Window::AUTO && !mIsShowing )
1586 // Only take one touch point
1587 if( gesture.numberOfTouches == 1 && mGestureDetected == false )
1589 mGestureDeltaY += gesture.displacement.y;
1591 if( mGestureDeltaY >= mImageHeight * SHOWING_DISTANCE_HEIGHT_RATE )
1593 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1594 mGestureDetected = true;
1602 case Gesture::Finished:
1603 case Gesture::Cancelled:
1605 // if indicator is showing, hide again when touching is finished (Since touch leave is activated, checking it in gesture::finish instead of touch::up)
1606 if( mVisible == Dali::Window::AUTO && mIsShowing )
1608 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1620 void Indicator::OnStageTouched(const Dali::TouchEvent& touchEvent)
1622 const TouchPoint& touchPoint = touchEvent.GetPoint( 0 );
1624 // when stage is touched while indicator is showing temporary, hide it
1625 if( mIsShowing && ( CheckVisibleState() == false || mVisible == Dali::Window::AUTO ) )
1627 switch( touchPoint.state )
1629 case Dali::PointState::DOWN:
1631 // if touch point is inside the indicator, indicator is not hidden
1632 if( mImageHeight < int(touchPoint.screen.y) )
1634 ShowIndicator( HIDE_NOW );