egl_display.h revision ada798b7ca7cabc255aa159964b64975e7fdb2df
1518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian/* 2518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Copyright 2007, The Android Open Source Project 3518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 4518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Licensed under the Apache License, Version 2.0 (the "License"); 5518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** you may not use this file except in compliance with the License. 6518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** You may obtain a copy of the License at 7518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 8518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** http://www.apache.org/licenses/LICENSE-2.0 9518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 10518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Unless required by applicable law or agreed to in writing, software 11518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** distributed under the License is distributed on an "AS IS" BASIS, 12518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** See the License for the specific language governing permissions and 14518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** limitations under the License. 15518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 16518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 17518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#ifndef ANDROID_EGL_DISPLAY_H 18518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#define ANDROID_EGL_DISPLAY_H 19518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 20518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 21518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <ctype.h> 22518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <stdint.h> 23518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <stdlib.h> 24518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 25518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <EGL/egl.h> 26518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <EGL/eglext.h> 27518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <GLES/gl.h> 28518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <GLES/glext.h> 29518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 30518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/SortedVector.h> 31518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/threads.h> 324b9511c16195a646242eff833b0af212933b6ecaMathias Agopian#include <utils/String8.h> 33518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 341cadb25da1ed875bdd078270e642966724a0c39aMathias Agopian#include "egldefs.h" 35518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "hooks.h" 36518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 37518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 38518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiannamespace android { 39518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 40518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 41518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianclass egl_object_t; 42fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopianclass egl_context_t; 43518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianclass egl_connection_t; 44518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 45518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 46518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 47518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstruct egl_config_t { 48518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_config_t() {} 49ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_config_t(EGLConfig config) 50ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian : config(config), configId(0), implConfigId(0) { } 51518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config; // the implementation's EGLConfig 52518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint configId; // our CONFIG_ID 53518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint implConfigId; // the implementation's CONFIG_ID 54518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian inline bool operator < (const egl_config_t& rhs) const { 55518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return config < rhs.config; 56518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 57518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 58518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 59518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 60518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 6198c6383580f94bb7ff9cc9a7cc24d8b8519e484aJamie Gennisclass EGLAPI egl_display_t { // marked as EGLAPI for testing purposes 62518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian static egl_display_t sDisplay[NUM_DISPLAYS]; 63518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay getDisplay(EGLNativeDisplayType display); 64a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian void loseCurrentImpl(egl_context_t * cur_c); 65518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 66518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianpublic: 67518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian enum { 68518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NOT_INITIALIZED = 0, 69518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian INITIALIZED = 1, 70518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian TERMINATED = 2 71518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 72518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 73518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t(); 74518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ~egl_display_t(); 75518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 76518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean initialize(EGLint *major, EGLint *minor); 77518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean terminate(); 78518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 79518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // add object to this display's list 80518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian void addObject(egl_object_t* object); 815b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // remove object from this display's list 825b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian void removeObject(egl_object_t* object); 83518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // add reference to this object. returns true if this is a valid object. 84f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian bool getObject(egl_object_t* object) const; 85518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 86518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian static egl_display_t* get(EGLDisplay dpy); 87518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp); 88518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 89fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian EGLBoolean makeCurrent(egl_context_t* c, egl_context_t* cur_c, 90fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian EGLSurface draw, EGLSurface read, EGLContext ctx, 91fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx); 92fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian static void loseCurrent(egl_context_t * cur_c); 93fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian 94518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian inline bool isReady() const { return (refs > 0); } 95518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian inline bool isValid() const { return magic == '_dpy'; } 96518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian inline bool isAlive() const { return isValid(); } 97518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 984b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getVendorString() const { return mVendorString.string(); } 994b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getVersionString() const { return mVersionString.string(); } 1004b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getClientApiString() const { return mClientApiString.string(); } 1014b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getExtensionString() const { return mExtensionString.string(); } 1024b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 1034725e2ca8050250813afcdcac1330244c6e0f5aeRomain Guy inline uint32_t getRefsCount() const { return refs; } 1044725e2ca8050250813afcdcac1330244c6e0f5aeRomain Guy 105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian struct strings_t { 106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * vendor; 107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * version; 108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * clientApi; 109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * extensions; 110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian struct DisplayImpl { 113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), 114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian state(NOT_INITIALIZED), numConfigs(0) { } 115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy; 116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig* config; 117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint state; 118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint numConfigs; 119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian strings_t queryString; 120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianprivate: 123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian uint32_t magic; 124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianpublic: 126ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian DisplayImpl disp; 127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint numTotalConfigs; 128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_config_t* configs; 129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianprivate: 131f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian uint32_t refs; 132f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian mutable Mutex lock; 133f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SortedVector<egl_object_t*> objects; 1344b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mVendorString; 1354b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mVersionString; 1364b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mClientApiString; 1374b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mExtensionString; 138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianinline egl_display_t* get_display(EGLDisplay dpy) { 143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return egl_display_t::get(dpy); 144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_display_t* validate_display(EGLDisplay dpy); 149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_connection_t* validate_display_config(EGLDisplay dpy, 150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config, egl_display_t const*& dp); 151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx); 152518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface); 153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 154518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; // namespace android 156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 158518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif // ANDROID_EGL_DISPLAY_H 159