• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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* getDisplay(EGLNativeDisplayType dpy) const;
59 
60 #ifndef ANDROID
61     // Return the EglDisplay instance corresponding to a given EGLDisplay |dpy|
62     // value. NULL if none matches.
63     EglDisplay* getDisplay(EGLDisplay dpy) const;
64 #endif
65 
66     // Remove a given EGLDisplay identified by |dpy|.
67     bool removeDisplay(EGLDisplay dpy);
68 
69     // Return the default native internal display handle.
getDefaultNativeDisplay()70     EglOS::Display* getDefaultNativeDisplay() const {
71         return m_display;
72     };
73 
74     // Return the default engine handle.
getOsEngine()75     EglOS::Engine* getOsEngine() const {
76         return m_engine;
77     }
78 
79     // Set the GLES interface pointer corresponding to a given GLES version.
80     // |iface| is a pointer to a structure containing function pointers
81     // related to a specific GLES version.
82     // |ver| is a version identifier, e.g. GLES_1_1 or GLES_2_0.
setIface(const GLESiface * iface,GLESVersion ver)83     void setIface(const GLESiface* iface, GLESVersion ver) {
84         m_gles_ifaces[ver] = iface;
85     };
86 
setEglIface(const EGLiface * iface)87     void setEglIface(const EGLiface* iface) {
88         m_eglIface = iface;
89     }
90 
getEglIface()91     const EGLiface* getEglIface() {
92         return m_eglIface;
93     }
94 
95     // Return the current GLES interface pointer for a given GLES version.
96     // |ver| is a version identifier, e.g. GLES_1_1 or GLES_2_0.
getIface(GLESVersion ver)97     const GLESiface* getIface(GLESVersion ver) const {
98         return m_gles_ifaces[ver];
99     }
100 
101     // Initialize the table of extension functions for a given GLES version
102     // |ver|. This must be called after setIface() for the corresponding
103     // version.
104     void initClientExtFuncTable(GLESVersion ver);
105 
106     void markSurfaceForDestroy(EglDisplay* display,
107                                EGLSurface toDestroy);
108 
109     // Only call this if there is a suitable context bound, or no
110     // actual deleting will happen at the host driver level.
111     void sweepDestroySurfaces();
112 
113     // setEgl2Egl(true) to enable egl on top of another egl.
114     // Must be called before instantiation.
115     static void setEgl2Egl(EGLBoolean enable, bool nullEgl = false);
116     static bool isEgl2Egl();
117 
118     // isEgl2EglSyncSafeToUse
119     static void setEgl2EglSyncSafeToUse(EGLBoolean enable);
120     static bool isEgl2EglSyncSafeToUse();
121 
122     EglGlobalInfo(bool nullEgl);
123     ~EglGlobalInfo();
124 
125 private:
126 
127     std::vector<EglDisplay*>       m_displays;
128 
129     std::vector<std::pair<EglDisplay*, EGLSurface> >
130                                    m_surfaceDestroyList;
131 
132     EglOS::Engine*                 m_engine = nullptr;
133     EglOS::Display*                m_display = nullptr;
134     const GLESiface*               m_gles_ifaces[MAX_GLES_VERSION] = {};
135     const EGLiface*                m_eglIface = nullptr;
136     bool                           m_gles_extFuncs_inited[MAX_GLES_VERSION] = {};
137     mutable android::base::Lock           m_lock;
138 };
139 
140 #endif
141