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