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::Texture emptyTexture;
474 SetForegroundImage( emptyTexture );
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 Dali::Texture texture = Dali::Texture::New( *nativeImageSource );
939 SetForegroundImage( texture );
940 mIndicatorContentActor.SetSize( mImageWidth, mImageHeight );
941 mIndicatorActor.SetSize( mImageWidth, mImageHeight );
942 mEventActor.SetSize( mImageWidth, mImageHeight );
946 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
948 if( mObserver != NULL )
950 mObserver->IndicatorClosed( this );
952 // Don't do connection in this callback - strange things happen!
953 StartReconnectionTimer();
957 void Indicator::CreateNewImage( int bufferNumber )
959 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d", mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight );
960 mIndicatorBuffer = new IndicatorBuffer( mAdaptor, mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight, Pixel::BGRA8888 );
961 bool success = false;
963 if( CopyToBuffer( bufferNumber ) ) // Only create images if we have valid image buffer
965 Dali::Texture texture = Dali::Texture::New( mIndicatorBuffer->GetNativeImage() );
968 SetForegroundImage( texture );
975 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
977 if( mObserver != NULL )
979 mObserver->IndicatorClosed( this );
981 // Don't do connection in this callback - strange things happen!
982 StartReconnectionTimer();
986 Dali::Geometry Indicator::CreateBackgroundGeometry()
988 switch( mOpacityMode )
990 case Dali::Window::TRANSLUCENT:
991 if( !mTranslucentGeometry )
993 // Construct 5 interval mesh
1007 struct BackgroundVertex
1013 unsigned int numVertices = 2 * ( NUM_GRADIENT_INTERVALS + 1 );
1014 BackgroundVertex vertices[ numVertices ];
1017 float delta = 1.0f / NUM_GRADIENT_INTERVALS;
1018 BackgroundVertex* currentVertex = vertices;
1019 for( int y = 0; y < NUM_GRADIENT_INTERVALS + 1; ++y, d += delta )
1021 currentVertex->mPosition = Vector2( -0.5f, d );
1022 currentVertex->mAlpha = GRADIENT_ALPHA[ y ];
1025 currentVertex->mPosition = Vector2( 0.5f, d );
1026 currentVertex->mAlpha = GRADIENT_ALPHA[ y ];
1031 unsigned int numIndices = 2 * 3 * NUM_GRADIENT_INTERVALS;
1032 unsigned short indices[ numIndices ];
1034 unsigned short* currentIndex = indices;
1035 for( int y = 0; y < NUM_GRADIENT_INTERVALS; ++y )
1037 *currentIndex++ = (2 * y);
1038 *currentIndex++ = (2 * y) + 3;
1039 *currentIndex++ = (2 * y) + 1;
1041 *currentIndex++ = (2 * y);
1042 *currentIndex++ = (2 * y) + 2;
1043 *currentIndex++ = (2 * y) + 3;
1046 Dali::Property::Map vertexFormat;
1047 vertexFormat[ "aPosition" ] = Dali::Property::VECTOR2;
1048 vertexFormat[ "aAlpha" ] = Dali::Property::FLOAT;
1049 Dali::PropertyBuffer vertexPropertyBuffer = Dali::PropertyBuffer::New( vertexFormat );
1050 vertexPropertyBuffer.SetData( vertices, numVertices );
1052 // Create the geometry object
1053 mTranslucentGeometry = Dali::Geometry::New();
1054 mTranslucentGeometry.AddVertexBuffer( vertexPropertyBuffer );
1055 mTranslucentGeometry.SetIndexBuffer( &indices[0], numIndices );
1058 return mTranslucentGeometry;
1059 case Dali::Window::OPAQUE:
1061 if( !mSolidGeometry )
1064 struct BackgroundVertex
1070 BackgroundVertex vertices[ 4 ] = { { Vector2( -0.5f, -0.5f ), 1.0f }, { Vector2( 0.5f, -0.5f ), 1.0f },
1071 { Vector2( -0.5f, 0.5f ), 1.0f }, { Vector2( 0.5f, 0.5f ), 1.0f } };
1074 unsigned short indices[ 6 ] = { 0, 3, 1, 0, 2, 3 };
1076 Dali::Property::Map vertexFormat;
1077 vertexFormat[ "aPosition" ] = Dali::Property::VECTOR2;
1078 vertexFormat[ "aAlpha" ] = Dali::Property::FLOAT;
1079 Dali::PropertyBuffer vertexPropertyBuffer = Dali::PropertyBuffer::New( vertexFormat );
1080 vertexPropertyBuffer.SetData( vertices, 4 );
1083 // Create the geometry object
1084 mSolidGeometry = Dali::Geometry::New();
1085 mSolidGeometry.AddVertexBuffer( vertexPropertyBuffer );
1086 mSolidGeometry.SetIndexBuffer( &indices[0], 6 );
1089 return mSolidGeometry;
1090 case Dali::Window::TRANSPARENT:
1094 return Dali::Geometry();
1097 void Indicator::SetForegroundImage( Dali::Texture texture )
1099 if( !mForegroundRenderer && texture )
1102 Dali::Shader shader = Dali::Shader::New( FOREGROUND_VERTEX_SHADER, FOREGROUND_FRAGMENT_SHADER );
1104 // Create renderer from geometry and material
1105 Dali::Geometry quad = Dali::Geometry::QUAD();
1106 mForegroundRenderer = Dali::Renderer::New( quad, shader );
1107 // Make sure the foreground stays in front of the background
1108 mForegroundRenderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, 1.f );
1110 // Set blend function
1111 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB, Dali::BlendFactor::ONE );
1112 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB, Dali::BlendFactor::ONE_MINUS_SRC_ALPHA );
1113 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA, Dali::BlendFactor::ONE );
1114 mForegroundRenderer.SetProperty( Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA, Dali::BlendFactor::ONE );
1116 // Create a texture-set and add to renderer
1118 Dali::TextureSet textureSet = Dali::TextureSet::New();
1119 textureSet.SetTexture( 0u, texture );
1120 mForegroundRenderer.SetTextures( textureSet );
1122 mIndicatorContentActor.AddRenderer( mForegroundRenderer );
1124 else if( mForegroundRenderer )
1126 Dali::TextureSet textureSet = mForegroundRenderer.GetTextures();
1127 textureSet.SetTexture( 0u, texture );
1130 if( mImageWidth == 0 && mImageHeight == 0 && texture)
1132 Resize( texture.GetWidth(), texture.GetHeight() );
1136 void Indicator::OnIndicatorTypeChanged( Type indicatorType )
1138 if( mObserver != NULL )
1140 mObserver->IndicatorTypeChanged( indicatorType );
1144 void Indicator::DataReceived( void* event )
1146 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1147 Ecore_Ipc_Event_Server_Data *epcEvent = static_cast<Ecore_Ipc_Event_Server_Data *>( event );
1149 switch( epcEvent->minor )
1153 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE\n" );
1156 mAdaptor->RequestUpdateOnce();
1160 case OP_UPDATE_DONE:
1162 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE_DONE [%d]\n", epcEvent->response );
1163 // epcEvent->response == display buffer #
1164 UpdateImageData( epcEvent->response );
1169 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF0\n" );
1170 SetSharedImageInfo( epcEvent );
1175 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF1\n" );
1176 SetLockFileInfo( epcEvent );
1181 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF2\n" );
1182 LoadSharedImage( epcEvent );
1187 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_RESIZE\n" );
1189 if( (epcEvent->data) && (epcEvent->size >= (int)sizeof(IpcDataResize)) )
1191 IpcDataResize *newSize = static_cast<IpcDataResize*>( epcEvent->data );
1192 Resize( newSize->w, newSize->h );
1198 int msgDomain = epcEvent->ref;
1199 int msgId = epcEvent->ref_to;
1201 void *msgData = NULL;
1202 int msgDataSize = 0;
1203 msgData = epcEvent->data;
1204 msgDataSize = epcEvent->size;
1206 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_MSG_PARENT. msgDomain = %d\n", msgDomain );
1208 if( msgDomain == MSG_DOMAIN_CONTROL_INDICATOR )
1212 case MSG_ID_INDICATOR_TYPE:
1214 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_MSG_PARENT, INDICATOR_TYPE\n" );
1215 Type* indicatorType = static_cast<Type*>( epcEvent->data );
1216 OnIndicatorTypeChanged( *indicatorType );
1220 case MSG_ID_INDICATOR_START_ANIMATION:
1222 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: MSG_ID_INDICATOR_START_ANIMATION\n" );
1224 if (msgDataSize != (int)sizeof(IpcIndicatorDataAnimation))
1226 DALI_LOG_ERROR("Message data is incorrect");
1230 IpcIndicatorDataAnimation *animData = static_cast<IpcIndicatorDataAnimation*>(msgData);
1232 if(!CheckVisibleState())
1234 ShowIndicator( animData->duration /* n sec */ );
1246 void Indicator::ConnectionClosed()
1248 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1250 // Will get this callback if the server connection failed to start up.
1251 delete mServerConnection;
1252 mServerConnection = NULL;
1253 mState = DISCONNECTED;
1255 // Attempt to re-connect
1259 bool Indicator::CheckVisibleState()
1261 if( mOrientation == Dali::Window::LANDSCAPE
1262 || mOrientation == Dali::Window::LANDSCAPE_INVERSE
1263 || (mVisible != Dali::Window::VISIBLE) )
1271 void Indicator::ClearSharedFileInfo()
1273 for( int i = 0; i < SHARED_FILE_NUMBER; i++ )
1275 delete mSharedFileInfo[i].mLock;
1276 mSharedFileInfo[i].mLock = NULL;
1278 delete mSharedFileInfo[i].mSharedFile;
1279 mSharedFileInfo[i].mSharedFile = NULL;
1281 mSharedFileInfo[i].mLockFileName.clear();
1282 mSharedFileInfo[i].mSharedFileName.clear();
1287 * duration can be this
1291 * KEEP_SHOWING = -1,
1295 void Indicator::ShowIndicator(float duration)
1297 if( !mIndicatorAnimation )
1299 mIndicatorAnimation = Dali::Animation::New(SLIDING_ANIMATION_DURATION);
1300 mIndicatorAnimation.FinishedSignal().Connect(this, &Indicator::OnAnimationFinished);
1303 if(mIsShowing && !EqualsZero(duration))
1305 // If need to show during showing, do nothing.
1306 // In 2nd phase (below) will update timer
1308 else if(!mIsShowing && mIsAnimationPlaying && EqualsZero(duration))
1310 // If need to hide during hiding or hidden already, do nothing
1314 if( EqualsZero(duration) )
1316 mIndicatorAnimation.AnimateTo( Property( mIndicatorContentActor, Dali::Actor::Property::POSITION ), Vector3(0, -mImageHeight, 0), Dali::AlphaFunction::EASE_OUT );
1320 OnIndicatorTypeChanged( INDICATOR_TYPE_2 ); // un-toucable
1324 mIndicatorAnimation.AnimateTo( Property( mIndicatorContentActor, Dali::Actor::Property::POSITION ), Vector3(0, 0, 0), Dali::AlphaFunction::EASE_OUT );
1328 OnIndicatorTypeChanged( INDICATOR_TYPE_1 ); // touchable
1331 mIndicatorAnimation.Play();
1332 mIsAnimationPlaying = true;
1339 mShowTimer = Dali::Timer::New(1000 * duration);
1340 mShowTimer.TickSignal().Connect(this, &Indicator::OnShowTimer);
1342 mShowTimer.SetInterval(1000* duration);
1345 if( mVisible == Dali::Window::AUTO )
1347 // check the stage touch
1348 Dali::Stage::GetCurrent().TouchedSignal().Connect( this, &Indicator::OnStageTouched );
1353 if(mShowTimer && mShowTimer.IsRunning())
1358 if( mVisible == Dali::Window::AUTO )
1360 // check the stage touch
1361 Dali::Stage::GetCurrent().TouchedSignal().Disconnect( this, &Indicator::OnStageTouched );
1366 bool Indicator::OnShowTimer()
1368 // after time up, hide indicator
1369 ShowIndicator( HIDE_NOW );
1374 void Indicator::OnAnimationFinished(Dali::Animation& animation)
1376 mIsAnimationPlaying = false;
1377 // once animation is finished and indicator is hidden, take it off stage
1380 if( mObserver != NULL )
1382 mObserver->IndicatorVisibilityChanged( mIsShowing ); // is showing?
1387 void Indicator::OnPan( Dali::Actor actor, const Dali::PanGesture& gesture )
1389 if( mServerConnection )
1391 switch( gesture.state )
1393 case Gesture::Started:
1395 mGestureDetected = false;
1397 // The gesture position is the current position after it has moved by the displacement.
1398 // We want to reference the original position.
1399 mGestureDeltaY = gesture.position.y - gesture.displacement.y;
1402 // No break, Fall through
1403 case Gesture::Continuing:
1405 if( mVisible == Dali::Window::AUTO && !mIsShowing )
1407 // Only take one touch point
1408 if( gesture.numberOfTouches == 1 && mGestureDetected == false )
1410 mGestureDeltaY += gesture.displacement.y;
1412 if( mGestureDeltaY >= mImageHeight * SHOWING_DISTANCE_HEIGHT_RATE )
1414 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1415 mGestureDetected = true;
1423 case Gesture::Finished:
1424 case Gesture::Cancelled:
1426 // if indicator is showing, hide again when touching is finished (Since touch leave is activated, checking it in gesture::finish instead of touch::up)
1427 if( mVisible == Dali::Window::AUTO && mIsShowing )
1429 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1441 void Indicator::OnStageTouched(const Dali::TouchEvent& touchEvent)
1443 const TouchPoint& touchPoint = touchEvent.GetPoint( 0 );
1445 // when stage is touched while indicator is showing temporary, hide it
1446 if( mIsShowing && ( CheckVisibleState() == false || mVisible == Dali::Window::AUTO ) )
1448 switch( touchPoint.state )
1450 case Dali::PointState::DOWN:
1452 ShowIndicator( HIDE_NOW );