• 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_info.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::GetANGLEVersionString() << "), ";
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     // The list of supported swapchain formats is available at:
54     // https://cs.android.com/android/platform/superproject/+/master:frameworks/native/vulkan/libvulkan/swapchain.cpp;l=465-486?q=GetNativePixelFormat
55     // TODO (Issue 4062): Add conditional support for GL_RGB10_A2 and GL_RGBA16F when the
56     // Android Vulkan loader adds conditional support for them.
57     const std::array<GLenum, 3> kColorFormats = {GL_RGBA8, GL_RGB8, GL_RGB565};
58 
59     std::vector<GLenum> depthStencilFormats(
60         egl_vk::kConfigDepthStencilFormats,
61         egl_vk::kConfigDepthStencilFormats + ArraySize(egl_vk::kConfigDepthStencilFormats));
62 
63     if (getCaps().stencil8)
64     {
65         depthStencilFormats.push_back(GL_STENCIL_INDEX8);
66     }
67     return egl_vk::GenerateConfigs(kColorFormats.data(), kColorFormats.size(),
68                                    depthStencilFormats.data(), depthStencilFormats.size(), this);
69 }
70 
enableRecordableIfSupported(egl::Config * config)71 void DisplayVkAndroid::enableRecordableIfSupported(egl::Config *config)
72 {
73     // TODO(b/181163023): Determine how to properly query for support. This is a hack to unblock
74     // launching SwANGLE on Cuttlefish.
75     // anglebug.com/6612: This is also required for app compatiblity.
76     config->recordable = true;
77 }
78 
checkConfigSupport(egl::Config * config)79 void DisplayVkAndroid::checkConfigSupport(egl::Config *config)
80 {
81     // TODO(geofflang): Test for native support and modify the config accordingly.
82     // anglebug.com/2692
83 
84     enableRecordableIfSupported(config);
85 }
86 
validateImageClientBuffer(const gl::Context * context,EGLenum target,EGLClientBuffer clientBuffer,const egl::AttributeMap & attribs) const87 egl::Error DisplayVkAndroid::validateImageClientBuffer(const gl::Context *context,
88                                                        EGLenum target,
89                                                        EGLClientBuffer clientBuffer,
90                                                        const egl::AttributeMap &attribs) const
91 {
92     switch (target)
93     {
94         case EGL_NATIVE_BUFFER_ANDROID:
95             return HardwareBufferImageSiblingVkAndroid::ValidateHardwareBuffer(
96                 mRenderer, clientBuffer, attribs);
97 
98         default:
99             return DisplayVk::validateImageClientBuffer(context, target, clientBuffer, attribs);
100     }
101 }
102 
createExternalImageSibling(const gl::Context * context,EGLenum target,EGLClientBuffer buffer,const egl::AttributeMap & attribs)103 ExternalImageSiblingImpl *DisplayVkAndroid::createExternalImageSibling(
104     const gl::Context *context,
105     EGLenum target,
106     EGLClientBuffer buffer,
107     const egl::AttributeMap &attribs)
108 {
109     switch (target)
110     {
111         case EGL_NATIVE_BUFFER_ANDROID:
112             return new HardwareBufferImageSiblingVkAndroid(buffer);
113 
114         default:
115             return DisplayVk::createExternalImageSibling(context, target, buffer, attribs);
116     }
117 }
118 
getWSIExtension() const119 const char *DisplayVkAndroid::getWSIExtension() const
120 {
121     return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
122 }
123 
IsVulkanAndroidDisplayAvailable()124 bool IsVulkanAndroidDisplayAvailable()
125 {
126     return true;
127 }
128 
CreateVulkanAndroidDisplay(const egl::DisplayState & state)129 DisplayImpl *CreateVulkanAndroidDisplay(const egl::DisplayState &state)
130 {
131     return new DisplayVkAndroid(state);
132 }
133 }  // namespace rx
134