Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
flutter::SurfaceTextureExternalTexture Class Referenceabstract

#include <surface_texture_external_texture.h>

Inheritance diagram for flutter::SurfaceTextureExternalTexture:
flutter::Texture flutter::ContextListener flutter::SurfaceTextureExternalTextureGL flutter::SurfaceTextureExternalTextureImpellerGL

Public Member Functions

 SurfaceTextureExternalTexture (int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &surface_texture, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade)
 
 ~SurfaceTextureExternalTexture () override
 
void Paint (PaintContext &context, const SkRect &bounds, bool freeze, const DlImageSampling sampling) 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 ()
 
- 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
 
virtual void Detach ()
 
void Attach (int gl_tex_id)
 
bool ShouldUpdate ()
 
void Update ()
 
 FML_DISALLOW_COPY_AND_ASSIGN (SurfaceTextureExternalTexture)
 

Protected Attributes

std::shared_ptr< PlatformViewAndroidJNIjni_facade_
 
fml::jni::ScopedJavaGlobalRef< jobject > surface_texture_
 
AttachmentState state_ = AttachmentState::kUninitialized
 
SkMatrix transform_
 
sk_sp< flutter::DlImagedl_image_
 

Detailed Description

Definition at line 16 of file surface_texture_external_texture.h.

Member Enumeration Documentation

◆ AttachmentState

Constructor & Destructor Documentation

◆ SurfaceTextureExternalTexture()

flutter::SurfaceTextureExternalTexture::SurfaceTextureExternalTexture ( int64_t  id,
const fml::jni::ScopedJavaGlobalRef< jobject > &  surface_texture,
const std::shared_ptr< PlatformViewAndroidJNI > &  jni_facade 
)

Definition at line 24 of file surface_texture_external_texture.cc.

28 : Texture(id),
29 jni_facade_(jni_facade),
30 surface_texture_(surface_texture),
static const SkMatrix & I()
fml::jni::ScopedJavaGlobalRef< jobject > surface_texture_
std::shared_ptr< PlatformViewAndroidJNI > jni_facade_
Texture(int64_t id)
Definition texture.cc:13

◆ ~SurfaceTextureExternalTexture()

flutter::SurfaceTextureExternalTexture::~SurfaceTextureExternalTexture ( )
override

Definition at line 33 of file surface_texture_external_texture.cc.

33{}

Member Function Documentation

◆ Attach()

void flutter::SurfaceTextureExternalTexture::Attach ( int  gl_tex_id)
protected

◆ Detach()

void flutter::SurfaceTextureExternalTexture::Detach ( )
protectedvirtual

◆ FML_DISALLOW_COPY_AND_ASSIGN()

flutter::SurfaceTextureExternalTexture::FML_DISALLOW_COPY_AND_ASSIGN ( SurfaceTextureExternalTexture  )
protected

◆ MarkNewFrameAvailable()

void flutter::SurfaceTextureExternalTexture::MarkNewFrameAvailable ( )
overridevirtual

Implements flutter::Texture.

Definition at line 39 of file surface_texture_external_texture.cc.

39 {
40 // NOOP.
41}

◆ OnGrContextCreated()

void flutter::SurfaceTextureExternalTexture::OnGrContextCreated ( )
overridevirtual

◆ OnGrContextDestroyed()

void flutter::SurfaceTextureExternalTexture::OnGrContextDestroyed ( )
overridevirtual

◆ OnTextureUnregistered()

void flutter::SurfaceTextureExternalTexture::OnTextureUnregistered ( )
overridevirtual

Implements flutter::Texture.

Definition at line 92 of file surface_texture_external_texture.cc.

92{}

◆ Paint()

void flutter::SurfaceTextureExternalTexture::Paint ( PaintContext context,
const SkRect bounds,
bool  freeze,
const DlImageSampling  sampling 
)
overridevirtual

Implements flutter::Texture.

Definition at line 43 of file surface_texture_external_texture.cc.

46 {
48 return;
49 }
50 const bool should_process_frame =
51 !freeze || ShouldUpdate() || dl_image_ == nullptr;
52 if (should_process_frame) {
53 ProcessFrame(context, bounds);
54 }
56
57 if (dl_image_) {
58 DlAutoCanvasRestore autoRestore(context.canvas, true);
59
60 // The incoming texture is vertically flipped, so we flip it
61 // back. OpenGL's coordinate system has Positive Y equivalent to up, while
62 // Skia's coordinate system has Negative Y equvalent to up.
63 context.canvas->Translate(bounds.x(), bounds.y() + bounds.height());
64 context.canvas->Scale(bounds.width(), -bounds.height());
65
66 if (!transform_.isIdentity()) {
67 DlImageColorSource source(dl_image_, DlTileMode::kClamp,
68 DlTileMode::kClamp, sampling, &transform_);
69
70 DlPaint paintWithShader;
71 if (context.paint) {
72 paintWithShader = *context.paint;
73 }
74 paintWithShader.setColorSource(&source);
75 context.canvas->DrawRect(SkRect::MakeWH(1, 1), paintWithShader);
76 } else {
77 context.canvas->DrawImage(dl_image_, {0, 0}, sampling, context.paint);
78 }
79 } else {
80 FML_LOG(WARNING)
81 << "No DlImage available for SurfaceTextureExternalTexture to paint.";
82 }
83}
bool isIdentity() const
Definition SkMatrix.h:223
virtual void ProcessFrame(PaintContext &context, const SkRect &bounds)=0
SkBitmap source
Definition examples.cpp:28
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
Optional< SkRect > bounds
Definition SkRecords.h:189
SkSamplingOptions sampling
Definition SkRecords.h:337
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ ProcessFrame()

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

◆ ShouldUpdate()

bool flutter::SurfaceTextureExternalTexture::ShouldUpdate ( )
protected

Definition at line 106 of file surface_texture_external_texture.cc.

106 {
107 return jni_facade_->SurfaceTextureShouldUpdate(
109}

◆ Update()

void flutter::SurfaceTextureExternalTexture::Update ( )
protected

Definition at line 111 of file surface_texture_external_texture.cc.

111 {
112 jni_facade_->SurfaceTextureUpdateTexImage(
114
115 jni_facade_->SurfaceTextureGetTransformMatrix(
117
118 // Android's SurfaceTexture transform matrix works on texture coordinate
119 // lookups in the range 0.0-1.0, while Skia's Shader transform matrix works on
120 // the image itself, as if it were inscribed inside a clip rect.
121 // An Android transform that scales lookup by 0.5 (displaying 50% of the
122 // texture) is the same as a Skia transform by 2.0 (scaling 50% of the image
123 // outside of the virtual "clip rect"), so we invert the incoming matrix.
124 SkMatrix inverted;
125 if (!transform_.invert(&inverted)) {
127 << "Invalid (not invertable) SurfaceTexture transformation matrix";
128 }
129 transform_ = inverted;
130}
bool invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206
#define FATAL(error)

Member Data Documentation

◆ dl_image_

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

Definition at line 52 of file surface_texture_external_texture.h.

◆ jni_facade_

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

Definition at line 48 of file surface_texture_external_texture.h.

◆ state_

AttachmentState flutter::SurfaceTextureExternalTexture::state_ = AttachmentState::kUninitialized
protected

Definition at line 50 of file surface_texture_external_texture.h.

◆ surface_texture_

fml::jni::ScopedJavaGlobalRef<jobject> flutter::SurfaceTextureExternalTexture::surface_texture_
protected

Definition at line 49 of file surface_texture_external_texture.h.

◆ transform_

SkMatrix flutter::SurfaceTextureExternalTexture::transform_
protected

Definition at line 51 of file surface_texture_external_texture.h.


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