1 #ifndef __DALI_INTERNAL_ECORE_INDICATOR_H__
2 #define __DALI_INTERNAL_ECORE_INDICATOR_H__
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/animation/animation.h>
23 #include <dali/public-api/events/pan-gesture.h>
24 #include <dali/public-api/events/pan-gesture-detector.h>
25 #include <dali/public-api/events/touch-data.h>
26 #include <dali/public-api/rendering/renderer.h>
29 #include <base/interfaces/indicator-interface.h>
30 #include <indicator-buffer.h>
31 #include <ecore-server-connection.h>
32 #include <shared-file.h>
49 typedef unsigned int PixmapId;
52 * The Indicator class connects to the indicator server, and gets and draws the indicator
53 * for the given orientation.
55 class Indicator : public ConnectionTracker, public ServerConnection::Observer, public IndicatorInterface
66 * copied from ecore_evas_extn_engine.h
70 BUFFER_TYPE_SHM = 0, ///< shared memory-based buffer backend
71 BUFFER_TYPE_DRI2_PIXMAP, ///< dri2 pixmap-based buffer backend
72 BUFFER_TYPE_EVASGL_PIXMAP, ///< pixmap backend for Evas GL only (DEPRECATED)
73 BUFFER_TYPE_GL_PIXMAP, ///< double buffered GL pixmap backend
78 * Class to encapsulate lock file
84 * Constructor. open lock file
86 LockFile(const std::string filename);
94 * Grab an exclusive lock on this file
95 * @return true if the lock succeeded, false if it failed
105 * Test if there is an error with the lock file, and clears
107 * @return true if an error was thrown
109 bool RetrieveAndClearErrorStatus();
112 std::string mFilename;
118 * Class to ensure lock/unlock through object destruction
124 * Constructor - creates a lock on the lockfile
125 * @param[in] lockFile The lockfile to use
127 ScopedLock( LockFile* lockFile );
130 * Destructor - removes the lock (if any) on the lockfile
135 * Method to test if the locking succeeded
136 * @return TRUE if locked
141 LockFile* mLockFile; ///< The lock file to use
142 bool mLocked; ///< Whether the lock succeeded
146 public: // Dali::Internal::Adaptor::IndicicatorInterface
148 * @copydoc Dali::Internal::IndicatorInterface::IndicatorInterface
150 Indicator( Adaptor* adaptor,
151 Dali::Window::WindowOrientation orientation,
152 IndicatorInterface::Observer* observer );
155 * @copydoc Dali::Internal::IndicatorInterface::~IndicatorInterface
157 virtual ~Indicator();
160 virtual void SetAdaptor(Adaptor* adaptor);
163 * @copydoc Dali::Internal::IndicatorInterface::GetActor
165 virtual Dali::Actor GetActor();
168 * @copydoc Dali::Internal::IndicatorInterface::Open
170 virtual void Open( Dali::Window::WindowOrientation orientation );
173 * @copydoc Dali::Internal::IndicatorInterface::Close
175 virtual void Close();
178 * @copydoc Dali::Internal::IndicatorInterface::SetOpacityMode
180 virtual void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
183 * @copydoc Dali::Internal::IndicatorInterface::SetVisible
185 virtual void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
188 * @copydoc Dali::Internal::IndicatorInterface::IsConnected
190 virtual bool IsConnected();
193 * @copydoc Dali::Internal::IndicatorInterface::SendMessage
195 virtual bool SendMessage( int messageDomain, int messageId, const void *data, int size );
199 * Initialize the indicator actors
204 * Constructs the renderers used for the background
206 Dali::Geometry CreateBackgroundGeometry();
209 * Set the texture to be rendered as indicator foreground
210 * @param[in] texture The foreground texture.
212 void SetForegroundImage( Dali::Texture texture );
215 * Touch event callback.
216 * It should pass the valid touch event to indicator server
218 * @param[in] indicator The indicator actor that was touched
219 * @param[in] touchEvent The touch data
221 bool OnTouch(Dali::Actor indicator, const Dali::TouchData& touchData);
224 * Pan gesture callback.
225 * It finds flick down gesture to show hidden indicator image
227 * @param[in] actor The actor for gesture
228 * @param[in] gesture The gesture event
230 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
233 * Touch event callback on stage.
234 * If stage is touched, hide showing indicator image
236 * @param[in] touchEvent The touch data
238 void OnStageTouch(const Dali::TouchData& touchData);
241 * Connect to the indicator service
246 * Start the reconnection timer. This will run every second until we reconnect to
247 * the indicator service.
249 void StartReconnectionTimer();
252 * If connection failed, attempt to re-connect every second
254 bool OnReconnectTimer();
257 * Disconnect from the indicator service
262 * Handle Resize event
263 * @param[in] width The new width
264 * @param[in] height The new height
266 void Resize( int width, int height );
269 * Set the lock file info.
270 * @param[in] epcEvent Current ecore event.
272 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
275 * Set the shared indicator image info
276 * @param[in] epcEvent The event containing the image data
278 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
281 * Load the shared indicator image
282 * @param[in] epcEvent The event containing the image data
284 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
287 * Load the pixmap indicator image
288 * @param[in] epcEvent The event containing the image data
290 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
293 * Update top margin of the stage as much as indicator height
295 void UpdateTopMargin();
298 * Update the visibility and position of the actors
300 void UpdateVisibility();
303 * Inform dali that the indicator data has been updated.
304 * @param[in] bufferNumber The shared file number
306 void UpdateImageData( int bufferNumber );
309 * Lock the temporary file, Copy the shared image into IndicatorBuffer
310 * and then unlock the temporary file.
311 * Caller should ensure we are not writing image to gl texture.
312 * @param[in] bufferNumber The shared file number
314 bool CopyToBuffer( int bufferNumber );
317 * Create a new image for the indicator, and set up signal handling for it.
318 * @param[in] bufferNumber The shared file number
320 void CreateNewImage( int bufferNumber );
323 * Create a new pixmap image for the indicator, and set up signal handling for it.
325 void CreateNewPixmapImage();
328 * Indicator type has changed.
330 * @param[in] type The new indicator type
332 void OnIndicatorTypeChanged( Type type );
335 * Check whether the indicator could be visible or invisible
336 * @return true if indicator should be shown
338 bool CheckVisibleState();
341 * Show/Hide indicator actor with effect
342 * @param[in] duration how long need to show the indicator,
343 * if it equal to 0, hide the indicator
344 * if it less than 0, show always
346 void ShowIndicator( float duration );
349 * Showing timer callback
354 * Showing animation finished callback
355 * @param[in] animation
357 void OnAnimationFinished( Dali::Animation& animation );
359 private: // Implementation of ServerConnection::Observer
361 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
363 virtual void DataReceived( void* event );
366 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
368 virtual void ConnectionClosed();
373 * Clear shared file info
375 void ClearSharedFileInfo();
379 struct SharedFileInfo
389 mSharedFileNumber( 0 )
393 LockFile* mLock; ///< File lock for the shared file
394 SharedFile* mSharedFile; ///< Shared file
396 int mImageWidth; ///< Shared image width
397 int mImageHeight; ///< Shared image height
399 std::string mLockFileName; ///< Lock file name
400 std::string mSharedFileName; ///< Shared file name
401 int mSharedFileID; ///< Shared file ID
402 int mSharedFileNumber; ///< Shared file number
405 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
407 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
408 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
409 Dali::Shader mBackgroundShader; ///< Shader used for rendering the background
411 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
412 PixmapId mPixmap; ///< Pixmap including indicator content
413 Dali::Renderer mForegroundRenderer; ///< Renderer renders the indicator foreground
414 Dali::Renderer mBackgroundRenderer; ///< Renderer renders the indicator background
416 Dali::Actor mIndicatorContentActor; ///< Actor container for image and background
417 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
418 Dali::Actor mEventActor; ///< Handle to event
419 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
420 float mGestureDeltaY; ///< Checking how much panning moved
421 bool mGestureDetected; ///< Whether find the flick gesture
423 Dali::Timer mReconnectTimer; ///< Reconnection timer
424 SlotDelegate< Indicator > mConnection;
426 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
427 Indicator::State mState; ///< The connection state
430 ServerConnection* mServerConnection;
431 IndicatorInterface::Observer* mObserver; ///< Upload observer
433 Dali::Window::WindowOrientation mOrientation;
436 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
438 Dali::Timer mShowTimer; ///< Timer to show indicator
439 bool mIsShowing; ///< Whether the indicator is showing on the screen
440 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
442 bool mIsAnimationPlaying; ///< Whether the animation is playing
444 int mCurrentSharedFile; ///< Current shared file number
445 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info
447 BufferType mSharedBufferType; ///< Shared buffer type which is used to render indicator
449 struct Impl; ///< Contains Ecore specific information
450 Impl* mImpl; ///< Created on construction and destroyed on destruction.
452 bool mBackgroundVisible; ///< Indicate whether background is visible
453 int mTopMargin; ///< Top margin of the stage for indicator