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 EGL_GLOBAL_INFO 17 #define EGL_GLOBAL_INFO 18 19 #include "EglDisplay.h" 20 #include "EglConfig.h" 21 #include "EglContext.h" 22 #include "EglOsApi.h" 23 24 #include "aemu/base/synchronization/Lock.h" 25 26 #include <GLcommon/TranslatorIfaces.h> 27 28 #include <EGL/egl.h> 29 30 #include <vector> 31 32 class EglDisplay; 33 34 // Holds all global information shared by the EGL implementation in a given 35 // process. This really amounts to: 36 // 37 // - A list of EglDisplay instances, each identified by an 38 // EGLNativeDisplayType and EglOS::Display*. 39 // 40 // - GLES interface function pointers for all supported GLES versions. 41 42 class EglGlobalInfo { 43 44 public: 45 // Returns a pointer to the process' single instance, which will be 46 // created on demand. This can be called multiple times, each call will 47 // increment an internal reference-count. 48 static EglGlobalInfo* getInstance(bool nullEgl = false); 49 50 // Create a new EglDisplay instance from an existing native |dpy| value. 51 // |idpy| is the corresponding native internal display type. See 52 // generateInternalDisplay() below to understand how they differ. 53 EglDisplay* addDisplay(EGLNativeDisplayType dpy, 54 EglOS::Display* idpy); 55 56 // Return the EglDisplay instance corresponding to a given native |dpy| 57 // value. 58 EglDisplay* getDisplayFromDisplayType(EGLNativeDisplayType dpy) const; 59 60 // Return the EglDisplay instance corresponding to a given EGLDisplay |dpy| 61 // value. NULL if none matches. 62 EglDisplay* getDisplay(EGLDisplay dpy) const; 63 64 // Remove a given EGLDisplay identified by |dpy|. 65 bool removeDisplay(EGLDisplay dpy); 66 67 // Return the default native internal display handle. getDefaultNativeDisplay()68 EglOS::Display* getDefaultNativeDisplay() const { 69 return m_display; 70 }; 71 72 // Return the default engine handle. getOsEngine()73 EglOS::Engine* getOsEngine() const { 74 return m_engine; 75 } 76 77 // Set the GLES interface pointer corresponding to a given GLES version. 78 // |iface| is a pointer to a structure containing function pointers 79 // related to a specific GLES version. 80 // |ver| is a version identifier, e.g. GLES_1_1 or GLES_2_0. setIface(const GLESiface * iface,GLESVersion ver)81 void setIface(const GLESiface* iface, GLESVersion ver) { 82 m_gles_ifaces[ver] = iface; 83 }; 84 setEglIface(const EGLiface * iface)85 void setEglIface(const EGLiface* iface) { 86 m_eglIface = iface; 87 } 88 getEglIface()89 const EGLiface* getEglIface() { 90 return m_eglIface; 91 } 92 93 // Return the current GLES interface pointer for a given GLES version. 94 // |ver| is a version identifier, e.g. GLES_1_1 or GLES_2_0. getIface(GLESVersion ver)95 const GLESiface* getIface(GLESVersion ver) const { 96 return m_gles_ifaces[ver]; 97 } 98 99 // Initialize the table of extension functions for a given GLES version 100 // |ver|. This must be called after setIface() for the corresponding 101 // version. 102 void initClientExtFuncTable(GLESVersion ver); 103 104 void markSurfaceForDestroy(EglDisplay* display, 105 EGLSurface toDestroy); 106 107 // Only call this if there is a suitable context bound, or no 108 // actual deleting will happen at the host driver level. 109 void sweepDestroySurfaces(); 110 111 // setEgl2Egl(true) to enable egl on top of another egl. 112 // Must be called before instantiation. 113 static void setEgl2Egl(EGLBoolean enable, bool nullEgl = false); 114 static bool isEgl2Egl(); 115 116 // isEgl2EglSyncSafeToUse 117 static void setEgl2EglSyncSafeToUse(EGLBoolean enable); 118 static bool isEgl2EglSyncSafeToUse(); 119 120 EglGlobalInfo(bool nullEgl); 121 ~EglGlobalInfo(); 122 123 private: 124 125 std::vector<EglDisplay*> m_displays; 126 127 std::vector<std::pair<EglDisplay*, EGLSurface> > 128 m_surfaceDestroyList; 129 130 EglOS::Engine* m_engine = nullptr; 131 EglOS::Display* m_display = nullptr; 132 const GLESiface* m_gles_ifaces[MAX_GLES_VERSION] = {}; 133 const EGLiface* m_eglIface = nullptr; 134 bool m_gles_extFuncs_inited[MAX_GLES_VERSION] = {}; 135 mutable android::base::Lock m_lock; 136 }; 137 138 #endif 139