Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3079cb7c authored by Corey Tabaka's avatar Corey Tabaka Committed by Alex Vakulenko
Browse files

Use generic libpdx event bits facility in libvrflinger and bufferhubd.

Use the generic event bits abstraction to support UDS and ServiceFS
backends properly.

Bug: 34466748
Test: start/stop basicvr repeatedly; observe stable bufferhub counts.
Change-Id: I9f2ea67c25860ad7fb931938991a29a37f3391fc
parent a8a92784
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -71,6 +71,15 @@ class BufferHubBuffer : public pdx::Client {
  }

  using Client::event_fd;

  Status<int> GetEventMask(int events) {
    if (auto* client_channel = GetChannel()) {
      return client_channel->GetEventMask(events);
    } else {
      return pdx::ErrorStatus(EINVAL);
    }
  }

  native_handle_t* native_handle() const {
    return const_cast<native_handle_t*>(slices_[0].handle());
  }
@@ -158,8 +167,9 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> {
  int Post(const LocalHandle& ready_fence) {
    return Post(ready_fence, nullptr, 0);
  }
  template <typename Meta, typename = typename std::enable_if<
                               !std::is_void<Meta>::value>::type>
  template <
      typename Meta,
      typename = typename std::enable_if<!std::is_void<Meta>::value>::type>
  int Post(const LocalHandle& ready_fence, const Meta& meta) {
    return Post(ready_fence, &meta, sizeof(meta));
  }
+10 −0
Original line number Diff line number Diff line
@@ -396,6 +396,16 @@ void DisplaySurface::OnPostConsumer(

void DisplaySurface::HandleConsumerEvents(
    const std::shared_ptr<BufferConsumer>& consumer, int events) {
  auto status = consumer->GetEventMask(events);
  if (!status) {
    ALOGW(
        "DisplaySurface::HandleConsumerEvents: Failed to get event mask for "
        "consumer: %s",
        status.GetErrorMessage().c_str());
    return;
  }

  events = status.get();
  if (events & EPOLLHUP) {
    ALOGD_IF(TRACE,
             "DisplaySurface::HandleConsumerEvents: removing event handler for "
+9 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ std::string BufferHubService::DumpState(size_t /*max_length*/) {
        // consumer_count is tracked by producer. When it's zero, producer must
        // have already hung up and the consumer is orphaned.
        stream << std::setw(14) << "Orphaned.";
        stream << (" channel_id=" + std::to_string(channel->channel_id()));
        stream << std::endl;
        continue;
      }
@@ -433,6 +434,9 @@ bool BufferHubService::RemoveNamedBuffer(const ProducerChannel& buffer) {

void BufferHubChannel::SignalAvailable() {
  ATRACE_NAME("BufferHubChannel::SignalAvailable");
  ALOGD_IF(TRACE,
           "BufferHubChannel::SignalAvailable: channel_id=%d buffer_id=%d",
           channel_id(), buffer_id());
  if (!IsDetached()) {
    const int ret = service_->ModifyChannelEvents(channel_id_, 0, POLLIN);
    ALOGE_IF(ret < 0,
@@ -446,6 +450,9 @@ void BufferHubChannel::SignalAvailable() {

void BufferHubChannel::ClearAvailable() {
  ATRACE_NAME("BufferHubChannel::ClearAvailable");
  ALOGD_IF(TRACE,
           "BufferHubChannel::ClearAvailable: channel_id=%d buffer_id=%d",
           channel_id(), buffer_id());
  if (!IsDetached()) {
    const int ret = service_->ModifyChannelEvents(channel_id_, POLLIN, 0);
    ALOGE_IF(ret < 0,
@@ -459,6 +466,8 @@ void BufferHubChannel::ClearAvailable() {

void BufferHubChannel::Hangup() {
  ATRACE_NAME("BufferHubChannel::Hangup");
  ALOGD_IF(TRACE, "BufferHubChannel::Hangup: channel_id=%d buffer_id=%d",
           channel_id(), buffer_id());
  if (!IsDetached()) {
    const int ret = service_->ModifyChannelEvents(channel_id_, 0, POLLHUP);
    ALOGE_IF(
+3 −2
Original line number Diff line number Diff line
@@ -27,8 +27,9 @@ ConsumerChannel::ConsumerChannel(BufferHubService* service, int buffer_id,
}

ConsumerChannel::~ConsumerChannel() {
  ALOGD_IF(TRACE, "ConsumerChannel::~ConsumerChannel: channel_id=%d",
           channel_id());
  ALOGD_IF(TRACE,
           "ConsumerChannel::~ConsumerChannel: channel_id=%d buffer_id=%d",
           channel_id(), buffer_id());

  if (auto producer = GetProducer()) {
    if (!handled_)  // Producer is waiting for our Release.
+9 −8
Original line number Diff line number Diff line
@@ -60,8 +60,9 @@ std::shared_ptr<ProducerChannel> ProducerChannel::Create(
}

ProducerChannel::~ProducerChannel() {
  ALOGD_IF(TRACE, "ProducerChannel::~ProducerChannel: channel_id=%d",
           channel_id());
  ALOGD_IF(TRACE,
           "ProducerChannel::~ProducerChannel: channel_id=%d buffer_id=%d",
           channel_id(), buffer_id());
  for (auto consumer : consumer_channels_)
    consumer->OnProducerClosed();
}
@@ -274,8 +275,9 @@ int ProducerChannel::OnConsumerRelease(Message&, LocalFence release_fence) {
  // Attempt to merge the fences if necessary.
  if (release_fence) {
    if (returned_fence_) {
      LocalFence merged_fence(sync_merge(
          "bufferhub_merged", returned_fence_.get_fd(), release_fence.get_fd()));
      LocalFence merged_fence(sync_merge("bufferhub_merged",
                                         returned_fence_.get_fd(),
                                         release_fence.get_fd()));
      const int error = errno;
      if (!merged_fence) {
        ALOGE("ProducerChannel::OnConsumerRelease: Failed to merge fences: %s",
@@ -366,10 +368,9 @@ bool ProducerChannel::CheckAccess(int euid, int egid) {
bool ProducerChannel::CheckParameters(int width, int height, int format,
                                      int usage, size_t meta_size_bytes,
                                      size_t slice_count) {
  return slices_.size() == slice_count &&
         meta_size_bytes == meta_size_bytes_ && slices_[0].width() == width &&
         slices_[0].height() == height && slices_[0].format() == format &&
         slices_[0].usage() == usage;
  return slices_.size() == slice_count && meta_size_bytes == meta_size_bytes_ &&
         slices_[0].width() == width && slices_[0].height() == height &&
         slices_[0].format() == format && slices_[0].usage() == usage;
}

}  // namespace dvr