Flutter Engine
The Flutter Engine
texture_registrar.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_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_
7
9
10#include <cstdint>
11#include <functional>
12#include <memory>
13#include <utility>
14#include <variant>
15
16namespace flutter {
17
18// A pixel buffer texture.
20 public:
21 // A callback used for retrieving pixel buffers.
22 typedef std::function<const FlutterDesktopPixelBuffer*(size_t width,
23 size_t height)>
25
26 // Creates a pixel buffer texture that uses the provided |copy_buffer_cb| to
27 // retrieve the buffer.
28 // As the callback is usually invoked from the render thread, the callee must
29 // take care of proper synchronization. It also needs to be ensured that the
30 // returned buffer isn't released prior to unregistering this texture.
31 explicit PixelBufferTexture(CopyBufferCallback copy_buffer_callback)
32 : copy_buffer_callback_(std::move(copy_buffer_callback)) {}
33
34 // Returns the callback-provided FlutterDesktopPixelBuffer that contains the
35 // actual pixel data. The intended surface size is specified by |width| and
36 // |height|.
38 size_t height) const {
39 return copy_buffer_callback_(width, height);
40 }
41
42 private:
43 const CopyBufferCallback copy_buffer_callback_;
44};
45
46// A GPU surface-based texture.
48 public:
49 // A callback used for retrieving surface descriptors.
50 typedef std::function<
51 const FlutterDesktopGpuSurfaceDescriptor*(size_t width, size_t height)>
53
55 ObtainDescriptorCallback obtain_descriptor_callback)
56 : surface_type_(surface_type),
57 obtain_descriptor_callback_(std::move(obtain_descriptor_callback)) {}
58
59 // Returns the callback-provided FlutterDesktopGpuSurfaceDescriptor that
60 // contains the surface handle. The intended surface size is specified by
61 // |width| and |height|.
63 size_t width,
64 size_t height) const {
65 return obtain_descriptor_callback_(width, height);
66 }
67
68 // Gets the surface type.
69 FlutterDesktopGpuSurfaceType surface_type() const { return surface_type_; }
70
71 private:
72 const FlutterDesktopGpuSurfaceType surface_type_;
73 const ObtainDescriptorCallback obtain_descriptor_callback_;
74};
75
76// The available texture variants.
77// Only PixelBufferTexture is currently implemented.
78// Other variants are expected to be added in the future.
79typedef std::variant<PixelBufferTexture, GpuSurfaceTexture> TextureVariant;
80
81// An object keeping track of external textures.
82//
83// Thread safety:
84// It's safe to call the member methods from any thread.
86 public:
87 virtual ~TextureRegistrar() = default;
88
89 // Registers a |texture| object and returns the ID for that texture.
90 virtual int64_t RegisterTexture(TextureVariant* texture) = 0;
91
92 // Notifies the flutter engine that the texture object corresponding
93 // to |texure_id| needs to render a new frame.
94 //
95 // For PixelBufferTextures, this will effectively make the engine invoke
96 // the callback that was provided upon creating the texture.
97 virtual bool MarkTextureFrameAvailable(int64_t texture_id) = 0;
98
99 // Asynchronously unregisters an existing texture object.
100 // Upon completion, the optional |callback| gets invoked.
101 virtual void UnregisterTexture(int64_t texture_id,
102 std::function<void()> callback) = 0;
103
104 // Unregisters an existing texture object.
105 // DEPRECATED: Use UnregisterTexture(texture_id, optional_callback) instead.
106 virtual bool UnregisterTexture(int64_t texture_id) = 0;
107};
108
109} // namespace flutter
110
111#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_
GpuSurfaceTexture(FlutterDesktopGpuSurfaceType surface_type, ObtainDescriptorCallback obtain_descriptor_callback)
FlutterDesktopGpuSurfaceType surface_type() const
std::function< const FlutterDesktopGpuSurfaceDescriptor *(size_t width, size_t height)> ObtainDescriptorCallback
const FlutterDesktopGpuSurfaceDescriptor * ObtainDescriptor(size_t width, size_t height) const
const FlutterDesktopPixelBuffer * CopyPixelBuffer(size_t width, size_t height) const
std::function< const FlutterDesktopPixelBuffer *(size_t width, size_t height)> CopyBufferCallback
PixelBufferTexture(CopyBufferCallback copy_buffer_callback)
virtual bool UnregisterTexture(int64_t texture_id)=0
virtual ~TextureRegistrar()=default
virtual void UnregisterTexture(int64_t texture_id, std::function< void()> callback)=0
virtual bool MarkTextureFrameAvailable(int64_t texture_id)=0
virtual int64_t RegisterTexture(TextureVariant *texture)=0
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
FlutterDesktopGpuSurfaceType
Dart_NativeFunction function
Definition: fuchsia.cc:51
FlTexture * texture
std::variant< PixelBufferTexture, GpuSurfaceTexture > TextureVariant
Definition: ref_ptr.h:256
int32_t height
int32_t width
int64_t texture_id