Flutter Engine
 
Loading...
Searching...
No Matches
image_external_texture.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_ANDROID_IMAGE_EXTERNAL_TEXTURE_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_H_
7
13
15#include <android/hardware_buffer_jni.h>
16
17namespace flutter {
18
19//------------------------------------------------------------------------------
20/// @brief External texture peered to a sequence of
21/// android.hardware.HardwareBuffers.
22///
23/// Android Hardware Buffers are available on newer versions of
24/// Android (API 29 and above).
25///
26/// This is an abstract base class and graphics packages provide
27/// concrete implementations of this class that bind hardware
28/// buffers to their own package-specific implementations of
29/// textures (SkImages, impeller::Texture, etc...).
30///
31/// Android Hardware Buffers allow binding to both OpenGL and Vulkan
32/// client-rendering APIs in a zero copy manner. Because of this
33/// graphics packages that support OpenGL and Vulkan can have
34/// multiple subclasses for each supported client-rendering API.
35///
37 public:
38 /// Whether the last image should be reset when the context is destroyed.
40
41 explicit ImageExternalTexture(
42 int64_t id,
43 const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry,
44 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
45 ImageLifecycle lifecycle);
46
47 // |flutter::Texture|
49
50 protected:
51 //----------------------------------------------------------------------------
52 /// @brief Subclasses override this method to bind the latest
53 /// representation of the hardware buffer wrapped by this texture
54 /// instance to their own graphics package specific texture
55 /// classes (SkImage, impeller::Texture, etc...).
56 ///
57 /// After a call to this method, attachment state of this instance
58 /// must be kAttached. That is the responsibility of the subclass.
59 ///
60 /// @param context The context
61 /// @param[in] bounds The bounds
62 ///
63 virtual void ProcessFrame(PaintContext& context, const SkRect& bounds) = 0;
64
65 virtual void Attach(PaintContext& context) = 0;
66
67 virtual void Detach() = 0;
68
70
72
74
75 void CloseHardwareBuffer(const fml::jni::JavaRef<jobject>& hardware_buffer);
76
77 AHardwareBuffer* AHardwareBufferFor(
78 const fml::jni::JavaRef<jobject>& hardware_buffer);
79
81 std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
82
85 sk_sp<flutter::DlImage> dl_image_;
87
88 private:
89 // |flutter::Texture|.
90 void Paint(PaintContext& context,
91 const DlRect& bounds,
92 bool freeze,
93 const DlImageSampling sampling) override;
94
95 // |flutter::Texture|.
96 void MarkNewFrameAvailable() override;
97
98 // |flutter::Texture|
99 void OnTextureUnregistered() override;
100
101 // |flutter::ContextListener|
102 void OnGrContextCreated() override;
103
104 // |flutter::ContextListener|
105 void OnGrContextDestroyed() override;
106
107 const ImageLifecycle texture_lifecycle_;
109};
110
111} // namespace flutter
112
113#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_H_
External texture peered to a sequence of android.hardware.HardwareBuffers.
AHardwareBuffer * AHardwareBufferFor(const fml::jni::JavaRef< jobject > &hardware_buffer)
JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef< jobject > &image)
virtual void ProcessFrame(PaintContext &context, const SkRect &bounds)=0
Subclasses override this method to bind the latest representation of the hardware buffer wrapped by t...
void CloseHardwareBuffer(const fml::jni::JavaRef< jobject > &hardware_buffer)
sk_sp< flutter::DlImage > dl_image_
void CloseImage(const fml::jni::JavaRef< jobject > &image)
virtual void Attach(PaintContext &context)=0
std::shared_ptr< PlatformViewAndroidJNI > jni_facade_
fml::jni::ScopedJavaGlobalRef< jobject > image_texture_entry_
ImageLifecycle
Whether the last image should be reset when the context is destroyed.
FlutterVulkanImage * image
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::nullptr_t JavaLocalRef