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 
26 #include <set>
27 
28 namespace egl
29 {
30 	class Surface;
31 	class Context;
32 
33 	const EGLDisplay PRIMARY_DISPLAY = (EGLDisplay)1;
34 	const EGLDisplay HEADLESS_DISPLAY = (EGLDisplay)0xFACE1E55;
35 
36 	class Display
37 	{
38 	public:
39 		static Display *get(EGLDisplay dpy);
40 
41 		bool initialize();
42 		void terminate();
43 
44 		bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig);
45 		bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
46 
47 		EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList);
48 		EGLSurface createPBufferSurface(EGLConfig config, const EGLint *attribList);
49 		EGLContext createContext(EGLConfig configHandle, const Context *shareContext, EGLint clientVersion);
50 		EGLSyncKHR createSync(Context *context);
51 
52 		void destroySurface(Surface *surface);
53 		void destroyContext(Context *context);
54 		void destroySync(FenceSync *sync);
55 
56 		bool isInitialized() const;
57 		bool isValidConfig(EGLConfig config);
58 		bool isValidContext(Context *context);
59 		bool isValidSurface(Surface *surface);
60 		bool isValidWindow(EGLNativeWindowType window);
61 		bool hasExistingWindowSurface(EGLNativeWindowType window);
62 		bool isValidSync(FenceSync *sync);
63 
64 		EGLint getMinSwapInterval() const;
65 		EGLint getMaxSwapInterval() const;
66 
67 		void *getNativeDisplay() const;
68 		const char *getExtensionString() const;
69 
70 	private:
71 		explicit Display(void *nativeDisplay);
72 		~Display();
73 
74 		sw::Format getDisplayFormat() const;
75 
76 		void *const nativeDisplay;
77 
78 		EGLint mMaxSwapInterval;
79 		EGLint mMinSwapInterval;
80 
81 		typedef std::set<Surface*> SurfaceSet;
82 		SurfaceSet mSurfaceSet;
83 
84 		ConfigSet mConfigSet;
85 
86 		typedef std::set<Context*> ContextSet;
87 		ContextSet mContextSet;
88 
89 		typedef std::set<FenceSync*> SyncSet;
90 		sw::BackoffLock mSyncSetMutex;
91 		SyncSet mSyncSet;
92 	};
93 }
94 
95 #endif   // INCLUDE_DISPLAY_H_
96