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