Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6a90b7f

Browse files
loongliucbracken
authored andcommitted
Reuse texture cache in ios_external_texture_gl
In current implementation, external texture data flow is a producer-consumer model. When painting external texture, it always asks registered external texture object to produce new CVPixelBuffer, then transforms it to texture. `MarkNewFrameAvailable` function is ignored. This commit changes the dataflow. Now ios_external_texture_gl caches previous opengl texture, if no new frame are available, it do not `copyPixelBuffer` method, just uses cached opengl texture to draw. This is a re-land of #9806, which was previously reverted in #11522.
1 parent bf77966 commit 6a90b7f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

shell/platform/darwin/ios/ios_external_texture_gl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class IOSExternalTextureGL : public flutter::Texture {
3030
void CreateTextureFromPixelBuffer();
3131

3232
void EnsureTextureCacheExists();
33+
bool NeedUpdateTexture(bool freeze);
3334

35+
bool new_frame_ready_ = false;
3436
NSObject<FlutterTexture>* external_texture_;
3537
fml::CFRef<CVOpenGLESTextureCacheRef> cache_ref_;
3638
fml::CFRef<CVOpenGLESTextureRef> texture_ref_;

shell/platform/darwin/ios/ios_external_texture_gl.mm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,24 @@
5353
}
5454
}
5555

56+
bool IOSExternalTextureGL::NeedUpdateTexture(bool freeze) {
57+
// Update texture if `texture_ref_` is reset to `nullptr` when GrContext
58+
// is destroied or new frame is ready.
59+
return (!freeze && new_frame_ready_) || !texture_ref_;
60+
}
61+
5662
void IOSExternalTextureGL::Paint(SkCanvas& canvas,
5763
const SkRect& bounds,
5864
bool freeze,
5965
GrContext* context) {
6066
EnsureTextureCacheExists();
61-
if (!freeze) {
67+
if (NeedUpdateTexture(freeze)) {
6268
auto pixelBuffer = [external_texture_ copyPixelBuffer];
6369
if (pixelBuffer) {
6470
buffer_ref_.Reset(pixelBuffer);
6571
}
6672
CreateTextureFromPixelBuffer();
73+
new_frame_ready_ = false;
6774
}
6875
if (!texture_ref_) {
6976
return;
@@ -93,6 +100,8 @@
93100
cache_ref_.Reset(nullptr);
94101
}
95102

96-
void IOSExternalTextureGL::MarkNewFrameAvailable() {}
103+
void IOSExternalTextureGL::MarkNewFrameAvailable() {
104+
new_frame_ready_ = true;
105+
}
97106

98107
} // namespace flutter

0 commit comments

Comments
 (0)