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 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, PixelFormat * 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 private: 80 EGLClient_glesInterface *loadGLESClientAPI(const char *libName, 81 EGLClient_eglInterface *eglIface, 82 void **libHandle); 83 EGLBoolean getAttribValue(EGLConfig config, EGLint attribIdxi, EGLint * value); 84 EGLBoolean setAttribValue(EGLConfig config, EGLint attribIdxi, EGLint value); 85 void processConfigs(); 86 87 private: 88 pthread_mutex_t m_lock; 89 bool m_initialized; 90 int m_major; 91 int m_minor; 92 int m_hostRendererVersion; 93 int m_numConfigs; 94 int m_numConfigAttribs; 95 96 /* This is the mapping between an attribute name to it's index in any given config */ 97 std::map<EGLint, EGLint> m_attribs; 98 /* 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>) 99 * v[0,0],..,v[0,m_numConfigAttribs-1], 100 *... 101 * v[m_numConfigs-1,0],..,v[m_numConfigs-1,m_numConfigAttribs-1] 102 */ 103 EGLint *m_configs; 104 EGLClient_glesInterface *m_gles_iface; 105 EGLClient_glesInterface *m_gles2_iface; 106 char *m_versionString; 107 char *m_vendorString; 108 char *m_extensionString; 109 110 #if __cplusplus >= 201103L 111 typedef std::unordered_set<EGLContext> EGLContextSet; 112 typedef std::unordered_set<EGLSurface> EGLSurfaceSet; 113 #else 114 typedef std::hash_set<EGLContext> EGLContextSet; 115 typedef std::hash_set<EGLSurface> EGLSurfaceSet; 116 #endif 117 EGLContextSet m_contexts; 118 EGLSurfaceSet m_surfaces; 119 pthread_mutex_t m_ctxLock; 120 pthread_mutex_t m_surfaceLock; 121 }; 122 123 #endif 124