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