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