Description
Currently, WR will resolve the external_id to gl handle at [1] and then calls the release texture callback at [2]. The external texture will be released in the release callback. That will have a problem when we call render() several times without updating a new display_list data.
So, I would try to extend the callback function sets to 4 functions:
a) get()
Get the correspond external_id object into WR. It also means that WR will hold that object until the release() callback.
b) lock()
WR will read the texture content for rendering. The WR client could not change the texture content until unlock() call.
c) unlock()
Unlock the external texture object.
d) release()
Release the external texture object. Then, the WR client could release the object after this call.
When we add a external texture, the get() call will be used.
When we try to resolve the external texture id, the lock() call will be used.
When the rendering is done, the unlock() call will be used.
Finally, when we try to remove the old textures(as expire_old_resources()), the release() call will be used.
[1] resolve_source_texture
webrender/webrender/src/renderer.rs
Line 846 in 8b8e97b
[2] release_external_textures
webrender/webrender/src/renderer.rs
Line 1574 in 8b8e97b
[3] expire_old_resources
webrender/webrender/src/resource_cache.rs
Line 154 in 8b8e97b