blob: b68fd61c1177d361fadfabd97b3823408d31c711 [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
Mathias Agopian311b4792017-02-28 15:00:49 -080017#include "egl_object.h"
18
Michael Lentinee2fc6f82015-07-28 16:30:10 -070019#include <sstream>
20
Mathias Agopian518ec112011-05-13 16:21:08 -070021
22// ----------------------------------------------------------------------------
23namespace android {
24// ----------------------------------------------------------------------------
25
26egl_object_t::egl_object_t(egl_display_t* disp) :
Mathias Agopian5b287a62011-05-16 18:58:55 -070027 display(disp), count(1) {
28 // NOTE: this does an implicit incRef
Mathias Agopian518ec112011-05-13 16:21:08 -070029 display->addObject(this);
30}
31
Mathias Agopian5b287a62011-05-16 18:58:55 -070032egl_object_t::~egl_object_t() {
Mathias Agopian518ec112011-05-13 16:21:08 -070033}
34
Mathias Agopian5b287a62011-05-16 18:58:55 -070035void egl_object_t::terminate() {
36 // this marks the object as "terminated"
37 display->removeObject(this);
38 if (decRef() == 1) {
39 // shouldn't happen because this is called from LocalRef
Steve Blocke6f43dd2012-01-06 19:20:56 +000040 ALOGE("egl_object_t::terminate() removed the last reference!");
Mathias Agopian5b287a62011-05-16 18:58:55 -070041 }
42}
43
44void egl_object_t::destroy() {
45 if (decRef() == 1) {
46 delete this;
47 }
48}
49
Mathias Agopianf0480de2011-11-13 20:50:07 -080050bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
Mathias Agopian5b287a62011-05-16 18:58:55 -070051 // used by LocalRef, this does an incRef() atomically with
52 // checking that the object is valid.
Mathias Agopianf0480de2011-11-13 20:50:07 -080053 return display->getObject(object);
Mathias Agopian518ec112011-05-13 16:21:08 -070054}
55
56// ----------------------------------------------------------------------------
Mathias Agopian48d438d2012-01-28 21:44:00 -080057
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -060058egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, EGLNativeWindowType win,
59 EGLSurface surface, EGLint colorSpace, egl_connection_t const* cnx)
60 : egl_object_t(dpy),
61 surface(surface),
62 config(config),
63 win(win),
64 cnx(cnx),
65 connected(true),
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -070066 colorSpace(colorSpace),
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -080067 egl_smpte2086_metadata({}),
68 egl_cta861_3_metadata({}) {
Mathias Agopian65421432017-03-08 11:49:05 -080069 if (win) {
70 win->incStrong(this);
71 }
72}
Jesse Hall25838592012-04-05 15:53:28 -070073
74egl_surface_t::~egl_surface_t() {
Mathias Agopian65421432017-03-08 11:49:05 -080075 if (win != NULL) {
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070076 disconnect();
Mathias Agopian65421432017-03-08 11:49:05 -080077 win->decStrong(this);
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070078 }
79}
80
81void egl_surface_t::disconnect() {
Mathias Agopian65421432017-03-08 11:49:05 -080082 if (win != NULL && connected) {
83 native_window_set_buffers_format(win, 0);
84 if (native_window_api_disconnect(win, NATIVE_WINDOW_API_EGL)) {
85 ALOGW("EGLNativeWindowType %p disconnect failed", win);
Jesse Hall25838592012-04-05 15:53:28 -070086 }
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070087 connected = false;
Jesse Hall25838592012-04-05 15:53:28 -070088 }
89}
90
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -070091EGLBoolean egl_surface_t::setSmpte2086Attribute(EGLint attribute, EGLint value) {
92 switch (attribute) {
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -070093 case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -080094 egl_smpte2086_metadata.displayPrimaryRed.x = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -070095 return EGL_TRUE;
96 case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -080097 egl_smpte2086_metadata.displayPrimaryRed.y = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -070098 return EGL_TRUE;
99 case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800100 egl_smpte2086_metadata.displayPrimaryGreen.x = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700101 return EGL_TRUE;
102 case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800103 egl_smpte2086_metadata.displayPrimaryGreen.y = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700104 return EGL_TRUE;
105 case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800106 egl_smpte2086_metadata.displayPrimaryBlue.x = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700107 return EGL_TRUE;
108 case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800109 egl_smpte2086_metadata.displayPrimaryBlue.y = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700110 return EGL_TRUE;
111 case EGL_SMPTE2086_WHITE_POINT_X_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800112 egl_smpte2086_metadata.whitePoint.x = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700113 return EGL_TRUE;
114 case EGL_SMPTE2086_WHITE_POINT_Y_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800115 egl_smpte2086_metadata.whitePoint.y = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700116 return EGL_TRUE;
117 case EGL_SMPTE2086_MAX_LUMINANCE_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800118 egl_smpte2086_metadata.maxLuminance = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700119 return EGL_TRUE;
120 case EGL_SMPTE2086_MIN_LUMINANCE_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800121 egl_smpte2086_metadata.minLuminance = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700122 return EGL_TRUE;
123 }
124 return EGL_FALSE;
125}
126
127EGLBoolean egl_surface_t::setCta8613Attribute(EGLint attribute, EGLint value) {
128 switch (attribute) {
129 case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800130 egl_cta861_3_metadata.maxContentLightLevel = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700131 return EGL_TRUE;
132 case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800133 egl_cta861_3_metadata.maxFrameAverageLightLevel = value;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700134 return EGL_TRUE;
135 }
136 return EGL_FALSE;
137}
138
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800139const android_smpte2086_metadata egl_surface_t::getSmpte2086Metadata() {
140 android_smpte2086_metadata metadata;
141 metadata.displayPrimaryRed.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.x) / EGL_METADATA_SCALING_EXT;
142 metadata.displayPrimaryRed.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.y) / EGL_METADATA_SCALING_EXT;
143 metadata.displayPrimaryGreen.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.x) / EGL_METADATA_SCALING_EXT;
144 metadata.displayPrimaryGreen.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.y) / EGL_METADATA_SCALING_EXT;
145 metadata.displayPrimaryBlue.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.x) / EGL_METADATA_SCALING_EXT;
146 metadata.displayPrimaryBlue.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.y) / EGL_METADATA_SCALING_EXT;
147 metadata.whitePoint.x = static_cast<float>(egl_smpte2086_metadata.whitePoint.x) / EGL_METADATA_SCALING_EXT;
148 metadata.whitePoint.y = static_cast<float>(egl_smpte2086_metadata.whitePoint.y) / EGL_METADATA_SCALING_EXT;
149 metadata.maxLuminance = static_cast<float>(egl_smpte2086_metadata.maxLuminance) / EGL_METADATA_SCALING_EXT;
150 metadata.minLuminance = static_cast<float>(egl_smpte2086_metadata.minLuminance) / EGL_METADATA_SCALING_EXT;
151
152 return metadata;
153}
154
155const android_cta861_3_metadata egl_surface_t::getCta8613Metadata() {
156 android_cta861_3_metadata metadata;
157 metadata.maxContentLightLevel = static_cast<float>(egl_cta861_3_metadata.maxContentLightLevel) / EGL_METADATA_SCALING_EXT;
158 metadata.maxFrameAverageLightLevel = static_cast<float>(egl_cta861_3_metadata.maxFrameAverageLightLevel) / EGL_METADATA_SCALING_EXT;
159 return metadata;
160}
161
162
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700163EGLBoolean egl_surface_t::getColorSpaceAttribute(EGLint attribute, EGLint* value) const {
164 if (attribute == EGL_GL_COLORSPACE_KHR) {
165 *value = colorSpace;
166 return EGL_TRUE;
167 }
168 return EGL_FALSE;
169}
170
171EGLBoolean egl_surface_t::getSmpte2086Attribute(EGLint attribute, EGLint *value) const {
172 switch (attribute) {
173 case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800174 *value = egl_smpte2086_metadata.displayPrimaryRed.x;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700175 return EGL_TRUE;
176 break;
177 case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800178 *value = egl_smpte2086_metadata.displayPrimaryRed.y;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700179 return EGL_TRUE;
180 break;
181 case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800182 *value = egl_smpte2086_metadata.displayPrimaryGreen.x;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700183 return EGL_TRUE;
184 break;
185 case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800186 *value = egl_smpte2086_metadata.displayPrimaryGreen.y;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700187 return EGL_TRUE;
188 break;
189 case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800190 *value = egl_smpte2086_metadata.displayPrimaryBlue.x;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700191 return EGL_TRUE;
192 break;
193 case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800194 *value = egl_smpte2086_metadata.displayPrimaryBlue.y;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700195 return EGL_TRUE;
196 break;
197 case EGL_SMPTE2086_WHITE_POINT_X_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800198 *value = egl_smpte2086_metadata.whitePoint.x;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700199 return EGL_TRUE;
200 break;
201 case EGL_SMPTE2086_WHITE_POINT_Y_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800202 *value = egl_smpte2086_metadata.whitePoint.y;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700203 return EGL_TRUE;
204 break;
205 case EGL_SMPTE2086_MAX_LUMINANCE_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800206 *value = egl_smpte2086_metadata.maxLuminance;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700207 return EGL_TRUE;
208 break;
209 case EGL_SMPTE2086_MIN_LUMINANCE_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800210 *value = egl_smpte2086_metadata.minLuminance;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700211 return EGL_TRUE;
212 break;
213 }
214 return EGL_FALSE;
215}
216
217EGLBoolean egl_surface_t::getCta8613Attribute(EGLint attribute, EGLint *value) const {
218 switch (attribute) {
219 case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800220 *value = egl_cta861_3_metadata.maxContentLightLevel;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700221 return EGL_TRUE;
222 break;
223 case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT:
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -0800224 *value = egl_cta861_3_metadata.maxFrameAverageLightLevel;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700225 return EGL_TRUE;
226 break;
227 }
228 return EGL_FALSE;
229}
230
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -0700231void egl_surface_t::terminate() {
232 disconnect();
233 egl_object_t::terminate();
234}
235
Jesse Hall25838592012-04-05 15:53:28 -0700236// ----------------------------------------------------------------------------
237
Mathias Agopian48d438d2012-01-28 21:44:00 -0800238egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
Mathias Agopianada798b2012-02-13 17:09:30 -0800239 egl_connection_t const* cnx, int version) :
Jesse Hallb29e5e82012-04-04 16:53:42 -0700240 egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context),
241 config(config), read(0), draw(0), cnx(cnx), version(version) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800242}
243
244void egl_context_t::onLooseCurrent() {
245 read = NULL;
246 draw = NULL;
247}
248
249void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
250 this->read = read;
251 this->draw = draw;
252
253 /*
254 * Here we cache the GL_EXTENSIONS string for this context and we
255 * add the extensions always handled by the wrapper
256 */
257
Mathias Agopian65421432017-03-08 11:49:05 -0800258 if (gl_extensions.empty()) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800259 // call the implementation's glGetString(GL_EXTENSIONS)
Mathias Agopianada798b2012-02-13 17:09:30 -0800260 const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
Alistair Strachan89301ea2015-05-22 14:10:09 -0700261
Jesse Hall09fc8f92017-09-29 15:57:42 -0700262 // If this context is sharing with another context, and the other context was reset
263 // e.g. due to robustness failure, this context might also be reset and glGetString can
264 // return NULL.
265 if (exts) {
266 gl_extensions = exts;
267 if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) {
268 gl_extensions.insert(0, "GL_EXT_debug_marker ");
269 }
270
271 // tokenize the supported extensions for the glGetStringi() wrapper
272 std::stringstream ss;
273 std::string str;
274 ss << gl_extensions;
275 while (ss >> str) {
276 tokenized_gl_extensions.push_back(str);
277 }
Alistair Strachan89301ea2015-05-22 14:10:09 -0700278 }
Mathias Agopian48d438d2012-01-28 21:44:00 -0800279 }
280}
281
282// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -0700283}; // namespace android
284// ----------------------------------------------------------------------------