1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2016 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */ /*!
21 * \file
22 * \brief CTS Android Activity.
23 */ /*-------------------------------------------------------------------*/
24
25 #include "glcAndroidTestActivity.hpp"
26 #include "glcTestRunner.hpp"
27 #include "tcuAndroidAssets.hpp"
28 #include "tcuAndroidPlatform.hpp"
29 #include "tcuAndroidUtil.hpp"
30
31 #include <android/window.h>
32 #include <stdlib.h>
33
34 namespace glcts
35 {
36 namespace Android
37 {
38
39 using tcu::Android::Platform;
40 using tcu::Android::AssetArchive;
41 using tcu::Android::NativeActivity;
42
43 static const char* DEFAULT_LOG_PATH = "/sdcard";
44
getWaiverPath(ANativeActivity * activity)45 static std::string getWaiverPath(ANativeActivity* activity)
46 {
47 return tcu::Android::getIntentStringExtra(activity, "waivers");
48 }
49
getLogPath(ANativeActivity * activity)50 static std::string getLogPath(ANativeActivity* activity)
51 {
52 std::string path = tcu::Android::getIntentStringExtra(activity, "logdir");
53 return path.empty() ? std::string(DEFAULT_LOG_PATH) : path;
54 }
55
getFlags(ANativeActivity * activity)56 static deUint32 getFlags(ANativeActivity* activity)
57 {
58 deUint32 flags = 0;
59 if (tcu::Android::getIntentStringExtra(activity, "verbose") == "true")
60 flags |= TestRunner::VERBOSE_ALL;
61 else if (tcu::Android::getIntentStringExtra(activity, "summary") == "true")
62 flags |= TestRunner::PRINT_SUMMARY;
63 return flags;
64 }
65
TestThread(NativeActivity & activity,tcu::Android::AssetArchive & archive,const std::string & waiverPath,const std::string & logPath,glu::ApiType runType,deUint32 runFlags)66 TestThread::TestThread(NativeActivity& activity, tcu::Android::AssetArchive& archive, const std::string& waiverPath,
67 const std::string& logPath, glu::ApiType runType, deUint32 runFlags)
68 : RenderThread(activity)
69 , m_platform(activity)
70 , m_archive(archive)
71 , m_app(m_platform, m_archive, waiverPath.c_str(), logPath.c_str(), runType, runFlags)
72 , m_finished(false)
73 {
74 }
75
~TestThread(void)76 TestThread::~TestThread(void)
77 {
78 // \note m_testApp is managed by thread.
79 }
80
run(void)81 void TestThread::run(void)
82 {
83 RenderThread::run();
84 }
85
onWindowCreated(ANativeWindow * window)86 void TestThread::onWindowCreated(ANativeWindow* window)
87 {
88 m_platform.getWindowRegistry().addWindow(window);
89 }
90
onWindowDestroyed(ANativeWindow * window)91 void TestThread::onWindowDestroyed(ANativeWindow* window)
92 {
93 m_platform.getWindowRegistry().destroyWindow(window);
94 }
95
onWindowResized(ANativeWindow * window)96 void TestThread::onWindowResized(ANativeWindow* window)
97 {
98 // \todo [2013-05-12 pyry] Handle this in some sane way.
99 DE_UNREF(window);
100 tcu::print("Warning: Native window was resized, results may be undefined");
101 }
102
render(void)103 bool TestThread::render(void)
104 {
105 if (!m_finished)
106 m_finished = !m_app.iterate();
107 return !m_finished;
108 }
109
110 // TestActivity
111
TestActivity(ANativeActivity * activity,glu::ApiType runType)112 TestActivity::TestActivity(ANativeActivity* activity, glu::ApiType runType)
113 : RenderActivity(activity)
114 , m_archive(activity->assetManager)
115 , m_cmdLine(tcu::Android::getIntentStringExtra(activity, "cmdLine"))
116 , m_testThread(*this, m_archive, getWaiverPath(activity), getLogPath(activity), runType, getFlags(activity))
117 , m_started(false)
118 {
119 // Set initial orientation.
120 tcu::Android::setRequestedOrientation(getNativeActivity(),
121 tcu::Android::mapScreenRotation(m_cmdLine.getScreenRotation()));
122
123 // Set up window flags.
124 ANativeActivity_setWindowFlags(activity,
125 AWINDOW_FLAG_KEEP_SCREEN_ON | AWINDOW_FLAG_TURN_SCREEN_ON | AWINDOW_FLAG_FULLSCREEN |
126 AWINDOW_FLAG_SHOW_WHEN_LOCKED,
127 0);
128 }
129
~TestActivity(void)130 TestActivity::~TestActivity(void)
131 {
132 }
133
onStart(void)134 void TestActivity::onStart(void)
135 {
136 if (!m_started)
137 {
138 setThread(&m_testThread);
139 m_testThread.start();
140 m_started = true;
141 }
142
143 RenderActivity::onStart();
144 }
145
onDestroy(void)146 void TestActivity::onDestroy(void)
147 {
148 if (m_started)
149 {
150 setThread(DE_NULL);
151 m_testThread.stop();
152 m_started = false;
153 }
154
155 RenderActivity::onDestroy();
156
157 // Kill this process.
158 tcu::print("Done, killing process");
159 exit(0);
160 }
161
onConfigurationChanged(void)162 void TestActivity::onConfigurationChanged(void)
163 {
164 RenderActivity::onConfigurationChanged();
165
166 // Update rotation.
167 tcu::Android::setRequestedOrientation(getNativeActivity(),
168 tcu::Android::mapScreenRotation(m_cmdLine.getScreenRotation()));
169 }
170
171 } // Android
172 } // glcts
173