blob: 296ee44ce53d6d3e5e16a3f0caffe5b2844a7aa2 [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
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Cody Northrop68d10352018-10-15 07:22:09 -060019#include "egl_platform_entries.h"
20
Mathias Agopian518ec112011-05-13 16:21:08 -070021#include <ctype.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070022#include <dlfcn.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070023#include <stdlib.h>
24#include <string.h>
25
Craig Donnere96a3252017-02-02 12:13:34 -080026#include <hardware/gralloc1.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070027
28#include <EGL/egl.h>
29#include <EGL/eglext.h>
Courtney Goeltzenleuchter555f1df2018-09-25 14:34:29 -060030#include <EGL/eglext_angle.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070031
Craig Donner60761072017-01-27 12:30:44 -080032#include <android/hardware_buffer.h>
Mathias Agopian89ed4c82017-02-09 18:48:34 -080033#include <private/android/AHardwareBufferHelpers.h>
34
Mathias Agopian7db993a2012-03-25 00:49:46 -070035#include <cutils/compiler.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070036#include <cutils/properties.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070037#include <log/log.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070038
Mathias Agopian65421432017-03-08 11:49:05 -080039#include <condition_variable>
40#include <deque>
41#include <mutex>
42#include <unordered_map>
43#include <string>
44#include <thread>
Mathias Agopian518ec112011-05-13 16:21:08 -070045
Mathias Agopian39c24a22013-04-04 23:17:56 -070046#include "../egl_impl.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070047
48#include "egl_display.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070049#include "egl_object.h"
50#include "egl_tls.h"
Mathias Agopian65421432017-03-08 11:49:05 -080051#include "egl_trace.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070052
53using namespace android;
54
55// ----------------------------------------------------------------------------
56
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070057namespace android {
58
Mathias Agopian65421432017-03-08 11:49:05 -080059using nsecs_t = int64_t;
60
Mathias Agopian518ec112011-05-13 16:21:08 -070061struct extention_map_t {
62 const char* name;
63 __eglMustCastToProperFunctionPointerType address;
64};
65
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070066/*
Jesse Hall21558da2013-08-06 15:31:22 -070067 * This is the list of EGL extensions exposed to applications.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070068 *
Jesse Hall21558da2013-08-06 15:31:22 -070069 * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL
70 * wrapper and are always available.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070071 *
Jesse Hall21558da2013-08-06 15:31:22 -070072 * The rest (gExtensionString) depend on support in the EGL driver, and are
73 * only available if the driver supports them. However, some of these must be
74 * supported because they are used by the Android system itself; these are
Pablo Ceballos02b05da2016-02-02 17:53:18 -080075 * listed as mandatory below and are required by the CDD. The system *assumes*
Jesse Hall21558da2013-08-06 15:31:22 -070076 * the mandatory extensions are present and may not function properly if some
77 * are missing.
78 *
79 * NOTE: Both strings MUST have a single space as the last character.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070080 */
Mathias Agopian737b8962017-02-24 14:32:05 -080081
Mathias Agopian311b4792017-02-28 15:00:49 -080082extern char const * const gBuiltinExtensionString;
83extern char const * const gExtensionString;
Mathias Agopian737b8962017-02-24 14:32:05 -080084
Courtney Goeltzenleuchter21b33cb2017-04-17 17:31:29 -060085// clang-format off
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -070086// Extensions implemented by the EGL wrapper.
Mathias Agopian311b4792017-02-28 15:00:49 -080087char const * const gBuiltinExtensionString =
Jesse Hall21558da2013-08-06 15:31:22 -070088 "EGL_KHR_get_all_proc_addresses "
89 "EGL_ANDROID_presentation_time "
Dan Stozaa894d082015-02-19 15:27:36 -080090 "EGL_KHR_swap_buffers_with_damage "
Craig Donner60761072017-01-27 12:30:44 -080091 "EGL_ANDROID_get_native_client_buffer "
Pablo Ceballos02b05da2016-02-02 17:53:18 -080092 "EGL_ANDROID_front_buffer_auto_refresh "
Pablo Ceballosc18be292016-05-31 14:55:42 -070093 "EGL_ANDROID_get_frame_timestamps "
Courtney Goeltzenleuchtera1e59f12018-03-05 08:19:25 -070094 "EGL_EXT_surface_SMPTE2086_metadata "
95 "EGL_EXT_surface_CTA861_3_metadata "
Jesse Hall21558da2013-08-06 15:31:22 -070096 ;
Mathias Agopian311b4792017-02-28 15:00:49 -080097
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -070098// Whitelist of extensions exposed to applications if implemented in the vendor driver.
Mathias Agopian311b4792017-02-28 15:00:49 -080099char const * const gExtensionString =
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700100 "EGL_KHR_image " // mandatory
101 "EGL_KHR_image_base " // mandatory
Krzysztof Kosiński41171c52018-04-19 21:38:54 -0700102 "EGL_EXT_image_gl_colorspace "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700103 "EGL_KHR_image_pixmap "
104 "EGL_KHR_lock_surface "
Jesse Hallc2e41222013-08-08 13:40:22 -0700105 "EGL_KHR_gl_colorspace "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700106 "EGL_KHR_gl_texture_2D_image "
Season Li000d88f2015-07-01 11:39:40 -0700107 "EGL_KHR_gl_texture_3D_image "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700108 "EGL_KHR_gl_texture_cubemap_image "
109 "EGL_KHR_gl_renderbuffer_image "
110 "EGL_KHR_reusable_sync "
111 "EGL_KHR_fence_sync "
Jamie Gennisf6d1c392013-04-25 18:48:41 -0700112 "EGL_KHR_create_context "
Season Li000d88f2015-07-01 11:39:40 -0700113 "EGL_KHR_config_attribs "
114 "EGL_KHR_surfaceless_context "
115 "EGL_KHR_stream "
116 "EGL_KHR_stream_fifo "
117 "EGL_KHR_stream_producer_eglsurface "
118 "EGL_KHR_stream_consumer_gltexture "
119 "EGL_KHR_stream_cross_process_fd "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700120 "EGL_EXT_create_context_robustness "
121 "EGL_NV_system_time "
122 "EGL_ANDROID_image_native_buffer " // mandatory
Mathias Agopian2bb71682013-03-27 17:32:41 -0700123 "EGL_KHR_wait_sync " // strongly recommended
Jamie Gennisdbe92452013-09-23 17:22:10 -0700124 "EGL_ANDROID_recordable " // mandatory
Dan Stozaa894d082015-02-19 15:27:36 -0800125 "EGL_KHR_partial_update " // strongly recommended
Courtney Goeltzenleuchter0e4e3952016-11-16 13:53:40 -0700126 "EGL_EXT_pixel_format_float "
Dan Stozaa894d082015-02-19 15:27:36 -0800127 "EGL_EXT_buffer_age " // strongly recommended with partial_update
Jesse Hall408e59f2015-04-24 01:40:42 -0700128 "EGL_KHR_create_context_no_error "
Pablo Ceballosceb9ee72016-04-13 11:17:32 -0700129 "EGL_KHR_mutable_render_buffer "
Mika Isojärvif37864b2016-04-15 11:58:56 -0700130 "EGL_EXT_yuv_surface "
Craig Donneraec86972016-04-28 18:09:40 -0700131 "EGL_EXT_protected_content "
Christian Poetzscha7805f62016-12-01 16:34:39 +0000132 "EGL_IMG_context_priority "
Pyry Haulos51d53c42017-03-06 09:39:09 -0800133 "EGL_KHR_no_config_context "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700134 ;
Courtney Goeltzenleuchter21b33cb2017-04-17 17:31:29 -0600135// clang-format on
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700136
137// extensions not exposed to applications but used by the ANDROID system
138// "EGL_ANDROID_blob_cache " // strongly recommended
139// "EGL_IMG_hibernate_process " // optional
140// "EGL_ANDROID_native_fence_sync " // strongly recommended
141// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700142
143/*
144 * EGL Extensions entry-points exposed to 3rd party applications
145 * (keep in sync with gExtensionString above)
146 *
147 */
148static const extention_map_t sExtensionMap[] = {
149 // EGL_KHR_lock_surface
Mathias Agopian518ec112011-05-13 16:21:08 -0700150 { "eglLockSurfaceKHR",
151 (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
152 { "eglUnlockSurfaceKHR",
153 (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700154
155 // EGL_KHR_image, EGL_KHR_image_base
Mathias Agopian518ec112011-05-13 16:21:08 -0700156 { "eglCreateImageKHR",
157 (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
158 { "eglDestroyImageKHR",
159 (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700160
161 // EGL_KHR_reusable_sync, EGL_KHR_fence_sync
162 { "eglCreateSyncKHR",
163 (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
164 { "eglDestroySyncKHR",
165 (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
166 { "eglClientWaitSyncKHR",
167 (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
168 { "eglSignalSyncKHR",
169 (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR },
170 { "eglGetSyncAttribKHR",
171 (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
172
173 // EGL_NV_system_time
Jonas Yang1c3d72a2011-08-26 20:04:39 +0800174 { "eglGetSystemTimeFrequencyNV",
175 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
176 { "eglGetSystemTimeNV",
177 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700178
Mathias Agopian2bb71682013-03-27 17:32:41 -0700179 // EGL_KHR_wait_sync
180 { "eglWaitSyncKHR",
181 (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700182
183 // EGL_ANDROID_presentation_time
184 { "eglPresentationTimeANDROID",
185 (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID },
Dan Stozaa894d082015-02-19 15:27:36 -0800186
187 // EGL_KHR_swap_buffers_with_damage
188 { "eglSwapBuffersWithDamageKHR",
189 (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR },
190
Craig Donner60761072017-01-27 12:30:44 -0800191 // EGL_ANDROID_get_native_client_buffer
192 { "eglGetNativeClientBufferANDROID",
193 (__eglMustCastToProperFunctionPointerType)&eglGetNativeClientBufferANDROID },
194
Dan Stozaa894d082015-02-19 15:27:36 -0800195 // EGL_KHR_partial_update
196 { "eglSetDamageRegionKHR",
197 (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR },
Season Li000d88f2015-07-01 11:39:40 -0700198
199 { "eglCreateStreamKHR",
200 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR },
201 { "eglDestroyStreamKHR",
202 (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR },
203 { "eglStreamAttribKHR",
204 (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR },
205 { "eglQueryStreamKHR",
206 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR },
207 { "eglQueryStreamu64KHR",
208 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR },
209 { "eglQueryStreamTimeKHR",
210 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR },
211 { "eglCreateStreamProducerSurfaceKHR",
212 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR },
213 { "eglStreamConsumerGLTextureExternalKHR",
214 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR },
215 { "eglStreamConsumerAcquireKHR",
216 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR },
217 { "eglStreamConsumerReleaseKHR",
218 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR },
219 { "eglGetStreamFileDescriptorKHR",
220 (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR },
221 { "eglCreateStreamFromFileDescriptorKHR",
222 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR },
Pablo Ceballosc18be292016-05-31 14:55:42 -0700223
224 // EGL_ANDROID_get_frame_timestamps
Brian Anderson1049d1d2016-12-16 17:25:57 -0800225 { "eglGetNextFrameIdANDROID",
226 (__eglMustCastToProperFunctionPointerType)&eglGetNextFrameIdANDROID },
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800227 { "eglGetCompositorTimingANDROID",
228 (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingANDROID },
229 { "eglGetCompositorTimingSupportedANDROID",
230 (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingSupportedANDROID },
Pablo Ceballosc18be292016-05-31 14:55:42 -0700231 { "eglGetFrameTimestampsANDROID",
232 (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampsANDROID },
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800233 { "eglGetFrameTimestampSupportedANDROID",
234 (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampSupportedANDROID },
Craig Donner55901a22017-04-17 15:31:06 -0700235
236 // EGL_ANDROID_native_fence_sync
237 { "eglDupNativeFenceFDANDROID",
238 (__eglMustCastToProperFunctionPointerType)&eglDupNativeFenceFDANDROID },
Mathias Agopian518ec112011-05-13 16:21:08 -0700239};
240
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700241/*
242 * These extensions entry-points should not be exposed to applications.
243 * They're used internally by the Android EGL layer.
244 */
245#define FILTER_EXTENSIONS(procname) \
246 (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \
247 !strcmp((procname), "eglHibernateProcessIMG") || \
Craig Donner55901a22017-04-17 15:31:06 -0700248 !strcmp((procname), "eglAwakenProcessIMG"))
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700249
Mathias Agopian518ec112011-05-13 16:21:08 -0700250// accesses protected by sExtensionMapMutex
Mathias Agopian65421432017-03-08 11:49:05 -0800251static std::unordered_map<std::string, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
252
Mathias Agopian518ec112011-05-13 16:21:08 -0700253static int sGLExtentionSlot = 0;
254static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
255
256static void(*findProcAddress(const char* name,
257 const extention_map_t* map, size_t n))() {
258 for (uint32_t i=0 ; i<n ; i++) {
259 if (!strcmp(name, map[i].name)) {
260 return map[i].address;
261 }
262 }
Yi Kong48a6cd22018-07-18 10:07:09 -0700263 return nullptr;
Mathias Agopian518ec112011-05-13 16:21:08 -0700264}
265
266// ----------------------------------------------------------------------------
267
Mathias Agopian518ec112011-05-13 16:21:08 -0700268extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
269extern EGLBoolean egl_init_drivers();
270extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
Mathias Agopian518ec112011-05-13 16:21:08 -0700271extern gl_hooks_t gHooksTrace;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700272
Mathias Agopian518ec112011-05-13 16:21:08 -0700273// ----------------------------------------------------------------------------
274
Mathias Agopian518ec112011-05-13 16:21:08 -0700275static inline EGLContext getContext() { return egl_tls_t::getContext(); }
276
277// ----------------------------------------------------------------------------
278
Cody Northrop68d10352018-10-15 07:22:09 -0600279EGLDisplay eglGetDisplayImpl(EGLNativeDisplayType display)
Mathias Agopian518ec112011-05-13 16:21:08 -0700280{
Dan Stozac3289c42014-01-17 11:38:34 -0800281 uintptr_t index = reinterpret_cast<uintptr_t>(display);
Mathias Agopian518ec112011-05-13 16:21:08 -0700282 if (index >= NUM_DISPLAYS) {
283 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
284 }
285
Mathias Agopian518ec112011-05-13 16:21:08 -0700286 EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
287 return dpy;
288}
289
290// ----------------------------------------------------------------------------
291// Initialization
292// ----------------------------------------------------------------------------
293
Cody Northrop68d10352018-10-15 07:22:09 -0600294EGLBoolean eglInitializeImpl(EGLDisplay dpy, EGLint *major, EGLint *minor)
Mathias Agopian518ec112011-05-13 16:21:08 -0700295{
Jesse Hallb29e5e82012-04-04 16:53:42 -0700296 egl_display_ptr dp = get_display(dpy);
Mathias Agopian737b8962017-02-24 14:32:05 -0800297 if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700298
299 EGLBoolean res = dp->initialize(major, minor);
300
301 return res;
302}
303
Cody Northrop68d10352018-10-15 07:22:09 -0600304EGLBoolean eglTerminateImpl(EGLDisplay dpy)
Mathias Agopian518ec112011-05-13 16:21:08 -0700305{
306 // NOTE: don't unload the drivers b/c some APIs can be called
307 // after eglTerminate() has been called. eglTerminate() only
308 // terminates an EGLDisplay, not a EGL itself.
309
Jesse Hallb29e5e82012-04-04 16:53:42 -0700310 egl_display_ptr dp = get_display(dpy);
Mathias Agopian737b8962017-02-24 14:32:05 -0800311 if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700312
313 EGLBoolean res = dp->terminate();
Jesse Hall47743382013-02-08 11:13:46 -0800314
Mathias Agopian518ec112011-05-13 16:21:08 -0700315 return res;
316}
317
318// ----------------------------------------------------------------------------
319// configuration
320// ----------------------------------------------------------------------------
321
Cody Northrop68d10352018-10-15 07:22:09 -0600322EGLBoolean eglGetConfigsImpl(EGLDisplay dpy,
323 EGLConfig *configs,
324 EGLint config_size, EGLint *num_config)
Mathias Agopian518ec112011-05-13 16:21:08 -0700325{
Jesse Hallb29e5e82012-04-04 16:53:42 -0700326 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700327 if (!dp) return EGL_FALSE;
328
Yi Kong48a6cd22018-07-18 10:07:09 -0700329 if (num_config==nullptr) {
Mathias Agopian737b8962017-02-24 14:32:05 -0800330 return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700331 }
332
Mathias Agopian7773c432012-02-13 20:06:08 -0800333 EGLBoolean res = EGL_FALSE;
334 *num_config = 0;
335
336 egl_connection_t* const cnx = &gEGLImpl;
337 if (cnx->dso) {
338 res = cnx->egl.eglGetConfigs(
339 dp->disp.dpy, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700340 }
Mathias Agopian7773c432012-02-13 20:06:08 -0800341
342 return res;
Mathias Agopian518ec112011-05-13 16:21:08 -0700343}
344
Cody Northrop68d10352018-10-15 07:22:09 -0600345EGLBoolean eglChooseConfigImpl( EGLDisplay dpy, const EGLint *attrib_list,
346 EGLConfig *configs, EGLint config_size,
347 EGLint *num_config)
Mathias Agopian518ec112011-05-13 16:21:08 -0700348{
Jesse Hallb29e5e82012-04-04 16:53:42 -0700349 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700350 if (!dp) return EGL_FALSE;
351
Yi Kong48a6cd22018-07-18 10:07:09 -0700352 if (num_config==nullptr) {
Mathias Agopian737b8962017-02-24 14:32:05 -0800353 return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700354 }
355
Mathias Agopian518ec112011-05-13 16:21:08 -0700356 EGLBoolean res = EGL_FALSE;
357 *num_config = 0;
358
Mathias Agopianada798b2012-02-13 17:09:30 -0800359 egl_connection_t* const cnx = &gEGLImpl;
360 if (cnx->dso) {
Romain Guy1cffc802012-10-15 18:13:05 -0700361 if (attrib_list) {
362 char value[PROPERTY_VALUE_MAX];
363 property_get("debug.egl.force_msaa", value, "false");
364
365 if (!strcmp(value, "true")) {
366 size_t attribCount = 0;
367 EGLint attrib = attrib_list[0];
368
369 // Only enable MSAA if the context is OpenGL ES 2.0 and
Romain Guybe3c3e42012-10-15 19:25:18 -0700370 // if no caveat is requested
Yi Kong48a6cd22018-07-18 10:07:09 -0700371 const EGLint *attribRendererable = nullptr;
372 const EGLint *attribCaveat = nullptr;
Romain Guy1cffc802012-10-15 18:13:05 -0700373
374 // Count the number of attributes and look for
Romain Guybe3c3e42012-10-15 19:25:18 -0700375 // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT
Romain Guy1cffc802012-10-15 18:13:05 -0700376 while (attrib != EGL_NONE) {
377 attrib = attrib_list[attribCount];
378 switch (attrib) {
379 case EGL_RENDERABLE_TYPE:
380 attribRendererable = &attrib_list[attribCount];
381 break;
382 case EGL_CONFIG_CAVEAT:
383 attribCaveat = &attrib_list[attribCount];
384 break;
Mathias Agopian737b8962017-02-24 14:32:05 -0800385 default:
386 break;
Romain Guy1cffc802012-10-15 18:13:05 -0700387 }
388 attribCount++;
389 }
390
391 if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT &&
392 (!attribCaveat || attribCaveat[1] != EGL_NONE)) {
Jesse Hall47743382013-02-08 11:13:46 -0800393
Romain Guy1cffc802012-10-15 18:13:05 -0700394 // Insert 2 extra attributes to force-enable MSAA 4x
395 EGLint aaAttribs[attribCount + 4];
396 aaAttribs[0] = EGL_SAMPLE_BUFFERS;
397 aaAttribs[1] = 1;
398 aaAttribs[2] = EGL_SAMPLES;
399 aaAttribs[3] = 4;
400
401 memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint));
402
403 EGLint numConfigAA;
404 EGLBoolean resAA = cnx->egl.eglChooseConfig(
405 dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA);
406
407 if (resAA == EGL_TRUE && numConfigAA > 0) {
408 ALOGD("Enabling MSAA 4x");
409 *num_config = numConfigAA;
410 return resAA;
411 }
412 }
413 }
414 }
415
Mathias Agopian7773c432012-02-13 20:06:08 -0800416 res = cnx->egl.eglChooseConfig(
417 dp->disp.dpy, attrib_list, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700418 }
419 return res;
420}
421
Cody Northrop68d10352018-10-15 07:22:09 -0600422EGLBoolean eglGetConfigAttribImpl(EGLDisplay dpy, EGLConfig config,
Mathias Agopian518ec112011-05-13 16:21:08 -0700423 EGLint attribute, EGLint *value)
424{
Yi Kong48a6cd22018-07-18 10:07:09 -0700425 egl_connection_t* cnx = nullptr;
Jesse Hallb29e5e82012-04-04 16:53:42 -0700426 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
427 if (!dp) return EGL_FALSE;
Jesse Hall47743382013-02-08 11:13:46 -0800428
Mathias Agopian518ec112011-05-13 16:21:08 -0700429 return cnx->egl.eglGetConfigAttrib(
Mathias Agopian7773c432012-02-13 20:06:08 -0800430 dp->disp.dpy, config, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700431}
432
433// ----------------------------------------------------------------------------
434// surfaces
435// ----------------------------------------------------------------------------
436
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700437// Translates EGL color spaces to Android data spaces.
438static android_dataspace dataSpaceFromEGLColorSpace(EGLint colorspace) {
Jesse Hallc2e41222013-08-08 13:40:22 -0700439 if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) {
Chia-I Wu6c354012018-06-20 10:57:48 +0800440 return HAL_DATASPACE_UNKNOWN;
Jesse Hallc2e41222013-08-08 13:40:22 -0700441 } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800442 return HAL_DATASPACE_SRGB;
Courtney Goeltzenleuchter21b33cb2017-04-17 17:31:29 -0600443 } else if (colorspace == EGL_GL_COLORSPACE_DISPLAY_P3_EXT) {
444 return HAL_DATASPACE_DISPLAY_P3;
445 } else if (colorspace == EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT) {
446 return HAL_DATASPACE_DISPLAY_P3_LINEAR;
Courtney Goeltzenleuchter33e2b782017-06-23 09:06:52 -0600447 } else if (colorspace == EGL_GL_COLORSPACE_SCRGB_EXT) {
448 return HAL_DATASPACE_V0_SCRGB;
Courtney Goeltzenleuchter21b33cb2017-04-17 17:31:29 -0600449 } else if (colorspace == EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT) {
450 return HAL_DATASPACE_V0_SCRGB_LINEAR;
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700451 } else if (colorspace == EGL_GL_COLORSPACE_BT2020_LINEAR_EXT) {
452 return HAL_DATASPACE_BT2020_LINEAR;
453 } else if (colorspace == EGL_GL_COLORSPACE_BT2020_PQ_EXT) {
454 return HAL_DATASPACE_BT2020_PQ;
Jesse Hallc2e41222013-08-08 13:40:22 -0700455 }
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700456 return HAL_DATASPACE_UNKNOWN;
Jesse Hallc2e41222013-08-08 13:40:22 -0700457}
458
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700459// Get the colorspace value that should be reported from queries. When the colorspace
460// is unknown (no attribute passed), default to reporting LINEAR.
461static EGLint getReportedColorSpace(EGLint colorspace) {
462 return colorspace == EGL_UNKNOWN ? EGL_GL_COLORSPACE_LINEAR_KHR : colorspace;
463}
464
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700465// Returns a list of color spaces understood by the vendor EGL driver.
466static std::vector<EGLint> getDriverColorSpaces(egl_display_ptr dp,
467 android_pixel_format format) {
468 std::vector<EGLint> colorSpaces;
469 if (!dp->hasColorSpaceSupport) return colorSpaces;
Courtney Goeltzenleuchtera1e59f12018-03-05 08:19:25 -0700470
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700471 // OpenGL drivers only support sRGB encoding with 8-bit formats.
472 // RGB_888 is never returned by getNativePixelFormat, but is included for completeness.
473 const bool formatSupportsSRGBEncoding =
474 format == HAL_PIXEL_FORMAT_RGBA_8888 || format == HAL_PIXEL_FORMAT_RGBX_8888 ||
475 format == HAL_PIXEL_FORMAT_RGB_888;
476 const bool formatIsFloatingPoint = format == HAL_PIXEL_FORMAT_RGBA_FP16;
Courtney Goeltzenleuchtera1e59f12018-03-05 08:19:25 -0700477
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700478 if (formatSupportsSRGBEncoding) {
479 // sRGB and linear are always supported when color space support is present.
480 colorSpaces.push_back(EGL_GL_COLORSPACE_SRGB_KHR);
481 colorSpaces.push_back(EGL_GL_COLORSPACE_LINEAR_KHR);
482 // DCI-P3 uses the sRGB transfer function, so it's only relevant for 8-bit formats.
483 if (findExtension(dp->disp.queryString.extensions,
484 "EGL_EXT_gl_colorspace_display_p3")) {
485 colorSpaces.push_back(EGL_GL_COLORSPACE_DISPLAY_P3_EXT);
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600486 }
487 }
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700488
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700489 // According to the spec, scRGB is only supported for floating point formats.
490 // For non-linear scRGB, the application is responsible for applying the
491 // transfer function.
492 if (formatIsFloatingPoint) {
493 if (findExtension(dp->disp.queryString.extensions,
494 "EGL_EXT_gl_colorspace_scrgb")) {
495 colorSpaces.push_back(EGL_GL_COLORSPACE_SCRGB_EXT);
496 }
497 if (findExtension(dp->disp.queryString.extensions,
498 "EGL_EXT_gl_colorspace_scrgb_linear")) {
499 colorSpaces.push_back(EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT);
500 }
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600501 }
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700502
503 // BT2020 can be used with any pixel format. PQ encoding must be applied by the
504 // application and does not affect the behavior of OpenGL.
505 if (findExtension(dp->disp.queryString.extensions,
506 "EGL_EXT_gl_colorspace_bt2020_linear")) {
507 colorSpaces.push_back(EGL_GL_COLORSPACE_BT2020_LINEAR_EXT);
508 }
509 if (findExtension(dp->disp.queryString.extensions,
510 "EGL_EXT_gl_colorspace_bt2020_pq")) {
511 colorSpaces.push_back(EGL_GL_COLORSPACE_BT2020_PQ_EXT);
512 }
513
514 // Linear DCI-P3 simply uses different primaries than standard RGB and thus
515 // can be used with any pixel format.
516 if (findExtension(dp->disp.queryString.extensions,
517 "EGL_EXT_gl_colorspace_display_p3_linear")) {
518 colorSpaces.push_back(EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT);
519 }
520 return colorSpaces;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600521}
522
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700523// Cleans up color space related parameters that the driver does not understand.
524// If there is no color space attribute in attrib_list, colorSpace is left
525// unmodified.
526static EGLBoolean processAttributes(egl_display_ptr dp, NativeWindowType window,
527 android_pixel_format format, const EGLint* attrib_list,
528 EGLint* colorSpace,
529 std::vector<EGLint>* strippedAttribList) {
530 for (const EGLint* attr = attrib_list; attr && attr[0] != EGL_NONE; attr += 2) {
531 bool copyAttribute = true;
532 if (attr[0] == EGL_GL_COLORSPACE_KHR) {
533 // Fail immediately if the driver doesn't have color space support at all.
534 if (!dp->hasColorSpaceSupport) return false;
535 *colorSpace = attr[1];
Courtney Goeltzenleuchtere5d6f992017-07-07 14:55:40 -0600536
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700537 // Strip the attribute if the driver doesn't understand it.
538 copyAttribute = false;
539 std::vector<EGLint> driverColorSpaces = getDriverColorSpaces(dp, format);
540 for (auto driverColorSpace : driverColorSpaces) {
541 if (attr[1] == driverColorSpace) {
542 copyAttribute = true;
543 break;
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600544 }
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600545 }
Chris Forbes8e8fb4a2018-10-04 09:52:42 -0700546
547 // If the driver doesn't understand it, we should map sRGB-encoded P3 to
548 // sRGB rather than just dropping the colorspace on the floor.
549 // For this format, the driver is expected to apply the sRGB
550 // transfer function during framebuffer operations.
551 if (!copyAttribute && attr[1] == EGL_GL_COLORSPACE_DISPLAY_P3_EXT) {
552 strippedAttribList->push_back(attr[0]);
553 strippedAttribList->push_back(EGL_GL_COLORSPACE_SRGB_KHR);
554 }
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600555 }
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700556 if (copyAttribute) {
557 strippedAttribList->push_back(attr[0]);
558 strippedAttribList->push_back(attr[1]);
559 }
560 }
561 // Terminate the attribute list.
562 strippedAttribList->push_back(EGL_NONE);
563
564 // If the passed color space has wide color gamut, check whether the target native window
565 // supports wide color.
566 const bool colorSpaceIsNarrow =
567 *colorSpace == EGL_GL_COLORSPACE_SRGB_KHR ||
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700568 *colorSpace == EGL_GL_COLORSPACE_LINEAR_KHR ||
569 *colorSpace == EGL_UNKNOWN;
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700570 if (window && !colorSpaceIsNarrow) {
571 bool windowSupportsWideColor = true;
572 // Ordinarily we'd put a call to native_window_get_wide_color_support
573 // at the beginning of the function so that we'll have the
574 // result when needed elsewhere in the function.
575 // However, because eglCreateWindowSurface is called by SurfaceFlinger and
576 // SurfaceFlinger is required to answer the call below we would
577 // end up in a deadlock situation. By moving the call to only happen
578 // if the application has specifically asked for wide-color we avoid
579 // the deadlock with SurfaceFlinger since it will not ask for a
580 // wide-color surface.
581 int err = native_window_get_wide_color_support(window, &windowSupportsWideColor);
582
583 if (err) {
584 ALOGE("processAttributes: invalid window (win=%p) "
585 "failed (%#x) (already connected to another API?)",
586 window, err);
587 return false;
588 }
589 if (!windowSupportsWideColor) {
590 // Application has asked for a wide-color colorspace but
591 // wide-color support isn't available on the display the window is on.
592 return false;
593 }
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600594 }
595 return true;
596}
597
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700598// Gets the native pixel format corrsponding to the passed EGLConfig.
599void getNativePixelFormat(EGLDisplay dpy, egl_connection_t* cnx, EGLConfig config,
600 android_pixel_format* format) {
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600601 // Set the native window's buffers format to match what this config requests.
602 // Whether to use sRGB gamma is not part of the EGLconfig, but is part
603 // of our native format. So if sRGB gamma is requested, we have to
604 // modify the EGLconfig's format before setting the native window's
605 // format.
606
607 EGLint componentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
608 cnx->egl.eglGetConfigAttrib(dpy, config, EGL_COLOR_COMPONENT_TYPE_EXT, &componentType);
609
610 EGLint a = 0;
611 EGLint r, g, b;
612 r = g = b = 0;
613 cnx->egl.eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r);
614 cnx->egl.eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g);
615 cnx->egl.eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b);
616 cnx->egl.eglGetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &a);
617 EGLint colorDepth = r + g + b;
618
619 // Today, the driver only understands sRGB and linear on 888X
620 // formats. Strip other colorspaces from the attribute list and
621 // only use them to set the dataspace via
622 // native_window_set_buffers_dataspace
623 // if pixel format is RGBX 8888
624 // TBD: Can test for future extensions that indicate that driver
625 // handles requested color space and we can let it through.
626 // allow SRGB and LINEAR. All others need to be stripped.
627 // else if 565, 4444
628 // TBD: Can we assume these are supported if 8888 is?
629 // else if FP16 or 1010102
630 // strip colorspace from attribs.
631 // endif
632 if (a == 0) {
633 if (colorDepth <= 16) {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700634 *format = HAL_PIXEL_FORMAT_RGB_565;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600635 } else {
636 if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) {
637 if (colorDepth > 24) {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700638 *format = HAL_PIXEL_FORMAT_RGBA_1010102;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600639 } else {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700640 *format = HAL_PIXEL_FORMAT_RGBX_8888;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600641 }
642 } else {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700643 *format = HAL_PIXEL_FORMAT_RGBA_FP16;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600644 }
645 }
646 } else {
647 if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) {
648 if (colorDepth > 24) {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700649 *format = HAL_PIXEL_FORMAT_RGBA_1010102;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600650 } else {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700651 *format = HAL_PIXEL_FORMAT_RGBA_8888;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600652 }
653 } else {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700654 *format = HAL_PIXEL_FORMAT_RGBA_FP16;
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600655 }
656 }
657}
658
Courtney Goeltzenleuchter936799c2018-03-02 16:47:08 -0700659EGLBoolean sendSurfaceMetadata(egl_surface_t* s) {
660 android_smpte2086_metadata smpteMetadata;
661 if (s->getSmpte2086Metadata(smpteMetadata)) {
662 int err =
663 native_window_set_buffers_smpte2086_metadata(s->getNativeWindow(), &smpteMetadata);
664 s->resetSmpte2086Metadata();
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700665 if (err != 0) {
666 ALOGE("error setting native window smpte2086 metadata: %s (%d)",
667 strerror(-err), err);
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700668 return EGL_FALSE;
669 }
670 }
Courtney Goeltzenleuchter936799c2018-03-02 16:47:08 -0700671 android_cta861_3_metadata cta8613Metadata;
672 if (s->getCta8613Metadata(cta8613Metadata)) {
673 int err =
674 native_window_set_buffers_cta861_3_metadata(s->getNativeWindow(), &cta8613Metadata);
675 s->resetCta8613Metadata();
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700676 if (err != 0) {
677 ALOGE("error setting native window CTS 861.3 metadata: %s (%d)",
678 strerror(-err), err);
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700679 return EGL_FALSE;
680 }
681 }
682 return EGL_TRUE;
683}
684
Cody Northrop68d10352018-10-15 07:22:09 -0600685EGLSurface eglCreateWindowSurfaceImpl( EGLDisplay dpy, EGLConfig config,
686 NativeWindowType window,
687 const EGLint *attrib_list)
Mathias Agopian518ec112011-05-13 16:21:08 -0700688{
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700689 const EGLint *origAttribList = attrib_list;
Mathias Agopian518ec112011-05-13 16:21:08 -0700690
Yi Kong48a6cd22018-07-18 10:07:09 -0700691 egl_connection_t* cnx = nullptr;
Jesse Hallb29e5e82012-04-04 16:53:42 -0700692 egl_display_ptr dp = validate_display_connection(dpy, cnx);
693 if (dp) {
Mathias Agopian10e9ab52017-03-08 15:02:55 -0800694 if (!window) {
695 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
696 }
697
698 int value = 0;
699 window->query(window, NATIVE_WINDOW_IS_VALID, &value);
700 if (!value) {
701 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
702 }
703
Courtney Goeltzenleuchter555f1df2018-09-25 14:34:29 -0600704 // NOTE: When using Vulkan backend, the Vulkan runtime makes all the
705 // native_window_* calls, so don't do them here.
706 if (cnx->angleBackend != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) {
707 int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
708 if (result < 0) {
709 ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) "
710 "failed (%#x) (already connected to another API?)",
711 window, result);
712 return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
713 }
Mathias Agopian81a63352011-07-29 17:55:48 -0700714 }
715
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700716 EGLDisplay iDpy = dp->disp.dpy;
717 android_pixel_format format;
718 getNativePixelFormat(iDpy, cnx, config, &format);
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600719
720 // now select correct colorspace and dataspace based on user's attribute list
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700721 EGLint colorSpace = EGL_UNKNOWN;
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700722 std::vector<EGLint> strippedAttribList;
723 if (!processAttributes(dp, window, format, attrib_list, &colorSpace,
724 &strippedAttribList)) {
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600725 ALOGE("error invalid colorspace: %d", colorSpace);
726 return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700727 }
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700728 attrib_list = strippedAttribList.data();
Alistair Strachan733a8072015-02-12 12:33:25 -0800729
Courtney Goeltzenleuchter555f1df2018-09-25 14:34:29 -0600730 if (cnx->angleBackend != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) {
Jesse Hallc2e41222013-08-08 13:40:22 -0700731 int err = native_window_set_buffers_format(window, format);
732 if (err != 0) {
733 ALOGE("error setting native window pixel format: %s (%d)",
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700734 strerror(-err), err);
Jesse Hallc2e41222013-08-08 13:40:22 -0700735 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
736 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
737 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700738
Courtney Goeltzenleuchter555f1df2018-09-25 14:34:29 -0600739 android_dataspace dataSpace = dataSpaceFromEGLColorSpace(colorSpace);
740 if (dataSpace != HAL_DATASPACE_UNKNOWN) {
741 err = native_window_set_buffers_data_space(window, dataSpace);
742 if (err != 0) {
743 ALOGE("error setting native window pixel dataSpace: %s (%d)", strerror(-err),
744 err);
745 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
746 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
747 }
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800748 }
749 }
750
Jamie Gennis59769462011-11-19 18:04:43 -0800751 // the EGL spec requires that a new EGLSurface default to swap interval
752 // 1, so explicitly set that on the window here.
753 ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
754 anw->setSwapInterval(anw, 1);
755
Mathias Agopian518ec112011-05-13 16:21:08 -0700756 EGLSurface surface = cnx->egl.eglCreateWindowSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800757 iDpy, config, window, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700758 if (surface != EGL_NO_SURFACE) {
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600759 egl_surface_t* s =
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700760 new egl_surface_t(dp.get(), config, window, surface,
761 getReportedColorSpace(colorSpace), cnx);
Courtney Goeltzenleuchtera1e59f12018-03-05 08:19:25 -0700762 return s;
Mathias Agopian518ec112011-05-13 16:21:08 -0700763 }
Mathias Agopian81a63352011-07-29 17:55:48 -0700764
765 // EGLSurface creation failed
Courtney Goeltzenleuchter555f1df2018-09-25 14:34:29 -0600766 if (cnx->angleBackend != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) {
767 native_window_set_buffers_format(window, 0);
768 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
769 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700770 }
771 return EGL_NO_SURFACE;
772}
773
Cody Northrop68d10352018-10-15 07:22:09 -0600774EGLSurface eglCreatePixmapSurfaceImpl( EGLDisplay dpy, EGLConfig config,
775 NativePixmapType pixmap,
776 const EGLint *attrib_list)
Mathias Agopian518ec112011-05-13 16:21:08 -0700777{
Yi Kong48a6cd22018-07-18 10:07:09 -0700778 egl_connection_t* cnx = nullptr;
Jesse Hallb29e5e82012-04-04 16:53:42 -0700779 egl_display_ptr dp = validate_display_connection(dpy, cnx);
780 if (dp) {
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700781 EGLDisplay iDpy = dp->disp.dpy;
782 android_pixel_format format;
783 getNativePixelFormat(iDpy, cnx, config, &format);
784
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600785 // now select a corresponding sRGB format if needed
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700786 EGLint colorSpace = EGL_UNKNOWN;
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700787 std::vector<EGLint> strippedAttribList;
788 if (!processAttributes(dp, nullptr, format, attrib_list, &colorSpace,
789 &strippedAttribList)) {
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600790 ALOGE("error invalid colorspace: %d", colorSpace);
791 return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
792 }
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700793 attrib_list = strippedAttribList.data();
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600794
Mathias Agopian518ec112011-05-13 16:21:08 -0700795 EGLSurface surface = cnx->egl.eglCreatePixmapSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800796 dp->disp.dpy, config, pixmap, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700797 if (surface != EGL_NO_SURFACE) {
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700798 egl_surface_t* s =
Yi Kong48a6cd22018-07-18 10:07:09 -0700799 new egl_surface_t(dp.get(), config, nullptr, surface,
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700800 getReportedColorSpace(colorSpace), cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700801 return s;
802 }
803 }
804 return EGL_NO_SURFACE;
805}
806
Cody Northrop68d10352018-10-15 07:22:09 -0600807EGLSurface eglCreatePbufferSurfaceImpl( EGLDisplay dpy, EGLConfig config,
808 const EGLint *attrib_list)
Mathias Agopian518ec112011-05-13 16:21:08 -0700809{
Yi Kong48a6cd22018-07-18 10:07:09 -0700810 egl_connection_t* cnx = nullptr;
Jesse Hallb29e5e82012-04-04 16:53:42 -0700811 egl_display_ptr dp = validate_display_connection(dpy, cnx);
812 if (dp) {
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600813 EGLDisplay iDpy = dp->disp.dpy;
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700814 android_pixel_format format;
815 getNativePixelFormat(iDpy, cnx, config, &format);
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600816
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700817 // Select correct colorspace based on user's attribute list
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700818 EGLint colorSpace = EGL_UNKNOWN;
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700819 std::vector<EGLint> strippedAttribList;
820 if (!processAttributes(dp, nullptr, format, attrib_list, &colorSpace,
821 &strippedAttribList)) {
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600822 ALOGE("error invalid colorspace: %d", colorSpace);
823 return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
824 }
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700825 attrib_list = strippedAttribList.data();
Courtney Goeltzenleuchtereeaa52b2017-06-20 08:12:54 -0600826
Mathias Agopian518ec112011-05-13 16:21:08 -0700827 EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800828 dp->disp.dpy, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700829 if (surface != EGL_NO_SURFACE) {
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700830 egl_surface_t* s =
Yi Kong48a6cd22018-07-18 10:07:09 -0700831 new egl_surface_t(dp.get(), config, nullptr, surface,
Krzysztof Kosiński12752442018-05-08 15:25:31 -0700832 getReportedColorSpace(colorSpace), cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700833 return s;
834 }
835 }
836 return EGL_NO_SURFACE;
837}
Jesse Hall47743382013-02-08 11:13:46 -0800838
Cody Northrop68d10352018-10-15 07:22:09 -0600839EGLBoolean eglDestroySurfaceImpl(EGLDisplay dpy, EGLSurface surface)
Mathias Agopian518ec112011-05-13 16:21:08 -0700840{
Jesse Hallb29e5e82012-04-04 16:53:42 -0700841 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700842 if (!dp) return EGL_FALSE;
843
Jesse Hallb29e5e82012-04-04 16:53:42 -0700844 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700845 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -0800846 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700847
848 egl_surface_t * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800849 EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700850 if (result == EGL_TRUE) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700851 _s.terminate();
852 }
853 return result;
854}
855
Cody Northrop68d10352018-10-15 07:22:09 -0600856EGLBoolean eglQuerySurfaceImpl( EGLDisplay dpy, EGLSurface surface,
857 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -0700858{
Jesse Hallb29e5e82012-04-04 16:53:42 -0700859 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700860 if (!dp) return EGL_FALSE;
861
Jesse Hallb29e5e82012-04-04 16:53:42 -0700862 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700863 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -0800864 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700865
Mathias Agopian518ec112011-05-13 16:21:08 -0700866 egl_surface_t const * const s = get_surface(surface);
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700867 if (s->getColorSpaceAttribute(attribute, value)) {
868 return EGL_TRUE;
869 } else if (s->getSmpte2086Attribute(attribute, value)) {
870 return EGL_TRUE;
871 } else if (s->getCta8613Attribute(attribute, value)) {
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -0600872 return EGL_TRUE;
873 }
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700874 return s->cnx->egl.eglQuerySurface(dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700875}
876
Cody Northrop68d10352018-10-15 07:22:09 -0600877void EGLAPI eglBeginFrameImpl(EGLDisplay dpy, EGLSurface surface) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700878 const egl_display_ptr dp = validate_display(dpy);
Jamie Gennise8696a42012-01-15 18:54:57 -0800879 if (!dp) {
880 return;
881 }
882
Jesse Hallb29e5e82012-04-04 16:53:42 -0700883 SurfaceRef _s(dp.get(), surface);
Jamie Gennise8696a42012-01-15 18:54:57 -0800884 if (!_s.get()) {
885 setError(EGL_BAD_SURFACE, EGL_FALSE);
Jamie Gennise8696a42012-01-15 18:54:57 -0800886 }
Jamie Gennise8696a42012-01-15 18:54:57 -0800887}
888
Mathias Agopian518ec112011-05-13 16:21:08 -0700889// ----------------------------------------------------------------------------
890// Contexts
891// ----------------------------------------------------------------------------
892
Cody Northrop68d10352018-10-15 07:22:09 -0600893EGLContext eglCreateContextImpl(EGLDisplay dpy, EGLConfig config,
894 EGLContext share_list, const EGLint *attrib_list)
Mathias Agopian518ec112011-05-13 16:21:08 -0700895{
Yi Kong48a6cd22018-07-18 10:07:09 -0700896 egl_connection_t* cnx = nullptr;
Jesse Hallb29e5e82012-04-04 16:53:42 -0700897 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
Michael Chock0673e1e2012-06-21 12:53:17 -0700898 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700899 if (share_list != EGL_NO_CONTEXT) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700900 if (!ContextRef(dp.get(), share_list).get()) {
901 return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
902 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700903 egl_context_t* const c = get_context(share_list);
904 share_list = c->context;
905 }
906 EGLContext context = cnx->egl.eglCreateContext(
Mathias Agopian7773c432012-02-13 20:06:08 -0800907 dp->disp.dpy, config, share_list, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700908 if (context != EGL_NO_CONTEXT) {
909 // figure out if it's a GLESv1 or GLESv2
910 int version = 0;
911 if (attrib_list) {
912 while (*attrib_list != EGL_NONE) {
913 GLint attr = *attrib_list++;
914 GLint value = *attrib_list++;
915 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
916 if (value == 1) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800917 version = egl_connection_t::GLESv1_INDEX;
Jesse Hall47743382013-02-08 11:13:46 -0800918 } else if (value == 2 || value == 3) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800919 version = egl_connection_t::GLESv2_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700920 }
921 }
922 };
923 }
Jesse Hallb29e5e82012-04-04 16:53:42 -0700924 egl_context_t* c = new egl_context_t(dpy, context, config, cnx,
925 version);
Mathias Agopian518ec112011-05-13 16:21:08 -0700926 return c;
927 }
928 }
929 return EGL_NO_CONTEXT;
930}
931
Cody Northrop68d10352018-10-15 07:22:09 -0600932EGLBoolean eglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx)
Mathias Agopian518ec112011-05-13 16:21:08 -0700933{
Jesse Hallb29e5e82012-04-04 16:53:42 -0700934 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700935 if (!dp)
936 return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700937
Jesse Hallb29e5e82012-04-04 16:53:42 -0700938 ContextRef _c(dp.get(), ctx);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700939 if (!_c.get())
Mathias Agopian737b8962017-02-24 14:32:05 -0800940 return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);
Jesse Hall47743382013-02-08 11:13:46 -0800941
Mathias Agopian518ec112011-05-13 16:21:08 -0700942 egl_context_t * const c = get_context(ctx);
Mathias Agopianada798b2012-02-13 17:09:30 -0800943 EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
Mathias Agopian518ec112011-05-13 16:21:08 -0700944 if (result == EGL_TRUE) {
945 _c.terminate();
946 }
947 return result;
948}
949
Cody Northrop68d10352018-10-15 07:22:09 -0600950EGLBoolean eglMakeCurrentImpl( EGLDisplay dpy, EGLSurface draw,
951 EGLSurface read, EGLContext ctx)
Mathias Agopian518ec112011-05-13 16:21:08 -0700952{
Jesse Hallb29e5e82012-04-04 16:53:42 -0700953 egl_display_ptr dp = validate_display(dpy);
Mathias Agopian737b8962017-02-24 14:32:05 -0800954 if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700955
Mathias Agopian5b287a62011-05-16 18:58:55 -0700956 // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
957 // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
958 // a valid but uninitialized display.
Mathias Agopian518ec112011-05-13 16:21:08 -0700959 if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
960 (draw != EGL_NO_SURFACE) ) {
Mathias Agopian737b8962017-02-24 14:32:05 -0800961 if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700962 }
963
964 // get a reference to the object passed in
Jesse Hallb29e5e82012-04-04 16:53:42 -0700965 ContextRef _c(dp.get(), ctx);
966 SurfaceRef _d(dp.get(), draw);
967 SurfaceRef _r(dp.get(), read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700968
969 // validate the context (if not EGL_NO_CONTEXT)
Mathias Agopian5b287a62011-05-16 18:58:55 -0700970 if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700971 // EGL_NO_CONTEXT is valid
Mathias Agopian737b8962017-02-24 14:32:05 -0800972 return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700973 }
974
975 // these are the underlying implementation's object
976 EGLContext impl_ctx = EGL_NO_CONTEXT;
977 EGLSurface impl_draw = EGL_NO_SURFACE;
978 EGLSurface impl_read = EGL_NO_SURFACE;
979
980 // these are our objects structs passed in
Yi Kong48a6cd22018-07-18 10:07:09 -0700981 egl_context_t * c = nullptr;
982 egl_surface_t const * d = nullptr;
983 egl_surface_t const * r = nullptr;
Mathias Agopian518ec112011-05-13 16:21:08 -0700984
985 // these are the current objects structs
986 egl_context_t * cur_c = get_context(getContext());
Jesse Hall47743382013-02-08 11:13:46 -0800987
Mathias Agopian518ec112011-05-13 16:21:08 -0700988 if (ctx != EGL_NO_CONTEXT) {
989 c = get_context(ctx);
990 impl_ctx = c->context;
991 } else {
992 // no context given, use the implementation of the current context
Michael Chock0673e1e2012-06-21 12:53:17 -0700993 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
994 // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
Mathias Agopian737b8962017-02-24 14:32:05 -0800995 return setError(EGL_BAD_MATCH, (EGLBoolean)EGL_FALSE);
Michael Chock0673e1e2012-06-21 12:53:17 -0700996 }
Yi Kong48a6cd22018-07-18 10:07:09 -0700997 if (cur_c == nullptr) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700998 // no current context
Mathias Agopian518ec112011-05-13 16:21:08 -0700999 // not an error, there is just no current context.
1000 return EGL_TRUE;
1001 }
1002 }
1003
1004 // retrieve the underlying implementation's draw EGLSurface
1005 if (draw != EGL_NO_SURFACE) {
Mathias Agopian737b8962017-02-24 14:32:05 -08001006 if (!_d.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001007 d = get_surface(draw);
Mathias Agopian518ec112011-05-13 16:21:08 -07001008 impl_draw = d->surface;
1009 }
1010
1011 // retrieve the underlying implementation's read EGLSurface
1012 if (read != EGL_NO_SURFACE) {
Mathias Agopian737b8962017-02-24 14:32:05 -08001013 if (!_r.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001014 r = get_surface(read);
Mathias Agopian518ec112011-05-13 16:21:08 -07001015 impl_read = r->surface;
1016 }
1017
Mathias Agopian518ec112011-05-13 16:21:08 -07001018
Jesse Hallb29e5e82012-04-04 16:53:42 -07001019 EGLBoolean result = dp->makeCurrent(c, cur_c,
Mathias Agopianfb87e542012-01-30 18:20:52 -08001020 draw, read, ctx,
1021 impl_draw, impl_read, impl_ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -07001022
1023 if (result == EGL_TRUE) {
Mathias Agopianfb87e542012-01-30 18:20:52 -08001024 if (c) {
Mathias Agopian518ec112011-05-13 16:21:08 -07001025 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
1026 egl_tls_t::setContext(ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -07001027 _c.acquire();
1028 _r.acquire();
1029 _d.acquire();
Mathias Agopian518ec112011-05-13 16:21:08 -07001030 } else {
1031 setGLHooksThreadSpecific(&gHooksNoContext);
1032 egl_tls_t::setContext(EGL_NO_CONTEXT);
1033 }
Mathias Agopian5fecea72011-08-25 18:38:24 -07001034 } else {
Steve Blocke6f43dd2012-01-06 19:20:56 +00001035 // this will ALOGE the error
Mathias Agopian63108c32013-09-06 13:36:49 -07001036 egl_connection_t* const cnx = &gEGLImpl;
Mathias Agopian737b8962017-02-24 14:32:05 -08001037 result = setError(cnx->egl.eglGetError(), (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001038 }
1039 return result;
1040}
1041
Cody Northrop68d10352018-10-15 07:22:09 -06001042EGLBoolean eglQueryContextImpl( EGLDisplay dpy, EGLContext ctx,
1043 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -07001044{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001045 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001046 if (!dp) return EGL_FALSE;
1047
Jesse Hallb29e5e82012-04-04 16:53:42 -07001048 ContextRef _c(dp.get(), ctx);
Mathias Agopian737b8962017-02-24 14:32:05 -08001049 if (!_c.get()) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001050
Mathias Agopian518ec112011-05-13 16:21:08 -07001051 egl_context_t * const c = get_context(ctx);
Mathias Agopian7773c432012-02-13 20:06:08 -08001052 return c->cnx->egl.eglQueryContext(
1053 dp->disp.dpy, c->context, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001054
Mathias Agopian518ec112011-05-13 16:21:08 -07001055}
1056
Cody Northrop68d10352018-10-15 07:22:09 -06001057EGLContext eglGetCurrentContextImpl(void)
Mathias Agopian518ec112011-05-13 16:21:08 -07001058{
1059 // could be called before eglInitialize(), but we wouldn't have a context
1060 // then, and this function would correctly return EGL_NO_CONTEXT.
Mathias Agopian518ec112011-05-13 16:21:08 -07001061 EGLContext ctx = getContext();
1062 return ctx;
1063}
1064
Cody Northrop68d10352018-10-15 07:22:09 -06001065EGLSurface eglGetCurrentSurfaceImpl(EGLint readdraw)
Mathias Agopian518ec112011-05-13 16:21:08 -07001066{
1067 // could be called before eglInitialize(), but we wouldn't have a context
1068 // then, and this function would correctly return EGL_NO_SURFACE.
1069
Mathias Agopian518ec112011-05-13 16:21:08 -07001070 EGLContext ctx = getContext();
1071 if (ctx) {
1072 egl_context_t const * const c = get_context(ctx);
1073 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
1074 switch (readdraw) {
1075 case EGL_READ: return c->read;
Jesse Hall47743382013-02-08 11:13:46 -08001076 case EGL_DRAW: return c->draw;
Mathias Agopian518ec112011-05-13 16:21:08 -07001077 default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
1078 }
1079 }
1080 return EGL_NO_SURFACE;
1081}
1082
Cody Northrop68d10352018-10-15 07:22:09 -06001083EGLDisplay eglGetCurrentDisplayImpl(void)
Mathias Agopian518ec112011-05-13 16:21:08 -07001084{
1085 // could be called before eglInitialize(), but we wouldn't have a context
1086 // then, and this function would correctly return EGL_NO_DISPLAY.
1087
Mathias Agopian518ec112011-05-13 16:21:08 -07001088 EGLContext ctx = getContext();
1089 if (ctx) {
1090 egl_context_t const * const c = get_context(ctx);
1091 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
1092 return c->dpy;
1093 }
1094 return EGL_NO_DISPLAY;
1095}
1096
Cody Northrop68d10352018-10-15 07:22:09 -06001097EGLBoolean eglWaitGLImpl(void)
Mathias Agopian518ec112011-05-13 16:21:08 -07001098{
Mathias Agopianada798b2012-02-13 17:09:30 -08001099 egl_connection_t* const cnx = &gEGLImpl;
1100 if (!cnx->dso)
Mathias Agopian737b8962017-02-24 14:32:05 -08001101 return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);
Mathias Agopianada798b2012-02-13 17:09:30 -08001102
1103 return cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001104}
1105
Cody Northrop68d10352018-10-15 07:22:09 -06001106EGLBoolean eglWaitNativeImpl(EGLint engine)
Mathias Agopian518ec112011-05-13 16:21:08 -07001107{
Mathias Agopianada798b2012-02-13 17:09:30 -08001108 egl_connection_t* const cnx = &gEGLImpl;
1109 if (!cnx->dso)
Mathias Agopian737b8962017-02-24 14:32:05 -08001110 return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);
Mathias Agopianada798b2012-02-13 17:09:30 -08001111
1112 return cnx->egl.eglWaitNative(engine);
Mathias Agopian518ec112011-05-13 16:21:08 -07001113}
1114
Cody Northrop68d10352018-10-15 07:22:09 -06001115EGLint eglGetErrorImpl(void)
Mathias Agopian518ec112011-05-13 16:21:08 -07001116{
Mathias Agopianada798b2012-02-13 17:09:30 -08001117 EGLint err = EGL_SUCCESS;
1118 egl_connection_t* const cnx = &gEGLImpl;
1119 if (cnx->dso) {
1120 err = cnx->egl.eglGetError();
Mathias Agopian518ec112011-05-13 16:21:08 -07001121 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001122 if (err == EGL_SUCCESS) {
1123 err = egl_tls_t::getError();
1124 }
1125 return err;
Mathias Agopian518ec112011-05-13 16:21:08 -07001126}
1127
Michael Chockc0ec5e22014-01-27 08:14:33 -08001128static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(
Jesse Hallc07b5202013-07-04 12:08:16 -07001129 const char* procname) {
1130 const egl_connection_t* cnx = &gEGLImpl;
Yi Kong48a6cd22018-07-18 10:07:09 -07001131 void* proc = nullptr;
Jesse Hallc07b5202013-07-04 12:08:16 -07001132
Michael Chockc0ec5e22014-01-27 08:14:33 -08001133 proc = dlsym(cnx->libEgl, procname);
1134 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
1135
Jesse Hallc07b5202013-07-04 12:08:16 -07001136 proc = dlsym(cnx->libGles2, procname);
1137 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
1138
1139 proc = dlsym(cnx->libGles1, procname);
1140 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
1141
Yi Kong48a6cd22018-07-18 10:07:09 -07001142 return nullptr;
Jesse Hallc07b5202013-07-04 12:08:16 -07001143}
1144
Cody Northrop68d10352018-10-15 07:22:09 -06001145__eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procname)
Mathias Agopian518ec112011-05-13 16:21:08 -07001146{
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -07001147 if (FILTER_EXTENSIONS(procname)) {
Yi Kong48a6cd22018-07-18 10:07:09 -07001148 return nullptr;
Jamie Gennisaca51c02011-11-03 17:42:43 -07001149 }
1150
Mathias Agopian518ec112011-05-13 16:21:08 -07001151 __eglMustCastToProperFunctionPointerType addr;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -07001152 addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap));
Mathias Agopian518ec112011-05-13 16:21:08 -07001153 if (addr) return addr;
1154
Michael Chockc0ec5e22014-01-27 08:14:33 -08001155 addr = findBuiltinWrapper(procname);
Jesse Hallc07b5202013-07-04 12:08:16 -07001156 if (addr) return addr;
Jamie Gennisaca51c02011-11-03 17:42:43 -07001157
Mathias Agopian518ec112011-05-13 16:21:08 -07001158 // this protects accesses to sGLExtentionMap and sGLExtentionSlot
1159 pthread_mutex_lock(&sExtensionMapMutex);
1160
Cody Northrop9f20d922018-10-12 14:34:26 -06001161 /*
1162 * Since eglGetProcAddress() is not associated to anything, it needs
1163 * to return a function pointer that "works" regardless of what
1164 * the current context is.
1165 *
1166 * For this reason, we return a "forwarder", a small stub that takes
1167 * care of calling the function associated with the context
1168 * currently bound.
1169 *
1170 * We first look for extensions we've already resolved, if we're seeing
1171 * this extension for the first time, we go through all our
1172 * implementations and call eglGetProcAddress() and record the
1173 * result in the appropriate implementation hooks and return the
1174 * address of the forwarder corresponding to that hook set.
1175 *
1176 */
Mathias Agopian518ec112011-05-13 16:21:08 -07001177
Cody Northrop9f20d922018-10-12 14:34:26 -06001178 const std::string name(procname);
Mathias Agopian65421432017-03-08 11:49:05 -08001179
1180 auto& extentionMap = sGLExtentionMap;
1181 auto pos = extentionMap.find(name);
Cody Northrop9f20d922018-10-12 14:34:26 -06001182 addr = (pos != extentionMap.end()) ? pos->second : nullptr;
1183 const int slot = sGLExtentionSlot;
Mathias Agopian518ec112011-05-13 16:21:08 -07001184
Cody Northrop9f20d922018-10-12 14:34:26 -06001185 ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
1186 "no more slots for eglGetProcAddress(\"%s\")",
1187 procname);
Mathias Agopian518ec112011-05-13 16:21:08 -07001188
Cody Northrop9f20d922018-10-12 14:34:26 -06001189 if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
1190 bool found = false;
Mathias Agopianada798b2012-02-13 17:09:30 -08001191
Cody Northrop9f20d922018-10-12 14:34:26 -06001192 egl_connection_t* const cnx = &gEGLImpl;
1193 if (cnx->dso && cnx->egl.eglGetProcAddress) {
1194 // Extensions are independent of the bound context
1195 addr =
Cody Northropd9f0ec42018-10-04 14:48:07 -06001196 cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
Cody Northrop9f20d922018-10-12 14:34:26 -06001197 cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
1198 cnx->egl.eglGetProcAddress(procname);
1199 if (addr) found = true;
1200 }
1201
1202 if (found) {
Cody Northropd9f0ec42018-10-04 14:48:07 -06001203 addr = gExtensionForwarders[slot];
Cody Northrop9f20d922018-10-12 14:34:26 -06001204 extentionMap[name] = addr;
Mathias Agopian518ec112011-05-13 16:21:08 -07001205 sGLExtentionSlot++;
1206 }
1207 }
1208
1209 pthread_mutex_unlock(&sExtensionMapMutex);
1210 return addr;
1211}
1212
Mathias Agopian65421432017-03-08 11:49:05 -08001213class FrameCompletionThread {
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001214public:
1215
1216 static void queueSync(EGLSyncKHR sync) {
Mathias Agopian65421432017-03-08 11:49:05 -08001217 static FrameCompletionThread thread;
1218
1219 char name[64];
1220
1221 std::lock_guard<std::mutex> lock(thread.mMutex);
1222 snprintf(name, sizeof(name), "kicked off frame %u", (unsigned int)thread.mFramesQueued);
1223 ATRACE_NAME(name);
1224
1225 thread.mQueue.push_back(sync);
1226 thread.mCondition.notify_one();
1227 thread.mFramesQueued++;
1228 ATRACE_INT("GPU Frames Outstanding", int32_t(thread.mQueue.size()));
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001229 }
1230
1231private:
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001232
Mathias Agopian65421432017-03-08 11:49:05 -08001233 FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {
1234 std::thread thread(&FrameCompletionThread::loop, this);
1235 thread.detach();
1236 }
1237
1238#pragma clang diagnostic push
1239#pragma clang diagnostic ignored "-Wmissing-noreturn"
1240 void loop() {
1241 while (true) {
1242 threadLoop();
1243 }
1244 }
1245#pragma clang diagnostic pop
1246
1247 void threadLoop() {
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001248 EGLSyncKHR sync;
1249 uint32_t frameNum;
1250 {
Mathias Agopian65421432017-03-08 11:49:05 -08001251 std::unique_lock<std::mutex> lock(mMutex);
1252 while (mQueue.empty()) {
1253 mCondition.wait(lock);
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001254 }
1255 sync = mQueue[0];
1256 frameNum = mFramesCompleted;
1257 }
1258 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1259 {
Mathias Agopian65421432017-03-08 11:49:05 -08001260 char name[64];
1261 snprintf(name, sizeof(name), "waiting for frame %u", (unsigned int)frameNum);
1262 ATRACE_NAME(name);
1263
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001264 EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR);
1265 if (result == EGL_FALSE) {
1266 ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError());
1267 } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
1268 ALOGE("FrameCompletion: timeout waiting for fence");
1269 }
1270 eglDestroySyncKHR(dpy, sync);
1271 }
1272 {
Mathias Agopian65421432017-03-08 11:49:05 -08001273 std::lock_guard<std::mutex> lock(mMutex);
1274 mQueue.pop_front();
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001275 mFramesCompleted++;
Mathias Agopian737b8962017-02-24 14:32:05 -08001276 ATRACE_INT("GPU Frames Outstanding", int32_t(mQueue.size()));
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001277 }
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001278 }
1279
1280 uint32_t mFramesQueued;
1281 uint32_t mFramesCompleted;
Mathias Agopian65421432017-03-08 11:49:05 -08001282 std::deque<EGLSyncKHR> mQueue;
1283 std::condition_variable mCondition;
1284 std::mutex mMutex;
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001285};
1286
Cody Northrop68d10352018-10-15 07:22:09 -06001287EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw,
Dan Stozaa894d082015-02-19 15:27:36 -08001288 EGLint *rects, EGLint n_rects)
Mathias Agopian518ec112011-05-13 16:21:08 -07001289{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001290 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001291 if (!dp) return EGL_FALSE;
1292
Jesse Hallb29e5e82012-04-04 16:53:42 -07001293 SurfaceRef _s(dp.get(), draw);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001294 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -08001295 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001296
Courtney Goeltzenleuchter936799c2018-03-02 16:47:08 -07001297 egl_surface_t* const s = get_surface(draw);
Mathias Agopian7db993a2012-03-25 00:49:46 -07001298
Mathias Agopianed6d08b2013-04-16 16:39:46 -07001299 if (CC_UNLIKELY(dp->traceGpuCompletion)) {
Yi Kong48a6cd22018-07-18 10:07:09 -07001300 EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, nullptr);
Mathias Agopianed6d08b2013-04-16 16:39:46 -07001301 if (sync != EGL_NO_SYNC_KHR) {
1302 FrameCompletionThread::queueSync(sync);
1303 }
1304 }
1305
Mathias Agopian7db993a2012-03-25 00:49:46 -07001306 if (CC_UNLIKELY(dp->finishOnSwap)) {
1307 uint32_t pixel;
1308 egl_context_t * const c = get_context( egl_tls_t::getContext() );
1309 if (c) {
1310 // glReadPixels() ensures that the frame is complete
1311 s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1,
1312 GL_RGBA,GL_UNSIGNED_BYTE,&pixel);
1313 }
1314 }
1315
Courtney Goeltzenleuchter555f1df2018-09-25 14:34:29 -06001316 if (s->cnx->angleBackend != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) {
1317 if (!sendSurfaceMetadata(s)) {
1318 native_window_api_disconnect(s->getNativeWindow(), NATIVE_WINDOW_API_EGL);
1319 return setError(EGL_BAD_NATIVE_WINDOW, (EGLBoolean)EGL_FALSE);
1320 }
Courtney Goeltzenleuchter936799c2018-03-02 16:47:08 -07001321 }
1322
Dan Stozaa894d082015-02-19 15:27:36 -08001323 if (n_rects == 0) {
1324 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1325 }
1326
Mathias Agopian65421432017-03-08 11:49:05 -08001327 std::vector<android_native_rect_t> androidRects((size_t)n_rects);
Dan Stozaa894d082015-02-19 15:27:36 -08001328 for (int r = 0; r < n_rects; ++r) {
1329 int offset = r * 4;
1330 int x = rects[offset];
1331 int y = rects[offset + 1];
1332 int width = rects[offset + 2];
1333 int height = rects[offset + 3];
1334 android_native_rect_t androidRect;
1335 androidRect.left = x;
1336 androidRect.top = y + height;
1337 androidRect.right = x + width;
1338 androidRect.bottom = y;
1339 androidRects.push_back(androidRect);
1340 }
Courtney Goeltzenleuchter555f1df2018-09-25 14:34:29 -06001341 if (s->cnx->angleBackend != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) {
1342 native_window_set_surface_damage(s->getNativeWindow(), androidRects.data(),
1343 androidRects.size());
1344 }
Dan Stozaa894d082015-02-19 15:27:36 -08001345
1346 if (s->cnx->egl.eglSwapBuffersWithDamageKHR) {
1347 return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface,
1348 rects, n_rects);
1349 } else {
1350 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1351 }
1352}
1353
Cody Northrop68d10352018-10-15 07:22:09 -06001354EGLBoolean eglSwapBuffersImpl(EGLDisplay dpy, EGLSurface surface)
Dan Stozaa894d082015-02-19 15:27:36 -08001355{
Cody Northrop68d10352018-10-15 07:22:09 -06001356 return eglSwapBuffersWithDamageKHRImpl(dpy, surface, nullptr, 0);
Mathias Agopian518ec112011-05-13 16:21:08 -07001357}
1358
Cody Northrop68d10352018-10-15 07:22:09 -06001359EGLBoolean eglCopyBuffersImpl( EGLDisplay dpy, EGLSurface surface,
1360 NativePixmapType target)
Mathias Agopian518ec112011-05-13 16:21:08 -07001361{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001362 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001363 if (!dp) return EGL_FALSE;
1364
Jesse Hallb29e5e82012-04-04 16:53:42 -07001365 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001366 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -08001367 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001368
Mathias Agopian518ec112011-05-13 16:21:08 -07001369 egl_surface_t const * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -08001370 return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
Mathias Agopian518ec112011-05-13 16:21:08 -07001371}
1372
Cody Northrop68d10352018-10-15 07:22:09 -06001373const char* eglQueryStringImpl(EGLDisplay dpy, EGLint name)
Mathias Agopian518ec112011-05-13 16:21:08 -07001374{
Chia-I Wue57d1352016-08-15 16:10:02 +08001375 // Generate an error quietly when client extensions (as defined by
1376 // EGL_EXT_client_extensions) are queried. We do not want to rely on
1377 // validate_display to generate the error as validate_display would log
1378 // the error, which can be misleading.
1379 //
1380 // If we want to support EGL_EXT_client_extensions later, we can return
1381 // the client extension string here instead.
1382 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS)
Yi Kong48a6cd22018-07-18 10:07:09 -07001383 return setErrorQuiet(EGL_BAD_DISPLAY, (const char*)nullptr);
Chia-I Wue57d1352016-08-15 16:10:02 +08001384
Jesse Hallb29e5e82012-04-04 16:53:42 -07001385 const egl_display_ptr dp = validate_display(dpy);
Yi Kong48a6cd22018-07-18 10:07:09 -07001386 if (!dp) return (const char *) nullptr;
Mathias Agopian518ec112011-05-13 16:21:08 -07001387
1388 switch (name) {
1389 case EGL_VENDOR:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001390 return dp->getVendorString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001391 case EGL_VERSION:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001392 return dp->getVersionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001393 case EGL_EXTENSIONS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001394 return dp->getExtensionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001395 case EGL_CLIENT_APIS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001396 return dp->getClientApiString();
Mathias Agopian737b8962017-02-24 14:32:05 -08001397 default:
1398 break;
Mathias Agopian518ec112011-05-13 16:21:08 -07001399 }
Yi Kong48a6cd22018-07-18 10:07:09 -07001400 return setError(EGL_BAD_PARAMETER, (const char *)nullptr);
Mathias Agopian518ec112011-05-13 16:21:08 -07001401}
1402
Cody Northrop68d10352018-10-15 07:22:09 -06001403EGLAPI const char* eglQueryStringImplementationANDROIDImpl(EGLDisplay dpy, EGLint name)
Mathias Agopianca088332013-03-28 17:44:13 -07001404{
Mathias Agopianca088332013-03-28 17:44:13 -07001405 const egl_display_ptr dp = validate_display(dpy);
Yi Kong48a6cd22018-07-18 10:07:09 -07001406 if (!dp) return (const char *) nullptr;
Mathias Agopianca088332013-03-28 17:44:13 -07001407
1408 switch (name) {
1409 case EGL_VENDOR:
1410 return dp->disp.queryString.vendor;
1411 case EGL_VERSION:
1412 return dp->disp.queryString.version;
1413 case EGL_EXTENSIONS:
1414 return dp->disp.queryString.extensions;
1415 case EGL_CLIENT_APIS:
1416 return dp->disp.queryString.clientApi;
Mathias Agopian737b8962017-02-24 14:32:05 -08001417 default:
1418 break;
Mathias Agopianca088332013-03-28 17:44:13 -07001419 }
Yi Kong48a6cd22018-07-18 10:07:09 -07001420 return setError(EGL_BAD_PARAMETER, (const char *)nullptr);
Mathias Agopianca088332013-03-28 17:44:13 -07001421}
Mathias Agopian518ec112011-05-13 16:21:08 -07001422
1423// ----------------------------------------------------------------------------
1424// EGL 1.1
1425// ----------------------------------------------------------------------------
1426
Cody Northrop68d10352018-10-15 07:22:09 -06001427EGLBoolean eglSurfaceAttribImpl(
Mathias Agopian518ec112011-05-13 16:21:08 -07001428 EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1429{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001430 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001431 if (!dp) return EGL_FALSE;
1432
Jesse Hallb29e5e82012-04-04 16:53:42 -07001433 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001434 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -08001435 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001436
Pablo Ceballosc18be292016-05-31 14:55:42 -07001437 egl_surface_t * const s = get_surface(surface);
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001438
Pablo Ceballos02b05da2016-02-02 17:53:18 -08001439 if (attribute == EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID) {
Mathias Agopian65421432017-03-08 11:49:05 -08001440 if (!s->getNativeWindow()) {
Brian Anderson069b3652016-07-22 10:32:47 -07001441 setError(EGL_BAD_SURFACE, EGL_FALSE);
1442 }
Mathias Agopian65421432017-03-08 11:49:05 -08001443 int err = native_window_set_auto_refresh(s->getNativeWindow(), value != 0);
1444 return (err == 0) ? EGL_TRUE : setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001445 }
1446
Pablo Ceballosc18be292016-05-31 14:55:42 -07001447 if (attribute == EGL_TIMESTAMPS_ANDROID) {
Mathias Agopian65421432017-03-08 11:49:05 -08001448 if (!s->getNativeWindow()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08001449 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson069b3652016-07-22 10:32:47 -07001450 }
Mathias Agopian65421432017-03-08 11:49:05 -08001451 int err = native_window_enable_frame_timestamps(s->getNativeWindow(), value != 0);
1452 return (err == 0) ? EGL_TRUE : setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07001453 }
1454
Courtney Goeltzenleuchter786ab882018-01-26 13:37:33 -08001455 if (s->setSmpte2086Attribute(attribute, value)) {
1456 return EGL_TRUE;
1457 } else if (s->setCta8613Attribute(attribute, value)) {
1458 return EGL_TRUE;
1459 } else if (s->cnx->egl.eglSurfaceAttrib) {
Mathias Agopian518ec112011-05-13 16:21:08 -07001460 return s->cnx->egl.eglSurfaceAttrib(
Mathias Agopianada798b2012-02-13 17:09:30 -08001461 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001462 }
Mathias Agopian737b8962017-02-24 14:32:05 -08001463 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001464}
1465
Cody Northrop68d10352018-10-15 07:22:09 -06001466EGLBoolean eglBindTexImageImpl(
Mathias Agopian518ec112011-05-13 16:21:08 -07001467 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1468{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001469 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001470 if (!dp) return EGL_FALSE;
1471
Jesse Hallb29e5e82012-04-04 16:53:42 -07001472 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001473 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -08001474 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001475
Mathias Agopian518ec112011-05-13 16:21:08 -07001476 egl_surface_t const * const s = get_surface(surface);
1477 if (s->cnx->egl.eglBindTexImage) {
1478 return s->cnx->egl.eglBindTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001479 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001480 }
Mathias Agopian737b8962017-02-24 14:32:05 -08001481 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001482}
1483
Cody Northrop68d10352018-10-15 07:22:09 -06001484EGLBoolean eglReleaseTexImageImpl(
Mathias Agopian518ec112011-05-13 16:21:08 -07001485 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1486{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001487 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001488 if (!dp) return EGL_FALSE;
1489
Jesse Hallb29e5e82012-04-04 16:53:42 -07001490 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001491 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -08001492 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001493
Mathias Agopian518ec112011-05-13 16:21:08 -07001494 egl_surface_t const * const s = get_surface(surface);
1495 if (s->cnx->egl.eglReleaseTexImage) {
1496 return s->cnx->egl.eglReleaseTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001497 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001498 }
Mathias Agopian737b8962017-02-24 14:32:05 -08001499 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001500}
1501
Cody Northrop68d10352018-10-15 07:22:09 -06001502EGLBoolean eglSwapIntervalImpl(EGLDisplay dpy, EGLint interval)
Mathias Agopian518ec112011-05-13 16:21:08 -07001503{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001504 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001505 if (!dp) return EGL_FALSE;
1506
1507 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001508 egl_connection_t* const cnx = &gEGLImpl;
1509 if (cnx->dso && cnx->egl.eglSwapInterval) {
1510 res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
Mathias Agopian518ec112011-05-13 16:21:08 -07001511 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001512
Mathias Agopian518ec112011-05-13 16:21:08 -07001513 return res;
1514}
1515
1516
1517// ----------------------------------------------------------------------------
1518// EGL 1.2
1519// ----------------------------------------------------------------------------
1520
Cody Northrop68d10352018-10-15 07:22:09 -06001521EGLBoolean eglWaitClientImpl(void)
Mathias Agopian518ec112011-05-13 16:21:08 -07001522{
Mathias Agopianada798b2012-02-13 17:09:30 -08001523 egl_connection_t* const cnx = &gEGLImpl;
1524 if (!cnx->dso)
Mathias Agopian737b8962017-02-24 14:32:05 -08001525 return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);
Mathias Agopianada798b2012-02-13 17:09:30 -08001526
1527 EGLBoolean res;
1528 if (cnx->egl.eglWaitClient) {
1529 res = cnx->egl.eglWaitClient();
1530 } else {
1531 res = cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001532 }
1533 return res;
1534}
1535
Cody Northrop68d10352018-10-15 07:22:09 -06001536EGLBoolean eglBindAPIImpl(EGLenum api)
Mathias Agopian518ec112011-05-13 16:21:08 -07001537{
Mathias Agopian518ec112011-05-13 16:21:08 -07001538 // bind this API on all EGLs
1539 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001540 egl_connection_t* const cnx = &gEGLImpl;
1541 if (cnx->dso && cnx->egl.eglBindAPI) {
1542 res = cnx->egl.eglBindAPI(api);
Mathias Agopian518ec112011-05-13 16:21:08 -07001543 }
1544 return res;
1545}
1546
Cody Northrop68d10352018-10-15 07:22:09 -06001547EGLenum eglQueryAPIImpl(void)
Mathias Agopian518ec112011-05-13 16:21:08 -07001548{
Mathias Agopianada798b2012-02-13 17:09:30 -08001549 egl_connection_t* const cnx = &gEGLImpl;
1550 if (cnx->dso && cnx->egl.eglQueryAPI) {
1551 return cnx->egl.eglQueryAPI();
Mathias Agopian518ec112011-05-13 16:21:08 -07001552 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001553
Mathias Agopian518ec112011-05-13 16:21:08 -07001554 // or, it can only be OpenGL ES
1555 return EGL_OPENGL_ES_API;
1556}
1557
Cody Northrop68d10352018-10-15 07:22:09 -06001558EGLBoolean eglReleaseThreadImpl(void)
Mathias Agopian518ec112011-05-13 16:21:08 -07001559{
Mathias Agopianada798b2012-02-13 17:09:30 -08001560 egl_connection_t* const cnx = &gEGLImpl;
1561 if (cnx->dso && cnx->egl.eglReleaseThread) {
1562 cnx->egl.eglReleaseThread();
Mathias Agopian518ec112011-05-13 16:21:08 -07001563 }
Sai Kiran Korwar3ac517a2014-01-31 21:15:07 +05301564
1565 // If there is context bound to the thread, release it
1566 egl_display_t::loseCurrent(get_context(getContext()));
1567
Mathias Agopian518ec112011-05-13 16:21:08 -07001568 egl_tls_t::clearTLS();
Mathias Agopian518ec112011-05-13 16:21:08 -07001569 return EGL_TRUE;
1570}
1571
Cody Northrop68d10352018-10-15 07:22:09 -06001572EGLSurface eglCreatePbufferFromClientBufferImpl(
Mathias Agopian518ec112011-05-13 16:21:08 -07001573 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
1574 EGLConfig config, const EGLint *attrib_list)
1575{
Yi Kong48a6cd22018-07-18 10:07:09 -07001576 egl_connection_t* cnx = nullptr;
Jesse Hallb29e5e82012-04-04 16:53:42 -07001577 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
1578 if (!dp) return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -07001579 if (cnx->egl.eglCreatePbufferFromClientBuffer) {
1580 return cnx->egl.eglCreatePbufferFromClientBuffer(
Mathias Agopian7773c432012-02-13 20:06:08 -08001581 dp->disp.dpy, buftype, buffer, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001582 }
1583 return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
1584}
1585
1586// ----------------------------------------------------------------------------
1587// EGL_EGLEXT_VERSION 3
1588// ----------------------------------------------------------------------------
1589
Cody Northrop68d10352018-10-15 07:22:09 -06001590EGLBoolean eglLockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface,
Mathias Agopian518ec112011-05-13 16:21:08 -07001591 const EGLint *attrib_list)
1592{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001593 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001594 if (!dp) return EGL_FALSE;
1595
Jesse Hallb29e5e82012-04-04 16:53:42 -07001596 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001597 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -08001598 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001599
1600 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001601 if (s->cnx->egl.eglLockSurfaceKHR) {
1602 return s->cnx->egl.eglLockSurfaceKHR(
Mathias Agopianada798b2012-02-13 17:09:30 -08001603 dp->disp.dpy, s->surface, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001604 }
Mathias Agopian737b8962017-02-24 14:32:05 -08001605 return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001606}
1607
Cody Northrop68d10352018-10-15 07:22:09 -06001608EGLBoolean eglUnlockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface)
Mathias Agopian518ec112011-05-13 16:21:08 -07001609{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001610 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001611 if (!dp) return EGL_FALSE;
1612
Jesse Hallb29e5e82012-04-04 16:53:42 -07001613 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001614 if (!_s.get())
Mathias Agopian737b8962017-02-24 14:32:05 -08001615 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001616
1617 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001618 if (s->cnx->egl.eglUnlockSurfaceKHR) {
Mathias Agopianada798b2012-02-13 17:09:30 -08001619 return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001620 }
Mathias Agopian737b8962017-02-24 14:32:05 -08001621 return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001622}
1623
Cody Northrop68d10352018-10-15 07:22:09 -06001624EGLImageKHR eglCreateImageKHRImpl(EGLDisplay dpy, EGLContext ctx, EGLenum target,
Mathias Agopian518ec112011-05-13 16:21:08 -07001625 EGLClientBuffer buffer, const EGLint *attrib_list)
1626{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001627 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001628 if (!dp) return EGL_NO_IMAGE_KHR;
1629
Jesse Hallb29e5e82012-04-04 16:53:42 -07001630 ContextRef _c(dp.get(), ctx);
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001631 egl_context_t * const c = _c.get();
Mathias Agopian518ec112011-05-13 16:21:08 -07001632
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001633 EGLImageKHR result = EGL_NO_IMAGE_KHR;
1634 egl_connection_t* const cnx = &gEGLImpl;
1635 if (cnx->dso && cnx->egl.eglCreateImageKHR) {
1636 result = cnx->egl.eglCreateImageKHR(
1637 dp->disp.dpy,
1638 c ? c->context : EGL_NO_CONTEXT,
Krzysztof Kosiński30c1d902018-06-27 17:14:33 -07001639 target, buffer, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001640 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001641 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001642}
1643
Cody Northrop68d10352018-10-15 07:22:09 -06001644EGLBoolean eglDestroyImageKHRImpl(EGLDisplay dpy, EGLImageKHR img)
Mathias Agopian518ec112011-05-13 16:21:08 -07001645{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001646 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001647 if (!dp) return EGL_FALSE;
1648
Steven Holte646a5c52012-06-04 20:02:11 -07001649 EGLBoolean result = EGL_FALSE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001650 egl_connection_t* const cnx = &gEGLImpl;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001651 if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
Steven Holte646a5c52012-06-04 20:02:11 -07001652 result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
Mathias Agopian518ec112011-05-13 16:21:08 -07001653 }
Steven Holte646a5c52012-06-04 20:02:11 -07001654 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001655}
1656
1657// ----------------------------------------------------------------------------
1658// EGL_EGLEXT_VERSION 5
1659// ----------------------------------------------------------------------------
1660
1661
Cody Northrop68d10352018-10-15 07:22:09 -06001662EGLSyncKHR eglCreateSyncKHRImpl(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
Mathias Agopian518ec112011-05-13 16:21:08 -07001663{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001664 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001665 if (!dp) return EGL_NO_SYNC_KHR;
1666
Mathias Agopian518ec112011-05-13 16:21:08 -07001667 EGLSyncKHR result = EGL_NO_SYNC_KHR;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001668 egl_connection_t* const cnx = &gEGLImpl;
1669 if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
1670 result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001671 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001672 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001673}
1674
Cody Northrop68d10352018-10-15 07:22:09 -06001675EGLBoolean eglDestroySyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync)
Mathias Agopian518ec112011-05-13 16:21:08 -07001676{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001677 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001678 if (!dp) return EGL_FALSE;
1679
Mathias Agopian518ec112011-05-13 16:21:08 -07001680 EGLBoolean result = EGL_FALSE;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001681 egl_connection_t* const cnx = &gEGLImpl;
1682 if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
1683 result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
Mathias Agopian518ec112011-05-13 16:21:08 -07001684 }
1685 return result;
1686}
1687
Cody Northrop68d10352018-10-15 07:22:09 -06001688EGLBoolean eglSignalSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) {
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -07001689 const egl_display_ptr dp = validate_display(dpy);
1690 if (!dp) return EGL_FALSE;
1691
1692 EGLBoolean result = EGL_FALSE;
1693 egl_connection_t* const cnx = &gEGLImpl;
1694 if (cnx->dso && cnx->egl.eglSignalSyncKHR) {
1695 result = cnx->egl.eglSignalSyncKHR(
1696 dp->disp.dpy, sync, mode);
1697 }
1698 return result;
1699}
1700
Cody Northrop68d10352018-10-15 07:22:09 -06001701EGLint eglClientWaitSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync,
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001702 EGLint flags, EGLTimeKHR timeout)
Mathias Agopian518ec112011-05-13 16:21:08 -07001703{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001704 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001705 if (!dp) return EGL_FALSE;
1706
Mathias Agopian737b8962017-02-24 14:32:05 -08001707 EGLint result = EGL_FALSE;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001708 egl_connection_t* const cnx = &gEGLImpl;
1709 if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {
1710 result = cnx->egl.eglClientWaitSyncKHR(
1711 dp->disp.dpy, sync, flags, timeout);
Mathias Agopian518ec112011-05-13 16:21:08 -07001712 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001713 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001714}
1715
Cody Northrop68d10352018-10-15 07:22:09 -06001716EGLBoolean eglGetSyncAttribKHRImpl(EGLDisplay dpy, EGLSyncKHR sync,
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001717 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -07001718{
Jesse Hallb29e5e82012-04-04 16:53:42 -07001719 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001720 if (!dp) return EGL_FALSE;
1721
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001722 EGLBoolean result = EGL_FALSE;
1723 egl_connection_t* const cnx = &gEGLImpl;
1724 if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
1725 result = cnx->egl.eglGetSyncAttribKHR(
1726 dp->disp.dpy, sync, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001727 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001728 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001729}
1730
Cody Northrop68d10352018-10-15 07:22:09 -06001731EGLStreamKHR eglCreateStreamKHRImpl(EGLDisplay dpy, const EGLint *attrib_list)
Season Li000d88f2015-07-01 11:39:40 -07001732{
Season Li000d88f2015-07-01 11:39:40 -07001733 const egl_display_ptr dp = validate_display(dpy);
1734 if (!dp) return EGL_NO_STREAM_KHR;
1735
1736 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1737 egl_connection_t* const cnx = &gEGLImpl;
1738 if (cnx->dso && cnx->egl.eglCreateStreamKHR) {
1739 result = cnx->egl.eglCreateStreamKHR(
1740 dp->disp.dpy, attrib_list);
1741 }
1742 return result;
1743}
1744
Cody Northrop68d10352018-10-15 07:22:09 -06001745EGLBoolean eglDestroyStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream)
Season Li000d88f2015-07-01 11:39:40 -07001746{
Season Li000d88f2015-07-01 11:39:40 -07001747 const egl_display_ptr dp = validate_display(dpy);
1748 if (!dp) return EGL_FALSE;
1749
1750 EGLBoolean result = EGL_FALSE;
1751 egl_connection_t* const cnx = &gEGLImpl;
1752 if (cnx->dso && cnx->egl.eglDestroyStreamKHR) {
1753 result = cnx->egl.eglDestroyStreamKHR(
1754 dp->disp.dpy, stream);
1755 }
1756 return result;
1757}
1758
Cody Northrop68d10352018-10-15 07:22:09 -06001759EGLBoolean eglStreamAttribKHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
Season Li000d88f2015-07-01 11:39:40 -07001760 EGLenum attribute, EGLint value)
1761{
Season Li000d88f2015-07-01 11:39:40 -07001762 const egl_display_ptr dp = validate_display(dpy);
1763 if (!dp) return EGL_FALSE;
1764
1765 EGLBoolean result = EGL_FALSE;
1766 egl_connection_t* const cnx = &gEGLImpl;
1767 if (cnx->dso && cnx->egl.eglStreamAttribKHR) {
1768 result = cnx->egl.eglStreamAttribKHR(
1769 dp->disp.dpy, stream, attribute, value);
1770 }
1771 return result;
1772}
1773
Cody Northrop68d10352018-10-15 07:22:09 -06001774EGLBoolean eglQueryStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
Season Li000d88f2015-07-01 11:39:40 -07001775 EGLenum attribute, EGLint *value)
1776{
Season Li000d88f2015-07-01 11:39:40 -07001777 const egl_display_ptr dp = validate_display(dpy);
1778 if (!dp) return EGL_FALSE;
1779
1780 EGLBoolean result = EGL_FALSE;
1781 egl_connection_t* const cnx = &gEGLImpl;
1782 if (cnx->dso && cnx->egl.eglQueryStreamKHR) {
1783 result = cnx->egl.eglQueryStreamKHR(
1784 dp->disp.dpy, stream, attribute, value);
1785 }
1786 return result;
1787}
1788
Cody Northrop68d10352018-10-15 07:22:09 -06001789EGLBoolean eglQueryStreamu64KHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
Season Li000d88f2015-07-01 11:39:40 -07001790 EGLenum attribute, EGLuint64KHR *value)
1791{
Season Li000d88f2015-07-01 11:39:40 -07001792 const egl_display_ptr dp = validate_display(dpy);
1793 if (!dp) return EGL_FALSE;
1794
1795 EGLBoolean result = EGL_FALSE;
1796 egl_connection_t* const cnx = &gEGLImpl;
1797 if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) {
1798 result = cnx->egl.eglQueryStreamu64KHR(
1799 dp->disp.dpy, stream, attribute, value);
1800 }
1801 return result;
1802}
1803
Cody Northrop68d10352018-10-15 07:22:09 -06001804EGLBoolean eglQueryStreamTimeKHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
Season Li000d88f2015-07-01 11:39:40 -07001805 EGLenum attribute, EGLTimeKHR *value)
1806{
Season Li000d88f2015-07-01 11:39:40 -07001807 const egl_display_ptr dp = validate_display(dpy);
1808 if (!dp) return EGL_FALSE;
1809
1810 EGLBoolean result = EGL_FALSE;
1811 egl_connection_t* const cnx = &gEGLImpl;
1812 if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) {
1813 result = cnx->egl.eglQueryStreamTimeKHR(
1814 dp->disp.dpy, stream, attribute, value);
1815 }
1816 return result;
1817}
1818
Cody Northrop68d10352018-10-15 07:22:09 -06001819EGLSurface eglCreateStreamProducerSurfaceKHRImpl(EGLDisplay dpy, EGLConfig config,
Season Li000d88f2015-07-01 11:39:40 -07001820 EGLStreamKHR stream, const EGLint *attrib_list)
1821{
Season Li000d88f2015-07-01 11:39:40 -07001822 egl_display_ptr dp = validate_display(dpy);
1823 if (!dp) return EGL_NO_SURFACE;
1824
1825 egl_connection_t* const cnx = &gEGLImpl;
1826 if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) {
1827 EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR(
1828 dp->disp.dpy, config, stream, attrib_list);
1829 if (surface != EGL_NO_SURFACE) {
Yi Kong48a6cd22018-07-18 10:07:09 -07001830 egl_surface_t* s = new egl_surface_t(dp.get(), config, nullptr, surface,
Courtney Goeltzenleuchterb1d70ec2018-02-08 18:09:33 -07001831 EGL_GL_COLORSPACE_LINEAR_KHR, cnx);
Season Li000d88f2015-07-01 11:39:40 -07001832 return s;
1833 }
1834 }
1835 return EGL_NO_SURFACE;
1836}
1837
Cody Northrop68d10352018-10-15 07:22:09 -06001838EGLBoolean eglStreamConsumerGLTextureExternalKHRImpl(EGLDisplay dpy,
Season Li000d88f2015-07-01 11:39:40 -07001839 EGLStreamKHR stream)
1840{
Season Li000d88f2015-07-01 11:39:40 -07001841 const egl_display_ptr dp = validate_display(dpy);
1842 if (!dp) return EGL_FALSE;
1843
1844 EGLBoolean result = EGL_FALSE;
1845 egl_connection_t* const cnx = &gEGLImpl;
1846 if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) {
1847 result = cnx->egl.eglStreamConsumerGLTextureExternalKHR(
1848 dp->disp.dpy, stream);
1849 }
1850 return result;
1851}
1852
Cody Northrop68d10352018-10-15 07:22:09 -06001853EGLBoolean eglStreamConsumerAcquireKHRImpl(EGLDisplay dpy,
Season Li000d88f2015-07-01 11:39:40 -07001854 EGLStreamKHR stream)
1855{
Season Li000d88f2015-07-01 11:39:40 -07001856 const egl_display_ptr dp = validate_display(dpy);
1857 if (!dp) return EGL_FALSE;
1858
1859 EGLBoolean result = EGL_FALSE;
1860 egl_connection_t* const cnx = &gEGLImpl;
1861 if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) {
1862 result = cnx->egl.eglStreamConsumerAcquireKHR(
1863 dp->disp.dpy, stream);
1864 }
1865 return result;
1866}
1867
Cody Northrop68d10352018-10-15 07:22:09 -06001868EGLBoolean eglStreamConsumerReleaseKHRImpl(EGLDisplay dpy,
Season Li000d88f2015-07-01 11:39:40 -07001869 EGLStreamKHR stream)
1870{
Season Li000d88f2015-07-01 11:39:40 -07001871 const egl_display_ptr dp = validate_display(dpy);
1872 if (!dp) return EGL_FALSE;
1873
1874 EGLBoolean result = EGL_FALSE;
1875 egl_connection_t* const cnx = &gEGLImpl;
1876 if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) {
1877 result = cnx->egl.eglStreamConsumerReleaseKHR(
1878 dp->disp.dpy, stream);
1879 }
1880 return result;
1881}
1882
Cody Northrop68d10352018-10-15 07:22:09 -06001883EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHRImpl(
Season Li000d88f2015-07-01 11:39:40 -07001884 EGLDisplay dpy, EGLStreamKHR stream)
1885{
Season Li000d88f2015-07-01 11:39:40 -07001886 const egl_display_ptr dp = validate_display(dpy);
1887 if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR;
1888
1889 EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR;
1890 egl_connection_t* const cnx = &gEGLImpl;
1891 if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) {
1892 result = cnx->egl.eglGetStreamFileDescriptorKHR(
1893 dp->disp.dpy, stream);
1894 }
1895 return result;
1896}
1897
Cody Northrop68d10352018-10-15 07:22:09 -06001898EGLStreamKHR eglCreateStreamFromFileDescriptorKHRImpl(
Season Li000d88f2015-07-01 11:39:40 -07001899 EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor)
1900{
Season Li000d88f2015-07-01 11:39:40 -07001901 const egl_display_ptr dp = validate_display(dpy);
1902 if (!dp) return EGL_NO_STREAM_KHR;
1903
1904 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1905 egl_connection_t* const cnx = &gEGLImpl;
1906 if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) {
1907 result = cnx->egl.eglCreateStreamFromFileDescriptorKHR(
1908 dp->disp.dpy, file_descriptor);
1909 }
1910 return result;
1911}
1912
Mathias Agopian518ec112011-05-13 16:21:08 -07001913// ----------------------------------------------------------------------------
Mathias Agopian2bb71682013-03-27 17:32:41 -07001914// EGL_EGLEXT_VERSION 15
1915// ----------------------------------------------------------------------------
1916
Cody Northrop68d10352018-10-15 07:22:09 -06001917EGLint eglWaitSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
Mathias Agopian2bb71682013-03-27 17:32:41 -07001918 const egl_display_ptr dp = validate_display(dpy);
1919 if (!dp) return EGL_FALSE;
1920 EGLint result = EGL_FALSE;
1921 egl_connection_t* const cnx = &gEGLImpl;
1922 if (cnx->dso && cnx->egl.eglWaitSyncKHR) {
1923 result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags);
1924 }
1925 return result;
1926}
1927
1928// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -07001929// ANDROID extensions
1930// ----------------------------------------------------------------------------
1931
Cody Northrop68d10352018-10-15 07:22:09 -06001932EGLint eglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync)
Jamie Gennis331841b2012-09-06 14:52:00 -07001933{
Jamie Gennis331841b2012-09-06 14:52:00 -07001934 const egl_display_ptr dp = validate_display(dpy);
1935 if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID;
1936
1937 EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID;
1938 egl_connection_t* const cnx = &gEGLImpl;
1939 if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) {
1940 result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync);
1941 }
1942 return result;
1943}
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001944
Cody Northrop68d10352018-10-15 07:22:09 -06001945EGLBoolean eglPresentationTimeANDROIDImpl(EGLDisplay dpy, EGLSurface surface,
Andy McFadden72841452013-03-01 16:25:32 -08001946 EGLnsecsANDROID time)
1947{
Andy McFadden72841452013-03-01 16:25:32 -08001948 const egl_display_ptr dp = validate_display(dpy);
1949 if (!dp) {
1950 return EGL_FALSE;
1951 }
1952
1953 SurfaceRef _s(dp.get(), surface);
1954 if (!_s.get()) {
1955 setError(EGL_BAD_SURFACE, EGL_FALSE);
1956 return EGL_FALSE;
1957 }
1958
1959 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian65421432017-03-08 11:49:05 -08001960 native_window_set_buffers_timestamp(s->getNativeWindow(), time);
Andy McFadden72841452013-03-01 16:25:32 -08001961
1962 return EGL_TRUE;
1963}
1964
Cody Northrop68d10352018-10-15 07:22:09 -06001965EGLClientBuffer eglGetNativeClientBufferANDROIDImpl(const AHardwareBuffer *buffer) {
Jiyong Parka243e5d2017-06-21 12:26:51 +09001966 // AHardwareBuffer_to_ANativeWindowBuffer is a platform-only symbol and thus
1967 // this function cannot be implemented when this libEGL is built for
1968 // vendors.
1969#ifndef __ANDROID_VNDK__
Yi Kong48a6cd22018-07-18 10:07:09 -07001970 if (!buffer) return setError(EGL_BAD_PARAMETER, (EGLClientBuffer) nullptr);
Mathias Agopian61963402017-02-24 16:38:15 -08001971 return const_cast<ANativeWindowBuffer *>(AHardwareBuffer_to_ANativeWindowBuffer(buffer));
Jiyong Parka243e5d2017-06-21 12:26:51 +09001972#else
Yi Kong48a6cd22018-07-18 10:07:09 -07001973 return setError(EGL_BAD_PARAMETER, (EGLClientBuffer) nullptr);
Jiyong Parka243e5d2017-06-21 12:26:51 +09001974#endif
Craig Donner60761072017-01-27 12:30:44 -08001975}
1976
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001977// ----------------------------------------------------------------------------
1978// NVIDIA extensions
1979// ----------------------------------------------------------------------------
Cody Northrop68d10352018-10-15 07:22:09 -06001980EGLuint64NV eglGetSystemTimeFrequencyNVImpl()
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001981{
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001982 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001983 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001984
Mathias Agopianada798b2012-02-13 17:09:30 -08001985 if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1986 return cnx->egl.eglGetSystemTimeFrequencyNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001987 }
1988
Mathias Agopian737b8962017-02-24 14:32:05 -08001989 return setErrorQuiet(EGL_BAD_DISPLAY, (EGLuint64NV)0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001990}
1991
Cody Northrop68d10352018-10-15 07:22:09 -06001992EGLuint64NV eglGetSystemTimeNVImpl()
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001993{
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001994 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001995 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001996
Mathias Agopianada798b2012-02-13 17:09:30 -08001997 if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
1998 return cnx->egl.eglGetSystemTimeNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001999 }
2000
Mathias Agopian737b8962017-02-24 14:32:05 -08002001 return setErrorQuiet(EGL_BAD_DISPLAY, (EGLuint64NV)0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08002002}
Dan Stozaa894d082015-02-19 15:27:36 -08002003
2004// ----------------------------------------------------------------------------
2005// Partial update extension
2006// ----------------------------------------------------------------------------
Cody Northrop68d10352018-10-15 07:22:09 -06002007EGLBoolean eglSetDamageRegionKHRImpl(EGLDisplay dpy, EGLSurface surface,
Dan Stozaa894d082015-02-19 15:27:36 -08002008 EGLint *rects, EGLint n_rects)
2009{
Dan Stozaa894d082015-02-19 15:27:36 -08002010 const egl_display_ptr dp = validate_display(dpy);
2011 if (!dp) {
2012 setError(EGL_BAD_DISPLAY, EGL_FALSE);
2013 return EGL_FALSE;
2014 }
2015
2016 SurfaceRef _s(dp.get(), surface);
2017 if (!_s.get()) {
2018 setError(EGL_BAD_SURFACE, EGL_FALSE);
2019 return EGL_FALSE;
2020 }
2021
2022 egl_surface_t const * const s = get_surface(surface);
2023 if (s->cnx->egl.eglSetDamageRegionKHR) {
2024 return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface,
2025 rects, n_rects);
2026 }
2027
2028 return EGL_FALSE;
2029}
Pablo Ceballosc18be292016-05-31 14:55:42 -07002030
Cody Northrop68d10352018-10-15 07:22:09 -06002031EGLBoolean eglGetNextFrameIdANDROIDImpl(EGLDisplay dpy, EGLSurface surface,
Brian Anderson1049d1d2016-12-16 17:25:57 -08002032 EGLuint64KHR *frameId) {
Brian Anderson1049d1d2016-12-16 17:25:57 -08002033 const egl_display_ptr dp = validate_display(dpy);
2034 if (!dp) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002035 return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Brian Anderson1049d1d2016-12-16 17:25:57 -08002036 }
2037
2038 SurfaceRef _s(dp.get(), surface);
2039 if (!_s.get()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002040 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson1049d1d2016-12-16 17:25:57 -08002041 }
2042
2043 egl_surface_t const * const s = get_surface(surface);
2044
Mathias Agopian65421432017-03-08 11:49:05 -08002045 if (!s->getNativeWindow()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002046 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson1049d1d2016-12-16 17:25:57 -08002047 }
2048
2049 uint64_t nextFrameId = 0;
Mathias Agopian65421432017-03-08 11:49:05 -08002050 int ret = native_window_get_next_frame_id(s->getNativeWindow(), &nextFrameId);
Brian Anderson1049d1d2016-12-16 17:25:57 -08002051
Mathias Agopian65421432017-03-08 11:49:05 -08002052 if (ret != 0) {
Brian Anderson1049d1d2016-12-16 17:25:57 -08002053 // This should not happen. Return an error that is not in the spec
2054 // so it's obvious something is very wrong.
2055 ALOGE("eglGetNextFrameId: Unexpected error.");
Mathias Agopian737b8962017-02-24 14:32:05 -08002056 return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE);
Brian Anderson1049d1d2016-12-16 17:25:57 -08002057 }
2058
2059 *frameId = nextFrameId;
2060 return EGL_TRUE;
2061}
2062
Cody Northrop68d10352018-10-15 07:22:09 -06002063EGLBoolean eglGetCompositorTimingANDROIDImpl(EGLDisplay dpy, EGLSurface surface,
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002064 EGLint numTimestamps, const EGLint *names, EGLnsecsANDROID *values)
2065{
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002066 const egl_display_ptr dp = validate_display(dpy);
2067 if (!dp) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002068 return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002069 }
2070
2071 SurfaceRef _s(dp.get(), surface);
2072 if (!_s.get()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002073 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002074 }
2075
2076 egl_surface_t const * const s = get_surface(surface);
2077
Mathias Agopian65421432017-03-08 11:49:05 -08002078 if (!s->getNativeWindow()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002079 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002080 }
2081
2082 nsecs_t* compositeDeadline = nullptr;
2083 nsecs_t* compositeInterval = nullptr;
2084 nsecs_t* compositeToPresentLatency = nullptr;
2085
2086 for (int i = 0; i < numTimestamps; i++) {
2087 switch (names[i]) {
2088 case EGL_COMPOSITE_DEADLINE_ANDROID:
2089 compositeDeadline = &values[i];
2090 break;
2091 case EGL_COMPOSITE_INTERVAL_ANDROID:
2092 compositeInterval = &values[i];
2093 break;
2094 case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID:
2095 compositeToPresentLatency = &values[i];
2096 break;
2097 default:
Mathias Agopian737b8962017-02-24 14:32:05 -08002098 return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002099 }
2100 }
2101
Mathias Agopian65421432017-03-08 11:49:05 -08002102 int ret = native_window_get_compositor_timing(s->getNativeWindow(),
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002103 compositeDeadline, compositeInterval, compositeToPresentLatency);
2104
2105 switch (ret) {
Mathias Agopian65421432017-03-08 11:49:05 -08002106 case 0:
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002107 return EGL_TRUE;
Mathias Agopian65421432017-03-08 11:49:05 -08002108 case -ENOSYS:
Mathias Agopian737b8962017-02-24 14:32:05 -08002109 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002110 default:
2111 // This should not happen. Return an error that is not in the spec
2112 // so it's obvious something is very wrong.
2113 ALOGE("eglGetCompositorTiming: Unexpected error.");
Mathias Agopian737b8962017-02-24 14:32:05 -08002114 return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002115 }
2116}
2117
Cody Northrop68d10352018-10-15 07:22:09 -06002118EGLBoolean eglGetCompositorTimingSupportedANDROIDImpl(
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002119 EGLDisplay dpy, EGLSurface surface, EGLint name)
2120{
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002121 const egl_display_ptr dp = validate_display(dpy);
2122 if (!dp) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002123 return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002124 }
2125
2126 SurfaceRef _s(dp.get(), surface);
2127 if (!_s.get()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002128 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002129 }
2130
2131 egl_surface_t const * const s = get_surface(surface);
2132
Mathias Agopian65421432017-03-08 11:49:05 -08002133 ANativeWindow* window = s->getNativeWindow();
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002134 if (!window) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002135 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002136 }
2137
2138 switch (name) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002139 case EGL_COMPOSITE_DEADLINE_ANDROID:
2140 case EGL_COMPOSITE_INTERVAL_ANDROID:
2141 case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID:
2142 return EGL_TRUE;
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002143 default:
2144 return EGL_FALSE;
2145 }
2146}
2147
Cody Northrop68d10352018-10-15 07:22:09 -06002148EGLBoolean eglGetFrameTimestampsANDROIDImpl(EGLDisplay dpy, EGLSurface surface,
Brian Anderson1049d1d2016-12-16 17:25:57 -08002149 EGLuint64KHR frameId, EGLint numTimestamps, const EGLint *timestamps,
Pablo Ceballosc18be292016-05-31 14:55:42 -07002150 EGLnsecsANDROID *values)
2151{
Pablo Ceballosc18be292016-05-31 14:55:42 -07002152 const egl_display_ptr dp = validate_display(dpy);
2153 if (!dp) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002154 return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002155 }
2156
2157 SurfaceRef _s(dp.get(), surface);
2158 if (!_s.get()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002159 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002160 }
2161
2162 egl_surface_t const * const s = get_surface(surface);
2163
Mathias Agopian65421432017-03-08 11:49:05 -08002164 if (!s->getNativeWindow()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002165 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002166 }
2167
Brian Andersondbd0ea82016-07-22 09:38:59 -07002168 nsecs_t* requestedPresentTime = nullptr;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002169 nsecs_t* acquireTime = nullptr;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002170 nsecs_t* latchTime = nullptr;
2171 nsecs_t* firstRefreshStartTime = nullptr;
Brian Andersonb04c6f02016-10-21 12:57:46 -07002172 nsecs_t* gpuCompositionDoneTime = nullptr;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002173 nsecs_t* lastRefreshStartTime = nullptr;
Brian Anderson069b3652016-07-22 10:32:47 -07002174 nsecs_t* displayPresentTime = nullptr;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002175 nsecs_t* dequeueReadyTime = nullptr;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002176 nsecs_t* releaseTime = nullptr;
2177
2178 for (int i = 0; i < numTimestamps; i++) {
2179 switch (timestamps[i]) {
Brian Andersondbd0ea82016-07-22 09:38:59 -07002180 case EGL_REQUESTED_PRESENT_TIME_ANDROID:
2181 requestedPresentTime = &values[i];
Pablo Ceballosc18be292016-05-31 14:55:42 -07002182 break;
2183 case EGL_RENDERING_COMPLETE_TIME_ANDROID:
2184 acquireTime = &values[i];
2185 break;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002186 case EGL_COMPOSITION_LATCH_TIME_ANDROID:
2187 latchTime = &values[i];
Pablo Ceballosc18be292016-05-31 14:55:42 -07002188 break;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002189 case EGL_FIRST_COMPOSITION_START_TIME_ANDROID:
2190 firstRefreshStartTime = &values[i];
2191 break;
2192 case EGL_LAST_COMPOSITION_START_TIME_ANDROID:
2193 lastRefreshStartTime = &values[i];
2194 break;
Brian Andersonb04c6f02016-10-21 12:57:46 -07002195 case EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID:
2196 gpuCompositionDoneTime = &values[i];
Pablo Ceballosc18be292016-05-31 14:55:42 -07002197 break;
Brian Anderson069b3652016-07-22 10:32:47 -07002198 case EGL_DISPLAY_PRESENT_TIME_ANDROID:
2199 displayPresentTime = &values[i];
2200 break;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002201 case EGL_DEQUEUE_READY_TIME_ANDROID:
2202 dequeueReadyTime = &values[i];
2203 break;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002204 case EGL_READS_DONE_TIME_ANDROID:
2205 releaseTime = &values[i];
2206 break;
2207 default:
Mathias Agopian737b8962017-02-24 14:32:05 -08002208 return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002209 }
2210 }
2211
Mathias Agopian65421432017-03-08 11:49:05 -08002212 int ret = native_window_get_frame_timestamps(s->getNativeWindow(), frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002213 requestedPresentTime, acquireTime, latchTime, firstRefreshStartTime,
Brian Andersonb04c6f02016-10-21 12:57:46 -07002214 lastRefreshStartTime, gpuCompositionDoneTime, displayPresentTime,
Brian Anderson4e606e32017-03-16 15:34:57 -07002215 dequeueReadyTime, releaseTime);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002216
Brian Anderson069b3652016-07-22 10:32:47 -07002217 switch (ret) {
Mathias Agopian65421432017-03-08 11:49:05 -08002218 case 0:
Mathias Agopian737b8962017-02-24 14:32:05 -08002219 return EGL_TRUE;
Mathias Agopian65421432017-03-08 11:49:05 -08002220 case -ENOENT:
Mathias Agopian737b8962017-02-24 14:32:05 -08002221 return setError(EGL_BAD_ACCESS, (EGLBoolean)EGL_FALSE);
Mathias Agopian65421432017-03-08 11:49:05 -08002222 case -ENOSYS:
Mathias Agopian737b8962017-02-24 14:32:05 -08002223 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Mathias Agopian65421432017-03-08 11:49:05 -08002224 case -EINVAL:
Mathias Agopian737b8962017-02-24 14:32:05 -08002225 return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
2226 default:
2227 // This should not happen. Return an error that is not in the spec
2228 // so it's obvious something is very wrong.
2229 ALOGE("eglGetFrameTimestamps: Unexpected error.");
2230 return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002231 }
Pablo Ceballosc18be292016-05-31 14:55:42 -07002232}
2233
Cody Northrop68d10352018-10-15 07:22:09 -06002234EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl(
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002235 EGLDisplay dpy, EGLSurface surface, EGLint timestamp)
Pablo Ceballosc18be292016-05-31 14:55:42 -07002236{
Pablo Ceballosc18be292016-05-31 14:55:42 -07002237 const egl_display_ptr dp = validate_display(dpy);
2238 if (!dp) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002239 return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002240 }
2241
2242 SurfaceRef _s(dp.get(), surface);
2243 if (!_s.get()) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002244 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Brian Anderson069b3652016-07-22 10:32:47 -07002245 }
2246
2247 egl_surface_t const * const s = get_surface(surface);
2248
Mathias Agopian65421432017-03-08 11:49:05 -08002249 ANativeWindow* window = s->getNativeWindow();
Brian Anderson069b3652016-07-22 10:32:47 -07002250 if (!window) {
Mathias Agopian737b8962017-02-24 14:32:05 -08002251 return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002252 }
2253
2254 switch (timestamp) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -08002255 case EGL_COMPOSITE_DEADLINE_ANDROID:
2256 case EGL_COMPOSITE_INTERVAL_ANDROID:
2257 case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID:
Brian Andersondbd0ea82016-07-22 09:38:59 -07002258 case EGL_REQUESTED_PRESENT_TIME_ANDROID:
Pablo Ceballosc18be292016-05-31 14:55:42 -07002259 case EGL_RENDERING_COMPLETE_TIME_ANDROID:
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002260 case EGL_COMPOSITION_LATCH_TIME_ANDROID:
2261 case EGL_FIRST_COMPOSITION_START_TIME_ANDROID:
2262 case EGL_LAST_COMPOSITION_START_TIME_ANDROID:
Brian Andersonb04c6f02016-10-21 12:57:46 -07002263 case EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID:
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002264 case EGL_DEQUEUE_READY_TIME_ANDROID:
Pablo Ceballosc18be292016-05-31 14:55:42 -07002265 case EGL_READS_DONE_TIME_ANDROID:
2266 return EGL_TRUE;
Brian Anderson6b376712017-04-04 10:51:39 -07002267 case EGL_DISPLAY_PRESENT_TIME_ANDROID: {
2268 int value = 0;
2269 window->query(window,
2270 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &value);
2271 return value == 0 ? EGL_FALSE : EGL_TRUE;
2272 }
Pablo Ceballosc18be292016-05-31 14:55:42 -07002273 default:
2274 return EGL_FALSE;
2275 }
2276}
Cody Northrop68d10352018-10-15 07:22:09 -06002277
2278const GLubyte * glGetStringImpl(GLenum name) {
2279 const GLubyte * ret = egl_get_string_for_current_context(name);
2280 if (ret == NULL) {
2281 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
2282 if(_c) ret = _c->glGetString(name);
2283 }
2284 return ret;
2285}
2286
2287const GLubyte * glGetStringiImpl(GLenum name, GLuint index) {
2288 const GLubyte * ret = egl_get_string_for_current_context(name, index);
2289 if (ret == NULL) {
2290 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
2291 if(_c) ret = _c->glGetStringi(name, index);
2292 }
2293 return ret;
2294}
2295
2296void glGetBooleanvImpl(GLenum pname, GLboolean * data) {
2297 if (pname == GL_NUM_EXTENSIONS) {
2298 int num_exts = egl_get_num_extensions_for_current_context();
2299 if (num_exts >= 0) {
2300 *data = num_exts > 0 ? GL_TRUE : GL_FALSE;
2301 return;
2302 }
2303 }
2304
2305 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
2306 if (_c) _c->glGetBooleanv(pname, data);
2307}
2308
2309void glGetFloatvImpl(GLenum pname, GLfloat * data) {
2310 if (pname == GL_NUM_EXTENSIONS) {
2311 int num_exts = egl_get_num_extensions_for_current_context();
2312 if (num_exts >= 0) {
2313 *data = (GLfloat)num_exts;
2314 return;
2315 }
2316 }
2317
2318 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
2319 if (_c) _c->glGetFloatv(pname, data);
2320}
2321
2322void glGetIntegervImpl(GLenum pname, GLint * data) {
2323 if (pname == GL_NUM_EXTENSIONS) {
2324 int num_exts = egl_get_num_extensions_for_current_context();
2325 if (num_exts >= 0) {
2326 *data = (GLint)num_exts;
2327 return;
2328 }
2329 }
2330
2331 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
2332 if (_c) _c->glGetIntegerv(pname, data);
2333}
2334
2335void glGetInteger64vImpl(GLenum pname, GLint64 * data) {
2336 if (pname == GL_NUM_EXTENSIONS) {
2337 int num_exts = egl_get_num_extensions_for_current_context();
2338 if (num_exts >= 0) {
2339 *data = (GLint64)num_exts;
2340 return;
2341 }
2342 }
2343
2344 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
2345 if (_c) _c->glGetInteger64v(pname, data);
2346}
2347
2348struct implementation_map_t {
2349 const char* name;
2350 EGLFuncPointer address;
2351};
2352
2353static const implementation_map_t sPlatformImplMap[] = {
2354 { "eglGetDisplay", (EGLFuncPointer)&eglGetDisplayImpl },
2355 { "eglInitialize", (EGLFuncPointer)&eglInitializeImpl },
2356 { "eglTerminate", (EGLFuncPointer)&eglTerminateImpl },
2357 { "eglGetConfigs", (EGLFuncPointer)&eglGetConfigsImpl },
2358 { "eglChooseConfig", (EGLFuncPointer)&eglChooseConfigImpl },
2359 { "eglGetConfigAttrib", (EGLFuncPointer)&eglGetConfigAttribImpl },
2360 { "eglCreateWindowSurface", (EGLFuncPointer)&eglCreateWindowSurfaceImpl },
2361 { "eglCreatePixmapSurface", (EGLFuncPointer)&eglCreatePixmapSurfaceImpl },
2362 { "eglCreatePbufferSurface", (EGLFuncPointer)&eglCreatePbufferSurfaceImpl },
2363 { "eglDestroySurface", (EGLFuncPointer)&eglDestroySurfaceImpl },
2364 { "eglQuerySurface", (EGLFuncPointer)&eglQuerySurfaceImpl },
2365 { "eglBeginFrame", (EGLFuncPointer)&eglBeginFrameImpl },
2366 { "eglCreateContext", (EGLFuncPointer)&eglCreateContextImpl },
2367 { "eglDestroyContext", (EGLFuncPointer)&eglDestroyContextImpl },
2368 { "eglMakeCurrent", (EGLFuncPointer)&eglMakeCurrentImpl },
2369 { "eglQueryContext", (EGLFuncPointer)&eglQueryContextImpl },
2370 { "eglGetCurrentContext", (EGLFuncPointer)&eglGetCurrentContextImpl },
2371 { "eglGetCurrentSurface", (EGLFuncPointer)&eglGetCurrentSurfaceImpl },
2372 { "eglGetCurrentDisplay", (EGLFuncPointer)&eglGetCurrentDisplayImpl },
2373 { "eglWaitGL", (EGLFuncPointer)&eglWaitGLImpl },
2374 { "eglWaitNative", (EGLFuncPointer)&eglWaitNativeImpl },
2375 { "eglGetError", (EGLFuncPointer)&eglGetErrorImpl },
2376 { "eglSwapBuffersWithDamageKHR", (EGLFuncPointer)&eglSwapBuffersWithDamageKHRImpl },
2377 { "eglGetProcAddress", (EGLFuncPointer)&eglGetProcAddressImpl },
2378 { "eglSwapBuffers", (EGLFuncPointer)&eglSwapBuffersImpl },
2379 { "eglCopyBuffers", (EGLFuncPointer)&eglCopyBuffersImpl },
2380 { "eglQueryString", (EGLFuncPointer)&eglQueryStringImpl },
2381 { "eglQueryStringImplementationANDROID", (EGLFuncPointer)&eglQueryStringImplementationANDROIDImpl },
2382 { "eglSurfaceAttrib", (EGLFuncPointer)&eglSurfaceAttribImpl },
2383 { "eglBindTexImage", (EGLFuncPointer)&eglBindTexImageImpl },
2384 { "eglReleaseTexImage", (EGLFuncPointer)&eglReleaseTexImageImpl },
2385 { "eglSwapInterval", (EGLFuncPointer)&eglSwapIntervalImpl },
2386 { "eglWaitClient", (EGLFuncPointer)&eglWaitClientImpl },
2387 { "eglBindAPI", (EGLFuncPointer)&eglBindAPIImpl },
2388 { "eglQueryAPI", (EGLFuncPointer)&eglQueryAPIImpl },
2389 { "eglReleaseThread", (EGLFuncPointer)&eglReleaseThreadImpl },
2390 { "eglCreatePbufferFromClientBuffer", (EGLFuncPointer)&eglCreatePbufferFromClientBufferImpl },
2391 { "eglLockSurfaceKHR", (EGLFuncPointer)&eglLockSurfaceKHRImpl },
2392 { "eglUnlockSurfaceKHR", (EGLFuncPointer)&eglUnlockSurfaceKHRImpl },
2393 { "eglCreateImageKHR", (EGLFuncPointer)&eglCreateImageKHRImpl },
2394 { "eglDestroyImageKHR", (EGLFuncPointer)&eglDestroyImageKHRImpl },
2395 { "eglCreateSyncKHR", (EGLFuncPointer)&eglCreateSyncKHRImpl },
2396 { "eglDestroySyncKHR", (EGLFuncPointer)&eglDestroySyncKHRImpl },
2397 { "eglSignalSyncKHR", (EGLFuncPointer)&eglSignalSyncKHRImpl },
2398 { "eglClientWaitSyncKHR", (EGLFuncPointer)&eglClientWaitSyncKHRImpl },
2399 { "eglGetSyncAttribKHR", (EGLFuncPointer)&eglGetSyncAttribKHRImpl },
2400 { "eglCreateStreamKHR", (EGLFuncPointer)&eglCreateStreamKHRImpl },
2401 { "eglDestroyStreamKHR", (EGLFuncPointer)&eglDestroyStreamKHRImpl },
2402 { "eglStreamAttribKHR", (EGLFuncPointer)&eglStreamAttribKHRImpl },
2403 { "eglQueryStreamKHR", (EGLFuncPointer)&eglQueryStreamKHRImpl },
2404 { "eglQueryStreamu64KHR", (EGLFuncPointer)&eglQueryStreamu64KHRImpl },
2405 { "eglQueryStreamTimeKHR", (EGLFuncPointer)&eglQueryStreamTimeKHRImpl },
2406 { "eglCreateStreamProducerSurfaceKHR", (EGLFuncPointer)&eglCreateStreamProducerSurfaceKHRImpl },
2407 { "eglStreamConsumerGLTextureExternalKHR", (EGLFuncPointer)&eglStreamConsumerGLTextureExternalKHRImpl },
2408 { "eglStreamConsumerAcquireKHR", (EGLFuncPointer)&eglStreamConsumerAcquireKHRImpl },
2409 { "eglStreamConsumerReleaseKHR", (EGLFuncPointer)&eglStreamConsumerReleaseKHRImpl },
2410 { "eglGetStreamFileDescriptorKHR", (EGLFuncPointer)&eglGetStreamFileDescriptorKHRImpl },
2411 { "eglCreateStreamFromFileDescriptorKHR", (EGLFuncPointer)&eglCreateStreamFromFileDescriptorKHRImpl },
2412 { "eglWaitSyncKHR", (EGLFuncPointer)&eglWaitSyncKHRImpl },
2413 { "eglDupNativeFenceFDANDROID", (EGLFuncPointer)&eglDupNativeFenceFDANDROIDImpl },
2414 { "eglPresentationTimeANDROID", (EGLFuncPointer)&eglPresentationTimeANDROIDImpl },
2415 { "eglGetNativeClientBufferANDROID", (EGLFuncPointer)&eglGetNativeClientBufferANDROIDImpl },
2416 { "eglGetSystemTimeFrequencyNV", (EGLFuncPointer)&eglGetSystemTimeFrequencyNVImpl },
2417 { "eglGetSystemTimeNV", (EGLFuncPointer)&eglGetSystemTimeNVImpl },
2418 { "eglSetDamageRegionKHR", (EGLFuncPointer)&eglSetDamageRegionKHRImpl },
2419 { "eglGetNextFrameIdANDROID", (EGLFuncPointer)&eglGetNextFrameIdANDROIDImpl },
2420 { "eglGetCompositorTimingANDROID", (EGLFuncPointer)&eglGetCompositorTimingANDROIDImpl },
2421 { "eglGetCompositorTimingSupportedANDROID", (EGLFuncPointer)&eglGetCompositorTimingSupportedANDROIDImpl },
2422 { "eglGetFrameTimestampsANDROID", (EGLFuncPointer)&eglGetFrameTimestampsANDROIDImpl },
2423 { "eglGetFrameTimestampSupportedANDROID", (EGLFuncPointer)&eglGetFrameTimestampSupportedANDROIDImpl },
2424 { "glGetString", (EGLFuncPointer)&glGetStringImpl },
2425 { "glGetStringi", (EGLFuncPointer)&glGetStringiImpl },
2426 { "glGetBooleanv", (EGLFuncPointer)&glGetBooleanvImpl },
2427 { "glGetFloatv", (EGLFuncPointer)&glGetFloatvImpl },
2428 { "glGetIntegerv", (EGLFuncPointer)&glGetIntegervImpl },
2429 { "glGetInteger64v", (EGLFuncPointer)&glGetInteger64vImpl },
2430};
2431
2432EGLFuncPointer FindPlatformImplAddr(const char* name)
2433{
2434 static const bool DEBUG = false;
2435
2436 if (name == nullptr) {
2437 ALOGV("FindPlatformImplAddr called with null name");
2438 return nullptr;
2439 }
2440
2441 for (int i = 0; i < NELEM(sPlatformImplMap); i++) {
2442 if (sPlatformImplMap[i].name == nullptr) {
2443 ALOGV("FindPlatformImplAddr found nullptr for sPlatformImplMap[%i].name (%s)", i, name);
2444 return nullptr;
2445 }
2446 if (!strcmp(name, sPlatformImplMap[i].name)) {
2447 ALOGV("FindPlatformImplAddr found %llu for sPlatformImplMap[%i].address (%s)", (unsigned long long)sPlatformImplMap[i].address, i, name);
2448 return sPlatformImplMap[i].address;
2449 }
2450 }
2451
2452 ALOGV("FindPlatformImplAddr did not find an entry for %s", name);
2453 return nullptr;
2454}
2455} // namespace android