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