[NUI] Remove RenderTask itself from the RenderTaskList when disposed
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Common / RenderTask.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20
21 namespace Tizen.NUI
22 {
23     /// This will be released at Tizen.NET API Level 6, so currently this would be used as inhouse API.
24     [EditorBrowsable(EditorBrowsableState.Never)]
25     public class RenderTask : Animatable
26     {
27         internal RenderTask(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
28         {
29         }
30
31         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
32         {
33             Interop.RenderTask.DeleteRenderTask(swigCPtr);
34         }
35
36
37         public static RenderTask GetRenderTaskFromPtr(global::System.IntPtr cPtr)
38         {
39             RenderTask ret = new RenderTask(cPtr, false);
40             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41             return ret;
42         }
43
44         protected override void Dispose(DisposeTypes type)
45         {
46             if (Disposed)
47             {
48                 return;
49             }
50
51             foreach (var window in Application.GetWindowList())
52             {
53                 window.GetRenderTaskList().RemoveTask(this);
54             }
55
56             base.Dispose(type);
57         }
58
59         internal class Property
60         {
61             internal static readonly int ViewportPosition = Interop.RenderTask.ViewportPositionGet();
62             internal static readonly int ViewportSize = Interop.RenderTask.ViewportSizeGet();
63             internal static readonly int ClearColor = Interop.RenderTask.ClearColorGet();
64             internal static readonly int RequiresSync = Interop.RenderTask.RequiresSyncGet();
65         }
66
67         internal static SWIGTYPE_p_f_r_Dali__Vector2__bool DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION
68         {
69             get
70             {
71                 global::System.IntPtr cPtr = Interop.RenderTask.DefaultScreenToFramebufferFunctionGet();
72                 SWIGTYPE_p_f_r_Dali__Vector2__bool ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_r_Dali__Vector2__bool(cPtr);
73                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74                 return ret;
75             }
76         }
77
78         internal static SWIGTYPE_p_f_r_Dali__Vector2__bool FULLSCREEN_FRAMEBUFFER_FUNCTION
79         {
80             get
81             {
82                 global::System.IntPtr cPtr = Interop.RenderTask.FullscreenFramebufferFunctionGet();
83                 SWIGTYPE_p_f_r_Dali__Vector2__bool ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_r_Dali__Vector2__bool(cPtr);
84                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85                 return ret;
86             }
87         }
88
89         public static bool DEFAULT_EXCLUSIVE
90         {
91             get
92             {
93                 bool ret = Interop.RenderTask.DefaultExclusiveGet();
94                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
95                 return ret;
96             }
97         }
98
99         public static bool DEFAULT_INPUT_ENABLED
100         {
101             get
102             {
103                 bool ret = Interop.RenderTask.DefaultInputEnabledGet();
104                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
105                 return ret;
106             }
107         }
108
109         public static Vector4 DEFAULT_CLEAR_COLOR
110         {
111             get
112             {
113                 global::System.IntPtr cPtr = Interop.RenderTask.DefaultClearColorGet();
114                 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
115                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
116                 return ret;
117             }
118         }
119
120         public static bool DEFAULT_CLEAR_ENABLED
121         {
122             get
123             {
124                 bool ret = Interop.RenderTask.DefaultClearEnabledGet();
125                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
126                 return ret;
127             }
128         }
129
130         public static bool DEFAULT_CULL_MODE
131         {
132             get
133             {
134                 bool ret = Interop.RenderTask.DefaultCullModeGet();
135                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
136                 return ret;
137             }
138         }
139
140         public static uint DEFAULT_REFRESH_RATE
141         {
142             get
143             {
144                 uint ret = Interop.RenderTask.DefaultRefreshRateGet();
145                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
146                 return ret;
147             }
148         }
149
150         public RenderTask() : this(Interop.RenderTask.NewRenderTask(), true)
151         {
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153         }
154
155         public static RenderTask DownCast(BaseHandle handle)
156         {
157             if (handle == null)
158             {
159                 throw new global::System.ArgumentNullException(nameof(handle));
160             }
161             RenderTask ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as RenderTask;
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163             return ret;
164         }
165
166         public RenderTask(RenderTask handle) : this(Interop.RenderTask.NewRenderTask(RenderTask.getCPtr(handle)), true)
167         {
168             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169         }
170
171         public RenderTask Assign(RenderTask rhs)
172         {
173             RenderTask ret = new RenderTask(Interop.RenderTask.Assign(SwigCPtr, RenderTask.getCPtr(rhs)), false);
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             return ret;
176         }
177
178         public void SetSourceView(View view)
179         {
180             Interop.RenderTask.SetSourceActor(SwigCPtr, View.getCPtr(view));
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182         }
183
184         public View GetSourceView()
185         {
186             View ret = new View(Interop.RenderTask.GetSourceActor(SwigCPtr), true);
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188             return ret;
189         }
190
191         public void SetExclusive(bool exclusive)
192         {
193             Interop.RenderTask.SetExclusive(SwigCPtr, exclusive);
194             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195         }
196
197         public bool IsExclusive()
198         {
199             bool ret = Interop.RenderTask.IsExclusive(SwigCPtr);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201             return ret;
202         }
203
204         public void SetInputEnabled(bool enabled)
205         {
206             Interop.RenderTask.SetInputEnabled(SwigCPtr, enabled);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208         }
209
210         public bool GetInputEnabled()
211         {
212             bool ret = Interop.RenderTask.GetInputEnabled(SwigCPtr);
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214             return ret;
215         }
216
217         [Obsolete("Do not use this. Use Tizen.NUI.Scene3D.Camera instead.")]
218         [EditorBrowsable(EditorBrowsableState.Never)]
219         public void SetCamera(Camera camera)
220         {
221             Interop.RenderTask.SetCameraActor(SwigCPtr, Camera.getCPtr(camera));
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223         }
224
225         [Obsolete("Do not use this. Use Tizen.NUI.Scene3D.Camera instead.")]
226         [EditorBrowsable(EditorBrowsableState.Never)]
227         public Camera GetCamera()
228         {
229             Camera ret = new Camera(Interop.RenderTask.GetCameraActor(SwigCPtr), true);
230             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231             return ret;
232         }
233
234         public void SetFrameBuffer(FrameBuffer frameBuffer)
235         {
236             Interop.RenderTask.SetFrameBuffer(SwigCPtr, FrameBuffer.getCPtr(frameBuffer));
237             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238         }
239
240         public FrameBuffer GetFrameBuffer()
241         {
242             FrameBuffer ret = new FrameBuffer(Interop.RenderTask.GetFrameBuffer(SwigCPtr), true);
243             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244             return ret;
245         }
246
247         internal void SetScreenToFrameBufferFunction(SWIGTYPE_p_f_r_Dali__Vector2__bool conversionFunction)
248         {
249             Interop.RenderTask.SetScreenToFrameBufferFunction(SwigCPtr, SWIGTYPE_p_f_r_Dali__Vector2__bool.getCPtr(conversionFunction));
250             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251         }
252
253         internal SWIGTYPE_p_f_r_Dali__Vector2__bool GetScreenToFrameBufferFunction()
254         {
255             global::System.IntPtr cPtr = Interop.RenderTask.GetScreenToFrameBufferFunction(SwigCPtr);
256             SWIGTYPE_p_f_r_Dali__Vector2__bool ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_r_Dali__Vector2__bool(cPtr);
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258             return ret;
259         }
260
261         public void SetScreenToFrameBufferMappingView(View mappingView)
262         {
263             Interop.RenderTask.SetScreenToFrameBufferMappingActor(SwigCPtr, View.getCPtr(mappingView));
264             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265         }
266
267         public View GetScreenToFrameBufferMappingView()
268         {
269             View ret = new View(Interop.RenderTask.GetScreenToFrameBufferMappingActor(SwigCPtr), true);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         public void SetViewportPosition(Vector2 position)
275         {
276             Interop.RenderTask.SetViewportPosition(SwigCPtr, Vector2.getCPtr(position));
277             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278         }
279
280         public Vector2 GetCurrentViewportPosition()
281         {
282             Vector2 ret = new Vector2(Interop.RenderTask.GetCurrentViewportPosition(SwigCPtr), true);
283             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284             return ret;
285         }
286
287         public void SetViewportSize(Vector2 size)
288         {
289             Interop.RenderTask.SetViewportSize(SwigCPtr, Vector2.getCPtr(size));
290             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291         }
292
293         public Vector2 GetCurrentViewportSize()
294         {
295             Vector2 ret = new Vector2(Interop.RenderTask.GetCurrentViewportSize(SwigCPtr), true);
296             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297             return ret;
298         }
299
300         public void SetViewport(Rectangle viewport)
301         {
302             Interop.RenderTask.SetViewport(SwigCPtr, Rectangle.getCPtr(viewport));
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304         }
305
306         public Rectangle GetViewport()
307         {
308             Rectangle ret = new Rectangle(Interop.RenderTask.GetViewport(SwigCPtr), true);
309             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310             return ret;
311         }
312
313         [Obsolete("This has been deprecated in API9 and will be removed in API11. Use ClearColor property instead.")]
314         public void SetClearColor(Vector4 color)
315         {
316             Interop.RenderTask.SetClearColor(SwigCPtr, Vector4.getCPtr(color));
317             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318         }
319
320         [Obsolete("This has been deprecated in API9 and will be removed in API11. Use ClearColor property instead.")]
321         public Vector4 GetClearColor()
322         {
323             Vector4 ret = new Vector4(Interop.RenderTask.GetClearColor(SwigCPtr), true);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             return ret;
326         }
327
328         public void SetClearEnabled(bool enabled)
329         {
330             Interop.RenderTask.SetClearEnabled(SwigCPtr, enabled);
331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332         }
333
334         public bool GetClearEnabled()
335         {
336             bool ret = Interop.RenderTask.GetClearEnabled(SwigCPtr);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             return ret;
339         }
340
341         public void SetCullMode(bool cullMode)
342         {
343             Interop.RenderTask.SetCullMode(SwigCPtr, cullMode);
344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345         }
346
347         public bool GetCullMode()
348         {
349             bool ret = Interop.RenderTask.GetCullMode(SwigCPtr);
350             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351             return ret;
352         }
353
354         public void SetRefreshRate(uint refreshRate)
355         {
356             Interop.RenderTask.SetRefreshRate(SwigCPtr, refreshRate);
357             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358         }
359
360         public uint GetRefreshRate()
361         {
362             uint ret = Interop.RenderTask.GetRefreshRate(SwigCPtr);
363             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364             return ret;
365         }
366
367         public bool WorldToViewport(Vector3 position, out float viewportX, out float viewportY)
368         {
369             bool ret = Interop.RenderTask.WorldToViewport(SwigCPtr, Vector3.getCPtr(position), out viewportX, out viewportY);
370             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371             return ret;
372         }
373
374         public bool ViewportToLocal(View view, float viewportX, float viewportY, out float localX, out float localY)
375         {
376             bool ret = Interop.RenderTask.ViewportToLocal(SwigCPtr, View.getCPtr(view), viewportX, viewportY, out localX, out localY);
377             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378             return ret;
379         }
380
381         internal RenderTaskSignal FinishedSignal()
382         {
383             RenderTaskSignal ret = new RenderTaskSignal(Interop.RenderTask.FinishedSignal(SwigCPtr), false);
384             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
385             return ret;
386         }
387
388         /// <since_tizen> 3 </since_tizen>
389         public enum RefreshRate
390         {
391             REFRESH_ONCE = 0,
392             REFRESH_ALWAYS = 1
393         }
394
395         public Vector2 ViewportPosition
396         {
397             get
398             {
399                 Vector2 retVal = new Vector2(0.0f, 0.0f);
400                 PropertyValue viewportPos = GetProperty(RenderTask.Property.ViewportPosition);
401                 viewportPos?.Get(retVal);
402                 viewportPos?.Dispose();
403                 return retVal;
404             }
405             set
406             {
407                 PropertyValue setVal = new Tizen.NUI.PropertyValue(value);
408                 SetProperty(RenderTask.Property.ViewportPosition, setVal);
409                 setVal?.Dispose();
410             }
411         }
412         public Vector2 ViewportSize
413         {
414             get
415             {
416                 Vector2 retVal = new Vector2(0.0f, 0.0f);
417                 PropertyValue viewportSize = GetProperty(RenderTask.Property.ViewportSize);
418                 viewportSize?.Get(retVal);
419                 viewportSize?.Dispose();
420                 return retVal;
421             }
422             set
423             {
424                 PropertyValue setVal = new Tizen.NUI.PropertyValue(value);
425                 SetProperty(RenderTask.Property.ViewportSize, setVal);
426                 setVal?.Dispose();
427             }
428         }
429         public Vector4 ClearColor
430         {
431             get
432             {
433                 Vector4 retVal = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
434                 PropertyValue clearColor = GetProperty(RenderTask.Property.ClearColor);
435                 clearColor?.Get(retVal);
436                 clearColor?.Dispose();
437                 return retVal;
438             }
439             set
440             {
441                 PropertyValue setVal = new Tizen.NUI.PropertyValue(value);
442                 SetProperty(RenderTask.Property.ClearColor, setVal);
443                 setVal?.Dispose();
444             }
445         }
446         public bool RequiresSync
447         {
448             get
449             {
450                 bool retVal = false;
451                 PropertyValue reqSync = GetProperty(RenderTask.Property.RequiresSync);
452                 reqSync?.Get(out retVal);
453                 reqSync?.Dispose();
454                 return retVal;
455             }
456             set
457             {
458                 PropertyValue setVal = new Tizen.NUI.PropertyValue(value);
459                 SetProperty(RenderTask.Property.RequiresSync, setVal);
460                 setVal?.Dispose();
461             }
462         }
463     }
464 }