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

Commit a50abc2f authored by Daniel Nicoara's avatar Daniel Nicoara
Browse files

Use IVrComposerClient interface to expose the VR HWC client

Since the VR HWC implements the IVrComposerClient make sure the
implementation inherits from the correct interface.

Bug: 36564122
Test: Ran on device
Change-Id: I5481ab5505f824034944b4df34fb51ee1b86082b
parent d788ad50
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -181,6 +181,13 @@ Composer::Composer(bool useVrComposer)
    if (mClient == nullptr) {
        LOG_ALWAYS_FATAL("failed to create composer client");
    }

    if (mIsUsingVrComposer) {
        sp<IVrComposerClient> vrClient = IVrComposerClient::castFrom(mClient);
        if (vrClient == nullptr) {
            LOG_ALWAYS_FATAL("failed to create vr composer client");
        }
    }
}

std::vector<IComposer::Capability> Composer::getCapabilities()
+174 −10
Original line number Diff line number Diff line
@@ -24,26 +24,63 @@

namespace android {
namespace dvr {
namespace {

using android::hardware::graphics::common::V1_0::PixelFormat;
using android::frameworks::vr::composer::V1_0::IVrComposerClient;

VrComposerClient::VrComposerClient(dvr::VrHwc& hal)
class ComposerClientImpl : public ComposerClient {
 public:
  ComposerClientImpl(android::dvr::VrHwc& hal);
  virtual ~ComposerClientImpl();

 private:
  class VrCommandReader : public ComposerClient::CommandReader {
   public:
    VrCommandReader(ComposerClientImpl& client);
    ~VrCommandReader() override;

    bool parseCommand(IComposerClient::Command command,
                      uint16_t length) override;

   private:
    bool parseSetLayerInfo(uint16_t length);
    bool parseSetClientTargetMetadata(uint16_t length);
    bool parseSetLayerBufferMetadata(uint16_t length);

    IVrComposerClient::BufferMetadata readBufferMetadata();

    ComposerClientImpl& mVrClient;
    android::dvr::VrHwc& mVrHal;

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

  std::unique_ptr<CommandReader> createCommandReader() override;

  dvr::VrHwc& mVrHal;

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

ComposerClientImpl::ComposerClientImpl(android::dvr::VrHwc& hal)
    : ComposerClient(hal), mVrHal(hal) {}

VrComposerClient::~VrComposerClient() {}
ComposerClientImpl::~ComposerClientImpl() {}

std::unique_ptr<ComposerClient::CommandReader>
VrComposerClient::createCommandReader() {
ComposerClientImpl::createCommandReader() {
  return std::unique_ptr<CommandReader>(new VrCommandReader(*this));
}

VrComposerClient::VrCommandReader::VrCommandReader(VrComposerClient& client)
ComposerClientImpl::VrCommandReader::VrCommandReader(ComposerClientImpl& client)
    : CommandReader(client), mVrClient(client), mVrHal(client.mVrHal) {}

VrComposerClient::VrCommandReader::~VrCommandReader() {}
ComposerClientImpl::VrCommandReader::~VrCommandReader() {}

bool VrComposerClient::VrCommandReader::parseCommand(
bool ComposerClientImpl::VrCommandReader::parseCommand(
    IComposerClient::Command command, uint16_t length) {
  IVrComposerClient::VrCommand vrCommand =
      static_cast<IVrComposerClient::VrCommand>(command);
@@ -59,7 +96,7 @@ bool VrComposerClient::VrCommandReader::parseCommand(
  }
}

bool VrComposerClient::VrCommandReader::parseSetLayerInfo(uint16_t length) {
bool ComposerClientImpl::VrCommandReader::parseSetLayerInfo(uint16_t length) {
  if (length != 2) {
    return false;
  }
@@ -72,7 +109,7 @@ bool VrComposerClient::VrCommandReader::parseSetLayerInfo(uint16_t length) {
  return true;
}

bool VrComposerClient::VrCommandReader::parseSetClientTargetMetadata(
bool ComposerClientImpl::VrCommandReader::parseSetClientTargetMetadata(
    uint16_t length) {
  if (length != 7)
    return false;
@@ -84,7 +121,7 @@ bool VrComposerClient::VrCommandReader::parseSetClientTargetMetadata(
  return true;
}

bool VrComposerClient::VrCommandReader::parseSetLayerBufferMetadata(
bool ComposerClientImpl::VrCommandReader::parseSetLayerBufferMetadata(
    uint16_t length) {
  if (length != 7)
    return false;
@@ -98,7 +135,7 @@ bool VrComposerClient::VrCommandReader::parseSetLayerBufferMetadata(
}

IVrComposerClient::BufferMetadata
VrComposerClient::VrCommandReader::readBufferMetadata() {
ComposerClientImpl::VrCommandReader::readBufferMetadata() {
  IVrComposerClient::BufferMetadata metadata = {
    .width = read(),
    .height = read(),
@@ -110,5 +147,132 @@ VrComposerClient::VrCommandReader::readBufferMetadata() {
  return metadata;
}

}  // namespace

VrComposerClient::VrComposerClient(dvr::VrHwc& hal)
    : client_(new ComposerClientImpl(hal)) {
  client_->initialize();
}

VrComposerClient::~VrComposerClient() {}

void VrComposerClient::onHotplug(Display display,
    IComposerCallback::Connection connected) {
  client_->onHotplug(display, connected);
}

Return<void> VrComposerClient::registerCallback(
    const sp<IComposerCallback>& callback) {
  return client_->registerCallback(callback);
}

Return<uint32_t> VrComposerClient::getMaxVirtualDisplayCount() {
  return client_->getMaxVirtualDisplayCount();
}

Return<void> VrComposerClient::createVirtualDisplay(uint32_t width,
    uint32_t height, PixelFormat formatHint, uint32_t outputBufferSlotCount,
    createVirtualDisplay_cb hidl_cb) {
  return client_->createVirtualDisplay(
      width, height, formatHint, outputBufferSlotCount, hidl_cb);
}

Return<Error> VrComposerClient::destroyVirtualDisplay(Display display) {
  return client_->destroyVirtualDisplay(display);
}

Return<void> VrComposerClient::createLayer(Display display,
    uint32_t bufferSlotCount, createLayer_cb hidl_cb) {
  return client_->createLayer(display, bufferSlotCount, hidl_cb);
}

Return<Error> VrComposerClient::destroyLayer(Display display, Layer layer) {
  return client_->destroyLayer(display, layer);
}

Return<void> VrComposerClient::getActiveConfig(Display display,
    getActiveConfig_cb hidl_cb) {
  return client_->getActiveConfig(display, hidl_cb);
}

Return<Error> VrComposerClient::getClientTargetSupport(Display display,
    uint32_t width, uint32_t height, PixelFormat format, Dataspace dataspace) {
  return client_->getClientTargetSupport(display, width, height, format,
                                         dataspace);
}

Return<void> VrComposerClient::getColorModes(Display display,
    getColorModes_cb hidl_cb) {
  return client_->getColorModes(display, hidl_cb);
}

Return<void> VrComposerClient::getDisplayAttribute(Display display,
    Config config, Attribute attribute, getDisplayAttribute_cb hidl_cb) {
  return client_->getDisplayAttribute(display, config, attribute, hidl_cb);
}

Return<void> VrComposerClient::getDisplayConfigs(Display display,
    getDisplayConfigs_cb hidl_cb) {
  return client_->getDisplayConfigs(display, hidl_cb);
}

Return<void> VrComposerClient::getDisplayName(Display display,
    getDisplayName_cb hidl_cb) {
  return client_->getDisplayName(display, hidl_cb);
}

Return<void> VrComposerClient::getDisplayType(Display display,
    getDisplayType_cb hidl_cb) {
  return client_->getDisplayType(display, hidl_cb);
}

Return<void> VrComposerClient::getDozeSupport(
    Display display, getDozeSupport_cb hidl_cb) {
  return client_->getDozeSupport(display, hidl_cb);
}

Return<void> VrComposerClient::getHdrCapabilities(
    Display display, getHdrCapabilities_cb hidl_cb) {
  return client_->getHdrCapabilities(display, hidl_cb);
}

Return<Error> VrComposerClient::setActiveConfig(Display display,
    Config config) {
  return client_->setActiveConfig(display, config);
}

Return<Error> VrComposerClient::setColorMode(Display display, ColorMode mode) {
  return client_->setColorMode(display, mode);
}

Return<Error> VrComposerClient::setPowerMode(Display display, PowerMode mode) {
  return client_->setPowerMode(display, mode);
}

Return<Error> VrComposerClient::setVsyncEnabled(Display display,
    Vsync enabled) {
  return client_->setVsyncEnabled(display, enabled);
}

Return<Error> VrComposerClient::setClientTargetSlotCount(
    Display display, uint32_t clientTargetSlotCount) {
  return client_->setClientTargetSlotCount(display, clientTargetSlotCount);
}

Return<Error> VrComposerClient::setInputCommandQueue(
    const hardware::MQDescriptorSync<uint32_t>& descriptor) {
  return client_->setInputCommandQueue(descriptor);
}

Return<void> VrComposerClient::getOutputCommandQueue(
    getOutputCommandQueue_cb hidl_cb) {
  return client_->getOutputCommandQueue(hidl_cb);
}

Return<void> VrComposerClient::executeCommands(uint32_t inLength,
    const hidl_vec<hidl_handle>& inHandles, executeCommands_cb hidl_cb) {
  return client_->executeCommands(inLength, inHandles, hidl_cb);
}

}  // namespace dvr
}  // namespace android
+48 −26
Original line number Diff line number Diff line
@@ -29,37 +29,59 @@ class VrHwc;
using hardware::graphics::common::V1_0::PixelFormat;
using hardware::graphics::composer::V2_1::implementation::ComposerClient;

class VrComposerClient : public ComposerClient {
class VrComposerClient : public IVrComposerClient {
 public:
  VrComposerClient(android::dvr::VrHwc& hal);
  virtual ~VrComposerClient();

 private:
  class VrCommandReader : public ComposerClient::CommandReader {
   public:
    VrCommandReader(VrComposerClient& client);
    ~VrCommandReader() override;

    bool parseCommand(IComposerClient::Command command,
                      uint16_t length) override;
  void onHotplug(Display display, IComposerCallback::Connection connected);

  // IComposerClient
  Return<void> registerCallback(const sp<IComposerCallback>& callback) override;
  Return<uint32_t> getMaxVirtualDisplayCount() override;
  Return<void> createVirtualDisplay(
      uint32_t width, uint32_t height, PixelFormat formatHint,
      uint32_t outputBufferSlotCount, createVirtualDisplay_cb hidl_cb) override;
  Return<Error> destroyVirtualDisplay(Display display) override;
  Return<void> createLayer(Display display, uint32_t bufferSlotCount,
                           createLayer_cb hidl_cb) override;
  Return<Error> destroyLayer(Display display, Layer layer) override;
  Return<void> getActiveConfig(Display display,
                               getActiveConfig_cb hidl_cb) override;
  Return<Error> getClientTargetSupport(
      Display display, uint32_t width, uint32_t height, PixelFormat format,
      Dataspace dataspace) override;
  Return<void> getColorModes(Display display,
                             getColorModes_cb hidl_cb) override;
  Return<void> getDisplayAttribute(
      Display display, Config config, Attribute attribute,
      getDisplayAttribute_cb hidl_cb) override;
  Return<void> getDisplayConfigs(Display display,
                                 getDisplayConfigs_cb hidl_cb) override;
  Return<void> getDisplayName(Display display,
                              getDisplayName_cb hidl_cb) override;
  Return<void> getDisplayType(Display display,
                              getDisplayType_cb hidl_cb) override;
  Return<void> getDozeSupport(Display display,
                              getDozeSupport_cb hidl_cb) override;
  Return<void> getHdrCapabilities(Display display,
                                  getHdrCapabilities_cb hidl_cb) override;
  Return<Error> setActiveConfig(Display display, Config config) override;
  Return<Error> setColorMode(Display display, ColorMode mode) override;
  Return<Error> setPowerMode(Display display, PowerMode mode) override;
  Return<Error> setVsyncEnabled(Display display, Vsync enabled) override;
  Return<Error> setClientTargetSlotCount(
      Display display, uint32_t clientTargetSlotCount) override;
  Return<Error> setInputCommandQueue(
      const hardware::MQDescriptorSync<uint32_t>& descriptor) override;
  Return<void> getOutputCommandQueue(
      getOutputCommandQueue_cb hidl_cb) override;
  Return<void> executeCommands(
      uint32_t inLength, const hidl_vec<hidl_handle>& inHandles,
      executeCommands_cb hidl_cb) override;

 private:
    bool parseSetLayerInfo(uint16_t length);
    bool parseSetClientTargetMetadata(uint16_t length);
    bool parseSetLayerBufferMetadata(uint16_t length);

    IVrComposerClient::BufferMetadata readBufferMetadata();

    VrComposerClient& mVrClient;
    android::dvr::VrHwc& mVrHal;

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

  std::unique_ptr<CommandReader> createCommandReader() override;

  dvr::VrHwc& mVrHal;
  std::unique_ptr<ComposerClient> client_;

  VrComposerClient(const VrComposerClient&) = delete;
  void operator=(const VrComposerClient&) = delete;
+0 −8
Original line number Diff line number Diff line
@@ -820,7 +820,6 @@ Return<void> VrHwc::createClient(createClient_cb hidl_cb) {
  sp<VrComposerClient> client;
  if (client_ == nullptr) {
    client = new VrComposerClient(*this);
    client->initialize();
  } else {
    ALOGE("Already have a client");
    status = Error::NO_RESOURCES;
@@ -852,12 +851,5 @@ HwcDisplay* VrHwc::FindDisplay(Display display) {
  return iter == displays_.end() ? nullptr : iter->second.get();
}

ComposerView* GetComposerViewFromIComposer(
    hardware::graphics::composer::V2_1::IComposer* composer) {
  return static_cast<VrHwc*>(composer);
}

IComposer* HIDL_FETCH_IComposer(const char*) { return new VrHwc(); }

}  // namespace dvr
}  // namespace android
+0 −7
Original line number Diff line number Diff line
@@ -309,13 +309,6 @@ class VrHwc : public IComposer, public ComposerBase, public ComposerView {
  void operator=(const VrHwc&) = delete;
};


ComposerView* GetComposerViewFromIComposer(
    hardware::graphics::composer::V2_1::IComposer* composer);

hardware::graphics::composer::V2_1::IComposer* HIDL_FETCH_IComposer(
    const char* name);

}  // namespace dvr
}  // namespace android

Loading