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

#include <image_external_texture_gl.h>

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

Classes

struct  GlEntry
 

Public Member Functions

 ImageExternalTextureGL (int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &image_textury_entry, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, ImageExternalTexture::ImageLifecycle lifecycle)
 
- Public Member Functions inherited from flutter::ImageExternalTexture
 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 Member Functions

void Attach (PaintContext &context) override
 
void Detach () override
 
void ProcessFrame (PaintContext &context, const SkRect &bounds) override
 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 sk_sp< flutter::DlImageCreateDlImage (PaintContext &context, const SkRect &bounds, std::optional< HardwareBufferKey > id, impeller::UniqueEGLImageKHR &&egl_image)=0
 
void UpdateImage (JavaLocalRef &hardware_buffer, const SkRect &bounds, PaintContext &context)
 
impeller::UniqueEGLImageKHR CreateEGLImage (AHardwareBuffer *buffer)
 
 FML_DISALLOW_COPY_AND_ASSIGN (ImageExternalTextureGL)
 
- Protected Member Functions inherited from flutter::ImageExternalTexture
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

std::unordered_map< HardwareBufferKey, GlEntrygl_entries_
 
- Protected Attributes inherited from flutter::ImageExternalTexture
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()
 

Additional Inherited Members

- Public Types inherited from flutter::ImageExternalTexture
enum class  ImageLifecycle {
  kReset ,
  kKeepAlive
}
 Whether the last image should be reset when the context is destroyed. More...
 
- Protected Types inherited from flutter::ImageExternalTexture
enum class  AttachmentState {
  kUninitialized ,
  kAttached ,
  kDetached
}
 

Detailed Description

Definition at line 18 of file image_external_texture_gl.h.

Constructor & Destructor Documentation

◆ ImageExternalTextureGL()

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

Definition at line 24 of file image_external_texture_gl.cc.

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

Member Function Documentation

◆ Attach()

void flutter::ImageExternalTextureGL::Attach ( PaintContext context)
overrideprotectedvirtual

Implements flutter::ImageExternalTexture.

Definition at line 31 of file image_external_texture_gl.cc.

31 {
33 // TODO(johnmccurtchan): We currently display the first frame after an
34 // attach-detach cycle as blank. There seems to be an issue on some
35 // devices where ImageReaders/Images from before the detach aren't
36 // valid after the attach. According to Android folks this doesn't
37 // match the spec. Revisit this in the future.
38 // See https://github.com/flutter/flutter/issues/142978 and
39 // https://github.com/flutter/flutter/issues/139039.
41 }
42}

References flutter::ImageExternalTexture::kAttached, flutter::ImageExternalTexture::kUninitialized, and flutter::ImageExternalTexture::state_.

◆ CreateDlImage()

virtual sk_sp< flutter::DlImage > flutter::ImageExternalTextureGL::CreateDlImage ( PaintContext context,
const SkRect &  bounds,
std::optional< HardwareBufferKey id,
impeller::UniqueEGLImageKHR &&  egl_image 
)
protectedpure virtual

Referenced by UpdateImage().

◆ CreateEGLImage()

impeller::UniqueEGLImageKHR flutter::ImageExternalTextureGL::CreateEGLImage ( AHardwareBuffer *  buffer)
protected

Definition at line 84 of file image_external_texture_gl.cc.

85 {
86 if (hardware_buffer == nullptr) {
88 }
89
90 EGLDisplay display = eglGetCurrentDisplay();
91 if (display == EGL_NO_DISPLAY) {
92 // This could happen when running in a deferred task that executes after
93 // the thread has lost its EGL state.
95 }
96
97 EGLClientBuffer client_buffer =
98 impeller::android::GetProcTable().eglGetNativeClientBufferANDROID(
99 hardware_buffer);
100 FML_DCHECK(client_buffer != nullptr);
101 if (client_buffer == nullptr) {
102 FML_LOG(ERROR) << "eglGetNativeClientBufferAndroid returned null.";
104 }
105
108 eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
109 client_buffer, 0),
110 display};
111
112 return impeller::UniqueEGLImageKHR(maybe_image);
113}
#define FML_LOG(severity)
Definition logging.h:101
#define FML_DCHECK(condition)
Definition logging.h:122
const ProcTable & GetProcTable()
Definition proc_table.cc:12
fml::UniqueObject< EGLImageKHRWithDisplay, EGLImageKHRWithDisplayTraits > UniqueEGLImageKHR
Definition image.h:62

References FML_DCHECK, FML_LOG, and impeller::android::GetProcTable().

Referenced by UpdateImage().

◆ Detach()

void flutter::ImageExternalTextureGL::Detach ( )
overrideprotectedvirtual

Implements flutter::ImageExternalTexture.

Definition at line 79 of file image_external_texture_gl.cc.

79 {
81 gl_entries_.clear();
82}
std::unordered_map< HardwareBufferKey, GlEntry > gl_entries_
void Clear()
Remove all entires from the image cache.
Definition image_lru.cc:60

References flutter::ImageLRU::Clear(), gl_entries_, and flutter::ImageExternalTexture::image_lru_.

◆ FML_DISALLOW_COPY_AND_ASSIGN()

flutter::ImageExternalTextureGL::FML_DISALLOW_COPY_AND_ASSIGN ( ImageExternalTextureGL  )
protected

◆ ProcessFrame()

void flutter::ImageExternalTextureGL::ProcessFrame ( PaintContext context,
const SkRect &  bounds 
)
overrideprotectedvirtual

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

Implements flutter::ImageExternalTexture.

Definition at line 68 of file image_external_texture_gl.cc.

69 {
71 if (image.is_null()) {
72 return;
73 }
74 JavaLocalRef hardware_buffer = HardwareBufferFor(image);
75 UpdateImage(hardware_buffer, bounds, context);
76 CloseHardwareBuffer(hardware_buffer);
77}
void UpdateImage(JavaLocalRef &hardware_buffer, const SkRect &bounds, PaintContext &context)
JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef< jobject > &image)
void CloseHardwareBuffer(const fml::jni::JavaRef< jobject > &hardware_buffer)
FlutterVulkanImage * image
std::nullptr_t JavaLocalRef

References flutter::ImageExternalTexture::AcquireLatestImage(), flutter::ImageExternalTexture::CloseHardwareBuffer(), flutter::ImageExternalTexture::HardwareBufferFor(), image, and UpdateImage().

◆ UpdateImage()

void flutter::ImageExternalTextureGL::UpdateImage ( JavaLocalRef hardware_buffer,
const SkRect &  bounds,
PaintContext context 
)
protected

Definition at line 44 of file image_external_texture_gl.cc.

46 {
47 AHardwareBuffer* latest_hardware_buffer = AHardwareBufferFor(hardware_buffer);
48 std::optional<HardwareBufferKey> key =
50 latest_hardware_buffer);
51 auto existing_image = image_lru_.FindImage(key);
52 if (existing_image != nullptr) {
53 dl_image_ = existing_image;
54 return;
55 }
56
57 auto egl_image = CreateEGLImage(latest_hardware_buffer);
58 if (!egl_image.is_valid()) {
59 return;
60 }
61
62 dl_image_ = CreateDlImage(context, bounds, key, std::move(egl_image));
63 if (key.has_value()) {
65 }
66}
virtual sk_sp< flutter::DlImage > CreateDlImage(PaintContext &context, const SkRect &bounds, std::optional< HardwareBufferKey > id, impeller::UniqueEGLImageKHR &&egl_image)=0
impeller::UniqueEGLImageKHR CreateEGLImage(AHardwareBuffer *buffer)
AHardwareBuffer * AHardwareBufferFor(const fml::jni::JavaRef< jobject > &hardware_buffer)
sk_sp< flutter::DlImage > dl_image_
HardwareBufferKey AddImage(const sk_sp< flutter::DlImage > &image, HardwareBufferKey key)
Add a new image to the cache with a key, returning the key of the LRU entry that was removed.
Definition image_lru.cc:42
sk_sp< flutter::DlImage > FindImage(std::optional< HardwareBufferKey > key)
Retrieve the image associated with the given [key], or nullptr.
Definition image_lru.cc:9
std::optional< uint64_t > GetSystemUniqueID() const
Get the system wide unique ID of the hardware buffer if possible. This is only available on Android A...

References flutter::ImageLRU::AddImage(), flutter::ImageExternalTexture::AHardwareBufferFor(), CreateDlImage(), CreateEGLImage(), flutter::ImageExternalTexture::dl_image_, flutter::ImageLRU::FindImage(), impeller::android::HardwareBuffer::GetSystemUniqueID(), gl_entries_, flutter::ImageExternalTexture::image_lru_, and key.

Referenced by ProcessFrame().

Member Data Documentation

◆ gl_entries_

std::unordered_map<HardwareBufferKey, GlEntry> flutter::ImageExternalTextureGL::gl_entries_
protected

Definition at line 56 of file image_external_texture_gl.h.

Referenced by Detach(), and UpdateImage().


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