| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1 | /* | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 2 | ** Copyright 2007, The Android Open Source Project | 
|  | 3 | ** | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 7 | ** | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 8 | **     http://www.apache.org/licenses/LICENSE-2.0 | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 9 | ** | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 14 | ** limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 17 | #include "egl_object.h" | 
|  | 18 |  | 
| Michael Lentine | e2fc6f8 | 2015-07-28 16:30:10 -0700 | [diff] [blame] | 19 | #include <sstream> | 
|  | 20 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 21 | namespace android { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 22 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 23 | egl_object_t::egl_object_t(egl_display_t* disp) : display(disp), count(1) { | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 24 | // NOTE: this does an implicit incRef | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 25 | display->addObject(this); | 
|  | 26 | } | 
|  | 27 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 28 | egl_object_t::~egl_object_t() {} | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 29 |  | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 30 | void egl_object_t::terminate() { | 
|  | 31 | // this marks the object as "terminated" | 
|  | 32 | display->removeObject(this); | 
|  | 33 | if (decRef() == 1) { | 
|  | 34 | // shouldn't happen because this is called from LocalRef | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 35 | ALOGE("egl_object_t::terminate() removed the last reference!"); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 36 | } | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | void egl_object_t::destroy() { | 
|  | 40 | if (decRef() == 1) { | 
|  | 41 | delete this; | 
|  | 42 | } | 
|  | 43 | } | 
|  | 44 |  | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 45 | bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) { | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 46 | // used by LocalRef, this does an incRef() atomically with | 
|  | 47 | // checking that the object is valid. | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 48 | return display->getObject(object); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 51 | egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, EGLNativeWindowType win, | 
|  | 52 | EGLSurface surface, EGLint colorSpace, egl_connection_t const* cnx) | 
|  | 53 | : egl_object_t(dpy), | 
|  | 54 | surface(surface), | 
|  | 55 | config(config), | 
|  | 56 | win(win), | 
|  | 57 | cnx(cnx), | 
|  | 58 | connected(true), | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 59 | colorSpace(colorSpace), | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 60 | egl_smpte2086_dirty(false), | 
|  | 61 | egl_cta861_3_dirty(false) { | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 62 | egl_smpte2086_metadata.displayPrimaryRed = {EGL_DONT_CARE, EGL_DONT_CARE}; | 
|  | 63 | egl_smpte2086_metadata.displayPrimaryGreen = {EGL_DONT_CARE, EGL_DONT_CARE}; | 
|  | 64 | egl_smpte2086_metadata.displayPrimaryBlue = {EGL_DONT_CARE, EGL_DONT_CARE}; | 
|  | 65 | egl_smpte2086_metadata.whitePoint = {EGL_DONT_CARE, EGL_DONT_CARE}; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 66 | egl_smpte2086_metadata.maxLuminance = EGL_DONT_CARE; | 
|  | 67 | egl_smpte2086_metadata.minLuminance = EGL_DONT_CARE; | 
|  | 68 | egl_cta861_3_metadata.maxFrameAverageLightLevel = EGL_DONT_CARE; | 
|  | 69 | egl_cta861_3_metadata.maxContentLightLevel = EGL_DONT_CARE; | 
|  | 70 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 71 | if (win) { | 
|  | 72 | win->incStrong(this); | 
|  | 73 | } | 
|  | 74 | } | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 75 |  | 
|  | 76 | egl_surface_t::~egl_surface_t() { | 
| Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 77 | if (win != nullptr) { | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 78 | disconnect(); | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 79 | win->decStrong(this); | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 80 | } | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | void egl_surface_t::disconnect() { | 
| Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 84 | if (win != nullptr && connected) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 85 | native_window_set_buffers_format(win, 0); | 
|  | 86 | if (native_window_api_disconnect(win, NATIVE_WINDOW_API_EGL)) { | 
|  | 87 | ALOGW("EGLNativeWindowType %p disconnect failed", win); | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 88 | } | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 89 | connected = false; | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 90 | } | 
|  | 91 | } | 
|  | 92 |  | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 93 | EGLBoolean egl_surface_t::setSmpte2086Attribute(EGLint attribute, EGLint value) { | 
|  | 94 | switch (attribute) { | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 95 | case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 96 | egl_smpte2086_metadata.displayPrimaryRed.x = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 97 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 98 | return EGL_TRUE; | 
|  | 99 | case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 100 | egl_smpte2086_metadata.displayPrimaryRed.y = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 101 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 102 | return EGL_TRUE; | 
|  | 103 | case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 104 | egl_smpte2086_metadata.displayPrimaryGreen.x = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 105 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 106 | return EGL_TRUE; | 
|  | 107 | case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 108 | egl_smpte2086_metadata.displayPrimaryGreen.y = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 109 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 110 | return EGL_TRUE; | 
|  | 111 | case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 112 | egl_smpte2086_metadata.displayPrimaryBlue.x = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 113 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 114 | return EGL_TRUE; | 
|  | 115 | case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 116 | egl_smpte2086_metadata.displayPrimaryBlue.y = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 117 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 118 | return EGL_TRUE; | 
|  | 119 | case EGL_SMPTE2086_WHITE_POINT_X_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 120 | egl_smpte2086_metadata.whitePoint.x = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 121 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 122 | return EGL_TRUE; | 
|  | 123 | case EGL_SMPTE2086_WHITE_POINT_Y_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 124 | egl_smpte2086_metadata.whitePoint.y = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 125 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 126 | return EGL_TRUE; | 
|  | 127 | case EGL_SMPTE2086_MAX_LUMINANCE_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 128 | egl_smpte2086_metadata.maxLuminance = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 129 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 130 | return EGL_TRUE; | 
|  | 131 | case EGL_SMPTE2086_MIN_LUMINANCE_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 132 | egl_smpte2086_metadata.minLuminance = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 133 | egl_smpte2086_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 134 | return EGL_TRUE; | 
|  | 135 | } | 
|  | 136 | return EGL_FALSE; | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | EGLBoolean egl_surface_t::setCta8613Attribute(EGLint attribute, EGLint value) { | 
|  | 140 | switch (attribute) { | 
|  | 141 | case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 142 | egl_cta861_3_metadata.maxContentLightLevel = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 143 | egl_cta861_3_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 144 | return EGL_TRUE; | 
|  | 145 | case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 146 | egl_cta861_3_metadata.maxFrameAverageLightLevel = value; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 147 | egl_cta861_3_dirty = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 148 | return EGL_TRUE; | 
|  | 149 | } | 
|  | 150 | return EGL_FALSE; | 
|  | 151 | } | 
|  | 152 |  | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 153 | EGLBoolean egl_surface_t::getSmpte2086Metadata(android_smpte2086_metadata& metadata) const { | 
|  | 154 | if (!egl_smpte2086_dirty) return EGL_FALSE; | 
|  | 155 | if (egl_smpte2086_metadata.displayPrimaryRed.x == EGL_DONT_CARE || | 
|  | 156 | egl_smpte2086_metadata.displayPrimaryRed.y == EGL_DONT_CARE || | 
|  | 157 | egl_smpte2086_metadata.displayPrimaryGreen.x == EGL_DONT_CARE || | 
|  | 158 | egl_smpte2086_metadata.displayPrimaryGreen.y == EGL_DONT_CARE || | 
|  | 159 | egl_smpte2086_metadata.displayPrimaryBlue.x == EGL_DONT_CARE || | 
|  | 160 | egl_smpte2086_metadata.displayPrimaryBlue.y == EGL_DONT_CARE || | 
|  | 161 | egl_smpte2086_metadata.whitePoint.x == EGL_DONT_CARE || | 
|  | 162 | egl_smpte2086_metadata.whitePoint.y == EGL_DONT_CARE || | 
|  | 163 | egl_smpte2086_metadata.maxLuminance == EGL_DONT_CARE || | 
|  | 164 | egl_smpte2086_metadata.minLuminance == EGL_DONT_CARE) { | 
|  | 165 | ALOGW("egl_surface_t: incomplete SMPTE 2086 metadata!"); | 
|  | 166 | return EGL_FALSE; | 
|  | 167 | } | 
|  | 168 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 169 | metadata.displayPrimaryRed.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.x) / | 
|  | 170 | EGL_METADATA_SCALING_EXT; | 
|  | 171 | metadata.displayPrimaryRed.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.y) / | 
|  | 172 | EGL_METADATA_SCALING_EXT; | 
|  | 173 | metadata.displayPrimaryGreen.x = | 
|  | 174 | static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.x) / | 
|  | 175 | EGL_METADATA_SCALING_EXT; | 
|  | 176 | metadata.displayPrimaryGreen.y = | 
|  | 177 | static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.y) / | 
|  | 178 | EGL_METADATA_SCALING_EXT; | 
|  | 179 | metadata.displayPrimaryBlue.x = | 
|  | 180 | static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.x) / | 
|  | 181 | EGL_METADATA_SCALING_EXT; | 
|  | 182 | metadata.displayPrimaryBlue.y = | 
|  | 183 | static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.y) / | 
|  | 184 | EGL_METADATA_SCALING_EXT; | 
|  | 185 | metadata.whitePoint.x = | 
|  | 186 | static_cast<float>(egl_smpte2086_metadata.whitePoint.x) / EGL_METADATA_SCALING_EXT; | 
|  | 187 | metadata.whitePoint.y = | 
|  | 188 | static_cast<float>(egl_smpte2086_metadata.whitePoint.y) / EGL_METADATA_SCALING_EXT; | 
|  | 189 | metadata.maxLuminance = | 
|  | 190 | static_cast<float>(egl_smpte2086_metadata.maxLuminance) / EGL_METADATA_SCALING_EXT; | 
|  | 191 | metadata.minLuminance = | 
|  | 192 | static_cast<float>(egl_smpte2086_metadata.minLuminance) / EGL_METADATA_SCALING_EXT; | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 193 |  | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 194 | return EGL_TRUE; | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 197 | EGLBoolean egl_surface_t::getCta8613Metadata(android_cta861_3_metadata& metadata) const { | 
|  | 198 | if (!egl_cta861_3_dirty) return EGL_FALSE; | 
|  | 199 |  | 
|  | 200 | if (egl_cta861_3_metadata.maxContentLightLevel == EGL_DONT_CARE || | 
|  | 201 | egl_cta861_3_metadata.maxFrameAverageLightLevel == EGL_DONT_CARE) { | 
|  | 202 | ALOGW("egl_surface_t: incomplete CTA861.3 metadata!"); | 
|  | 203 | return EGL_FALSE; | 
|  | 204 | } | 
|  | 205 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 206 | metadata.maxContentLightLevel = static_cast<float>(egl_cta861_3_metadata.maxContentLightLevel) / | 
|  | 207 | EGL_METADATA_SCALING_EXT; | 
|  | 208 | metadata.maxFrameAverageLightLevel = | 
|  | 209 | static_cast<float>(egl_cta861_3_metadata.maxFrameAverageLightLevel) / | 
|  | 210 | EGL_METADATA_SCALING_EXT; | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 211 |  | 
|  | 212 | return EGL_TRUE; | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 213 | } | 
|  | 214 |  | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 215 | EGLBoolean egl_surface_t::getColorSpaceAttribute(EGLint attribute, EGLint* value) const { | 
|  | 216 | if (attribute == EGL_GL_COLORSPACE_KHR) { | 
|  | 217 | *value = colorSpace; | 
|  | 218 | return EGL_TRUE; | 
|  | 219 | } | 
|  | 220 | return EGL_FALSE; | 
|  | 221 | } | 
|  | 222 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 223 | EGLBoolean egl_surface_t::getSmpte2086Attribute(EGLint attribute, EGLint* value) const { | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 224 | switch (attribute) { | 
|  | 225 | case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 226 | *value = egl_smpte2086_metadata.displayPrimaryRed.x; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 227 | return EGL_TRUE; | 
|  | 228 | break; | 
|  | 229 | case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 230 | *value = egl_smpte2086_metadata.displayPrimaryRed.y; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 231 | return EGL_TRUE; | 
|  | 232 | break; | 
|  | 233 | case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 234 | *value = egl_smpte2086_metadata.displayPrimaryGreen.x; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 235 | return EGL_TRUE; | 
|  | 236 | break; | 
|  | 237 | case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 238 | *value = egl_smpte2086_metadata.displayPrimaryGreen.y; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 239 | return EGL_TRUE; | 
|  | 240 | break; | 
|  | 241 | case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 242 | *value = egl_smpte2086_metadata.displayPrimaryBlue.x; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 243 | return EGL_TRUE; | 
|  | 244 | break; | 
|  | 245 | case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 246 | *value = egl_smpte2086_metadata.displayPrimaryBlue.y; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 247 | return EGL_TRUE; | 
|  | 248 | break; | 
|  | 249 | case EGL_SMPTE2086_WHITE_POINT_X_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 250 | *value = egl_smpte2086_metadata.whitePoint.x; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 251 | return EGL_TRUE; | 
|  | 252 | break; | 
|  | 253 | case EGL_SMPTE2086_WHITE_POINT_Y_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 254 | *value = egl_smpte2086_metadata.whitePoint.y; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 255 | return EGL_TRUE; | 
|  | 256 | break; | 
|  | 257 | case EGL_SMPTE2086_MAX_LUMINANCE_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 258 | *value = egl_smpte2086_metadata.maxLuminance; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 259 | return EGL_TRUE; | 
|  | 260 | break; | 
|  | 261 | case EGL_SMPTE2086_MIN_LUMINANCE_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 262 | *value = egl_smpte2086_metadata.minLuminance; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 263 | return EGL_TRUE; | 
|  | 264 | break; | 
|  | 265 | } | 
|  | 266 | return EGL_FALSE; | 
|  | 267 | } | 
|  | 268 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 269 | EGLBoolean egl_surface_t::getCta8613Attribute(EGLint attribute, EGLint* value) const { | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 270 | switch (attribute) { | 
|  | 271 | case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 272 | *value = egl_cta861_3_metadata.maxContentLightLevel; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 273 | return EGL_TRUE; | 
|  | 274 | break; | 
|  | 275 | case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT: | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 276 | *value = egl_cta861_3_metadata.maxFrameAverageLightLevel; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 277 | return EGL_TRUE; | 
|  | 278 | break; | 
|  | 279 | } | 
|  | 280 | return EGL_FALSE; | 
|  | 281 | } | 
|  | 282 |  | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 283 | void egl_surface_t::terminate() { | 
|  | 284 | disconnect(); | 
|  | 285 | egl_object_t::terminate(); | 
|  | 286 | } | 
|  | 287 |  | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 288 | egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, | 
| Yiwei Zhang | 0657fba | 2020-08-12 19:09:26 -0700 | [diff] [blame] | 289 | egl_connection_t const* cnx, int version) | 
|  | 290 | : egl_object_t(get_display(dpy)), | 
|  | 291 | dpy(dpy), | 
|  | 292 | context(context), | 
|  | 293 | config(config), | 
|  | 294 | read(nullptr), | 
|  | 295 | draw(nullptr), | 
|  | 296 | cnx(cnx), | 
|  | 297 | version(version) {} | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 298 |  | 
|  | 299 | void egl_context_t::onLooseCurrent() { | 
| Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 300 | read = nullptr; | 
|  | 301 | draw = nullptr; | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 302 | } | 
|  | 303 |  | 
|  | 304 | void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) { | 
|  | 305 | this->read = read; | 
|  | 306 | this->draw = draw; | 
|  | 307 |  | 
|  | 308 | /* | 
|  | 309 | * Here we cache the GL_EXTENSIONS string for this context and we | 
|  | 310 | * add the extensions always handled by the wrapper | 
|  | 311 | */ | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 312 | if (!gl_extensions.empty()) return; | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 313 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 314 | // call the implementation's glGetString(GL_EXTENSIONS) | 
|  | 315 | const char* exts = (const char*)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS); | 
|  | 316 | if (!exts) return; | 
| Alistair Strachan | 89301ea | 2015-05-22 14:10:09 -0700 | [diff] [blame] | 317 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 318 | // If this context is sharing with another context, and the other context was reset | 
|  | 319 | // e.g. due to robustness failure, this context might also be reset and glGetString can | 
|  | 320 | // return NULL. | 
|  | 321 | gl_extensions = exts; | 
|  | 322 | if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) { | 
|  | 323 | gl_extensions.insert(0, "GL_EXT_debug_marker "); | 
|  | 324 | // eglGetProcAddress could return function pointers to these | 
|  | 325 | // functions while they actually don't work. Fix them now. | 
|  | 326 | __eglMustCastToProperFunctionPointerType* f; | 
|  | 327 | f = (__eglMustCastToProperFunctionPointerType*)&gEGLImpl.hooks[version] | 
|  | 328 | ->gl.glInsertEventMarkerEXT; | 
|  | 329 | if (*f != gl_noop) *f = gl_noop; | 
|  | 330 | f = (__eglMustCastToProperFunctionPointerType*)&gEGLImpl.hooks[version] | 
|  | 331 | ->gl.glPushGroupMarkerEXT; | 
|  | 332 | if (*f != gl_noop) *f = gl_noop; | 
|  | 333 | f = (__eglMustCastToProperFunctionPointerType*)&gEGLImpl.hooks[version] | 
|  | 334 | ->gl.glPopGroupMarkerEXT; | 
|  | 335 | if (*f != gl_noop) *f = gl_noop; | 
|  | 336 | } | 
| Jesse Hall | 09fc8f9 | 2017-09-29 15:57:42 -0700 | [diff] [blame] | 337 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 338 | // tokenize the supported extensions for the glGetStringi() wrapper | 
|  | 339 | std::stringstream ss; | 
|  | 340 | std::string str; | 
|  | 341 | ss << gl_extensions; | 
|  | 342 | while (ss >> str) { | 
|  | 343 | tokenized_gl_extensions.push_back(str); | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 344 | } | 
|  | 345 | } | 
|  | 346 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 347 | }; // namespace android |