• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 
77     egl::Error waitClient(const gl::Context *context) override;
78     egl::Error waitNative(const gl::Context *context, EGLint engine) override;
79 
80     egl::Error makeCurrent(egl::Display *display,
81                            egl::Surface *drawSurface,
82                            egl::Surface *readSurface,
83                            gl::Context *context) override;
84 
85     gl::Version getMaxSupportedESVersion() const override;
86 
87     void initializeFrontendFeatures(angle::FrontendFeatures *features) const override;
88 
89     void populateFeatureList(angle::FeatureList *features) override;
90 
91     RendererGL *getRenderer() const override;
92 
93     egl::Error validateImageClientBuffer(const gl::Context *context,
94                                          EGLenum target,
95                                          EGLClientBuffer clientBuffer,
96                                          const egl::AttributeMap &attribs) const override;
97 
98     ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context,
99                                                          EGLenum target,
100                                                          EGLClientBuffer buffer,
101                                                          const egl::AttributeMap &attribs) override;
102 
103   protected:
104     egl::Error initializeContext(EGLContext shareContext,
105                                  const egl::AttributeMap &eglAttributes,
106                                  EGLContext *outContext,
107                                  native_egl::AttributeVector *outAttribs) const;
108 
109     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
110 
111     egl::Error createRenderer(EGLContext shareContext, std::shared_ptr<RendererEGL> *outRenderer);
112 
113     egl::Error makeCurrentSurfaceless(gl::Context *context) override;
114 
115     virtual EGLint fixSurfaceType(EGLint surfaceType) const;
116 
117     template <typename T>
118     void getConfigAttrib(EGLConfig config, EGLint attribute, T *value) const;
119 
120     template <typename T, typename U>
121     void getConfigAttribIfExtension(EGLConfig config,
122                                     EGLint attribute,
123                                     T *value,
124                                     const char *extension,
125                                     const U &defaultValue) const;
126 
127     std::shared_ptr<RendererEGL> mRenderer;
128     FunctionsEGLDL *mEGL;
129     EGLConfig mConfig;
130     egl::AttributeMap mDisplayAttributes;
131     std::vector<EGLint> mConfigAttribList;
132 
133     struct CurrentNativeContext
134     {
135         EGLSurface surface = EGL_NO_SURFACE;
136         EGLContext context = EGL_NO_CONTEXT;
137         // True if the current context is an external context. and both surface and context will be
138         // unset when an external context is current.
139         bool isExternalContext = false;
140     };
141     angle::HashMap<std::thread::id, CurrentNativeContext> mCurrentNativeContexts;
142 
143   private:
144     void generateCaps(egl::Caps *outCaps) const override;
145 
146     std::map<EGLint, EGLint> mConfigIds;
147 
148     bool mHasEXTCreateContextRobustness;
149     bool mHasNVRobustnessVideoMemoryPurge;
150 };
151 
152 }  // namespace rx
153 
154 #endif  // LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_
155