Flutter Engine
 
Loading...
Searching...
No Matches
flutter::ImageExternalTexture Class Referenceabstract

External texture peered to a sequence of android.hardware.HardwareBuffers. More...

#include <image_external_texture.h>

Inheritance diagram for flutter::ImageExternalTexture:
flutter::Texture flutter::ContextListener flutter::ImageExternalTextureGL flutter::ImageExternalTextureVKImpeller flutter::ImageExternalTextureGLImpeller flutter::ImageExternalTextureGLSkia

Public Types

enum class  ImageLifecycle {
  kReset ,
  kKeepAlive
}
 Whether the last image should be reset when the context is destroyed. More...
 

Public Member Functions

 ImageExternalTexture (int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &image_texture_entry, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, ImageLifecycle lifecycle)
 
virtual ~ImageExternalTexture ()
 
- Public Member Functions inherited from flutter::Texture
 Texture (int64_t id)
 
virtual ~Texture ()
 
int64_t Id ()
 
- Public Member Functions inherited from flutter::ContextListener
 ContextListener ()
 
 ~ContextListener ()
 

Protected Types

enum class  AttachmentState {
  kUninitialized ,
  kAttached ,
  kDetached
}
 

Protected Member Functions

virtual void ProcessFrame (PaintContext &context, const SkRect &bounds)=0
 Subclasses override this method to bind the latest representation of the hardware buffer wrapped by this texture instance to their own graphics package specific texture classes (SkImage, impeller::Texture, etc...).
 
virtual void Attach (PaintContext &context)=0
 
virtual void Detach ()=0
 
JavaLocalRef AcquireLatestImage ()
 
void CloseImage (const fml::jni::JavaRef< jobject > &image)
 
JavaLocalRef HardwareBufferFor (const fml::jni::JavaRef< jobject > &image)
 
void CloseHardwareBuffer (const fml::jni::JavaRef< jobject > &hardware_buffer)
 
AHardwareBuffer * AHardwareBufferFor (const fml::jni::JavaRef< jobject > &hardware_buffer)
 

Protected Attributes

fml::jni::ScopedJavaGlobalRef< jobject > image_texture_entry_
 
std::shared_ptr< PlatformViewAndroidJNIjni_facade_
 
AttachmentState state_ = AttachmentState::kUninitialized
 
sk_sp< flutter::DlImagedl_image_
 
ImageLRU image_lru_ = ImageLRU()
 

Detailed Description

External texture peered to a sequence of android.hardware.HardwareBuffers.

Android Hardware Buffers are available on newer versions of Android (API 29 and above).

This is an abstract base class and graphics packages provide concrete implementations of this class that bind hardware buffers to their own package-specific implementations of textures (SkImages, impeller::Texture, etc...).

Android Hardware Buffers allow binding to both OpenGL and Vulkan client-rendering APIs in a zero copy manner. Because of this graphics packages that support OpenGL and Vulkan can have multiple subclasses for each supported client-rendering API.

Definition at line 36 of file image_external_texture.h.

Member Enumeration Documentation

◆ AttachmentState

◆ ImageLifecycle

Whether the last image should be reset when the context is destroyed.

Enumerator
kReset 
kKeepAlive 

Definition at line 39 of file image_external_texture.h.

Constructor & Destructor Documentation

◆ ImageExternalTexture()

flutter::ImageExternalTexture::ImageExternalTexture ( int64_t  id,
const fml::jni::ScopedJavaGlobalRef< jobject > &  image_texture_entry,
const std::shared_ptr< PlatformViewAndroidJNI > &  jni_facade,
ImageLifecycle  lifecycle 
)
explicit

Definition at line 16 of file image_external_texture.cc.

21 : Texture(id),
22 image_texture_entry_(image_texture_entry),
23 jni_facade_(jni_facade),
24 texture_lifecycle_(lifecycle) {}
std::shared_ptr< PlatformViewAndroidJNI > jni_facade_
fml::jni::ScopedJavaGlobalRef< jobject > image_texture_entry_
Texture(int64_t id)
Definition texture.cc:13

◆ ~ImageExternalTexture()

flutter::ImageExternalTexture::~ImageExternalTexture ( )
virtualdefault

Member Function Documentation

◆ AcquireLatestImage()

JavaLocalRef flutter::ImageExternalTexture::AcquireLatestImage ( )
protected

Definition at line 89 of file image_external_texture.cc.

89 {
90 JNIEnv* env = fml::jni::AttachCurrentThread();
91 FML_CHECK(env != nullptr);
92
93 // ImageTextureEntry.acquireLatestImage.
94 JavaLocalRef image_java =
95 jni_facade_->ImageProducerTextureEntryAcquireLatestImage(
97 return image_java;
98}
#define FML_CHECK(condition)
Definition logging.h:104
std::nullptr_t JavaLocalRef
JNIEnv * AttachCurrentThread()
Definition jni_util.cc:34

References fml::jni::AttachCurrentThread(), FML_CHECK, image_texture_entry_, and jni_facade_.

Referenced by flutter::ImageExternalTextureGL::ProcessFrame().

◆ AHardwareBufferFor()

AHardwareBuffer * flutter::ImageExternalTexture::AHardwareBufferFor ( const fml::jni::JavaRef< jobject > &  hardware_buffer)
protected

Definition at line 124 of file image_external_texture.cc.

125 {
126 JNIEnv* env = fml::jni::AttachCurrentThread();
127 FML_CHECK(env != nullptr);
128 const auto& proc =
129 impeller::android::GetProcTable().AHardwareBuffer_fromHardwareBuffer;
130 return proc ? proc(env, hardware_buffer.obj()) : nullptr;
131}
const ProcTable & GetProcTable()
Definition proc_table.cc:12

References fml::jni::AttachCurrentThread(), FML_CHECK, impeller::android::GetProcTable(), and fml::jni::JavaRef< T >::obj().

Referenced by flutter::ImageExternalTextureGL::UpdateImage().

◆ Attach()

virtual void flutter::ImageExternalTexture::Attach ( PaintContext context)
protectedpure virtual

◆ CloseHardwareBuffer()

void flutter::ImageExternalTexture::CloseHardwareBuffer ( const fml::jni::JavaRef< jobject > &  hardware_buffer)
protected

Definition at line 107 of file image_external_texture.cc.

108 {
109 if (hardware_buffer.obj() == nullptr) {
110 return;
111 }
112 jni_facade_->HardwareBufferClose(JavaLocalRef(hardware_buffer));
113}

References jni_facade_, and fml::jni::JavaRef< T >::obj().

Referenced by flutter::ImageExternalTextureGL::ProcessFrame().

◆ CloseImage()

void flutter::ImageExternalTexture::CloseImage ( const fml::jni::JavaRef< jobject > &  image)
protected

Definition at line 100 of file image_external_texture.cc.

100 {
101 if (image.obj() == nullptr) {
102 return;
103 }
104 jni_facade_->ImageClose(JavaLocalRef(image));
105}
FlutterVulkanImage * image

References image, and jni_facade_.

◆ Detach()

virtual void flutter::ImageExternalTexture::Detach ( )
protectedpure virtual

◆ HardwareBufferFor()

JavaLocalRef flutter::ImageExternalTexture::HardwareBufferFor ( const fml::jni::JavaRef< jobject > &  image)
protected

Definition at line 115 of file image_external_texture.cc.

116 {
117 if (image.obj() == nullptr) {
118 return JavaLocalRef();
119 }
120 // Image.getHardwareBuffer.
121 return jni_facade_->ImageGetHardwareBuffer(JavaLocalRef(image));
122}

References image, and jni_facade_.

Referenced by flutter::ImageExternalTextureGL::ProcessFrame().

◆ ProcessFrame()

virtual void flutter::ImageExternalTexture::ProcessFrame ( PaintContext context,
const SkRect &  bounds 
)
protectedpure virtual

Subclasses override this method to bind the latest representation of the hardware buffer wrapped by this texture instance to their own graphics package specific texture classes (SkImage, impeller::Texture, etc...).

After a call to this method, attachment state of this instance must be kAttached. That is the responsibility of the subclass.

Parameters
contextThe context
[in]boundsThe bounds

Implemented in flutter::ImageExternalTextureGL.

Member Data Documentation

◆ dl_image_

sk_sp<flutter::DlImage> flutter::ImageExternalTexture::dl_image_
protected

◆ image_lru_

ImageLRU flutter::ImageExternalTexture::image_lru_ = ImageLRU()
protected

◆ image_texture_entry_

fml::jni::ScopedJavaGlobalRef<jobject> flutter::ImageExternalTexture::image_texture_entry_
protected

Definition at line 80 of file image_external_texture.h.

Referenced by AcquireLatestImage().

◆ jni_facade_

std::shared_ptr<PlatformViewAndroidJNI> flutter::ImageExternalTexture::jni_facade_
protected

◆ state_

AttachmentState flutter::ImageExternalTexture::state_ = AttachmentState::kUninitialized
protected

Definition at line 84 of file image_external_texture.h.

Referenced by flutter::ImageExternalTextureGL::Attach().


The documentation for this class was generated from the following files: