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/rendering/renderer.h>
28 #include <base/interfaces/indicator-interface.h>
29 #include <indicator-buffer.h>
30 #include <ecore-server-connection.h>
31 #include <shared-file.h>
48 typedef unsigned int PixmapId;
51 * The Indicator class connects to the indicator server, and gets and draws the indicator
52 * for the given orientation.
54 class Indicator : public ConnectionTracker, public ServerConnection::Observer, public IndicatorInterface
65 * copied from ecore_evas_extn_engine.h
69 BUFFER_TYPE_SHM = 0, ///< shared memory-based buffer backend
70 BUFFER_TYPE_DRI2_PIXMAP, ///< dri2 pixmap-based buffer backend
71 BUFFER_TYPE_EVASGL_PIXMAP, ///< pixmap backend for Evas GL only (DEPRECATED)
72 BUFFER_TYPE_GL_PIXMAP, ///< double buffered GL pixmap backend
77 * Class to encapsulate lock file
83 * Constructor. open lock file
85 LockFile(const std::string filename);
93 * Grab an exclusive lock on this file
94 * @return true if the lock succeeded, false if it failed
104 * Test if there is an error with the lock file, and clears
106 * @return true if an error was thrown
108 bool RetrieveAndClearErrorStatus();
111 std::string mFilename;
117 * Class to ensure lock/unlock through object destruction
123 * Constructor - creates a lock on the lockfile
124 * @param[in] lockFile The lockfile to use
126 ScopedLock( LockFile* lockFile );
129 * Destructor - removes the lock (if any) on the lockfile
134 * Method to test if the locking succeeded
135 * @return TRUE if locked
140 LockFile* mLockFile; ///< The lock file to use
141 bool mLocked; ///< Whether the lock succeeded
145 public: // Dali::Internal::Adaptor::IndicicatorInterface
147 * @copydoc Dali::Internal::IndicatorInterface::IndicatorInterface
149 Indicator( Adaptor* adaptor,
150 Dali::Window::WindowOrientation orientation,
151 IndicatorInterface::Observer* observer );
154 * @copydoc Dali::Internal::IndicatorInterface::~IndicatorInterface
156 virtual ~Indicator();
159 virtual void SetAdaptor(Adaptor* adaptor);
162 * @copydoc Dali::Internal::IndicatorInterface::GetActor
164 virtual Dali::Actor GetActor();
167 * @copydoc Dali::Internal::IndicatorInterface::Open
169 virtual void Open( Dali::Window::WindowOrientation orientation );
172 * @copydoc Dali::Internal::IndicatorInterface::Close
174 virtual void Close();
177 * @copydoc Dali::Internal::IndicatorInterface::SetOpacityMode
179 virtual void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
182 * @copydoc Dali::Internal::IndicatorInterface::SetVisible
184 virtual void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
187 * @copydoc Dali::Internal::IndicatorInterface::IsConnected
189 virtual bool IsConnected();
192 * @copydoc Dali::Internal::IndicatorInterface::SendMessage
194 virtual bool SendMessage( int messageDomain, int messageId, const void *data, int size );
198 * Initialize the indicator actors
203 * Constructs the renderers used for the background
205 Dali::Geometry CreateBackgroundGeometry();
208 * Set the texture to be rendered as indicator foreground
209 * @param[in] texture The foreground texture.
211 void SetForegroundImage( Dali::Texture texture );
214 * Touch event callback.
215 * It should pass the valid touch event to indicator server
217 * @param[in] indicator The indicator actor that was touched
218 * @param[in] touchEvent The touch event
220 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
223 * Pan gesture callback.
224 * It finds flick down gesture to show hidden indicator image
226 * @param[in] actor The actor for gesture
227 * @param[in] gesture The gesture event
229 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
232 * Touch event callback on stage.
233 * If stage is touched, hide showing indicator image
235 * @param[in] touchEvent The touch event
237 void OnStageTouched(const Dali::TouchEvent& touchEvent);
240 * Connect to the indicator service
245 * Start the reconnection timer. This will run every second until we reconnect to
246 * the indicator service.
248 void StartReconnectionTimer();
251 * If connection failed, attempt to re-connect every second
253 bool OnReconnectTimer();
256 * Disconnect from the indicator service
261 * Handle Resize event
262 * @param[in] width The new width
263 * @param[in] height The new height
265 void Resize( int width, int height );
268 * Set the lock file info.
269 * @param[in] epcEvent Current ecore event.
271 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
274 * Set the shared indicator image info
275 * @param[in] epcEvent The event containing the image data
277 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
280 * Load the shared indicator image
281 * @param[in] epcEvent The event containing the image data
283 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
286 * Load the pixmap indicator image
287 * @param[in] epcEvent The event containing the image data
289 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
292 * Update the visibility and position of the actors
294 void UpdateVisibility();
297 * Inform dali that the indicator data has been updated.
298 * @param[in] bufferNumber The shared file number
300 void UpdateImageData( int bufferNumber );
303 * Lock the temporary file, Copy the shared image into IndicatorBuffer
304 * and then unlock the temporary file.
305 * Caller should ensure we are not writing image to gl texture.
306 * @param[in] bufferNumber The shared file number
308 bool CopyToBuffer( int bufferNumber );
311 * Create a new image for the indicator, and set up signal handling for it.
312 * @param[in] bufferNumber The shared file number
314 void CreateNewImage( int bufferNumber );
317 * Create a new pixmap image for the indicator, and set up signal handling for it.
319 void CreateNewPixmapImage();
322 * Indicator type has changed.
324 * @param[in] type The new indicator type
326 void OnIndicatorTypeChanged( Type type );
329 * Check whether the indicator could be visible or invisible
330 * @return true if indicator should be shown
332 bool CheckVisibleState();
335 * Show/Hide indicator actor with effect
336 * @param[in] duration how long need to show the indicator,
337 * if it equal to 0, hide the indicator
338 * if it less than 0, show always
340 void ShowIndicator( float duration );
343 * Showing timer callback
348 * Showing animation finished callback
349 * @param[in] animation
351 void OnAnimationFinished( Dali::Animation& animation );
353 private: // Implementation of ServerConnection::Observer
355 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
357 virtual void DataReceived( void* event );
360 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
362 virtual void ConnectionClosed();
367 * Clear shared file info
369 void ClearSharedFileInfo();
373 struct SharedFileInfo
383 mSharedFileNumber( 0 )
387 LockFile* mLock; ///< File lock for the shared file
388 SharedFile* mSharedFile; ///< Shared file
390 int mImageWidth; ///< Shared image width
391 int mImageHeight; ///< Shared image height
393 std::string mLockFileName; ///< Lock file name
394 std::string mSharedFileName; ///< Shared file name
395 int mSharedFileID; ///< Shared file ID
396 int mSharedFileNumber; ///< Shared file number
399 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
401 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
402 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
403 Dali::Shader mBackgroundShader; ///< Shader used for rendering the background
405 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
406 PixmapId mPixmap; ///< Pixmap including indicator content
407 Dali::Renderer mForegroundRenderer; ///< Renderer renders the indicator foreground
408 Dali::Renderer mBackgroundRenderer; ///< Renderer renders the indicator background
410 Dali::Actor mIndicatorContentActor; ///< Actor container for image and background
411 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
412 Dali::Actor mEventActor; ///< Handle to event
413 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
414 float mGestureDeltaY; ///< Checking how much panning moved
415 bool mGestureDetected; ///< Whether find the flick gesture
417 Dali::Timer mReconnectTimer; ///< Reconnection timer
418 SlotDelegate< Indicator > mConnection;
420 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
421 Indicator::State mState; ///< The connection state
424 ServerConnection* mServerConnection;
425 IndicatorInterface::Observer* mObserver; ///< Upload observer
427 Dali::Window::WindowOrientation mOrientation;
430 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
432 Dali::Timer mShowTimer; ///< Timer to show indicator
433 bool mIsShowing; ///< Whether the indicator is showing on the screen
434 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
436 bool mIsAnimationPlaying; ///< Whether the animation is playing
438 int mCurrentSharedFile; ///< Current shared file number
439 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info
441 BufferType mSharedBufferType; ///< Shared buffer type which is used to render indicator
443 struct Impl; ///< Contains Ecore specific information
444 Impl* mImpl; ///< Created on construction and destroyed on destruction.
446 bool mBackgroundVisible; ///< Indicate whether background is visible