1 // 2 // Copyright 2016 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // DisplayEGL.h: Common across EGL parts of platform specific egl::Display implementations 8 9 #ifndef LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_ 10 #define LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_ 11 12 #include <map> 13 #include <string> 14 #include <vector> 15 16 #include "libANGLE/renderer/gl/DisplayGL.h" 17 #include "libANGLE/renderer/gl/egl/egl_utils.h" 18 19 namespace rx 20 { 21 22 class FunctionsEGL; 23 class FunctionsEGLDL; 24 class RendererEGL; 25 class WorkerContext; 26 27 class DisplayEGL : public DisplayGL 28 { 29 public: 30 DisplayEGL(const egl::DisplayState &state); 31 ~DisplayEGL() override; 32 33 ImageImpl *createImage(const egl::ImageState &state, 34 const gl::Context *context, 35 EGLenum target, 36 const egl::AttributeMap &attribs) override; 37 38 EGLSyncImpl *createSync(const egl::AttributeMap &attribs) override; 39 40 void setBlobCacheFuncs(EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get) override; 41 42 virtual void destroyNativeContext(EGLContext context); 43 44 virtual WorkerContext *createWorkerContext(std::string *infoLog, 45 EGLContext sharedContext, 46 const native_egl::AttributeVector workerAttribs); 47 48 egl::Error initialize(egl::Display *display) override; 49 void terminate() override; 50 51 SurfaceImpl *createWindowSurface(const egl::SurfaceState &state, 52 EGLNativeWindowType window, 53 const egl::AttributeMap &attribs) override; 54 SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state, 55 const egl::AttributeMap &attribs) override; 56 SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state, 57 EGLenum buftype, 58 EGLClientBuffer clientBuffer, 59 const egl::AttributeMap &attribs) override; 60 SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state, 61 NativePixmapType nativePixmap, 62 const egl::AttributeMap &attribs) override; 63 64 ContextImpl *createContext(const gl::State &state, 65 gl::ErrorSet *errorSet, 66 const egl::Config *configuration, 67 const gl::Context *shareContext, 68 const egl::AttributeMap &attribs) override; 69 70 egl::ConfigSet generateConfigs() override; 71 72 bool testDeviceLost() override; 73 egl::Error restoreLostDevice(const egl::Display *display) override; 74 75 bool isValidNativeWindow(EGLNativeWindowType window) const override; 76 egl::Error validateClientBuffer(const egl::Config *configuration, 77 EGLenum buftype, 78 EGLClientBuffer clientBuffer, 79 const egl::AttributeMap &attribs) const override; 80 81 egl::Error waitClient(const gl::Context *context) override; 82 egl::Error waitNative(const gl::Context *context, EGLint engine) override; 83 84 egl::Error makeCurrent(egl::Display *display, 85 egl::Surface *drawSurface, 86 egl::Surface *readSurface, 87 gl::Context *context) override; 88 89 gl::Version getMaxSupportedESVersion() const override; 90 91 void initializeFrontendFeatures(angle::FrontendFeatures *features) const override; 92 93 void populateFeatureList(angle::FeatureList *features) override; 94 95 RendererGL *getRenderer() const override; 96 97 egl::Error validateImageClientBuffer(const gl::Context *context, 98 EGLenum target, 99 EGLClientBuffer clientBuffer, 100 const egl::AttributeMap &attribs) const override; 101 102 ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context, 103 EGLenum target, 104 EGLClientBuffer buffer, 105 const egl::AttributeMap &attribs) override; 106 107 const FunctionsEGL *getFunctionsEGL() const; 108 109 DeviceImpl *createDevice() override; 110 111 bool supportsDmaBufFormat(EGLint format) const override; 112 egl::Error queryDmaBufFormats(EGLint maxFormats, EGLint *formats, EGLint *numFormats) override; 113 egl::Error queryDmaBufModifiers(EGLint format, 114 EGLint maxModifiers, 115 EGLuint64KHR *modifiers, 116 EGLBoolean *externalOnly, 117 EGLint *numModifiers) override; 118 119 protected: 120 virtual EGLint fixSurfaceType(EGLint surfaceType) const; 121 122 private: 123 const char *getEGLPath() const; 124 125 egl::Error initializeContext(EGLContext shareContext, 126 const egl::AttributeMap &eglAttributes, 127 EGLContext *outContext, 128 native_egl::AttributeVector *outAttribs) const; 129 130 void generateExtensions(egl::DisplayExtensions *outExtensions) const override; 131 132 egl::Error createRenderer(EGLContext shareContext, 133 bool makeNewContextCurrent, 134 bool isExternalContext, 135 std::shared_ptr<RendererEGL> *outRenderer); 136 137 egl::Error makeCurrentSurfaceless(gl::Context *context) override; 138 139 template <typename T> 140 void getConfigAttrib(EGLConfig config, EGLint attribute, T *value) const; 141 142 template <typename T, typename U> 143 void getConfigAttribIfExtension(EGLConfig config, 144 EGLint attribute, 145 T *value, 146 const char *extension, 147 const U &defaultValue) const; 148 149 std::shared_ptr<RendererEGL> mRenderer; 150 std::map<EGLAttrib, std::weak_ptr<RendererEGL>> mVirtualizationGroups; 151 152 FunctionsEGLDL *mEGL = nullptr; 153 EGLConfig mConfig = EGL_NO_CONFIG_KHR; 154 egl::AttributeMap mDisplayAttributes; 155 std::vector<EGLint> mConfigAttribList; 156 157 struct CurrentNativeContext 158 { 159 EGLSurface surface = EGL_NO_SURFACE; 160 EGLContext context = EGL_NO_CONTEXT; 161 // True if the current context is an external context. and both surface and context will be 162 // unset when an external context is current. 163 bool isExternalContext = false; 164 }; 165 angle::HashMap<uint64_t, CurrentNativeContext> mCurrentNativeContexts; 166 167 void generateCaps(egl::Caps *outCaps) const override; 168 169 std::map<EGLint, EGLint> mConfigIds; 170 171 bool mHasEXTCreateContextRobustness = false; 172 bool mHasNVRobustnessVideoMemoryPurge = false; 173 174 bool mSupportsSurfaceless = false; 175 bool mSupportsNoConfigContexts = false; 176 177 EGLSurface mMockPbuffer = EGL_NO_SURFACE; 178 179 // Supported DRM formats 180 bool mSupportsDmaBufImportModifiers = false; 181 bool mNoOpDmaBufImportModifiers = false; 182 std::vector<EGLint> mDrmFormats; 183 bool mDrmFormatsInitialized = false; 184 }; 185 186 } // namespace rx 187 188 #endif // LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_ 189