blob: 3e22efa52e38ba8fcef674cf59f05e5546959781 [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
Jamie Gennis98c63832011-11-07 17:03:54 -080047class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes
Mathias Agopian518ec112011-05-13 16:21:08 -070048 static egl_display_t sDisplay[NUM_DISPLAYS];
49 EGLDisplay getDisplay(EGLNativeDisplayType display);
Mathias Agopiana4b2c042012-02-03 15:24:51 -080050 void loseCurrentImpl(egl_context_t * cur_c);
Mathias Agopian518ec112011-05-13 16:21:08 -070051
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);
Mathias Agopian5b287a62011-05-16 18:58:55 -070067 // remove object from this display's list
68 void removeObject(egl_object_t* object);
Mathias Agopian518ec112011-05-13 16:21:08 -070069 // add reference to this object. returns true if this is a valid object.
Mathias Agopianf0480de2011-11-13 20:50:07 -080070 bool getObject(egl_object_t* object) const;
Mathias Agopian518ec112011-05-13 16:21:08 -070071
Mathias Agopian518ec112011-05-13 16:21:08 -070072 static egl_display_t* get(EGLDisplay dpy);
73 static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp);
74
Mathias Agopianfb87e542012-01-30 18:20:52 -080075 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
Mathias Agopian518ec112011-05-13 16:21:08 -070080 inline bool isReady() const { return (refs > 0); }
81 inline bool isValid() const { return magic == '_dpy'; }
82 inline bool isAlive() const { return isValid(); }
83
Mathias Agopian4b9511c2011-11-13 23:52:47 -080084 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
Romain Guy4725e2c2011-11-09 20:10:18 -080089 inline uint32_t getRefsCount() const { return refs; }
90
Mathias Agopian518ec112011-05-13 16:21:08 -070091 struct strings_t {
92 char const * vendor;
93 char const * version;
94 char const * clientApi;
95 char const * extensions;
96 };
97
98 struct DisplayImpl {
Mathias Agopian7773c432012-02-13 20:06:08 -080099 DisplayImpl() : dpy(EGL_NO_DISPLAY), state(NOT_INITIALIZED) { }
Mathias Agopian518ec112011-05-13 16:21:08 -0700100 EGLDisplay dpy;
Mathias Agopian518ec112011-05-13 16:21:08 -0700101 EGLint state;
Mathias Agopian518ec112011-05-13 16:21:08 -0700102 strings_t queryString;
103 };
104
105private:
106 uint32_t magic;
107
108public:
Mathias Agopianada798b2012-02-13 17:09:30 -0800109 DisplayImpl disp;
Jamie Gennis28ef8d72012-04-05 20:34:54 -0700110 bool finishOnSwap; // property: debug.egl.finish
111 bool traceGpuCompletion; // property: debug.egl.traceGpuCompletion
Mathias Agopian518ec112011-05-13 16:21:08 -0700112
113private:
Mathias Agopianf0480de2011-11-13 20:50:07 -0800114 uint32_t refs;
115 mutable Mutex lock;
116 SortedVector<egl_object_t*> objects;
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800117 String8 mVendorString;
118 String8 mVersionString;
119 String8 mClientApiString;
120 String8 mExtensionString;
Mathias Agopian518ec112011-05-13 16:21:08 -0700121};
122
123// ----------------------------------------------------------------------------
124
125inline egl_display_t* get_display(EGLDisplay dpy) {
126 return egl_display_t::get(dpy);
127}
128
129// ----------------------------------------------------------------------------
130
131egl_display_t* validate_display(EGLDisplay dpy);
132egl_connection_t* validate_display_config(EGLDisplay dpy,
133 EGLConfig config, egl_display_t const*& dp);
134EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx);
135EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface);
136
137// ----------------------------------------------------------------------------
138}; // namespace android
139// ----------------------------------------------------------------------------
140
141#endif // ANDROID_EGL_DISPLAY_H