Make Android integration more robust for API >= 11
[platform/upstream/VK-GL-CTS.git] / framework / platform / android / tcuAndroidWindow.hpp
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
66         ANativeWindow*                  getNativeWindow         (void)  { return m_window;      }
67
68         void                                    setBuffersGeometry      (int width, int height, int32_t format);
69
70         IVec2                                   getSize                         (void) const;
71
72 private:
73                                                         Window                          (const Window& other);
74         Window&                                 operator=                       (const Window& other);
75
76         ANativeWindow*                  m_window;
77         mutable de::Mutex               m_stateLock;
78         State                                   m_state;
79 };
80
81 class WindowRegistry
82 {
83 public:
84                                                         WindowRegistry          (void);
85                                                         ~WindowRegistry         (void);
86
87         void                                    addWindow                       (ANativeWindow* window);
88         void                                    destroyWindow           (ANativeWindow* window);
89
90         Window*                                 tryAcquireWindow        (void);
91
92         void                                    garbageCollect          (void);
93
94 private:
95         std::vector<Window*>    m_windows;
96 };
97
98 } // Android
99 } // tcu
100
101 #endif // _TCUANDROIDWINDOW_HPP