X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=adaptors%2Fecore%2Fcommon%2Fecore-indicator-impl.cpp;h=e3bf901d771a006cfa91f3563ab484ae8e41969b;hb=b2c3e32b52490698ad2ec4784b3291f527e4bec1;hp=7cbe6690aad0799e27810434d7a72de991d8a115;hpb=b02339ca050d56d80668a59e94ced87e2c189541;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/adaptors/ecore/common/ecore-indicator-impl.cpp b/adaptors/ecore/common/ecore-indicator-impl.cpp index 7cbe669..e3bf901 100644 --- a/adaptors/ecore/common/ecore-indicator-impl.cpp +++ b/adaptors/ecore/common/ecore-indicator-impl.cpp @@ -21,6 +21,11 @@ // EXTERNAL INCLUDES #include #include +#ifdef WAYLAND +#include +#else +#include +#endif #include #include @@ -32,8 +37,6 @@ #include #include #include -#include -#include #include #include @@ -119,6 +122,27 @@ const char* FOREGROUND_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( }\n ); +Dali::Geometry CreateQuadGeometry() +{ + Dali::Property::Map quadVertexFormat; + quadVertexFormat["aPosition"] = Dali::Property::VECTOR2; + Dali::PropertyBuffer vertexData = Dali::PropertyBuffer::New( quadVertexFormat ); + + const float halfQuadSize = .5f; + struct QuadVertex { Dali::Vector2 position; }; + QuadVertex quadVertexData[4] = { + { Dali::Vector2(-halfQuadSize, -halfQuadSize) }, + { Dali::Vector2(-halfQuadSize, halfQuadSize) }, + { Dali::Vector2( halfQuadSize, -halfQuadSize) }, + { Dali::Vector2( halfQuadSize, halfQuadSize) } }; + vertexData.SetData(quadVertexData, 4); + + Dali::Geometry quad = Dali::Geometry::New(); + quad.AddVertexBuffer( vertexData ); + quad.SetType( Dali::Geometry::TRIANGLE_STRIP ); + return quad; +} + const float OPAQUE_THRESHOLD(0.99f); const float TRANSPARENT_THRESHOLD(0.05f); @@ -127,6 +151,8 @@ const char* INDICATOR_SERVICE_NAME("elm_indicator"); // Copied from ecore_evas_extn_engine.h +#define NBUF 2 + enum // opcodes { OP_RESIZE, @@ -154,7 +180,8 @@ enum // opcodes OP_EV_KEY_DOWN, OP_EV_HOLD, OP_MSG_PARENT, - OP_MSG + OP_MSG, + OP_PIXMAP_REF, }; // Copied from elm_conform.c @@ -264,6 +291,107 @@ namespace Adaptor Debug::Filter* gIndicatorLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_INDICATOR"); #endif +// Impl to hide EFL implementation. + +struct Indicator::Impl +{ + enum // operation mode + { + INDICATOR_HIDE, + INDICATOR_STAY_WITH_DURATION + }; + + /** + * Constructor + */ + Impl(Indicator* indicator) + : mIndicator(indicator), + mEcoreEventHandler(NULL) + { +#if defined(DALI_PROFILE_MOBILE) +#if defined(WAYLAND) + mEcoreEventHandler = ecore_event_handler_add(ECORE_WL_EVENT_INDICATOR_FLICK, EcoreEventIndicator, this); +#else + mEcoreEventHandler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, EcoreEventClientMessage, this); +#endif +#endif // WAYLAND && DALI_PROFILE_MOBILE + } + + /** + * Destructor + */ + ~Impl() + { + if ( mEcoreEventHandler ) + { + ecore_event_handler_del(mEcoreEventHandler); + } + } + + static void SetIndicatorVisibility( void* data, int operation ) + { + Indicator::Impl* indicatorImpl((Indicator::Impl*)data); + + if ( indicatorImpl == NULL || indicatorImpl->mIndicator == NULL) + { + return; + } + if ( operation == INDICATOR_STAY_WITH_DURATION ) + { + // if indicator is not showing, INDICATOR_FLICK_DONE is given + if( indicatorImpl->mIndicator->mVisible == Dali::Window::AUTO && + !indicatorImpl->mIndicator->mIsShowing ) + { + indicatorImpl->mIndicator->ShowIndicator( AUTO_INDICATOR_STAY_DURATION ); + } + } + else if( operation == INDICATOR_HIDE ) + { + if( indicatorImpl->mIndicator->mVisible == Dali::Window::AUTO && + indicatorImpl->mIndicator->mIsShowing ) + { + indicatorImpl->mIndicator->ShowIndicator( HIDE_NOW ); + } + } + } +#if defined(DALI_PROFILE_MOBILE) +#if defined(WAYLAND) + /** + * Called when the Ecore indicator event is received. + */ + static Eina_Bool EcoreEventIndicator( void* data, int type, void* event ) + { + SetIndicatorVisibility( data, INDICATOR_STAY_WITH_DURATION ); + return ECORE_CALLBACK_PASS_ON; + } +#else + /** + * Called when the client messages (i.e. quick panel state) are received. + */ + static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event ) + { + Ecore_X_Event_Client_Message* clientMessageEvent((Ecore_X_Event_Client_Message*)event); + + if ( clientMessageEvent != NULL ) + { + if (clientMessageEvent->message_type == ECORE_X_ATOM_E_INDICATOR_FLICK_DONE) + { + SetIndicatorVisibility( data, INDICATOR_STAY_WITH_DURATION ); + } + else if ( clientMessageEvent->message_type == ECORE_X_ATOM_E_MOVE_QUICKPANEL_STATE ) + { + SetIndicatorVisibility( data, INDICATOR_HIDE ); + } + } + return ECORE_CALLBACK_PASS_ON; + } +#endif +#endif // WAYLAND && DALI_PROFILE_MOBILE + + // Data + Indicator* mIndicator; + Ecore_Event_Handler* mEcoreEventHandler; +}; Indicator::LockFile::LockFile(const std::string filename) : mFilename(filename), @@ -371,7 +499,10 @@ Indicator::Indicator( Adaptor* adaptor, Dali::Window::WindowOrientation orientat mIsShowing( true ), mIsAnimationPlaying( false ), mCurrentSharedFile( 0 ), - mBackgroundVisible( false ) + mSharedBufferType( BUFFER_TYPE_SHM ), + mImpl( NULL ), + mBackgroundVisible( false ), + mTopMargin( 0 ) { mIndicatorContentActor = Dali::Actor::New(); mIndicatorContentActor.SetParentOrigin( ParentOrigin::TOP_CENTER ); @@ -408,10 +539,19 @@ Indicator::Indicator( Adaptor* adaptor, Dali::Window::WindowOrientation orientat } // hide the indicator by default mIndicatorActor.SetVisible( false ); + + // create impl to handle ecore event + mImpl = new Impl(this); } Indicator::~Indicator() { + if(mImpl) + { + delete mImpl; + mImpl = NULL; + } + if(mEventActor) { mEventActor.TouchedSignal().Disconnect( this, &Indicator::OnTouched ); @@ -470,8 +610,8 @@ void Indicator::Close() } } - Dali::Image emptyImage; - SetForegroundImage(emptyImage); + Dali::Texture emptyTexture; + SetForegroundImage( emptyTexture ); } void Indicator::SetOpacityMode( Dali::Window::IndicatorBgOpacity mode ) @@ -492,7 +632,7 @@ void Indicator::SetOpacityMode( Dali::Window::IndicatorBgOpacity mode ) { if( !mBackgroundShader ) { - mBackgroundShader = Dali::Shader::New( BACKGROUND_VERTEX_SHADER, BACKGROUND_FRAGMENT_SHADER, Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT ); + mBackgroundShader = Dali::Shader::New( BACKGROUND_VERTEX_SHADER, BACKGROUND_FRAGMENT_SHADER, Dali::Shader::Hint::OUTPUT_IS_TRANSPARENT ); } mBackgroundRenderer = Dali::Renderer::New( geometry, mBackgroundShader ); @@ -509,6 +649,7 @@ void Indicator::SetOpacityMode( Dali::Window::IndicatorBgOpacity mode ) mIndicatorContentActor.RemoveRenderer( mBackgroundRenderer ); mBackgroundVisible = false; } + UpdateTopMargin(); } void Indicator::SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate ) @@ -520,14 +661,28 @@ void Indicator::SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool { UpdateImageData( mCurrentSharedFile ); } - if ( visibleMode != Dali::Window::INVISIBLE ) + + if ( visibleMode == Dali::Window::INVISIBLE ) + { + if (mServerConnection) + { + mServerConnection->SendEvent( OP_HIDE, NULL, 0 ); + } + } + else { mIndicatorActor.SetVisible( true ); + + if( mServerConnection ) + { + mServerConnection->SendEvent( OP_SHOW, NULL, 0 ); + } } mVisible = visibleMode; + UpdateTopMargin(); - if( mForegroundRenderer && mForegroundRenderer.GetTextures().GetImage( 0u ) ) + if( mForegroundRenderer && mForegroundRenderer.GetTextures().GetTexture( 0u ) ) { if( CheckVisibleState() && mVisible == Dali::Window::AUTO ) { @@ -545,6 +700,10 @@ void Indicator::SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool ShowIndicator( HIDE_NOW ); } } + else + { + mIsShowing = false; + } } } @@ -599,6 +758,7 @@ bool Indicator::OnTouched(Dali::Actor indicator, const Dali::TouchEvent& touchEv break; case Dali::PointState::UP: + case Dali::PointState::INTERRUPTED: { IpcDataEvMouseUp ipcUp( touchEvent.time ); mServerConnection->SendEvent( OP_EV_MOUSE_UP, &ipcUp, sizeof(ipcUp) ); @@ -719,6 +879,7 @@ void Indicator::Resize( int width, int height ) mIndicatorContentActor.SetSize( mImageWidth, mImageHeight ); mIndicatorActor.SetSize( mImageWidth, mImageHeight ); mEventActor.SetSize(mImageWidth, mImageHeight); + UpdateTopMargin(); } } @@ -793,6 +954,11 @@ void Indicator::LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent ) // epcEvent->ref_to == sys // epcEvent->response == buffer num + if ( mSharedBufferType != BUFFER_TYPE_SHM ) + { + return ; + } + int n = epcEvent->response; if( n >= 0 && n < SHARED_FILE_NUMBER ) @@ -825,19 +991,7 @@ void Indicator::LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent ) } CreateNewImage( n ); - - if( CheckVisibleState() ) - { - // set default indicator type (enable the quick panel) - OnIndicatorTypeChanged( INDICATOR_TYPE_1 ); - } - else - { - // set default indicator type (disable the quick panel) - OnIndicatorTypeChanged( INDICATOR_TYPE_2 ); - } - - SetVisible(mVisible, true); + UpdateVisibility(); } } } @@ -846,38 +1000,53 @@ void Indicator::LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent ) { DALI_LOG_TRACE_METHOD( gIndicatorLogFilter ); - // epcEvent->ref == w - // epcEvent->ref_to == h - // epcEvent->response == alpha - // epcEvent->data = pixmap id + // epcEvent->ref == pixmap id + // epcEvent->ref_to == type + // epcEvent->response == buffer num - if( ( epcEvent->data ) && - (epcEvent->size >= (int)sizeof(PixmapId)) ) + if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) ) { + mSharedBufferType = (BufferType)(epcEvent->ref_to); + ClearSharedFileInfo(); - if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) ) - { - mImageWidth = epcEvent->ref; - mImageHeight = epcEvent->ref_to; + mPixmap = static_cast(epcEvent->ref); + DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "mPixmap [%x]", mPixmap); - mPixmap = *(static_cast(epcEvent->data)); - CreateNewPixmapImage(); + CreateNewPixmapImage(); + UpdateVisibility(); + } +} - if( CheckVisibleState() ) - { - // set default indicator type (enable the quick panel) - OnIndicatorTypeChanged( INDICATOR_TYPE_1 ); - } - else - { - // set default indicator type (disable the quick panel) - OnIndicatorTypeChanged( INDICATOR_TYPE_2 ); - } +void Indicator::UpdateTopMargin() +{ + int newMargin = (mVisible == Dali::Window::VISIBLE && mOpacityMode == Dali::Window::OPAQUE) ? mImageHeight : 0; + if (mTopMargin != newMargin) + { + mTopMargin = newMargin; + mAdaptor->IndicatorSizeChanged( mTopMargin ); + } +} - SetVisible(mVisible, true); - } +void Indicator::UpdateVisibility() +{ + if( CheckVisibleState() ) + { + // set default indicator type (enable the quick panel) + OnIndicatorTypeChanged( INDICATOR_TYPE_1 ); + } + else + { + // set default indicator type (disable the quick panel) + OnIndicatorTypeChanged( INDICATOR_TYPE_2 ); + } + + if( !mIsShowing ) + { + mIndicatorContentActor.SetPosition( 0.0f, -mImageHeight, 0.0f ); } + + SetVisible(mVisible, true); } void Indicator::UpdateImageData( int bufferNumber ) @@ -935,10 +1104,12 @@ void Indicator::CreateNewPixmapImage() if( nativeImageSource ) { - SetForegroundImage( Dali::NativeImage::New(*nativeImageSource) ); + Dali::Texture texture = Dali::Texture::New( *nativeImageSource ); + SetForegroundImage( texture ); mIndicatorContentActor.SetSize( mImageWidth, mImageHeight ); mIndicatorActor.SetSize( mImageWidth, mImageHeight ); - mEventActor.SetSize(mImageWidth, mImageHeight); + mEventActor.SetSize( mImageWidth, mImageHeight ); + UpdateTopMargin(); } else { @@ -957,13 +1128,19 @@ void Indicator::CreateNewImage( int bufferNumber ) { DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d", mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight ); mIndicatorBuffer = new IndicatorBuffer( mAdaptor, mSharedFileInfo[bufferNumber].mImageWidth, mSharedFileInfo[bufferNumber].mImageHeight, Pixel::BGRA8888 ); - Dali::Image image = Dali::NativeImage::New( mIndicatorBuffer->GetNativeImage() ); + bool success = false; if( CopyToBuffer( bufferNumber ) ) // Only create images if we have valid image buffer { - SetForegroundImage( image ); + Dali::Texture texture = Dali::Texture::New( mIndicatorBuffer->GetNativeImage() ); + if( texture ) + { + SetForegroundImage( texture ); + success = true; + } } - else + + if( !success ) { DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n"); Disconnect(); @@ -1087,15 +1264,15 @@ Dali::Geometry Indicator::CreateBackgroundGeometry() return Dali::Geometry(); } -void Indicator::SetForegroundImage( Dali::Image image ) +void Indicator::SetForegroundImage( Dali::Texture texture ) { - if( !mForegroundRenderer && image ) + if( !mForegroundRenderer && texture ) { // Create Shader Dali::Shader shader = Dali::Shader::New( FOREGROUND_VERTEX_SHADER, FOREGROUND_FRAGMENT_SHADER ); // Create renderer from geometry and material - Dali::Geometry quad = Dali::Geometry::QUAD(); + Dali::Geometry quad = CreateQuadGeometry(); mForegroundRenderer = Dali::Renderer::New( quad, shader ); // Make sure the foreground stays in front of the background mForegroundRenderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, 1.f ); @@ -1109,7 +1286,7 @@ void Indicator::SetForegroundImage( Dali::Image image ) // Create a texture-set and add to renderer Dali::TextureSet textureSet = Dali::TextureSet::New(); - textureSet.SetImage( 0u, image ); + textureSet.SetTexture( 0u, texture ); mForegroundRenderer.SetTextures( textureSet ); mIndicatorContentActor.AddRenderer( mForegroundRenderer ); @@ -1117,12 +1294,12 @@ void Indicator::SetForegroundImage( Dali::Image image ) else if( mForegroundRenderer ) { Dali::TextureSet textureSet = mForegroundRenderer.GetTextures(); - textureSet.SetImage( 0u, image ); + textureSet.SetTexture( 0u, texture ); } - if( mImageWidth == 0 && mImageHeight == 0 && image) + if( mImageWidth == 0 && mImageHeight == 0 && texture) { - Resize( image.GetWidth(), image.GetHeight() ); + Resize( texture.GetWidth(), texture.GetHeight() ); } } @@ -1175,6 +1352,12 @@ void Indicator::DataReceived( void* event ) LoadSharedImage( epcEvent ); break; } + case OP_PIXMAP_REF: + { + DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_PIXMAP_REF\n" ); + LoadPixmapImage( epcEvent ); + break; + } case OP_RESIZE: { DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_RESIZE\n" ); @@ -1216,7 +1399,7 @@ void Indicator::DataReceived( void* event ) if (msgDataSize != (int)sizeof(IpcIndicatorDataAnimation)) { - DALI_LOG_ERROR("Message data is incorrect"); + DALI_LOG_ERROR("Message data is incorrect\n"); break; } @@ -1228,7 +1411,6 @@ void Indicator::DataReceived( void* event ) } break; } - } } break; @@ -1253,7 +1435,8 @@ bool Indicator::CheckVisibleState() { if( mOrientation == Dali::Window::LANDSCAPE || mOrientation == Dali::Window::LANDSCAPE_INVERSE - || (mVisible != Dali::Window::VISIBLE) ) + || (mVisible == Dali::Window::INVISIBLE) + || (mVisible == Dali::Window::AUTO && !mIsShowing) ) { return false; } @@ -1304,6 +1487,8 @@ void Indicator::ShowIndicator(float duration) } else { + mIndicatorAnimation.Clear(); + if( EqualsZero(duration) ) { mIndicatorAnimation.AnimateTo( Property( mIndicatorContentActor, Dali::Actor::Property::POSITION ), Vector3(0, -mImageHeight, 0), Dali::AlphaFunction::EASE_OUT ); @@ -1368,17 +1553,16 @@ void Indicator::OnAnimationFinished(Dali::Animation& animation) { mIsAnimationPlaying = false; // once animation is finished and indicator is hidden, take it off stage - if( !mIsShowing ) + if( mObserver != NULL ) { - if( mObserver != NULL ) - { - mObserver->IndicatorVisibilityChanged( mIsShowing ); // is showing? - } + mObserver->IndicatorVisibilityChanged( mIsShowing ); // is showing? } } void Indicator::OnPan( Dali::Actor actor, const Dali::PanGesture& gesture ) { + return ; + if( mServerConnection ) { switch( gesture.state ) @@ -1442,7 +1626,11 @@ void Indicator::OnStageTouched(const Dali::TouchEvent& touchEvent) { case Dali::PointState::DOWN: { - ShowIndicator( HIDE_NOW ); + // if touch point is inside the indicator, indicator is not hidden + if( mImageHeight < int(touchPoint.screen.y) ) + { + ShowIndicator( HIDE_NOW ); + } break; }