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 "Sync.hpp" 24 #include "Common/RecursiveLock.hpp" 25 #include "common/NameSpace.hpp" 26 27 #include <set> 28 29 #ifndef EGL_ANGLE_iosurface_client_buffer 30 #define EGL_ANGLE_iosurface_client_buffer 1 31 #define EGL_IOSURFACE_ANGLE 0x3454 32 #define EGL_IOSURFACE_PLANE_ANGLE 0x345A 33 #define EGL_TEXTURE_RECTANGLE_ANGLE 0x345B 34 #define EGL_TEXTURE_TYPE_ANGLE 0x345C 35 #define EGL_TEXTURE_INTERNAL_FORMAT_ANGLE 0x345D 36 #define EGL_BIND_TO_TEXTURE_TARGET_ANGLE 0x348D 37 #endif // EGL_ANGLE_iosurface_client_buffer 38 39 namespace egl 40 { 41 class Surface; 42 class Context; 43 class Image; 44 45 const EGLDisplay PRIMARY_DISPLAY = reinterpret_cast<EGLDisplay>((intptr_t)1); 46 const EGLDisplay HEADLESS_DISPLAY = reinterpret_cast<EGLDisplay>((intptr_t)0xFACE1E55); 47 48 class [[clang::lto_visibility_public]] Display 49 { 50 protected: 51 explicit Display(EGLDisplay eglDisplay, void *nativeDisplay); 52 virtual ~Display() = 0; 53 54 public: 55 static Display *get(EGLDisplay dpy); 56 57 bool initialize(); 58 void terminate(); 59 60 bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig); 61 bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value); 62 63 EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLAttrib *attribList); 64 EGLSurface createPBufferSurface(EGLConfig config, const EGLint *attribList, EGLClientBuffer clientBuffer = nullptr); 65 EGLContext createContext(EGLConfig configHandle, const Context *shareContext, EGLint clientVersion); 66 EGLSyncKHR createSync(Context *context); 67 68 void destroySurface(Surface *surface); 69 void destroyContext(Context *context); 70 void destroySync(FenceSync *sync); 71 72 bool isInitialized() const; 73 bool isValidConfig(EGLConfig config); 74 bool isValidContext(Context *context); 75 bool isValidSurface(Surface *surface); 76 bool isValidWindow(EGLNativeWindowType window); 77 bool hasExistingWindowSurface(EGLNativeWindowType window); 78 bool isValidSync(FenceSync *sync); 79 80 EGLint getMinSwapInterval() const; 81 EGLint getMaxSwapInterval() const; 82 83 EGLDisplay getEGLDisplay() const; 84 void *getNativeDisplay() const; 85 86 EGLImageKHR createSharedImage(Image *image); 87 bool destroySharedImage(EGLImageKHR); 88 virtual Image *getSharedImage(EGLImageKHR name) = 0; 89 getLock()90 sw::RecursiveLock *getLock() { return &mApiMutex; } 91 92 private: 93 sw::Format getDisplayFormat() const; 94 95 const EGLDisplay eglDisplay; 96 void *const nativeDisplay; 97 98 EGLint mMaxSwapInterval; 99 EGLint mMinSwapInterval; 100 101 typedef std::set<Surface*> SurfaceSet; 102 SurfaceSet mSurfaceSet; 103 104 ConfigSet mConfigSet; 105 106 typedef std::set<Context*> ContextSet; 107 ContextSet mContextSet; 108 109 typedef std::set<FenceSync*> SyncSet; 110 SyncSet mSyncSet; 111 112 gl::NameSpace<Image> mSharedImageNameSpace; 113 sw::RecursiveLock mApiMutex; 114 }; 115 } 116 117 #endif // INCLUDE_DISPLAY_H_ 118