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 #include <ui/PixelFormat.h>
27 
28 #define ATTRIBUTE_NONE -1
29 //FIXME: are we in this namespace?
30 using namespace android;
31 
32 class eglDisplay
33 {
34 public:
35     eglDisplay();
36     ~eglDisplay();
37 
38     bool initialize(EGLClient_eglInterface *eglIface);
39     void terminate();
40 
getVersionMajor()41     int getVersionMajor() const { return m_major; }
getVersionMinor()42     int getVersionMinor() const { return m_minor; }
initialized()43     bool initialized() const { return m_initialized; }
44 
45     const char *queryString(EGLint name);
46 
gles_iface()47     const EGLClient_glesInterface *gles_iface() const { return m_gles_iface; }
gles2_iface()48     const EGLClient_glesInterface *gles2_iface() const { return m_gles2_iface; }
49 
getNumConfigs()50     int     getNumConfigs(){ return m_numConfigs; }
51     EGLBoolean  getConfigAttrib(EGLConfig config, EGLint attrib, EGLint * value);
52     EGLBoolean  setConfigAttrib(EGLConfig config, EGLint attrib, EGLint value);
53     EGLBoolean getConfigGLPixelFormat(EGLConfig config, GLenum * format);
54     EGLBoolean getConfigNativePixelFormat(EGLConfig config, PixelFormat * format);
55 
56     void     dumpConfig(EGLConfig config);
57 private:
58     EGLClient_glesInterface *loadGLESClientAPI(const char *libName,
59                                                EGLClient_eglInterface *eglIface,
60                                                void **libHandle);
61     EGLBoolean getAttribValue(EGLConfig config, EGLint attribIdxi, EGLint * value);
62     EGLBoolean setAttribValue(EGLConfig config, EGLint attribIdxi, EGLint value);
63     void     processConfigs();
64 
65 private:
66     pthread_mutex_t m_lock;
67     bool m_initialized;
68     int  m_major;
69     int  m_minor;
70     int  m_hostRendererVersion;
71     int  m_numConfigs;
72     int  m_numConfigAttribs;
73 
74     /* This is the mapping between an attribute name to it's index in any given config */
75     DefaultKeyedVector<EGLint, EGLint>    m_attribs;
76     /* 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>)
77      * v[0,0],..,v[0,m_numConfigAttribs-1],
78      *...
79      * v[m_numConfigs-1,0],..,v[m_numConfigs-1,m_numConfigAttribs-1]
80      */
81     EGLint *m_configs;
82     EGLClient_glesInterface *m_gles_iface;
83     EGLClient_glesInterface *m_gles2_iface;
84     char *m_versionString;
85     char *m_vendorString;
86     char *m_extensionString;
87 };
88 
89 #endif
90