• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2011 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 #ifndef TRANSLATOR_IFACES_H
17 #define TRANSLATOR_IFACES_H
18 
19 #include "aemu/base/containers/SmallVector.h"
20 #include "GLcommon/GLutils.h"
21 #include "GLcommon/ShareGroup.h"
22 
23 #include <EGL/egl.h>
24 #include <GLES/gl.h>
25 #include <GLES2/gl2.h>
26 #include <GLES3/gl3.h>
27 #include <string.h>
28 
29 #include <memory>
30 #include <unordered_map>
31 #include <functional>
32 
33 extern "C" {
34 
35 /* This is a generic function pointer type, whose name indicates it must
36  * be cast to the proper type *and calling convention* before use.
37  */
38 typedef void (*__translatorMustCastToProperFunctionPointerType)(void);
39 
40 typedef struct {
41   const char*                                     name;
42   __translatorMustCastToProperFunctionPointerType address;
43 } ExtensionDescriptor;
44 
45 class SaveableTexture;
46 typedef std::shared_ptr<SaveableTexture> SaveableTexturePtr;
47 
48 struct EglImage
49 {
EglImageEglImage50     EglImage() :
51         isNative(false),
52         isImported(false),
53         nativeImage((EGLImage)0),
54         imageId(0),
55         globalTexObj(nullptr),
56         width(0),
57         height(0),
58         internalFormat(0),
59         border(0),
60         format(0),
61         type(0),
62         texStorageLevels(0),
63         saveableTexture(0),
64         needRestore(false),
65         sync(nullptr) { }
~EglImageEglImage66     ~EglImage(){};
67     bool isNative;
68     bool isImported;
69     EGLImage nativeImage;
70     unsigned int imageId;
71     NamedObjectPtr globalTexObj;
72     unsigned int width;
73     unsigned int height;
74     unsigned int internalFormat;
75     unsigned int border;
76     unsigned int format;
77     unsigned int type;
78     unsigned int texStorageLevels;
79     SaveableTexturePtr saveableTexture;
80     bool needRestore;
81     GLsync sync;
82 };
83 
84 typedef std::shared_ptr<EglImage> ImagePtr;
85 typedef std::unordered_map<unsigned int, ImagePtr> ImagesHndlMap;
86 typedef std::unordered_map<unsigned int, SaveableTexturePtr> SaveableTextureMap;
87 
88 class GLEScontext;
89 class SaveableTexture;
90 
91 namespace android_studio {
92     class EmulatorGLESUsages;
93 }
94 
95 typedef struct {
96     void (*initGLESx)(bool isGles2Gles);
97     GLEScontext*                                    (*createGLESContext)(int majorVersion, int minorVersion, GlobalNameSpace* globalNameSpace, android::base::Stream* stream);
98     void                                            (*initContext)(GLEScontext*, ShareGroupPtr, bool);
99     void                                            (*setMaxGlesVersion)(GLESVersion);
100     void                                            (*deleteGLESContext)(GLEScontext*);
101     void                                            (*flush)();
102     void                                            (*finish)();
103     int                                             (*getError)();
104     void                                            (*setShareGroup)(GLEScontext*,ShareGroupPtr);
105     __translatorMustCastToProperFunctionPointerType (*getProcAddress)(const char*);
106     GLsync                                          (*fenceSync)(GLenum, GLbitfield);
107     GLenum                                          (*clientWaitSync)(GLsync, GLbitfield, GLuint64);
108     void                                            (*waitSync)(GLsync, GLbitfield, GLuint64);
109     void                                            (*deleteSync)(GLsync);
110     void                                            (*preSaveTexture)();
111     void                                            (*postSaveTexture)();
112     void                                            (*saveTexture)(SaveableTexture*, android::base::Stream*, android::base::SmallVector<unsigned char>* buffer);
113     SaveableTexture* (*createTexture)(GlobalNameSpace*,
114                                       std::function<void(SaveableTexture*)>&&);
115     void                                            (*restoreTexture)(SaveableTexture*);
116     void                                            (*deleteRbo)(GLuint);
117     void                                            (*blitFromCurrentReadBufferANDROID)(EGLImage);
118     bool                                            (*vulkanInteropSupported)();
119     void                                            (*getSynciv)(GLsync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
120 } GLESiface;
121 
122 class GlLibrary;
123 
124 // A structure containing function pointers implemented by the EGL
125 // translator library, and called from the GLES 1.x and 2.0 translator
126 // libraries.
127 struct EGLiface {
128     // Get the current GLESContext instance for the current thread.
129     GLEScontext* (*getGLESContext)();
130 
131     // Retrieve a shared pointer to a global EglImage object named |imageId|
132     ImagePtr    (*getEGLImage)(unsigned int imageId);
133 
134     // Return instance of GlLibrary class to use for dispatch.
135     // at runtime. This is implemented in the EGL library because on Windows
136     // all functions returned by wglGetProcAddress() are context-dependent!
137     GlLibrary* (*eglGetGlLibrary)();
138 
139     // Context creation functions for auxiliary functions (e.g.,
140     // background loading). Instead of going through the standard
141     // eglChooseConfig/eglCreatePbufferSurface/eglCreateContext/eglMakeCurrent,
142     // these functions set up a minimal context with pre-set configuration
143     // that allows one to easily run GL calls in separate threads.
144     // createAndBindAuxiliaryContext(): Creates a minimal context (1x1 pbuffer, with first config)
145     // and makes it the current context and writes the resulting context and surface to
146     // |context_out| and |surface_out|. Returns false if any step of context creation failed,
147     // true otherwise.
148     bool (*createAndBindAuxiliaryContext)(EGLContext* context_out, EGLSurface* surface_out);
149     // unbindAndDestroyAuxiliaryContext(): Cleans up the resulting |context| and |surface| from a
150     // createAndBindAuxiliaryContext() call; binds the null context and surface, then
151     // destroys the surface and context. Returns false if any step of cleanup failed,
152     // true otherwise.
153     bool (*unbindAndDestroyAuxiliaryContext)(EGLContext context, EGLSurface surface);
154     // Makes |context| and |surface| current, assuming they have been created already.
155     bool (*bindAuxiliaryContext)(EGLContext context, EGLSurface surface);
156     // Makes EGL_NO_SURFACE and EGL_NO_CONTEXT current, unbinding whatever is the current context.
157     bool (*unbindAuxiliaryContext)();
158 
159     // When we need to get function pointers via eglGetProcAddress.
160     std::function<void*(const char*)> getProcAddress;
161 };
162 
163 typedef GLESiface* (*__translator_getGLESIfaceFunc)(const EGLiface*);
164 
165 }
166 #endif
167