egl_display.h revision 7db993a98b9239bd4e384cc4aa128262fe3cf52c
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// ---------------------------------------------------------------------------- 38namespace android { 39// ---------------------------------------------------------------------------- 40 41class egl_object_t; 42class egl_context_t; 43class egl_connection_t; 44 45// ---------------------------------------------------------------------------- 46 47class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes 48 static egl_display_t sDisplay[NUM_DISPLAYS]; 49 EGLDisplay getDisplay(EGLNativeDisplayType display); 50 void loseCurrentImpl(egl_context_t * cur_c); 51 52public: 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); 67 // remove object from this display's list 68 void removeObject(egl_object_t* object); 69 // add reference to this object. returns true if this is a valid object. 70 bool getObject(egl_object_t* object) const; 71 72 static egl_display_t* get(EGLDisplay dpy); 73 static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp); 74 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 80 inline bool isReady() const { return (refs > 0); } 81 inline bool isValid() const { return magic == '_dpy'; } 82 inline bool isAlive() const { return isValid(); } 83 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 89 inline uint32_t getRefsCount() const { return refs; } 90 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 { 99 DisplayImpl() : dpy(EGL_NO_DISPLAY), state(NOT_INITIALIZED) { } 100 EGLDisplay dpy; 101 EGLint state; 102 strings_t queryString; 103 }; 104 105private: 106 uint32_t magic; 107 108public: 109 DisplayImpl disp; 110 bool finishOnSwap; 111 112private: 113 uint32_t refs; 114 mutable Mutex lock; 115 SortedVector<egl_object_t*> objects; 116 String8 mVendorString; 117 String8 mVersionString; 118 String8 mClientApiString; 119 String8 mExtensionString; 120}; 121 122// ---------------------------------------------------------------------------- 123 124inline egl_display_t* get_display(EGLDisplay dpy) { 125 return egl_display_t::get(dpy); 126} 127 128// ---------------------------------------------------------------------------- 129 130egl_display_t* validate_display(EGLDisplay dpy); 131egl_connection_t* validate_display_config(EGLDisplay dpy, 132 EGLConfig config, egl_display_t const*& dp); 133EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx); 134EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface); 135 136// ---------------------------------------------------------------------------- 137}; // namespace android 138// ---------------------------------------------------------------------------- 139 140#endif // ANDROID_EGL_DISPLAY_H 141