• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 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 // DisplayVkAndroid.cpp:
7 //    Implements the class methods for DisplayVkAndroid.
8 //
9 
10 #include "libANGLE/renderer/vulkan/android/DisplayVkAndroid.h"
11 
12 #include <android/log.h>
13 #include <android/native_window.h>
14 #include <vulkan/vulkan.h>
15 
16 #include "common/angle_version.h"
17 #include "libANGLE/renderer/driver_utils.h"
18 #include "libANGLE/renderer/vulkan/RendererVk.h"
19 #include "libANGLE/renderer/vulkan/android/HardwareBufferImageSiblingVkAndroid.h"
20 #include "libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.h"
21 #include "libANGLE/renderer/vulkan/vk_caps_utils.h"
22 
23 namespace rx
24 {
25 
DisplayVkAndroid(const egl::DisplayState & state)26 DisplayVkAndroid::DisplayVkAndroid(const egl::DisplayState &state) : DisplayVk(state) {}
27 
initialize(egl::Display * display)28 egl::Error DisplayVkAndroid::initialize(egl::Display *display)
29 {
30     ANGLE_TRY(DisplayVk::initialize(display));
31 
32     std::stringstream strstr;
33     strstr << "Version (" << ANGLE_VERSION_STRING << "), ";
34     strstr << "Renderer (" << mRenderer->getRendererDescription() << ")";
35     __android_log_print(ANDROID_LOG_INFO, "ANGLE", "%s", strstr.str().c_str());
36 
37     return egl::NoError();
38 }
39 
isValidNativeWindow(EGLNativeWindowType window) const40 bool DisplayVkAndroid::isValidNativeWindow(EGLNativeWindowType window) const
41 {
42     return (ANativeWindow_getFormat(window) >= 0);
43 }
44 
createWindowSurfaceVk(const egl::SurfaceState & state,EGLNativeWindowType window)45 SurfaceImpl *DisplayVkAndroid::createWindowSurfaceVk(const egl::SurfaceState &state,
46                                                      EGLNativeWindowType window)
47 {
48     return new WindowSurfaceVkAndroid(state, window);
49 }
50 
generateConfigs()51 egl::ConfigSet DisplayVkAndroid::generateConfigs()
52 {
53     // TODO (Issue 4062): Add conditional support for GL_RGB10_A2 and GL_RGBA16F when the
54     // Android Vulkan loader adds conditional support for them.
55     const std::array<GLenum, 3> kColorFormats = {GL_RGBA8, GL_RGB8, GL_RGB565};
56 
57     std::vector<GLenum> depthStencilFormats(
58         egl_vk::kConfigDepthStencilFormats,
59         egl_vk::kConfigDepthStencilFormats + ArraySize(egl_vk::kConfigDepthStencilFormats));
60 
61     if (getCaps().stencil8)
62     {
63         depthStencilFormats.push_back(GL_STENCIL_INDEX8);
64     }
65     return egl_vk::GenerateConfigs(kColorFormats.data(), kColorFormats.size(),
66                                    depthStencilFormats.data(), depthStencilFormats.size(), this);
67 }
68 
enableRecordableIfSupported(egl::Config * config)69 void DisplayVkAndroid::enableRecordableIfSupported(egl::Config *config)
70 {
71     const VkPhysicalDeviceProperties &physicalDeviceProperties =
72         getRenderer()->getPhysicalDeviceProperties();
73 
74     // TODO(b/181163023): Determine how to properly query for support. This is a hack to unblock
75     // launching SwANGLE on Cuttlefish.
76     bool isSwiftShader =
77         IsSwiftshader(physicalDeviceProperties.vendorID, physicalDeviceProperties.deviceID);
78 
79     if (isSwiftShader)
80     {
81         config->recordable = true;
82     }
83 }
84 
checkConfigSupport(egl::Config * config)85 void DisplayVkAndroid::checkConfigSupport(egl::Config *config)
86 {
87     // TODO(geofflang): Test for native support and modify the config accordingly.
88     // anglebug.com/2692
89 
90     enableRecordableIfSupported(config);
91 }
92 
validateImageClientBuffer(const gl::Context * context,EGLenum target,EGLClientBuffer clientBuffer,const egl::AttributeMap & attribs) const93 egl::Error DisplayVkAndroid::validateImageClientBuffer(const gl::Context *context,
94                                                        EGLenum target,
95                                                        EGLClientBuffer clientBuffer,
96                                                        const egl::AttributeMap &attribs) const
97 {
98     switch (target)
99     {
100         case EGL_NATIVE_BUFFER_ANDROID:
101             return HardwareBufferImageSiblingVkAndroid::ValidateHardwareBuffer(mRenderer,
102                                                                                clientBuffer);
103 
104         default:
105             return DisplayVk::validateImageClientBuffer(context, target, clientBuffer, attribs);
106     }
107 }
108 
createExternalImageSibling(const gl::Context * context,EGLenum target,EGLClientBuffer buffer,const egl::AttributeMap & attribs)109 ExternalImageSiblingImpl *DisplayVkAndroid::createExternalImageSibling(
110     const gl::Context *context,
111     EGLenum target,
112     EGLClientBuffer buffer,
113     const egl::AttributeMap &attribs)
114 {
115     switch (target)
116     {
117         case EGL_NATIVE_BUFFER_ANDROID:
118             return new HardwareBufferImageSiblingVkAndroid(buffer);
119 
120         default:
121             return DisplayVk::createExternalImageSibling(context, target, buffer, attribs);
122     }
123 }
124 
getWSIExtension() const125 const char *DisplayVkAndroid::getWSIExtension() const
126 {
127     return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
128 }
129 
IsVulkanAndroidDisplayAvailable()130 bool IsVulkanAndroidDisplayAvailable()
131 {
132     return true;
133 }
134 
CreateVulkanAndroidDisplay(const egl::DisplayState & state)135 DisplayImpl *CreateVulkanAndroidDisplay(const egl::DisplayState &state)
136 {
137     return new DisplayVkAndroid(state);
138 }
139 }  // namespace rx
140