forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvulkan_surface_pool.h
77 lines (58 loc) · 2.16 KB
/
vulkan_surface_pool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <list>
#include <unordered_map>
#include "flutter/content_handler/vulkan_surface.h"
#include "lib/fxl/macros.h"
namespace flutter_runner {
class VulkanSurfacePool {
public:
static const size_t kMaxSurfacesOfSameSize = 3;
static const size_t kMaxSurfaceAge = 3;
VulkanSurfacePool(vulkan::VulkanProcTable& vk,
sk_sp<GrContext> context,
sk_sp<GrVkBackendContext> backend_context,
scenic_lib::Session* mozart_session);
~VulkanSurfacePool();
std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>
AcquireSurface(const SkISize& size);
void SubmitSurface(
std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>
surface);
void AgeAndCollectOldBuffers();
private:
using SurfacesSet = std::list<
std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>>;
template <class T>
static void HashCombine(size_t& seed, T const& v) {
seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
struct SkISizeHash {
std::size_t operator()(const SkISize& key) const {
size_t seed = 0;
HashCombine(seed, key.fWidth);
HashCombine(seed, key.fHeight);
return seed;
}
};
vulkan::VulkanProcTable& vk_;
sk_sp<GrContext> context_;
sk_sp<GrVkBackendContext> backend_context_;
scenic_lib::Session* mozart_session_;
std::unordered_map<SkISize, SurfacesSet, SkISizeHash> available_surfaces_;
std::unordered_map<
uintptr_t,
std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>>
pending_surfaces_;
size_t trace_surfaces_created_ = 0;
size_t trace_surfaces_reused_ = 0;
std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>
GetCachedOrCreateSurface(const SkISize& size);
std::unique_ptr<VulkanSurface> CreateSurface(const SkISize& size);
void RecycleSurface(uintptr_t surface_key);
void TraceStats();
FXL_DISALLOW_COPY_AND_ASSIGN(VulkanSurfacePool);
};
} // namespace flutter_runner