preface

We discussed the display Image logic on the Flutter Dart level, where we can see the uit.instantiateImagecodec (bytes) method, So that’s where we’re going to start today and take a look at what the internals of The Flux-Engine do to get the Image data.

The body of the

InstantiateImageCodec

InstantiateImageCodec the method instantiateImageCodec in the Fluvial engine is instantiateImageCodec. The logic in the instantiateImageCodec is to take the parameters from the Dart layer and generate a Codec handle based on the parameters. This Codec handle has ui_codec implementing MultiFrameCodec and SingleFrameCodec, respectively, and then goes back to the Dart layer.

The MakeFromData(buffer) method is the key method, which actually takes the image data collected, analyzes it and returns different Codec.

GetNextFrame

We can see the statement _nextFrame = await _codec.getNextFrame(); So how does getNextFrame go? We can see that the getNextFrame method belongs to MultiFrameCodec. Actually, it looks pretty simple inside the method, and it does a couple of things. 1. Obtain the UI Task thread first. 2. To obtain the current Skia processing Queue 3. 4. Get context switch to the IO GetNextFrameAndInvokeCallback threads run

GetNextFrameAndInvokeCallback inside is divided into three steps

GetNextFrameImage

What you do is basically get the SkImage data for the next frame, and save the key data from the previous frame. Here we can see that there are multiple copies, so it’s all in the I/O thread.

InvokeCallback

What you’re doing here is basically taking the SkImage you just got from GetNextFrameImage, plugging it into the FrameInfo structure, and changing the index of the next frame. Then Callback back in the UI thread.

conclusion

All you do here is select the Codec and parse the image, and the entire process is processed in the IO thread.

Thank you for reading