1 #ifndef _TCUANDROIDWINDOW_HPP 2 #define _TCUANDROIDWINDOW_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Android window. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "tcuVector.hpp" 28 #include "deSemaphore.hpp" 29 #include "deMutex.hpp" 30 31 #include <vector> 32 33 #include <android/native_window.h> 34 35 namespace tcu 36 { 37 namespace Android 38 { 39 40 // \note Window is thread-safe, WindowRegistry is not 41 42 class Window 43 { 44 public: 45 enum State 46 { 47 STATE_AVAILABLE = 0, 48 STATE_IN_USE, 49 STATE_PENDING_DESTROY, 50 STATE_READY_FOR_DESTROY, 51 STATE_ACQUIRED_FOR_DESTROY, 52 53 STATE_LAST 54 }; 55 56 Window(ANativeWindow *window); 57 ~Window(void); 58 59 bool tryAcquire(void); 60 void release(void); 61 62 void markForDestroy(void); 63 bool isPendingDestroy(void) const; 64 bool tryAcquireForDestroy(bool onlyMarked); 65 getNativeWindow(void)66 ANativeWindow *getNativeWindow(void) 67 { 68 return m_window; 69 } 70 71 void setBuffersGeometry(int width, int height, int32_t format); 72 73 IVec2 getSize(void) const; 74 75 private: 76 Window(const Window &other); 77 Window &operator=(const Window &other); 78 79 ANativeWindow *m_window; 80 mutable de::Mutex m_stateLock; 81 State m_state; 82 }; 83 84 class WindowRegistry 85 { 86 public: 87 WindowRegistry(void); 88 ~WindowRegistry(void); 89 90 void addWindow(ANativeWindow *window); 91 void destroyWindow(ANativeWindow *window); 92 93 Window *tryAcquireWindow(void); 94 95 void garbageCollect(void); 96 97 private: 98 std::vector<Window *> m_windows; 99 }; 100 101 } // namespace Android 102 } // namespace tcu 103 104 #endif // _TCUANDROIDWINDOW_HPP 105