opengl: fix a race condition when unloading gl driver

Previously, EGL apis call clearError() at the first place including those core
apis which initialize the driver. Calling clearError() before the driver has
been loaded is basically a no-op.

Later the driver unloading mechanism was added to support Angle and updatable
driver with EGL/GL driver still preloaded in Zygote. However, calling
clearError() on another thread races with the driver unloading process. So this
change moves the clearError() calls after the driver has been successfully
unloaded and reloaded, so that the initial core apis will be protected by the
driver loading lock in the loader.

For those non-core apis, they could still be incorrectly called before calling
any of those core apis on another thread when the driver unloading and reloading
is still on going. Since this scenario is supposed to error out anyway, so the
apps need to use EGL apis correctly by themselves.

Bug: 140072978
Test: CtsAngleDeveloperOptionHostTest
Change-Id: Ica5b19edc0dfb0a0910f56c1442eaff63f76b35a
Merged-In: Ica5b19edc0dfb0a0910f56c1442eaff63f76b35a
1 file changed