1 // 2 // Copyright (c) 2002-2013 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/Caps.h" 19 #include "libANGLE/Config.h" 20 #include "libANGLE/Error.h" 21 #include "libANGLE/LoggingAnnotator.h" 22 #include "libANGLE/MemoryProgramCache.h" 23 #include "libANGLE/Version.h" 24 25 namespace gl 26 { 27 class Context; 28 class TextureManager; 29 } 30 31 namespace rx 32 { 33 class DisplayImpl; 34 } 35 36 namespace egl 37 { 38 class Device; 39 class Image; 40 class Surface; 41 class Stream; 42 class Thread; 43 44 using SurfaceSet = std::set<Surface *>; 45 46 struct DisplayState final : private angle::NonCopyable 47 { 48 DisplayState(); 49 ~DisplayState(); 50 51 SurfaceSet surfaceSet; 52 }; 53 54 // Constant coded here as a sanity limit. 55 constexpr EGLAttrib kProgramCacheSizeAbsoluteMax = 0x4000000; 56 57 class Display final : angle::NonCopyable 58 { 59 public: 60 ~Display(); 61 62 Error initialize(); 63 Error terminate(); 64 65 static Display *GetDisplayFromDevice(Device *device, const AttributeMap &attribMap); 66 static Display *GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay, 67 const AttributeMap &attribMap); 68 static void CleanupDisplays(); 69 70 static const ClientExtensions &GetClientExtensions(); 71 static const std::string &GetClientExtensionString(); 72 73 std::vector<const Config *> getConfigs(const AttributeMap &attribs) const; 74 75 Error createWindowSurface(const Config *configuration, 76 EGLNativeWindowType window, 77 const AttributeMap &attribs, 78 Surface **outSurface); 79 Error createPbufferSurface(const Config *configuration, 80 const AttributeMap &attribs, 81 Surface **outSurface); 82 Error createPbufferFromClientBuffer(const Config *configuration, 83 EGLenum buftype, 84 EGLClientBuffer clientBuffer, 85 const AttributeMap &attribs, 86 Surface **outSurface); 87 Error createPixmapSurface(const Config *configuration, 88 NativePixmapType nativePixmap, 89 const AttributeMap &attribs, 90 Surface **outSurface); 91 92 Error createImage(const gl::Context *context, 93 EGLenum target, 94 EGLClientBuffer buffer, 95 const AttributeMap &attribs, 96 Image **outImage); 97 98 Error createStream(const AttributeMap &attribs, Stream **outStream); 99 100 Error createContext(const Config *configuration, 101 gl::Context *shareContext, 102 const AttributeMap &attribs, 103 gl::Context **outContext); 104 105 Error makeCurrent(Surface *drawSurface, Surface *readSurface, gl::Context *context); 106 107 Error destroySurface(Surface *surface); 108 void destroyImage(Image *image); 109 void destroyStream(Stream *stream); 110 Error destroyContext(gl::Context *context); 111 112 bool isInitialized() const; 113 bool isValidConfig(const Config *config) const; 114 bool isValidContext(const gl::Context *context) const; 115 bool isValidSurface(const Surface *surface) const; 116 bool isValidImage(const Image *image) const; 117 bool isValidStream(const Stream *stream) const; 118 bool isValidNativeWindow(EGLNativeWindowType window) const; 119 120 Error validateClientBuffer(const Config *configuration, 121 EGLenum buftype, 122 EGLClientBuffer clientBuffer, 123 const AttributeMap &attribs); 124 125 static bool isValidDisplay(const Display *display); 126 static bool isValidNativeDisplay(EGLNativeDisplayType display); 127 static bool hasExistingWindowSurface(EGLNativeWindowType window); 128 129 bool isDeviceLost() const; 130 bool testDeviceLost(); 131 void notifyDeviceLost(); 132 133 Error waitClient(const gl::Context *context) const; 134 Error waitNative(const gl::Context *context, EGLint engine) const; 135 136 const Caps &getCaps() const; 137 138 const DisplayExtensions &getExtensions() const; 139 const std::string &getExtensionString() const; 140 const std::string &getVendorString() const; 141 142 EGLint programCacheGetAttrib(EGLenum attrib) const; 143 Error programCacheQuery(EGLint index, 144 void *key, 145 EGLint *keysize, 146 void *binary, 147 EGLint *binarysize); 148 Error programCachePopulate(const void *key, 149 EGLint keysize, 150 const void *binary, 151 EGLint binarysize); 152 EGLint programCacheResize(EGLint limit, EGLenum mode); 153 getAttributeMap()154 const AttributeMap &getAttributeMap() const { return mAttributeMap; } getNativeDisplayId()155 EGLNativeDisplayType getNativeDisplayId() const { return mDisplayId; } 156 getImplementation()157 rx::DisplayImpl *getImplementation() const { return mImplementation; } 158 Device *getDevice() const; getPlatform()159 EGLenum getPlatform() const { return mPlatform; } 160 161 gl::Version getMaxSupportedESVersion() const; 162 getState()163 const DisplayState &getState() const { return mState; } 164 getProxyContext()165 gl::Context *getProxyContext() const { return mProxyContext.get(); } 166 167 private: 168 Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice); 169 170 void setAttributes(rx::DisplayImpl *impl, const AttributeMap &attribMap); 171 172 Error restoreLostDevice(); 173 174 void initDisplayExtensions(); 175 void initVendorString(); 176 177 DisplayState mState; 178 rx::DisplayImpl *mImplementation; 179 180 EGLNativeDisplayType mDisplayId; 181 AttributeMap mAttributeMap; 182 183 ConfigSet mConfigSet; 184 185 typedef std::set<gl::Context*> ContextSet; 186 ContextSet mContextSet; 187 188 typedef std::set<Image *> ImageSet; 189 ImageSet mImageSet; 190 191 typedef std::set<Stream *> StreamSet; 192 StreamSet mStreamSet; 193 194 bool mInitialized; 195 bool mDeviceLost; 196 197 Caps mCaps; 198 199 DisplayExtensions mDisplayExtensions; 200 std::string mDisplayExtensionString; 201 202 std::string mVendorString; 203 204 Device *mDevice; 205 EGLenum mPlatform; 206 angle::LoggingAnnotator mAnnotator; 207 208 gl::TextureManager *mTextureManager; 209 gl::MemoryProgramCache mMemoryProgramCache; 210 size_t mGlobalTextureShareGroupUsers; 211 212 // This gl::Context is a simple proxy to the Display for the GL back-end entry points 213 // that need access to implementation-specific data, like a Renderer object. 214 angle::UniqueObjectPointer<gl::Context, Display> mProxyContext; 215 }; 216 217 } // namespace egl 218 219 #endif // LIBANGLE_DISPLAY_H_ 220