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 <sys/types.h>
31 #include <dali/public-api/images/native-image.h>
32 #include <dali/public-api/events/touch-event.h>
33 #include <dali/public-api/events/touch-point.h>
34 #include <dali/public-api/common/stage.h>
35 #include <dali/public-api/actors/blending.h>
36 #include <dali/public-api/shader-effects/shader-effect.h>
37 #include <dali/public-api/images/buffer-image.h>
39 #include <dali/integration-api/debug.h>
42 #include <adaptor-impl.h>
43 #include <accessibility-adaptor-impl.h>
44 #include <native-image-source.h>
48 #if defined(DEBUG_ENABLED)
49 #define STATE_DEBUG_STRING(state) (state==DISCONNECTED?"DISCONNECTED":state==CONNECTED?"CONNECTED":"UNKNOWN")
55 const float SLIDING_ANIMATION_DURATION( 0.2f ); // 200 milli seconds
56 const float AUTO_INDICATOR_STAY_DURATION(3.0f); // 3 seconds
57 const float SHOWING_DISTANCE_HEIGHT_RATE(0.34f); // 20 pixels
65 const int NUM_GRADIENT_INTERVALS(5); // Number of gradient intervals
66 const float GRADIENT_ALPHA[NUM_GRADIENT_INTERVALS+1] = { 0.6f, 0.38f, 0.20f, 0.08f, 0.0f, 0.0f };
68 #define MAKE_SHADER(A)#A
70 const char* BACKGROUND_VERTEX_SHADER = MAKE_SHADER(
71 attribute mediump vec2 aPosition;
72 attribute mediump float aAlpha;
73 varying mediump float vAlpha;
74 uniform mediump mat4 uMvpMatrix;
75 uniform mediump vec3 uSize;
79 mediump vec4 vertexPosition = vec4( aPosition * uSize.xy, 0.0, 1.0 );
80 vertexPosition = uMvpMatrix * vertexPosition;
83 gl_Position = vertexPosition;
87 const char* BACKGROUND_FRAGMENT_SHADER = MAKE_SHADER(
88 uniform lowp vec4 uColor;
89 varying mediump float vAlpha;
93 gl_FragColor = uColor;
94 gl_FragColor.a *= vAlpha;
98 const char* FOREGROUND_VERTEX_SHADER = DALI_COMPOSE_SHADER(
99 attribute mediump vec2 aPosition;\n
100 varying mediump vec2 vTexCoord;\n
101 uniform mediump mat4 uMvpMatrix;\n
102 uniform mediump vec3 uSize;\n
103 uniform mediump vec4 sTextureRect;\n
107 gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n
108 vTexCoord = aPosition + vec2(0.5);\n
112 const char* FOREGROUND_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
113 varying mediump vec2 vTexCoord;\n
114 uniform sampler2D sTexture;\n
118 gl_FragColor = texture2D( sTexture, vTexCoord );\n // the foreground does not apply actor color
122 const float OPAQUE_THRESHOLD(0.99f);
123 const float TRANSPARENT_THRESHOLD(0.05f);
125 // indicator service name
126 const char* INDICATOR_SERVICE_NAME("elm_indicator");
128 // Copied from ecore_evas_extn_engine.h
142 OP_PROFILE_CHANGE_REQUEST,
143 OP_PROFILE_CHANGE_DONE,
160 // Copied from elm_conform.c
162 const int MSG_DOMAIN_CONTROL_INDICATOR( 0x10001 );
163 const int MSG_ID_INDICATOR_REPEAT_EVENT( 0x10002 );
164 const int MSG_ID_INDICATOR_ROTATION( 0x10003 );
165 const int MSG_ID_INDICATOR_OPACITY( 0X1004 );
166 const int MSG_ID_INDICATOR_TYPE( 0X1005 );
167 const int MSG_ID_INDICATOR_START_ANIMATION( 0X10006 );
179 struct IpcIndicatorDataAnimation
185 struct IpcDataEvMouseUp
188 Evas_Button_Flags flags;
190 unsigned int timestamp;
191 Evas_Event_Flags event_flags;
193 IpcDataEvMouseUp(unsigned long timestamp)
195 flags(EVAS_BUTTON_NONE),
197 timestamp(static_cast<unsigned int>(timestamp)),
198 event_flags(EVAS_EVENT_FLAG_NONE)
203 struct IpcDataEvMouseDown
206 Evas_Button_Flags flags;
208 unsigned int timestamp;
209 Evas_Event_Flags event_flags;
211 IpcDataEvMouseDown(unsigned long timestamp)
213 flags(EVAS_BUTTON_NONE),
215 timestamp(static_cast<unsigned int>(timestamp)),
216 event_flags(EVAS_EVENT_FLAG_NONE)
221 struct IpcDataEvMouseMove
224 Evas_Button_Flags flags;
226 unsigned int timestamp;
227 Evas_Event_Flags event_flags;
229 IpcDataEvMouseMove(const Dali::TouchPoint& touchPoint, unsigned long timestamp)
230 : x(static_cast<Evas_Coord>(touchPoint.local.x)),
231 y(static_cast<Evas_Coord>(touchPoint.local.y)),
232 flags(EVAS_BUTTON_NONE),
234 timestamp(static_cast<unsigned int>(timestamp)),
235 event_flags(EVAS_EVENT_FLAG_NONE)
240 struct IpcDataEvMouseOut
242 unsigned int timestamp;
244 Evas_Event_Flags event_flags;
246 IpcDataEvMouseOut(unsigned long timestamp)
247 : timestamp(static_cast<unsigned int>(timestamp)),
249 event_flags(EVAS_EVENT_FLAG_NONE)
254 } // anonymous namespace
263 #if defined(DEBUG_ENABLED)
264 Debug::Filter* gIndicatorLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_INDICATOR");
268 Indicator::LockFile::LockFile(const std::string filename)
269 : mFilename(filename),
272 mFileDescriptor = open(filename.c_str(), O_RDWR);
273 if( mFileDescriptor == -1 )
277 DALI_LOG_ERROR( "### Cannot open %s for indicator lock ###\n", mFilename.c_str() );
281 Indicator::LockFile::~LockFile()
283 // Closing file descriptor also unlocks file.
284 close( mFileDescriptor );
287 bool Indicator::LockFile::Lock()
289 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
292 if( mFileDescriptor > 0 )
294 if( lockf( mFileDescriptor, F_LOCK, 0 ) == 0 ) // Note, operation may block.
302 // file descriptor is no longer valid or not writable
305 DALI_LOG_ERROR( "### Cannot lock indicator: bad file descriptor for %s ###\n", mFilename.c_str() );
313 void Indicator::LockFile::Unlock()
315 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
316 if( lockf( mFileDescriptor, F_ULOCK, 0 ) != 0 )
320 // file descriptor is no longer valid or not writable
323 DALI_LOG_ERROR( "### Cannot unlock indicator: bad file descriptor for %s\n", mFilename.c_str() );
328 bool Indicator::LockFile::RetrieveAndClearErrorStatus()
330 bool error = mErrorThrown;
331 mErrorThrown = false;
335 Indicator::ScopedLock::ScopedLock(LockFile* lockFile)
336 : mLockFile(lockFile),
341 mLocked = mLockFile->Lock();
345 Indicator::ScopedLock::~ScopedLock()
353 bool Indicator::ScopedLock::IsLocked()
358 Indicator::Indicator( Adaptor* adaptor, Dali::Window::WindowOrientation orientation, IndicatorInterface::Observer* observer )
360 mGestureDetected( false ),
362 mOpacityMode( Dali::Window::OPAQUE ),
363 mState( DISCONNECTED ),
365 mServerConnection( NULL ),
366 mObserver( observer ),
367 mOrientation( orientation ),
370 mVisible( Dali::Window::INVISIBLE ),
372 mIsAnimationPlaying( false ),
373 mCurrentSharedFile( 0 ),
374 mBackgroundVisible( false )
376 mIndicatorContentActor = Dali::Actor::New();
377 mIndicatorContentActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
378 mIndicatorContentActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
380 // Indicator image handles the touch event including "leave"
381 mIndicatorContentActor.SetLeaveRequired( true );
382 mIndicatorContentActor.TouchedSignal().Connect( this, &Indicator::OnTouched );
383 mIndicatorContentActor.SetColor( Color::BLACK );
385 mIndicatorActor = Dali::Actor::New();
386 mIndicatorActor.Add( mIndicatorContentActor );
388 // Event handler to find out flick down gesture
389 mEventActor = Dali::Actor::New();
390 mEventActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
391 mEventActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
392 mIndicatorActor.Add( mEventActor );
394 // Attach pan gesture to find flick down during hiding.
395 // It can prevent the problem that scrollview gets pan gesture even indicator area is touched,
396 // since it consumes the pan gesture in advance.
397 mPanDetector = Dali::PanGestureDetector::New();
398 mPanDetector.DetectedSignal().Connect( this, &Indicator::OnPan );
399 mPanDetector.Attach( mEventActor );
403 // register indicator to accessibility adaptor
404 Dali::AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
405 if(accessibilityAdaptor)
407 AccessibilityAdaptor::GetImplementation( accessibilityAdaptor ).SetIndicator( this );
409 // hide the indicator by default
410 mIndicatorActor.SetVisible( false );
413 Indicator::~Indicator()
417 mEventActor.TouchedSignal().Disconnect( this, &Indicator::OnTouched );
422 void Indicator::SetAdaptor(Adaptor* adaptor)
425 mIndicatorBuffer->SetAdaptor( adaptor );
428 Dali::Actor Indicator::GetActor()
430 return mIndicatorActor;
433 void Indicator::Open( Dali::Window::WindowOrientation orientation )
435 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
437 // Calls from Window should be set up to ensure we are in a
438 // disconnected state before opening a second time.
439 DALI_ASSERT_DEBUG( mState == DISCONNECTED );
441 mOrientation = orientation;
445 // Change background visibility depending on orientation
446 if( mOrientation == Dali::Window::LANDSCAPE || mOrientation == Dali::Window::LANDSCAPE_INVERSE )
448 if( mBackgroundRenderer )
450 mIndicatorContentActor.RemoveRenderer( mBackgroundRenderer );
451 mBackgroundVisible = false;
456 SetOpacityMode( mOpacityMode );
460 void Indicator::Close()
462 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "State: %s", STATE_DEBUG_STRING(mState) );
464 if( mState == CONNECTED )
467 if( mObserver != NULL )
469 mObserver->IndicatorClosed( this );
473 Dali::Image emptyImage;
474 SetForegroundImage(emptyImage);
477 void Indicator::SetOpacityMode( Dali::Window::IndicatorBgOpacity mode )
481 Dali::Geometry geometry = CreateBackgroundGeometry();
484 if( mBackgroundRenderer )
486 if( mBackgroundRenderer.GetGeometry() != geometry )
488 mBackgroundRenderer.SetGeometry( geometry );
493 if( !mBackgroundShader )
495 mBackgroundShader = Dali::Shader::New( BACKGROUND_VERTEX_SHADER, BACKGROUND_FRAGMENT_SHADER, Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT );
498 mBackgroundRenderer = Dali::Renderer::New( geometry, mBackgroundShader );
501 if( !mBackgroundVisible )
503 mIndicatorContentActor.AddRenderer( mBackgroundRenderer );
504 mBackgroundVisible = true;
507 else if( mBackgroundRenderer )
509 mIndicatorContentActor.RemoveRenderer( mBackgroundRenderer );
510 mBackgroundVisible = false;
514 void Indicator::SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate )
516 if ( visibleMode != mVisible || forceUpdate )
518 // If we were previously hidden, then we should update the image data before we display the indicator
519 if ( mVisible == Dali::Window::INVISIBLE )
521 UpdateImageData( mCurrentSharedFile );
523 if ( visibleMode != Dali::Window::INVISIBLE )
525 mIndicatorActor.SetVisible( true );
528 mVisible = visibleMode;
530 if( mForegroundRenderer && mForegroundRenderer.GetTextures().GetImage( 0u ) )
532 if( CheckVisibleState() && mVisible == Dali::Window::AUTO )
535 ShowIndicator( AUTO_INDICATOR_STAY_DURATION /* stay n sec */ );
537 else if( CheckVisibleState() && mVisible == Dali::Window::VISIBLE )
540 ShowIndicator( KEEP_SHOWING );
545 ShowIndicator( HIDE_NOW );
551 bool Indicator::IsConnected()
553 return ( mState == CONNECTED );
556 bool Indicator::SendMessage( int messageDomain, int messageId, const void *data, int size )
560 return mServerConnection->SendEvent( OP_MSG, messageDomain, messageId, data, size );
568 bool Indicator::OnTouched(Dali::Actor indicator, const Dali::TouchEvent& touchEvent)
570 if( mServerConnection )
572 const TouchPoint& touchPoint = touchEvent.GetPoint( 0 );
574 // Send touch event to indicator server when indicator is showing
575 if( CheckVisibleState() || mIsShowing )
577 switch( touchPoint.state )
579 case Dali::PointState::DOWN:
581 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
582 IpcDataEvMouseDown ipcDown( touchEvent.time );
583 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
584 mServerConnection->SendEvent( OP_EV_MOUSE_DOWN, &ipcDown, sizeof(ipcDown) );
586 if( mVisible == Dali::Window::AUTO )
588 // Stop hiding indicator
589 ShowIndicator( KEEP_SHOWING );
594 case Dali::PointState::MOTION:
596 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
597 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
601 case Dali::PointState::UP:
603 IpcDataEvMouseUp ipcUp( touchEvent.time );
604 mServerConnection->SendEvent( OP_EV_MOUSE_UP, &ipcUp, sizeof(ipcUp) );
606 if( mVisible == Dali::Window::AUTO )
609 ShowIndicator( 0.5f /* hide after 0.5 sec */ );
614 case Dali::TouchPoint::Leave:
616 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
617 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
618 IpcDataEvMouseUp ipcOut( touchEvent.time );
619 mServerConnection->SendEvent( OP_EV_MOUSE_OUT, &ipcOut, sizeof(ipcOut) );
634 bool Indicator::Connect()
636 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
638 DALI_ASSERT_DEBUG( mState == DISCONNECTED );
640 bool connected = false;
642 mServerConnection = new ServerConnection( INDICATOR_SERVICE_NAME, 0, false, this );
643 if( mServerConnection )
645 connected = mServerConnection->IsConnected();
648 delete mServerConnection;
649 mServerConnection = NULL;
655 StartReconnectionTimer();
665 void Indicator::StartReconnectionTimer()
667 if( ! mReconnectTimer )
669 mReconnectTimer = Dali::Timer::New(1000);
670 mConnection.DisconnectAll();
671 mReconnectTimer.TickSignal().Connect( mConnection, &Indicator::OnReconnectTimer );
673 mReconnectTimer.Start();
676 bool Indicator::OnReconnectTimer()
680 if( mState == DISCONNECTED )
691 void Indicator::Disconnect()
693 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
695 mState = DISCONNECTED;
697 delete mServerConnection;
698 mServerConnection = NULL;
700 ClearSharedFileInfo();
703 void Indicator::Resize( int width, int height )
714 if( mImageWidth != width || mImageHeight != height )
717 mImageHeight = height;
719 mIndicatorContentActor.SetSize( mImageWidth, mImageHeight );
720 mIndicatorActor.SetSize( mImageWidth, mImageHeight );
721 mEventActor.SetSize(mImageWidth, mImageHeight);
725 void Indicator::SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent )
727 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
729 // epcEvent->ref == w
730 // epcEvent->ref_to == h
731 // epcEvent->response == buffer num
732 // epcEvent->data = lockfile + nul byte
734 if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) && (epcEvent->data) &&
735 (((unsigned char *)epcEvent->data)[epcEvent->size - 1] == 0) )
737 int n = epcEvent->response;
739 if( n >= 0 && n < SHARED_FILE_NUMBER )
741 mCurrentSharedFile = n;
743 mSharedFileInfo[n].mImageWidth = epcEvent->ref;
744 mSharedFileInfo[n].mImageHeight = epcEvent->ref_to;
746 mSharedFileInfo[n].mLockFileName.clear();
748 mSharedFileInfo[n].mLockFileName = static_cast< char* >( epcEvent->data );
750 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "SetLockFileInfo: buffer num = %d, w = %d, h = %d, lock = %s\n",
751 n, mSharedFileInfo[n].mImageWidth, mSharedFileInfo[n].mImageHeight, mSharedFileInfo[n].mLockFileName.c_str() );
756 void Indicator::SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent )
758 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
760 // epcEvent->ref == shm id
761 // epcEvent->ref_to == shm num
762 // epcEvent->response == buffer num
763 // epcEvent->data = shm ref string + nul byte
765 if ( (epcEvent->data) &&
766 (epcEvent->size > 0) &&
767 (((unsigned char *)epcEvent->data)[epcEvent->size - 1] == 0) )
769 int n = epcEvent->response;
771 if( n >= 0 && n < SHARED_FILE_NUMBER )
773 mCurrentSharedFile = n;
775 mSharedFileInfo[n].mSharedFileName.clear();
777 mSharedFileInfo[n].mSharedFileName = static_cast< char* >( epcEvent->data );
779 mSharedFileInfo[n].mSharedFileID = epcEvent->ref;
780 mSharedFileInfo[n].mSharedFileNumber = epcEvent->ref_to;
782 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "SetSharedImageInfo: buffer num %d, shared file = %s, id = %d, num = %d\n",
783 n, mSharedFileInfo[n].mSharedFileName.c_str(), mSharedFileInfo[n].mSharedFileID, mSharedFileInfo[n].mSharedFileNumber );
788 void Indicator::LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent )
790 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
792 // epcEvent->ref == alpha
793 // epcEvent->ref_to == sys
794 // epcEvent->response == buffer num
796 int n = epcEvent->response;
798 if( n >= 0 && n < SHARED_FILE_NUMBER )
800 mCurrentSharedFile = n;
802 delete mSharedFileInfo[n].mSharedFile;
803 mSharedFileInfo[n].mSharedFile = NULL;
805 delete mSharedFileInfo[n].mLock;
806 mSharedFileInfo[n].mLock = NULL;
808 std::stringstream sharedFileID;
809 std::stringstream sharedFileNumber;
811 sharedFileID << mSharedFileInfo[n].mSharedFileID;
812 sharedFileNumber << mSharedFileInfo[n].mSharedFileNumber;
814 std::string sharedFilename = "/" + mSharedFileInfo[n].mSharedFileName + "-" + sharedFileID.str() + "." + sharedFileNumber.str();
816 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "LoadSharedImage: file name = %s\n", sharedFilename.c_str() );
818 mSharedFileInfo[n].mSharedFile = SharedFile::New( sharedFilename.c_str(), mSharedFileInfo[n].mImageWidth * mSharedFileInfo[n].mImageWidth * 4, true );
819 if( mSharedFileInfo[n].mSharedFile != NULL )
821 mSharedFileInfo[n].mLock = new Indicator::LockFile( mSharedFileInfo[n].mLockFileName );
822 if( mSharedFileInfo[n].mLock->RetrieveAndClearErrorStatus() )
824 DALI_LOG_ERROR( "### Indicator error: Cannot open lock file %s ###\n", mSharedFileInfo[n].mLockFileName.c_str() );
829 if( CheckVisibleState() )
831 // set default indicator type (enable the quick panel)
832 OnIndicatorTypeChanged( INDICATOR_TYPE_1 );
836 // set default indicator type (disable the quick panel)
837 OnIndicatorTypeChanged( INDICATOR_TYPE_2 );
840 SetVisible(mVisible, true);
845 void Indicator::LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent )
847 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
849 // epcEvent->ref == w
850 // epcEvent->ref_to == h
851 // epcEvent->response == alpha
852 // epcEvent->data = pixmap id
854 if( ( epcEvent->data ) &&
855 (epcEvent->size >= (int)sizeof(PixmapId)) )
857 ClearSharedFileInfo();
859 if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) )
861 mImageWidth = epcEvent->ref;
862 mImageHeight = epcEvent->ref_to;
864 mPixmap = *(static_cast<PixmapId*>(epcEvent->data));
865 CreateNewPixmapImage();
867 if( CheckVisibleState() )
869 // set default indicator type (enable the quick panel)
870 OnIndicatorTypeChanged( INDICATOR_TYPE_1 );
874 // set default indicator type (disable the quick panel)
875 OnIndicatorTypeChanged( INDICATOR_TYPE_2 );
878 SetVisible(mVisible, true);
883 void Indicator::UpdateImageData( int bufferNumber )
885 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "State: %s mVisible: %s", STATE_DEBUG_STRING(mState), mVisible?"T":"F" );
887 if( mState == CONNECTED && mVisible )
891 // in case of shm indicator (not pixmap), not sure we can skip it when mIsShowing is false
892 CopyToBuffer( bufferNumber );
898 mAdaptor->RequestUpdateOnce();
904 bool Indicator::CopyToBuffer( int bufferNumber )
906 bool success = false;
908 if( mSharedFileInfo[bufferNumber].mLock )
910 Indicator::ScopedLock scopedLock(mSharedFileInfo[bufferNumber].mLock);
911 if( mSharedFileInfo[bufferNumber].mLock->RetrieveAndClearErrorStatus() )
915 else if( scopedLock.IsLocked() )
917 unsigned char *src = mSharedFileInfo[bufferNumber].mSharedFile->GetAddress();
918 size_t size = mSharedFileInfo[bufferNumber].mImageWidth * mSharedFileInfo[bufferNumber].mImageHeight * 4;
920 if( mIndicatorBuffer->UpdatePixels( src, size ) )
922 mAdaptor->RequestUpdateOnce();
931 void Indicator::CreateNewPixmapImage()
933 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d", mImageWidth, mImageHeight );
934 Dali::NativeImageSourcePtr nativeImageSource = Dali::NativeImageSource::New( mPixmap );
936 if( nativeImageSource )
938 SetForegroundImage( Dali::NativeImage::New(*nativeImageSource) );
939 mIndicatorContentActor.SetSize( mImageWidth, mImageHeight );
940 mIndicatorActor.SetSize( mImageWidth, mImageHeight );
941 mEventActor.SetSize(mImageWidth, mImageHeight);
945 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
947 if( mObserver != NULL )
949 mObserver->IndicatorClosed( this );
951 // Don't do connection in this callback - strange things happen!
952 StartReconnectionTimer();
956 void Indicator::CreateNewImage( int bufferNumber )
958 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d", mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight );
959 mIndicatorBuffer = new IndicatorBuffer( mAdaptor, mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight, Pixel::BGRA8888 );
960 Dali::Image image = Dali::NativeImage::New( mIndicatorBuffer->GetNativeImage() );
962 if( CopyToBuffer( bufferNumber ) ) // Only create images if we have valid image buffer
964 SetForegroundImage( image );
968 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
970 if( mObserver != NULL )
972 mObserver->IndicatorClosed( this );
974 // Don't do connection in this callback - strange things happen!
975 StartReconnectionTimer();
979 Dali::Geometry Indicator::CreateBackgroundGeometry()
981 switch( mOpacityMode )
983 case Dali::Window::TRANSLUCENT:
984 if( !mTranslucentGeometry )
986 // Construct 5 interval mesh
1000 struct BackgroundVertex
1006 unsigned int numVertices = 2 * ( NUM_GRADIENT_INTERVALS + 1 );
1007 BackgroundVertex vertices[ numVertices ];
1010 float delta = 1.0f / NUM_GRADIENT_INTERVALS;
1011 BackgroundVertex* currentVertex = vertices;
1012 for( int y = 0; y < NUM_GRADIENT_INTERVALS + 1; ++y, d += delta )
1014 currentVertex->mPosition = Vector2( -0.5f, d );
1015 currentVertex->mAlpha = GRADIENT_ALPHA[ y ];
1018 currentVertex->mPosition = Vector2( 0.5f, d );
1019 currentVertex->mAlpha = GRADIENT_ALPHA[ y ];
1024 unsigned int numIndices = 2 * 3 * NUM_GRADIENT_INTERVALS;
1025 unsigned short indices[ numIndices ];
1027 unsigned short* currentIndex = indices;
1028 for( int y = 0; y < NUM_GRADIENT_INTERVALS; ++y )
1030 *currentIndex++ = (2 * y);
1031 *currentIndex++ = (2 * y) + 3;
1032 *currentIndex++ = (2 * y) + 1;
1034 *currentIndex++ = (2 * y);
1035 *currentIndex++ = (2 * y) + 2;
1036 *currentIndex++ = (2 * y) + 3;
1039 Dali::Property::Map vertexFormat;
1040 vertexFormat[ "aPosition" ] = Dali::Property::VECTOR2;
1041 vertexFormat[ "aAlpha" ] = Dali::Property::FLOAT;
1042 Dali::PropertyBuffer vertexPropertyBuffer = Dali::PropertyBuffer::New( vertexFormat );
1043 vertexPropertyBuffer.SetData( vertices, numVertices );
1045 // Create the geometry object
1046 mTranslucentGeometry = Dali::Geometry::New();
1047 mTranslucentGeometry.AddVertexBuffer( vertexPropertyBuffer );
1048 mTranslucentGeometry.SetIndexBuffer( &indices[0], numIndices );
1051 return mTranslucentGeometry;
1052 case Dali::Window::OPAQUE:
1054 if( !mSolidGeometry )
1057 struct BackgroundVertex
1063 BackgroundVertex vertices[ 4 ] = { { Vector2( -0.5f, -0.5f ), 1.0f }, { Vector2( 0.5f, -0.5f ), 1.0f },
1064 { Vector2( -0.5f, 0.5f ), 1.0f }, { Vector2( 0.5f, 0.5f ), 1.0f } };
1067 unsigned short indices[ 6 ] = { 0, 3, 1, 0, 2, 3 };
1069 Dali::Property::Map vertexFormat;
1070 vertexFormat[ "aPosition" ] = Dali::Property::VECTOR2;
1071 vertexFormat[ "aAlpha" ] = Dali::Property::FLOAT;
1072 Dali::PropertyBuffer vertexPropertyBuffer = Dali::PropertyBuffer::New( vertexFormat );
1073 vertexPropertyBuffer.SetData( vertices, 4 );
1076 // Create the geometry object
1077 mSolidGeometry = Dali::Geometry::New();
1078 mSolidGeometry.AddVertexBuffer( vertexPropertyBuffer );
1079 mSolidGeometry.SetIndexBuffer( &indices[0], 6 );
1082 return mSolidGeometry;
1083 case Dali::Window::TRANSPARENT:
1087 return Dali::Geometry();
1090 void Indicator::SetForegroundImage( Dali::Image image )
1092 if( !mForegroundRenderer && image )
1095 Dali::Shader shader = Dali::Shader::New( FOREGROUND_VERTEX_SHADER, FOREGROUND_FRAGMENT_SHADER );
1097 // Create renderer from geometry and material
1098 Dali::Geometry quad = Dali::Geometry::QUAD();
1099 mForegroundRenderer = Dali::Renderer::New( quad, shader );
1100 // Make sure the foreground stays in front of the background
1101 mForegroundRenderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, 1.f );
1103 // Set blend function
1104 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB, Dali::BlendFactor::ONE );
1105 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB, Dali::BlendFactor::ONE_MINUS_SRC_ALPHA );
1106 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA, Dali::BlendFactor::ONE );
1107 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA, Dali::BlendFactor::ONE );
1109 // Create a texture-set and add to renderer
1111 Dali::TextureSet textureSet = Dali::TextureSet::New();
1112 textureSet.SetImage( 0u, image );
1113 mForegroundRenderer.SetTextures( textureSet );
1115 mIndicatorContentActor.AddRenderer( mForegroundRenderer );
1117 else if( mForegroundRenderer )
1119 Dali::TextureSet textureSet = mForegroundRenderer.GetTextures();
1120 textureSet.SetImage( 0u, image );
1123 if( mImageWidth == 0 && mImageHeight == 0 && image)
1125 Resize( image.GetWidth(), image.GetHeight() );
1129 void Indicator::OnIndicatorTypeChanged( Type indicatorType )
1131 if( mObserver != NULL )
1133 mObserver->IndicatorTypeChanged( indicatorType );
1137 void Indicator::DataReceived( void* event )
1139 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1140 Ecore_Ipc_Event_Server_Data *epcEvent = static_cast<Ecore_Ipc_Event_Server_Data *>( event );
1142 switch( epcEvent->minor )
1146 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE\n" );
1149 mAdaptor->RequestUpdateOnce();
1153 case OP_UPDATE_DONE:
1155 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE_DONE [%d]\n", epcEvent->response );
1156 // epcEvent->response == display buffer #
1157 UpdateImageData( epcEvent->response );
1162 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF0\n" );
1163 SetSharedImageInfo( epcEvent );
1168 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF1\n" );
1169 SetLockFileInfo( epcEvent );
1174 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF2\n" );
1175 LoadSharedImage( epcEvent );
1180 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_RESIZE\n" );
1182 if( (epcEvent->data) && (epcEvent->size >= (int)sizeof(IpcDataResize)) )
1184 IpcDataResize *newSize = static_cast<IpcDataResize*>( epcEvent->data );
1185 Resize( newSize->w, newSize->h );
1191 int msgDomain = epcEvent->ref;
1192 int msgId = epcEvent->ref_to;
1194 void *msgData = NULL;
1195 int msgDataSize = 0;
1196 msgData = epcEvent->data;
1197 msgDataSize = epcEvent->size;
1199 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_MSG_PARENT. msgDomain = %d\n", msgDomain );
1201 if( msgDomain == MSG_DOMAIN_CONTROL_INDICATOR )
1205 case MSG_ID_INDICATOR_TYPE:
1207 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_MSG_PARENT, INDICATOR_TYPE\n" );
1208 Type* indicatorType = static_cast<Type*>( epcEvent->data );
1209 OnIndicatorTypeChanged( *indicatorType );
1213 case MSG_ID_INDICATOR_START_ANIMATION:
1215 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: MSG_ID_INDICATOR_START_ANIMATION\n" );
1217 if (msgDataSize != (int)sizeof(IpcIndicatorDataAnimation))
1219 DALI_LOG_ERROR("Message data is incorrect");
1223 IpcIndicatorDataAnimation *animData = static_cast<IpcIndicatorDataAnimation*>(msgData);
1225 if(!CheckVisibleState())
1227 ShowIndicator( animData->duration /* n sec */ );
1239 void Indicator::ConnectionClosed()
1241 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1243 // Will get this callback if the server connection failed to start up.
1244 delete mServerConnection;
1245 mServerConnection = NULL;
1246 mState = DISCONNECTED;
1248 // Attempt to re-connect
1252 bool Indicator::CheckVisibleState()
1254 if( mOrientation == Dali::Window::LANDSCAPE
1255 || mOrientation == Dali::Window::LANDSCAPE_INVERSE
1256 || (mVisible != Dali::Window::VISIBLE) )
1264 void Indicator::ClearSharedFileInfo()
1266 for( int i = 0; i < SHARED_FILE_NUMBER; i++ )
1268 delete mSharedFileInfo[i].mLock;
1269 mSharedFileInfo[i].mLock = NULL;
1271 delete mSharedFileInfo[i].mSharedFile;
1272 mSharedFileInfo[i].mSharedFile = NULL;
1274 mSharedFileInfo[i].mLockFileName.clear();
1275 mSharedFileInfo[i].mSharedFileName.clear();
1280 * duration can be this
1284 * KEEP_SHOWING = -1,
1288 void Indicator::ShowIndicator(float duration)
1290 if( !mIndicatorAnimation )
1292 mIndicatorAnimation = Dali::Animation::New(SLIDING_ANIMATION_DURATION);
1293 mIndicatorAnimation.FinishedSignal().Connect(this, &Indicator::OnAnimationFinished);
1296 if(mIsShowing && !EqualsZero(duration))
1298 // If need to show during showing, do nothing.
1299 // In 2nd phase (below) will update timer
1301 else if(!mIsShowing && mIsAnimationPlaying && EqualsZero(duration))
1303 // If need to hide during hiding or hidden already, do nothing
1307 if( EqualsZero(duration) )
1309 mIndicatorAnimation.AnimateTo( Property( mIndicatorContentActor, Dali::Actor::Property::POSITION ), Vector3(0, -mImageHeight, 0), Dali::AlphaFunction::EASE_OUT );
1313 OnIndicatorTypeChanged( INDICATOR_TYPE_2 ); // un-toucable
1317 mIndicatorAnimation.AnimateTo( Property( mIndicatorContentActor, Dali::Actor::Property::POSITION ), Vector3(0, 0, 0), Dali::AlphaFunction::EASE_OUT );
1321 OnIndicatorTypeChanged( INDICATOR_TYPE_1 ); // touchable
1324 mIndicatorAnimation.Play();
1325 mIsAnimationPlaying = true;
1332 mShowTimer = Dali::Timer::New(1000 * duration);
1333 mShowTimer.TickSignal().Connect(this, &Indicator::OnShowTimer);
1335 mShowTimer.SetInterval(1000* duration);
1338 if( mVisible == Dali::Window::AUTO )
1340 // check the stage touch
1341 Dali::Stage::GetCurrent().TouchedSignal().Connect( this, &Indicator::OnStageTouched );
1346 if(mShowTimer && mShowTimer.IsRunning())
1351 if( mVisible == Dali::Window::AUTO )
1353 // check the stage touch
1354 Dali::Stage::GetCurrent().TouchedSignal().Disconnect( this, &Indicator::OnStageTouched );
1359 bool Indicator::OnShowTimer()
1361 // after time up, hide indicator
1362 ShowIndicator( HIDE_NOW );
1367 void Indicator::OnAnimationFinished(Dali::Animation& animation)
1369 mIsAnimationPlaying = false;
1370 // once animation is finished and indicator is hidden, take it off stage
1373 if( mObserver != NULL )
1375 mObserver->IndicatorVisibilityChanged( mIsShowing ); // is showing?
1380 void Indicator::OnPan( Dali::Actor actor, const Dali::PanGesture& gesture )
1382 if( mServerConnection )
1384 switch( gesture.state )
1386 case Gesture::Started:
1388 mGestureDetected = false;
1390 // The gesture position is the current position after it has moved by the displacement.
1391 // We want to reference the original position.
1392 mGestureDeltaY = gesture.position.y - gesture.displacement.y;
1395 // No break, Fall through
1396 case Gesture::Continuing:
1398 if( mVisible == Dali::Window::AUTO && !mIsShowing )
1400 // Only take one touch point
1401 if( gesture.numberOfTouches == 1 && mGestureDetected == false )
1403 mGestureDeltaY += gesture.displacement.y;
1405 if( mGestureDeltaY >= mImageHeight * SHOWING_DISTANCE_HEIGHT_RATE )
1407 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1408 mGestureDetected = true;
1416 case Gesture::Finished:
1417 case Gesture::Cancelled:
1419 // if indicator is showing, hide again when touching is finished (Since touch leave is activated, checking it in gesture::finish instead of touch::up)
1420 if( mVisible == Dali::Window::AUTO && mIsShowing )
1422 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1434 void Indicator::OnStageTouched(const Dali::TouchEvent& touchEvent)
1436 const TouchPoint& touchPoint = touchEvent.GetPoint( 0 );
1438 // when stage is touched while indicator is showing temporary, hide it
1439 if( mIsShowing && ( CheckVisibleState() == false || mVisible == Dali::Window::AUTO ) )
1441 switch( touchPoint.state )
1443 case Dali::PointState::DOWN:
1445 ShowIndicator( HIDE_NOW );