blob: acd639a0691093d343ecbaf9ef3213945917c02a [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// 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"
Nicolas Capens58df2f62016-06-07 14:48:56 -040024#include "common/NameSpace.hpp"
Nicolas Capens0bac2852016-05-07 06:09:58 -040025
26#include <set>
27
28namespace egl
29{
30 class Surface;
31 class Context;
Nicolas Capens58df2f62016-06-07 14:48:56 -040032 class Image;
Nicolas Capens0bac2852016-05-07 06:09:58 -040033
Nicolas Capens99135582016-07-01 23:12:12 -040034 const EGLDisplay PRIMARY_DISPLAY = reinterpret_cast<EGLDisplay>((intptr_t)1);
35 const EGLDisplay HEADLESS_DISPLAY = reinterpret_cast<EGLDisplay>((intptr_t)0xFACE1E55);
Nicolas Capens0bac2852016-05-07 06:09:58 -040036
37 class Display
38 {
39 public:
40 static Display *get(EGLDisplay dpy);
41
42 bool initialize();
43 void terminate();
44
45 bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig);
46 bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
47
48 EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList);
49 EGLSurface createPBufferSurface(EGLConfig config, const EGLint *attribList);
50 EGLContext createContext(EGLConfig configHandle, const Context *shareContext, EGLint clientVersion);
51 EGLSyncKHR createSync(Context *context);
52
53 void destroySurface(Surface *surface);
54 void destroyContext(Context *context);
55 void destroySync(FenceSync *sync);
56
57 bool isInitialized() const;
58 bool isValidConfig(EGLConfig config);
59 bool isValidContext(Context *context);
60 bool isValidSurface(Surface *surface);
61 bool isValidWindow(EGLNativeWindowType window);
62 bool hasExistingWindowSurface(EGLNativeWindowType window);
63 bool isValidSync(FenceSync *sync);
64
65 EGLint getMinSwapInterval() const;
66 EGLint getMaxSwapInterval() const;
67
68 void *getNativeDisplay() const;
Nicolas Capens58df2f62016-06-07 14:48:56 -040069
70 EGLImageKHR createSharedImage(Image *image);
71 bool destroySharedImage(EGLImageKHR);
72 virtual Image *getSharedImage(EGLImageKHR name);
Nicolas Capens0bac2852016-05-07 06:09:58 -040073
74 private:
75 explicit Display(void *nativeDisplay);
76 ~Display();
77
78 sw::Format getDisplayFormat() const;
79
80 void *const nativeDisplay;
81
82 EGLint mMaxSwapInterval;
83 EGLint mMinSwapInterval;
84
85 typedef std::set<Surface*> SurfaceSet;
86 SurfaceSet mSurfaceSet;
87
88 ConfigSet mConfigSet;
89
90 typedef std::set<Context*> ContextSet;
91 ContextSet mContextSet;
92
93 typedef std::set<FenceSync*> SyncSet;
94 SyncSet mSyncSet;
Nicolas Capens58df2f62016-06-07 14:48:56 -040095
96 gl::NameSpace<Image> mSharedImageNameSpace;
Nicolas Capens0bac2852016-05-07 06:09:58 -040097 };
98}
99
100#endif // INCLUDE_DISPLAY_H_