• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef _SYSTEM_EGL_DISPLAY_H
17 #define _SYSTEM_EGL_DISPLAY_H
18 
19 #include <assert.h>
20 #include <pthread.h>
21 #include "glUtils.h"
22 #include <EGL/egl.h>
23 #include <EGL/eglext.h>
24 
25 #include "EGLClientIface.h"
26 #include "gfxstream/guest/GLClientState.h"
27 
28 #if __cplusplus >= 201103L
29 #include <unordered_set>
30 #else
31 #include <hash_set>
32 #endif
33 
34 #include <map>
35 
36 #define ATTRIBUTE_NONE (-1)
37 //FIXME: are we in this namespace?
38 using namespace gfxstream::guest;
39 
40 class eglDisplay
41 {
42 public:
43     eglDisplay();
44     ~eglDisplay();
45 
46     bool initialize(EGLClient_eglInterface *eglIface);
47     void terminate();
48 
getVersionMajor()49     int getVersionMajor() const { return m_major; }
getVersionMinor()50     int getVersionMinor() const { return m_minor; }
initialized()51     bool initialized() const { return m_initialized; }
52 
53     const char *queryString(EGLint name);
54 
gles_iface()55     const EGLClient_glesInterface *gles_iface() const { return m_gles_iface; }
gles2_iface()56     const EGLClient_glesInterface *gles2_iface() const { return m_gles2_iface; }
57 
getNumConfigs()58     int     getNumConfigs(){ return m_numConfigs; }
59 
60     EGLConfig getConfigAtIndex(uint32_t index) const;
61     uint32_t getIndexOfConfig(EGLConfig config) const;
62     bool isValidConfig(EGLConfig cfg) const;
63 
64     EGLBoolean  getConfigAttrib(EGLConfig config, EGLint attrib, EGLint * value);
65     EGLBoolean  setConfigAttrib(EGLConfig config, EGLint attrib, EGLint value);
66     EGLBoolean getConfigGLPixelFormat(EGLConfig config, GLenum * format);
67     EGLBoolean getConfigNativePixelFormat(EGLConfig config, uint32_t * format);
68 
69     void     dumpConfig(EGLConfig config);
70 
71     void onCreateContext(EGLContext ctx);
72     void onCreateSurface(EGLSurface surface);
73 
74     void onDestroyContext(EGLContext ctx);
75     void onDestroySurface(EGLSurface surface);
76 
77     bool isContext(EGLContext ctx);
78     bool isSurface(EGLSurface ctx);
79 
80     // Needs a current context (put this near eglMakeCurrent)
81     HostDriverCaps getHostDriverCaps(int majorVersion, int minorVersion);
82 
83 private:
84     EGLClient_glesInterface *loadGLESClientAPI(const char *libName,
85                                                EGLClient_eglInterface *eglIface,
86                                                void **libHandle);
87     EGLBoolean getAttribValue(EGLConfig config, EGLint attribIdxi, EGLint * value);
88     EGLBoolean setAttribValue(EGLConfig config, EGLint attribIdxi, EGLint value);
89     void     processConfigs();
90 
91 private:
92     pthread_mutex_t m_lock;
93     bool m_initialized;
94     int  m_major;
95     int  m_minor;
96     int  m_hostRendererVersion;
97     int  m_numConfigs;
98     int  m_numConfigAttribs;
99 
100     /* This is the mapping between an attribute name to it's index in any given config */
101     std::map<EGLint, EGLint>    m_attribs;
102     /* This is an array of all config's attributes values stored in the following sequencial fasion (read: v[c,a] = the value of attribute <a> of config <c>)
103      * v[0,0],..,v[0,m_numConfigAttribs-1],
104      *...
105      * v[m_numConfigs-1,0],..,v[m_numConfigs-1,m_numConfigAttribs-1]
106      */
107     EGLint *m_configs;
108     EGLClient_glesInterface *m_gles_iface;
109     EGLClient_glesInterface *m_gles2_iface;
110     char *m_versionString;
111     char *m_vendorString;
112     char *m_extensionString;
113 
114 #if __cplusplus >= 201103L
115     typedef std::unordered_set<EGLContext> EGLContextSet;
116     typedef std::unordered_set<EGLSurface> EGLSurfaceSet;
117 #else
118     typedef std::hash_set<EGLContext> EGLContextSet;
119     typedef std::hash_set<EGLSurface> EGLSurfaceSet;
120 #endif
121     EGLContextSet m_contexts;
122     EGLSurfaceSet m_surfaces;
123     pthread_mutex_t m_ctxLock;
124     pthread_mutex_t m_surfaceLock;
125 
126     int m_hostDriverCaps_knownMajorVersion;
127     int m_hostDriverCaps_knownMinorVersion;
128     HostDriverCaps m_hostDriverCaps;
129 };
130 
131 #endif
132