Flutter Engine
flutter::AndroidExternalTextureGL Class Reference

#include <android_external_texture_gl.h>

Inheritance diagram for flutter::AndroidExternalTextureGL:
flutter::Texture

Public Member Functions

 AndroidExternalTextureGL (int64_t id, const fml::jni::JavaObjectWeakGlobalRef &surface_texture, std::shared_ptr< PlatformViewAndroidJNI > jni_facade)
 
 ~AndroidExternalTextureGL () override
 
void Paint (SkCanvas &canvas, const SkRect &bounds, bool freeze, GrDirectContext *context, SkFilterQuality filter_quality) override
 
void OnGrContextCreated () override
 
void OnGrContextDestroyed () override
 
void MarkNewFrameAvailable () override
 
void OnTextureUnregistered () override
 
- Public Member Functions inherited from flutter::Texture
 Texture (int64_t id)
 
virtual ~Texture ()
 
int64_t Id ()
 

Detailed Description

Definition at line 16 of file android_external_texture_gl.h.

Constructor & Destructor Documentation

◆ AndroidExternalTextureGL()

flutter::AndroidExternalTextureGL::AndroidExternalTextureGL ( int64_t  id,
const fml::jni::JavaObjectWeakGlobalRef surface_texture,
std::shared_ptr< PlatformViewAndroidJNI jni_facade 
)

Definition at line 14 of file android_external_texture_gl.cc.

18  : Texture(id),
19  jni_facade_(jni_facade),
20  surface_texture_(surface_texture),
21  transform(SkMatrix::I()) {}
Texture(int64_t id)
Definition: texture.cc:9

◆ ~AndroidExternalTextureGL()

flutter::AndroidExternalTextureGL::~AndroidExternalTextureGL ( )
override

Definition at line 23 of file android_external_texture_gl.cc.

23  {
24  if (state_ == AttachmentState::attached) {
25  glDeleteTextures(1, &texture_name_);
26  }
27 }

Member Function Documentation

◆ MarkNewFrameAvailable()

void flutter::AndroidExternalTextureGL::MarkNewFrameAvailable ( )
overridevirtual

Implements flutter::Texture.

Definition at line 33 of file android_external_texture_gl.cc.

33  {
34  new_frame_ready_ = true;
35 }

◆ OnGrContextCreated()

void flutter::AndroidExternalTextureGL::OnGrContextCreated ( )
overridevirtual

Implements flutter::Texture.

Definition at line 29 of file android_external_texture_gl.cc.

29  {
30  state_ = AttachmentState::uninitialized;
31 }

◆ OnGrContextDestroyed()

void flutter::AndroidExternalTextureGL::OnGrContextDestroyed ( )
overridevirtual

Implements flutter::Texture.

Definition at line 82 of file android_external_texture_gl.cc.

82  {
83  if (state_ == AttachmentState::attached) {
84  Detach();
85  glDeleteTextures(1, &texture_name_);
86  }
87  state_ = AttachmentState::detached;
88 }

◆ OnTextureUnregistered()

void flutter::AndroidExternalTextureGL::OnTextureUnregistered ( )
overridevirtual

Implements flutter::Texture.

Definition at line 103 of file android_external_texture_gl.cc.

103 {}

◆ Paint()

void flutter::AndroidExternalTextureGL::Paint ( SkCanvas &  canvas,
const SkRect &  bounds,
bool  freeze,
GrDirectContext *  context,
SkFilterQuality  filter_quality 
)
overridevirtual

Implements flutter::Texture.

Definition at line 37 of file android_external_texture_gl.cc.

41  {
42  if (state_ == AttachmentState::detached) {
43  return;
44  }
45  if (state_ == AttachmentState::uninitialized) {
46  glGenTextures(1, &texture_name_);
47  Attach(static_cast<jint>(texture_name_));
48  state_ = AttachmentState::attached;
49  }
50  if (!freeze && new_frame_ready_) {
51  Update();
52  new_frame_ready_ = false;
53  }
54  GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_,
55  GL_RGBA8_OES};
56  GrBackendTexture backendTexture(1, 1, GrMipMapped::kNo, textureInfo);
57  sk_sp<SkImage> image = SkImage::MakeFromTexture(
58  context, backendTexture, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
59  kPremul_SkAlphaType, nullptr);
60  if (image) {
61  SkAutoCanvasRestore autoRestore(&canvas, true);
62  canvas.translate(bounds.x(), bounds.y());
63  canvas.scale(bounds.width(), bounds.height());
64  if (!transform.isIdentity()) {
65  SkMatrix transformAroundCenter(transform);
66 
67  transformAroundCenter.preTranslate(-0.5, -0.5);
68  transformAroundCenter.postScale(1, -1);
69  transformAroundCenter.postTranslate(0.5, 0.5);
70  canvas.concat(transformAroundCenter);
71  }
72  SkPaint paint;
73  paint.setFilterQuality(filter_quality);
74  canvas.drawImage(image, 0, 0, &paint);
75  }
76 }

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