1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 using System.Runtime.InteropServices;
22 /// An Adaptor object is used to initialize and control how Dali runs.
24 /// It provides the lifecycle interface that allows the application
25 /// writer to provide their own main loop and other platform related
28 /// The Adaptor class provides a means for initialising the resources required by the Dali::Core.
30 /// When dealing with platform events, the application writer must ensure that DALi is called in a
31 /// thread-safe manner.
33 /// As soon as the Adaptor class is created and started, the application writer can initialise their
34 /// view objects straight away or as required by the main loop they intend to use (there is no
35 /// need to wait for an initialize signal as per the Tizen.NUI.Application class).
38 public class Adaptor : global::System.IDisposable
40 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
41 protected bool swigCMemOwn;
43 internal Adaptor(global::System.IntPtr cPtr, bool cMemoryOwn)
45 swigCMemOwn = cMemoryOwn;
46 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
49 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Adaptor obj)
51 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
54 //A Flag to check who called Dispose(). (By User or DisposeQueue)
55 private bool isDisposeQueued = false;
56 //A Flat to check if it is already disposed.
57 protected bool disposed = false;
63 isDisposeQueued = true;
64 DisposeQueue.Instance.Add(this);
68 /// <since_tizen> 4 </since_tizen>
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
88 protected virtual void Dispose(DisposeTypes type)
95 if (type == DisposeTypes.Explicit)
98 //Release your own managed resources here.
99 //You should release all of your own disposable objects here.
103 //Release your own unmanaged resources here.
104 //You should not access any managed member here except static instance.
105 //because the execution order of Finalizes is non-deterministic.
107 if (swigCPtr.Handle != global::System.IntPtr.Zero)
110 NDalicManualPINVOKE.delete_Adaptor(swigCPtr);
111 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
117 internal static Adaptor GetAdaptorFromPtr(global::System.IntPtr cPtr)
119 Adaptor ret = new Adaptor(cPtr, false);
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 internal static Adaptor New(Window window)
126 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_0(Window.getCPtr(window)), false);
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 internal static Adaptor New(Window window, SWIGTYPE_p_Configuration__ContextLoss configuration)
133 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_1(Window.getCPtr(window), SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration)), false);
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
140 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_2(Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface)), false);
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface, SWIGTYPE_p_Configuration__ContextLoss configuration)
147 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_3(Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface), SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration)), false);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153 /// Starts the adaptor.
155 internal void Start()
157 NDalicManualPINVOKE.Adaptor_Start(swigCPtr);
158 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 /// Pauses the adaptor.
164 internal void Pause()
166 NDalicManualPINVOKE.Adaptor_Pause(swigCPtr);
167 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171 /// Resumes the adaptor, if previously paused.
173 /// <remarks>If the adaptor is not paused, this does not do anything.</remarks>
174 internal void Resume()
176 NDalicManualPINVOKE.Adaptor_Resume(swigCPtr);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181 /// Stops the adaptor.
185 NDalicManualPINVOKE.Adaptor_Stop(swigCPtr);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
191 bool ret = NDalicManualPINVOKE.Adaptor_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
192 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 internal void RemoveIdle(SWIGTYPE_p_Dali__CallbackBase callback)
198 NDalicManualPINVOKE.Adaptor_RemoveIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202 internal void ReplaceSurface(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
204 NDalicManualPINVOKE.Adaptor_ReplaceSurface(swigCPtr, Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface));
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208 internal SWIGTYPE_p_Dali__RenderSurface GetSurface()
210 SWIGTYPE_p_Dali__RenderSurface ret = new SWIGTYPE_p_Dali__RenderSurface(NDalicManualPINVOKE.Adaptor_GetSurface(swigCPtr), false);
211 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 internal Any GetNativeWindowHandle()
217 Any ret = new Any(NDalicManualPINVOKE.Adaptor_GetNativeWindowHandle(swigCPtr), true);
218 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 /// Releases any locks the surface may hold.
226 /// For example, after compositing an offscreen surface, use this method to allow rendering to continue.
228 internal void ReleaseSurfaceLock()
230 NDalicManualPINVOKE.Adaptor_ReleaseSurfaceLock(swigCPtr);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 /// Sets the number of frames per render.
237 /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
239 /// Suggest this is a power of two:
240 /// 1 - render each vsync frame.
241 /// 2 - render every other vsync frame.
242 /// 4 - render every fourth vsync frame.
243 /// 8 - render every eighth vsync frame.
245 internal void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
247 NDalicManualPINVOKE.Adaptor_SetRenderRefreshRate(swigCPtr, numberOfVSyncsPerRender);
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 /// Sets whether the frame count per render is managed using the hardware vsync or manually timed.
254 /// <param name="useHardware">True if the hardware vsync should be used.</param>
255 internal void SetUseHardwareVSync(bool useHardware)
257 NDalicManualPINVOKE.Adaptor_SetUseHardwareVSync(swigCPtr, useHardware);
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 private static readonly Adaptor instance = Adaptor.Get();
263 internal static Adaptor Get()
265 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_Get(), false);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 /// Returns a reference to the instance of the adaptor used by the current thread.
273 /// <remarks>The adaptor has been initialized. This is only valid in the main thread.</remarks>
274 /// <since_tizen> 4 </since_tizen>
275 public static Adaptor Instance
284 /// Checks whether the adaptor is available.
286 /// <returns>True if it is available, false otherwise.</returns>
287 internal static bool IsAvailable()
289 bool ret = NDalicManualPINVOKE.Adaptor_IsAvailable();
290 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 /// Calls this method to notify DALi when a scene is created and initialized.
296 /// Notify the adaptor that the scene has been created.
298 internal void NotifySceneCreated()
300 NDalicManualPINVOKE.Adaptor_NotifySceneCreated(swigCPtr);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 /// Calls this method to notify DALi when the system language changes.
307 /// Use this only when not using Dali::Application. As the application is created, using the
308 /// application will automatically receive notification of the language change.
309 /// When Dali::Application is not used, the application developer should
310 /// use app-core to receive the language change notifications and should update DALi
311 /// by calling this method.
313 internal void NotifyLanguageChanged()
315 NDalicManualPINVOKE.Adaptor_NotifyLanguageChanged(swigCPtr);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Sets the minimum distance in pixels that the fingers must move towards or away from each other in order to trigger a pinch gesture.
322 /// <param name="distance">The minimum pinch distance in pixels.</param>
323 internal void SetMinimumPinchDistance(float distance)
325 NDalicManualPINVOKE.Adaptor_SetMinimumPinchDistance(swigCPtr, distance);
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 internal void FeedTouchPoint(TouchPoint point, int timeStamp)
331 NDalicManualPINVOKE.Adaptor_FeedTouchPoint(swigCPtr, TouchPoint.getCPtr(point), timeStamp);
332 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 /// Feeds a wheel event to the adaptor.
338 /// <param name="wheelEvent">The wheel event.</param>
339 /// <since_tizen> 4 </since_tizen>
340 public void FeedWheelEvent(Wheel wheelEvent)
342 NDalicManualPINVOKE.Adaptor_FeedWheelEvent(swigCPtr, Wheel.getCPtr(wheelEvent));
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 /// Feeds a key event to the adaptor.
349 /// <param name="keyEvent">The key event holding the key information.</param>
350 /// <since_tizen> 4 </since_tizen>
351 public void FeedKeyEvent(Key keyEvent)
353 NDalicManualPINVOKE.Adaptor_FeedKeyEvent(swigCPtr, Key.getCPtr(keyEvent));
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 /// Notifies core that the scene has been created.
360 internal void SceneCreated()
362 NDalicManualPINVOKE.Adaptor_SceneCreated(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366 internal void SetViewMode(ViewMode viewMode)
368 NDalicManualPINVOKE.Adaptor_SetViewMode(swigCPtr, (int)viewMode);
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 /// Sets the stereo base (eye separation) for stereoscopic 3D.
374 /// The stereo base is the distance in millimetres between the eyes. Typical values are
375 /// between 50mm and 70mm. The default value is 65mm.
377 /// <param name="stereoBase">The stereo base (eye separation) for stereoscopic 3D.</param>
378 internal void SetStereoBase(float stereoBase)
380 NDalicManualPINVOKE.Adaptor_SetStereoBase(swigCPtr, stereoBase);
381 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
385 /// Event arguments that passed via the Resized signal.
387 internal class ResizedEventArgs : EventArgs
391 /// Adaptor - is the adaptor which has size changed.
393 /// <since_tizen> 4 </since_tizen>
394 public Adaptor Adaptor
401 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
402 private delegate void ResizedCallbackDelegate(IntPtr adaptor);
403 private EventHandler<ResizedEventArgs> _resizedEventHandler;
404 private ResizedCallbackDelegate _resizedCallbackDelegate;
407 /// An event for the Resized signal which can be used to subscribe or unsubscribe the event handler
408 /// provided by the user. The Resized signal is emitted when the size changes.<br>
410 internal event EventHandler<ResizedEventArgs> Resized
414 if (_resizedEventHandler == null)
416 _resizedCallbackDelegate = (OnResized);
417 ResizedSignal().Connect(_resizedCallbackDelegate);
419 _resizedEventHandler += value;
423 _resizedEventHandler -= value;
424 if (_resizedEventHandler == null && ResizedSignal().Empty() == false)
426 ResizedSignal().Disconnect(_resizedCallbackDelegate);
431 private void OnResized(IntPtr adaptor)
433 ResizedEventArgs e = new ResizedEventArgs();
436 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
439 if (_resizedEventHandler != null)
441 //here we send all data to user event handlers
442 _resizedEventHandler(this, e);
446 internal AdaptorSignalType ResizedSignal()
448 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_ResizedSignal(swigCPtr), false);
449 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454 /// Event arguments that passed via the LanguageChanged signal.
456 internal class LanguageChangedEventArgs : EventArgs
460 /// Adaptor - is the adaptor which has language changed.
462 /// <since_tizen> 4 </since_tizen>
463 public Adaptor Adaptor
470 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
471 private delegate void LanguageChangedCallbackDelegate(IntPtr adaptor);
472 private EventHandler<LanguageChangedEventArgs> _languageChangedEventHandler;
473 private LanguageChangedCallbackDelegate _languageChangedCallbackDelegate;
476 /// An event for LanguageChanged signal which can be used to subscribe or unsubscribe the event handler
477 /// provided by the user. The LanguageChanged signal is emitted when the language changes.<br>
479 internal event EventHandler<LanguageChangedEventArgs> LanguageChanged
483 if (_languageChangedEventHandler == null)
485 _languageChangedCallbackDelegate = (OnLanguageChanged);
486 LanguageChangedSignal().Connect(_languageChangedCallbackDelegate);
488 _languageChangedEventHandler += value;
492 _languageChangedEventHandler -= value;
493 if (_languageChangedEventHandler == null && LanguageChangedSignal().Empty() == false)
495 LanguageChangedSignal().Disconnect(_languageChangedCallbackDelegate);
500 private void OnLanguageChanged(IntPtr adaptor)
502 LanguageChangedEventArgs e = new LanguageChangedEventArgs();
505 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
508 if (_languageChangedEventHandler != null)
510 //here we send all data to user event handlers
511 _languageChangedEventHandler(this, e);
515 internal AdaptorSignalType LanguageChangedSignal()
517 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_LanguageChangedSignal(swigCPtr), false);
518 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();