1 //
2 // Copyright 2019 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 // WindowSurfaceVkFuchsia.cpp:
7 // Implements methods from WindowSurfaceVkFuchsia.
8 //
9
10 #include "libANGLE/renderer/vulkan/fuchsia/WindowSurfaceVkFuchsia.h"
11
12 #include <zircon/syscalls.h>
13 #include <zircon/syscalls/object.h>
14 #include "common/fuchsia_egl/fuchsia_egl.h"
15 #include "common/fuchsia_egl/fuchsia_egl_backend.h"
16
17 #include "libANGLE/renderer/vulkan/RendererVk.h"
18 #include "libANGLE/renderer/vulkan/vk_utils.h"
19
20 namespace rx
21 {
22
WindowSurfaceVkFuchsia(const egl::SurfaceState & surfaceState,EGLNativeWindowType window)23 WindowSurfaceVkFuchsia::WindowSurfaceVkFuchsia(const egl::SurfaceState &surfaceState,
24 EGLNativeWindowType window)
25 : WindowSurfaceVk(surfaceState, window)
26 {}
27
~WindowSurfaceVkFuchsia()28 WindowSurfaceVkFuchsia::~WindowSurfaceVkFuchsia() {}
29
30 // static
isValidNativeWindow(EGLNativeWindowType window)31 bool WindowSurfaceVkFuchsia::isValidNativeWindow(EGLNativeWindowType window)
32 {
33 fuchsia_egl_window *egl_window = reinterpret_cast<fuchsia_egl_window *>(window);
34 return fuchsia_egl_window_get_width(egl_window) >= 0;
35 }
36
createSurfaceVk(vk::Context * context,gl::Extents * extentsOut)37 angle::Result WindowSurfaceVkFuchsia::createSurfaceVk(vk::Context *context, gl::Extents *extentsOut)
38 {
39 #if !defined(ANGLE_SHARED_LIBVULKAN)
40 InitImagePipeSurfaceFUCHSIAFunctions(context->getRenderer()->getInstance());
41 #endif // !defined(ANGLE_SHARED_LIBVULKAN)
42 fuchsia_egl_window *egl_window = reinterpret_cast<fuchsia_egl_window *>(mNativeWindowType);
43
44 VkImagePipeSurfaceCreateInfoFUCHSIA createInfo = {};
45 createInfo.sType = VK_STRUCTURE_TYPE_IMAGEPIPE_SURFACE_CREATE_INFO_FUCHSIA;
46 createInfo.imagePipeHandle = fuchsia_egl_window_release_image_pipe(egl_window);
47 ANGLE_VK_TRY(context, vkCreateImagePipeSurfaceFUCHSIA(context->getRenderer()->getInstance(),
48 &createInfo, nullptr, &mSurface));
49
50 return getCurrentWindowSize(context, extentsOut);
51 }
52
getCurrentWindowSize(vk::Context * context,gl::Extents * extentsOut)53 angle::Result WindowSurfaceVkFuchsia::getCurrentWindowSize(vk::Context *context,
54 gl::Extents *extentsOut)
55 {
56 fuchsia_egl_window *egl_window = reinterpret_cast<fuchsia_egl_window *>(mNativeWindowType);
57
58 int32_t width = fuchsia_egl_window_get_width(egl_window);
59 int32_t height = fuchsia_egl_window_get_height(egl_window);
60
61 *extentsOut = gl::Extents(width, height, 1);
62
63 return angle::Result::Continue;
64 }
65
66 } // namespace rx
67