Reuse texture cache in ios_external_texture_gl. (flutter/engine#9806)
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 commit is contained in:
@@ -31,6 +31,7 @@ class IOSExternalTextureGL : public flutter::Texture {
|
|||||||
|
|
||||||
void EnsureTextureCacheExists();
|
void EnsureTextureCacheExists();
|
||||||
|
|
||||||
|
bool new_frame_ready_ = false;
|
||||||
NSObject<FlutterTexture>* external_texture_;
|
NSObject<FlutterTexture>* external_texture_;
|
||||||
fml::CFRef<CVOpenGLESTextureCacheRef> cache_ref_;
|
fml::CFRef<CVOpenGLESTextureCacheRef> cache_ref_;
|
||||||
fml::CFRef<CVOpenGLESTextureRef> texture_ref_;
|
fml::CFRef<CVOpenGLESTextureRef> texture_ref_;
|
||||||
|
|||||||
@@ -53,17 +53,24 @@ void IOSExternalTextureGL::CreateTextureFromPixelBuffer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IOSExternalTextureGL::NeedUpdateTexture(bool freeze) {
|
||||||
|
// Update texture if `texture_ref_` is reset to `nullptr` when GrContext
|
||||||
|
// is destroied or new frame is ready.
|
||||||
|
return (!freeze && new_frame_ready_) || !texture_ref_;
|
||||||
|
}
|
||||||
|
|
||||||
void IOSExternalTextureGL::Paint(SkCanvas& canvas,
|
void IOSExternalTextureGL::Paint(SkCanvas& canvas,
|
||||||
const SkRect& bounds,
|
const SkRect& bounds,
|
||||||
bool freeze,
|
bool freeze,
|
||||||
GrContext* context) {
|
GrContext* context) {
|
||||||
EnsureTextureCacheExists();
|
EnsureTextureCacheExists();
|
||||||
if (!freeze) {
|
if (NeedUpdateTexture(freeze)) {
|
||||||
auto pixelBuffer = [external_texture_ copyPixelBuffer];
|
auto pixelBuffer = [external_texture_ copyPixelBuffer];
|
||||||
if (pixelBuffer) {
|
if (pixelBuffer) {
|
||||||
buffer_ref_.Reset(pixelBuffer);
|
buffer_ref_.Reset(pixelBuffer);
|
||||||
}
|
}
|
||||||
CreateTextureFromPixelBuffer();
|
CreateTextureFromPixelBuffer();
|
||||||
|
new_frame_ready_ = false;
|
||||||
}
|
}
|
||||||
if (!texture_ref_) {
|
if (!texture_ref_) {
|
||||||
return;
|
return;
|
||||||
@@ -93,6 +100,8 @@ void IOSExternalTextureGL::OnGrContextDestroyed() {
|
|||||||
cache_ref_.Reset(nullptr);
|
cache_ref_.Reset(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IOSExternalTextureGL::MarkNewFrameAvailable() {}
|
void IOSExternalTextureGL::MarkNewFrameAvailable() {
|
||||||
|
new_frame_ready_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace flutter
|
} // namespace flutter
|
||||||
|
|||||||
Reference in New Issue
Block a user