egl_display.h revision 4b9511c16195a646242eff833b0af212933b6eca
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; 42518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianclass egl_connection_t; 43518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 44518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 45518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 46518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstruct egl_config_t { 47518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_config_t() {} 48518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_config_t(int impl, EGLConfig config) 49518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian : impl(impl), config(config), configId(0), implConfigId(0) { } 50518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian int impl; // the implementation this config is for 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 if (impl < rhs.impl) return true; 56518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (impl > rhs.impl) return false; 57518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return config < rhs.config; 58518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 59518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 60518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 61518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 62518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 6398c6383580f94bb7ff9cc9a7cc24d8b8519e484aJamie Gennisclass EGLAPI egl_display_t { // marked as EGLAPI for testing purposes 64518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian static egl_display_t sDisplay[NUM_DISPLAYS]; 65518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay getDisplay(EGLNativeDisplayType display); 66518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 67518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianpublic: 68518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian enum { 69518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NOT_INITIALIZED = 0, 70518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian INITIALIZED = 1, 71518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian TERMINATED = 2 72518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 73518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 74518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t(); 75518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ~egl_display_t(); 76518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 77518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean initialize(EGLint *major, EGLint *minor); 78518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean terminate(); 79518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 80518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // add object to this display's list 81518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian void addObject(egl_object_t* object); 825b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // remove object from this display's list 835b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian void removeObject(egl_object_t* object); 84518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // add reference to this object. returns true if this is a valid object. 85f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian bool getObject(egl_object_t* object) const; 86518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 875b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian 88518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian static egl_display_t* get(EGLDisplay dpy); 89518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp); 90518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 91518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian inline bool isReady() const { return (refs > 0); } 92518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian inline bool isValid() const { return magic == '_dpy'; } 93518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian inline bool isAlive() const { return isValid(); } 94518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 954b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getVendorString() const { return mVendorString.string(); } 964b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getVersionString() const { return mVersionString.string(); } 974b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getClientApiString() const { return mClientApiString.string(); } 984b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const * getExtensionString() const { return mExtensionString.string(); } 994b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 1004725e2ca8050250813afcdcac1330244c6e0f5aeRomain Guy inline uint32_t getRefsCount() const { return refs; } 1014725e2ca8050250813afcdcac1330244c6e0f5aeRomain Guy 102518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian struct strings_t { 103518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * vendor; 104518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * version; 105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * clientApi; 106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian char const * extensions; 107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian struct DisplayImpl { 110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), 111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian state(NOT_INITIALIZED), numConfigs(0) { } 112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy; 113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig* config; 114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint state; 115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint numConfigs; 116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian strings_t queryString; 117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianprivate: 120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian uint32_t magic; 121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianpublic: 123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS]; 124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint numTotalConfigs; 125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_config_t* configs; 126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianprivate: 128f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian uint32_t refs; 129f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian mutable Mutex lock; 130f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SortedVector<egl_object_t*> objects; 1314b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mVendorString; 1324b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mVersionString; 1334b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mClientApiString; 1344b9511c16195a646242eff833b0af212933b6ecaMathias Agopian String8 mExtensionString; 135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianinline egl_display_t* get_display(EGLDisplay dpy) { 140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return egl_display_t::get(dpy); 141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_display_t* validate_display(EGLDisplay dpy); 146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_connection_t* validate_display_config(EGLDisplay dpy, 147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config, egl_display_t const*& dp); 148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx); 149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface); 150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 152518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; // namespace android 153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 154518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif // ANDROID_EGL_DISPLAY_H 156