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

Commit bb752684 authored by Ady Abraham's avatar Ady Abraham
Browse files

Remove libvrflinger

Not used anymore.

Test: build
Change-Id: If4c6494d1bf3a32516ada3670ee449e2a047c7ed
parent 9fc2805c
Loading
Loading
Loading
Loading

libs/vr/libvrflinger/Android.bp

deleted100644 → 0
+0 −111
Original line number Diff line number Diff line
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_native_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_native_license"],
}

sourceFiles = [
    "acquired_buffer.cpp",
    "epoll_event_dispatcher.cpp",
    "display_manager_service.cpp",
    "display_service.cpp",
    "display_surface.cpp",
    "hardware_composer.cpp",
    "vr_flinger.cpp",
]

includeFiles = ["include"]

staticLibraries = [
    "libdisplay",
    "libdvrcommon",
    "libperformance",
    "libvrsensor",
    "libbroadcastring",
    "libvr_manager",
    "libbroadcastring",
    "libaidlcommonsupport",
]

sharedLibraries = [
    "android.frameworks.vr.composer@2.0",
    "android.hardware.graphics.allocator@2.0",
    "android.hardware.graphics.composer@2.1",
    "android.hardware.graphics.composer@2.2",
    "android.hardware.graphics.composer@2.3",
    "android.hardware.graphics.composer@2.4",
    "android.hardware.graphics.composer3-V1-ndk",
    "libbinder",
    "libbinder_ndk",
    "libbase",
    "libbufferhubqueue",
    "libcutils",
    "liblog",
    "libhardware",
    "libnativewindow",
    "libprocessgroup",
    "libutils",
    "libEGL",
    "libGLESv1_CM",
    "libGLESv2",
    "libvulkan",
    "libui",
    "libgui",
    "libsync",
    "libhidlbase",
    "libfmq",
    "libpdx_default_transport",
]

headerLibraries = [
    "android.hardware.graphics.composer@2.1-command-buffer",
    "android.hardware.graphics.composer@2.2-command-buffer",
    "android.hardware.graphics.composer@2.3-command-buffer",
    "android.hardware.graphics.composer@2.4-command-buffer",
    "android.hardware.graphics.composer3-command-buffer",
    "libdvr_headers",
    "libsurfaceflinger_headers",
]

cc_library_static {
    srcs: sourceFiles,
    export_include_dirs: includeFiles,

    clang: true,
    cflags: [
        "-DLOG_TAG=\"vr_flinger\"",
        "-DTRACE=0",
        "-DATRACE_TAG=ATRACE_TAG_GRAPHICS",
        "-DGL_GLEXT_PROTOTYPES",
        "-DEGL_EGLEXT_PROTOTYPES",
        "-Wall",
        "-Werror",
        "-Wno-error=sign-compare", // to fix later
        "-Wno-unused-variable",
    ],
    shared_libs: sharedLibraries,
    whole_static_libs: staticLibraries,
    header_libs: headerLibraries,
    name: "libvrflinger",
}

subdirs = [
    "tests",
]
+0 −103
Original line number Diff line number Diff line
#include "acquired_buffer.h"

#include <log/log.h>
#include <sync/sync.h>

using android::pdx::LocalHandle;

namespace android {
namespace dvr {

AcquiredBuffer::AcquiredBuffer(const std::shared_ptr<ConsumerBuffer>& buffer,
                               LocalHandle acquire_fence, std::size_t slot)
    : buffer_(buffer), acquire_fence_(std::move(acquire_fence)), slot_(slot) {}

AcquiredBuffer::AcquiredBuffer(const std::shared_ptr<ConsumerBuffer>& buffer,
                               int* error) {
  LocalHandle fence;
  const int ret = buffer->Acquire(&fence);

  if (error)
    *error = ret;

  if (ret < 0) {
    ALOGW("AcquiredBuffer::AcquiredBuffer: Failed to acquire buffer: %s",
          strerror(-ret));
    buffer_ = nullptr;
    // Default construct sets acquire_fence_ to empty.
  } else {
    buffer_ = buffer;
    acquire_fence_ = std::move(fence);
  }
}

AcquiredBuffer::AcquiredBuffer(AcquiredBuffer&& other) noexcept {
  *this = std::move(other);
}

AcquiredBuffer::~AcquiredBuffer() { Release(LocalHandle(kEmptyFence)); }

AcquiredBuffer& AcquiredBuffer::operator=(AcquiredBuffer&& other) noexcept {
  if (this != &other) {
    Release();

    using std::swap;
    swap(buffer_, other.buffer_);
    swap(acquire_fence_, other.acquire_fence_);
    swap(slot_, other.slot_);
  }
  return *this;
}

bool AcquiredBuffer::IsAvailable() const {
  if (IsEmpty())
    return false;

  // Only check the fence if the acquire fence is not empty.
  if (acquire_fence_) {
    const int ret = sync_wait(acquire_fence_.Get(), 0);
    ALOGD_IF(TRACE || (ret < 0 && errno != ETIME),
             "AcquiredBuffer::IsAvailable: buffer_id=%d acquire_fence=%d "
             "sync_wait()=%d errno=%d.",
             buffer_->id(), acquire_fence_.Get(), ret, ret < 0 ? errno : 0);
    if (ret == 0) {
      // The fence is completed, so to avoid further calls to sync_wait we close
      // it here.
      acquire_fence_.Close();
    }
    return ret == 0;
  } else {
    return true;
  }
}

LocalHandle AcquiredBuffer::ClaimAcquireFence() {
  return std::move(acquire_fence_);
}

std::shared_ptr<ConsumerBuffer> AcquiredBuffer::ClaimBuffer() {
  return std::move(buffer_);
}

int AcquiredBuffer::Release(LocalHandle release_fence) {
  ALOGD_IF(TRACE, "AcquiredBuffer::Release: buffer_id=%d release_fence=%d",
           buffer_ ? buffer_->id() : -1, release_fence.Get());
  if (buffer_) {
    const int ret = buffer_->ReleaseAsync();
    if (ret < 0) {
      ALOGE("AcquiredBuffer::Release: Failed to release buffer %d: %s",
            buffer_->id(), strerror(-ret));
      if (ret != -ESHUTDOWN)
        return ret;
    }

    buffer_ = nullptr;
  }

  acquire_fence_.Close();
  slot_ = 0;
  return 0;
}

}  // namespace dvr
}  // namespace android
+0 −87
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_SERVICES_DISPLAYD_ACQUIRED_BUFFER_H_
#define ANDROID_DVR_SERVICES_DISPLAYD_ACQUIRED_BUFFER_H_

#include <pdx/file_handle.h>
#include <private/dvr/consumer_buffer.h>

#include <memory>

namespace android {
namespace dvr {

// Manages the ACQUIRE/RELEASE ownership cycle of a ConsumerBuffer.
class AcquiredBuffer {
 public:
  static constexpr int kEmptyFence = pdx::LocalHandle::kEmptyFileHandle;

  AcquiredBuffer() : buffer_(nullptr), acquire_fence_(kEmptyFence) {}

  // Constructs an AcquiredBuffer from a ConsumerBuffer pointer and an acquire
  // fence. The ConsumerBuffer MUST be in the ACQUIRED state prior to calling
  // this constructor; the constructor does not attempt to ACQUIRE the buffer
  // itself.
  AcquiredBuffer(const std::shared_ptr<ConsumerBuffer>& buffer,
                 pdx::LocalHandle acquire_fence, std::size_t slot = 0);

  // Constructs an AcquiredBuffer from a ConsumerBuffer. The ConsumerBuffer MUST
  // be in the POSTED state prior to calling this constructor, as this
  // constructor attempts to ACQUIRE the buffer. If ACQUIRING the buffer fails
  // this instance is left in the empty state. An optional error code is
  // returned in |error|, which may be nullptr if not needed.
  AcquiredBuffer(const std::shared_ptr<ConsumerBuffer>& buffer, int* error);

  // Move constructor. Behaves similarly to the move assignment operator below.
  AcquiredBuffer(AcquiredBuffer&& other) noexcept;

  ~AcquiredBuffer();

  // Move assignment operator. Moves the ConsumerBuffer and acquire fence from
  // |other| into this instance after RELEASING the current ConsumerBuffer and
  // closing the acquire fence. After the move |other| is left in the empty
  // state.
  AcquiredBuffer& operator=(AcquiredBuffer&& other) noexcept;

  // Accessors for the underlying ConsumerBuffer, the acquire fence, and the
  // use-case specific sequence value from the acquisition (see
  // private/dvr/consumer_buffer.h).
  std::shared_ptr<ConsumerBuffer> buffer() const { return buffer_; }
  int acquire_fence() const { return acquire_fence_.Get(); }

  // When non-empty, returns true if the acquired fence was signaled (or if the
  // fence is empty). Returns false when empty or if the fence is not signaled.
  bool IsAvailable() const;

  bool IsEmpty() const { return buffer_ == nullptr; }

  // Returns the acquire fence, passing ownership to the caller.
  pdx::LocalHandle ClaimAcquireFence();

  // Returns the buffer, passing ownership to the caller. Caller is responsible
  // for calling Release on the returned buffer.
  std::shared_ptr<ConsumerBuffer> ClaimBuffer();

  // Releases the ConsumerBuffer, passing the release fence in |release_fence|
  // to the producer. On success, the ConsumerBuffer and acquire fence are set
  // to empty state; if release fails, the ConsumerBuffer and acquire fence are
  // left in place and a negative error code is returned.
  int Release(pdx::LocalHandle release_fence = {});

  // Returns the slot in the queue this buffer belongs to. Buffers that are not
  // part of a queue return 0.
  std::size_t slot() const { return slot_; }

 private:
  std::shared_ptr<ConsumerBuffer> buffer_;
  // Mutable so that the fence can be closed when it is determined to be
  // signaled during IsAvailable().
  mutable pdx::LocalHandle acquire_fence_;
  std::size_t slot_{0};

  AcquiredBuffer(const AcquiredBuffer&) = delete;
  void operator=(const AcquiredBuffer&) = delete;
};

}  // namespace dvr
}  // namespace android

#endif  // ANDROID_DVR_SERVICES_DISPLAYD_ACQUIRED_BUFFER_H_
+0 −142
Original line number Diff line number Diff line
#include "display_manager_service.h"

#include <pdx/channel_handle.h>
#include <pdx/default_transport/service_endpoint.h>
#include <private/android_filesystem_config.h>
#include <private/dvr/display_protocol.h>
#include <private/dvr/trusted_uids.h>
#include <sys/poll.h>

#include <array>

using android::dvr::display::DisplayManagerProtocol;
using android::pdx::Channel;
using android::pdx::LocalChannelHandle;
using android::pdx::Message;
using android::pdx::default_transport::Endpoint;
using android::pdx::ErrorStatus;
using android::pdx::rpc::DispatchRemoteMethod;
using android::pdx::rpc::IfAnyOf;
using android::pdx::rpc::RemoteMethodError;

namespace android {
namespace dvr {

void DisplayManager::SetNotificationsPending(bool pending) {
  auto status = service_->ModifyChannelEvents(channel_id_, pending ? 0 : POLLIN,
                                              pending ? POLLIN : 0);
  ALOGE_IF(!status,
           "DisplayManager::SetNotificationPending: Failed to modify channel "
           "events: %s",
           status.GetErrorMessage().c_str());
}

DisplayManagerService::DisplayManagerService(
    const std::shared_ptr<DisplayService>& display_service)
    : BASE("DisplayManagerService",
           Endpoint::Create(DisplayManagerProtocol::kClientPath)),
      display_service_(display_service) {
  display_service_->SetDisplayConfigurationUpdateNotifier(
      std::bind(&DisplayManagerService::OnDisplaySurfaceChange, this));
}

std::shared_ptr<pdx::Channel> DisplayManagerService::OnChannelOpen(
    pdx::Message& message) {
  const int user_id = message.GetEffectiveUserId();
  const bool trusted = user_id == AID_ROOT || IsTrustedUid(user_id);

  // Check if the display_manager_ has a defunct channel.
  if (display_manager_ && !HasChannelId(display_manager_->channel_id())) {
    ALOGE("DisplayManagerService::OnChannelOpen: Found defunct channel %d with "
          "no OnChannelClose, clearing prior display manager.",
          display_manager_->channel_id());
    display_manager_ = nullptr;
  }

  // Prevent more than one display manager from registering at a time or
  // untrusted UIDs from connecting.
  if (display_manager_ || !trusted) {
    RemoteMethodError(message, EPERM);
    return nullptr;
  }

  display_manager_ =
      std::make_shared<DisplayManager>(this, message.GetChannelId());
  return display_manager_;
}

void DisplayManagerService::OnChannelClose(
    pdx::Message& /*message*/, const std::shared_ptr<pdx::Channel>& channel) {
  // Unregister the display manager when the channel closes.
  if (display_manager_ == channel)
    display_manager_ = nullptr;
}

pdx::Status<void> DisplayManagerService::HandleMessage(pdx::Message& message) {
  ATRACE_NAME("DisplayManagerService::HandleMessage");
  auto channel = std::static_pointer_cast<DisplayManager>(message.GetChannel());

  switch (message.GetOp()) {
    case DisplayManagerProtocol::GetSurfaceState::Opcode:
      DispatchRemoteMethod<DisplayManagerProtocol::GetSurfaceState>(
          *this, &DisplayManagerService::OnGetSurfaceState, message);
      return {};

    case DisplayManagerProtocol::GetSurfaceQueue::Opcode:
      DispatchRemoteMethod<DisplayManagerProtocol::GetSurfaceQueue>(
          *this, &DisplayManagerService::OnGetSurfaceQueue, message);
      return {};

    default:
      return Service::DefaultHandleMessage(message);
  }
}

pdx::Status<std::vector<display::SurfaceState>>
DisplayManagerService::OnGetSurfaceState(pdx::Message& /*message*/) {
  std::vector<display::SurfaceState> items;

  display_service_->ForEachDisplaySurface(
      SurfaceType::Application,
      [&items](const std::shared_ptr<DisplaySurface>& surface) mutable {
        items.push_back({surface->surface_id(), surface->process_id(),
                         surface->user_id(), surface->attributes(),
                         surface->update_flags(), surface->GetQueueIds()});
        surface->ClearUpdate();
      });

  // The fact that we're in the message handler implies that display_manager_ is
  // not nullptr. No check required, unless this service becomes multi-threaded.
  display_manager_->SetNotificationsPending(false);
  return items;
}

pdx::Status<pdx::LocalChannelHandle> DisplayManagerService::OnGetSurfaceQueue(
    pdx::Message& /*message*/, int surface_id, int queue_id) {
  auto surface = display_service_->GetDisplaySurface(surface_id);
  if (!surface || surface->surface_type() != SurfaceType::Application)
    return ErrorStatus(EINVAL);

  auto queue =
      std::static_pointer_cast<ApplicationDisplaySurface>(surface)->GetQueue(
          queue_id);
  if (!queue)
    return ErrorStatus(EINVAL);

  auto status = queue->CreateConsumerQueueHandle();
  ALOGE_IF(
      !status,
      "DisplayManagerService::OnGetSurfaceQueue: Failed to create consumer "
      "queue for queue_id=%d: %s",
      queue->id(), status.GetErrorMessage().c_str());

  return status;
}

void DisplayManagerService::OnDisplaySurfaceChange() {
  if (display_manager_)
    display_manager_->SetNotificationsPending(true);
}

}  // namespace dvr
}  // namespace android
+0 −74
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_SERVICES_VRFLINGER_DISPLAY_MANAGER_SERVICE_H_
#define ANDROID_DVR_SERVICES_VRFLINGER_DISPLAY_MANAGER_SERVICE_H_

#include <pdx/service.h>
#include <pdx/status.h>
#include <private/dvr/display_protocol.h>

#include "display_service.h"

namespace android {
namespace dvr {

class DisplayManagerService;

// The display manager is a client of the display manager service. This class
// represents the connected client that the display manager service sends
// notifications to.
class DisplayManager : public pdx::Channel {
 public:
  DisplayManager(DisplayManagerService* service, int channel_id)
      : service_(service), channel_id_(channel_id) {}

  int channel_id() const { return channel_id_; }

  // Sets or clears the channel event mask to indicate pending events that the
  // display manager on the other end of the channel should read and handle.
  // When |pending| is true the POLLIN bit is set in the event mask; when
  // |pending| is false the POLLIN bit is cleared in the event mask.
  void SetNotificationsPending(bool pending);

 private:
  DisplayManager(const DisplayManager&) = delete;
  void operator=(const DisplayManager&) = delete;

  DisplayManagerService* service_;
  int channel_id_;
};

// The display manager service marshalls state and events from the display
// service to the display manager.
class DisplayManagerService : public pdx::ServiceBase<DisplayManagerService> {
 public:
  std::shared_ptr<pdx::Channel> OnChannelOpen(pdx::Message& message) override;
  void OnChannelClose(pdx::Message& message,
                      const std::shared_ptr<pdx::Channel>& channel) override;
  pdx::Status<void> HandleMessage(pdx::Message& message) override;

 private:
  friend BASE;

  explicit DisplayManagerService(
      const std::shared_ptr<DisplayService>& display_service);

  pdx::Status<std::vector<display::SurfaceState>> OnGetSurfaceState(
      pdx::Message& message);
  pdx::Status<pdx::LocalChannelHandle> OnGetSurfaceQueue(pdx::Message& message,
                                                         int surface_id,
                                                         int queue_id);

  // Called by the display service to indicate changes to display surfaces that
  // the display manager should evaluate.
  void OnDisplaySurfaceChange();

  DisplayManagerService(const DisplayManagerService&) = delete;
  void operator=(const DisplayManagerService&) = delete;

  std::shared_ptr<DisplayService> display_service_;
  std::shared_ptr<DisplayManager> display_manager_;
};

}  // namespace dvr
}  // namespace android

#endif  // ANDROID_DVR_SERVICES_VRFLINGER_DISPLAY_MANAGER_SERVICE_H_
Loading