cdb95920920088a39a98640f4b920af73d0c9593
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / src / processor-controller.cpp
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 // CLASS HEADER
19 #include "processor-controller.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/stage-devel.h>
23 #include <dali/integration-api/adaptor-framework/adaptor.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 ProcessorController::ProcessorController()
30 : mHandler(nullptr),
31   mPostHandler(nullptr),
32   mKeepRenderingApplied(false)
33 {
34   {
35     try
36     {
37       Dali::Adaptor::Get().RegisterProcessor(*this);
38       Dali::Adaptor::Get().RegisterProcessor(*this, true);
39     }
40     CALL_CATCH_EXCEPTION();
41   }
42 }
43
44 ProcessorController::~ProcessorController()
45 {
46   {
47     try
48     {
49       Dali::Adaptor::Get().UnregisterProcessor(*this);
50       Dali::Adaptor::Get().UnregisterProcessor(*this, true);
51     }
52     CALL_CATCH_EXCEPTION();
53   }
54 }
55
56 void ProcessorController::Process(bool postProcessor)
57 {
58   if(!postProcessor)
59   {
60     // We will ignore Awake events during Process running
61     mKeepRenderingApplied = true;
62     mHandler();
63   }
64   else
65   {
66     mPostHandler();
67     // Make awake events can be applied after PostProcess done.
68     mKeepRenderingApplied = false;
69   }
70 }
71
72 void ProcessorController::SetCallback(  ProcessorControllerProcessCallback callback )
73 {
74   mHandler = callback;
75 }
76
77 void ProcessorController::SetPostCallback(  ProcessorControllerProcessCallback postCallback )
78 {
79   mPostHandler = postCallback;
80 }
81
82 void ProcessorController::RemoveCallback(  ProcessorControllerProcessCallback callback )
83 {
84   mHandler = nullptr;
85 }
86 void ProcessorController::RemovePostCallback(  ProcessorControllerProcessCallback postCallback )
87 {
88   mPostHandler = nullptr;
89 }
90
91 void ProcessorController::Awake()
92 {
93   if(DALI_UNLIKELY(!mKeepRenderingApplied))
94   {
95     if(DALI_LIKELY(Dali::Stage::IsInstalled()))
96     {
97       auto stage = Dali::Stage::GetCurrent();
98       stage.KeepRendering(0.0f);
99       mKeepRenderingApplied = true;
100     }
101   }
102 }
103
104 // ProcessorController Bindings
105 SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_new_ProcessorController() {
106
107   ProcessorController *result = 0 ;
108
109   {
110     try {
111       result = (ProcessorController *)new ProcessorController();
112     } CALL_CATCH_EXCEPTION(0);
113   }
114
115   return (void *)result;
116 }
117
118 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_ProcessorController(void * jarg1) {
119
120   ProcessorController * arg1 = (ProcessorController *)jarg1;
121   {
122     try {
123       delete arg1;
124     } CALL_CATCH_EXCEPTION();
125   }
126 }
127
128 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_ProcessorController_SetCallback( void* jarg1, ProcessorController::ProcessorControllerProcessCallback callback )
129 {
130   ProcessorController* processorController = (ProcessorController *) jarg1;
131
132   if( processorController )
133   {
134     processorController->SetCallback( callback );
135   }
136 }
137
138 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_ProcessorController_SetPostCallback( void* jarg1, ProcessorController::ProcessorControllerProcessCallback callback )
139 {
140   ProcessorController* processorController = (ProcessorController *) jarg1;
141
142   if( processorController )
143   {
144     processorController->SetPostCallback( callback );
145   }
146 }
147
148 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_ProcessorController_RemoveCallback( void* jarg1, ProcessorController::ProcessorControllerProcessCallback callback )
149 {
150   ProcessorController* processorController = (ProcessorController *) jarg1;
151
152   if( processorController )
153   {
154     processorController->RemoveCallback( callback );
155   }
156 }
157
158 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_ProcessorController_RemovePostCallback( void* jarg1, ProcessorController::ProcessorControllerProcessCallback callback )
159 {
160   ProcessorController* processorController = (ProcessorController *) jarg1;
161
162   if( processorController )
163   {
164     processorController->RemovePostCallback( callback );
165   }
166 }
167
168 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_ProcessorController_Awake( void* jarg1 )
169 {
170   ProcessorController* processorController = (ProcessorController *) jarg1;
171
172   if( processorController )
173   {
174     processorController->Awake();
175   }
176 }
177
178 #ifdef __cplusplus
179 }
180 #endif