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 /// <since_tizen> 4 </since_tizen>
40 public class Adaptor : global::System.IDisposable
42 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43 /// <summary>swigCMemOwn.</summary>
44 /// <since_tizen> 4 </since_tizen>
45 protected bool swigCMemOwn;
47 internal Adaptor(global::System.IntPtr cPtr, bool cMemoryOwn)
49 swigCMemOwn = cMemoryOwn;
50 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
53 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Adaptor obj)
55 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
58 //A Flag to check who called Dispose(). (By User or DisposeQueue)
59 private bool isDisposeQueued = false;
61 /// A Flat to check if it is already disposed.
63 /// <since_tizen> 4 </since_tizen>
64 protected bool disposed = false;
69 /// <since_tizen> 3 </since_tizen>
74 isDisposeQueued = true;
75 DisposeQueue.Instance.Add(this);
79 /// <since_tizen> 4 </since_tizen>
82 //Throw excpetion if Dispose() is called in separate thread.
83 if (!Window.IsInstalled())
85 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
90 Dispose(DisposeTypes.Implicit);
94 Dispose(DisposeTypes.Explicit);
95 System.GC.SuppressFinalize(this);
102 /// <since_tizen> 4 </since_tizen>
103 protected virtual void Dispose(DisposeTypes type)
110 if (type == DisposeTypes.Explicit)
113 //Release your own managed resources here.
114 //You should release all of your own disposable objects here.
118 //Release your own unmanaged resources here.
119 //You should not access any managed member here except static instance.
120 //because the execution order of Finalizes is non-deterministic.
122 if (swigCPtr.Handle != global::System.IntPtr.Zero)
125 NDalicManualPINVOKE.delete_Adaptor(swigCPtr);
126 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
132 internal static Adaptor GetAdaptorFromPtr(global::System.IntPtr cPtr)
134 Adaptor ret = new Adaptor(cPtr, false);
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139 internal static Adaptor New(Window window)
141 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_0(Window.getCPtr(window)), false);
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146 internal static Adaptor New(Window window, SWIGTYPE_p_Configuration__ContextLoss configuration)
148 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_1(Window.getCPtr(window), SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration)), false);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
155 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_2(Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface)), false);
156 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface, SWIGTYPE_p_Configuration__ContextLoss configuration)
162 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);
163 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// Starts the adaptor.
170 internal void Start()
172 NDalicManualPINVOKE.Adaptor_Start(swigCPtr);
173 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177 /// Pauses the adaptor.
179 internal void Pause()
181 NDalicManualPINVOKE.Adaptor_Pause(swigCPtr);
182 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 /// Resumes the adaptor, if previously paused.
188 /// <remarks>If the adaptor is not paused, this does not do anything.</remarks>
189 internal void Resume()
191 NDalicManualPINVOKE.Adaptor_Resume(swigCPtr);
192 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 /// Stops the adaptor.
200 NDalicManualPINVOKE.Adaptor_Stop(swigCPtr);
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
206 bool ret = NDalicManualPINVOKE.Adaptor_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
207 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 internal void RemoveIdle(SWIGTYPE_p_Dali__CallbackBase callback)
213 NDalicManualPINVOKE.Adaptor_RemoveIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 internal void ReplaceSurface(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
219 NDalicManualPINVOKE.Adaptor_ReplaceSurface(swigCPtr, Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface));
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 internal SWIGTYPE_p_Dali__RenderSurface GetSurface()
225 SWIGTYPE_p_Dali__RenderSurface ret = new SWIGTYPE_p_Dali__RenderSurface(NDalicManualPINVOKE.Adaptor_GetSurface(swigCPtr), false);
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 internal Any GetNativeWindowHandle()
232 Any ret = new Any(NDalicManualPINVOKE.Adaptor_GetNativeWindowHandle(swigCPtr), true);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// Releases any locks the surface may hold.
241 /// For example, after compositing an offscreen surface, use this method to allow rendering to continue.
243 internal void ReleaseSurfaceLock()
245 NDalicManualPINVOKE.Adaptor_ReleaseSurfaceLock(swigCPtr);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// Sets the number of frames per render.
252 /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
254 /// Suggest this is a power of two:
255 /// 1 - render each vsync frame.
256 /// 2 - render every other vsync frame.
257 /// 4 - render every fourth vsync frame.
258 /// 8 - render every eighth vsync frame.
260 internal void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
262 NDalicManualPINVOKE.Adaptor_SetRenderRefreshRate(swigCPtr, numberOfVSyncsPerRender);
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 /// Sets whether the frame count per render is managed using the hardware vsync or manually timed.
269 /// <param name="useHardware">True if the hardware vsync should be used.</param>
270 internal void SetUseHardwareVSync(bool useHardware)
272 NDalicManualPINVOKE.Adaptor_SetUseHardwareVSync(swigCPtr, useHardware);
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 private static readonly Adaptor instance = Adaptor.Get();
278 internal static Adaptor Get()
280 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_Get(), false);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Returns a reference to the instance of the adaptor used by the current thread.
288 /// <remarks>The adaptor has been initialized. This is only valid in the main thread.</remarks>
289 /// <since_tizen> 4 </since_tizen>
290 public static Adaptor Instance
299 /// Checks whether the adaptor is available.
301 /// <returns>True if it is available, false otherwise.</returns>
302 internal static bool IsAvailable()
304 bool ret = NDalicManualPINVOKE.Adaptor_IsAvailable();
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 /// Calls this method to notify DALi when a scene is created and initialized.
311 /// Notify the adaptor that the scene has been created.
313 internal void NotifySceneCreated()
315 NDalicManualPINVOKE.Adaptor_NotifySceneCreated(swigCPtr);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Calls this method to notify DALi when the system language changes.
322 /// Use this only when not using Dali::Application. As the application is created, using the
323 /// application will automatically receive notification of the language change.
324 /// When Dali::Application is not used, the application developer should
325 /// use app-core to receive the language change notifications and should update DALi
326 /// by calling this method.
328 internal void NotifyLanguageChanged()
330 NDalicManualPINVOKE.Adaptor_NotifyLanguageChanged(swigCPtr);
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335 /// Sets the minimum distance in pixels that the fingers must move towards or away from each other in order to trigger a pinch gesture.
337 /// <param name="distance">The minimum pinch distance in pixels.</param>
338 internal void SetMinimumPinchDistance(float distance)
340 NDalicManualPINVOKE.Adaptor_SetMinimumPinchDistance(swigCPtr, distance);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 internal void FeedTouchPoint(TouchPoint point, int timeStamp)
346 NDalicManualPINVOKE.Adaptor_FeedTouchPoint(swigCPtr, TouchPoint.getCPtr(point), timeStamp);
347 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 /// Feeds a wheel event to the adaptor.
353 /// <param name="wheelEvent">The wheel event.</param>
354 /// <since_tizen> 4 </since_tizen>
355 public void FeedWheelEvent(Wheel wheelEvent)
357 NDalicManualPINVOKE.Adaptor_FeedWheelEvent(swigCPtr, Wheel.getCPtr(wheelEvent));
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 /// Feeds a key event to the adaptor.
364 /// <param name="keyEvent">The key event holding the key information.</param>
365 /// <since_tizen> 4 </since_tizen>
366 public void FeedKeyEvent(Key keyEvent)
368 NDalicManualPINVOKE.Adaptor_FeedKeyEvent(swigCPtr, Key.getCPtr(keyEvent));
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 /// Notifies core that the scene has been created.
375 internal void SceneCreated()
377 NDalicManualPINVOKE.Adaptor_SceneCreated(swigCPtr);
378 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 internal void SetViewMode(ViewMode viewMode)
383 NDalicManualPINVOKE.Adaptor_SetViewMode(swigCPtr, (int)viewMode);
384 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// Sets the stereo base (eye separation) for stereoscopic 3D.
389 /// The stereo base is the distance in millimetres between the eyes. Typical values are
390 /// between 50mm and 70mm. The default value is 65mm.
392 /// <param name="stereoBase">The stereo base (eye separation) for stereoscopic 3D.</param>
393 internal void SetStereoBase(float stereoBase)
395 NDalicManualPINVOKE.Adaptor_SetStereoBase(swigCPtr, stereoBase);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Event arguments that passed via the Resized signal.
402 internal class ResizedEventArgs : EventArgs
406 /// Adaptor - is the adaptor which has size changed.
408 /// <since_tizen> 4 </since_tizen>
409 public Adaptor Adaptor
416 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
417 private delegate void ResizedCallbackDelegate(IntPtr adaptor);
418 private EventHandler<ResizedEventArgs> _resizedEventHandler;
419 private ResizedCallbackDelegate _resizedCallbackDelegate;
422 /// An event for the Resized signal which can be used to subscribe or unsubscribe the event handler
423 /// provided by the user. The Resized signal is emitted when the size changes.<br />
425 internal event EventHandler<ResizedEventArgs> Resized
429 if (_resizedEventHandler == null)
431 _resizedCallbackDelegate = (OnResized);
432 ResizedSignal().Connect(_resizedCallbackDelegate);
434 _resizedEventHandler += value;
438 _resizedEventHandler -= value;
439 if (_resizedEventHandler == null && ResizedSignal().Empty() == false)
441 ResizedSignal().Disconnect(_resizedCallbackDelegate);
446 private void OnResized(IntPtr adaptor)
448 ResizedEventArgs e = new ResizedEventArgs();
451 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
454 if (_resizedEventHandler != null)
456 //here we send all data to user event handlers
457 _resizedEventHandler(this, e);
461 internal AdaptorSignalType ResizedSignal()
463 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_ResizedSignal(swigCPtr), false);
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 /// Event arguments that passed via the LanguageChanged signal.
471 internal class LanguageChangedEventArgs : EventArgs
475 /// Adaptor - is the adaptor which has language changed.
477 /// <since_tizen> 4 </since_tizen>
478 public Adaptor Adaptor
485 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
486 private delegate void LanguageChangedCallbackDelegate(IntPtr adaptor);
487 private EventHandler<LanguageChangedEventArgs> _languageChangedEventHandler;
488 private LanguageChangedCallbackDelegate _languageChangedCallbackDelegate;
491 /// An event for LanguageChanged signal which can be used to subscribe or unsubscribe the event handler
492 /// provided by the user. The LanguageChanged signal is emitted when the language changes.<br />
494 internal event EventHandler<LanguageChangedEventArgs> LanguageChanged
498 if (_languageChangedEventHandler == null)
500 _languageChangedCallbackDelegate = (OnLanguageChanged);
501 LanguageChangedSignal().Connect(_languageChangedCallbackDelegate);
503 _languageChangedEventHandler += value;
507 _languageChangedEventHandler -= value;
508 if (_languageChangedEventHandler == null && LanguageChangedSignal().Empty() == false)
510 LanguageChangedSignal().Disconnect(_languageChangedCallbackDelegate);
515 private void OnLanguageChanged(IntPtr adaptor)
517 LanguageChangedEventArgs e = new LanguageChangedEventArgs();
520 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
523 if (_languageChangedEventHandler != null)
525 //here we send all data to user event handlers
526 _languageChangedEventHandler(this, e);
530 internal AdaptorSignalType LanguageChangedSignal()
532 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_LanguageChangedSignal(swigCPtr), false);
533 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();