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