• 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/version.h"
17 #include "libANGLE/renderer/vulkan/RendererVk.h"
18 #include "libANGLE/renderer/vulkan/android/HardwareBufferImageSiblingVkAndroid.h"
19 #include "libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.h"
20 #include "libANGLE/renderer/vulkan/vk_caps_utils.h"
21 
22 namespace rx
23 {
24 
DisplayVkAndroid(const egl::DisplayState & state)25 DisplayVkAndroid::DisplayVkAndroid(const egl::DisplayState &state) : DisplayVk(state) {}
26 
initialize(egl::Display * display)27 egl::Error DisplayVkAndroid::initialize(egl::Display *display)
28 {
29     ANGLE_TRY(DisplayVk::initialize(display));
30 
31     std::stringstream strstr;
32     strstr << "Version (" << ANGLE_VERSION_STRING << "), ";
33     strstr << "Renderer (" << mRenderer->getRendererDescription() << ")";
34     __android_log_print(ANDROID_LOG_INFO, "ANGLE", "%s", strstr.str().c_str());
35 
36     return egl::NoError();
37 }
38 
isValidNativeWindow(EGLNativeWindowType window) const39 bool DisplayVkAndroid::isValidNativeWindow(EGLNativeWindowType window) const
40 {
41     return (ANativeWindow_getFormat(window) >= 0);
42 }
43 
createWindowSurfaceVk(const egl::SurfaceState & state,EGLNativeWindowType window)44 SurfaceImpl *DisplayVkAndroid::createWindowSurfaceVk(const egl::SurfaceState &state,
45                                                      EGLNativeWindowType window)
46 {
47     return new WindowSurfaceVkAndroid(state, window);
48 }
49 
generateConfigs()50 egl::ConfigSet DisplayVkAndroid::generateConfigs()
51 {
52     // TODO (Issue 4062): Add conditional support for GL_RGB10_A2 and GL_RGBA16F when the
53     // Android Vulkan loader adds conditional support for them.
54     constexpr GLenum kColorFormats[] = {GL_RGBA8, GL_RGB8, GL_RGB565};
55     return egl_vk::GenerateConfigs(kColorFormats, egl_vk::kConfigDepthStencilFormats, this);
56 }
57 
checkConfigSupport(egl::Config * config)58 bool DisplayVkAndroid::checkConfigSupport(egl::Config *config)
59 {
60     // TODO(geofflang): Test for native support and modify the config accordingly.
61     // anglebug.com/2692
62     return true;
63 }
64 
validateImageClientBuffer(const gl::Context * context,EGLenum target,EGLClientBuffer clientBuffer,const egl::AttributeMap & attribs) const65 egl::Error DisplayVkAndroid::validateImageClientBuffer(const gl::Context *context,
66                                                        EGLenum target,
67                                                        EGLClientBuffer clientBuffer,
68                                                        const egl::AttributeMap &attribs) const
69 {
70     switch (target)
71     {
72         case EGL_NATIVE_BUFFER_ANDROID:
73             return HardwareBufferImageSiblingVkAndroid::ValidateHardwareBuffer(mRenderer,
74                                                                                clientBuffer);
75 
76         default:
77             return DisplayVk::validateImageClientBuffer(context, target, clientBuffer, attribs);
78     }
79 }
80 
createExternalImageSibling(const gl::Context * context,EGLenum target,EGLClientBuffer buffer,const egl::AttributeMap & attribs)81 ExternalImageSiblingImpl *DisplayVkAndroid::createExternalImageSibling(
82     const gl::Context *context,
83     EGLenum target,
84     EGLClientBuffer buffer,
85     const egl::AttributeMap &attribs)
86 {
87     switch (target)
88     {
89         case EGL_NATIVE_BUFFER_ANDROID:
90             return new HardwareBufferImageSiblingVkAndroid(buffer);
91 
92         default:
93             return DisplayVk::createExternalImageSibling(context, target, buffer, attribs);
94     }
95 }
96 
getWSIExtension() const97 const char *DisplayVkAndroid::getWSIExtension() const
98 {
99     return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
100 }
101 
IsVulkanAndroidDisplayAvailable()102 bool IsVulkanAndroidDisplayAvailable()
103 {
104     return true;
105 }
106 
CreateVulkanAndroidDisplay(const egl::DisplayState & state)107 DisplayImpl *CreateVulkanAndroidDisplay(const egl::DisplayState &state)
108 {
109     return new DisplayVkAndroid(state);
110 }
111 }  // namespace rx
112