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