Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
software_surface.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_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_SOFTWARE_SURFACE_H_
7
8#include <fuchsia/sysmem/cpp/fidl.h>
9#include <fuchsia/ui/composition/cpp/fidl.h>
10#include <lib/async/cpp/wait.h>
11#include <lib/zx/event.h>
12#include <lib/zx/vmo.h>
13
14#include <array>
15#include <cstdint>
16#include <memory>
17
18#include "flutter/fml/macros.h"
21
22#include "surface_producer.h"
23
24namespace flutter_runner {
25
27 public:
28 SoftwareSurface(fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
29 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
30 const SkISize& size);
31
32 ~SoftwareSurface() override;
33
34 size_t GetAllocationSize() const { return surface_size_bytes_; }
35
36 // |SurfaceProducerSurface|
37 size_t AdvanceAndGetAge() override;
38
39 // |SurfaceProducerSurface|
41
42 // |SurfaceProducerSurface|
43 bool IsValid() const override;
44
45 // |SurfaceProducerSurface|
46 SkISize GetSize() const override;
47
48 // |SurfaceProducerSurface|
50 const std::function<void(void)>& on_surface_read_finished) override;
51
52 // |SurfaceProducerSurface|
53 void SetImageId(uint32_t image_id) override;
54
55 // |SurfaceProducerSurface|
56 uint32_t GetImageId() override;
57
58 // |SurfaceProducerSurface|
59 sk_sp<SkSurface> GetSkiaSurface() const override;
60
61 // |SurfaceProducerSurface|
62 fuchsia::ui::composition::BufferCollectionImportToken
64
65 // |SurfaceProducerSurface|
66 zx::event GetAcquireFence() override;
67
68 // |SurfaceProducerSurface|
69 zx::event GetReleaseFence() override;
70
71 // |SurfaceProducerSurface|
73 ReleaseImageCallback release_image_callback) override;
74
75 private:
76 void OnSurfaceReadFinished(async_dispatcher_t* dispatcher,
77 async::WaitBase* wait,
78 zx_status_t status,
79 const zx_packet_signal_t* signal);
80
81 bool SetupSkiaSurface(
82 fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
83 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
84 const SkISize& size);
85
86 bool CreateFences();
87
88 void Reset();
89 uint32_t image_id_ = 0;
90
91 sk_sp<SkSurface> sk_surface_;
92
93 // This is associated with `release_event_` and allows detection of when
94 // scenic has finished reading from the surface (and thus it is safe to re-use
95 // for writing).
96 async::WaitMethod<SoftwareSurface, &SoftwareSurface::OnSurfaceReadFinished>
97 wait_for_surface_read_finished_;
98 // Called when scenic has finished reading from the surface, to allow
99 // `SoftwareSurfaceProducer` to re-use the surface.
100 std::function<void()> surface_read_finished_callback_;
101 // Called when the surface is destroyed, to allow
102 // `ExternalViewEmbedder` to release the associated Flatland image.
103 ReleaseImageCallback release_image_callback_;
104
105 // Allows Flatland to associate this surface with a Flatland Image.
106 fuchsia::ui::composition::BufferCollectionImportToken import_token_;
107 zx::event acquire_event_; // Signals to scenic that writing is finished.
108 zx::event release_event_; // Signalled by scenic that reading is finished.
109 zx::vmo surface_vmo_; // VMO that is backing the surface memory.
110
111 uint32_t surface_size_bytes_; // Size of the surface memory, in bytes.
112 size_t age_{0}; // Number of frames since surface was last written to.
113
114 bool needs_cache_clean_{false};
115 bool valid_{false};
116
117 FML_DISALLOW_COPY_AND_ASSIGN(SoftwareSurface);
118};
119
120} // namespace flutter_runner
121
122#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_SOFTWARE_SURFACE_H_
bool FlushSessionAcquireAndReleaseEvents() override
fuchsia::ui::composition::BufferCollectionImportToken GetBufferCollectionImportToken() override
void SetReleaseImageCallback(ReleaseImageCallback release_image_callback) override
zx::event GetReleaseFence() override
zx::event GetAcquireFence() override
SoftwareSurface(fuchsia::sysmem::AllocatorSyncPtr &sysmem_allocator, fuchsia::ui::composition::AllocatorPtr &flatland_allocator, const SkISize &size)
sk_sp< SkSurface > GetSkiaSurface() const override
void SetImageId(uint32_t image_id) override
SkISize GetSize() const override
void SignalWritesFinished(const std::function< void(void)> &on_surface_read_finished) override
FlKeyEvent * event
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::function< void()> ReleaseImageCallback
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkSize.h:16