bool NativeDisplayEventReceiver::processPendingEvents( nsecs_t* outTimestamp, int32_t* outId, uint32_t* outCount) { bool gotVsync = false; DisplayEventReceiver::Event buf[EVENT_BUFFER_SIZE]; ssize_t n; while ((n = mReceiver.getEvents(buf, EVENT_BUFFER_SIZE)) > 0) { ALOGV("receiver %p ~ Read %d events.", this, int(n)); for (ssize_t i = 0; i < n; i++) { const DisplayEventReceiver::Event& ev = buf[i]; switch (ev.header.type) { case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: // Later vsync events will just overwrite the info from earlier // ones. That's fine, we only care about the most recent. gotVsync = true; *outTimestamp = ev.header.timestamp; *outId = ev.header.id; *outCount = ev.vsync.count; break; case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: dispatchHotplug(ev.header.timestamp, ev.header.id, ev.hotplug.connected); break; default: ALOGW("receiver %p ~ ignoring unknown event type %#x", this, ev.header.type); break; } } } if (n < 0) { ALOGW("Failed to get events from display event receiver, status=%d", status_t(n)); } return gotVsync; }
bool NativeDisplayEventReceiver::readLastVsyncMessage( nsecs_t* outTimestamp, int32_t* outId, uint32_t* outCount) { android::DisplayEventReceiver::Event buf[EVENT_BUFFER_SIZE]; ssize_t n; while ((n = mReceiver.getEvents(buf, EVENT_BUFFER_SIZE)) > 0) { ALOGV("receiver %p ~ Read %d events.", this, int(n)); while (n-- > 0) { const android::DisplayEventReceiver::Event& ev = buf[n]; if (ev.header.type == android::DisplayEventReceiver::DISPLAY_EVENT_VSYNC) { *outTimestamp = ev.header.timestamp; *outId = ev.header.id; *outCount = ev.vsync.count; return true; // stop at last vsync in the buffer } if (ev.header.type == android::DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG) { dispatchHotplug(ev.header.timestamp, ev.header.id, ev.hotplug.connected); } } } if (n < 0) { ALOGW("Failed to get events from display event receiver, status=%d", android::status_t(n)); } return false; }