Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
vulkan_surface_pool.h
Go to the documentation of this file.
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_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_POOL_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_POOL_H_
7
8#include <fuchsia/ui/composition/cpp/fidl.h>
9
10#include <unordered_map>
11#include <vector>
12
13#include "flutter/fml/macros.h"
14#include "vulkan_surface.h"
15
16namespace flutter_runner {
17
18class VulkanSurfacePool final {
19 public:
20 // Only keep 12 surfaces at a time. This value was based on how many
21 // surfaces got cached in the old, exact-match-only caching logic.
22 static constexpr int kMaxSurfaces = 12;
23 // If a surface doesn't get used for 3 or more generations, we discard it.
24 static constexpr int kMaxSurfaceAge = 3;
25
28
30
31 std::unique_ptr<VulkanSurface> CreateSurface(const SkISize& size);
32 std::unique_ptr<VulkanSurface> AcquireSurface(const SkISize& size);
33
34 void SubmitSurface(std::unique_ptr<SurfaceProducerSurface> surface);
35
37
38 // Shrink all oversized |VulkanSurfaces| in |available_surfaces_| to as
39 // small as they can be.
40 void ShrinkToFit();
41
42 private:
43 vulkan::VulkanProvider& vulkan_provider_;
45 fuchsia::sysmem::AllocatorSyncPtr sysmem_allocator_;
46 fuchsia::ui::composition::AllocatorPtr flatland_allocator_;
47 std::vector<std::unique_ptr<VulkanSurface>> available_surfaces_;
48 std::unordered_map<uintptr_t, std::unique_ptr<VulkanSurface>>
49 pending_surfaces_;
50
51 size_t trace_surfaces_created_ = 0;
52 size_t trace_surfaces_reused_ = 0;
53
54 std::unique_ptr<VulkanSurface> GetCachedOrCreateSurface(const SkISize& size);
55
56 void RecycleSurface(std::unique_ptr<VulkanSurface> surface);
57
58 void RecyclePendingSurface(uintptr_t surface_key);
59
60 void TraceStats();
61
63};
64
65} // namespace flutter_runner
66
67#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_POOL_H_
std::unique_ptr< VulkanSurface > CreateSurface(const SkISize &size)
void SubmitSurface(std::unique_ptr< SurfaceProducerSurface > surface)
std::unique_ptr< VulkanSurface > AcquireSurface(const SkISize &size)
VkSurfaceKHR surface
Definition main.cc:49
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27