• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 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 // DisplayVkHeadless.cpp:
7 //    Implements the class methods for DisplayVkHeadless.
8 //
9 
10 #include "DisplayVkHeadless.h"
11 #include "WindowSurfaceVkHeadless.h"
12 
13 #include "libANGLE/Display.h"
14 #include "libANGLE/renderer/vulkan/vk_caps_utils.h"
15 #include "libANGLE/renderer/vulkan/vk_renderer.h"
16 
17 namespace rx
18 {
19 
DisplayVkHeadless(const egl::DisplayState & state)20 DisplayVkHeadless::DisplayVkHeadless(const egl::DisplayState &state) : DisplayVkLinux(state) {}
21 
terminate()22 void DisplayVkHeadless::terminate()
23 {
24     DisplayVk::terminate();
25 }
26 
isValidNativeWindow(EGLNativeWindowType window) const27 bool DisplayVkHeadless::isValidNativeWindow(EGLNativeWindowType window) const
28 {
29     return true;
30 }
31 
createWindowSurfaceVk(const egl::SurfaceState & state,EGLNativeWindowType window)32 SurfaceImpl *DisplayVkHeadless::createWindowSurfaceVk(const egl::SurfaceState &state,
33                                                       EGLNativeWindowType window)
34 {
35     return new WindowSurfaceVkHeadless(state, window);
36 }
37 
generateConfigs()38 egl::ConfigSet DisplayVkHeadless::generateConfigs()
39 {
40     std::vector<GLenum> kColorFormats;
41     std::vector<GLenum> kDesiredColorFormats = {GL_RGBA8, GL_BGRA8_EXT, GL_RGB565, GL_RGB8,
42                                                 GL_RGB10_A2};
43 
44     for (GLenum glFormat : kDesiredColorFormats)
45     {
46         VkFormat vkFormat =
47             mRenderer->getFormat(glFormat).getActualRenderableImageVkFormat(mRenderer);
48         ASSERT(vkFormat != VK_FORMAT_UNDEFINED);
49 
50         angle::FormatID actualFormatID = vk::GetFormatIDFromVkFormat(vkFormat);
51 
52         if (mRenderer->hasImageFormatFeatureBits(
53                 actualFormatID, VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT |
54                                     VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
55                                     VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT |
56                                     VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
57                                     VK_FORMAT_FEATURE_TRANSFER_DST_BIT))
58         {
59             // If VK_GOOGLE_surfaceless_query is present, additionally check the surface
60             // capabilities with this format.  If the extension is not supported, advertise the
61             // format anyway and hope for the best.
62             if (getFeatures().supportsSurfacelessQueryExtension.enabled &&
63                 !isConfigFormatSupported(vkFormat))
64             {
65                 continue;
66             }
67 
68             kColorFormats.push_back(glFormat);
69         }
70     }
71 
72     return egl_vk::GenerateConfigs(kColorFormats.data(), kColorFormats.size(),
73                                    egl_vk::kConfigDepthStencilFormats,
74                                    ArraySize(egl_vk::kConfigDepthStencilFormats), this);
75 }
76 
checkConfigSupport(egl::Config * config)77 void DisplayVkHeadless::checkConfigSupport(egl::Config *config) {}
78 
getWSIExtension() const79 const char *DisplayVkHeadless::getWSIExtension() const
80 {
81     return VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME;
82 }
83 
IsVulkanHeadlessDisplayAvailable()84 bool IsVulkanHeadlessDisplayAvailable()
85 {
86     return true;
87 }
88 
CreateVulkanHeadlessDisplay(const egl::DisplayState & state)89 DisplayImpl *CreateVulkanHeadlessDisplay(const egl::DisplayState &state)
90 {
91     return new DisplayVkHeadless(state);
92 }
93 
94 }  // namespace rx
95