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