• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
19 #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 
30 namespace android {
31 
32 ANDROID_SINGLETON_STATIC_INSTANCE(SyncFeatures);
33 
SyncFeatures()34 SyncFeatures::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.
41     const char* exts = eglQueryString(dpy, EGL_EXTENSIONS);
42     LOG_ALWAYS_FATAL_IF(exts == nullptr, "eglQueryString failed");
43     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 
useNativeFenceSync() const68 bool 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 }
useFenceSync() const73 bool SyncFeatures::useFenceSync() const {
74     return !mHasNativeFenceSync && mHasFenceSync;
75 }
useWaitSync() const76 bool SyncFeatures::useWaitSync() const {
77     return (useNativeFenceSync() || useFenceSync()) && mHasWaitSync;
78 }
79 
toString() const80 String8 SyncFeatures::toString() const {
81     return mString;
82 }
83 
84 } // namespace android
85