• 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 #include "EGLClientIface.h"
25 
26 #if __cplusplus >= 201103L
27 #include <unordered_set>
28 #else
29 #include <hash_set>
30 #endif
31 
32 #include <map>
33 
34 #include <ui/PixelFormat.h>
35 
36 #define ATTRIBUTE_NONE (-1)
37 //FIXME: are we in this namespace?
38 using namespace android;
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     EGLBoolean  getConfigAttrib(EGLConfig config, EGLint attrib, EGLint * value);
60     EGLBoolean  setConfigAttrib(EGLConfig config, EGLint attrib, EGLint value);
61     EGLBoolean getConfigGLPixelFormat(EGLConfig config, GLenum * format);
62     EGLBoolean getConfigNativePixelFormat(EGLConfig config, PixelFormat * format);
63 
64     void     dumpConfig(EGLConfig config);
65 
66     void onCreateContext(EGLContext ctx);
67     void onCreateSurface(EGLSurface surface);
68 
69     void onDestroyContext(EGLContext ctx);
70     void onDestroySurface(EGLSurface surface);
71 
72     bool isContext(EGLContext ctx);
73     bool isSurface(EGLSurface ctx);
74 private:
75     EGLClient_glesInterface *loadGLESClientAPI(const char *libName,
76                                                EGLClient_eglInterface *eglIface,
77                                                void **libHandle);
78     EGLBoolean getAttribValue(EGLConfig config, EGLint attribIdxi, EGLint * value);
79     EGLBoolean setAttribValue(EGLConfig config, EGLint attribIdxi, EGLint value);
80     void     processConfigs();
81 
82 private:
83     pthread_mutex_t m_lock;
84     bool m_initialized;
85     int  m_major;
86     int  m_minor;
87     int  m_hostRendererVersion;
88     int  m_numConfigs;
89     int  m_numConfigAttribs;
90 
91     /* This is the mapping between an attribute name to it's index in any given config */
92     std::map<EGLint, EGLint>    m_attribs;
93     /* 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>)
94      * v[0,0],..,v[0,m_numConfigAttribs-1],
95      *...
96      * v[m_numConfigs-1,0],..,v[m_numConfigs-1,m_numConfigAttribs-1]
97      */
98     EGLint *m_configs;
99     EGLClient_glesInterface *m_gles_iface;
100     EGLClient_glesInterface *m_gles2_iface;
101     char *m_versionString;
102     char *m_vendorString;
103     char *m_extensionString;
104 
105 #if __cplusplus >= 201103L
106     typedef std::unordered_set<EGLContext> EGLContextSet;
107     typedef std::unordered_set<EGLSurface> EGLSurfaceSet;
108 #else
109     typedef std::hash_set<EGLContext> EGLContextSet;
110     typedef std::hash_set<EGLSurface> EGLSurfaceSet;
111 #endif
112     EGLContextSet m_contexts;
113     EGLSurfaceSet m_surfaces;
114     pthread_mutex_t m_ctxLock;
115     pthread_mutex_t m_surfaceLock;
116 };
117 
118 #endif
119