blob: 1a8fc1a00af0c12e64536ea52bc1d233a3fd0954 [file] [log] [blame]
Mathias Agopianca088332013-03-28 17:44:13 -07001/*
2 ** Copyright 2013, The Android Open Source Project
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16
17#define LOG_TAG "GLConsumer"
18
Mathias Agopianca088332013-03-28 17:44:13 -070019#define EGL_EGLEXT_PROTOTYPES
20
21#include <EGL/egl.h>
22#include <EGL/eglext.h>
23
24#include <utils/Log.h>
25#include <utils/Singleton.h>
26#include <utils/String8.h>
27
28#include <private/gui/SyncFeatures.h>
29
Mathias Agopianca088332013-03-28 17:44:13 -070030namespace android {
31
32ANDROID_SINGLETON_STATIC_INSTANCE(SyncFeatures);
33
34SyncFeatures::SyncFeatures() : Singleton<SyncFeatures>(),
35 mHasNativeFenceSync(false),
36 mHasFenceSync(false),
37 mHasWaitSync(false) {
38 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
39 // This can only be called after EGL has been initialized; otherwise the
40 // check below will abort.
Yiwei Zhang0378f4d2020-08-12 15:03:23 -070041 const char* exts = eglQueryString(dpy, EGL_EXTENSIONS);
42 LOG_ALWAYS_FATAL_IF(exts == nullptr, "eglQueryString failed");
Mathias Agopianca088332013-03-28 17:44:13 -070043 if (strstr(exts, "EGL_ANDROID_native_fence_sync")) {
44 // This makes GLConsumer use the EGL_ANDROID_native_fence_sync
45 // extension to create Android native fences to signal when all
46 // GLES reads for a given buffer have completed.
47 mHasNativeFenceSync = true;
48 }
49 if (strstr(exts, "EGL_KHR_fence_sync")) {
50 mHasFenceSync = true;
51 }
52 if (strstr(exts, "EGL_KHR_wait_sync")) {
53 mHasWaitSync = true;
54 }
55 mString.append("[using:");
56 if (useNativeFenceSync()) {
57 mString.append(" EGL_ANDROID_native_fence_sync");
58 }
59 if (useFenceSync()) {
60 mString.append(" EGL_KHR_fence_sync");
61 }
62 if (useWaitSync()) {
63 mString.append(" EGL_KHR_wait_sync");
64 }
65 mString.append("]");
66}
67
68bool SyncFeatures::useNativeFenceSync() const {
69 // EGL_ANDROID_native_fence_sync is not compatible with using the
70 // EGL_KHR_fence_sync extension for the same purpose.
71 return mHasNativeFenceSync;
72}
73bool SyncFeatures::useFenceSync() const {
Mathias Agopianca088332013-03-28 17:44:13 -070074 return !mHasNativeFenceSync && mHasFenceSync;
Mathias Agopianca088332013-03-28 17:44:13 -070075}
76bool SyncFeatures::useWaitSync() const {
77 return (useNativeFenceSync() || useFenceSync()) && mHasWaitSync;
78}
79
80String8 SyncFeatures::toString() const {
81 return mString;
82}
83
84} // namespace android