xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/vulkan/DisplayVk.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2016 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 // DisplayVk.h:
7*8975f5c5SAndroid Build Coastguard Worker //    Defines the class interface for DisplayVk, implementing DisplayImpl.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker 
10*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_RENDERER_VULKAN_DISPLAYVK_H_
11*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_RENDERER_VULKAN_DISPLAYVK_H_
12*8975f5c5SAndroid Build Coastguard Worker 
13*8975f5c5SAndroid Build Coastguard Worker #include "common/MemoryBuffer.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/DisplayImpl.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/vulkan/vk_cache_utils.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/vulkan/vk_utils.h"
17*8975f5c5SAndroid Build Coastguard Worker 
18*8975f5c5SAndroid Build Coastguard Worker namespace rx
19*8975f5c5SAndroid Build Coastguard Worker {
20*8975f5c5SAndroid Build Coastguard Worker class DisplayVk : public DisplayImpl, public vk::Context, public vk::GlobalOps
21*8975f5c5SAndroid Build Coastguard Worker {
22*8975f5c5SAndroid Build Coastguard Worker   public:
23*8975f5c5SAndroid Build Coastguard Worker     DisplayVk(const egl::DisplayState &state);
24*8975f5c5SAndroid Build Coastguard Worker     ~DisplayVk() override;
25*8975f5c5SAndroid Build Coastguard Worker 
26*8975f5c5SAndroid Build Coastguard Worker     egl::Error initialize(egl::Display *display) override;
27*8975f5c5SAndroid Build Coastguard Worker     void terminate() override;
28*8975f5c5SAndroid Build Coastguard Worker 
29*8975f5c5SAndroid Build Coastguard Worker     egl::Error makeCurrent(egl::Display *display,
30*8975f5c5SAndroid Build Coastguard Worker                            egl::Surface *drawSurface,
31*8975f5c5SAndroid Build Coastguard Worker                            egl::Surface *readSurface,
32*8975f5c5SAndroid Build Coastguard Worker                            gl::Context *context) override;
33*8975f5c5SAndroid Build Coastguard Worker 
34*8975f5c5SAndroid Build Coastguard Worker     bool testDeviceLost() override;
35*8975f5c5SAndroid Build Coastguard Worker     egl::Error restoreLostDevice(const egl::Display *display) override;
36*8975f5c5SAndroid Build Coastguard Worker 
37*8975f5c5SAndroid Build Coastguard Worker     std::string getRendererDescription() override;
38*8975f5c5SAndroid Build Coastguard Worker     std::string getVendorString() override;
39*8975f5c5SAndroid Build Coastguard Worker     std::string getVersionString(bool includeFullVersion) override;
40*8975f5c5SAndroid Build Coastguard Worker 
41*8975f5c5SAndroid Build Coastguard Worker     DeviceImpl *createDevice() override;
42*8975f5c5SAndroid Build Coastguard Worker 
43*8975f5c5SAndroid Build Coastguard Worker     egl::Error waitClient(const gl::Context *context) override;
44*8975f5c5SAndroid Build Coastguard Worker     egl::Error waitNative(const gl::Context *context, EGLint engine) override;
45*8975f5c5SAndroid Build Coastguard Worker 
46*8975f5c5SAndroid Build Coastguard Worker     SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
47*8975f5c5SAndroid Build Coastguard Worker                                      EGLNativeWindowType window,
48*8975f5c5SAndroid Build Coastguard Worker                                      const egl::AttributeMap &attribs) override;
49*8975f5c5SAndroid Build Coastguard Worker     SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
50*8975f5c5SAndroid Build Coastguard Worker                                       const egl::AttributeMap &attribs) override;
51*8975f5c5SAndroid Build Coastguard Worker     SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state,
52*8975f5c5SAndroid Build Coastguard Worker                                                EGLenum buftype,
53*8975f5c5SAndroid Build Coastguard Worker                                                EGLClientBuffer clientBuffer,
54*8975f5c5SAndroid Build Coastguard Worker                                                const egl::AttributeMap &attribs) override;
55*8975f5c5SAndroid Build Coastguard Worker     SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state,
56*8975f5c5SAndroid Build Coastguard Worker                                      NativePixmapType nativePixmap,
57*8975f5c5SAndroid Build Coastguard Worker                                      const egl::AttributeMap &attribs) override;
58*8975f5c5SAndroid Build Coastguard Worker 
59*8975f5c5SAndroid Build Coastguard Worker     ImageImpl *createImage(const egl::ImageState &state,
60*8975f5c5SAndroid Build Coastguard Worker                            const gl::Context *context,
61*8975f5c5SAndroid Build Coastguard Worker                            EGLenum target,
62*8975f5c5SAndroid Build Coastguard Worker                            const egl::AttributeMap &attribs) override;
63*8975f5c5SAndroid Build Coastguard Worker 
64*8975f5c5SAndroid Build Coastguard Worker     ContextImpl *createContext(const gl::State &state,
65*8975f5c5SAndroid Build Coastguard Worker                                gl::ErrorSet *errorSet,
66*8975f5c5SAndroid Build Coastguard Worker                                const egl::Config *configuration,
67*8975f5c5SAndroid Build Coastguard Worker                                const gl::Context *shareContext,
68*8975f5c5SAndroid Build Coastguard Worker                                const egl::AttributeMap &attribs) override;
69*8975f5c5SAndroid Build Coastguard Worker 
70*8975f5c5SAndroid Build Coastguard Worker     StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
71*8975f5c5SAndroid Build Coastguard Worker                                                        const egl::AttributeMap &attribs) override;
72*8975f5c5SAndroid Build Coastguard Worker 
73*8975f5c5SAndroid Build Coastguard Worker     EGLSyncImpl *createSync() override;
74*8975f5c5SAndroid Build Coastguard Worker 
75*8975f5c5SAndroid Build Coastguard Worker     gl::Version getMaxSupportedESVersion() const override;
76*8975f5c5SAndroid Build Coastguard Worker     gl::Version getMaxConformantESVersion() const override;
77*8975f5c5SAndroid Build Coastguard Worker 
78*8975f5c5SAndroid Build Coastguard Worker     egl::Error validateImageClientBuffer(const gl::Context *context,
79*8975f5c5SAndroid Build Coastguard Worker                                          EGLenum target,
80*8975f5c5SAndroid Build Coastguard Worker                                          EGLClientBuffer clientBuffer,
81*8975f5c5SAndroid Build Coastguard Worker                                          const egl::AttributeMap &attribs) const override;
82*8975f5c5SAndroid Build Coastguard Worker     ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context,
83*8975f5c5SAndroid Build Coastguard Worker                                                          EGLenum target,
84*8975f5c5SAndroid Build Coastguard Worker                                                          EGLClientBuffer buffer,
85*8975f5c5SAndroid Build Coastguard Worker                                                          const egl::AttributeMap &attribs) override;
86*8975f5c5SAndroid Build Coastguard Worker     virtual const char *getWSIExtension() const = 0;
87*8975f5c5SAndroid Build Coastguard Worker     virtual const char *getWSILayer() const;
88*8975f5c5SAndroid Build Coastguard Worker 
89*8975f5c5SAndroid Build Coastguard Worker     // Determine if a config with given formats and sample counts is supported.  This callback may
90*8975f5c5SAndroid Build Coastguard Worker     // modify the config to add or remove platform specific attributes such as nativeVisualID.  If
91*8975f5c5SAndroid Build Coastguard Worker     // the config is not supported by the window system, it removes the EGL_WINDOW_BIT from
92*8975f5c5SAndroid Build Coastguard Worker     // surfaceType, which would still allow the config to be used for pbuffers.
93*8975f5c5SAndroid Build Coastguard Worker     virtual void checkConfigSupport(egl::Config *config) = 0;
94*8975f5c5SAndroid Build Coastguard Worker 
getScratchBuffer()95*8975f5c5SAndroid Build Coastguard Worker     angle::ScratchBuffer *getScratchBuffer() { return &mScratchBuffer; }
96*8975f5c5SAndroid Build Coastguard Worker 
97*8975f5c5SAndroid Build Coastguard Worker     void handleError(VkResult result,
98*8975f5c5SAndroid Build Coastguard Worker                      const char *file,
99*8975f5c5SAndroid Build Coastguard Worker                      const char *function,
100*8975f5c5SAndroid Build Coastguard Worker                      unsigned int line) override;
101*8975f5c5SAndroid Build Coastguard Worker 
102*8975f5c5SAndroid Build Coastguard Worker     void initializeFrontendFeatures(angle::FrontendFeatures *features) const override;
103*8975f5c5SAndroid Build Coastguard Worker 
104*8975f5c5SAndroid Build Coastguard Worker     void populateFeatureList(angle::FeatureList *features) override;
105*8975f5c5SAndroid Build Coastguard Worker 
106*8975f5c5SAndroid Build Coastguard Worker     ShareGroupImpl *createShareGroup(const egl::ShareGroupState &state) override;
107*8975f5c5SAndroid Build Coastguard Worker 
108*8975f5c5SAndroid Build Coastguard Worker     bool isConfigFormatSupported(VkFormat format) const;
109*8975f5c5SAndroid Build Coastguard Worker     bool isSurfaceFormatColorspacePairSupported(VkSurfaceKHR surface,
110*8975f5c5SAndroid Build Coastguard Worker                                                 VkFormat format,
111*8975f5c5SAndroid Build Coastguard Worker                                                 VkColorSpaceKHR colorspace) const;
112*8975f5c5SAndroid Build Coastguard Worker 
113*8975f5c5SAndroid Build Coastguard Worker   protected:
114*8975f5c5SAndroid Build Coastguard Worker     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
115*8975f5c5SAndroid Build Coastguard Worker 
116*8975f5c5SAndroid Build Coastguard Worker   private:
117*8975f5c5SAndroid Build Coastguard Worker     virtual SurfaceImpl *createWindowSurfaceVk(const egl::SurfaceState &state,
118*8975f5c5SAndroid Build Coastguard Worker                                                EGLNativeWindowType window) = 0;
119*8975f5c5SAndroid Build Coastguard Worker     void generateCaps(egl::Caps *outCaps) const override;
120*8975f5c5SAndroid Build Coastguard Worker 
121*8975f5c5SAndroid Build Coastguard Worker     virtual angle::Result waitNativeImpl();
122*8975f5c5SAndroid Build Coastguard Worker 
123*8975f5c5SAndroid Build Coastguard Worker     bool isColorspaceSupported(VkColorSpaceKHR colorspace) const;
124*8975f5c5SAndroid Build Coastguard Worker     void initSupportedSurfaceFormatColorspaces();
125*8975f5c5SAndroid Build Coastguard Worker 
126*8975f5c5SAndroid Build Coastguard Worker     // vk::GlobalOps
127*8975f5c5SAndroid Build Coastguard Worker     void putBlob(const angle::BlobCacheKey &key, const angle::MemoryBuffer &value) override;
128*8975f5c5SAndroid Build Coastguard Worker     bool getBlob(const angle::BlobCacheKey &key, angle::BlobCacheValue *valueOut) override;
129*8975f5c5SAndroid Build Coastguard Worker     std::shared_ptr<angle::WaitableEvent> postMultiThreadWorkerTask(
130*8975f5c5SAndroid Build Coastguard Worker         const std::shared_ptr<angle::Closure> &task) override;
131*8975f5c5SAndroid Build Coastguard Worker     void notifyDeviceLost() override;
132*8975f5c5SAndroid Build Coastguard Worker 
133*8975f5c5SAndroid Build Coastguard Worker     angle::ScratchBuffer mScratchBuffer;
134*8975f5c5SAndroid Build Coastguard Worker 
135*8975f5c5SAndroid Build Coastguard Worker     // Map of supported colorspace and associated surface format set.
136*8975f5c5SAndroid Build Coastguard Worker     angle::HashMap<VkColorSpaceKHR, std::unordered_set<VkFormat>> mSupportedColorspaceFormatsMap;
137*8975f5c5SAndroid Build Coastguard Worker };
138*8975f5c5SAndroid Build Coastguard Worker 
139*8975f5c5SAndroid Build Coastguard Worker }  // namespace rx
140*8975f5c5SAndroid Build Coastguard Worker 
141*8975f5c5SAndroid Build Coastguard Worker #endif  // LIBANGLE_RENDERER_VULKAN_DISPLAYVK_H_
142