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 <thread> 15 #include <vector> 16 17 #include "libANGLE/renderer/gl/DisplayGL.h" 18 #include "libANGLE/renderer/gl/egl/egl_utils.h" 19 20 namespace rx 21 { 22 23 class FunctionsEGL; 24 class FunctionsEGLDL; 25 class RendererEGL; 26 class WorkerContext; 27 28 class DisplayEGL : public DisplayGL 29 { 30 public: 31 DisplayEGL(const egl::DisplayState &state); 32 ~DisplayEGL() override; 33 34 ImageImpl *createImage(const egl::ImageState &state, 35 const gl::Context *context, 36 EGLenum target, 37 const egl::AttributeMap &attribs) override; 38 39 EGLSyncImpl *createSync(const egl::AttributeMap &attribs) override; 40 41 void setBlobCacheFuncs(EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get) override; 42 43 virtual void destroyNativeContext(EGLContext context); 44 45 virtual WorkerContext *createWorkerContext(std::string *infoLog, 46 EGLContext sharedContext, 47 const native_egl::AttributeVector workerAttribs); 48 49 egl::Error initialize(egl::Display *display) override; 50 void terminate() override; 51 52 SurfaceImpl *createWindowSurface(const egl::SurfaceState &state, 53 EGLNativeWindowType window, 54 const egl::AttributeMap &attribs) override; 55 SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state, 56 const egl::AttributeMap &attribs) override; 57 SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state, 58 EGLenum buftype, 59 EGLClientBuffer clientBuffer, 60 const egl::AttributeMap &attribs) override; 61 SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state, 62 NativePixmapType nativePixmap, 63 const egl::AttributeMap &attribs) override; 64 65 ContextImpl *createContext(const gl::State &state, 66 gl::ErrorSet *errorSet, 67 const egl::Config *configuration, 68 const gl::Context *shareContext, 69 const egl::AttributeMap &attribs) override; 70 71 egl::ConfigSet generateConfigs() override; 72 73 bool testDeviceLost() override; 74 egl::Error restoreLostDevice(const egl::Display *display) override; 75 76 bool isValidNativeWindow(EGLNativeWindowType window) const override; 77 egl::Error validateClientBuffer(const egl::Config *configuration, 78 EGLenum buftype, 79 EGLClientBuffer clientBuffer, 80 const egl::AttributeMap &attribs) const override; 81 82 egl::Error waitClient(const gl::Context *context) override; 83 egl::Error waitNative(const gl::Context *context, EGLint engine) override; 84 85 egl::Error makeCurrent(egl::Display *display, 86 egl::Surface *drawSurface, 87 egl::Surface *readSurface, 88 gl::Context *context) override; 89 90 gl::Version getMaxSupportedESVersion() const override; 91 92 void initializeFrontendFeatures(angle::FrontendFeatures *features) const override; 93 94 void populateFeatureList(angle::FeatureList *features) override; 95 96 RendererGL *getRenderer() const override; 97 98 egl::Error validateImageClientBuffer(const gl::Context *context, 99 EGLenum target, 100 EGLClientBuffer clientBuffer, 101 const egl::AttributeMap &attribs) const override; 102 103 ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context, 104 EGLenum target, 105 EGLClientBuffer buffer, 106 const egl::AttributeMap &attribs) override; 107 108 const FunctionsEGL *getFunctionsEGL() const; 109 110 protected: 111 virtual EGLint fixSurfaceType(EGLint surfaceType) const; 112 113 private: 114 const char *getEGLPath() const; 115 116 egl::Error initializeContext(EGLContext shareContext, 117 const egl::AttributeMap &eglAttributes, 118 EGLContext *outContext, 119 native_egl::AttributeVector *outAttribs) const; 120 121 void generateExtensions(egl::DisplayExtensions *outExtensions) const override; 122 123 egl::Error createRenderer(EGLContext shareContext, 124 bool makeNewContextCurrent, 125 bool isExternalContext, 126 std::shared_ptr<RendererEGL> *outRenderer); 127 128 egl::Error makeCurrentSurfaceless(gl::Context *context) override; 129 130 template <typename T> 131 void getConfigAttrib(EGLConfig config, EGLint attribute, T *value) const; 132 133 template <typename T, typename U> 134 void getConfigAttribIfExtension(EGLConfig config, 135 EGLint attribute, 136 T *value, 137 const char *extension, 138 const U &defaultValue) const; 139 140 std::shared_ptr<RendererEGL> mRenderer; 141 std::map<EGLAttrib, std::weak_ptr<RendererEGL>> mVirtualizationGroups; 142 143 FunctionsEGLDL *mEGL = nullptr; 144 EGLConfig mConfig = EGL_NO_CONFIG_KHR; 145 egl::AttributeMap mDisplayAttributes; 146 std::vector<EGLint> mConfigAttribList; 147 148 struct CurrentNativeContext 149 { 150 EGLSurface surface = EGL_NO_SURFACE; 151 EGLContext context = EGL_NO_CONTEXT; 152 // True if the current context is an external context. and both surface and context will be 153 // unset when an external context is current. 154 bool isExternalContext = false; 155 }; 156 angle::HashMap<std::thread::id, CurrentNativeContext> mCurrentNativeContexts; 157 158 void generateCaps(egl::Caps *outCaps) const override; 159 160 std::map<EGLint, EGLint> mConfigIds; 161 162 bool mHasEXTCreateContextRobustness = false; 163 bool mHasNVRobustnessVideoMemoryPurge = false; 164 165 bool mSupportsSurfaceless = false; 166 bool mSupportsNoConfigContexts = false; 167 168 EGLSurface mMockPbuffer = EGL_NO_SURFACE; 169 }; 170 171 } // namespace rx 172 173 #endif // LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_ 174