22
22
#include < private/backend/BackendUtilsAndroid.h>
23
23
#include < private/backend/VirtualMachineEnv.h>
24
24
25
- #include " ExternalStreamManagerAndroid.h"
26
25
#include " opengl/GLUtils.h"
26
+ #include " ExternalStreamManagerAndroid.h"
27
27
28
28
#include < android/api-level.h>
29
- #include < android/hardware_buffer.h>
30
29
#include < android/native_window.h>
30
+ #include < android/hardware_buffer.h>
31
31
32
32
#include < utils/android/PerformanceHintManager.h>
33
33
34
- #include < utils/Log.h>
34
+ #include < utils/compiler.h>
35
+ #include < utils/ostream.h>
35
36
#include < utils/Panic.h>
37
+ #include < utils/Log.h>
36
38
#include < utils/compiler.h>
37
39
#include < utils/ostream.h>
38
40
57
59
// We require filament to be built with an API 19 toolchain, before that, OpenGLES 3.0 didn't exist
58
60
// Actually, OpenGL ES 3.0 was added to API 18, but API 19 is the better target and
59
61
// the minimum for Jetpack at the time of this comment.
60
- #if __ANDROID_API__ < 21
61
- #error "__ANDROID_API__ must be at least 21 "
62
+ #if __ANDROID_API__ < 19
63
+ #error "__ANDROID_API__ must be at least 19 "
62
64
#endif
63
65
64
66
using namespace utils ;
@@ -77,44 +79,43 @@ extern PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
77
79
78
80
UTILS_PRIVATE PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC eglGetNativeClientBufferANDROID = {};
79
81
UTILS_PRIVATE PFNEGLPRESENTATIONTIMEANDROIDPROC eglPresentationTimeANDROID = {};
80
- UTILS_PRIVATE PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROIDPROC
81
- eglGetCompositorTimingSupportedANDROID = {};
82
+ UTILS_PRIVATE PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROIDPROC eglGetCompositorTimingSupportedANDROID = {};
82
83
UTILS_PRIVATE PFNEGLGETCOMPOSITORTIMINGANDROIDPROC eglGetCompositorTimingANDROID = {};
83
84
UTILS_PRIVATE PFNEGLGETNEXTFRAMEIDANDROIDPROC eglGetNextFrameIdANDROID = {};
84
85
UTILS_PRIVATE PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROIDPROC eglGetFrameTimestampSupportedANDROID = {};
85
86
UTILS_PRIVATE PFNEGLGETFRAMETIMESTAMPSANDROIDPROC eglGetFrameTimestampsANDROID = {};
86
- }// namespace glext
87
+ }
87
88
using namespace glext ;
88
89
89
90
// ---------------------------------------------------------------------------------------------
90
91
91
- PlatformEGLAndroid::InitializeJvmForPerformanceManagerIfNeeded::
92
- InitializeJvmForPerformanceManagerIfNeeded () {
92
+ PlatformEGLAndroid::InitializeJvmForPerformanceManagerIfNeeded::InitializeJvmForPerformanceManagerIfNeeded () {
93
93
// PerformanceHintManager() needs the calling thread to be a Java thread; so we need
94
94
// to attach this thread to the JVM before we initialize PerformanceHintManager.
95
95
// This should be done in PerformanceHintManager(), but libutils doesn't have access to
96
96
// VirtualMachineEnv.
97
97
if (PerformanceHintManager::isSupported ()) {
98
- (void ) VirtualMachineEnv::get ().getEnvironment ();
98
+ (void )VirtualMachineEnv::get ().getEnvironment ();
99
99
}
100
100
}
101
101
102
102
// ---------------------------------------------------------------------------------------------
103
103
104
104
PlatformEGLAndroid::PlatformEGLAndroid () noexcept
105
- : PlatformEGL(),
106
- mExternalStreamManager (ExternalStreamManagerAndroid::create()),
107
- mInitializeJvmForPerformanceManagerIfNeeded(),
108
- mPerformanceHintManager() {
105
+ : PlatformEGL(),
106
+ mExternalStreamManager (ExternalStreamManagerAndroid::create()),
107
+ mInitializeJvmForPerformanceManagerIfNeeded(),
108
+ mPerformanceHintManager() {
109
109
mOSVersion = android_get_device_api_level ();
110
110
if (mOSVersion < 0 ) {
111
111
mOSVersion = __ANDROID_API_FUTURE__;
112
112
}
113
113
114
114
mNativeWindowLib = dlopen (" libnativewindow.so" , RTLD_LOCAL | RTLD_NOW);
115
115
if (mNativeWindowLib ) {
116
- ANativeWindow_getBuffersDefaultDataSpace = (int32_t (*)(ANativeWindow*)) dlsym (
117
- mNativeWindowLib , " ANativeWindow_getBuffersDefaultDataSpace" );
116
+ ANativeWindow_getBuffersDefaultDataSpace =
117
+ (int32_t (*)(ANativeWindow*))dlsym (mNativeWindowLib ,
118
+ " ANativeWindow_getBuffersDefaultDataSpace" );
118
119
}
119
120
}
120
121
@@ -132,7 +133,8 @@ void PlatformEGLAndroid::terminate() noexcept {
132
133
static constexpr const std::string_view kNativeWindowInvalidMsg =
133
134
" ANativeWindow is invalid. It probably has been destroyed. EGL surface = " ;
134
135
135
- bool PlatformEGLAndroid::makeCurrent (ContextType type, SwapChain* drawSwapChain,
136
+ bool PlatformEGLAndroid::makeCurrent (ContextType type,
137
+ SwapChain* drawSwapChain,
136
138
SwapChain* readSwapChain) noexcept {
137
139
138
140
// fast & safe path
@@ -157,12 +159,12 @@ bool PlatformEGLAndroid::makeCurrent(ContextType type, SwapChain* drawSwapChain,
157
159
// is valid query enum value
158
160
enum { IS_VALID = 17 };
159
161
uint64_t pad[18 ];
160
- int (*query)(ANativeWindow const *, int , int *);
162
+ int (* query)(ANativeWindow const *, int , int *);
161
163
} const * pWindow = reinterpret_cast <NativeWindow const *>(dsc->nativeWindow );
162
164
int isValid = 0 ;
163
- if (UTILS_LIKELY (pWindow->query )) {// just in case it's nullptr
165
+ if (UTILS_LIKELY (pWindow->query )) { // just in case it's nullptr
164
166
int const err = pWindow->query (dsc->nativeWindow , NativeWindow::IS_VALID, &isValid);
165
- if (UTILS_LIKELY (err >= 0 )) {// in case the IS_VALID enum is not recognized
167
+ if (UTILS_LIKELY (err >= 0 )) { // in case the IS_VALID enum is not recognized
166
168
// query call succeeded
167
169
FILAMENT_CHECK_POSTCONDITION (isValid) << kNativeWindowInvalidMsg << dsc->sur ;
168
170
}
@@ -171,7 +173,9 @@ bool PlatformEGLAndroid::makeCurrent(ContextType type, SwapChain* drawSwapChain,
171
173
return PlatformEGL::makeCurrent (type, drawSwapChain, readSwapChain);
172
174
}
173
175
174
- void PlatformEGLAndroid::beginFrame (int64_t monotonic_clock_ns, int64_t refreshIntervalNs,
176
+ void PlatformEGLAndroid::beginFrame (
177
+ int64_t monotonic_clock_ns,
178
+ int64_t refreshIntervalNs,
175
179
uint32_t frameId) noexcept {
176
180
if (mPerformanceHintSession .isValid ()) {
177
181
if (refreshIntervalNs <= 0 ) {
@@ -198,8 +202,8 @@ Driver* PlatformEGLAndroid::createDriver(void* sharedContext,
198
202
199
203
// the refresh rate default value doesn't matter, we change it later
200
204
int32_t const tid = gettid ();
201
- mPerformanceHintSession =
202
- PerformanceHintManager::Session{ mPerformanceHintManager , &tid, 1 , 16'666'667 };
205
+ mPerformanceHintSession = PerformanceHintManager::Session{
206
+ mPerformanceHintManager , &tid, 1 , 16'666'667 };
203
207
204
208
Driver* driver = PlatformEGL::createDriver (sharedContext, driverConfig);
205
209
auto extensions = GLUtils::split (eglQueryString (mEGLDisplay , EGL_EXTENSIONS));
@@ -208,22 +212,20 @@ Driver* PlatformEGLAndroid::createDriver(void* sharedContext,
208
212
" eglGetNativeClientBufferANDROID" );
209
213
210
214
if (extensions.has (" EGL_ANDROID_presentation_time" )) {
211
- eglPresentationTimeANDROID =
212
- (PFNEGLPRESENTATIONTIMEANDROIDPROC) eglGetProcAddress ( " eglPresentationTimeANDROID" );
215
+ eglPresentationTimeANDROID = (PFNEGLPRESENTATIONTIMEANDROIDPROC) eglGetProcAddress (
216
+ " eglPresentationTimeANDROID" );
213
217
}
214
218
215
219
if (extensions.has (" EGL_ANDROID_get_frame_timestamps" )) {
216
- eglGetCompositorTimingSupportedANDROID =
217
- (PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROIDPROC) eglGetProcAddress (
218
- " eglGetCompositorTimingSupportedANDROID" );
219
- eglGetCompositorTimingANDROID = (PFNEGLGETCOMPOSITORTIMINGANDROIDPROC) eglGetProcAddress (
220
+ eglGetCompositorTimingSupportedANDROID = (PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROIDPROC)eglGetProcAddress (
221
+ " eglGetCompositorTimingSupportedANDROID" );
222
+ eglGetCompositorTimingANDROID = (PFNEGLGETCOMPOSITORTIMINGANDROIDPROC)eglGetProcAddress (
220
223
" eglGetCompositorTimingANDROID" );
221
- eglGetNextFrameIdANDROID =
222
- (PFNEGLGETNEXTFRAMEIDANDROIDPROC) eglGetProcAddress (" eglGetNextFrameIdANDROID" );
223
- eglGetFrameTimestampSupportedANDROID =
224
- (PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROIDPROC) eglGetProcAddress (
225
- " eglGetFrameTimestampSupportedANDROID" );
226
- eglGetFrameTimestampsANDROID = (PFNEGLGETFRAMETIMESTAMPSANDROIDPROC) eglGetProcAddress (
224
+ eglGetNextFrameIdANDROID = (PFNEGLGETNEXTFRAMEIDANDROIDPROC)eglGetProcAddress (
225
+ " eglGetNextFrameIdANDROID" );
226
+ eglGetFrameTimestampSupportedANDROID = (PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROIDPROC)eglGetProcAddress (
227
+ " eglGetFrameTimestampSupportedANDROID" );
228
+ eglGetFrameTimestampsANDROID = (PFNEGLGETFRAMETIMESTAMPSANDROIDPROC)eglGetProcAddress (
227
229
" eglGetFrameTimestampsANDROID" );
228
230
}
229
231
@@ -327,7 +329,9 @@ void PlatformEGLAndroid::setPresentationTime(int64_t presentationTimeInNanosecon
327
329
EGLSurface currentDrawSurface = eglGetCurrentSurface (EGL_DRAW);
328
330
if (currentDrawSurface != EGL_NO_SURFACE) {
329
331
if (eglPresentationTimeANDROID) {
330
- eglPresentationTimeANDROID (mEGLDisplay , currentDrawSurface,
332
+ eglPresentationTimeANDROID (
333
+ mEGLDisplay ,
334
+ currentDrawSurface,
331
335
presentationTimeInNanosecond);
332
336
}
333
337
}
@@ -345,7 +349,9 @@ void PlatformEGLAndroid::attach(Stream* stream, intptr_t tname) noexcept {
345
349
mExternalStreamManager .attach (stream, tname);
346
350
}
347
351
348
- void PlatformEGLAndroid::detach (Stream* stream) noexcept { mExternalStreamManager .detach (stream); }
352
+ void PlatformEGLAndroid::detach (Stream* stream) noexcept {
353
+ mExternalStreamManager .detach (stream);
354
+ }
349
355
350
356
void PlatformEGLAndroid::updateTexImage (Stream* stream, int64_t * timestamp) noexcept {
351
357
mExternalStreamManager .updateTexImage (stream, timestamp);
@@ -355,11 +361,13 @@ math::mat3f PlatformEGLAndroid::getTransformMatrix(Stream* stream) noexcept {
355
361
return mExternalStreamManager .getTransformMatrix (stream);
356
362
}
357
363
358
- int PlatformEGLAndroid::getOSVersion () const noexcept { return mOSVersion ; }
364
+ int PlatformEGLAndroid::getOSVersion () const noexcept {
365
+ return mOSVersion ;
366
+ }
359
367
360
368
AcquiredImage PlatformEGLAndroid::transformAcquiredImage (AcquiredImage source) noexcept {
361
369
// Convert the AHardwareBuffer to EGLImage.
362
- AHardwareBuffer const * const pHardwareBuffer = (const AHardwareBuffer*) source.image ;
370
+ AHardwareBuffer const * const pHardwareBuffer = (const AHardwareBuffer*)source.image ;
363
371
364
372
EGLClientBuffer clientBuffer = eglGetNativeClientBufferANDROID (pHardwareBuffer);
365
373
if (!clientBuffer) {
@@ -379,8 +387,8 @@ AcquiredImage PlatformEGLAndroid::transformAcquiredImage(AcquiredImage source) n
379
387
}
380
388
}
381
389
382
- EGLImageKHR eglImage = eglCreateImageKHR (mEGLDisplay , EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
383
- clientBuffer, attributes.data ());
390
+ EGLImageKHR eglImage = eglCreateImageKHR (mEGLDisplay ,
391
+ EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, clientBuffer, attributes.data ());
384
392
if (eglImage == EGL_NO_IMAGE_KHR) {
385
393
slog.e << " eglCreateImageKHR returned no image." << io::endl;
386
394
return {};
@@ -389,25 +397,23 @@ AcquiredImage PlatformEGLAndroid::transformAcquiredImage(AcquiredImage source) n
389
397
// Destroy the EGLImage before invoking the user's callback.
390
398
struct Closure {
391
399
Closure (AcquiredImage const & acquiredImage, EGLDisplay display)
392
- : acquiredImage(acquiredImage),
393
- display (display) {}
400
+ : acquiredImage(acquiredImage), display(display) {}
394
401
AcquiredImage acquiredImage;
395
402
EGLDisplay display;
396
403
};
397
- Closure* closure = new (std::nothrow) Closure(source, mEGLDisplay );
404
+ Closure* closure = new (std::nothrow) Closure (source, mEGLDisplay );
398
405
auto patchedCallback = [](void * image, void * userdata) {
399
- Closure* closure = (Closure*) userdata;
406
+ Closure* closure = (Closure*)userdata;
400
407
if (eglDestroyImageKHR (closure->display , (EGLImageKHR) image) == EGL_FALSE) {
401
408
slog.e << " eglDestroyImageKHR failed." << io::endl;
402
409
}
403
- closure->acquiredImage .callback (closure->acquiredImage .image ,
404
- closure->acquiredImage .userData );
410
+ closure->acquiredImage .callback (closure->acquiredImage .image , closure->acquiredImage .userData );
405
411
delete closure;
406
412
};
407
413
408
414
return { eglImage, patchedCallback, closure, source.handler };
409
415
}
410
416
411
- }// namespace filament::backend
417
+ } // namespace filament::backend
412
418
413
419
// ---------------------------------------------------------------------------------------------
0 commit comments