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> |
| 32 | |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame^] | 33 | #include "egldefs.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 34 | #include "hooks.h" |
| 35 | |
| 36 | // ---------------------------------------------------------------------------- |
| 37 | namespace android { |
| 38 | // ---------------------------------------------------------------------------- |
| 39 | |
| 40 | class egl_object_t; |
| 41 | class egl_connection_t; |
| 42 | |
| 43 | // ---------------------------------------------------------------------------- |
| 44 | |
| 45 | struct egl_config_t { |
| 46 | egl_config_t() {} |
| 47 | egl_config_t(int impl, EGLConfig config) |
| 48 | : impl(impl), config(config), configId(0), implConfigId(0) { } |
| 49 | int impl; // the implementation this config is for |
| 50 | EGLConfig config; // the implementation's EGLConfig |
| 51 | EGLint configId; // our CONFIG_ID |
| 52 | EGLint implConfigId; // the implementation's CONFIG_ID |
| 53 | inline bool operator < (const egl_config_t& rhs) const { |
| 54 | if (impl < rhs.impl) return true; |
| 55 | if (impl > rhs.impl) return false; |
| 56 | return config < rhs.config; |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | // ---------------------------------------------------------------------------- |
| 61 | |
| 62 | class egl_display_t { |
| 63 | static egl_display_t sDisplay[NUM_DISPLAYS]; |
| 64 | EGLDisplay getDisplay(EGLNativeDisplayType display); |
| 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. |
| 84 | bool getObject(egl_object_t* object); |
| 85 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 86 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 87 | static egl_display_t* get(EGLDisplay dpy); |
| 88 | static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp); |
| 89 | |
| 90 | inline bool isReady() const { return (refs > 0); } |
| 91 | inline bool isValid() const { return magic == '_dpy'; } |
| 92 | inline bool isAlive() const { return isValid(); } |
| 93 | |
| 94 | struct strings_t { |
| 95 | char const * vendor; |
| 96 | char const * version; |
| 97 | char const * clientApi; |
| 98 | char const * extensions; |
| 99 | }; |
| 100 | |
| 101 | struct DisplayImpl { |
| 102 | DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), |
| 103 | state(NOT_INITIALIZED), numConfigs(0) { } |
| 104 | EGLDisplay dpy; |
| 105 | EGLConfig* config; |
| 106 | EGLint state; |
| 107 | EGLint numConfigs; |
| 108 | strings_t queryString; |
| 109 | }; |
| 110 | |
| 111 | private: |
| 112 | uint32_t magic; |
| 113 | |
| 114 | public: |
| 115 | DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS]; |
| 116 | EGLint numTotalConfigs; |
| 117 | egl_config_t* configs; |
| 118 | |
| 119 | private: |
| 120 | uint32_t refs; |
| 121 | Mutex lock; |
| 122 | SortedVector<egl_object_t*> objects; |
| 123 | }; |
| 124 | |
| 125 | // ---------------------------------------------------------------------------- |
| 126 | |
| 127 | inline egl_display_t* get_display(EGLDisplay dpy) { |
| 128 | return egl_display_t::get(dpy); |
| 129 | } |
| 130 | |
| 131 | // ---------------------------------------------------------------------------- |
| 132 | |
| 133 | egl_display_t* validate_display(EGLDisplay dpy); |
| 134 | egl_connection_t* validate_display_config(EGLDisplay dpy, |
| 135 | EGLConfig config, egl_display_t const*& dp); |
| 136 | EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx); |
| 137 | EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface); |
| 138 | |
| 139 | // ---------------------------------------------------------------------------- |
| 140 | }; // namespace android |
| 141 | // ---------------------------------------------------------------------------- |
| 142 | |
| 143 | #endif // ANDROID_EGL_DISPLAY_H |
| 144 | |