xref: /aosp_15_r20/external/angle/src/libANGLE/Display.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker // Display.h: Defines the egl::Display class, representing the abstract
8*8975f5c5SAndroid Build Coastguard Worker // display on which graphics are drawn. Implements EGLDisplay.
9*8975f5c5SAndroid Build Coastguard Worker // [EGL 1.4] section 2.1.2 page 3.
10*8975f5c5SAndroid Build Coastguard Worker 
11*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_DISPLAY_H_
12*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_DISPLAY_H_
13*8975f5c5SAndroid Build Coastguard Worker 
14*8975f5c5SAndroid Build Coastguard Worker #include <mutex>
15*8975f5c5SAndroid Build Coastguard Worker #include <vector>
16*8975f5c5SAndroid Build Coastguard Worker 
17*8975f5c5SAndroid Build Coastguard Worker #include "common/SimpleMutex.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "common/WorkerThread.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "common/platform.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/AttributeMap.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/BlobCache.h"
22*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Caps.h"
23*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Config.h"
24*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Context.h"
25*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Debug.h"
26*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Error.h"
27*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/LoggingAnnotator.h"
28*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/MemoryProgramCache.h"
29*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/MemoryShaderCache.h"
30*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Observer.h"
31*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/ShareGroup.h"
32*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Version.h"
33*8975f5c5SAndroid Build Coastguard Worker #include "platform/Feature.h"
34*8975f5c5SAndroid Build Coastguard Worker #include "platform/autogen/FrontendFeatures_autogen.h"
35*8975f5c5SAndroid Build Coastguard Worker 
36*8975f5c5SAndroid Build Coastguard Worker // Only DisplayCGL needs to be notified about an EGL call about to be made to prepare
37*8975f5c5SAndroid Build Coastguard Worker // per-thread data. Disable Display::prepareForCall on other platforms for performance.
38*8975f5c5SAndroid Build Coastguard Worker #if !defined(ANGLE_USE_DISPLAY_PREPARE_FOR_CALL)
39*8975f5c5SAndroid Build Coastguard Worker #    if ANGLE_ENABLE_CGL
40*8975f5c5SAndroid Build Coastguard Worker #        define ANGLE_USE_DISPLAY_PREPARE_FOR_CALL 1
41*8975f5c5SAndroid Build Coastguard Worker #    else
42*8975f5c5SAndroid Build Coastguard Worker #        define ANGLE_USE_DISPLAY_PREPARE_FOR_CALL 0
43*8975f5c5SAndroid Build Coastguard Worker #    endif
44*8975f5c5SAndroid Build Coastguard Worker #endif
45*8975f5c5SAndroid Build Coastguard Worker 
46*8975f5c5SAndroid Build Coastguard Worker namespace angle
47*8975f5c5SAndroid Build Coastguard Worker {
48*8975f5c5SAndroid Build Coastguard Worker class FrameCaptureShared;
49*8975f5c5SAndroid Build Coastguard Worker }  // namespace angle
50*8975f5c5SAndroid Build Coastguard Worker 
51*8975f5c5SAndroid Build Coastguard Worker namespace gl
52*8975f5c5SAndroid Build Coastguard Worker {
53*8975f5c5SAndroid Build Coastguard Worker class Context;
54*8975f5c5SAndroid Build Coastguard Worker class TextureManager;
55*8975f5c5SAndroid Build Coastguard Worker class SemaphoreManager;
56*8975f5c5SAndroid Build Coastguard Worker }  // namespace gl
57*8975f5c5SAndroid Build Coastguard Worker 
58*8975f5c5SAndroid Build Coastguard Worker namespace rx
59*8975f5c5SAndroid Build Coastguard Worker {
60*8975f5c5SAndroid Build Coastguard Worker class DisplayImpl;
61*8975f5c5SAndroid Build Coastguard Worker class EGLImplFactory;
62*8975f5c5SAndroid Build Coastguard Worker }  // namespace rx
63*8975f5c5SAndroid Build Coastguard Worker 
64*8975f5c5SAndroid Build Coastguard Worker namespace egl
65*8975f5c5SAndroid Build Coastguard Worker {
66*8975f5c5SAndroid Build Coastguard Worker class Device;
67*8975f5c5SAndroid Build Coastguard Worker class Image;
68*8975f5c5SAndroid Build Coastguard Worker class Stream;
69*8975f5c5SAndroid Build Coastguard Worker class Surface;
70*8975f5c5SAndroid Build Coastguard Worker class Sync;
71*8975f5c5SAndroid Build Coastguard Worker class Thread;
72*8975f5c5SAndroid Build Coastguard Worker 
73*8975f5c5SAndroid Build Coastguard Worker using SurfaceMap = angle::HashMap<GLuint, Surface *>;
74*8975f5c5SAndroid Build Coastguard Worker using ThreadSet  = angle::HashSet<Thread *>;
75*8975f5c5SAndroid Build Coastguard Worker 
76*8975f5c5SAndroid Build Coastguard Worker struct DisplayState final : private angle::NonCopyable
77*8975f5c5SAndroid Build Coastguard Worker {
78*8975f5c5SAndroid Build Coastguard Worker     DisplayState(EGLNativeDisplayType nativeDisplayId);
79*8975f5c5SAndroid Build Coastguard Worker     ~DisplayState();
80*8975f5c5SAndroid Build Coastguard Worker 
81*8975f5c5SAndroid Build Coastguard Worker     void notifyDeviceLost() const;
82*8975f5c5SAndroid Build Coastguard Worker 
83*8975f5c5SAndroid Build Coastguard Worker     EGLLabelKHR label;
84*8975f5c5SAndroid Build Coastguard Worker     ContextMap contextMap;
85*8975f5c5SAndroid Build Coastguard Worker     mutable angle::SimpleMutex contextMapMutex;
86*8975f5c5SAndroid Build Coastguard Worker     SurfaceMap surfaceMap;
87*8975f5c5SAndroid Build Coastguard Worker     angle::FeatureOverrides featureOverrides;
88*8975f5c5SAndroid Build Coastguard Worker     EGLNativeDisplayType displayId;
89*8975f5c5SAndroid Build Coastguard Worker 
90*8975f5c5SAndroid Build Coastguard Worker     // Single-threaded and multithread pools for use by various parts of ANGLE, such as shader
91*8975f5c5SAndroid Build Coastguard Worker     // compilation.  These pools are internally synchronized.
92*8975f5c5SAndroid Build Coastguard Worker     std::shared_ptr<angle::WorkerThreadPool> singleThreadPool;
93*8975f5c5SAndroid Build Coastguard Worker     std::shared_ptr<angle::WorkerThreadPool> multiThreadPool;
94*8975f5c5SAndroid Build Coastguard Worker 
95*8975f5c5SAndroid Build Coastguard Worker     mutable bool deviceLost;
96*8975f5c5SAndroid Build Coastguard Worker };
97*8975f5c5SAndroid Build Coastguard Worker 
98*8975f5c5SAndroid Build Coastguard Worker // Constant coded here as a reasonable limit.
99*8975f5c5SAndroid Build Coastguard Worker constexpr EGLAttrib kProgramCacheSizeAbsoluteMax = 0x4000000;
100*8975f5c5SAndroid Build Coastguard Worker 
101*8975f5c5SAndroid Build Coastguard Worker using ImageMap  = angle::HashMap<GLuint, Image *>;
102*8975f5c5SAndroid Build Coastguard Worker using StreamSet = angle::HashSet<Stream *>;
103*8975f5c5SAndroid Build Coastguard Worker using SyncMap   = angle::HashMap<GLuint, std::unique_ptr<Sync>>;
104*8975f5c5SAndroid Build Coastguard Worker 
105*8975f5c5SAndroid Build Coastguard Worker class Display final : public LabeledObject,
106*8975f5c5SAndroid Build Coastguard Worker                       public angle::ObserverInterface,
107*8975f5c5SAndroid Build Coastguard Worker                       public angle::NonCopyable
108*8975f5c5SAndroid Build Coastguard Worker {
109*8975f5c5SAndroid Build Coastguard Worker   public:
110*8975f5c5SAndroid Build Coastguard Worker     ~Display() override;
111*8975f5c5SAndroid Build Coastguard Worker 
112*8975f5c5SAndroid Build Coastguard Worker     void setLabel(EGLLabelKHR label) override;
113*8975f5c5SAndroid Build Coastguard Worker     EGLLabelKHR getLabel() const override;
114*8975f5c5SAndroid Build Coastguard Worker 
115*8975f5c5SAndroid Build Coastguard Worker     // Observer implementation.
116*8975f5c5SAndroid Build Coastguard Worker     void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
117*8975f5c5SAndroid Build Coastguard Worker 
118*8975f5c5SAndroid Build Coastguard Worker     Error initialize();
119*8975f5c5SAndroid Build Coastguard Worker 
120*8975f5c5SAndroid Build Coastguard Worker     enum class TerminateReason
121*8975f5c5SAndroid Build Coastguard Worker     {
122*8975f5c5SAndroid Build Coastguard Worker         Api,
123*8975f5c5SAndroid Build Coastguard Worker         InternalCleanup,
124*8975f5c5SAndroid Build Coastguard Worker 
125*8975f5c5SAndroid Build Coastguard Worker         InvalidEnum,
126*8975f5c5SAndroid Build Coastguard Worker         EnumCount = InvalidEnum,
127*8975f5c5SAndroid Build Coastguard Worker     };
128*8975f5c5SAndroid Build Coastguard Worker     Error terminate(Thread *thread, TerminateReason terminateReason);
129*8975f5c5SAndroid Build Coastguard Worker 
130*8975f5c5SAndroid Build Coastguard Worker #if ANGLE_USE_DISPLAY_PREPARE_FOR_CALL
131*8975f5c5SAndroid Build Coastguard Worker     // Called before all display state dependent EGL functions. Backends can set up, for example,
132*8975f5c5SAndroid Build Coastguard Worker     // thread-specific backend state through this function. Not called for functions that do not
133*8975f5c5SAndroid Build Coastguard Worker     // need the state.
134*8975f5c5SAndroid Build Coastguard Worker     Error prepareForCall();
135*8975f5c5SAndroid Build Coastguard Worker #endif
136*8975f5c5SAndroid Build Coastguard Worker 
137*8975f5c5SAndroid Build Coastguard Worker     // Called on eglReleaseThread. Backends can tear down thread-specific backend state through
138*8975f5c5SAndroid Build Coastguard Worker     // this function.
139*8975f5c5SAndroid Build Coastguard Worker     Error releaseThread();
140*8975f5c5SAndroid Build Coastguard Worker 
141*8975f5c5SAndroid Build Coastguard Worker     static Display *GetDisplayFromDevice(Device *device, const AttributeMap &attribMap);
142*8975f5c5SAndroid Build Coastguard Worker     static Display *GetDisplayFromNativeDisplay(EGLenum platform,
143*8975f5c5SAndroid Build Coastguard Worker                                                 EGLNativeDisplayType nativeDisplay,
144*8975f5c5SAndroid Build Coastguard Worker                                                 const AttributeMap &attribMap);
145*8975f5c5SAndroid Build Coastguard Worker     static Display *GetExistingDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay);
146*8975f5c5SAndroid Build Coastguard Worker 
147*8975f5c5SAndroid Build Coastguard Worker     using EglDisplaySet = angle::HashSet<Display *>;
148*8975f5c5SAndroid Build Coastguard Worker 
149*8975f5c5SAndroid Build Coastguard Worker     static const ClientExtensions &GetClientExtensions();
150*8975f5c5SAndroid Build Coastguard Worker     static const std::string &GetClientExtensionString();
151*8975f5c5SAndroid Build Coastguard Worker 
152*8975f5c5SAndroid Build Coastguard Worker     std::vector<const Config *> getConfigs(const AttributeMap &attribs) const;
153*8975f5c5SAndroid Build Coastguard Worker     std::vector<const Config *> chooseConfig(const AttributeMap &attribs) const;
154*8975f5c5SAndroid Build Coastguard Worker 
155*8975f5c5SAndroid Build Coastguard Worker     Error createWindowSurface(const Config *configuration,
156*8975f5c5SAndroid Build Coastguard Worker                               EGLNativeWindowType window,
157*8975f5c5SAndroid Build Coastguard Worker                               const AttributeMap &attribs,
158*8975f5c5SAndroid Build Coastguard Worker                               Surface **outSurface);
159*8975f5c5SAndroid Build Coastguard Worker     Error createPbufferSurface(const Config *configuration,
160*8975f5c5SAndroid Build Coastguard Worker                                const AttributeMap &attribs,
161*8975f5c5SAndroid Build Coastguard Worker                                Surface **outSurface);
162*8975f5c5SAndroid Build Coastguard Worker     Error createPbufferFromClientBuffer(const Config *configuration,
163*8975f5c5SAndroid Build Coastguard Worker                                         EGLenum buftype,
164*8975f5c5SAndroid Build Coastguard Worker                                         EGLClientBuffer clientBuffer,
165*8975f5c5SAndroid Build Coastguard Worker                                         const AttributeMap &attribs,
166*8975f5c5SAndroid Build Coastguard Worker                                         Surface **outSurface);
167*8975f5c5SAndroid Build Coastguard Worker     Error createPixmapSurface(const Config *configuration,
168*8975f5c5SAndroid Build Coastguard Worker                               NativePixmapType nativePixmap,
169*8975f5c5SAndroid Build Coastguard Worker                               const AttributeMap &attribs,
170*8975f5c5SAndroid Build Coastguard Worker                               Surface **outSurface);
171*8975f5c5SAndroid Build Coastguard Worker 
172*8975f5c5SAndroid Build Coastguard Worker     Error createImage(const gl::Context *context,
173*8975f5c5SAndroid Build Coastguard Worker                       EGLenum target,
174*8975f5c5SAndroid Build Coastguard Worker                       EGLClientBuffer buffer,
175*8975f5c5SAndroid Build Coastguard Worker                       const AttributeMap &attribs,
176*8975f5c5SAndroid Build Coastguard Worker                       Image **outImage);
177*8975f5c5SAndroid Build Coastguard Worker 
178*8975f5c5SAndroid Build Coastguard Worker     Error createStream(const AttributeMap &attribs, Stream **outStream);
179*8975f5c5SAndroid Build Coastguard Worker 
180*8975f5c5SAndroid Build Coastguard Worker     Error createContext(const Config *configuration,
181*8975f5c5SAndroid Build Coastguard Worker                         gl::Context *shareContext,
182*8975f5c5SAndroid Build Coastguard Worker                         const AttributeMap &attribs,
183*8975f5c5SAndroid Build Coastguard Worker                         gl::Context **outContext);
184*8975f5c5SAndroid Build Coastguard Worker 
185*8975f5c5SAndroid Build Coastguard Worker     Error createSync(const gl::Context *currentContext,
186*8975f5c5SAndroid Build Coastguard Worker                      EGLenum type,
187*8975f5c5SAndroid Build Coastguard Worker                      const AttributeMap &attribs,
188*8975f5c5SAndroid Build Coastguard Worker                      Sync **outSync);
189*8975f5c5SAndroid Build Coastguard Worker 
190*8975f5c5SAndroid Build Coastguard Worker     Error makeCurrent(Thread *thread,
191*8975f5c5SAndroid Build Coastguard Worker                       gl::Context *previousContext,
192*8975f5c5SAndroid Build Coastguard Worker                       Surface *drawSurface,
193*8975f5c5SAndroid Build Coastguard Worker                       Surface *readSurface,
194*8975f5c5SAndroid Build Coastguard Worker                       gl::Context *context);
195*8975f5c5SAndroid Build Coastguard Worker 
196*8975f5c5SAndroid Build Coastguard Worker     Error destroySurface(Surface *surface);
197*8975f5c5SAndroid Build Coastguard Worker     void destroyImage(Image *image);
198*8975f5c5SAndroid Build Coastguard Worker     void destroyStream(Stream *stream);
199*8975f5c5SAndroid Build Coastguard Worker     Error destroyContext(Thread *thread, gl::Context *context);
200*8975f5c5SAndroid Build Coastguard Worker 
201*8975f5c5SAndroid Build Coastguard Worker     void destroySync(Sync *sync);
202*8975f5c5SAndroid Build Coastguard Worker 
203*8975f5c5SAndroid Build Coastguard Worker     bool isInitialized() const;
204*8975f5c5SAndroid Build Coastguard Worker     bool isValidConfig(const Config *config) const;
205*8975f5c5SAndroid Build Coastguard Worker     bool isValidContext(gl::ContextID contextID) const;
206*8975f5c5SAndroid Build Coastguard Worker     bool isValidSurface(SurfaceID surfaceID) const;
207*8975f5c5SAndroid Build Coastguard Worker     bool isValidImage(ImageID imageID) const;
208*8975f5c5SAndroid Build Coastguard Worker     bool isValidStream(const Stream *stream) const;
209*8975f5c5SAndroid Build Coastguard Worker     bool isValidSync(SyncID sync) const;
210*8975f5c5SAndroid Build Coastguard Worker     bool isValidNativeWindow(EGLNativeWindowType window) const;
211*8975f5c5SAndroid Build Coastguard Worker 
212*8975f5c5SAndroid Build Coastguard Worker     Error validateClientBuffer(const Config *configuration,
213*8975f5c5SAndroid Build Coastguard Worker                                EGLenum buftype,
214*8975f5c5SAndroid Build Coastguard Worker                                EGLClientBuffer clientBuffer,
215*8975f5c5SAndroid Build Coastguard Worker                                const AttributeMap &attribs) const;
216*8975f5c5SAndroid Build Coastguard Worker     Error validateImageClientBuffer(const gl::Context *context,
217*8975f5c5SAndroid Build Coastguard Worker                                     EGLenum target,
218*8975f5c5SAndroid Build Coastguard Worker                                     EGLClientBuffer clientBuffer,
219*8975f5c5SAndroid Build Coastguard Worker                                     const egl::AttributeMap &attribs) const;
220*8975f5c5SAndroid Build Coastguard Worker     Error valdiatePixmap(const Config *config,
221*8975f5c5SAndroid Build Coastguard Worker                          EGLNativePixmapType pixmap,
222*8975f5c5SAndroid Build Coastguard Worker                          const AttributeMap &attributes) const;
223*8975f5c5SAndroid Build Coastguard Worker 
224*8975f5c5SAndroid Build Coastguard Worker     static bool isValidDisplay(const Display *display);
225*8975f5c5SAndroid Build Coastguard Worker     static bool isValidNativeDisplay(EGLNativeDisplayType display);
226*8975f5c5SAndroid Build Coastguard Worker     static bool hasExistingWindowSurface(EGLNativeWindowType window);
227*8975f5c5SAndroid Build Coastguard Worker 
228*8975f5c5SAndroid Build Coastguard Worker     bool isDeviceLost() const;
229*8975f5c5SAndroid Build Coastguard Worker     bool testDeviceLost();
230*8975f5c5SAndroid Build Coastguard Worker     void notifyDeviceLost();
231*8975f5c5SAndroid Build Coastguard Worker 
232*8975f5c5SAndroid Build Coastguard Worker     void setBlobCacheFuncs(EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
areBlobCacheFuncsSet()233*8975f5c5SAndroid Build Coastguard Worker     bool areBlobCacheFuncsSet() const { return mBlobCache.areBlobCacheFuncsSet(); }
getBlobCache()234*8975f5c5SAndroid Build Coastguard Worker     BlobCache &getBlobCache() { return mBlobCache; }
235*8975f5c5SAndroid Build Coastguard Worker 
236*8975f5c5SAndroid Build Coastguard Worker     static EGLClientBuffer GetNativeClientBuffer(const struct AHardwareBuffer *buffer);
237*8975f5c5SAndroid Build Coastguard Worker     static Error CreateNativeClientBuffer(const egl::AttributeMap &attribMap,
238*8975f5c5SAndroid Build Coastguard Worker                                           EGLClientBuffer *eglClientBuffer);
239*8975f5c5SAndroid Build Coastguard Worker 
240*8975f5c5SAndroid Build Coastguard Worker     Error waitClient(const gl::Context *context);
241*8975f5c5SAndroid Build Coastguard Worker     Error waitNative(const gl::Context *context, EGLint engine);
242*8975f5c5SAndroid Build Coastguard Worker 
243*8975f5c5SAndroid Build Coastguard Worker     const Caps &getCaps() const;
244*8975f5c5SAndroid Build Coastguard Worker 
245*8975f5c5SAndroid Build Coastguard Worker     const DisplayExtensions &getExtensions() const;
246*8975f5c5SAndroid Build Coastguard Worker     const std::string &getExtensionString() const;
247*8975f5c5SAndroid Build Coastguard Worker     const std::string &getVendorString() const;
248*8975f5c5SAndroid Build Coastguard Worker     const std::string &getVersionString() const;
249*8975f5c5SAndroid Build Coastguard Worker     const std::string &getClientAPIString() const;
250*8975f5c5SAndroid Build Coastguard Worker 
251*8975f5c5SAndroid Build Coastguard Worker     std::string getBackendRendererDescription() const;
252*8975f5c5SAndroid Build Coastguard Worker     std::string getBackendVendorString() const;
253*8975f5c5SAndroid Build Coastguard Worker     std::string getBackendVersionString(bool includeFullVersion) const;
254*8975f5c5SAndroid Build Coastguard Worker 
255*8975f5c5SAndroid Build Coastguard Worker     EGLint programCacheGetAttrib(EGLenum attrib) const;
256*8975f5c5SAndroid Build Coastguard Worker     Error programCacheQuery(EGLint index,
257*8975f5c5SAndroid Build Coastguard Worker                             void *key,
258*8975f5c5SAndroid Build Coastguard Worker                             EGLint *keysize,
259*8975f5c5SAndroid Build Coastguard Worker                             void *binary,
260*8975f5c5SAndroid Build Coastguard Worker                             EGLint *binarysize);
261*8975f5c5SAndroid Build Coastguard Worker     Error programCachePopulate(const void *key,
262*8975f5c5SAndroid Build Coastguard Worker                                EGLint keysize,
263*8975f5c5SAndroid Build Coastguard Worker                                const void *binary,
264*8975f5c5SAndroid Build Coastguard Worker                                EGLint binarysize);
265*8975f5c5SAndroid Build Coastguard Worker     EGLint programCacheResize(EGLint limit, EGLenum mode);
266*8975f5c5SAndroid Build Coastguard Worker 
getAttributeMap()267*8975f5c5SAndroid Build Coastguard Worker     const AttributeMap &getAttributeMap() const { return mAttributeMap; }
getNativeDisplayId()268*8975f5c5SAndroid Build Coastguard Worker     EGLNativeDisplayType getNativeDisplayId() const { return mState.displayId; }
269*8975f5c5SAndroid Build Coastguard Worker 
getImplementation()270*8975f5c5SAndroid Build Coastguard Worker     rx::DisplayImpl *getImplementation() const { return mImplementation; }
271*8975f5c5SAndroid Build Coastguard Worker     Device *getDevice() const;
272*8975f5c5SAndroid Build Coastguard Worker     Surface *getWGLSurface() const;
getPlatform()273*8975f5c5SAndroid Build Coastguard Worker     EGLenum getPlatform() const { return mPlatform; }
274*8975f5c5SAndroid Build Coastguard Worker 
275*8975f5c5SAndroid Build Coastguard Worker     gl::Version getMaxSupportedESVersion() const;
276*8975f5c5SAndroid Build Coastguard Worker 
getState()277*8975f5c5SAndroid Build Coastguard Worker     const DisplayState &getState() const { return mState; }
278*8975f5c5SAndroid Build Coastguard Worker 
getFrontendFeatures()279*8975f5c5SAndroid Build Coastguard Worker     const angle::FrontendFeatures &getFrontendFeatures() { return mFrontendFeatures; }
280*8975f5c5SAndroid Build Coastguard Worker     void overrideFrontendFeatures(const std::vector<std::string> &featureNames, bool enabled);
281*8975f5c5SAndroid Build Coastguard Worker 
getFeatures()282*8975f5c5SAndroid Build Coastguard Worker     const angle::FeatureList &getFeatures() const { return mFeatures; }
283*8975f5c5SAndroid Build Coastguard Worker 
284*8975f5c5SAndroid Build Coastguard Worker     const char *queryStringi(const EGLint name, const EGLint index);
285*8975f5c5SAndroid Build Coastguard Worker 
286*8975f5c5SAndroid Build Coastguard Worker     EGLAttrib queryAttrib(const EGLint attribute);
287*8975f5c5SAndroid Build Coastguard Worker 
288*8975f5c5SAndroid Build Coastguard Worker     angle::ScratchBuffer requestScratchBuffer();
289*8975f5c5SAndroid Build Coastguard Worker     void returnScratchBuffer(angle::ScratchBuffer scratchBuffer);
290*8975f5c5SAndroid Build Coastguard Worker 
291*8975f5c5SAndroid Build Coastguard Worker     angle::ScratchBuffer requestZeroFilledBuffer();
292*8975f5c5SAndroid Build Coastguard Worker     void returnZeroFilledBuffer(angle::ScratchBuffer zeroFilledBuffer);
293*8975f5c5SAndroid Build Coastguard Worker 
294*8975f5c5SAndroid Build Coastguard Worker     egl::Error handleGPUSwitch();
295*8975f5c5SAndroid Build Coastguard Worker     egl::Error forceGPUSwitch(EGLint gpuIDHigh, EGLint gpuIDLow);
296*8975f5c5SAndroid Build Coastguard Worker 
297*8975f5c5SAndroid Build Coastguard Worker     egl::Error waitUntilWorkScheduled();
298*8975f5c5SAndroid Build Coastguard Worker 
getDisplayGlobalMutex()299*8975f5c5SAndroid Build Coastguard Worker     angle::SimpleMutex &getDisplayGlobalMutex() { return mDisplayGlobalMutex; }
getProgramCacheMutex()300*8975f5c5SAndroid Build Coastguard Worker     angle::SimpleMutex &getProgramCacheMutex() { return mProgramCacheMutex; }
301*8975f5c5SAndroid Build Coastguard Worker 
getMemoryShaderCache()302*8975f5c5SAndroid Build Coastguard Worker     gl::MemoryShaderCache *getMemoryShaderCache() { return &mMemoryShaderCache; }
303*8975f5c5SAndroid Build Coastguard Worker 
304*8975f5c5SAndroid Build Coastguard Worker     // Installs LoggingAnnotator as the global DebugAnnotator, for back-ends that do not implement
305*8975f5c5SAndroid Build Coastguard Worker     // their own DebugAnnotator.
setGlobalDebugAnnotator()306*8975f5c5SAndroid Build Coastguard Worker     void setGlobalDebugAnnotator() { gl::InitializeDebugAnnotations(&mAnnotator); }
307*8975f5c5SAndroid Build Coastguard Worker 
308*8975f5c5SAndroid Build Coastguard Worker     bool supportsDmaBufFormat(EGLint format) const;
309*8975f5c5SAndroid Build Coastguard Worker     Error queryDmaBufFormats(EGLint max_formats, EGLint *formats, EGLint *num_formats);
310*8975f5c5SAndroid Build Coastguard Worker     Error queryDmaBufModifiers(EGLint format,
311*8975f5c5SAndroid Build Coastguard Worker                                EGLint max_modifiers,
312*8975f5c5SAndroid Build Coastguard Worker                                EGLuint64KHR *modifiers,
313*8975f5c5SAndroid Build Coastguard Worker                                EGLBoolean *external_only,
314*8975f5c5SAndroid Build Coastguard Worker                                EGLint *num_modifiers);
315*8975f5c5SAndroid Build Coastguard Worker 
getSingleThreadPool()316*8975f5c5SAndroid Build Coastguard Worker     std::shared_ptr<angle::WorkerThreadPool> getSingleThreadPool() const
317*8975f5c5SAndroid Build Coastguard Worker     {
318*8975f5c5SAndroid Build Coastguard Worker         return mState.singleThreadPool;
319*8975f5c5SAndroid Build Coastguard Worker     }
getMultiThreadPool()320*8975f5c5SAndroid Build Coastguard Worker     std::shared_ptr<angle::WorkerThreadPool> getMultiThreadPool() const
321*8975f5c5SAndroid Build Coastguard Worker     {
322*8975f5c5SAndroid Build Coastguard Worker         return mState.multiThreadPool;
323*8975f5c5SAndroid Build Coastguard Worker     }
324*8975f5c5SAndroid Build Coastguard Worker 
325*8975f5c5SAndroid Build Coastguard Worker     angle::ImageLoadContext getImageLoadContext() const;
326*8975f5c5SAndroid Build Coastguard Worker 
327*8975f5c5SAndroid Build Coastguard Worker     const gl::Context *getContext(gl::ContextID contextID) const;
328*8975f5c5SAndroid Build Coastguard Worker     const egl::Surface *getSurface(egl::SurfaceID surfaceID) const;
329*8975f5c5SAndroid Build Coastguard Worker     const egl::Image *getImage(egl::ImageID imageID) const;
330*8975f5c5SAndroid Build Coastguard Worker     const egl::Sync *getSync(egl::SyncID syncID) const;
331*8975f5c5SAndroid Build Coastguard Worker     gl::Context *getContext(gl::ContextID contextID);
332*8975f5c5SAndroid Build Coastguard Worker     egl::Surface *getSurface(egl::SurfaceID surfaceID);
333*8975f5c5SAndroid Build Coastguard Worker     egl::Image *getImage(egl::ImageID imageID);
334*8975f5c5SAndroid Build Coastguard Worker     egl::Sync *getSync(egl::SyncID syncID);
335*8975f5c5SAndroid Build Coastguard Worker 
getSyncsForCapture()336*8975f5c5SAndroid Build Coastguard Worker     const SyncMap &getSyncsForCapture() const { return mSyncMap; }
getImagesForCapture()337*8975f5c5SAndroid Build Coastguard Worker     const ImageMap &getImagesForCapture() const { return mImageMap; }
338*8975f5c5SAndroid Build Coastguard Worker 
339*8975f5c5SAndroid Build Coastguard Worker     // Initialize thread-local variables used by the Display and its backing implementations.  This
340*8975f5c5SAndroid Build Coastguard Worker     // includes:
341*8975f5c5SAndroid Build Coastguard Worker     //
342*8975f5c5SAndroid Build Coastguard Worker     // - The unlocked tail call to be run at the end of the entry point.
343*8975f5c5SAndroid Build Coastguard Worker     // - Scratch space for an egl::Error used by the backends (this is not used by all backends, and
344*8975f5c5SAndroid Build Coastguard Worker     //   access *must* be restricted to backends that use it).
345*8975f5c5SAndroid Build Coastguard Worker     //
346*8975f5c5SAndroid Build Coastguard Worker     static void InitTLS();
347*8975f5c5SAndroid Build Coastguard Worker     static angle::UnlockedTailCall *GetCurrentThreadUnlockedTailCall();
348*8975f5c5SAndroid Build Coastguard Worker     static Error *GetCurrentThreadErrorScratchSpace();
349*8975f5c5SAndroid Build Coastguard Worker 
350*8975f5c5SAndroid Build Coastguard Worker   private:
351*8975f5c5SAndroid Build Coastguard Worker     Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice);
352*8975f5c5SAndroid Build Coastguard Worker 
setAttributes(const AttributeMap & attribMap)353*8975f5c5SAndroid Build Coastguard Worker     void setAttributes(const AttributeMap &attribMap) { mAttributeMap = attribMap; }
354*8975f5c5SAndroid Build Coastguard Worker     void setupDisplayPlatform(rx::DisplayImpl *impl);
355*8975f5c5SAndroid Build Coastguard Worker 
356*8975f5c5SAndroid Build Coastguard Worker     Error restoreLostDevice();
357*8975f5c5SAndroid Build Coastguard Worker     Error releaseContext(gl::Context *context, Thread *thread);
358*8975f5c5SAndroid Build Coastguard Worker     Error releaseContextImpl(std::unique_ptr<gl::Context> &&context);
359*8975f5c5SAndroid Build Coastguard Worker     std::unique_ptr<gl::Context> eraseContextImpl(gl::Context *context, ContextMap *contexts);
360*8975f5c5SAndroid Build Coastguard Worker 
361*8975f5c5SAndroid Build Coastguard Worker     void initDisplayExtensions();
362*8975f5c5SAndroid Build Coastguard Worker     void initVendorString();
363*8975f5c5SAndroid Build Coastguard Worker     void initVersionString();
364*8975f5c5SAndroid Build Coastguard Worker     void initClientAPIString();
365*8975f5c5SAndroid Build Coastguard Worker     void initializeFrontendFeatures();
366*8975f5c5SAndroid Build Coastguard Worker 
367*8975f5c5SAndroid Build Coastguard Worker     angle::ScratchBuffer requestScratchBufferImpl(std::vector<angle::ScratchBuffer> *bufferVector);
368*8975f5c5SAndroid Build Coastguard Worker     void returnScratchBufferImpl(angle::ScratchBuffer scratchBuffer,
369*8975f5c5SAndroid Build Coastguard Worker                                  std::vector<angle::ScratchBuffer> *bufferVector);
370*8975f5c5SAndroid Build Coastguard Worker 
371*8975f5c5SAndroid Build Coastguard Worker     Error destroyInvalidEglObjects();
372*8975f5c5SAndroid Build Coastguard Worker 
373*8975f5c5SAndroid Build Coastguard Worker     DisplayState mState;
374*8975f5c5SAndroid Build Coastguard Worker     rx::DisplayImpl *mImplementation;
375*8975f5c5SAndroid Build Coastguard Worker     angle::ObserverBinding mGPUSwitchedBinding;
376*8975f5c5SAndroid Build Coastguard Worker 
377*8975f5c5SAndroid Build Coastguard Worker     AttributeMap mAttributeMap;
378*8975f5c5SAndroid Build Coastguard Worker 
379*8975f5c5SAndroid Build Coastguard Worker     ConfigSet mConfigSet;
380*8975f5c5SAndroid Build Coastguard Worker 
381*8975f5c5SAndroid Build Coastguard Worker     ImageMap mImageMap;
382*8975f5c5SAndroid Build Coastguard Worker     StreamSet mStreamSet;
383*8975f5c5SAndroid Build Coastguard Worker 
384*8975f5c5SAndroid Build Coastguard Worker     SyncMap mSyncMap;
385*8975f5c5SAndroid Build Coastguard Worker 
386*8975f5c5SAndroid Build Coastguard Worker     static constexpr size_t kMaxSyncPoolSizePerType = 32;
387*8975f5c5SAndroid Build Coastguard Worker     using SyncPool = angle::FixedVector<std::unique_ptr<Sync>, kMaxSyncPoolSizePerType>;
388*8975f5c5SAndroid Build Coastguard Worker     std::map<EGLenum, SyncPool> mSyncPools;
389*8975f5c5SAndroid Build Coastguard Worker 
390*8975f5c5SAndroid Build Coastguard Worker     void destroyImageImpl(Image *image, ImageMap *images);
391*8975f5c5SAndroid Build Coastguard Worker     void destroyStreamImpl(Stream *stream, StreamSet *streams);
392*8975f5c5SAndroid Build Coastguard Worker     Error destroySurfaceImpl(Surface *surface, SurfaceMap *surfaces);
393*8975f5c5SAndroid Build Coastguard Worker     void destroySyncImpl(SyncID syncId, SyncMap *syncs);
394*8975f5c5SAndroid Build Coastguard Worker 
395*8975f5c5SAndroid Build Coastguard Worker     ContextMap mInvalidContextMap;
396*8975f5c5SAndroid Build Coastguard Worker     ImageMap mInvalidImageMap;
397*8975f5c5SAndroid Build Coastguard Worker     StreamSet mInvalidStreamSet;
398*8975f5c5SAndroid Build Coastguard Worker     SurfaceMap mInvalidSurfaceMap;
399*8975f5c5SAndroid Build Coastguard Worker     SyncMap mInvalidSyncMap;
400*8975f5c5SAndroid Build Coastguard Worker 
401*8975f5c5SAndroid Build Coastguard Worker     bool mInitialized;
402*8975f5c5SAndroid Build Coastguard Worker 
403*8975f5c5SAndroid Build Coastguard Worker     Caps mCaps;
404*8975f5c5SAndroid Build Coastguard Worker 
405*8975f5c5SAndroid Build Coastguard Worker     DisplayExtensions mDisplayExtensions;
406*8975f5c5SAndroid Build Coastguard Worker     std::string mDisplayExtensionString;
407*8975f5c5SAndroid Build Coastguard Worker 
408*8975f5c5SAndroid Build Coastguard Worker     std::string mVendorString;
409*8975f5c5SAndroid Build Coastguard Worker     std::string mVersionString;
410*8975f5c5SAndroid Build Coastguard Worker     std::string mClientAPIString;
411*8975f5c5SAndroid Build Coastguard Worker 
412*8975f5c5SAndroid Build Coastguard Worker     Device *mDevice;
413*8975f5c5SAndroid Build Coastguard Worker     Surface *mSurface;
414*8975f5c5SAndroid Build Coastguard Worker     EGLenum mPlatform;
415*8975f5c5SAndroid Build Coastguard Worker     angle::LoggingAnnotator mAnnotator;
416*8975f5c5SAndroid Build Coastguard Worker 
417*8975f5c5SAndroid Build Coastguard Worker     // mManagersMutex protects mTextureManager and mSemaphoreManager
418*8975f5c5SAndroid Build Coastguard Worker     ContextMutex *mManagersMutex;
419*8975f5c5SAndroid Build Coastguard Worker     gl::TextureManager *mTextureManager;
420*8975f5c5SAndroid Build Coastguard Worker     gl::SemaphoreManager *mSemaphoreManager;
421*8975f5c5SAndroid Build Coastguard Worker 
422*8975f5c5SAndroid Build Coastguard Worker     BlobCache mBlobCache;
423*8975f5c5SAndroid Build Coastguard Worker     gl::MemoryProgramCache mMemoryProgramCache;
424*8975f5c5SAndroid Build Coastguard Worker     gl::MemoryShaderCache mMemoryShaderCache;
425*8975f5c5SAndroid Build Coastguard Worker     size_t mGlobalTextureShareGroupUsers;
426*8975f5c5SAndroid Build Coastguard Worker     size_t mGlobalSemaphoreShareGroupUsers;
427*8975f5c5SAndroid Build Coastguard Worker 
428*8975f5c5SAndroid Build Coastguard Worker     gl::HandleAllocator mImageHandleAllocator;
429*8975f5c5SAndroid Build Coastguard Worker     gl::HandleAllocator mSurfaceHandleAllocator;
430*8975f5c5SAndroid Build Coastguard Worker     gl::HandleAllocator mSyncHandleAllocator;
431*8975f5c5SAndroid Build Coastguard Worker 
432*8975f5c5SAndroid Build Coastguard Worker     angle::FrontendFeatures mFrontendFeatures;
433*8975f5c5SAndroid Build Coastguard Worker 
434*8975f5c5SAndroid Build Coastguard Worker     angle::FeatureList mFeatures;
435*8975f5c5SAndroid Build Coastguard Worker 
436*8975f5c5SAndroid Build Coastguard Worker     angle::SimpleMutex mScratchBufferMutex;
437*8975f5c5SAndroid Build Coastguard Worker     std::vector<angle::ScratchBuffer> mScratchBuffers;
438*8975f5c5SAndroid Build Coastguard Worker     std::vector<angle::ScratchBuffer> mZeroFilledBuffers;
439*8975f5c5SAndroid Build Coastguard Worker 
440*8975f5c5SAndroid Build Coastguard Worker     angle::SimpleMutex mDisplayGlobalMutex;
441*8975f5c5SAndroid Build Coastguard Worker     angle::SimpleMutex mProgramCacheMutex;
442*8975f5c5SAndroid Build Coastguard Worker 
443*8975f5c5SAndroid Build Coastguard Worker     bool mTerminatedByApi;
444*8975f5c5SAndroid Build Coastguard Worker };
445*8975f5c5SAndroid Build Coastguard Worker 
446*8975f5c5SAndroid Build Coastguard Worker }  // namespace egl
447*8975f5c5SAndroid Build Coastguard Worker 
448*8975f5c5SAndroid Build Coastguard Worker #endif  // LIBANGLE_DISPLAY_H_
449