blob: 4479e00ede265706de378debf876926ea1c3fa8d [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>
Mathias Agopian4b9511c2011-11-13 23:52:47 -080032#include <utils/String8.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070033
Mathias Agopian1cadb252011-05-23 17:26:14 -070034#include "egldefs.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070035#include "hooks.h"
36
37// ----------------------------------------------------------------------------
38namespace android {
39// ----------------------------------------------------------------------------
40
41class egl_object_t;
Mathias Agopianfb87e542012-01-30 18:20:52 -080042class egl_context_t;
Mathias Agopian518ec112011-05-13 16:21:08 -070043class egl_connection_t;
44
45// ----------------------------------------------------------------------------
46
47struct egl_config_t {
48 egl_config_t() {}
49 egl_config_t(int impl, EGLConfig config)
50 : impl(impl), config(config), configId(0), implConfigId(0) { }
51 int impl; // the implementation this config is for
52 EGLConfig config; // the implementation's EGLConfig
53 EGLint configId; // our CONFIG_ID
54 EGLint implConfigId; // the implementation's CONFIG_ID
55 inline bool operator < (const egl_config_t& rhs) const {
56 if (impl < rhs.impl) return true;
57 if (impl > rhs.impl) return false;
58 return config < rhs.config;
59 }
60};
61
62// ----------------------------------------------------------------------------
63
Jamie Gennis98c63832011-11-07 17:03:54 -080064class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes
Mathias Agopian518ec112011-05-13 16:21:08 -070065 static egl_display_t sDisplay[NUM_DISPLAYS];
66 EGLDisplay getDisplay(EGLNativeDisplayType display);
67
68public:
69 enum {
70 NOT_INITIALIZED = 0,
71 INITIALIZED = 1,
72 TERMINATED = 2
73 };
74
75 egl_display_t();
76 ~egl_display_t();
77
78 EGLBoolean initialize(EGLint *major, EGLint *minor);
79 EGLBoolean terminate();
80
81 // add object to this display's list
82 void addObject(egl_object_t* object);
Mathias Agopian5b287a62011-05-16 18:58:55 -070083 // remove object from this display's list
84 void removeObject(egl_object_t* object);
Mathias Agopian518ec112011-05-13 16:21:08 -070085 // add reference to this object. returns true if this is a valid object.
Mathias Agopianf0480de2011-11-13 20:50:07 -080086 bool getObject(egl_object_t* object) const;
Mathias Agopian518ec112011-05-13 16:21:08 -070087
Mathias Agopian518ec112011-05-13 16:21:08 -070088 static egl_display_t* get(EGLDisplay dpy);
89 static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp);
90
Mathias Agopianfb87e542012-01-30 18:20:52 -080091 EGLBoolean makeCurrent(egl_context_t* c, egl_context_t* cur_c,
92 EGLSurface draw, EGLSurface read, EGLContext ctx,
93 EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx);
94 static void loseCurrent(egl_context_t * cur_c);
95
Mathias Agopian518ec112011-05-13 16:21:08 -070096 inline bool isReady() const { return (refs > 0); }
97 inline bool isValid() const { return magic == '_dpy'; }
98 inline bool isAlive() const { return isValid(); }
99
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800100 char const * getVendorString() const { return mVendorString.string(); }
101 char const * getVersionString() const { return mVersionString.string(); }
102 char const * getClientApiString() const { return mClientApiString.string(); }
103 char const * getExtensionString() const { return mExtensionString.string(); }
104
Romain Guy4725e2c2011-11-09 20:10:18 -0800105 inline uint32_t getRefsCount() const { return refs; }
106
Mathias Agopian518ec112011-05-13 16:21:08 -0700107 struct strings_t {
108 char const * vendor;
109 char const * version;
110 char const * clientApi;
111 char const * extensions;
112 };
113
114 struct DisplayImpl {
115 DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0),
116 state(NOT_INITIALIZED), numConfigs(0) { }
117 EGLDisplay dpy;
118 EGLConfig* config;
119 EGLint state;
120 EGLint numConfigs;
121 strings_t queryString;
122 };
123
124private:
125 uint32_t magic;
126
127public:
128 DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS];
129 EGLint numTotalConfigs;
130 egl_config_t* configs;
131
132private:
Mathias Agopianf0480de2011-11-13 20:50:07 -0800133 uint32_t refs;
134 mutable Mutex lock;
135 SortedVector<egl_object_t*> objects;
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800136 String8 mVendorString;
137 String8 mVersionString;
138 String8 mClientApiString;
139 String8 mExtensionString;
Mathias Agopian518ec112011-05-13 16:21:08 -0700140};
141
142// ----------------------------------------------------------------------------
143
144inline egl_display_t* get_display(EGLDisplay dpy) {
145 return egl_display_t::get(dpy);
146}
147
148// ----------------------------------------------------------------------------
149
150egl_display_t* validate_display(EGLDisplay dpy);
151egl_connection_t* validate_display_config(EGLDisplay dpy,
152 EGLConfig config, egl_display_t const*& dp);
153EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx);
154EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface);
155
156// ----------------------------------------------------------------------------
157}; // namespace android
158// ----------------------------------------------------------------------------
159
160#endif // ANDROID_EGL_DISPLAY_H