• 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                                               const void* gfxstreamFeatures,
60                                               int* glesMajorVersion_out,
61                                               int* glesMinorVersion_out);
62 
63 AEMU_EXPORT bool android_asyncReadbackSupported();
64 
65 /* See the description in render_api.h. */
66 typedef void (*OnPostFunc)(void* context, uint32_t displayId, int width,
67                            int height, int ydir, int format, int type,
68                            unsigned char* pixels);
69 AEMU_EXPORT void android_setPostCallback(OnPostFunc onPost,
70                              void* onPostContext,
71                              bool useBgraReadback,
72                              uint32_t displayId);
73 
74 typedef void (*ReadPixelsFunc)(void* pixels, uint32_t bytes, uint32_t displayId);
75 AEMU_EXPORT ReadPixelsFunc android_getReadPixelsFunc();
76 
77 
78 typedef void (*FlushReadPixelPipeline)(int displayId);
79 
80 /* Gets the function that can be used to make sure no
81  * frames are left in the video producer pipeline.
82  * This can result in a post callback.
83  */
84 FlushReadPixelPipeline android_getFlushReadPixelPipeline();
85 
86 /* Retrieve the Vendor/Renderer/Version strings describing the underlying GL
87  * implementation. The call only works while the renderer is started.
88  *
89  * Expects |*vendor|, |*renderer| and |*version| to be NULL.
90  *
91  * On exit, sets |*vendor|, |*renderer| and |*version| to point to new
92  * heap-allocated strings (that must be freed by the caller) which represent the
93  * OpenGL hardware vendor name, driver name and version, respectively.
94  * In case of error, |*vendor| etc. are set to NULL.
95  */
96 AEMU_EXPORT void android_getOpenglesHardwareStrings(char** vendor,
97                                                     char** renderer,
98                                                     char** version);
99 
100 AEMU_EXPORT int android_showOpenglesWindow(void* window,
101                                            int wx,
102                                            int wy,
103                                            int ww,
104                                            int wh,
105                                            int fbw,
106                                            int fbh,
107                                            float dpr,
108                                            float rotation,
109                                            bool deleteExisting,
110                                            bool hideWindow);
111 
112 AEMU_EXPORT int android_hideOpenglesWindow(void);
113 
114 AEMU_EXPORT void android_setOpenglesTranslation(float px, float py);
115 
116 AEMU_EXPORT void android_setOpenglesScreenMask(int width, int height, const unsigned char* rgbaData);
117 
118 AEMU_EXPORT void android_redrawOpenglesWindow(void);
119 
120 AEMU_EXPORT bool android_hasGuestPostedAFrame(void);
121 AEMU_EXPORT void android_resetGuestPostedAFrame(void);
122 
123 typedef bool (*ScreenshotFunc)(const char* dirname, uint32_t displayId);
124 AEMU_EXPORT void android_registerScreenshotFunc(ScreenshotFunc f);
125 AEMU_EXPORT bool android_screenShot(const char* dirname, uint32_t displayId);
126 
127 /* Stop the renderer process */
128 EMUGL_COMMON_API void android_stopOpenglesRenderer(bool wait);
129 
130 /* Finish all renderer work, deleting current
131  * render threads. Renderer is allowed to get
132  * new render threads after that. */
133 AEMU_EXPORT void android_finishOpenglesRenderer();
134 
135 /* set to TRUE if you want to use fast GLES pipes, 0 if you want to
136  * fallback to local TCP ones
137  */
138 AEMU_EXPORT extern int  android_gles_fast_pipes;
139 
140 // Notify the renderer that a guest graphics process is created or destroyed.
141 AEMU_EXPORT void android_onGuestGraphicsProcessCreate(uint64_t puid);
142 // TODO(kaiyili): rename this API to android_onGuestGraphicsProcessDestroy
143 AEMU_EXPORT void android_cleanupProcGLObjects(uint64_t puid);
144 
145 AEMU_EXPORT void android_waitForOpenglesProcessCleanup();
146 
147 #ifdef __cplusplus
148 namespace gfxstream {
149 class Renderer;
150 }
151 
152 AEMU_EXPORT const gfxstream::RendererPtr& android_getOpenglesRenderer();
153 EMUGL_COMMON_API void android_setOpenglesRenderer(gfxstream::RendererPtr* renderer);
154 #endif
155 
156 AEMU_EXPORT struct AndroidVirtioGpuOps* android_getVirtioGpuOps(void);
157 
158 /* Get EGL/GLESv2 dispatch tables */
159 AEMU_EXPORT const void* android_getEGLDispatch();
160 AEMU_EXPORT const void* android_getGLESv2Dispatch();
161 
162 /* Set vsync rate at runtime */
163 AEMU_EXPORT void android_setVsyncHz(int vsyncHz);
164 
165 AEMU_EXPORT void android_setOpenglesDisplayConfigs(int configId, int w, int h,
166                                                    int dpiX, int dpiY);
167 AEMU_EXPORT void android_setOpenglesDisplayActiveConfig(int configId);
168 
169 #ifndef USING_ANDROID_BP
170 ANDROID_END_HEADER
171 #endif
172