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 #include "GLClientState.h" 26 27 #if __cplusplus >= 201103L 28 #include <unordered_set> 29 #else 30 #include <hash_set> 31 #endif 32 33 #include <map> 34 35 #define ATTRIBUTE_NONE (-1) 36 //FIXME: are we in this namespace? 37 using namespace android; 38 39 class eglDisplay 40 { 41 public: 42 eglDisplay(); 43 ~eglDisplay(); 44 45 bool initialize(EGLClient_eglInterface *eglIface); 46 void terminate(); 47 getVersionMajor()48 int getVersionMajor() const { return m_major; } getVersionMinor()49 int getVersionMinor() const { return m_minor; } initialized()50 bool initialized() const { return m_initialized; } 51 52 const char *queryString(EGLint name); 53 gles_iface()54 const EGLClient_glesInterface *gles_iface() const { return m_gles_iface; } gles2_iface()55 const EGLClient_glesInterface *gles2_iface() const { return m_gles2_iface; } 56 getNumConfigs()57 int getNumConfigs(){ return m_numConfigs; } 58 59 EGLConfig getConfigAtIndex(uint32_t index) const; 60 uint32_t getIndexOfConfig(EGLConfig config) const; 61 bool isValidConfig(EGLConfig cfg) const; 62 63 EGLBoolean getConfigAttrib(EGLConfig config, EGLint attrib, EGLint * value); 64 EGLBoolean setConfigAttrib(EGLConfig config, EGLint attrib, EGLint value); 65 EGLBoolean getConfigGLPixelFormat(EGLConfig config, GLenum * format); 66 EGLBoolean getConfigNativePixelFormat(EGLConfig config, uint32_t * format); 67 68 void dumpConfig(EGLConfig config); 69 70 void onCreateContext(EGLContext ctx); 71 void onCreateSurface(EGLSurface surface); 72 73 void onDestroyContext(EGLContext ctx); 74 void onDestroySurface(EGLSurface surface); 75 76 bool isContext(EGLContext ctx); 77 bool isSurface(EGLSurface ctx); 78 79 // Needs a current context (put this near eglMakeCurrent) 80 HostDriverCaps getHostDriverCaps(int majorVersion, int minorVersion); 81 82 private: 83 EGLClient_glesInterface *loadGLESClientAPI(const char *libName, 84 EGLClient_eglInterface *eglIface, 85 void **libHandle); 86 EGLBoolean getAttribValue(EGLConfig config, EGLint attribIdxi, EGLint * value); 87 EGLBoolean setAttribValue(EGLConfig config, EGLint attribIdxi, EGLint value); 88 void processConfigs(); 89 90 private: 91 pthread_mutex_t m_lock; 92 bool m_initialized; 93 int m_major; 94 int m_minor; 95 int m_hostRendererVersion; 96 int m_numConfigs; 97 int m_numConfigAttribs; 98 99 /* This is the mapping between an attribute name to it's index in any given config */ 100 std::map<EGLint, EGLint> m_attribs; 101 /* 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>) 102 * v[0,0],..,v[0,m_numConfigAttribs-1], 103 *... 104 * v[m_numConfigs-1,0],..,v[m_numConfigs-1,m_numConfigAttribs-1] 105 */ 106 EGLint *m_configs; 107 EGLClient_glesInterface *m_gles_iface; 108 EGLClient_glesInterface *m_gles2_iface; 109 char *m_versionString; 110 char *m_vendorString; 111 char *m_extensionString; 112 113 #if __cplusplus >= 201103L 114 typedef std::unordered_set<EGLContext> EGLContextSet; 115 typedef std::unordered_set<EGLSurface> EGLSurfaceSet; 116 #else 117 typedef std::hash_set<EGLContext> EGLContextSet; 118 typedef std::hash_set<EGLSurface> EGLSurfaceSet; 119 #endif 120 EGLContextSet m_contexts; 121 EGLSurfaceSet m_surfaces; 122 pthread_mutex_t m_ctxLock; 123 pthread_mutex_t m_surfaceLock; 124 125 int m_hostDriverCaps_knownMajorVersion; 126 int m_hostDriverCaps_knownMinorVersion; 127 HostDriverCaps m_hostDriverCaps; 128 }; 129 130 #endif 131