1 // Copyright 2020 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <stddef.h> 18 19 #include "aemu/base/c_header.h" 20 #include "aemu/base/export.h" 21 #include "host-common/multi_display_agent.h" 22 #include "host-common/vm_operations.h" 23 #include "host-common/window_agent.h" 24 #include "render-utils/virtio_gpu_ops.h" 25 #include "render-utils/RenderLib.h" 26 27 #ifndef USING_ANDROID_BP 28 ANDROID_BEGIN_HEADER 29 #endif 30 31 /* A version of android_initOpenglesEmulation that is called from a library 32 * that has static access to libOpenglRender. */ 33 AEMU_EXPORT int android_prepareOpenglesEmulation(void); 34 AEMU_EXPORT int android_setOpenglesEmulation(void* renderLib, void* eglDispatch, void* glesv2Dispatch); 35 36 /* Call this function to initialize the hardware opengles emulation. 37 * This function will abort if we can't find the corresponding host 38 * libraries through dlopen() or equivalent. 39 */ 40 AEMU_EXPORT int android_initOpenglesEmulation(void); 41 42 /* Tries to start the renderer process. Returns 0 on success, -1 on error. 43 * At the moment, this must be done before the VM starts. The onPost callback 44 * may be NULL. 45 * 46 * width and height: the framebuffer dimensions that will be reported 47 * to the guest display driver. 48 * guestApiLevel: API level of guest image (23 for mnc, 24 for nyc, etc) 49 */ 50 AEMU_EXPORT int android_startOpenglesRenderer(int width, int height, 51 bool isPhone, int guestApiLevel, 52 const QAndroidVmOperations *vm_operations, 53 const QAndroidEmulatorWindowAgent *window_agent, 54 const QAndroidMultiDisplayAgent *multi_display_agent, 55 int* glesMajorVersion_out, 56 int* glesMinorVersion_out); 57 58 AEMU_EXPORT bool android_asyncReadbackSupported(); 59 60 /* See the description in render_api.h. */ 61 typedef void (*OnPostFunc)(void* context, uint32_t displayId, int width, 62 int height, int ydir, int format, int type, 63 unsigned char* pixels); 64 AEMU_EXPORT void android_setPostCallback(OnPostFunc onPost, 65 void* onPostContext, 66 bool useBgraReadback, 67 uint32_t displayId); 68 69 typedef void (*ReadPixelsFunc)(void* pixels, uint32_t bytes, uint32_t displayId); 70 AEMU_EXPORT ReadPixelsFunc android_getReadPixelsFunc(); 71 72 73 typedef void (*FlushReadPixelPipeline)(int displayId); 74 75 /* Gets the function that can be used to make sure no 76 * frames are left in the video producer pipeline. 77 * This can result in a post callback. 78 */ 79 FlushReadPixelPipeline android_getFlushReadPixelPipeline(); 80 81 /* Retrieve the Vendor/Renderer/Version strings describing the underlying GL 82 * implementation. The call only works while the renderer is started. 83 * 84 * Expects |*vendor|, |*renderer| and |*version| to be NULL. 85 * 86 * On exit, sets |*vendor|, |*renderer| and |*version| to point to new 87 * heap-allocated strings (that must be freed by the caller) which represent the 88 * OpenGL hardware vendor name, driver name and version, respectively. 89 * In case of error, |*vendor| etc. are set to NULL. 90 */ 91 AEMU_EXPORT void android_getOpenglesHardwareStrings(char** vendor, 92 char** renderer, 93 char** version); 94 95 AEMU_EXPORT int android_showOpenglesWindow(void* window, 96 int wx, 97 int wy, 98 int ww, 99 int wh, 100 int fbw, 101 int fbh, 102 float dpr, 103 float rotation, 104 bool deleteExisting, 105 bool hideWindow); 106 107 AEMU_EXPORT int android_hideOpenglesWindow(void); 108 109 AEMU_EXPORT void android_setOpenglesTranslation(float px, float py); 110 111 AEMU_EXPORT void android_setOpenglesScreenMask(int width, int height, const unsigned char* rgbaData); 112 113 AEMU_EXPORT void android_redrawOpenglesWindow(void); 114 115 AEMU_EXPORT bool android_hasGuestPostedAFrame(void); 116 AEMU_EXPORT void android_resetGuestPostedAFrame(void); 117 118 typedef bool (*ScreenshotFunc)(const char* dirname, uint32_t displayId); 119 AEMU_EXPORT void android_registerScreenshotFunc(ScreenshotFunc f); 120 AEMU_EXPORT bool android_screenShot(const char* dirname, uint32_t displayId); 121 122 /* Stop the renderer process */ 123 AEMU_EXPORT void android_stopOpenglesRenderer(bool wait); 124 125 /* Finish all renderer work, deleting current 126 * render threads. Renderer is allowed to get 127 * new render threads after that. */ 128 AEMU_EXPORT void android_finishOpenglesRenderer(); 129 130 /* set to TRUE if you want to use fast GLES pipes, 0 if you want to 131 * fallback to local TCP ones 132 */ 133 AEMU_EXPORT extern int android_gles_fast_pipes; 134 135 // Notify the renderer that a guest graphics process is created or destroyed. 136 AEMU_EXPORT void android_onGuestGraphicsProcessCreate(uint64_t puid); 137 // TODO(kaiyili): rename this API to android_onGuestGraphicsProcessDestroy 138 AEMU_EXPORT void android_cleanupProcGLObjects(uint64_t puid); 139 140 AEMU_EXPORT void android_waitForOpenglesProcessCleanup(); 141 142 namespace gfxstream { 143 class Renderer; 144 } 145 146 AEMU_EXPORT const gfxstream::RendererPtr& android_getOpenglesRenderer(); 147 148 AEMU_EXPORT struct AndroidVirtioGpuOps* android_getVirtioGpuOps(void); 149 150 /* Get EGL/GLESv2 dispatch tables */ 151 AEMU_EXPORT const void* android_getEGLDispatch(); 152 AEMU_EXPORT const void* android_getGLESv2Dispatch(); 153 154 /* Set vsync rate at runtime */ 155 AEMU_EXPORT void android_setVsyncHz(int vsyncHz); 156 157 AEMU_EXPORT void android_setOpenglesDisplayConfigs(int configId, int w, int h, 158 int dpiX, int dpiY); 159 AEMU_EXPORT void android_setOpenglesDisplayActiveConfig(int configId); 160 161 #ifndef USING_ANDROID_BP 162 ANDROID_END_HEADER 163 #endif 164