tcuAndroidTestActivity.cpp revision 3c827367444ee418f129b2c238299f49d3264554
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 test activity.
22 *//*--------------------------------------------------------------------*/
23
24#include "tcuAndroidTestActivity.hpp"
25#include "tcuAndroidUtil.hpp"
26
27#include <android/window.h>
28
29#include <string>
30#include <stdlib.h>
31
32using std::string;
33
34namespace tcu
35{
36namespace Android
37{
38
39// TestApp
40
41TestApp::TestApp (NativeActivity& activity, ANativeWindow* window, const CommandLine& cmdLine)
42	: m_cmdLine		(cmdLine)
43	, m_platform	(window)
44	, m_archive		(activity.getNativeActivity()->assetManager)
45	, m_log			(m_cmdLine.getLogFileName())
46	, m_app			(m_platform, m_archive, m_log, m_cmdLine)
47{
48}
49
50TestApp::~TestApp (void)
51{
52}
53
54bool TestApp::iterate (void)
55{
56	return m_app.iterate();
57}
58
59// TestThread
60
61TestThread::TestThread (NativeActivity& activity, const CommandLine& cmdLine)
62	: RenderThread	(activity)
63	, m_cmdLine		(cmdLine)
64	, m_testApp		(DE_NULL)
65	, m_done		(false)
66{
67}
68
69TestThread::~TestThread (void)
70{
71	// \note m_testApp is managed by thread.
72}
73
74void TestThread::run (void)
75{
76	RenderThread::run();
77
78	delete m_testApp;
79	m_testApp = DE_NULL;
80}
81
82void TestThread::onWindowCreated (ANativeWindow* window)
83{
84	DE_ASSERT(!m_testApp);
85	m_testApp = new TestApp(getNativeActivity(), window, m_cmdLine);
86}
87
88void TestThread::onWindowDestroyed (ANativeWindow* window)
89{
90	DE_UNREF(window);
91	DE_ASSERT(m_testApp);
92	delete m_testApp;
93	m_testApp = DE_NULL;
94
95	if (!m_done)
96	{
97		// \note We could just throw exception here and RenderThread would gracefully terminate.
98		//		 However, native window is often destroyed when app is closed and android may not
99		//		 end up calling onStop().
100		die("Window was destroyed during execution");
101	}
102}
103
104void TestThread::onWindowResized (ANativeWindow* window)
105{
106	// \todo [2013-05-12 pyry] Handle this in some sane way.
107	DE_UNREF(window);
108	print("Warning: Native window was resized, results may be undefined");
109}
110
111bool TestThread::render (void)
112{
113	DE_ASSERT(m_testApp);
114	m_done = !m_testApp->iterate();
115	return !m_done;
116}
117
118// TestActivity
119
120TestActivity::TestActivity (ANativeActivity* activity)
121	: RenderActivity	(activity)
122	, m_cmdLine			(getIntentStringExtra(activity, "cmdLine"))
123	, m_testThread		(*this, m_cmdLine)
124{
125	// Provide RenderThread
126	setThread(&m_testThread);
127
128	// Set initial orientation.
129	setRequestedOrientation(getNativeActivity(), mapScreenRotation(m_cmdLine.getScreenRotation()));
130
131	// Set up window flags.
132	ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON	|
133											 AWINDOW_FLAG_TURN_SCREEN_ON	|
134											 AWINDOW_FLAG_FULLSCREEN		|
135											 AWINDOW_FLAG_SHOW_WHEN_LOCKED, 0);
136}
137
138TestActivity::~TestActivity (void)
139{
140}
141
142void TestActivity::onStop (void)
143{
144	RenderActivity::onStop();
145
146	// Kill this process.
147	print("Done, killing process");
148	exit(0);
149}
150
151void TestActivity::onConfigurationChanged (void)
152{
153	RenderActivity::onConfigurationChanged();
154
155	// Update rotation.
156	setRequestedOrientation(getNativeActivity(), mapScreenRotation(m_cmdLine.getScreenRotation()));
157}
158
159} // Android
160} // tcu
161