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