blob: 13b94b6361be35dad8c5f58d602fcfa59aaf7dce [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),
67 smpte2086_metadata({}),
68 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) {
93 break;
94 case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:
95 smpte2086_metadata.displayPrimaryRed.x = value;
96 return EGL_TRUE;
97 case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT:
98 smpte2086_metadata.displayPrimaryRed.y = value;
99 return EGL_TRUE;
100 case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT:
101 smpte2086_metadata.displayPrimaryGreen.x = value;
102 return EGL_TRUE;
103 case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT:
104 smpte2086_metadata.displayPrimaryGreen.y = value;
105 return EGL_TRUE;
106 case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT:
107 smpte2086_metadata.displayPrimaryBlue.x = value;
108 return EGL_TRUE;
109 case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT:
110 smpte2086_metadata.displayPrimaryBlue.y = value;
111 return EGL_TRUE;
112 case EGL_SMPTE2086_WHITE_POINT_X_EXT:
113 smpte2086_metadata.whitePoint.x = value;
114 return EGL_TRUE;
115 case EGL_SMPTE2086_WHITE_POINT_Y_EXT:
116 smpte2086_metadata.whitePoint.y = value;
117 return EGL_TRUE;
118 case EGL_SMPTE2086_MAX_LUMINANCE_EXT:
119 smpte2086_metadata.maxLuminance = value;
120 return EGL_TRUE;
121 case EGL_SMPTE2086_MIN_LUMINANCE_EXT:
122 smpte2086_metadata.minLuminance = value;
123 return EGL_TRUE;
124 }
125 return EGL_FALSE;
126}
127
128EGLBoolean egl_surface_t::setCta8613Attribute(EGLint attribute, EGLint value) {
129 switch (attribute) {
130 case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:
131 cta861_3_metadata.maxContentLightLevel = value;
132 return EGL_TRUE;
133 case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT:
134 cta861_3_metadata.maxFrameAverageLightLevel = value;
135 return EGL_TRUE;
136 }
137 return EGL_FALSE;
138}
139
140EGLBoolean egl_surface_t::getColorSpaceAttribute(EGLint attribute, EGLint* value) const {
141 if (attribute == EGL_GL_COLORSPACE_KHR) {
142 *value = colorSpace;
143 return EGL_TRUE;
144 }
145 return EGL_FALSE;
146}
147
148EGLBoolean egl_surface_t::getSmpte2086Attribute(EGLint attribute, EGLint *value) const {
149 switch (attribute) {
150 case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:
151 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.displayPrimaryRed.x);
152 return EGL_TRUE;
153 break;
154 case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT:
155 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.displayPrimaryRed.y);
156 return EGL_TRUE;
157 break;
158 case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT:
159 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.displayPrimaryGreen.x);
160 return EGL_TRUE;
161 break;
162 case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT:
163 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.displayPrimaryGreen.y);
164 return EGL_TRUE;
165 break;
166 case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT:
167 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.displayPrimaryBlue.x);
168 return EGL_TRUE;
169 break;
170 case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT:
171 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.displayPrimaryBlue.y);
172 return EGL_TRUE;
173 break;
174 case EGL_SMPTE2086_WHITE_POINT_X_EXT:
175 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.whitePoint.x);
176 return EGL_TRUE;
177 break;
178 case EGL_SMPTE2086_WHITE_POINT_Y_EXT:
179 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.whitePoint.y);
180 return EGL_TRUE;
181 break;
182 case EGL_SMPTE2086_MAX_LUMINANCE_EXT:
183 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.maxLuminance);
184 return EGL_TRUE;
185 break;
186 case EGL_SMPTE2086_MIN_LUMINANCE_EXT:
187 *value = *reinterpret_cast<const int*>(&smpte2086_metadata.minLuminance);
188 return EGL_TRUE;
189 break;
190 }
191 return EGL_FALSE;
192}
193
194EGLBoolean egl_surface_t::getCta8613Attribute(EGLint attribute, EGLint *value) const {
195 switch (attribute) {
196 case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:
197 *value = *reinterpret_cast<const int*>(&cta861_3_metadata.maxContentLightLevel);
198 return EGL_TRUE;
199 break;
200 case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT:
201 *value = *reinterpret_cast<const int*>(&cta861_3_metadata.maxFrameAverageLightLevel);
202 return EGL_TRUE;
203 break;
204 }
205 return EGL_FALSE;
206}
207
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -0700208void egl_surface_t::terminate() {
209 disconnect();
210 egl_object_t::terminate();
211}
212
Jesse Hall25838592012-04-05 15:53:28 -0700213// ----------------------------------------------------------------------------
214
Mathias Agopian48d438d2012-01-28 21:44:00 -0800215egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
Mathias Agopianada798b2012-02-13 17:09:30 -0800216 egl_connection_t const* cnx, int version) :
Jesse Hallb29e5e82012-04-04 16:53:42 -0700217 egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context),
218 config(config), read(0), draw(0), cnx(cnx), version(version) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800219}
220
221void egl_context_t::onLooseCurrent() {
222 read = NULL;
223 draw = NULL;
224}
225
226void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
227 this->read = read;
228 this->draw = draw;
229
230 /*
231 * Here we cache the GL_EXTENSIONS string for this context and we
232 * add the extensions always handled by the wrapper
233 */
234
Mathias Agopian65421432017-03-08 11:49:05 -0800235 if (gl_extensions.empty()) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800236 // call the implementation's glGetString(GL_EXTENSIONS)
Mathias Agopianada798b2012-02-13 17:09:30 -0800237 const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
Alistair Strachan89301ea2015-05-22 14:10:09 -0700238
Jesse Hall09fc8f92017-09-29 15:57:42 -0700239 // If this context is sharing with another context, and the other context was reset
240 // e.g. due to robustness failure, this context might also be reset and glGetString can
241 // return NULL.
242 if (exts) {
243 gl_extensions = exts;
244 if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) {
245 gl_extensions.insert(0, "GL_EXT_debug_marker ");
246 }
247
248 // tokenize the supported extensions for the glGetStringi() wrapper
249 std::stringstream ss;
250 std::string str;
251 ss << gl_extensions;
252 while (ss >> str) {
253 tokenized_gl_extensions.push_back(str);
254 }
Alistair Strachan89301ea2015-05-22 14:10:09 -0700255 }
Mathias Agopian48d438d2012-01-28 21:44:00 -0800256 }
257}
258
259// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -0700260}; // namespace android
261// ----------------------------------------------------------------------------