Toggle for RenderEngine to cleanup texture memory.

Currently RenderEngine does not rebind texture memory after it is done
drawing, so buffers may not be freed until the corresponding texture is
deleted. For SurfaceFlinger this is more acceptable since layers tend to
reuse buffers and they own their own texture name, so it's more natural
to implicitly tie memory lifecycle to layer lifecycle since the buffers
won't need to be free until the layer is deleted anyways.
But for mediaserver it's not acceptable, since thumbnail generation is
rare and texture generation is expensive, so if we don't clean up
texture resources properly then mediaserver hangs on to a video frame
until the next time a thumbnail is generated, which is very bad for HDR
frames since it's a multi-megabyte overhead.

This patch will solve this for mediaserver by adding a toggle to
cleanupPostRender. It's likely that SurfaceFlinger can benefit from this
as well since rebinding memory is fast, but more investigation would be
needed to see if that is the case, and this patch is less risky to be
applied to other branches.

Bug: 162202251
Test: librenderengine_test
Test: Launch custom apk with thumbnail generation
Test: adb shell dumpsys meminfo mediaserver
Change-Id: Iec7f65c4911b5cbf2189fa33929bbcfa97bb4c14
Merged-In: Iec7f65c4911b5cbf2189fa33929bbcfa97bb4c14
5 files changed