1 /*
2  * Copyright 2019 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 #ifndef _ANDROID_GRAPHICS_SURFACE_TEXTURE_PLATFORM_H
18 #define _ANDROID_GRAPHICS_SURFACE_TEXTURE_PLATFORM_H
19 
20 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 #include <nativehelper/JNIHelp.h>
23 #include <system/graphics.h>
24 
25 // This file provides a facade API on top of SurfaceTexture, which avoids using
26 // C++ types. This is still a C++ unstable API though. Ideally features here
27 // will be exposed via public NDK API and this file will be deleted.
28 
29 struct ASurfaceTexture;
30 
31 namespace android {
32 
33 // Trampoline functions allowing libandroid.so to define the NDK symbols without including
34 // the entirety of libnativedisplay as a whole static lib. As libnativedisplay
35 // maintains global state, libnativedisplay can never be directly statically
36 // linked so that global state won't be duplicated. This way libandroid.so can
37 // reroute the NDK methods into the implementations defined by libnativedisplay
38 ANativeWindow* ASurfaceTexture_routeAcquireANativeWindow(ASurfaceTexture* st);
39 int ASurfaceTexture_routeAttachToGLContext(ASurfaceTexture* st, uint32_t texName);
40 int ASurfaceTexture_routeDetachFromGLContext(ASurfaceTexture* st);
41 void ASurfaceTexture_routeRelease(ASurfaceTexture* st);
42 int ASurfaceTexture_routeUpdateTexImage(ASurfaceTexture* st);
43 void ASurfaceTexture_routeGetTransformMatrix(ASurfaceTexture* st, float mtx[16]);
44 int64_t ASurfaceTexture_routeGetTimestamp(ASurfaceTexture* st);
45 ASurfaceTexture* ASurfaceTexture_routeFromSurfaceTexture(JNIEnv* env, jobject surfacetexture);
46 
47 /**
48  * ASurfaceTexture_getCurrentTextureTarget returns the texture target of the
49  * current texture.
50  */
51 unsigned int ASurfaceTexture_getCurrentTextureTarget(ASurfaceTexture* st);
52 
53 /**
54  * ASurfaceTexture_takeConsumerOwnership attaches an ASurfaceTexture that is
55  * currently in the 'detached' state to a consumer context.
56  */
57 void ASurfaceTexture_takeConsumerOwnership(ASurfaceTexture* st);
58 
59 /**
60  * ASurfaceTexture_releaseConsumerOwnership detaches a SurfaceTexture from
61  * a consumer context.
62  */
63 void ASurfaceTexture_releaseConsumerOwnership(ASurfaceTexture* st);
64 
65 /**
66  * Callback function needed by ASurfaceTexture_dequeueBuffer. It creates a
67  * fence that is signalled when the previous buffer is no longer in use by the
68  * consumer (usually HWUI RenderThread) and can be written to by the producer.
69  */
70 typedef int (*ASurfaceTexture_createReleaseFence)(bool useFenceSync, EGLSyncKHR* eglFence,
71                                                   EGLDisplay* display, int* releaseFence,
72                                                   void* fencePassThroughHandle);
73 
74 /**
75  * Callback function needed by ASurfaceTexture_dequeueBuffer. It waits for the
76  * new buffer fence to signal before issuing any draw commands.
77  */
78 typedef int (*ASurfaceTexture_fenceWait)(int fence, void* fencePassThroughHandle);
79 
80 /**
81  * ASurfaceTexture_dequeueBuffer returns the next available AHardwareBuffer.
82  * The caller gets ownership of the buffer and need to release it with
83  * AHardwareBuffer_release.
84  */
85 AHardwareBuffer* ASurfaceTexture_dequeueBuffer(ASurfaceTexture* st, int* outSlotid,
86                                                android_dataspace* outDataspace,
87                                                float* outTransformMatrix, bool* outNewContent,
88                                                ASurfaceTexture_createReleaseFence createFence,
89                                                ASurfaceTexture_fenceWait fenceWait,
90                                                void* fencePassThroughHandle);
91 
92 } // namespace android
93 
94 #endif // _ANDROID_GRAPHICS_SURFACE_TEXTURE_PLATFORM_H
95