Merge "Further relax line verification in primitive bbox tests" into nougat-cts-dev...
[platform/upstream/VK-GL-CTS.git] / framework / platform / android / tcuAndroidTestActivity.cpp
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
41 TestThread::TestThread (NativeActivity& activity, 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 }
51
52 TestThread::~TestThread (void)
53 {
54         // \note m_testApp is managed by thread.
55 }
56
57 void TestThread::run (void)
58 {
59         RenderThread::run();
60 }
61
62 void TestThread::onWindowCreated (ANativeWindow* window)
63 {
64         m_platform.getWindowRegistry().addWindow(window);
65 }
66
67 void TestThread::onWindowDestroyed (ANativeWindow* window)
68 {
69         m_platform.getWindowRegistry().destroyWindow(window);
70 }
71
72 void TestThread::onWindowResized (ANativeWindow* window)
73 {
74         DE_UNREF(window);
75         print("Warning: Native window was resized, results may be undefined");
76 }
77
78 bool TestThread::render (void)
79 {
80         if (!m_finished)
81                 m_finished = !m_app.iterate();
82         return !m_finished;
83 }
84
85 // TestActivity
86
87 TestActivity::TestActivity (ANativeActivity* activity)
88         : RenderActivity        (activity)
89         , m_cmdLine                     (getIntentStringExtra(activity, "cmdLine"))
90         , m_testThread          (*this, m_cmdLine)
91         , m_started                     (false)
92 {
93         // Set initial orientation.
94         setRequestedOrientation(getNativeActivity(), mapScreenRotation(m_cmdLine.getScreenRotation()));
95
96         // Set up window flags.
97         ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON    |
98                                                                                          AWINDOW_FLAG_TURN_SCREEN_ON    |
99                                                                                          AWINDOW_FLAG_FULLSCREEN                |
100                                                                                          AWINDOW_FLAG_SHOW_WHEN_LOCKED, 0);
101 }
102
103 TestActivity::~TestActivity (void)
104 {
105 }
106
107 void TestActivity::onStart (void)
108 {
109         if (!m_started)
110         {
111                 setThread(&m_testThread);
112                 m_testThread.start();
113                 m_started = true;
114         }
115
116         RenderActivity::onStart();
117 }
118
119 void TestActivity::onDestroy (void)
120 {
121         if (m_started)
122         {
123                 setThread(DE_NULL);
124                 m_testThread.stop();
125                 m_started = false;
126         }
127
128         RenderActivity::onDestroy();
129
130         // Kill this process.
131         print("Done, killing process");
132         exit(0);
133 }
134
135 void TestActivity::onConfigurationChanged (void)
136 {
137         RenderActivity::onConfigurationChanged();
138
139         // Update rotation.
140         setRequestedOrientation(getNativeActivity(), mapScreenRotation(m_cmdLine.getScreenRotation()));
141 }
142
143 } // Android
144 } // tcu