1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Display.h: Defines the egl::Display class, representing the abstract 16 // display on which graphics are drawn. Implements EGLDisplay. 17 // [EGL 1.4] section 2.1.2 page 3. 18 19 #ifndef INCLUDE_DISPLAY_H_ 20 #define INCLUDE_DISPLAY_H_ 21 22 #include "Config.h" 23 #include "Common/MutexLock.hpp" 24 #include "Sync.hpp" 25 #include "common/NameSpace.hpp" 26 27 #include <set> 28 29 namespace egl 30 { 31 class Surface; 32 class Context; 33 class Image; 34 35 const EGLDisplay PRIMARY_DISPLAY = reinterpret_cast<EGLDisplay>((intptr_t)1); 36 const EGLDisplay HEADLESS_DISPLAY = reinterpret_cast<EGLDisplay>((intptr_t)0xFACE1E55); 37 38 class [[clang::lto_visibility_public]] Display 39 { 40 protected: 41 explicit Display(EGLDisplay eglDisplay, void *nativeDisplay); 42 virtual ~Display() = 0; 43 44 public: 45 static Display *get(EGLDisplay dpy); 46 47 bool initialize(); 48 void terminate(); 49 50 bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig); 51 bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value); 52 53 EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList); 54 EGLSurface createPBufferSurface(EGLConfig config, const EGLint *attribList); 55 EGLContext createContext(EGLConfig configHandle, const Context *shareContext, EGLint clientVersion); 56 EGLSyncKHR createSync(Context *context); 57 58 void destroySurface(Surface *surface); 59 void destroyContext(Context *context); 60 void destroySync(FenceSync *sync); 61 62 bool isInitialized() const; 63 bool isValidConfig(EGLConfig config); 64 bool isValidContext(Context *context); 65 bool isValidSurface(Surface *surface); 66 bool isValidWindow(EGLNativeWindowType window); 67 bool hasExistingWindowSurface(EGLNativeWindowType window); 68 bool isValidSync(FenceSync *sync); 69 70 EGLint getMinSwapInterval() const; 71 EGLint getMaxSwapInterval() const; 72 73 EGLDisplay getEGLDisplay() const; 74 void *getNativeDisplay() const; 75 76 EGLImageKHR createSharedImage(Image *image); 77 bool destroySharedImage(EGLImageKHR); 78 virtual Image *getSharedImage(EGLImageKHR name) = 0; 79 80 private: 81 sw::Format getDisplayFormat() const; 82 83 const EGLDisplay eglDisplay; 84 void *const nativeDisplay; 85 86 EGLint mMaxSwapInterval; 87 EGLint mMinSwapInterval; 88 89 typedef std::set<Surface*> SurfaceSet; 90 SurfaceSet mSurfaceSet; 91 92 ConfigSet mConfigSet; 93 94 typedef std::set<Context*> ContextSet; 95 ContextSet mContextSet; 96 97 typedef std::set<FenceSync*> SyncSet; 98 sw::MutexLock mSyncSetMutex; 99 SyncSet mSyncSet; 100 101 gl::NameSpace<Image> mSharedImageNameSpace; 102 }; 103 } 104 105 #endif // INCLUDE_DISPLAY_H_ 106