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 top margin of the stage as much as indicator height
294 void UpdateTopMargin();
297 * Update the visibility and position of the actors
299 void UpdateVisibility();
302 * Inform dali that the indicator data has been updated.
303 * @param[in] bufferNumber The shared file number
305 void UpdateImageData( int bufferNumber );
308 * Lock the temporary file, Copy the shared image into IndicatorBuffer
309 * and then unlock the temporary file.
310 * Caller should ensure we are not writing image to gl texture.
311 * @param[in] bufferNumber The shared file number
313 bool CopyToBuffer( int bufferNumber );
316 * Create a new image for the indicator, and set up signal handling for it.
317 * @param[in] bufferNumber The shared file number
319 void CreateNewImage( int bufferNumber );
322 * Create a new pixmap image for the indicator, and set up signal handling for it.
324 void CreateNewPixmapImage();
327 * Indicator type has changed.
329 * @param[in] type The new indicator type
331 void OnIndicatorTypeChanged( Type type );
334 * Check whether the indicator could be visible or invisible
335 * @return true if indicator should be shown
337 bool CheckVisibleState();
340 * Show/Hide indicator actor with effect
341 * @param[in] duration how long need to show the indicator,
342 * if it equal to 0, hide the indicator
343 * if it less than 0, show always
345 void ShowIndicator( float duration );
348 * Showing timer callback
353 * Showing animation finished callback
354 * @param[in] animation
356 void OnAnimationFinished( Dali::Animation& animation );
358 private: // Implementation of ServerConnection::Observer
360 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
362 virtual void DataReceived( void* event );
365 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
367 virtual void ConnectionClosed();
372 * Clear shared file info
374 void ClearSharedFileInfo();
378 struct SharedFileInfo
388 mSharedFileNumber( 0 )
392 LockFile* mLock; ///< File lock for the shared file
393 SharedFile* mSharedFile; ///< Shared file
395 int mImageWidth; ///< Shared image width
396 int mImageHeight; ///< Shared image height
398 std::string mLockFileName; ///< Lock file name
399 std::string mSharedFileName; ///< Shared file name
400 int mSharedFileID; ///< Shared file ID
401 int mSharedFileNumber; ///< Shared file number
404 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
406 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
407 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
408 Dali::Shader mBackgroundShader; ///< Shader used for rendering the background
410 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
411 PixmapId mPixmap; ///< Pixmap including indicator content
412 Dali::Renderer mForegroundRenderer; ///< Renderer renders the indicator foreground
413 Dali::Renderer mBackgroundRenderer; ///< Renderer renders the indicator background
415 Dali::Actor mIndicatorContentActor; ///< Actor container for image and background
416 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
417 Dali::Actor mEventActor; ///< Handle to event
418 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
419 float mGestureDeltaY; ///< Checking how much panning moved
420 bool mGestureDetected; ///< Whether find the flick gesture
422 Dali::Timer mReconnectTimer; ///< Reconnection timer
423 SlotDelegate< Indicator > mConnection;
425 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
426 Indicator::State mState; ///< The connection state
429 ServerConnection* mServerConnection;
430 IndicatorInterface::Observer* mObserver; ///< Upload observer
432 Dali::Window::WindowOrientation mOrientation;
435 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
437 Dali::Timer mShowTimer; ///< Timer to show indicator
438 bool mIsShowing; ///< Whether the indicator is showing on the screen
439 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
441 bool mIsAnimationPlaying; ///< Whether the animation is playing
443 int mCurrentSharedFile; ///< Current shared file number
444 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info
446 BufferType mSharedBufferType; ///< Shared buffer type which is used to render indicator
448 struct Impl; ///< Contains Ecore specific information
449 Impl* mImpl; ///< Created on construction and destroyed on destruction.
451 bool mBackgroundVisible; ///< Indicate whether background is visible
452 int mTopMargin; ///< Top margin of the stage for indicator