Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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/sysmem2/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"
20#include "third_party/skia/include/core/SkSize.h"
21#include "third_party/skia/include/core/SkSurface.h"
22
23namespace flutter_runner {
24
26 public:
27 SoftwareSurface(fuchsia::sysmem2::AllocatorSyncPtr& sysmem_allocator,
28 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
29 const SkISize& size);
30
31 ~SoftwareSurface() override;
32
33 size_t GetAllocationSize() const { return surface_size_bytes_; }
34
35 // |SurfaceProducerSurface|
36 size_t AdvanceAndGetAge() override;
37
38 // |SurfaceProducerSurface|
40
41 // |SurfaceProducerSurface|
42 bool IsValid() const override;
43
44 // |SurfaceProducerSurface|
45 SkISize GetSize() const override;
46
47 // |SurfaceProducerSurface|
49 const std::function<void(void)>& on_surface_read_finished) override;
50
51 // |SurfaceProducerSurface|
52 void SetImageId(uint32_t image_id) override;
53
54 // |SurfaceProducerSurface|
55 uint32_t GetImageId() override;
56
57 // |SurfaceProducerSurface|
58 sk_sp<SkSurface> GetSkiaSurface() const override;
59
60 // |SurfaceProducerSurface|
61 fuchsia::ui::composition::BufferCollectionImportToken
63
64 // |SurfaceProducerSurface|
65 zx::event GetAcquireFence() override;
66
67 // |SurfaceProducerSurface|
68 zx::event GetReleaseFence() override;
69
70 // |SurfaceProducerSurface|
72 ReleaseImageCallback release_image_callback) override;
73
74 private:
75 void OnSurfaceReadFinished(async_dispatcher_t* dispatcher,
76 async::WaitBase* wait,
77 zx_status_t status,
78 const zx_packet_signal_t* signal);
79
80 bool SetupSkiaSurface(
81 fuchsia::sysmem2::AllocatorSyncPtr& sysmem_allocator,
82 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
83 const SkISize& size);
84
85 bool CreateFences();
86
87 void Reset();
88 uint32_t image_id_ = 0;
89
90 sk_sp<SkSurface> sk_surface_;
91
92 // This is associated with `release_event_` and allows detection of when
93 // scenic has finished reading from the surface (and thus it is safe to re-use
94 // for writing).
95 async::WaitMethod<SoftwareSurface, &SoftwareSurface::OnSurfaceReadFinished>
96 wait_for_surface_read_finished_;
97 // Called when scenic has finished reading from the surface, to allow
98 // `SoftwareSurfaceProducer` to re-use the surface.
99 std::function<void()> surface_read_finished_callback_;
100 // Called when the surface is destroyed, to allow
101 // `ExternalViewEmbedder` to release the associated Flatland image.
102 ReleaseImageCallback release_image_callback_;
103
104 // Allows Flatland to associate this surface with a Flatland Image.
105 fuchsia::ui::composition::BufferCollectionImportToken import_token_;
106 zx::event acquire_event_; // Signals to scenic that writing is finished.
107 zx::event release_event_; // Signalled by scenic that reading is finished.
108 zx::vmo surface_vmo_; // VMO that is backing the surface memory.
109
110 uint32_t surface_size_bytes_; // Size of the surface memory, in bytes.
111 size_t age_{0}; // Number of frames since surface was last written to.
112
113 bool needs_cache_clean_{false};
114 bool valid_{false};
115
116 FML_DISALLOW_COPY_AND_ASSIGN(SoftwareSurface);
117};
118
119} // namespace flutter_runner
120
121#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
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
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::function< void()> ReleaseImageCallback