1 /* 2 ** Copyright 2007, 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 17 #ifndef ANDROID_EGL_DISPLAY_H 18 #define ANDROID_EGL_DISPLAY_H 19 20 21 #include <ctype.h> 22 #include <stdint.h> 23 #include <stdlib.h> 24 25 #include <EGL/egl.h> 26 #include <EGL/eglext.h> 27 #include <GLES/gl.h> 28 #include <GLES/glext.h> 29 30 #include <utils/SortedVector.h> 31 #include <utils/threads.h> 32 #include <utils/String8.h> 33 34 #include "egldefs.h" 35 #include "hooks.h" 36 37 // ---------------------------------------------------------------------------- 38 namespace android { 39 // ---------------------------------------------------------------------------- 40 41 class egl_object_t; 42 class egl_connection_t; 43 44 // ---------------------------------------------------------------------------- 45 46 struct egl_config_t { 47 egl_config_t() {} 48 egl_config_t(int impl, EGLConfig config) 49 : impl(impl), config(config), configId(0), implConfigId(0) { } 50 int impl; // the implementation this config is for 51 EGLConfig config; // the implementation's EGLConfig 52 EGLint configId; // our CONFIG_ID 53 EGLint implConfigId; // the implementation's CONFIG_ID 54 inline bool operator < (const egl_config_t& rhs) const { 55 if (impl < rhs.impl) return true; 56 if (impl > rhs.impl) return false; 57 return config < rhs.config; 58 } 59 }; 60 61 // ---------------------------------------------------------------------------- 62 63 class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes 64 static egl_display_t sDisplay[NUM_DISPLAYS]; 65 EGLDisplay getDisplay(EGLNativeDisplayType display); 66 67 public: 68 enum { 69 NOT_INITIALIZED = 0, 70 INITIALIZED = 1, 71 TERMINATED = 2 72 }; 73 74 egl_display_t(); 75 ~egl_display_t(); 76 77 EGLBoolean initialize(EGLint *major, EGLint *minor); 78 EGLBoolean terminate(); 79 80 // add object to this display's list 81 void addObject(egl_object_t* object); 82 // remove object from this display's list 83 void removeObject(egl_object_t* object); 84 // add reference to this object. returns true if this is a valid object. 85 bool getObject(egl_object_t* object) const; 86 87 88 static egl_display_t* get(EGLDisplay dpy); 89 static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp); 90 91 inline bool isReady() const { return (refs > 0); } 92 inline bool isValid() const { return magic == '_dpy'; } 93 inline bool isAlive() const { return isValid(); } 94 95 char const * getVendorString() const { return mVendorString.string(); } 96 char const * getVersionString() const { return mVersionString.string(); } 97 char const * getClientApiString() const { return mClientApiString.string(); } 98 char const * getExtensionString() const { return mExtensionString.string(); } 99 100 inline uint32_t getRefsCount() const { return refs; } 101 102 struct strings_t { 103 char const * vendor; 104 char const * version; 105 char const * clientApi; 106 char const * extensions; 107 }; 108 109 struct DisplayImpl { 110 DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), 111 state(NOT_INITIALIZED), numConfigs(0) { } 112 EGLDisplay dpy; 113 EGLConfig* config; 114 EGLint state; 115 EGLint numConfigs; 116 strings_t queryString; 117 }; 118 119 private: 120 uint32_t magic; 121 122 public: 123 DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS]; 124 EGLint numTotalConfigs; 125 egl_config_t* configs; 126 127 private: 128 uint32_t refs; 129 mutable Mutex lock; 130 SortedVector<egl_object_t*> objects; 131 String8 mVendorString; 132 String8 mVersionString; 133 String8 mClientApiString; 134 String8 mExtensionString; 135 }; 136 137 // ---------------------------------------------------------------------------- 138 139 inline egl_display_t* get_display(EGLDisplay dpy) { 140 return egl_display_t::get(dpy); 141 } 142 143 // ---------------------------------------------------------------------------- 144 145 egl_display_t* validate_display(EGLDisplay dpy); 146 egl_connection_t* validate_display_config(EGLDisplay dpy, 147 EGLConfig config, egl_display_t const*& dp); 148 EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx); 149 EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface); 150 151 // ---------------------------------------------------------------------------- 152 }; // namespace android 153 // ---------------------------------------------------------------------------- 154 155 #endif // ANDROID_EGL_DISPLAY_H 156