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