Add multiple contexts tests
[platform/upstream/VK-GL-CTS.git] / framework / platform / win32 / tcuWGL.hpp
1 #ifndef _TCUWGL_HPP
2 #define _TCUWGL_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 WGL Utilities.
24  *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "gluRenderConfig.hpp"
28 #include "gluRenderContext.hpp"
29 #include "deDynamicLibrary.h"
30 #include "tcuWin32API.h"
31
32 #include <vector>
33
34 namespace glu
35 {
36 struct RenderConfig;
37 }
38
39 namespace tcu
40 {
41 namespace wgl
42 {
43
44 class Library;
45 class Context;
46
47 /*--------------------------------------------------------------------*//*!
48  * \brief WGL pixel format info.
49  *//*--------------------------------------------------------------------*/
50 class PixelFormatInfo
51 {
52 public:
53         enum PixelType
54         {
55                 PIXELTYPE_RGBA = 0,
56                 PIXELTYPE_RGBA_FLOAT,
57                 PIXELTYPE_RGBA_UNSIGNED_FLOAT,
58                 PIXELTYPE_COLOR_INDEX,
59                 PIXELTYPE_UNKNOWN,
60
61                 PIXELTYPE_LAST
62         };
63
64         enum SurfaceFlags
65         {
66                 SURFACE_WINDOW  = (1<<0),
67                 SURFACE_PIXMAP  = (1<<1)
68         };
69
70         enum Acceleration
71         {
72                 ACCELERATION_NONE = 0,
73                 ACCELERATION_GENERIC,
74                 ACCELERATION_FULL,
75                 ACCELERATION_UNKNOWN,
76
77                 ACCELERATION_LAST
78         };
79
80         int                             pixelFormat;
81
82         // From WGL_ARB_pixel_format
83         deUint32                surfaceTypes;
84         Acceleration    acceleration;
85         bool                    needPalette;
86         bool                    needSystemPalette;
87 //      bool                    swapLayerBuffers;
88 //      SwapMethod              swapMethod; { EXCHANGE, UNDEFINED }
89         int                             numOverlays;
90         int                             numUnderlays;
91 //      bool                    transparent;
92 //      int                             transparentRedValue;
93 //      int                             transparentGreenValue;
94 //      int                             transparentBlueValue;
95 //      int                             transparentAlphaValue;
96 //      int                             transparentIndexValue;
97 //      bool                    shareDepth;
98 //      bool                    shareStencil;
99 //      bool                    shareAccum;
100 //      bool                    supportGDI;
101         bool                    supportOpenGL;
102         bool                    doubleBuffer;
103         bool                    stereo;
104         PixelType               pixelType;
105
106 //      int                             colorBits;
107         int                             redBits;
108 //      int                             redShift;
109         int                             greenBits;
110 //      int                             greenShift;
111         int                             blueBits;
112 //      int                             blueShift;
113         int                             alphaBits;
114 //      int                             alphaShift;
115
116         int                             accumBits;
117 //      int                             accumRedBits;
118 //      int                             accumGreenBits;
119 //      int                             accumBlueBits;
120 //      int                             accumAlphaBits;
121
122         int                             depthBits;
123         int                             stencilBits;
124
125         int                             numAuxBuffers;
126
127         // From WGL_ARB_multisample
128         int                             sampleBuffers;
129         int                             samples;
130
131         // \todo [2013-04-14 pyry] Version bits?
132
133         PixelFormatInfo (void)
134                 : pixelFormat           (0)
135                 , surfaceTypes          (0)
136                 , acceleration          (ACCELERATION_LAST)
137                 , needPalette           (false)
138                 , needSystemPalette     (false)
139                 , numOverlays           (0)
140                 , numUnderlays          (0)
141                 , supportOpenGL         (false)
142                 , doubleBuffer          (false)
143                 , stereo                        (false)
144                 , pixelType                     (PIXELTYPE_LAST)
145                 , redBits                       (0)
146                 , greenBits                     (0)
147                 , blueBits                      (0)
148                 , alphaBits                     (0)
149                 , accumBits                     (0)
150                 , depthBits                     (0)
151                 , stencilBits           (0)
152                 , numAuxBuffers         (0)
153                 , sampleBuffers         (0)
154                 , samples                       (0)
155         {
156         }
157 };
158
159 /*--------------------------------------------------------------------*//*!
160  * \brief Core WGL API
161  *
162  * \note Created API objects depend on Core object being live. User is
163  *               resposible of keeping Core live as long as there are API objects
164  *               (such as GL contexts) live!
165  *//*--------------------------------------------------------------------*/
166 class Core
167 {
168 public:
169                                                 Core                            (HINSTANCE instance);
170                                                 ~Core                           (void);
171
172         std::vector<int>        getPixelFormats         (HDC deviceCtx) const;
173         PixelFormatInfo         getPixelFormatInfo      (HDC deviceCtx, int pixelFormat) const;
174
175         // Internal
176         const Library*          getLibrary                      (void) const { return m_library; }
177
178 private:
179                                                 Core                            (const Core& other);
180         Core&                           operator=                       (const Core& other);
181
182         Library*                        m_library;
183 };
184
185 //! Function pointer type.
186 typedef void (__stdcall* FunctionPtr) (void);
187
188 /*--------------------------------------------------------------------*//*!
189  * \brief WGL context
190  *
191  * Context is currently made current to current thread in constructor
192  * and detached in destructor. Thus context should be created in and
193  * accessed from a single thread.
194  *//*--------------------------------------------------------------------*/
195 class Context
196 {
197 public:
198                                                 Context                         (const Core*                                    core,
199                                                                                          HDC                                                    deviceCtx,
200                                                                                          const Context*                                 sharedContext,
201                                                                                          glu::ContextType                               ctxType,
202                                                                                          int                                                    pixelFormat,
203                                                                                          glu::ResetNotificationStrategy resetNotificationStrategy);
204                                                 ~Context                        (void);
205
206         FunctionPtr                     getGLFunction           (const char* name) const;
207
208         void                            makeCurrent                     (void);
209         void                            swapBuffers                     (void) const;
210
211         HDC                                     getDeviceContext        (void) const { return m_deviceCtx;      }
212         HGLRC                           getGLContext            (void) const { return m_context;        }
213
214 private:
215                                                 Context                         (const Context& other);
216         Context&                        operator=                       (const Context& other);
217
218         const Core*                     m_core;
219         HDC                                     m_deviceCtx;
220         HGLRC                           m_context;
221 };
222
223 //! Utility for selecting config. Returns -1 if no matching pixel format was found.
224 int             choosePixelFormat       (const Core& wgl, HDC deviceCtx, const glu::RenderConfig& config);
225
226 //! Is pixel format in general supported by dEQP tests?
227 bool    isSupportedByTests      (const PixelFormatInfo& pixelFormatInfo);
228
229 } // wgl
230 } // tcu
231
232 #endif // _TCUWGL_HPP