1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Android Native Activity.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuAndroidNativeActivity.hpp"
25 #include "deMemory.h"
26 
27 DE_BEGIN_EXTERN_C
28 
onStartCallback(ANativeActivity * activity)29 static void onStartCallback (ANativeActivity* activity)
30 {
31 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onStart();
32 }
33 
onResumeCallback(ANativeActivity * activity)34 static void onResumeCallback (ANativeActivity* activity)
35 {
36 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onResume();
37 }
38 
onSaveInstanceStateCallback(ANativeActivity * activity,size_t * outSize)39 static void* onSaveInstanceStateCallback (ANativeActivity* activity, size_t* outSize)
40 {
41 	return static_cast<tcu::Android::NativeActivity*>(activity->instance)->onSaveInstanceState(outSize);
42 }
43 
onPauseCallback(ANativeActivity * activity)44 static void onPauseCallback (ANativeActivity* activity)
45 {
46 	return static_cast<tcu::Android::NativeActivity*>(activity->instance)->onPause();
47 }
48 
onStopCallback(ANativeActivity * activity)49 static void onStopCallback (ANativeActivity* activity)
50 {
51 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onStop();
52 }
53 
onDestroyCallback(ANativeActivity * activity)54 static void onDestroyCallback (ANativeActivity* activity)
55 {
56 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onDestroy();
57 }
58 
onWindowFocusChangedCallback(ANativeActivity * activity,int hasFocus)59 static void onWindowFocusChangedCallback (ANativeActivity* activity, int hasFocus)
60 {
61 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onWindowFocusChanged(hasFocus);
62 }
63 
onNativeWindowCreatedCallback(ANativeActivity * activity,ANativeWindow * window)64 static void onNativeWindowCreatedCallback (ANativeActivity* activity, ANativeWindow* window)
65 {
66 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onNativeWindowCreated(window);
67 }
68 
onNativeWindowResizedCallback(ANativeActivity * activity,ANativeWindow * window)69 static void onNativeWindowResizedCallback (ANativeActivity* activity, ANativeWindow* window)
70 {
71 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onNativeWindowResized(window);
72 }
73 
onNativeWindowRedrawNeededCallback(ANativeActivity * activity,ANativeWindow * window)74 static void onNativeWindowRedrawNeededCallback (ANativeActivity* activity, ANativeWindow* window)
75 {
76 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onNativeWindowRedrawNeeded(window);
77 }
78 
onNativeWindowDestroyedCallback(ANativeActivity * activity,ANativeWindow * window)79 static void onNativeWindowDestroyedCallback (ANativeActivity* activity, ANativeWindow* window)
80 {
81 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onNativeWindowDestroyed(window);
82 }
83 
onInputQueueCreatedCallback(ANativeActivity * activity,AInputQueue * queue)84 static void onInputQueueCreatedCallback (ANativeActivity* activity, AInputQueue* queue)
85 {
86 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onInputQueueCreated(queue);
87 }
88 
onInputQueueDestroyedCallback(ANativeActivity * activity,AInputQueue * queue)89 static void onInputQueueDestroyedCallback (ANativeActivity* activity, AInputQueue* queue)
90 {
91 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onInputQueueDestroyed(queue);
92 }
93 
onContentRectChangedCallback(ANativeActivity * activity,const ARect * rect)94 static void onContentRectChangedCallback (ANativeActivity* activity, const ARect* rect)
95 {
96 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onContentRectChanged(rect);
97 }
98 
onConfigurationChangedCallback(ANativeActivity * activity)99 static void onConfigurationChangedCallback (ANativeActivity* activity)
100 {
101 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onConfigurationChanged();
102 }
103 
onLowMemoryCallback(ANativeActivity * activity)104 static void onLowMemoryCallback (ANativeActivity* activity)
105 {
106 	static_cast<tcu::Android::NativeActivity*>(activity->instance)->onLowMemory();
107 }
108 
109 DE_END_EXTERN_C
110 
111 namespace tcu
112 {
113 namespace Android
114 {
115 
NativeActivity(ANativeActivity * activity)116 NativeActivity::NativeActivity (ANativeActivity* activity)
117 	: m_activity(activity)
118 {
119 	activity->instance								= (void*)this;
120 	activity->callbacks->onStart					= onStartCallback;
121 	activity->callbacks->onResume					= onResumeCallback;
122 	activity->callbacks->onSaveInstanceState		= onSaveInstanceStateCallback;
123 	activity->callbacks->onPause					= onPauseCallback;
124 	activity->callbacks->onStop						= onStopCallback;
125 	activity->callbacks->onDestroy					= onDestroyCallback;
126 	activity->callbacks->onWindowFocusChanged		= onWindowFocusChangedCallback;
127 	activity->callbacks->onNativeWindowCreated		= onNativeWindowCreatedCallback;
128 	activity->callbacks->onNativeWindowResized		= onNativeWindowResizedCallback;
129 	activity->callbacks->onNativeWindowRedrawNeeded	= onNativeWindowRedrawNeededCallback;
130 	activity->callbacks->onNativeWindowDestroyed	= onNativeWindowDestroyedCallback;
131 	activity->callbacks->onInputQueueCreated		= onInputQueueCreatedCallback;
132 	activity->callbacks->onInputQueueDestroyed		= onInputQueueDestroyedCallback;
133 	activity->callbacks->onContentRectChanged		= onContentRectChangedCallback;
134 	activity->callbacks->onConfigurationChanged		= onConfigurationChangedCallback;
135 	activity->callbacks->onLowMemory				= onLowMemoryCallback;
136 }
137 
~NativeActivity(void)138 NativeActivity::~NativeActivity (void)
139 {
140 }
141 
onStart(void)142 void NativeActivity::onStart (void)
143 {
144 }
145 
onResume(void)146 void NativeActivity::onResume (void)
147 {
148 }
149 
onSaveInstanceState(size_t * outSize)150 void* NativeActivity::onSaveInstanceState (size_t* outSize)
151 {
152 	*outSize = 0;
153 	return DE_NULL;
154 }
155 
onPause(void)156 void NativeActivity::onPause (void)
157 {
158 }
159 
onStop(void)160 void NativeActivity::onStop (void)
161 {
162 }
163 
onDestroy(void)164 void NativeActivity::onDestroy (void)
165 {
166 }
167 
onWindowFocusChanged(int hasFocus)168 void NativeActivity::onWindowFocusChanged (int hasFocus)
169 {
170 	DE_UNREF(hasFocus);
171 }
172 
onNativeWindowCreated(ANativeWindow * window)173 void NativeActivity::onNativeWindowCreated (ANativeWindow* window)
174 {
175 	DE_UNREF(window);
176 }
177 
onNativeWindowResized(ANativeWindow * window)178 void NativeActivity::onNativeWindowResized (ANativeWindow* window)
179 {
180 	DE_UNREF(window);
181 }
182 
onNativeWindowRedrawNeeded(ANativeWindow * window)183 void NativeActivity::onNativeWindowRedrawNeeded (ANativeWindow* window)
184 {
185 	DE_UNREF(window);
186 }
187 
onNativeWindowDestroyed(ANativeWindow * window)188 void NativeActivity::onNativeWindowDestroyed (ANativeWindow* window)
189 {
190 	DE_UNREF(window);
191 }
192 
onInputQueueCreated(AInputQueue * queue)193 void NativeActivity::onInputQueueCreated (AInputQueue* queue)
194 {
195 	DE_UNREF(queue);
196 }
197 
onInputQueueDestroyed(AInputQueue * queue)198 void NativeActivity::onInputQueueDestroyed (AInputQueue* queue)
199 {
200 	DE_UNREF(queue);
201 }
202 
onContentRectChanged(const ARect * rect)203 void NativeActivity::onContentRectChanged (const ARect* rect)
204 {
205 	DE_UNREF(rect);
206 }
207 
onConfigurationChanged(void)208 void NativeActivity::onConfigurationChanged (void)
209 {
210 }
211 
onLowMemory(void)212 void NativeActivity::onLowMemory (void)
213 {
214 }
215 
finish(void)216 void NativeActivity::finish (void)
217 {
218 	ANativeActivity_finish(m_activity);
219 }
220 
221 } // Android
222 } // tcu
223