[NUI] Remove useless PostProcess callback (#4607)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Common / ProcessorController.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
18 using System.Runtime.InteropServices;
19 using System;
20 using System.ComponentModel;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// Singleton class.
26     /// ProcessorController handles ProcessorCallbacks those are requested to be called for each end of event process.
27     /// If there are works those required to be called after all of the event process for the efficiency, add them ProcessorController.
28     /// The calling order is not guaranteed but ProcessorCallbackes of LayoutController those are added by using AddLayoutControllerProcessor,
29     /// are called after ordinaly ProcessCallbacks added by AddProcessor.
30     ///
31     /// The added callbacks will be called every time of event tick.
32     /// If the callback is not be wanted to be called anymore, remove it.
33     /// </summary>
34     internal sealed class ProcessorController : Disposable
35     {
36         private static ProcessorController instance = null;
37
38         private ProcessorController() : this(Interop.ProcessorController.New(), true)
39         {
40         }
41
42         internal ProcessorController(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
43         {
44             processorCallback = new ProcessorEventHandler(Process);
45             Interop.ProcessorController.SetCallback(SwigCPtr, processorCallback);
46         }
47
48         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
49         internal delegate void ProcessorEventHandler();
50
51         private ProcessorEventHandler processorCallback = null;
52
53         public event EventHandler ProcessorOnceEvent;
54         public event EventHandler ProcessorEvent;
55         public event EventHandler LayoutProcessorEvent;
56
57         public static ProcessorController Instance
58         {
59             get
60             {
61                 if (instance == null)
62                 {
63                     instance = new ProcessorController();
64                 }
65                 return instance;
66             }
67         }
68
69         public void Process()
70         {
71             ProcessorOnceEvent?.Invoke(this, null);
72             ProcessorOnceEvent = null;
73             ProcessorEvent?.Invoke(this, null);
74             LayoutProcessorEvent?.Invoke(this, null);
75
76             // To avoid ImageView's properties mismatched problem,
77             // We need to invoke events now which attached during LayoutProcessor.
78             ProcessorOnceEvent?.Invoke(this, null);
79             ProcessorOnceEvent = null;
80         }
81
82         /// <summary>
83         /// Dispose ProcessorController.
84         /// </summary>
85         [EditorBrowsable(EditorBrowsableState.Never)]
86         protected override void Dispose(DisposeTypes type)
87         {
88             Interop.ProcessorController.RemoveCallback(SwigCPtr, processorCallback);
89             ProcessorOnceEvent = null;
90             ProcessorEvent = null;
91             LayoutProcessorEvent = null;
92             GC.SuppressFinalize(this);
93
94             base.Dispose(type);
95         }
96
97         /// <summary>
98         /// Awake ProcessorController.
99         /// It will call ProcessController.processorCallback and ProcessController.processorPostCallback hardly.
100         /// </summary>
101         /// <note>
102         /// When event thread is not in idle state, This function will be ignored.
103         /// </note>
104         [EditorBrowsable(EditorBrowsableState.Never)]
105         public void Awake()
106         {
107             Interop.ProcessorController.Awake(SwigCPtr);
108         }
109     } // class ProcessorController
110 } // namespace Tizen.NUI