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