Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
software_surface_producer.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_SOFTWARE_SURFACE_PRODUCER_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_SOFTWARE_SURFACE_PRODUCER_H_
7
8#include <fuchsia/sysmem/cpp/fidl.h>
9#include <fuchsia/ui/composition/cpp/fidl.h>
10
11#include <unordered_map>
12
13#include "flutter/fml/macros.h"
14
15#include "software_surface.h"
16
17namespace flutter_runner {
18
20 public:
21 // Only keep 12 surfaces at a time.
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
26 explicit SoftwareSurfaceProducer();
28
29 bool IsValid() const { return valid_; }
30
31 // |SurfaceProducer|
32 GrDirectContext* gr_context() const override { return nullptr; }
33
34 // |SurfaceProducer|
35 std::unique_ptr<SurfaceProducerSurface> ProduceOffscreenSurface(
36 const SkISize& size) override;
37
38 // |SurfaceProducer|
39 std::unique_ptr<SurfaceProducerSurface> ProduceSurface(
40 const SkISize& size) override;
41
42 // |SurfaceProducer|
43 void SubmitSurfaces(
44 std::vector<std::unique_ptr<SurfaceProducerSurface>> surfaces) override;
45
46 private:
47 void SubmitSurface(std::unique_ptr<SurfaceProducerSurface> surface);
48 std::unique_ptr<SoftwareSurface> CreateSurface(const SkISize& size);
49 void RecycleSurface(std::unique_ptr<SoftwareSurface> surface);
50
51 void RecyclePendingSurface(uintptr_t surface_key);
52
53 void AgeAndCollectOldBuffers();
54
55 void TraceStats();
56
57 fuchsia::sysmem::AllocatorSyncPtr sysmem_allocator_;
58 fuchsia::ui::composition::AllocatorPtr flatland_allocator_;
59
60 // These surfaces are available for re-use.
61 std::vector<std::unique_ptr<SoftwareSurface>> available_surfaces_;
62 // These surfaces have been written to, but scenic is not finished reading
63 // from them yet.
64 std::unordered_map<uintptr_t, std::unique_ptr<SoftwareSurface>>
65 pending_surfaces_;
66
67 size_t trace_surfaces_created_ = 0;
68 size_t trace_surfaces_reused_ = 0;
69
70 bool valid_ = false;
71
73};
74
75} // namespace flutter_runner
76
77#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_SOFTWARE_SURFACE_PRODUCER_H_
GrDirectContext * gr_context() const override
void SubmitSurfaces(std::vector< std::unique_ptr< SurfaceProducerSurface > > surfaces) override
std::unique_ptr< SurfaceProducerSurface > ProduceOffscreenSurface(const SkISize &size) override
std::unique_ptr< SurfaceProducerSurface > ProduceSurface(const SkISize &size) override
VkSurfaceKHR surface
Definition main.cc:49
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27