More efficient swapBuffers

Previously, we were using glFinish() in the host to make sure
that a buffer that we are presenting has been completely written to.
That is bad for performance, because it usually means to block the CPU
until the GPU's command queue is completely empty and all operations
have completed.

This CL uses eglCreateSyncKHR with a native fence FD to guarantee
the draw buffer is finished before presenting. The idea is that
after rcFlushWindowColorBufferAsync has queued up GPU commands to
finish up the draw buffer, eglCreateSyncKHR follows that up with a fence
command.

The fence command in turn is represented by a FD (by providing
EGL_SYNC_NATIVE_FENCE_ANDROID as the sync object type). Giving that FD
to queueBuffer tells SurfaceFlinger/BufferQueue not to do anything
that depends on the contents of that buffer until the fence command
has completed.

Theoretically, we are supposed to wait on the FD coming from dequeueBuffer
as well, to make sure no one else is using it, but in practice,
it matters much less; we will just overwrite the contents anyway, and it
has not proved to be any problem in terms of visual artifacts.

This is part of a sequential, multi-CL change. There is also
a corresponding multi-CL change on the host side:

https://android-review.googlesource.com/#/q/topic:emu-glsync-host

The changes in the system image are as follows:

platform/build:

https://googleplex-android-review.git.corp.google.com/1024926

device/generic/goldfish:

https://googleplex-android-review.git.corp.google.com/1230942

device/generic/goldfish-opengl:

https://googleplex-android-review.git.corp.google.com/1219535
https://googleplex-android-review.git.corp.google.com/1219536
https://googleplex-android-review.git.corp.google.com/1219537
https://googleplex-android-review.git.corp.google.com/1219538
https://googleplex-android-review.git.corp.google.com/1219539
https://googleplex-android-review.git.corp.google.com/1219570 <- needed
https://googleplex-android-review.git.corp.google.com/1219571 <- this CL

Change-Id: I3dd1b69c77665ac0143bd5a302e6a5a04736c9ea
1 file changed
tree: aff173b21e63625901cdaaf3ac0efd6b131ea982
  1. host/
  2. shared/
  3. system/
  4. tests/
  5. Android.mk
  6. common.mk
  7. README