1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_VULKAN_VULKAN_WINDOW_H_
6#define FLUTTER_VULKAN_VULKAN_WINDOW_H_
7
8#include <memory>
9#include <tuple>
10#include <utility>
11#include <vector>
12
13#include "flutter/fml/compiler_specific.h"
14#include "flutter/fml/macros.h"
15#include "flutter/vulkan/procs/vulkan_proc_table.h"
16#include "third_party/skia/include/core/SkRefCnt.h"
17#include "third_party/skia/include/core/SkSize.h"
18#include "third_party/skia/include/core/SkSurface.h"
19#include "third_party/skia/include/gpu/GrDirectContext.h"
20#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
21
22namespace vulkan {
23
24class VulkanNativeSurface;
25class VulkanDevice;
26class VulkanSurface;
27class VulkanSwapchain;
28class VulkanImage;
29class VulkanApplication;
30class VulkanBackbuffer;
31
32class VulkanWindow {
33 public:
34 //------------------------------------------------------------------------------
35 /// @brief Construct a VulkanWindow. Let it implicitly create a
36 /// GrDirectContext.
37 ///
38 VulkanWindow(fml::RefPtr<VulkanProcTable> proc_table,
39 std::unique_ptr<VulkanNativeSurface> native_surface);
40
41 //------------------------------------------------------------------------------
42 /// @brief Construct a VulkanWindow. Let reuse an existing
43 /// GrDirectContext built by another VulkanWindow.
44 ///
45 VulkanWindow(const sk_sp<GrDirectContext>& context,
46 fml::RefPtr<VulkanProcTable> proc_table,
47 std::unique_ptr<VulkanNativeSurface> native_surface);
48
49 ~VulkanWindow();
50
51 bool IsValid() const;
52
53 GrDirectContext* GetSkiaGrContext();
54
55 sk_sp<SkSurface> AcquireSurface();
56
57 bool SwapBuffers();
58
59 private:
60 bool valid_;
61 fml::RefPtr<VulkanProcTable> vk;
62 std::unique_ptr<VulkanApplication> application_;
63 std::unique_ptr<VulkanDevice> logical_device_;
64 std::unique_ptr<VulkanSurface> surface_;
65 std::unique_ptr<VulkanSwapchain> swapchain_;
66 sk_sp<skgpu::VulkanMemoryAllocator> memory_allocator_;
67 sk_sp<GrDirectContext> skia_gr_context_;
68
69 bool CreateSkiaGrContext();
70
71 bool CreateSkiaBackendContext(GrVkBackendContext* context);
72
73 [[nodiscard]] bool RecreateSwapchain();
74
75 FML_DISALLOW_COPY_AND_ASSIGN(VulkanWindow);
76};
77
78} // namespace vulkan
79
80#endif // FLUTTER_VULKAN_VULKAN_WINDOW_H_
81

source code of flutter_engine/flutter/vulkan/vulkan_window.h