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 <fuchsia_egl.h>
13 #include <fuchsia_egl_backend.h>
14 #include <zircon/syscalls.h>
15 #include <zircon/syscalls/object.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 fuchsia_egl_window *egl_window = reinterpret_cast<fuchsia_egl_window *>(mNativeWindowType);
40
41 VkImagePipeSurfaceCreateInfoFUCHSIA createInfo = {};
42 createInfo.sType = VK_STRUCTURE_TYPE_IMAGEPIPE_SURFACE_CREATE_INFO_FUCHSIA;
43 createInfo.imagePipeHandle = fuchsia_egl_window_release_image_pipe(egl_window);
44 ANGLE_VK_TRY(context, vkCreateImagePipeSurfaceFUCHSIA(context->getRenderer()->getInstance(),
45 &createInfo, nullptr, &mSurface));
46
47 return getCurrentWindowSize(context, extentsOut);
48 }
49
getCurrentWindowSize(vk::Context * context,gl::Extents * extentsOut)50 angle::Result WindowSurfaceVkFuchsia::getCurrentWindowSize(vk::Context *context,
51 gl::Extents *extentsOut)
52 {
53 fuchsia_egl_window *egl_window = reinterpret_cast<fuchsia_egl_window *>(mNativeWindowType);
54
55 int32_t width = fuchsia_egl_window_get_width(egl_window);
56 int32_t height = fuchsia_egl_window_get_height(egl_window);
57
58 *extentsOut = gl::Extents(width, height, 1);
59
60 return angle::Result::Continue;
61 }
62
63 } // namespace rx
64