blob: 867a1173b9e24b7b2ce05458332b562bfa7f24c9 [file] [log] [blame]
Jesse Hall47743382013-02-08 11:13:46 -08001/*
Mathias Agopian518ec112011-05-13 16:21:08 -07002 ** Copyright 2007, The Android Open Source Project
3 **
Jesse Hall47743382013-02-08 11:13:46 -08004 ** 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
Mathias Agopian518ec112011-05-13 16:21:08 -07007 **
Jesse Hall47743382013-02-08 11:13:46 -08008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopian518ec112011-05-13 16:21:08 -07009 **
Jesse Hall47743382013-02-08 11:13:46 -080010 ** 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
Mathias Agopian518ec112011-05-13 16:21:08 -070014 ** limitations under the License.
15 */
16
17#ifndef ANDROID_EGL_DISPLAY_H
18#define ANDROID_EGL_DISPLAY_H
19
Yiwei Zhang8af03062020-08-12 21:28:15 -070020#include <EGL/egl.h>
21#include <EGL/eglext.h>
Mathias Agopian311b4792017-02-28 15:00:49 -080022#include <stddef.h>
Yiwei Zhang8af03062020-08-12 21:28:15 -070023#include <stdint.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070024
Mathias Agopian65421432017-03-08 11:49:05 -080025#include <condition_variable>
Woody Chowa9550f32020-08-31 14:34:12 +090026#include <map>
27#include <memory>
Mathias Agopian65421432017-03-08 11:49:05 -080028#include <mutex>
29#include <string>
30#include <unordered_set>
31
Mathias Agopian39c24a22013-04-04 23:17:56 -070032#include "../hooks.h"
Yiwei Zhang8af03062020-08-12 21:28:15 -070033#include "egldefs.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070034
Mathias Agopian518ec112011-05-13 16:21:08 -070035namespace android {
Mathias Agopian518ec112011-05-13 16:21:08 -070036
37class egl_object_t;
Mathias Agopianfb87e542012-01-30 18:20:52 -080038class egl_context_t;
Bernhard Rosenkränzer9f425912014-11-17 21:12:15 +010039struct egl_connection_t;
Mathias Agopian518ec112011-05-13 16:21:08 -070040
Courtney Goeltzenleuchtera1e59f12018-03-05 08:19:25 -070041bool findExtension(const char* exts, const char* name, size_t nameLen = 0);
42
Jamie Gennis98c63832011-11-07 17:03:54 -080043class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes
Woody Chowa9550f32020-08-31 14:34:12 +090044 static std::map<EGLDisplay, std::unique_ptr<egl_display_t>> displayMap;
45 static std::mutex displayMapLock;
Mathias Agopian518ec112011-05-13 16:21:08 -070046 EGLDisplay getDisplay(EGLNativeDisplayType display);
Woody Chowa9550f32020-08-31 14:34:12 +090047 static EGLDisplay getPlatformDisplay(EGLNativeDisplayType display,
48 const EGLAttrib* attrib_list);
Yiwei Zhang8af03062020-08-12 21:28:15 -070049 void loseCurrentImpl(egl_context_t* cur_c);
Mathias Agopian518ec112011-05-13 16:21:08 -070050
51public:
52 enum {
53 NOT_INITIALIZED = 0,
Yiwei Zhang8af03062020-08-12 21:28:15 -070054 INITIALIZED = 1,
55 TERMINATED = 2,
Mathias Agopian518ec112011-05-13 16:21:08 -070056 };
57
58 egl_display_t();
59 ~egl_display_t();
60
Yiwei Zhang8af03062020-08-12 21:28:15 -070061 EGLBoolean initialize(EGLint* major, EGLint* minor);
Mathias Agopian518ec112011-05-13 16:21:08 -070062 EGLBoolean terminate();
63
64 // add object to this display's list
65 void addObject(egl_object_t* object);
Mathias Agopian5b287a62011-05-16 18:58:55 -070066 // remove object from this display's list
67 void removeObject(egl_object_t* object);
Mathias Agopian518ec112011-05-13 16:21:08 -070068 // add reference to this object. returns true if this is a valid object.
Mathias Agopianf0480de2011-11-13 20:50:07 -080069 bool getObject(egl_object_t* object) const;
Mathias Agopian518ec112011-05-13 16:21:08 -070070
Mathias Agopian518ec112011-05-13 16:21:08 -070071 static egl_display_t* get(EGLDisplay dpy);
Courtney Goeltzenleuchter4adf75b2018-10-11 13:09:40 -060072 static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp, const EGLAttrib* attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -070073
Yiwei Zhang8af03062020-08-12 21:28:15 -070074 EGLBoolean makeCurrent(egl_context_t* c, egl_context_t* cur_c, EGLSurface draw, EGLSurface read,
75 EGLContext ctx, EGLSurface impl_draw, EGLSurface impl_read,
76 EGLContext impl_ctx);
77 static void loseCurrent(egl_context_t* cur_c);
Mathias Agopianfb87e542012-01-30 18:20:52 -080078
Mathias Agopian518ec112011-05-13 16:21:08 -070079 inline bool isReady() const { return (refs > 0); }
80 inline bool isValid() const { return magic == '_dpy'; }
81 inline bool isAlive() const { return isValid(); }
82
Yiwei Zhang8af03062020-08-12 21:28:15 -070083 char const* getVendorString() const { return mVendorString.c_str(); }
84 char const* getVersionString() const { return mVersionString.c_str(); }
85 char const* getClientApiString() const { return mClientApiString.c_str(); }
86 char const* getExtensionString() const { return mExtensionString.c_str(); }
Mathias Agopian4b9511c2011-11-13 23:52:47 -080087
Jesse Hallc2e41222013-08-08 13:40:22 -070088 bool haveExtension(const char* name, size_t nameLen = 0) const;
89
Romain Guy4725e2c2011-11-09 20:10:18 -080090 inline uint32_t getRefsCount() const { return refs; }
91
Mathias Agopian518ec112011-05-13 16:21:08 -070092 struct strings_t {
Yiwei Zhang8af03062020-08-12 21:28:15 -070093 char const* vendor;
94 char const* version;
95 char const* clientApi;
96 char const* extensions;
Mathias Agopian518ec112011-05-13 16:21:08 -070097 };
98
99 struct DisplayImpl {
Yiwei Zhang8af03062020-08-12 21:28:15 -0700100 DisplayImpl() : dpy(EGL_NO_DISPLAY), state(NOT_INITIALIZED) {}
101 EGLDisplay dpy;
102 EGLint state;
103 strings_t queryString;
Mathias Agopian518ec112011-05-13 16:21:08 -0700104 };
105
106private:
Yiwei Zhang8af03062020-08-12 21:28:15 -0700107 uint32_t magic;
Mathias Agopian518ec112011-05-13 16:21:08 -0700108
109public:
Yiwei Zhang8af03062020-08-12 21:28:15 -0700110 DisplayImpl disp;
111 bool finishOnSwap; // property: debug.egl.finish
112 bool traceGpuCompletion; // property: debug.egl.traceGpuCompletion
113 bool hasColorSpaceSupport;
Mathias Agopian518ec112011-05-13 16:21:08 -0700114
115private:
Yiwei Zhang8af03062020-08-12 21:28:15 -0700116 uint32_t refs;
117 bool eglIsInitialized;
118 mutable std::mutex lock;
119 mutable std::mutex refLock;
120 mutable std::condition_variable refCond;
121 std::unordered_set<egl_object_t*> objects;
122 std::string mVendorString;
123 std::string mVersionString;
124 std::string mClientApiString;
125 std::string mExtensionString;
Mathias Agopian518ec112011-05-13 16:21:08 -0700126};
127
Yiwei Zhang0657fba2020-08-12 19:09:26 -0700128inline egl_display_t* get_display(EGLDisplay dpy) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700129 return egl_display_t::get(dpy);
130}
131
Yiwei Zhang0657fba2020-08-12 19:09:26 -0700132egl_display_t* validate_display(EGLDisplay dpy);
133egl_display_t* validate_display_connection(EGLDisplay dpy, egl_connection_t** outCnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700134EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx);
135EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface);
136
Mathias Agopian518ec112011-05-13 16:21:08 -0700137}; // namespace android
Mathias Agopian518ec112011-05-13 16:21:08 -0700138
139#endif // ANDROID_EGL_DISPLAY_H