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