• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
32 using std::string;
33 
34 namespace tcu
35 {
36 namespace Android
37 {
38 
39 // TestThread
40 
TestThread(NativeActivity & activity,const std::string & cmdLineString,const CommandLine & cmdLine)41 TestThread::TestThread (NativeActivity& activity, const std::string& cmdLineString, const CommandLine& cmdLine)
42 	: RenderThread	(activity)
43 	, m_cmdLine		(cmdLine)
44 	, m_platform	(activity)
45 	, m_archive		(activity.getNativeActivity()->assetManager)
46 	, m_log			(m_cmdLine.getLogFileName(), m_cmdLine.getLogFlags())
47 	, m_app			(m_platform, m_archive, m_log, m_cmdLine)
48 	, m_finished	(false)
49 {
50 	const std::string sessionInfo = "#sessionInfo commandLineParameters \"";
51 	m_log.writeSessionInfo(sessionInfo + cmdLineString + "\"\n");
52 }
53 
~TestThread(void)54 TestThread::~TestThread (void)
55 {
56 	// \note m_testApp is managed by thread.
57 }
58 
run(void)59 void TestThread::run (void)
60 {
61 	RenderThread::run();
62 }
63 
onWindowCreated(ANativeWindow * window)64 void TestThread::onWindowCreated (ANativeWindow* window)
65 {
66 	m_platform.getWindowRegistry().addWindow(window);
67 }
68 
onWindowDestroyed(ANativeWindow * window)69 void TestThread::onWindowDestroyed (ANativeWindow* window)
70 {
71 	m_platform.getWindowRegistry().destroyWindow(window);
72 }
73 
onWindowResized(ANativeWindow * window)74 void TestThread::onWindowResized (ANativeWindow* window)
75 {
76 	DE_UNREF(window);
77 	print("Warning: Native window was resized, results may be undefined");
78 }
79 
render(void)80 bool TestThread::render (void)
81 {
82 	if (!m_finished)
83 		m_finished = !m_app.iterate();
84 	return !m_finished;
85 }
86 
87 // TestActivity
88 
TestActivity(ANativeActivity * activity)89 TestActivity::TestActivity (ANativeActivity* activity)
90 	: RenderActivity	(activity)
91 	, m_cmdLine			(getIntentStringExtra(activity, "cmdLine"))
92 	, m_testThread		(*this, getIntentStringExtra(activity, "cmdLine"), m_cmdLine)
93 	, m_started			(false)
94 {
95 	// Set initial orientation.
96 	setRequestedOrientation(getNativeActivity(), mapScreenRotation(m_cmdLine.getScreenRotation()));
97 
98 	// Set up window flags.
99 	ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON	|
100 											 AWINDOW_FLAG_TURN_SCREEN_ON	|
101 											 AWINDOW_FLAG_FULLSCREEN		|
102 											 AWINDOW_FLAG_SHOW_WHEN_LOCKED, 0);
103 }
104 
~TestActivity(void)105 TestActivity::~TestActivity (void)
106 {
107 }
108 
onStart(void)109 void TestActivity::onStart (void)
110 {
111 	if (!m_started)
112 	{
113 		setThread(&m_testThread);
114 		m_testThread.start();
115 		m_started = true;
116 	}
117 
118 	RenderActivity::onStart();
119 }
120 
onDestroy(void)121 void TestActivity::onDestroy (void)
122 {
123 	if (m_started)
124 	{
125 		setThread(DE_NULL);
126 		m_testThread.stop();
127 		m_started = false;
128 	}
129 
130 	RenderActivity::onDestroy();
131 
132 	// Kill this process.
133 	print("Done, killing process");
134 	exit(0);
135 }
136 
onConfigurationChanged(void)137 void TestActivity::onConfigurationChanged (void)
138 {
139 	RenderActivity::onConfigurationChanged();
140 
141 	// Update rotation.
142 	setRequestedOrientation(getNativeActivity(), mapScreenRotation(m_cmdLine.getScreenRotation()));
143 }
144 
145 } // Android
146 } // tcu
147