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 "base/export.h" 20 #include "host-common/multi_display_agent.h" 21 #include "host-common/vm_operations.h" 22 #include "host-common/window_agent.h" 23 #include "host-common/opengl/virtio_gpu_ops.h" 24 #include "../stream-servers/RenderLib.h" 25 26 /* A version of android_initOpenglesEmulation that is called from a library 27 * that has static access to libOpenglRender. */ 28 AEMU_EXPORT int android_prepareOpenglesEmulation(void); 29 AEMU_EXPORT int android_setOpenglesEmulation(void* renderLib, void* eglDispatch, void* glesv2Dispatch); 30 31 /* Call this function to initialize the hardware opengles emulation. 32 * This function will abort if we can't find the corresponding host 33 * libraries through dlopen() or equivalent. 34 */ 35 AEMU_EXPORT int android_initOpenglesEmulation(void); 36 37 /* Tries to start the renderer process. Returns 0 on success, -1 on error. 38 * At the moment, this must be done before the VM starts. The onPost callback 39 * may be NULL. 40 * 41 * width and height: the framebuffer dimensions that will be reported 42 * to the guest display driver. 43 * guestApiLevel: API level of guest image (23 for mnc, 24 for nyc, etc) 44 */ 45 AEMU_EXPORT int android_startOpenglesRenderer(int width, int height, 46 bool isPhone, int guestApiLevel, 47 const QAndroidVmOperations *vm_operations, 48 const QAndroidEmulatorWindowAgent *window_agent, 49 const QAndroidMultiDisplayAgent *multi_display_agent, 50 int* glesMajorVersion_out, 51 int* glesMinorVersion_out); 52 53 AEMU_EXPORT bool android_asyncReadbackSupported(); 54 55 /* See the description in render_api.h. */ 56 typedef void (*OnPostFunc)(void* context, uint32_t displayId, int width, 57 int height, int ydir, int format, int type, 58 unsigned char* pixels); 59 AEMU_EXPORT void android_setPostCallback(OnPostFunc onPost, 60 void* onPostContext, 61 bool useBgraReadback, 62 uint32_t displayId); 63 64 typedef void (*ReadPixelsFunc)(void* pixels, uint32_t bytes, uint32_t displayId); 65 AEMU_EXPORT ReadPixelsFunc android_getReadPixelsFunc(); 66 67 68 typedef void (*FlushReadPixelPipeline)(int displayId); 69 70 /* Gets the function that can be used to make sure no 71 * frames are left in the video producer pipeline. 72 * This can result in a post callback. 73 */ 74 FlushReadPixelPipeline android_getFlushReadPixelPipeline(); 75 76 /* Retrieve the Vendor/Renderer/Version strings describing the underlying GL 77 * implementation. The call only works while the renderer is started. 78 * 79 * Expects |*vendor|, |*renderer| and |*version| to be NULL. 80 * 81 * On exit, sets |*vendor|, |*renderer| and |*version| to point to new 82 * heap-allocated strings (that must be freed by the caller) which represent the 83 * OpenGL hardware vendor name, driver name and version, respectively. 84 * In case of error, |*vendor| etc. are set to NULL. 85 */ 86 AEMU_EXPORT void android_getOpenglesHardwareStrings(char** vendor, 87 char** renderer, 88 char** version); 89 90 AEMU_EXPORT int android_showOpenglesWindow(void* window, 91 int wx, 92 int wy, 93 int ww, 94 int wh, 95 int fbw, 96 int fbh, 97 float dpr, 98 float rotation, 99 bool deleteExisting, 100 bool hideWindow); 101 102 AEMU_EXPORT int android_hideOpenglesWindow(void); 103 104 AEMU_EXPORT void android_setOpenglesTranslation(float px, float py); 105 106 AEMU_EXPORT void android_setOpenglesScreenMask(int width, int height, const unsigned char* rgbaData); 107 108 AEMU_EXPORT void android_redrawOpenglesWindow(void); 109 110 AEMU_EXPORT bool android_hasGuestPostedAFrame(void); 111 AEMU_EXPORT void android_resetGuestPostedAFrame(void); 112 113 typedef bool (*ScreenshotFunc)(const char* dirname, uint32_t displayId); 114 AEMU_EXPORT void android_registerScreenshotFunc(ScreenshotFunc f); 115 AEMU_EXPORT bool android_screenShot(const char* dirname, uint32_t displayId); 116 117 /* Stop the renderer process */ 118 AEMU_EXPORT void android_stopOpenglesRenderer(bool wait); 119 120 /* Finish all renderer work, deleting current 121 * render threads. Renderer is allowed to get 122 * new render threads after that. */ 123 AEMU_EXPORT void android_finishOpenglesRenderer(); 124 125 /* set to TRUE if you want to use fast GLES pipes, 0 if you want to 126 * fallback to local TCP ones 127 */ 128 AEMU_EXPORT extern int android_gles_fast_pipes; 129 130 AEMU_EXPORT void android_cleanupProcGLObjects(uint64_t puid); 131 132 AEMU_EXPORT void android_waitForOpenglesProcessCleanup(); 133 134 namespace emugl { 135 class Renderer; 136 } 137 138 AEMU_EXPORT const emugl::RendererPtr& android_getOpenglesRenderer(); 139 140 AEMU_EXPORT struct AndroidVirtioGpuOps* android_getVirtioGpuOps(void); 141 142 /* Get EGL/GLESv2 dispatch tables */ 143 AEMU_EXPORT const void* android_getEGLDispatch(); 144 AEMU_EXPORT const void* android_getGLESv2Dispatch(); 145