Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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/sysmem2/cpp/fidl.h>
9#include <fuchsia/ui/composition/cpp/fidl.h>
10
11#include <unordered_map>
12
13#include "flutter/fml/macros.h"
15
16namespace flutter_runner {
17
19 public:
20 // Only keep 12 surfaces at a time.
21 static constexpr int kMaxSurfaces = 12;
22 // If a surface doesn't get used for 3 or more generations, we discard it.
23 static constexpr int kMaxSurfaceAge = 3;
24
25 explicit SoftwareSurfaceProducer();
27
28 bool IsValid() const { return valid_; }
29
30 // |SurfaceProducer|
31 GrDirectContext* gr_context() const override { return nullptr; }
32
33 // |SurfaceProducer|
34 std::unique_ptr<SurfaceProducerSurface> ProduceOffscreenSurface(
35 const SkISize& size) override;
36
37 // |SurfaceProducer|
38 std::unique_ptr<SurfaceProducerSurface> ProduceSurface(
39 const SkISize& size) override;
40
41 // |SurfaceProducer|
42 void SubmitSurfaces(
43 std::vector<std::unique_ptr<SurfaceProducerSurface>> surfaces) override;
44
45 private:
46 void SubmitSurface(std::unique_ptr<SurfaceProducerSurface> surface);
47 std::unique_ptr<SoftwareSurface> CreateSurface(const SkISize& size);
48 void RecycleSurface(std::unique_ptr<SoftwareSurface> surface);
49
50 void RecyclePendingSurface(uintptr_t surface_key);
51
52 void AgeAndCollectOldBuffers();
53
54 void TraceStats();
55
56 fuchsia::sysmem2::AllocatorSyncPtr sysmem_allocator_;
57 fuchsia::ui::composition::AllocatorPtr flatland_allocator_;
58
59 // These surfaces are available for re-use.
60 std::vector<std::unique_ptr<SoftwareSurface>> available_surfaces_;
61 // These surfaces have been written to, but scenic is not finished reading
62 // from them yet.
63 std::unordered_map<uintptr_t, std::unique_ptr<SoftwareSurface>>
64 pending_surfaces_;
65
66 size_t trace_surfaces_created_ = 0;
67 size_t trace_surfaces_reused_ = 0;
68
69 bool valid_ = false;
70
72};
73
74} // namespace flutter_runner
75
76#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
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27