1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_INDICATOR_IMPL_ECORE_WL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_INDICATOR_IMPL_ECORE_WL_H
5 * Copyright (c) 2018 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 <dali/internal/window-system/common/indicator-interface.h>
30 #include <dali/internal/window-system/common/indicator-buffer.h>
31 #include <dali/internal/window-system/common/ecore-server-connection.h>
32 #include <dali/internal/system/common/shared-file.h>
33 #include <dali/public-api/adaptor-framework/timer.h>
34 #include <dali/public-api/adaptor-framework/window.h>
46 * The Indicator class connects to the indicator server, and gets and draws the indicator
47 * for the given orientation.
49 class IndicatorEcoreWl : public ConnectionTracker, public ServerConnection::Observer, public IndicatorInterface
61 * Class to encapsulate lock file
67 * Constructor. open lock file
69 LockFile(const std::string filename);
77 * Grab an exclusive lock on this file
78 * @return true if the lock succeeded, false if it failed
88 * Test if there is an error with the lock file, and clears
90 * @return true if an error was thrown
92 bool RetrieveAndClearErrorStatus();
95 std::string mFilename;
101 * Class to ensure lock/unlock through object destruction
107 * Constructor - creates a lock on the lockfile
108 * @param[in] lockFile The lockfile to use
110 ScopedLock( LockFile* lockFile );
113 * Destructor - removes the lock (if any) on the lockfile
118 * Method to test if the locking succeeded
119 * @return TRUE if locked
124 LockFile* mLockFile; ///< The lock file to use
125 bool mLocked; ///< Whether the lock succeeded
129 public: // Dali::Internal::Adaptor::IndicicatorInterface
131 * @copydoc Dali::Internal::IndicatorInterface::IndicatorInterface
133 IndicatorEcoreWl( Adaptor* adaptor,
134 Dali::Window::WindowOrientation orientation,
135 IndicatorInterface::Observer* observer );
138 * @copydoc Dali::Internal::IndicatorInterface::~IndicatorInterface
140 virtual ~IndicatorEcoreWl();
144 * @copydoc Dali::Internal::IndicatorInterface::SetAdaptor
146 virtual void SetAdaptor(Adaptor* adaptor);
149 * @copydoc Dali::Internal::IndicatorInterface::GetActor
151 virtual Dali::Actor GetActor();
154 * @copydoc Dali::Internal::IndicatorInterface::Open
156 virtual void Open( Dali::Window::WindowOrientation orientation );
159 * @copydoc Dali::Internal::IndicatorInterface::Close
161 virtual void Close();
164 * @copydoc Dali::Internal::IndicatorInterface::SetOpacityMode
166 virtual void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
169 * @copydoc Dali::Internal::IndicatorInterface::SetVisible
171 virtual void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
174 * @copydoc Dali::Internal::IndicatorInterface::IsConnected
176 virtual bool IsConnected();
179 * @copydoc Dali::Internal::IndicatorInterface::SendMessage
181 virtual bool SendMessage( int messageDomain, int messageId, const void *data, int size );
185 * Initialize the indicator actors
190 * Constructs the renderers used for the background
192 Dali::Geometry CreateBackgroundGeometry();
195 * Set the texture to be rendered as indicator foreground
196 * @param[in] texture The foreground texture.
198 void SetForegroundImage( Dali::Texture texture );
201 * Touch event callback.
202 * It should pass the valid touch event to indicator server
204 * @param[in] indicator The indicator actor that was touched
205 * @param[in] touchEvent The touch data
207 bool OnTouch(Dali::Actor indicator, const Dali::TouchData& touchData);
210 * Pan gesture callback.
211 * It finds flick down gesture to show hidden indicator image
213 * @param[in] actor The actor for gesture
214 * @param[in] gesture The gesture event
216 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
219 * Touch event callback on stage.
220 * If stage is touched, hide showing indicator image
222 * @param[in] touchEvent The touch data
224 void OnStageTouch(const Dali::TouchData& touchData);
227 * Connect to the indicator service
232 * Start the reconnection timer. This will run every second until we reconnect to
233 * the indicator service.
235 void StartReconnectionTimer();
238 * If connection failed, attempt to re-connect every second
240 bool OnReconnectTimer();
243 * Disconnect from the indicator service
248 * Handle Resize event
249 * @param[in] width The new width
250 * @param[in] height The new height
252 void Resize( int width, int height );
255 * Set the lock file info.
256 * @param[in] epcEvent Current ecore event.
258 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
261 * Set the shared indicator image info
262 * @param[in] epcEvent The event containing the image data
264 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
267 * Load the shared indicator image
268 * @param[in] epcEvent The event containing the image data
270 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
273 * Update top margin of the stage as much as indicator height
275 void UpdateTopMargin();
278 * Update the visibility and position of the actors
280 void UpdateVisibility();
283 * Inform dali that the indicator data has been updated.
284 * @param[in] bufferNumber The shared file number
286 void UpdateImageData( int bufferNumber );
289 * Lock the temporary file, Copy the shared image into IndicatorBuffer
290 * and then unlock the temporary file.
291 * Caller should ensure we are not writing image to gl texture.
292 * @param[in] bufferNumber The shared file number
294 bool CopyToBuffer( int bufferNumber );
297 * Create a new image for the indicator, and set up signal handling for it.
298 * @param[in] bufferNumber The shared file number
300 void CreateNewImage( int bufferNumber );
303 * Indicator type has changed.
305 * @param[in] type The new indicator type
307 void OnIndicatorTypeChanged( Type type );
310 * Check whether the indicator could be visible or invisible
311 * @return true if indicator should be shown
313 bool CheckVisibleState();
316 * Show/Hide indicator actor with effect
317 * @param[in] duration how long need to show the indicator,
318 * if it equal to 0, hide the indicator
319 * if it less than 0, show always
321 void ShowIndicator( float duration );
324 * Showing timer callback
329 * Showing animation finished callback
330 * @param[in] animation
332 void OnAnimationFinished( Dali::Animation& animation );
334 private: // Implementation of ServerConnection::Observer
336 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
338 virtual void DataReceived( void* event );
341 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
343 virtual void ConnectionClosed();
348 * Clear shared file info
350 void ClearSharedFileInfo();
354 struct SharedFileInfo
364 mSharedFileNumber( 0 )
368 LockFile* mLock; ///< File lock for the shared file
369 SharedFile* mSharedFile; ///< Shared file
371 int mImageWidth; ///< Shared image width
372 int mImageHeight; ///< Shared image height
374 std::string mLockFileName; ///< Lock file name
375 std::string mSharedFileName; ///< Shared file name
376 int mSharedFileID; ///< Shared file ID
377 int mSharedFileNumber; ///< Shared file number
380 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
382 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
383 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
384 Dali::Shader mBackgroundShader; ///< Shader used for rendering the background
386 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
387 Dali::Renderer mForegroundRenderer; ///< Renderer renders the indicator foreground
388 Dali::Renderer mBackgroundRenderer; ///< Renderer renders the indicator background
390 Dali::Actor mIndicatorContentActor; ///< Actor container for image and background
391 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
392 Dali::Actor mEventActor; ///< Handle to event
393 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
395 Dali::Timer mReconnectTimer; ///< Reconnection timer
396 SlotDelegate< IndicatorEcoreWl > mConnection;
398 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
399 IndicatorEcoreWl::State mState; ///< The connection state
402 ServerConnection* mServerConnection;
403 IndicatorInterface::Observer* mObserver; ///< Upload observer
405 Dali::Window::WindowOrientation mOrientation;
408 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
410 Dali::Timer mShowTimer; ///< Timer to show indicator
411 bool mIsShowing; ///< Whether the indicator is showing on the screen
412 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
414 bool mIsAnimationPlaying; ///< Whether the animation is playing
416 int mCurrentSharedFile; ///< Current shared file number
417 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info
419 struct Impl; ///< Contains Ecore specific information
420 Impl* mImpl; ///< Created on construction and destroyed on destruction.
422 bool mBackgroundVisible; ///< Indicate whether background is visible
423 int mTopMargin; ///< Top margin of the stage for indicator
430 #endif // DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_INDICATOR_IMPL_ECORE_WL_H