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 48 int getVersionMajor() const { return m_major; } 49 int getVersionMinor() const { return m_minor; } 50 bool initialized() const { return m_initialized; } 51 52 const char *queryString(EGLint name); 53 54 const EGLClient_glesInterface *gles_iface() const { return m_gles_iface; } 55 const EGLClient_glesInterface *gles2_iface() const { return m_gles2_iface; } 56 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 71 bool isContext(EGLContext ctx); 72 bool isSurface(EGLSurface ctx); 73 private: 74 EGLClient_glesInterface *loadGLESClientAPI(const char *libName, 75 EGLClient_eglInterface *eglIface, 76 void **libHandle); 77 EGLBoolean getAttribValue(EGLConfig config, EGLint attribIdxi, EGLint * value); 78 EGLBoolean setAttribValue(EGLConfig config, EGLint attribIdxi, EGLint value); 79 void processConfigs(); 80 81 private: 82 pthread_mutex_t m_lock; 83 bool m_initialized; 84 int m_major; 85 int m_minor; 86 int m_hostRendererVersion; 87 int m_numConfigs; 88 int m_numConfigAttribs; 89 90 /* This is the mapping between an attribute name to it's index in any given config */ 91 DefaultKeyedVector<EGLint, EGLint> m_attribs; 92 /* 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>) 93 * v[0,0],..,v[0,m_numConfigAttribs-1], 94 *... 95 * v[m_numConfigs-1,0],..,v[m_numConfigs-1,m_numConfigAttribs-1] 96 */ 97 EGLint *m_configs; 98 EGLClient_glesInterface *m_gles_iface; 99 EGLClient_glesInterface *m_gles2_iface; 100 char *m_versionString; 101 char *m_vendorString; 102 char *m_extensionString; 103 104 #if __cplusplus >= 201103L 105 typedef std::unordered_set<EGLContext> EGLContextSet; 106 typedef std::unordered_set<EGLSurface> EGLSurfaceSet; 107 #else 108 typedef std::hash_set<EGLContext> EGLContextSet; 109 typedef std::hash_set<EGLSurface> EGLSurfaceSet; 110 #endif 111 EGLContextSet m_contexts; 112 EGLSurfaceSet m_surfaces; 113 pthread_mutex_t m_ctxLock; 114 pthread_mutex_t m_surfaceLock; 115 }; 116 117 #endif 118