2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
23 /// An Adaptor object is used to initialize and control how Dali runs.
25 /// It provides the lifecycle interface that allows the application
26 /// writer to provide their own main loop and other platform related
29 /// The Adaptor class provides a means for initialising the resources required by the Dali::Core.
31 /// When dealing with platform events, the application writer must ensure that DALi is called in a
32 /// thread-safe manner.
34 /// As soon as the Adaptor class is created and started, the application writer can initialise their
35 /// view objects straight away or as required by the main loop they intend to use (there is no
36 /// need to wait for an initialize signal as per the Tizen.NUI.Application class).
39 public class Adaptor : global::System.IDisposable
41 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
42 /// <summary>swigCMemOwn.</summary>
43 /// <since_tizen> 3 </since_tizen>
44 protected bool swigCMemOwn;
46 internal Adaptor(global::System.IntPtr cPtr, bool cMemoryOwn)
48 swigCMemOwn = cMemoryOwn;
49 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
52 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Adaptor obj)
54 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
57 //A Flag to check who called Dispose(). (By User or DisposeQueue)
58 private bool isDisposeQueued = false;
60 /// A Flat to check if it is already disposed.
62 /// <since_tizen> 3 </since_tizen>
63 protected bool disposed = false;
68 /// <since_tizen> 3 </since_tizen>
73 isDisposeQueued = true;
74 DisposeQueue.Instance.Add(this);
78 /// <since_tizen> 4 </since_tizen>
81 //Throw excpetion if Dispose() is called in separate thread.
82 if (!Window.IsInstalled())
84 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
89 Dispose(DisposeTypes.Implicit);
93 Dispose(DisposeTypes.Explicit);
94 System.GC.SuppressFinalize(this);
101 /// <since_tizen> 3 </since_tizen>
102 protected virtual void Dispose(DisposeTypes type)
109 if (type == DisposeTypes.Explicit)
112 //Release your own managed resources here.
113 //You should release all of your own disposable objects here.
117 //Release your own unmanaged resources here.
118 //You should not access any managed member here except static instance.
119 //because the execution order of Finalizes is non-deterministic.
121 if (swigCPtr.Handle != global::System.IntPtr.Zero)
124 NDalicManualPINVOKE.delete_Adaptor(swigCPtr);
125 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
131 internal static Adaptor GetAdaptorFromPtr(global::System.IntPtr cPtr)
133 Adaptor ret = new Adaptor(cPtr, false);
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138 internal static Adaptor New(Window window)
140 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_0(Window.getCPtr(window)), false);
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 internal static Adaptor New(Window window, SWIGTYPE_p_Configuration__ContextLoss configuration)
147 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_1(Window.getCPtr(window), SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration)), false);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
154 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_2(Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface)), false);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface, SWIGTYPE_p_Configuration__ContextLoss configuration)
161 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);
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167 /// Starts the adaptor.
169 internal void Start()
171 NDalicManualPINVOKE.Adaptor_Start(swigCPtr);
172 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176 /// Pauses the adaptor.
178 internal void Pause()
180 NDalicManualPINVOKE.Adaptor_Pause(swigCPtr);
181 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185 /// Resumes the adaptor, if previously paused.
187 /// <remarks>If the adaptor is not paused, this does not do anything.</remarks>
188 internal void Resume()
190 NDalicManualPINVOKE.Adaptor_Resume(swigCPtr);
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195 /// Stops the adaptor.
199 NDalicManualPINVOKE.Adaptor_Stop(swigCPtr);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
205 bool ret = NDalicManualPINVOKE.Adaptor_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210 internal void RemoveIdle(SWIGTYPE_p_Dali__CallbackBase callback)
212 NDalicManualPINVOKE.Adaptor_RemoveIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 internal void ReplaceSurface(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
218 NDalicManualPINVOKE.Adaptor_ReplaceSurface(swigCPtr, Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface));
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222 internal SWIGTYPE_p_Dali__RenderSurface GetSurface()
224 SWIGTYPE_p_Dali__RenderSurface ret = new SWIGTYPE_p_Dali__RenderSurface(NDalicManualPINVOKE.Adaptor_GetSurface(swigCPtr), false);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 internal Any GetNativeWindowHandle()
231 Any ret = new Any(NDalicManualPINVOKE.Adaptor_GetNativeWindowHandle(swigCPtr), true);
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// Releases any locks the surface may hold.
240 /// For example, after compositing an offscreen surface, use this method to allow rendering to continue.
242 internal void ReleaseSurfaceLock()
244 NDalicManualPINVOKE.Adaptor_ReleaseSurfaceLock(swigCPtr);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 /// Sets the number of frames per render.
251 /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
253 /// Suggest this is a power of two:
254 /// 1 - render each vsync frame.
255 /// 2 - render every other vsync frame.
256 /// 4 - render every fourth vsync frame.
257 /// 8 - render every eighth vsync frame.
259 internal void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
261 NDalicManualPINVOKE.Adaptor_SetRenderRefreshRate(swigCPtr, numberOfVSyncsPerRender);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// Sets whether the frame count per render is managed using the hardware vsync or manually timed.
268 /// <param name="useHardware">True if the hardware vsync should be used.</param>
269 internal void SetUseHardwareVSync(bool useHardware)
271 NDalicManualPINVOKE.Adaptor_SetUseHardwareVSync(swigCPtr, useHardware);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 private static readonly Adaptor instance = Adaptor.Get();
277 internal static Adaptor Get()
279 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_Get(), false);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 /// Returns a reference to the instance of the adaptor used by the current thread.
287 /// <remarks>The adaptor has been initialized. This is only valid in the main thread.</remarks>
288 /// <since_tizen> 4 </since_tizen>
289 public static Adaptor Instance
298 /// Checks whether the adaptor is available.
300 /// <returns>True if it is available, false otherwise.</returns>
301 internal static bool IsAvailable()
303 bool ret = NDalicManualPINVOKE.Adaptor_IsAvailable();
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 /// Calls this method to notify DALi when a scene is created and initialized.
310 /// Notify the adaptor that the scene has been created.
312 internal void NotifySceneCreated()
314 NDalicManualPINVOKE.Adaptor_NotifySceneCreated(swigCPtr);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 /// Calls this method to notify DALi when the system language changes.
321 /// Use this only when not using Dali::Application. As the application is created, using the
322 /// application will automatically receive notification of the language change.
323 /// When Dali::Application is not used, the application developer should
324 /// use app-core to receive the language change notifications and should update DALi
325 /// by calling this method.
327 internal void NotifyLanguageChanged()
329 NDalicManualPINVOKE.Adaptor_NotifyLanguageChanged(swigCPtr);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Sets the minimum distance in pixels that the fingers must move towards or away from each other in order to trigger a pinch gesture.
336 /// <param name="distance">The minimum pinch distance in pixels.</param>
337 internal void SetMinimumPinchDistance(float distance)
339 NDalicManualPINVOKE.Adaptor_SetMinimumPinchDistance(swigCPtr, distance);
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 internal void FeedTouchPoint(TouchPoint point, int timeStamp)
345 NDalicManualPINVOKE.Adaptor_FeedTouchPoint(swigCPtr, TouchPoint.getCPtr(point), timeStamp);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350 /// Feeds a wheel event to the adaptor.
352 /// <param name="wheelEvent">The wheel event.</param>
353 /// <since_tizen> 4 </since_tizen>
354 public void FeedWheelEvent(Wheel wheelEvent)
356 NDalicManualPINVOKE.Adaptor_FeedWheelEvent(swigCPtr, Wheel.getCPtr(wheelEvent));
357 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 /// Feeds a key event to the adaptor.
363 /// <param name="keyEvent">The key event holding the key information.</param>
364 /// <since_tizen> 4 </since_tizen>
365 public void FeedKeyEvent(Key keyEvent)
367 NDalicManualPINVOKE.Adaptor_FeedKeyEvent(swigCPtr, Key.getCPtr(keyEvent));
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 /// Notifies core that the scene has been created.
374 internal void SceneCreated()
376 NDalicManualPINVOKE.Adaptor_SceneCreated(swigCPtr);
377 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 internal void SetViewMode(ViewMode viewMode)
382 NDalicManualPINVOKE.Adaptor_SetViewMode(swigCPtr, (int)viewMode);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 /// Sets the stereo base (eye separation) for stereoscopic 3D.
388 /// The stereo base is the distance in millimetres between the eyes. Typical values are
389 /// between 50mm and 70mm. The default value is 65mm.
391 /// <param name="stereoBase">The stereo base (eye separation) for stereoscopic 3D.</param>
392 internal void SetStereoBase(float stereoBase)
394 NDalicManualPINVOKE.Adaptor_SetStereoBase(swigCPtr, stereoBase);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 /// Event arguments that passed via the Resized signal.
401 internal class ResizedEventArgs : EventArgs
405 /// Adaptor - is the adaptor which has size changed.
407 /// <since_tizen> 4 </since_tizen>
408 public Adaptor Adaptor
415 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
416 private delegate void ResizedCallbackDelegate(IntPtr adaptor);
417 private EventHandler<ResizedEventArgs> _resizedEventHandler;
418 private ResizedCallbackDelegate _resizedCallbackDelegate;
421 /// An event for the Resized signal which can be used to subscribe or unsubscribe the event handler
422 /// provided by the user. The Resized signal is emitted when the size changes.<br />
424 internal event EventHandler<ResizedEventArgs> Resized
428 if (_resizedEventHandler == null)
430 _resizedCallbackDelegate = (OnResized);
431 ResizedSignal().Connect(_resizedCallbackDelegate);
433 _resizedEventHandler += value;
437 _resizedEventHandler -= value;
438 if (_resizedEventHandler == null && ResizedSignal().Empty() == false)
440 ResizedSignal().Disconnect(_resizedCallbackDelegate);
445 private void OnResized(IntPtr adaptor)
447 ResizedEventArgs e = new ResizedEventArgs();
450 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
453 if (_resizedEventHandler != null)
455 //here we send all data to user event handlers
456 _resizedEventHandler(this, e);
460 internal AdaptorSignalType ResizedSignal()
462 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_ResizedSignal(swigCPtr), false);
463 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 /// Event arguments that passed via the LanguageChanged signal.
470 internal class LanguageChangedEventArgs : EventArgs
474 /// Adaptor - is the adaptor which has language changed.
476 /// <since_tizen> 4 </since_tizen>
477 public Adaptor Adaptor
484 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
485 private delegate void LanguageChangedCallbackDelegate(IntPtr adaptor);
486 private EventHandler<LanguageChangedEventArgs> _languageChangedEventHandler;
487 private LanguageChangedCallbackDelegate _languageChangedCallbackDelegate;
490 /// An event for LanguageChanged signal which can be used to subscribe or unsubscribe the event handler
491 /// provided by the user. The LanguageChanged signal is emitted when the language changes.<br />
493 internal event EventHandler<LanguageChangedEventArgs> LanguageChanged
497 if (_languageChangedEventHandler == null)
499 _languageChangedCallbackDelegate = (OnLanguageChanged);
500 LanguageChangedSignal().Connect(_languageChangedCallbackDelegate);
502 _languageChangedEventHandler += value;
506 _languageChangedEventHandler -= value;
507 if (_languageChangedEventHandler == null && LanguageChangedSignal().Empty() == false)
509 LanguageChangedSignal().Disconnect(_languageChangedCallbackDelegate);
514 private void OnLanguageChanged(IntPtr adaptor)
516 LanguageChangedEventArgs e = new LanguageChangedEventArgs();
519 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
522 if (_languageChangedEventHandler != null)
524 //here we send all data to user event handlers
525 _languageChangedEventHandler(this, e);
529 internal AdaptorSignalType LanguageChangedSignal()
531 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_LanguageChangedSignal(swigCPtr), false);
532 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();