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);
70 //Throw excpetion if Dispose() is called in separate thread.
71 if (!Window.IsInstalled())
73 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
78 Dispose(DisposeTypes.Implicit);
82 Dispose(DisposeTypes.Explicit);
83 System.GC.SuppressFinalize(this);
87 protected virtual void Dispose(DisposeTypes type)
94 if (type == DisposeTypes.Explicit)
97 //Release your own managed resources here.
98 //You should release all of your own disposable objects here.
102 //Release your own unmanaged resources here.
103 //You should not access any managed member here except static instance.
104 //because the execution order of Finalizes is non-deterministic.
106 if (swigCPtr.Handle != global::System.IntPtr.Zero)
109 NDalicManualPINVOKE.delete_Adaptor(swigCPtr);
110 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
116 internal static Adaptor GetAdaptorFromPtr(global::System.IntPtr cPtr)
118 Adaptor ret = new Adaptor(cPtr, false);
119 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123 internal static Adaptor New(Window window)
125 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_0(Window.getCPtr(window)), false);
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130 internal static Adaptor New(Window window, SWIGTYPE_p_Configuration__ContextLoss configuration)
132 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_1(Window.getCPtr(window), SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration)), false);
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
139 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_New__SWIG_2(Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface)), false);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 internal static Adaptor New(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface, SWIGTYPE_p_Configuration__ContextLoss configuration)
146 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);
147 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 /// Starts the adaptor.
154 internal void Start()
156 NDalicManualPINVOKE.Adaptor_Start(swigCPtr);
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161 /// Pauses the adaptor.
163 internal void Pause()
165 NDalicManualPINVOKE.Adaptor_Pause(swigCPtr);
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170 /// Resumes the adaptor, if previously paused.
172 /// <remarks>If the adaptor is not paused, this does not do anything.</remarks>
173 internal void Resume()
175 NDalicManualPINVOKE.Adaptor_Resume(swigCPtr);
176 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// Stops the adaptor.
184 NDalicManualPINVOKE.Adaptor_Stop(swigCPtr);
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
190 bool ret = NDalicManualPINVOKE.Adaptor_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195 internal void RemoveIdle(SWIGTYPE_p_Dali__CallbackBase callback)
197 NDalicManualPINVOKE.Adaptor_RemoveIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201 internal void ReplaceSurface(Any nativeWindow, SWIGTYPE_p_Dali__RenderSurface surface)
203 NDalicManualPINVOKE.Adaptor_ReplaceSurface(swigCPtr, Any.getCPtr(nativeWindow), SWIGTYPE_p_Dali__RenderSurface.getCPtr(surface));
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 internal SWIGTYPE_p_Dali__RenderSurface GetSurface()
209 SWIGTYPE_p_Dali__RenderSurface ret = new SWIGTYPE_p_Dali__RenderSurface(NDalicManualPINVOKE.Adaptor_GetSurface(swigCPtr), false);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214 internal Any GetNativeWindowHandle()
216 Any ret = new Any(NDalicManualPINVOKE.Adaptor_GetNativeWindowHandle(swigCPtr), true);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222 /// Releases any locks the surface may hold.
225 /// For example, after compositing an offscreen surface, use this method to allow rendering to continue.
227 internal void ReleaseSurfaceLock()
229 NDalicManualPINVOKE.Adaptor_ReleaseSurfaceLock(swigCPtr);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 /// Sets the number of frames per render.
236 /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
238 /// Suggest this is a power of two:
239 /// 1 - render each vsync frame.
240 /// 2 - render every other vsync frame.
241 /// 4 - render every fourth vsync frame.
242 /// 8 - render every eighth vsync frame.
244 internal void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
246 NDalicManualPINVOKE.Adaptor_SetRenderRefreshRate(swigCPtr, numberOfVSyncsPerRender);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 /// Sets whether the frame count per render is managed using the hardware vsync or manually timed.
253 /// <param name="useHardware">True if the hardware vsync should be used.</param>
254 internal void SetUseHardwareVSync(bool useHardware)
256 NDalicManualPINVOKE.Adaptor_SetUseHardwareVSync(swigCPtr, useHardware);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 private static readonly Adaptor instance = Adaptor.Get();
262 internal static Adaptor Get()
264 Adaptor ret = new Adaptor(NDalicManualPINVOKE.Adaptor_Get(), false);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 /// Returns a reference to the instance of the adaptor used by the current thread.
272 /// <remarks>The adaptor has been initialized. This is only valid in the main thread.</remarks>
273 public static Adaptor Instance
282 /// Checks whether the adaptor is available.
284 /// <returns>True if it is available, false otherwise.</returns>
285 internal static bool IsAvailable()
287 bool ret = NDalicManualPINVOKE.Adaptor_IsAvailable();
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 /// Calls this method to notify DALi when a scene is created and initialized.
294 /// Notify the adaptor that the scene has been created.
296 internal void NotifySceneCreated()
298 NDalicManualPINVOKE.Adaptor_NotifySceneCreated(swigCPtr);
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 /// Calls this method to notify DALi when the system language changes.
305 /// Use this only when not using Dali::Application. As the application is created, using the
306 /// application will automatically receive notification of the language change.
307 /// When Dali::Application is not used, the application developer should
308 /// use app-core to receive the language change notifications and should update DALi
309 /// by calling this method.
311 internal void NotifyLanguageChanged()
313 NDalicManualPINVOKE.Adaptor_NotifyLanguageChanged(swigCPtr);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 /// Sets the minimum distance in pixels that the fingers must move towards or away from each other in order to trigger a pinch gesture.
320 /// <param name="distance">The minimum pinch distance in pixels.</param>
321 internal void SetMinimumPinchDistance(float distance)
323 NDalicManualPINVOKE.Adaptor_SetMinimumPinchDistance(swigCPtr, distance);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 internal void FeedTouchPoint(TouchPoint point, int timeStamp)
329 NDalicManualPINVOKE.Adaptor_FeedTouchPoint(swigCPtr, TouchPoint.getCPtr(point), timeStamp);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Feeds a wheel event to the adaptor.
336 /// <param name="wheelEvent">The wheel event.</param>
337 public void FeedWheelEvent(Wheel wheelEvent)
339 NDalicManualPINVOKE.Adaptor_FeedWheelEvent(swigCPtr, Wheel.getCPtr(wheelEvent));
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// Feeds a key event to the adaptor.
346 /// <param name="keyEvent">The key event holding the key information.</param>
347 public void FeedKeyEvent(Key keyEvent)
349 NDalicManualPINVOKE.Adaptor_FeedKeyEvent(swigCPtr, Key.getCPtr(keyEvent));
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 /// Notifies core that the scene has been created.
356 internal void SceneCreated()
358 NDalicManualPINVOKE.Adaptor_SceneCreated(swigCPtr);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 internal void SetViewMode(ViewMode viewMode)
364 NDalicManualPINVOKE.Adaptor_SetViewMode(swigCPtr, (int)viewMode);
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 /// Sets the stereo base (eye separation) for stereoscopic 3D.
370 /// The stereo base is the distance in millimetres between the eyes. Typical values are
371 /// between 50mm and 70mm. The default value is 65mm.
373 /// <param name="stereoBase">The stereo base (eye separation) for stereoscopic 3D.</param>
374 internal void SetStereoBase(float stereoBase)
376 NDalicManualPINVOKE.Adaptor_SetStereoBase(swigCPtr, stereoBase);
377 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 /// Event arguments that passed via the Resized signal.
383 internal class ResizedEventArgs : EventArgs
387 /// Adaptor - is the adaptor which has size changed.
389 public Adaptor Adaptor
396 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
397 private delegate void ResizedCallbackDelegate(IntPtr adaptor);
398 private EventHandler<ResizedEventArgs> _resizedEventHandler;
399 private ResizedCallbackDelegate _resizedCallbackDelegate;
402 /// An event for the Resized signal which can be used to subscribe or unsubscribe the event handler
403 /// provided by the user. The Resized signal is emitted when the size changes.<br>
405 internal event EventHandler<ResizedEventArgs> Resized
409 if (_resizedEventHandler == null)
411 _resizedCallbackDelegate = (OnResized);
412 ResizedSignal().Connect(_resizedCallbackDelegate);
414 _resizedEventHandler += value;
418 _resizedEventHandler -= value;
419 if (_resizedEventHandler == null && ResizedSignal().Empty() == false)
421 ResizedSignal().Disconnect(_resizedCallbackDelegate);
426 private void OnResized(IntPtr adaptor)
428 ResizedEventArgs e = new ResizedEventArgs();
431 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
434 if (_resizedEventHandler != null)
436 //here we send all data to user event handlers
437 _resizedEventHandler(this, e);
441 internal AdaptorSignalType ResizedSignal()
443 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_ResizedSignal(swigCPtr), false);
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 /// Event arguments that passed via the LanguageChanged signal.
451 internal class LanguageChangedEventArgs : EventArgs
455 /// Adaptor - is the adaptor which has language changed.
457 public Adaptor Adaptor
464 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
465 private delegate void LanguageChangedCallbackDelegate(IntPtr adaptor);
466 private EventHandler<LanguageChangedEventArgs> _languageChangedEventHandler;
467 private LanguageChangedCallbackDelegate _languageChangedCallbackDelegate;
470 /// An event for LanguageChanged signal which can be used to subscribe or unsubscribe the event handler
471 /// provided by the user. The LanguageChanged signal is emitted when the language changes.<br>
473 internal event EventHandler<LanguageChangedEventArgs> LanguageChanged
477 if (_languageChangedEventHandler == null)
479 _languageChangedCallbackDelegate = (OnLanguageChanged);
480 LanguageChangedSignal().Connect(_languageChangedCallbackDelegate);
482 _languageChangedEventHandler += value;
486 _languageChangedEventHandler -= value;
487 if (_languageChangedEventHandler == null && LanguageChangedSignal().Empty() == false)
489 LanguageChangedSignal().Disconnect(_languageChangedCallbackDelegate);
494 private void OnLanguageChanged(IntPtr adaptor)
496 LanguageChangedEventArgs e = new LanguageChangedEventArgs();
499 e.Adaptor = Adaptor.GetAdaptorFromPtr(adaptor);
502 if (_languageChangedEventHandler != null)
504 //here we send all data to user event handlers
505 _languageChangedEventHandler(this, e);
509 internal AdaptorSignalType LanguageChangedSignal()
511 AdaptorSignalType ret = new AdaptorSignalType(NDalicManualPINVOKE.Adaptor_LanguageChangedSignal(swigCPtr), false);
512 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();