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>
26 #include <dali/public-api/images/image.h>
27 #include <dali/public-api/object/any.h>
30 #include <base/interfaces/indicator-interface.h>
31 #include <native-image-source.h>
32 #include <indicator-buffer.h>
33 #include <ecore-server-connection.h>
34 #include <shared-file.h>
51 typedef unsigned int PixmapId;
54 * The Indicator class connects to the indicator server, and gets and draws the indicator
55 * for the given orientation.
57 class Indicator : public ConnectionTracker, public ServerConnection::Observer, public IndicatorInterface
68 * copied from ecore_evas_extn_engine.h
72 BUFFER_TYPE_SHM = 0, ///< shared memory-based buffer backend
73 BUFFER_TYPE_DRI2_PIXMAP, ///< dri2 pixmap-based buffer backend
74 BUFFER_TYPE_EVASGL_PIXMAP, ///< pixmap backend for Evas GL only (DEPRECATED)
75 BUFFER_TYPE_GL_PIXMAP, ///< double buffered GL pixmap backend
80 * Class to encapsulate lock file
86 * Constructor. open lock file
88 LockFile(const std::string filename);
96 * Grab an exclusive lock on this file
97 * @return true if the lock succeeded, false if it failed
107 * Test if there is an error with the lock file, and clears
109 * @return true if an error was thrown
111 bool RetrieveAndClearErrorStatus();
114 std::string mFilename;
120 * Class to ensure lock/unlock through object destruction
126 * Constructor - creates a lock on the lockfile
127 * @param[in] lockFile The lockfile to use
129 ScopedLock( LockFile* lockFile );
132 * Destructor - removes the lock (if any) on the lockfile
137 * Method to test if the locking succeeded
138 * @return TRUE if locked
143 LockFile* mLockFile; ///< The lock file to use
144 bool mLocked; ///< Whether the lock succeeded
148 public: // Dali::Internal::Adaptor::IndicicatorInterface
150 * @copydoc Dali::Internal::IndicatorInterface::IndicatorInterface
152 Indicator( Adaptor* adaptor,
153 Dali::Window::WindowOrientation orientation,
154 IndicatorInterface::Observer* observer );
157 * @copydoc Dali::Internal::IndicatorInterface::~IndicatorInterface
159 virtual ~Indicator();
162 virtual void SetAdaptor(Adaptor* adaptor);
165 * @copydoc Dali::Internal::IndicatorInterface::GetActor
167 virtual Dali::Actor GetActor();
170 * @copydoc Dali::Internal::IndicatorInterface::Open
172 virtual void Open( Dali::Window::WindowOrientation orientation );
175 * @copydoc Dali::Internal::IndicatorInterface::Close
177 virtual void Close();
180 * @copydoc Dali::Internal::IndicatorInterface::SetOpacityMode
182 virtual void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
185 * @copydoc Dali::Internal::IndicatorInterface::SetVisible
187 virtual void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
190 * @copydoc Dali::Internal::IndicatorInterface::IsConnected
192 virtual bool IsConnected();
195 * @copydoc Dali::Internal::IndicatorInterface::SendMessage
197 virtual bool SendMessage( int messageDomain, int messageId, const void *data, int size );
200 * Update native indicator image
201 * @param[in] source Native indicator image source
203 void UpdateIndicatorImage( Dali::Any source );
207 * Initialize the indicator actors
212 * Constructs the renderers used for the background
214 Dali::Geometry CreateBackgroundGeometry();
217 * Set the texture to be rendered as indicator foreground
218 * @param[in] texture The foreground texture.
220 void SetForegroundImage( Dali::Texture texture );
223 * Set the texture to be rendered as indicator foreground
224 * @param[in] image The foreground image.
226 void SetForegroundNativeImage( Dali::Image image );
229 * Touch event callback.
230 * It should pass the valid touch event to indicator server
232 * @param[in] indicator The indicator actor that was touched
233 * @param[in] touchEvent The touch event
235 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
238 * Pan gesture callback.
239 * It finds flick down gesture to show hidden indicator image
241 * @param[in] actor The actor for gesture
242 * @param[in] gesture The gesture event
244 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
247 * Touch event callback on stage.
248 * If stage is touched, hide showing indicator image
250 * @param[in] touchEvent The touch event
252 void OnStageTouched(const Dali::TouchEvent& touchEvent);
255 * Connect to the indicator service
260 * Start the reconnection timer. This will run every second until we reconnect to
261 * the indicator service.
263 void StartReconnectionTimer();
266 * If connection failed, attempt to re-connect every second
268 bool OnReconnectTimer();
271 * Disconnect from the indicator service
276 * Handle Resize event
277 * @param[in] width The new width
278 * @param[in] height The new height
280 void Resize( int width, int height );
283 * Set the lock file info.
284 * @param[in] epcEvent Current ecore event.
286 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
289 * Set the shared indicator image info
290 * @param[in] epcEvent The event containing the image data
292 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
295 * Load the shared indicator image
296 * @param[in] epcEvent The event containing the image data
298 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
301 * Load the pixmap indicator image
302 * @param[in] epcEvent The event containing the image data
304 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
307 * Update top margin of the stage as much as indicator height
309 void UpdateTopMargin();
312 * Setup native indicator image
313 * @param[in] epcEvent The event containing the image data information
315 void SetupNativeIndicatorImage( Ecore_Ipc_Event_Server_Data *epcEvent );
318 * Update the visibility and position of the actors
320 void UpdateVisibility();
323 * Inform dali that the indicator data has been updated.
324 * @param[in] bufferNumber The shared file number
326 void UpdateImageData( int bufferNumber );
329 * Lock the temporary file, Copy the shared image into IndicatorBuffer
330 * and then unlock the temporary file.
331 * Caller should ensure we are not writing image to gl texture.
332 * @param[in] bufferNumber The shared file number
334 bool CopyToBuffer( int bufferNumber );
337 * Create a new image for the indicator, and set up signal handling for it.
338 * @param[in] bufferNumber The shared file number
340 void CreateNewImage( int bufferNumber );
343 * Create a new pixmap image for the indicator, and set up signal handling for it.
345 void CreateNewPixmapImage();
348 * Indicator type has changed.
350 * @param[in] type The new indicator type
352 void OnIndicatorTypeChanged( Type type );
355 * Check whether the indicator could be visible or invisible
356 * @return true if indicator should be shown
358 bool CheckVisibleState();
361 * Show/Hide indicator actor with effect
362 * @param[in] duration how long need to show the indicator,
363 * if it equal to 0, hide the indicator
364 * if it less than 0, show always
366 void ShowIndicator( float duration );
369 * Showing timer callback
374 * Showing animation finished callback
375 * @param[in] animation
377 void OnAnimationFinished( Dali::Animation& animation );
380 * Set up native indicator image
382 void SetupNativeIndicatorImage();
384 private: // Implementation of ServerConnection::Observer
386 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
388 virtual void DataReceived( void* event );
391 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
393 virtual void ConnectionClosed();
398 * Clear shared file info
400 void ClearSharedFileInfo();
404 struct SharedFileInfo
414 mSharedFileNumber( 0 )
418 LockFile* mLock; ///< File lock for the shared file
419 SharedFile* mSharedFile; ///< Shared file
421 int mImageWidth; ///< Shared image width
422 int mImageHeight; ///< Shared image height
424 std::string mLockFileName; ///< Lock file name
425 std::string mSharedFileName; ///< Shared file name
426 int mSharedFileID; ///< Shared file ID
427 int mSharedFileNumber; ///< Shared file number
430 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
432 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
433 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
434 Dali::Shader mBackgroundShader; ///< Shader used for rendering the background
436 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
437 PixmapId mPixmap; ///< Pixmap including indicator content
438 Dali::NativeImageSourcePtr mNativeImageSource;
439 Dali::Renderer mForegroundRenderer; ///< Renderer renders the indicator foreground
440 Dali::Renderer mBackgroundRenderer; ///< Renderer renders the indicator background
442 Dali::Actor mIndicatorContentActor; ///< Actor container for image and background
443 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
444 Dali::Actor mEventActor; ///< Handle to event
445 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
446 float mGestureDeltaY; ///< Checking how much panning moved
447 bool mGestureDetected; ///< Whether find the flick gesture
449 Dali::Timer mReconnectTimer; ///< Reconnection timer
450 SlotDelegate< Indicator > mConnection;
452 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
453 Indicator::State mState; ///< The connection state
456 ServerConnection* mServerConnection;
457 IndicatorInterface::Observer* mObserver; ///< Upload observer
459 Dali::Window::WindowOrientation mOrientation;
462 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
464 Dali::Timer mShowTimer; ///< Timer to show indicator
465 bool mIsShowing; ///< Whether the indicator is showing on the screen
466 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
468 bool mIsAnimationPlaying; ///< Whether the animation is playing
470 int mCurrentSharedFile; ///< Current shared file number
471 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info
473 BufferType mSharedBufferType; ///< Shared buffer type which is used to render indicator
475 struct Impl; ///< Contains Ecore specific information
476 Impl* mImpl; ///< Created on construction and destroyed on destruction.
478 bool mBackgroundVisible; ///< Indicate whether background is visible
479 int mTopMargin; ///< Top margin of the stage for indicator