Flutter Engine
 
Loading...
Searching...
No Matches
surface_texture_external_texture.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_H_
7
8#include <GLES/gl.h>
9
12#include "flutter/third_party/skia/include/core/SkM44.h"
13
14namespace flutter {
15
16//------------------------------------------------------------------------------
17/// @brief Instances of external textures peered to
18/// `android.graphics.SurfaceTexture`.
19///
20/// SurfaceTextures are used on older versions of Android (API <
21/// 29). On newer versions, the Android Hardware Buffer backend
22/// `flutter::ImageExternalTexture` instances are used instead.
23///
24/// Due to the way surface textures are designed, it is not possible
25/// to have a Vulkan renderer interoperate with such textures.
26/// Consequently, both Skia and Impeller only have OpenGL
27/// implementations for these kinds of textures.
28///
29/// This is an abstract base class. Minimally, subclasses override
30/// the pure virtual `ProcessFrame` method to bind the package
31/// specific texture implementation to the surface texture.
32///
34 public:
36 int64_t id,
37 const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture,
38 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
39
40 // |Texture|
42
43 protected:
44 //----------------------------------------------------------------------------
45 /// @brief Subclasses override this method to bind the OpenGL texture
46 /// resource represented by this surface texture to the package
47 /// specific texture (SkImage, impeller::Texture, etc...).
48 ///
49 /// @important The state of texture should be AttachmentState::kAttached
50 /// after a call to this method. That is the responsibility of the
51 /// subclass.
52 ///
53 /// @param context The context.
54 /// @param[in] bounds The bounds of the texture.
55 ///
56 virtual void ProcessFrame(PaintContext& context, const SkRect& bounds) = 0;
57
58 virtual void DrawFrame(PaintContext& context,
59 const SkRect& bounds,
60 const DlImageSampling sampling) const;
61
62 //----------------------------------------------------------------------------
63 /// @brief Get the transformation that should be applied to the UV
64 /// texture coordinates when sampling from this texture.
65 ///
66 /// @return The current uv transformation.
67 ///
68 const SkM44& GetCurrentUVTransformation() const;
69
70 //----------------------------------------------------------------------------
71 /// @brief Provides an opportunity for the subclasses to sever the
72 /// connection between the OpenGL texture resource represented by
73 /// this surface texture and the underlying package handle
74 /// (SkImage, impeller::Texture, etc...).
75 ///
76 /// @important It is the responsibility of the subclass to ensure that a
77 /// context is current when this call is made. Subclass can do
78 /// this by overriding this method, making the context current in
79 /// the implementation and calling the base class method.
80 ///
81 virtual void Detach();
82
83 //----------------------------------------------------------------------------
84 /// @brief Attaches the given OpenGL texture handle to the surface
85 /// texture via a bind operation.
86 ///
87 /// @important It is the responsibility of the subclass to ensure that a
88 /// context is current when this call is made. Subclass can do
89 /// this by overriding this method, making the context current in
90 /// the implementation and calling the base class method.
91 ///
92 /// @param[in] gl_tex_id The gl tex identifier
93 ///
94 void Attach(int gl_tex_id);
95
96 bool ShouldUpdate();
97
98 //----------------------------------------------------------------------------
99 /// @brief Update the surface texture contents and transformation matrix.
100 ///
101 void Update();
102
103 //----------------------------------------------------------------------------
104 /// @brief Specifies how this instance is bound to the underlying surface
105 /// texture.
106 ///
108
109 std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
112 sk_sp<flutter::DlImage> dl_image_;
113
114 private:
115 SkM44 transform_;
116
117 // |Texture|
118 void Paint(PaintContext& context,
119 const DlRect& bounds,
120 bool freeze,
121 const DlImageSampling sampling) override;
122
123 // |ContextListener|
124 void OnGrContextCreated() override;
125
126 // |ContextListener|
127 void OnGrContextDestroyed() override;
128
129 // |Texture|
130 void MarkNewFrameAvailable() override;
131
132 // |Texture|
133 void OnTextureUnregistered() override;
134
136};
137
138} // namespace flutter
139
140#endif // FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_H_
Instances of external textures peered to android.graphics.SurfaceTexture.
AttachmentState
Specifies how this instance is bound to the underlying surface texture.
virtual void DrawFrame(PaintContext &context, const SkRect &bounds, const DlImageSampling sampling) const
fml::jni::ScopedJavaGlobalRef< jobject > surface_texture_
void Attach(int gl_tex_id)
Attaches the given OpenGL texture handle to the surface texture via a bind operation.
std::shared_ptr< PlatformViewAndroidJNI > jni_facade_
virtual void ProcessFrame(PaintContext &context, const SkRect &bounds)=0
Subclasses override this method to bind the OpenGL texture resource represented by this surface textu...
const SkM44 & GetCurrentUVTransformation() const
Get the transformation that should be applied to the UV texture coordinates when sampling from this t...
virtual void Detach()
Provides an opportunity for the subclasses to sever the connection between the OpenGL texture resourc...
void Update()
Update the surface texture contents and transformation matrix.
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27