13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief RenderActivity base class. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuAndroidRenderActivity.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deSemaphore.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <android/window.h> 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <stdlib.h> 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if defined(DE_DEBUG) 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# define DBG_PRINT(X) print X 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#else 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# define DBG_PRINT(X) 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Android 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MESSAGE_QUEUE_SIZE = 8 //!< Length of RenderThread message queue. 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 50217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos#if defined(DE_DEBUG) 51217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulosstatic const char* getMessageTypeName (MessageType type) 52217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos{ 53217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos static const char* s_names[] = 54217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos { 55217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "RESUME", 56217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "PAUSE", 57217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "FINISH", 58217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "WINDOW_CREATED", 59217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "WINDOW_RESIZED", 60217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "WINDOW_DESTROYED", 61217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "INPUT_QUEUE_CREATED", 62217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "INPUT_QUEUE_DESTROYED", 63217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos "SYNC" 64217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos }; 65217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == MESSAGETYPE_LAST); 66217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos return s_names[type]; 67217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos} 68217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos#endif 69217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// RenderThread 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderThread::RenderThread (NativeActivity& activity) 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_activity (activity) 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_msgQueue (MESSAGE_QUEUE_SIZE) 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_threadRunning (false) 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_inputQueue (DE_NULL) 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_windowState (WINDOWSTATE_NOT_CREATED) 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_window (DE_NULL) 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_paused (false) 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_finish (false) 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderThread::~RenderThread (void) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderThread::start (void) 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_threadRunning = true; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Thread::start(); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 94217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulosvoid RenderThread::stop (void) 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Queue finish command 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enqueue(Message(MESSAGE_FINISH)); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Wait for thread to terminate 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry join(); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_threadRunning = false; 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderThread::enqueue (const Message& message) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note Thread must be running or otherwise nobody is going to drain the queue. 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_threadRunning); 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_msgQueue.pushFront(message); 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderThread::pause (void) 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enqueue(Message(MESSAGE_PAUSE)); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderThread::resume (void) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enqueue(Message(MESSAGE_RESUME)); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderThread::sync (void) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Semaphore waitSem(0); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enqueue(Message(MESSAGE_SYNC, &waitSem)); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry waitSem.decrement(); 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderThread::processMessage (const Message& message) 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 131217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos DBG_PRINT(("RenderThread::processMessage(): message = { %s, %p }\n", getMessageTypeName(message.type), message.payload.window)); 132217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (message.type) 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_RESUME: m_paused = false; break; 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_PAUSE: m_paused = true; break; 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_FINISH: m_finish = true; break; 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 139217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos // \note While Platform / WindowRegistry are currently multi-window -capable, 140217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos // the fact that platform gives us windows too late / at unexpected times 141217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos // forces us to do some sanity checking and limit system to one window here. 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_WINDOW_CREATED: 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_windowState != WINDOWSTATE_NOT_CREATED && m_windowState != WINDOWSTATE_DESTROYED) 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw InternalError("Got unexpected onNativeWindowCreated() event from system"); 145217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_windowState = WINDOWSTATE_NOT_INITIALIZED; 14767e56c9a76571b87c58a174bdad44fa1425d40fePyry Haulos m_window = message.payload.window; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_WINDOW_RESIZED: 151217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos if (m_window != message.payload.window) 152217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos throw InternalError("Got onNativeWindowResized() event targeting different window"); 153217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_windowState == WINDOWSTATE_NOT_INITIALIZED) 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Got first resize event, window is ready for use. 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_windowState = WINDOWSTATE_READY; 15867e56c9a76571b87c58a174bdad44fa1425d40fePyry Haulos onWindowCreated(message.payload.window); 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_windowState == WINDOWSTATE_READY) 16167e56c9a76571b87c58a174bdad44fa1425d40fePyry Haulos onWindowResized(message.payload.window); 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw InternalError("Got unexpected onNativeWindowResized() event from system"); 164217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_WINDOW_DESTROYED: 168217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos if (m_window != message.payload.window) 169217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos throw InternalError("Got onNativeWindowDestroyed() event targeting different window"); 170217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_windowState != WINDOWSTATE_NOT_INITIALIZED && m_windowState != WINDOWSTATE_READY) 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw InternalError("Got unexpected onNativeWindowDestroyed() event from system"); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 174217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos if (m_windowState == WINDOWSTATE_READY) 175217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos onWindowDestroyed(message.payload.window); 176217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_windowState = WINDOWSTATE_DESTROYED; 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_window = DE_NULL; 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_INPUT_QUEUE_CREATED: 18267e56c9a76571b87c58a174bdad44fa1425d40fePyry Haulos m_inputQueue = message.payload.inputQueue; 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_INPUT_QUEUE_DESTROYED: 18667e56c9a76571b87c58a174bdad44fa1425d40fePyry Haulos m_inputQueue = message.payload.inputQueue; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case MESSAGE_SYNC: 19067e56c9a76571b87c58a174bdad44fa1425d40fePyry Haulos message.payload.semaphore->increment(); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw std::runtime_error("Unknown message type"); 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderThread::run (void) 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Init state 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_windowState = WINDOWSTATE_NOT_CREATED; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_paused = true; 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_finish = false; 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (!m_finish) 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_paused || m_windowState != WINDOWSTATE_READY) 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Block until we are not paused and window is ready. 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Message msg = m_msgQueue.popBack(); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry processMessage(msg); 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Process available commands 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Message msg; 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_msgQueue.tryPopBack(msg)) 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry processMessage(msg); 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_windowState == WINDOWSTATE_READY); 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Process input events. 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-05-08 pyry] What if system fills up the input queue before we have window ready? 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (m_inputQueue && 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AInputQueue_hasEvents(m_inputQueue) > 0) 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AInputEvent* event; 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(AInputQueue_getEvent(m_inputQueue, &event) >= 0); 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry onInputEvent(event); 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AInputQueue_finishEvent(m_inputQueue, event, 1); 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Everything set up - safe to render. 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!render()) 243217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos { 244217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos DBG_PRINT(("RenderThread::run(): render\n")); 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 246217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos } 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception& e) 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry print("RenderThread: %s\n", e.what()); 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Tell activity to finish. 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderThread::run(): done, waiting for FINISH\n")); 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_activity.finish(); 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Thread must keep draining message queue until FINISH message is encountered. 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (!m_finish) 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Message msg = m_msgQueue.popBack(); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Ignore all but SYNC and FINISH messages. 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (msg.type == MESSAGE_SYNC || msg.type == MESSAGE_FINISH) 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry processMessage(msg); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception& e) 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry die("RenderThread: %s\n", e.what()); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderThread::run(): exiting...\n")); 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// RenderActivity 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderActivity::RenderActivity (ANativeActivity* activity) 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : NativeActivity(activity) 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_thread (DE_NULL) 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::RenderActivity()")); 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2873c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderActivity::~RenderActivity (void) 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::~RenderActivity()")); 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::setThread (RenderThread* thread) 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread = thread; 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onStart (void) 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onStart()")); 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onResume (void) 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onResume()")); 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Resume (or start) test execution 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->resume(); 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onPause (void) 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onPause()")); 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Pause test execution 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->pause(); 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onStop (void) 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onStop()")); 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onDestroy (void) 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onDestroy()")); 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onNativeWindowCreated (ANativeWindow* window) 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onNativeWindowCreated()")); 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->enqueue(Message(MESSAGE_WINDOW_CREATED, window)); 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onNativeWindowResized (ANativeWindow* window) 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onNativeWindowResized()")); 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->enqueue(Message(MESSAGE_WINDOW_RESIZED, window)); 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onNativeWindowRedrawNeeded (ANativeWindow* window) 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_UNREF(window); 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onNativeWindowDestroyed (ANativeWindow* window) 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onNativeWindowDestroyed()")); 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->enqueue(Message(MESSAGE_WINDOW_DESTROYED, window)); 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->sync(); // Block until thread has processed all messages. 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onInputQueueCreated (AInputQueue* queue) 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onInputQueueCreated()")); 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->enqueue(Message(MESSAGE_INPUT_QUEUE_CREATED, queue)); 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderActivity::onInputQueueDestroyed (AInputQueue* queue) 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DBG_PRINT(("RenderActivity::onInputQueueDestroyed()")); 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->enqueue(Message(MESSAGE_INPUT_QUEUE_DESTROYED, queue)); 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread->sync(); 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Android 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 367