SF: Clean up HWC2::Layer ownership
Changes the HWC2::Display::createLayer() call to return a shared_ptr instead of a bare pointer. Also if the HWC2::Display is disconnected, instead of directly destroying the HWC2::Layers associated with the display, a new call is made to clear the display information from the layer. For safety, checks are added to take an early out if the display information isn't set for any call where it is used. The CompositionEngine code was already creating a shared_ptr for the createLayer call, and expecting the pointer to be valid until it released it via destroyLayer. However a hotplug disconnect could leave the CompositionEngine code holding an invalid pointer until the next display refresh, and it could lead to bad memory accesses if the pointer was dereferenced. CompositionEngine itself did not do so -- it released its ownership of the layer (and the associated display) without accessing them. This seems to have only affected "dumpsys SurfaceFlinger", if it happened to be executed after the disconnect, and before another refresh, and only because it tried to print out the HWC layer id. Bug: 181061001 Test: libsurfaceflinger_unittest Test: libcompositionengine_test Test: dumpsys SurfaceFlinger # after hotplug event Change-Id: I508d6aa8ef7a6af848dd54198408d5f311175070 Merged-In: I508d6aa8ef7a6af848dd54198408d5f311175070
Loading
Please register or sign in to comment