[AChoreographer] Add private api that decouples from ALooper.
For ease of use by HWUI, we'll get rid of the reliance of a thread-local
ALooper:
* Rather than using AChoreographer_getInstance to access a thread-local
AChoreographer instance, the caller will be expected to create and
destroy its own instnace.
* For use by HWUI's own looper instance, _getFd() will expose the
underlying file descriptor from which events can be listened. The
corresponding choreographer combined callback can be called to flush
pending display events.
Bug: 136262896
Test: builds
Change-Id: I94f102da22974cbad37f21a68d2f04ac0cec5c78
diff --git a/libs/gui/DisplayEventDispatcher.cpp b/libs/gui/DisplayEventDispatcher.cpp
index 208d729..8af1a1c 100644
--- a/libs/gui/DisplayEventDispatcher.cpp
+++ b/libs/gui/DisplayEventDispatcher.cpp
@@ -50,17 +50,20 @@
return result;
}
- int rc = mLooper->addFd(mReceiver.getFd(), 0, Looper::EVENT_INPUT, this, NULL);
- if (rc < 0) {
- return UNKNOWN_ERROR;
+ if (mLooper != nullptr) {
+ int rc = mLooper->addFd(mReceiver.getFd(), 0, Looper::EVENT_INPUT, this, NULL);
+ if (rc < 0) {
+ return UNKNOWN_ERROR;
+ }
}
+
return OK;
}
void DisplayEventDispatcher::dispose() {
ALOGV("dispatcher %p ~ Disposing display event dispatcher.", this);
- if (!mReceiver.initCheck()) {
+ if (!mReceiver.initCheck() && mLooper != nullptr) {
mLooper->removeFd(mReceiver.getFd());
}
}
@@ -101,6 +104,10 @@
mConfigChangeFlag = configChangeFlag;
}
+int DisplayEventDispatcher::getFd() {
+ return mReceiver.getFd();
+}
+
int DisplayEventDispatcher::handleEvent(int, int events, void*) {
if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
ALOGE("Display event receiver pipe was closed or an error occurred. "
diff --git a/libs/gui/include/gui/DisplayEventDispatcher.h b/libs/gui/include/gui/DisplayEventDispatcher.h
index 0b71801..679d572 100644
--- a/libs/gui/include/gui/DisplayEventDispatcher.h
+++ b/libs/gui/include/gui/DisplayEventDispatcher.h
@@ -32,6 +32,8 @@
void dispose();
status_t scheduleVsync();
void toggleConfigEvents(ISurfaceComposer::ConfigChanged configChangeFlag);
+ int getFd();
+ virtual int handleEvent(int receiveFd, int events, void* data);
protected:
virtual ~DisplayEventDispatcher() = default;
@@ -48,7 +50,6 @@
virtual void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId,
int32_t configId, nsecs_t vsyncPeriod) = 0;
- virtual int handleEvent(int receiveFd, int events, void* data);
bool processPendingEvents(nsecs_t* outTimestamp, PhysicalDisplayId* outDisplayId,
uint32_t* outCount);
};