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 78 egl::Error validateImageClientBuffer(const gl::Context *context, 79 EGLenum target, 80 EGLClientBuffer clientBuffer, 81 const egl::AttributeMap &attribs) const override; 82 ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context, 83 EGLenum target, 84 EGLClientBuffer buffer, 85 const egl::AttributeMap &attribs) override; 86 virtual const char *getWSIExtension() const = 0; 87 virtual const char *getWSILayer() const; 88 89 // Determine if a config with given formats and sample counts is supported. This callback may 90 // modify the config to add or remove platform specific attributes such as nativeVisualID. If 91 // the config is not supported by the window system, it removes the EGL_WINDOW_BIT from 92 // surfaceType, which would still allow the config to be used for pbuffers. 93 virtual void checkConfigSupport(egl::Config *config) = 0; 94 getScratchBuffer()95 angle::ScratchBuffer *getScratchBuffer() { return &mScratchBuffer; } 96 97 void handleError(VkResult result, 98 const char *file, 99 const char *function, 100 unsigned int line) override; 101 102 void initializeFrontendFeatures(angle::FrontendFeatures *features) const override; 103 104 void populateFeatureList(angle::FeatureList *features) override; 105 106 ShareGroupImpl *createShareGroup(const egl::ShareGroupState &state) override; 107 108 bool isConfigFormatSupported(VkFormat format) const; 109 bool isSurfaceFormatColorspacePairSupported(VkSurfaceKHR surface, 110 VkFormat format, 111 VkColorSpaceKHR colorspace) const; 112 113 protected: 114 void generateExtensions(egl::DisplayExtensions *outExtensions) const override; 115 116 private: 117 virtual SurfaceImpl *createWindowSurfaceVk(const egl::SurfaceState &state, 118 EGLNativeWindowType window) = 0; 119 void generateCaps(egl::Caps *outCaps) const override; 120 121 virtual angle::Result waitNativeImpl(); 122 123 bool isColorspaceSupported(VkColorSpaceKHR colorspace) const; 124 void initSupportedSurfaceFormatColorspaces(); 125 126 // vk::GlobalOps 127 void putBlob(const angle::BlobCacheKey &key, const angle::MemoryBuffer &value) override; 128 bool getBlob(const angle::BlobCacheKey &key, angle::BlobCacheValue *valueOut) override; 129 std::shared_ptr<angle::WaitableEvent> postMultiThreadWorkerTask( 130 const std::shared_ptr<angle::Closure> &task) override; 131 void notifyDeviceLost() override; 132 133 angle::ScratchBuffer mScratchBuffer; 134 135 // Map of supported colorspace and associated surface format set. 136 angle::HashMap<VkColorSpaceKHR, std::unordered_set<VkFormat>> mSupportedColorspaceFormatsMap; 137 }; 138 139 } // namespace rx 140 141 #endif // LIBANGLE_RENDERER_VULKAN_DISPLAYVK_H_ 142