Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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)
 
- 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)
 
virtual ~ImageExternalTexture ()=default
 
void Paint (PaintContext &context, const SkRect &bounds, bool freeze, const DlImageSampling sampling) override
 
void MarkNewFrameAvailable () override
 
void OnTextureUnregistered () override
 
void OnGrContextCreated () override
 
void OnGrContextDestroyed () override
 
- 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
 
void UpdateImage (JavaLocalRef &hardware_buffer, const SkRect &bounds, PaintContext &context)
 
virtual sk_sp< flutter::DlImageCreateDlImage (PaintContext &context, const SkRect &bounds, std::optional< HardwareBufferKey > id, impeller::UniqueEGLImageKHR &&egl_image)=0
 
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)
 
AHardwareBufferAHardwareBufferFor (const fml::jni::JavaRef< jobject > &hardware_buffer)
 
 FML_DISALLOW_COPY_AND_ASSIGN (ImageExternalTexture)
 

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

- Protected Types inherited from flutter::ImageExternalTexture
enum class  AttachmentState { kUninitialized , kAttached , kDetached }
 

Detailed Description

Definition at line 23 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 
)

Definition at line 24 of file image_external_texture_gl.cc.

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

Member Function Documentation

◆ Attach()

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

Implements flutter::ImageExternalTexture.

Reimplemented in flutter::ImageExternalTextureGLSkia, and flutter::ImageExternalTextureGLImpeller.

Definition at line 30 of file image_external_texture_gl.cc.

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

◆ CreateDlImage()

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

◆ CreateEGLImage()

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

Definition at line 83 of file image_external_texture_gl.cc.

84 {
85 if (hardware_buffer == nullptr) {
87 }
88
89 EGLDisplay display = eglGetCurrentDisplay();
90 FML_CHECK(display != EGL_NO_DISPLAY);
91
92 EGLClientBuffer client_buffer =
93 impeller::android::GetProcTable().eglGetNativeClientBufferANDROID(
94 hardware_buffer);
95 FML_DCHECK(client_buffer != nullptr);
96 if (client_buffer == nullptr) {
97 FML_LOG(ERROR) << "eglGetNativeClientBufferAndroid returned null.";
99 }
100
103 eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
104 client_buffer, 0),
105 display};
106
107 return impeller::UniqueEGLImageKHR(maybe_image);
108}
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
#define FML_DCHECK(condition)
Definition logging.h:103
const ProcTable & GetProcTable()
Definition proc_table.cc:12
fml::UniqueObject< EGLImageKHRWithDisplay, EGLImageKHRWithDisplayTraits > UniqueEGLImageKHR
Definition image.h:73
#define ERROR(message)

◆ Detach()

void flutter::ImageExternalTextureGL::Detach ( )
overrideprotectedvirtual

Implements flutter::ImageExternalTexture.

Reimplemented in flutter::ImageExternalTextureGLSkia, and flutter::ImageExternalTextureGLImpeller.

Definition at line 78 of file image_external_texture_gl.cc.

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

◆ 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

Implements flutter::ImageExternalTexture.

Definition at line 67 of file image_external_texture_gl.cc.

68 {
70 if (image.is_null()) {
71 return;
72 }
73 JavaLocalRef hardware_buffer = HardwareBufferFor(image);
74 UpdateImage(hardware_buffer, bounds, context);
75 CloseHardwareBuffer(hardware_buffer);
76}
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)
sk_sp< SkImage > image
Definition examples.cpp:29
std::nullptr_t JavaLocalRef

◆ UpdateImage()

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

Definition at line 43 of file image_external_texture_gl.cc.

45 {
46 AHardwareBuffer* latest_hardware_buffer = AHardwareBufferFor(hardware_buffer);
47 std::optional<HardwareBufferKey> key =
49 latest_hardware_buffer);
50 auto existing_image = image_lru_.FindImage(key);
51 if (existing_image != nullptr) {
52 dl_image_ = existing_image;
53 return;
54 }
55
56 auto egl_image = CreateEGLImage(latest_hardware_buffer);
57 if (!egl_image.is_valid()) {
58 return;
59 }
60
61 dl_image_ = CreateDlImage(context, bounds, key, std::move(egl_image));
62 if (key.has_value()) {
64 }
65}
struct AHardwareBuffer AHardwareBuffer
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...

Member Data Documentation

◆ gl_entries_

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

Definition at line 54 of file image_external_texture_gl.h.


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