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/actors/image-actor.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/events/pan-gesture.h>
25 #include <dali/public-api/events/pan-gesture-detector.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 event
221 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
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 event
238 void OnStageTouched(const Dali::TouchEvent& touchEvent);
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 * Inform dali that the indicator data has been updated.
294 * @param[in] bufferNumber The shared file number
296 void UpdateImageData( int bufferNumber );
299 * Lock the temporary file, Copy the shared image into IndicatorBuffer
300 * and then unlock the temporary file.
301 * Caller should ensure we are not writing image to gl texture.
302 * @param[in] bufferNumber The shared file number
304 bool CopyToBuffer( int bufferNumber );
307 * Create a new image for the indicator, and set up signal handling for it.
308 * @param[in] bufferNumber The shared file number
310 void CreateNewImage( int bufferNumber );
313 * Create a new pixmap image for the indicator, and set up signal handling for it.
315 void CreateNewPixmapImage();
318 * Indicator type has changed.
320 * @param[in] type The new indicator type
322 void OnIndicatorTypeChanged( Type type );
325 * Check whether the indicator could be visible or invisible
326 * @return true if indicator should be shown
328 bool CheckVisibleState();
331 * Show/Hide indicator actor with effect
332 * @param[in] duration how long need to show the indicator,
333 * if it equal to 0, hide the indicator
334 * if it less than 0, show always
336 void ShowIndicator( float duration );
339 * Showing timer callback
344 * Showing animation finished callback
345 * @param[in] animation
347 void OnAnimationFinished( Dali::Animation& animation );
349 private: // Implementation of ServerConnection::Observer
351 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
353 virtual void DataReceived( void* event );
356 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
358 virtual void ConnectionClosed();
363 * Clear shared file info
365 void ClearSharedFileInfo();
369 struct SharedFileInfo
379 mSharedFileNumber( 0 )
383 LockFile* mLock; ///< File lock for the shared file
384 SharedFile* mSharedFile; ///< Shared file
386 int mImageWidth; ///< Shared image width
387 int mImageHeight; ///< Shared image height
389 std::string mLockFileName; ///< Lock file name
390 std::string mSharedFileName; ///< Shared file name
391 int mSharedFileID; ///< Shared file ID
392 int mSharedFileNumber; ///< Shared file number
395 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
397 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
398 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
399 Dali::Shader mBackgroundShader; ///< Shader used for rendering the background
401 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
402 PixmapId mPixmap; ///< Pixmap including indicator content
403 Dali::Renderer mForegroundRenderer; ///< Renderer renders the indicator foreground
404 Dali::Renderer mBackgroundRenderer; ///< Renderer renders the indicator background
406 Dali::Actor mIndicatorContentActor; ///< Actor container for image and background
407 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
408 Dali::Actor mEventActor; ///< Handle to event
409 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
410 float mGestureDeltaY; ///< Checking how much panning moved
411 bool mGestureDetected; ///< Whether find the flick gesture
413 Dali::Timer mReconnectTimer; ///< Reconnection timer
414 SlotDelegate< Indicator > mConnection;
416 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
417 Indicator::State mState; ///< The connection state
420 ServerConnection* mServerConnection;
421 IndicatorInterface::Observer* mObserver; ///< Upload observer
423 Dali::Window::WindowOrientation mOrientation;
426 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
428 Dali::Timer mShowTimer; ///< Timer to show indicator
429 bool mIsShowing; ///< Whether the indicator is showing on the screen
430 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
432 bool mIsAnimationPlaying; ///< Whether the animation is playing
434 int mCurrentSharedFile; ///< Current shared file number
435 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info
437 BufferType mSharedBufferType; ///< Shared buffer type which is used to render indicator
439 struct Impl; ///< Contains Ecore specific information
440 Impl* mImpl; ///< Created on construction and destroyed on destruction.
442 bool mBackgroundVisible; ///< Indicate whether background is visible