| 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 "third_party/skia/include/core/SkRefCnt.h" |
| 16 | #include "third_party/skia/include/core/SkSize.h" |
| 17 | #include "third_party/skia/include/core/SkSurface.h" |
| 18 | #include "third_party/skia/include/gpu/GrDirectContext.h" |
| 19 | #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" |
| 20 | #include "vulkan_proc_table.h" |
| 21 | |
| 22 | namespace vulkan { |
| 23 | |
| 24 | class VulkanNativeSurface; |
| 25 | class VulkanDevice; |
| 26 | class VulkanSurface; |
| 27 | class VulkanSwapchain; |
| 28 | class VulkanImage; |
| 29 | class VulkanApplication; |
| 30 | class VulkanBackbuffer; |
| 31 | |
| 32 | class VulkanWindow { |
| 33 | public: |
| 34 | VulkanWindow(fml::RefPtr<VulkanProcTable> proc_table, |
| 35 | std::unique_ptr<VulkanNativeSurface> native_surface, |
| 36 | bool render_to_surface); |
| 37 | |
| 38 | ~VulkanWindow(); |
| 39 | |
| 40 | bool IsValid() const; |
| 41 | |
| 42 | GrDirectContext* GetSkiaGrContext(); |
| 43 | |
| 44 | sk_sp<SkSurface> AcquireSurface(); |
| 45 | |
| 46 | bool SwapBuffers(); |
| 47 | |
| 48 | private: |
| 49 | bool valid_; |
| 50 | fml::RefPtr<VulkanProcTable> vk; |
| 51 | std::unique_ptr<VulkanApplication> application_; |
| 52 | std::unique_ptr<VulkanDevice> logical_device_; |
| 53 | std::unique_ptr<VulkanSurface> surface_; |
| 54 | std::unique_ptr<VulkanSwapchain> swapchain_; |
| 55 | sk_sp<GrDirectContext> skia_gr_context_; |
| 56 | |
| 57 | bool CreateSkiaGrContext(); |
| 58 | |
| 59 | bool CreateSkiaBackendContext(GrVkBackendContext* context); |
| 60 | |
| 61 | [[nodiscard]] bool RecreateSwapchain(); |
| 62 | |
| 63 | FML_DISALLOW_COPY_AND_ASSIGN(VulkanWindow); |
| 64 | }; |
| 65 | |
| 66 | } // namespace vulkan |
| 67 | |
| 68 | #endif // FLUTTER_VULKAN_VULKAN_WINDOW_H_ |
| 69 |