Home | History | Annotate | Download | only in runner
      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 
     45 static std::string getLogPath(ANativeActivity* activity)
     46 {
     47 	std::string path = tcu::Android::getIntentStringExtra(activity, "logdir");
     48 	return path.empty() ? std::string(DEFAULT_LOG_PATH) : path;
     49 }
     50 
     51 static deUint32 getFlags(ANativeActivity* activity)
     52 {
     53 	deUint32 flags = 0;
     54 	if (tcu::Android::getIntentStringExtra(activity, "verbose") == "true")
     55 		flags |= TestRunner::VERBOSE_ALL;
     56 	else if (tcu::Android::getIntentStringExtra(activity, "summary") == "true")
     57 		flags |= TestRunner::PRINT_SUMMARY;
     58 	return flags;
     59 }
     60 
     61 TestThread::TestThread(NativeActivity& activity, tcu::Android::AssetArchive& archive, const std::string& logPath,
     62 					   glu::ApiType runType, deUint32 runFlags)
     63 	: RenderThread(activity)
     64 	, m_platform(activity)
     65 	, m_archive(archive)
     66 	, m_app(m_platform, m_archive, logPath.c_str(), runType, runFlags)
     67 	, m_finished(false)
     68 {
     69 }
     70 
     71 TestThread::~TestThread(void)
     72 {
     73 	// \note m_testApp is managed by thread.
     74 }
     75 
     76 void TestThread::run(void)
     77 {
     78 	RenderThread::run();
     79 }
     80 
     81 void TestThread::onWindowCreated(ANativeWindow* window)
     82 {
     83 	m_platform.getWindowRegistry().addWindow(window);
     84 }
     85 
     86 void TestThread::onWindowDestroyed(ANativeWindow* window)
     87 {
     88 	m_platform.getWindowRegistry().destroyWindow(window);
     89 }
     90 
     91 void TestThread::onWindowResized(ANativeWindow* window)
     92 {
     93 	// \todo [2013-05-12 pyry] Handle this in some sane way.
     94 	DE_UNREF(window);
     95 	tcu::print("Warning: Native window was resized, results may be undefined");
     96 }
     97 
     98 bool TestThread::render(void)
     99 {
    100 	if (!m_finished)
    101 		m_finished = !m_app.iterate();
    102 	return !m_finished;
    103 }
    104 
    105 // TestActivity
    106 
    107 TestActivity::TestActivity(ANativeActivity* activity, glu::ApiType runType)
    108 	: RenderActivity(activity)
    109 	, m_archive(activity->assetManager)
    110 	, m_cmdLine(tcu::Android::getIntentStringExtra(activity, "cmdLine"))
    111 	, m_testThread(*this, m_archive, getLogPath(activity), runType, getFlags(activity))
    112 	, m_started(false)
    113 {
    114 	// Set initial orientation.
    115 	tcu::Android::setRequestedOrientation(getNativeActivity(),
    116 										  tcu::Android::mapScreenRotation(m_cmdLine.getScreenRotation()));
    117 
    118 	// Set up window flags.
    119 	ANativeActivity_setWindowFlags(activity,
    120 								   AWINDOW_FLAG_KEEP_SCREEN_ON | AWINDOW_FLAG_TURN_SCREEN_ON | AWINDOW_FLAG_FULLSCREEN |
    121 									   AWINDOW_FLAG_SHOW_WHEN_LOCKED,
    122 								   0);
    123 }
    124 
    125 TestActivity::~TestActivity(void)
    126 {
    127 }
    128 
    129 void TestActivity::onStart(void)
    130 {
    131 	if (!m_started)
    132 	{
    133 		setThread(&m_testThread);
    134 		m_testThread.start();
    135 		m_started = true;
    136 	}
    137 
    138 	RenderActivity::onStart();
    139 }
    140 
    141 void TestActivity::onDestroy(void)
    142 {
    143 	if (m_started)
    144 	{
    145 		setThread(DE_NULL);
    146 		m_testThread.stop();
    147 		m_started = false;
    148 	}
    149 
    150 	RenderActivity::onDestroy();
    151 
    152 	// Kill this process.
    153 	tcu::print("Done, killing process");
    154 	exit(0);
    155 }
    156 
    157 void TestActivity::onConfigurationChanged(void)
    158 {
    159 	RenderActivity::onConfigurationChanged();
    160 
    161 	// Update rotation.
    162 	tcu::Android::setRequestedOrientation(getNativeActivity(),
    163 										  tcu::Android::mapScreenRotation(m_cmdLine.getScreenRotation()));
    164 }
    165 
    166 } // Android
    167 } // glcts
    168