• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2002 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 // Display.h: Defines the egl::Display class, representing the abstract
8 // display on which graphics are drawn. Implements EGLDisplay.
9 // [EGL 1.4] section 2.1.2 page 3.
10 
11 #ifndef LIBANGLE_DISPLAY_H_
12 #define LIBANGLE_DISPLAY_H_
13 
14 #include <mutex>
15 #include <set>
16 #include <vector>
17 
18 #include "libANGLE/AttributeMap.h"
19 #include "libANGLE/BlobCache.h"
20 #include "libANGLE/Caps.h"
21 #include "libANGLE/Config.h"
22 #include "libANGLE/Debug.h"
23 #include "libANGLE/Error.h"
24 #include "libANGLE/LoggingAnnotator.h"
25 #include "libANGLE/MemoryProgramCache.h"
26 #include "libANGLE/Version.h"
27 #include "platform/Feature.h"
28 #include "platform/FrontendFeatures.h"
29 
30 namespace gl
31 {
32 class Context;
33 class TextureManager;
34 }  // namespace gl
35 
36 namespace rx
37 {
38 class DisplayImpl;
39 }
40 
41 namespace egl
42 {
43 class Device;
44 class Image;
45 class Stream;
46 class Surface;
47 class Sync;
48 class Thread;
49 
50 using SurfaceSet = std::set<Surface *>;
51 
52 struct DisplayState final : private angle::NonCopyable
53 {
54     DisplayState(EGLNativeDisplayType nativeDisplayId);
55     ~DisplayState();
56 
57     EGLLabelKHR label;
58     SurfaceSet surfaceSet;
59     std::vector<std::string> featureOverridesEnabled;
60     std::vector<std::string> featureOverridesDisabled;
61     bool featuresAllDisabled;
62     EGLNativeDisplayType displayId;
63 };
64 
65 // Constant coded here as a sanity limit.
66 constexpr EGLAttrib kProgramCacheSizeAbsoluteMax = 0x4000000;
67 
68 class Display final : public LabeledObject, angle::NonCopyable
69 {
70   public:
71     ~Display() override;
72 
73     void setLabel(EGLLabelKHR label) override;
74     EGLLabelKHR getLabel() const override;
75 
76     Error initialize();
77     Error terminate(const Thread *thread);
78 
79     static Display *GetDisplayFromDevice(Device *device, const AttributeMap &attribMap);
80     static Display *GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay,
81                                                 const AttributeMap &attribMap);
82     static Display *GetExistingDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay);
83 
84     static const ClientExtensions &GetClientExtensions();
85     static const std::string &GetClientExtensionString();
86 
87     std::vector<const Config *> getConfigs(const AttributeMap &attribs) const;
88     std::vector<const Config *> chooseConfig(const AttributeMap &attribs) const;
89 
90     Error createWindowSurface(const Config *configuration,
91                               EGLNativeWindowType window,
92                               const AttributeMap &attribs,
93                               Surface **outSurface);
94     Error createPbufferSurface(const Config *configuration,
95                                const AttributeMap &attribs,
96                                Surface **outSurface);
97     Error createPbufferFromClientBuffer(const Config *configuration,
98                                         EGLenum buftype,
99                                         EGLClientBuffer clientBuffer,
100                                         const AttributeMap &attribs,
101                                         Surface **outSurface);
102     Error createPixmapSurface(const Config *configuration,
103                               NativePixmapType nativePixmap,
104                               const AttributeMap &attribs,
105                               Surface **outSurface);
106 
107     Error createImage(const gl::Context *context,
108                       EGLenum target,
109                       EGLClientBuffer buffer,
110                       const AttributeMap &attribs,
111                       Image **outImage);
112 
113     Error createStream(const AttributeMap &attribs, Stream **outStream);
114 
115     Error createContext(const Config *configuration,
116                         gl::Context *shareContext,
117                         const EGLenum clientType,
118                         const AttributeMap &attribs,
119                         gl::Context **outContext);
120 
121     Error createSync(const gl::Context *currentContext,
122                      EGLenum type,
123                      const AttributeMap &attribs,
124                      Sync **outSync);
125 
126     Error makeCurrent(const Thread *thread,
127                       Surface *drawSurface,
128                       Surface *readSurface,
129                       gl::Context *context);
130 
131     Error destroySurface(Surface *surface);
132     void destroyImage(Image *image);
133     void destroyStream(Stream *stream);
134     Error destroyContext(const Thread *thread, gl::Context *context);
135     void destroySync(Sync *sync);
136 
137     bool isInitialized() const;
138     bool isValidConfig(const Config *config) const;
139     bool isValidContext(const gl::Context *context) const;
140     bool isValidSurface(const Surface *surface) const;
141     bool isValidImage(const Image *image) const;
142     bool isValidStream(const Stream *stream) const;
143     bool isValidSync(const Sync *sync) const;
144     bool isValidNativeWindow(EGLNativeWindowType window) const;
145 
146     Error validateClientBuffer(const Config *configuration,
147                                EGLenum buftype,
148                                EGLClientBuffer clientBuffer,
149                                const AttributeMap &attribs) const;
150     Error validateImageClientBuffer(const gl::Context *context,
151                                     EGLenum target,
152                                     EGLClientBuffer clientBuffer,
153                                     const egl::AttributeMap &attribs) const;
154 
155     static bool isValidDisplay(const Display *display);
156     static bool isValidNativeDisplay(EGLNativeDisplayType display);
157     static bool hasExistingWindowSurface(EGLNativeWindowType window);
158 
159     bool isDeviceLost() const;
160     bool testDeviceLost();
161     void notifyDeviceLost();
162 
163     void setBlobCacheFuncs(EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
areBlobCacheFuncsSet()164     bool areBlobCacheFuncsSet() const { return mBlobCache.areBlobCacheFuncsSet(); }
getBlobCache()165     BlobCache &getBlobCache() { return mBlobCache; }
166 
167     static EGLClientBuffer GetNativeClientBuffer(const struct AHardwareBuffer *buffer);
168 
169     Error waitClient(const gl::Context *context);
170     Error waitNative(const gl::Context *context, EGLint engine);
171 
172     const Caps &getCaps() const;
173 
174     const DisplayExtensions &getExtensions() const;
175     const std::string &getExtensionString() const;
176     const std::string &getVendorString() const;
177 
178     EGLint programCacheGetAttrib(EGLenum attrib) const;
179     Error programCacheQuery(EGLint index,
180                             void *key,
181                             EGLint *keysize,
182                             void *binary,
183                             EGLint *binarysize);
184     Error programCachePopulate(const void *key,
185                                EGLint keysize,
186                                const void *binary,
187                                EGLint binarysize);
188     EGLint programCacheResize(EGLint limit, EGLenum mode);
189 
getAttributeMap()190     const AttributeMap &getAttributeMap() const { return mAttributeMap; }
getNativeDisplayId()191     EGLNativeDisplayType getNativeDisplayId() const { return mState.displayId; }
192 
getImplementation()193     rx::DisplayImpl *getImplementation() const { return mImplementation; }
194     Device *getDevice() const;
195     Surface *getWGLSurface() const;
getPlatform()196     EGLenum getPlatform() const { return mPlatform; }
197 
198     gl::Version getMaxSupportedESVersion() const;
199 
getState()200     const DisplayState &getState() const { return mState; }
201 
202     typedef std::set<gl::Context *> ContextSet;
getContextSet()203     const ContextSet &getContextSet() { return mContextSet; }
204 
getFrontendFeatures()205     const angle::FrontendFeatures &getFrontendFeatures() { return mFrontendFeatures; }
206 
getFeatures()207     const angle::FeatureList &getFeatures() const { return mFeatures; }
208 
209     const char *queryStringi(const EGLint name, const EGLint index);
210 
211     EGLAttrib queryAttrib(const EGLint attribute);
212 
213     angle::ScratchBuffer requestScratchBuffer();
214     void returnScratchBuffer(angle::ScratchBuffer scratchBuffer);
215 
216     angle::ScratchBuffer requestZeroFilledBuffer();
217     void returnZeroFilledBuffer(angle::ScratchBuffer zeroFilledBuffer);
218 
219   private:
220     Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice);
221 
setAttributes(const AttributeMap & attribMap)222     void setAttributes(const AttributeMap &attribMap) { mAttributeMap = attribMap; }
223 
224     void setupDisplayPlatform(rx::DisplayImpl *impl);
225 
226     void updateAttribsFromEnvironment(const AttributeMap &attribMap);
227 
228     Error restoreLostDevice();
229 
230     void initDisplayExtensions();
231     void initVendorString();
232     void initializeFrontendFeatures();
233 
234     angle::ScratchBuffer requestScratchBufferImpl(std::vector<angle::ScratchBuffer> *bufferVector);
235     void returnScratchBufferImpl(angle::ScratchBuffer scratchBuffer,
236                                  std::vector<angle::ScratchBuffer> *bufferVector);
237 
238     DisplayState mState;
239     rx::DisplayImpl *mImplementation;
240 
241     AttributeMap mAttributeMap;
242 
243     ConfigSet mConfigSet;
244 
245     ContextSet mContextSet;
246 
247     typedef std::set<Image *> ImageSet;
248     ImageSet mImageSet;
249 
250     typedef std::set<Stream *> StreamSet;
251     StreamSet mStreamSet;
252 
253     typedef std::set<Sync *> SyncSet;
254     SyncSet mSyncSet;
255 
256     bool mInitialized;
257     bool mDeviceLost;
258 
259     Caps mCaps;
260 
261     DisplayExtensions mDisplayExtensions;
262     std::string mDisplayExtensionString;
263 
264     std::string mVendorString;
265 
266     Device *mDevice;
267     Surface *mSurface;
268     EGLenum mPlatform;
269     angle::LoggingAnnotator mAnnotator;
270 
271     gl::TextureManager *mTextureManager;
272     BlobCache mBlobCache;
273     gl::MemoryProgramCache mMemoryProgramCache;
274     size_t mGlobalTextureShareGroupUsers;
275 
276     angle::FrontendFeatures mFrontendFeatures;
277 
278     angle::FeatureList mFeatures;
279 
280     std::mutex mScratchBufferMutex;
281     std::vector<angle::ScratchBuffer> mScratchBuffers;
282     std::vector<angle::ScratchBuffer> mZeroFilledBuffers;
283 };
284 
285 }  // namespace egl
286 
287 #endif  // LIBANGLE_DISPLAY_H_
288