| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 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> | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 32 | #include <utils/String8.h> | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 33 |  | 
| Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 34 | #include "egldefs.h" | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 35 | #include "hooks.h" | 
|  | 36 |  | 
|  | 37 | // ---------------------------------------------------------------------------- | 
|  | 38 | namespace android { | 
|  | 39 | // ---------------------------------------------------------------------------- | 
|  | 40 |  | 
|  | 41 | class egl_object_t; | 
| Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 42 | class egl_context_t; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 43 | class egl_connection_t; | 
|  | 44 |  | 
|  | 45 | // ---------------------------------------------------------------------------- | 
|  | 46 |  | 
|  | 47 | struct egl_config_t { | 
|  | 48 | egl_config_t() {} | 
|  | 49 | egl_config_t(int impl, EGLConfig config) | 
|  | 50 | : impl(impl), config(config), configId(0), implConfigId(0) { } | 
|  | 51 | int         impl;           // the implementation this config is for | 
|  | 52 | EGLConfig   config;         // the implementation's EGLConfig | 
|  | 53 | EGLint      configId;       // our CONFIG_ID | 
|  | 54 | EGLint      implConfigId;   // the implementation's CONFIG_ID | 
|  | 55 | inline bool operator < (const egl_config_t& rhs) const { | 
|  | 56 | if (impl < rhs.impl) return true; | 
|  | 57 | if (impl > rhs.impl) return false; | 
|  | 58 | return config < rhs.config; | 
|  | 59 | } | 
|  | 60 | }; | 
|  | 61 |  | 
|  | 62 | // ---------------------------------------------------------------------------- | 
|  | 63 |  | 
| Jamie Gennis | 98c6383 | 2011-11-07 17:03:54 -0800 | [diff] [blame] | 64 | class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 65 | static egl_display_t sDisplay[NUM_DISPLAYS]; | 
|  | 66 | EGLDisplay getDisplay(EGLNativeDisplayType display); | 
| Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 67 | void loseCurrentImpl(egl_context_t * cur_c); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 68 |  | 
|  | 69 | public: | 
|  | 70 | enum { | 
|  | 71 | NOT_INITIALIZED = 0, | 
|  | 72 | INITIALIZED     = 1, | 
|  | 73 | TERMINATED      = 2 | 
|  | 74 | }; | 
|  | 75 |  | 
|  | 76 | egl_display_t(); | 
|  | 77 | ~egl_display_t(); | 
|  | 78 |  | 
|  | 79 | EGLBoolean initialize(EGLint *major, EGLint *minor); | 
|  | 80 | EGLBoolean terminate(); | 
|  | 81 |  | 
|  | 82 | // add object to this display's list | 
|  | 83 | void addObject(egl_object_t* object); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 84 | // remove object from this display's list | 
|  | 85 | void removeObject(egl_object_t* object); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 86 | // add reference to this object. returns true if this is a valid object. | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 87 | bool getObject(egl_object_t* object) const; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 88 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 89 | static egl_display_t* get(EGLDisplay dpy); | 
|  | 90 | static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp); | 
|  | 91 |  | 
| Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 92 | EGLBoolean makeCurrent(egl_context_t* c, egl_context_t* cur_c, | 
|  | 93 | EGLSurface draw, EGLSurface read, EGLContext ctx, | 
|  | 94 | EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx); | 
|  | 95 | static void loseCurrent(egl_context_t * cur_c); | 
|  | 96 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 97 | inline bool isReady() const { return (refs > 0); } | 
|  | 98 | inline bool isValid() const { return magic == '_dpy'; } | 
|  | 99 | inline bool isAlive() const { return isValid(); } | 
|  | 100 |  | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 101 | char const * getVendorString() const { return mVendorString.string(); } | 
|  | 102 | char const * getVersionString() const { return mVersionString.string(); } | 
|  | 103 | char const * getClientApiString() const { return mClientApiString.string(); } | 
|  | 104 | char const * getExtensionString() const { return mExtensionString.string(); } | 
|  | 105 |  | 
| Romain Guy | 4725e2c | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 106 | inline uint32_t getRefsCount() const { return refs; } | 
|  | 107 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 108 | struct strings_t { | 
|  | 109 | char const * vendor; | 
|  | 110 | char const * version; | 
|  | 111 | char const * clientApi; | 
|  | 112 | char const * extensions; | 
|  | 113 | }; | 
|  | 114 |  | 
|  | 115 | struct DisplayImpl { | 
|  | 116 | DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), | 
|  | 117 | state(NOT_INITIALIZED), numConfigs(0) { } | 
|  | 118 | EGLDisplay  dpy; | 
|  | 119 | EGLConfig*  config; | 
|  | 120 | EGLint      state; | 
|  | 121 | EGLint      numConfigs; | 
|  | 122 | strings_t   queryString; | 
|  | 123 | }; | 
|  | 124 |  | 
|  | 125 | private: | 
|  | 126 | uint32_t        magic; | 
|  | 127 |  | 
|  | 128 | public: | 
|  | 129 | DisplayImpl     disp[IMPL_NUM_IMPLEMENTATIONS]; | 
|  | 130 | EGLint          numTotalConfigs; | 
|  | 131 | egl_config_t*   configs; | 
|  | 132 |  | 
|  | 133 | private: | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 134 | uint32_t                    refs; | 
|  | 135 | mutable Mutex                       lock; | 
|  | 136 | SortedVector<egl_object_t*> objects; | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 137 | String8 mVendorString; | 
|  | 138 | String8 mVersionString; | 
|  | 139 | String8 mClientApiString; | 
|  | 140 | String8 mExtensionString; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 141 | }; | 
|  | 142 |  | 
|  | 143 | // ---------------------------------------------------------------------------- | 
|  | 144 |  | 
|  | 145 | inline egl_display_t* get_display(EGLDisplay dpy) { | 
|  | 146 | return egl_display_t::get(dpy); | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | // ---------------------------------------------------------------------------- | 
|  | 150 |  | 
|  | 151 | egl_display_t* validate_display(EGLDisplay dpy); | 
|  | 152 | egl_connection_t* validate_display_config(EGLDisplay dpy, | 
|  | 153 | EGLConfig config, egl_display_t const*& dp); | 
|  | 154 | EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx); | 
|  | 155 | EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface); | 
|  | 156 |  | 
|  | 157 | // ---------------------------------------------------------------------------- | 
|  | 158 | }; // namespace android | 
|  | 159 | // ---------------------------------------------------------------------------- | 
|  | 160 |  | 
|  | 161 | #endif // ANDROID_EGL_DISPLAY_H |