blob: 94077bea1d997846b87d0b3960341e4ce861ba6c [file] [log] [blame]
Mathias Agopian518ec112011-05-13 16:21:08 -07001/*
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 Agopian1cadb252011-05-23 17:26:14 -070033#include "egldefs.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070034#include "hooks.h"
35
36// ----------------------------------------------------------------------------
37namespace android {
38// ----------------------------------------------------------------------------
39
40class egl_object_t;
41class egl_connection_t;
42
43// ----------------------------------------------------------------------------
44
45struct 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
Jamie Gennis98c63832011-11-07 17:03:54 -080062class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes
Mathias Agopian518ec112011-05-13 16:21:08 -070063 static egl_display_t sDisplay[NUM_DISPLAYS];
64 EGLDisplay getDisplay(EGLNativeDisplayType display);
65
66public:
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 Agopian5b287a62011-05-16 18:58:55 -070081 // remove object from this display's list
82 void removeObject(egl_object_t* object);
Mathias Agopian518ec112011-05-13 16:21:08 -070083 // add reference to this object. returns true if this is a valid object.
Mathias Agopianf0480de2011-11-13 20:50:07 -080084 bool getObject(egl_object_t* object) const;
Mathias Agopian518ec112011-05-13 16:21:08 -070085
Mathias Agopian5b287a62011-05-16 18:58:55 -070086
Mathias Agopian518ec112011-05-13 16:21:08 -070087 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
Romain Guy4725e2c2011-11-09 20:10:18 -080094 inline uint32_t getRefsCount() const { return refs; }
95
Mathias Agopian518ec112011-05-13 16:21:08 -070096 struct strings_t {
97 char const * vendor;
98 char const * version;
99 char const * clientApi;
100 char const * extensions;
101 };
102
103 struct DisplayImpl {
104 DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0),
105 state(NOT_INITIALIZED), numConfigs(0) { }
106 EGLDisplay dpy;
107 EGLConfig* config;
108 EGLint state;
109 EGLint numConfigs;
110 strings_t queryString;
111 };
112
113private:
114 uint32_t magic;
115
116public:
117 DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS];
118 EGLint numTotalConfigs;
119 egl_config_t* configs;
120
121private:
Mathias Agopianf0480de2011-11-13 20:50:07 -0800122 uint32_t refs;
123 mutable Mutex lock;
124 SortedVector<egl_object_t*> objects;
Mathias Agopian518ec112011-05-13 16:21:08 -0700125};
126
127// ----------------------------------------------------------------------------
128
129inline egl_display_t* get_display(EGLDisplay dpy) {
130 return egl_display_t::get(dpy);
131}
132
133// ----------------------------------------------------------------------------
134
135egl_display_t* validate_display(EGLDisplay dpy);
136egl_connection_t* validate_display_config(EGLDisplay dpy,
137 EGLConfig config, egl_display_t const*& dp);
138EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx);
139EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface);
140
141// ----------------------------------------------------------------------------
142}; // namespace android
143// ----------------------------------------------------------------------------
144
145#endif // ANDROID_EGL_DISPLAY_H